Chem.Subshape.SubshapeObjects

Package Chem :: Package Subshape :: Module SubshapeObjects |
[hide private]
[frames] | no frames]

# Source Code for Module Chem.Subshape.SubshapeObjects

     1  # $Id: SubshapeObjects.py 290 2007-07-16 05:19:53Z glandrum $
     2  #
     3  # Copyright (C) 2007 by Greg Landrum
     4  #  All rights reserved
     5  #
     6  import Chem
     7  import Geometry
     8
     9 -class SkeletonPoint(object):
    10    location=None
    11    shapeMoments=None
    12    shapeDirs=None
    13    molFeatures=None
    14    featmapFeatures=None
    15    fracVol=0.0
    16
    17 -  def __init__(self,*args,**kwargs):
    18      self._initMemberData()
    19      self.location = kwargs.get('location',None)
    20
    21 -  def _initMemberData(self):
    22      self.shapeMoments=(0.0,)*3
    23      self.shapeDirs=[None]*3
    24      self.molFeatures=[]
    25      self.featmapFeatures=[]
    26
    27 -class ShapeWithSkeleton(object):
    28    grid=None
    29    skelPts=None
    30
    31 -  def __init__(self,*args,**kwargs):
    32      self._initMemberData()
    33
    34 -  def _initMemberData(self):
    35      self.skelPts=[]
    36
    37
    38 -class SubshapeShape(object):
    39    shapes=None # a list of ShapeWithSkeleton objects at multiple resolutions (low to high)
    40    featMap=None
    41    keyFeat=None
    42
    43 -  def __init__(self,*args,**kwargs):
    44      self._initMemberData()
    45
    46 -  def _initMemberData(self):
    47      self.shapes=[]
    48
    49 -def _displaySubshapeSkelPt(viewer,skelPt,cgoNm,color):
    50    viewer.server.sphere(tuple(skelPt.location),.5,color,cgoNm)
    51    if hasattr(skelPt,'shapeDirs'):
    52      momBeg = skelPt.location-skelPt.shapeDirs[0]
    53      momEnd = skelPt.location+skelPt.shapeDirs[0]
    54      viewer.server.cylinder(tuple(momBeg),tuple(momEnd),.1,color,cgoNm)
    55
    56 -def DisplaySubshapeSkeleton(viewer,shape,name,color=(1,0,1),colorByOrder=False):
    57    orderColors=((1,0,0),(0,1,0),(0,0,1),(1,1,0),(1,0,1),(0,1,1))
    58    cgoNm='%s-skeleton'%name
    59    viewer.server.resetCGO(cgoNm)
    60    for i,pt in enumerate(shape.skelPts):
    61      if colorByOrder:
    62        color = orderColors[i%len(orderColors)]
    63      _displaySubshapeSkelPt(viewer,pt,cgoNm,color)
    64
    65 -def DisplaySubshape(viewer,shape,name,showSkelPts=True,color=(1,0,1)):
    66    import Geometry
    67    import os,tempfile
    68    fName = tempfile.mktemp('.grd')
    69    Geometry.WriteGridToFile(shape.grid,fName)
    70    viewer.server.loadSurface(fName,name,'',2.5)
    71    if showSkelPts:
    72      DisplaySubshapeSkeleton(viewer,shape,name,color)
    73    try:
    74      os.unlink(fName)
    75    except:
    76      import time
    77      time.sleep(.5)
    78      try:
    79        os.unlink(fName)
    80      except:
    81        pass
    82