def get_score_array(self):
     """ return a list of score for each terms per atoms"""
     # NEED TO CORRECT hbond
     # result = self.scorer.get_score_array()
     sal = score_array_list = []
     for t, w in self.terms:
         sal.append(t.get_score_array()*w)
     self.hbond_array = sal[1]
     result = Numeric.add(sal[0], sal[2])
     result = Numeric.add(result, sal[3])
     self.array = result
     return self.array
Пример #2
0
 def get_score_array(self):
     """ return a list of score for each terms per atoms"""
     # NEED TO CORRECT hbond
     # result = self.scorer.get_score_array()
     sal = score_array_list = []
     for t, w in self.terms:
         sal.append(t.get_score_array() * w)
     self.hbond_array = sal[1]
     result = Numeric.add(sal[0], sal[2])
     result = Numeric.add(result, sal[3])
     self.array = result
     return self.array
Пример #3
0
 def getVertsFromCornerPts(self, cornerPoints):
     # cornerPoints = (center-halfsides, center+halfsides)
     # cornerPoints = (pt0, pt1)
     x1,y1,z1=cornerPoints[1]
     x0,y0,z0=cornerPoints[0]
     self.xside = x1-x0
     self.yside = y1-y0
     self.zside = z1-z0
     center = (x1-(x1-x0)/2., y1-(y1-y0)/2., z1-(z1-z0)/2.)
     self.center = center
     # maxCube sets box to cube with side = largest of x,y,z-side
     # min sets box to cube with side = smallest of x,y,z-side
     # maxCube has precedence over minCube
     if self.maxCube or self.minCube:
         if self.maxCube:
             side = max((x1-x0,y1-y0,z1-z0))
         elif self.minCube:
             side = min((x1-x0,y1-y0,z1-z0))
         self.xside = side
         self.yside = side
         self.zside = side
         pt1=tuple(Numeric.add(center,(side/2.,side/2,side/2)))
         pt0=tuple(Numeric.subtract(center,(side/2,side/2,side/2)))
         x1,y1,z1 = pt1
         x0,y0,z0 = pt0
     #built list of 8 pts
     ptList=((x1,y1,z0),
         (x0,y1,z0),
         (x0,y0,z0),
         (x1,y0,z0),
         (x1,y1,z1),
         (x0,y1,z1),
         (x0,y0,z1),
         (x1,y0,z1))
     return ptList
Пример #4
0
 def getVertsFromCornerPts(self, cornerPoints):
     # cornerPoints = (center-halfsides, center+halfsides)
     # cornerPoints = (pt0, pt1)
     x1, y1, z1 = cornerPoints[1]
     x0, y0, z0 = cornerPoints[0]
     self.xside = x1 - x0
     self.yside = y1 - y0
     self.zside = z1 - z0
     center = (x1 - (x1 - x0) / 2., y1 - (y1 - y0) / 2.,
               z1 - (z1 - z0) / 2.)
     self.center = center
     # maxCube sets box to cube with side = largest of x,y,z-side
     # min sets box to cube with side = smallest of x,y,z-side
     # maxCube has precedence over minCube
     if self.maxCube or self.minCube:
         if self.maxCube:
             side = max((x1 - x0, y1 - y0, z1 - z0))
         elif self.minCube:
             side = min((x1 - x0, y1 - y0, z1 - z0))
         self.xside = side
         self.yside = side
         self.zside = side
         pt1 = tuple(Numeric.add(center, (side / 2., side / 2, side / 2)))
         pt0 = tuple(
             Numeric.subtract(center, (side / 2, side / 2, side / 2)))
         x1, y1, z1 = pt1
         x0, y0, z0 = pt0
     #built list of 8 pts
     ptList = ((x1, y1, z0), (x0, y1, z0), (x0, y0, z0), (x1, y0, z0),
               (x1, y1, z1), (x0, y1, z1), (x0, y0, z1), (x1, y0, z1))
     return ptList
Пример #5
0
 def getVertsFromCenter(self, center):
     self.center = center
     halfSide = Numeric.multiply(
         Numeric.array((self.xside, self.yside, self.zside)), 0.5)
     pt1 = tuple(Numeric.add(center, halfSide))
     pt0 = tuple(Numeric.subtract(center, halfSide))
     return (pt0, pt1)
Пример #6
0
    def __init__(self, name=None, check=1, **kw):

        self.maxCube = None
        self.minCube = None

        if    not kw.get('origin') \
          and not kw.get('center') \
          and not kw.get('cornerPoints') \
          and not kw.get('minCube'):
            kw['origin'] = (0, 0, 0)

        #set up some defaults:
        materials = kw.get('materials')
        #print 'in BOX materials kw=', materials
        if not materials:
            kw['materials'] = ((0,0,1),(0,1,0),(0,0,1),(0,1,0),(1,0,0),(1,0,0),)
        #print 'in BOX after test for materials, kwmaterials=', kw['materials']

        vertices = kw.get('vertices')
        if vertices is not None:
            assert len(vertices)==8
            pt1 = Numeric.array(vertices[2])
            pt2 = Numeric.array(vertices[4])
            self.center = tuple(Numeric.multiply(Numeric.add(pt1,pt2), 0.5))
            self.xside, self.yside, self.zside = \
                Numeric.subtract(pt2,pt1)
        else:
            #set up center 
            center = kw.get('center')
            #if not center: center = (0.,0.,0.)
            self.center = center

            #set up sides
            side = kw.get('side')
            if side:
                self.xside = side
                self.yside = side
                self.zside = side
            else:
                xside = kw.get('xside')
                if not xside: xside = 1.0
                self.xside = xside
                yside = kw.get('yside')
                if not yside: yside = 1.0
                self.yside = yside
                zside = kw.get('zside')
                if not zside: zside = 1.0
                self.zside = zside

        #NB faces shouldn't change
        self.faces=((0,3,2,1),
                (3,7,6,2),
                (7,4,5,6),
                (0,1,5,4),
                (1,2,6,5),
                (0,4,7,3))
        self.funcs = {}
        fkeys = ['center', 'origin', 'centerOrigin', 'xside', \
                'yside', 'zside','maxCube', 'minCube']
        fs = [self.getVertsFromCenter, self.getVertsFromOrigin, \
                self.getVertsFromCenterOrigin, 
                CallBackFunction(self.getVertsFromSide, 'xside'),
                CallBackFunction(self.getVertsFromSide, 'yside'),
                CallBackFunction(self.getVertsFromSide, 'zside'),
                self.setMaxCube, self.setMinCube]
        for i in range(len(fkeys)):
            self.funcs[fkeys[i]] = fs[i]


        self.pickableVertices = 1
        kw['frontPolyMode'] = 'line'
        apply( IndexedPolygons.__init__, (self, name, check), kw )
        self.inheritMaterial = 0
        
        #print 'calling self.Set with ', kw.get('materials')
        #apply(self.Set,(), kw)

        # register functions to compute normals
        self.VertexNormalFunction(self.ComputeVertexNormals)
        self.vertexSet.normals.ComputeMode( viewerConst.AUTO )
        self.FaceNormalFunction(self.ComputeFaceNormals)
        self.faceSet.normals.ComputeMode( viewerConst.AUTO )
        self._PrimitiveType()
        self.GetNormals()
        self.oldFPM = GL.GL_LINE
Пример #7
0
 def getVertsFromCenter(self, center):
     self.center = center
     halfSide = Numeric.multiply(Numeric.array((self.xside, self.yside, self.zside)), 0.5)
     pt1=tuple(Numeric.add(center,halfSide))
     pt0=tuple(Numeric.subtract(center,halfSide))
     return (pt0, pt1)
Пример #8
0
 def getVertsFromOrigin(self, origin):
     #set new center here, also
     side = Numeric.array((self.xside, self.yside, self.zside))
     self.center = tuple(Numeric.add(origin, Numeric.multiply(side, 0.5)))
     pt1=tuple(Numeric.add(origin, side))
     return (origin, pt1)
Пример #9
0
    def Set(self, check=1, redo=1, updateOwnGui=True, **kw):
        """set data for this object: Set polygon's vertices, faces, normals or materials
check=1 : verify that all the keywords present can be handle by this func 
redo=1 : append self to viewer.objectsNeedingRedo
updateOwnGui=True : allow to update owngui at the end this func
"""
        redoFlags = 0

        #newKeyList is list of keys specified in call to Set
        newKeyList = kw.keys()

        # Setting both center AND origin is a special case
        # which sets all side lengths
        centerOrigin = 0
        if 'center' in newKeyList and 'origin' in newKeyList:
            centerOrigin = 1

        side= kw.get( 'side')
        if side:
            kw['xside'] = side
            kw['yside'] = side
            kw['zside'] = side
            newKeyList.extend(['xside','yside', 'zside'])
            newKeyList = uniq(newKeyList)

        apply(self.updateVal, (['xside','yside','zside'],),kw)

        #these are either 1 or None
        self.maxCube = kw.get('maxCube')
        self.minCube = kw.get('minCube')
        if self.minCube and self.maxCube:
            self.center = [ (self.minCube[0] + self.maxCube[0]) * .5 ,
                            (self.minCube[1] + self.maxCube[1]) * .5 ,
                            (self.minCube[2] + self.maxCube[2]) * .5 ]
       
        # kl used to implement this precedence: 
        # side < [x,y,z]side < center < origin < cornerPoints < vertices
        # vertices are dealt with last
        cornerPoints = None
        kl = ['xside', 'yside', 'zside','minCube', 'maxCube', 'center', 'origin'] 
        for key in kl:
            if key in newKeyList:
                newVal = kw.get(key)
                if not newVal: continue
                if key in ['center','origin'] and centerOrigin:
                    self.center = kw.get('center')
                    newVal = kw.get('origin')
                    newKeyList.remove('center')
                    newKeyList.remove('origin')
                    f = self.funcs['centerOrigin']
                else:
                    del kw[key]
                    f = self.funcs[key]
                cornerPoints = apply(f, (newVal,),{})

        #if cornerPoints are specified, they override other info
        newcornerPoints = kw.get('cornerPoints')
        if newcornerPoints:
            cornerPoints = newcornerPoints

        if cornerPoints:
            ptList = self.getVertsFromCornerPts(cornerPoints)
        else:
            ptList = None

        #vertices overrides everything: set center+sides
        newVertices = kw.get('vertices')
        if newVertices is not None:
            assert len(newVertices)==8
            pt1 = Numeric.array(newVertices[2])
            pt2 = Numeric.array(newVertices[4])
            self.center = tuple(Numeric.multiply(Numeric.add(pt1,pt2), 0.5))
            self.xside, self.yside, self.zside = \
                Numeric.subtract(pt2,pt1)
            redoFlags |= self._redoFlags['redoDisplayListFlag']
        elif ptList:
            assert len(ptList)==8
            kw['vertices'] = ptList
            redoFlags |= self._redoFlags['redoDisplayListFlag']

        if kw.get('faces') is None:
            kw['faces'] = self.faces

        redoFlags |= apply( IndexedPolygons.Set, (self, check, 0), kw )

        return self.redoNow(redo, updateOwnGui, redoFlags)
Пример #10
0
    def __init__(self, name=None, check=1, **kw):

        self.maxCube = None
        self.minCube = None

        if    not kw.get('origin') \
          and not kw.get('center') \
          and not kw.get('cornerPoints') \
          and not kw.get('minCube'):
            kw['origin'] = (0, 0, 0)

        #set up some defaults:
        materials = kw.get('materials')
        #print 'in BOX materials kw=', materials
        if not materials:
            kw['materials'] = (
                (0, 0, 1),
                (0, 1, 0),
                (0, 0, 1),
                (0, 1, 0),
                (1, 0, 0),
                (1, 0, 0),
            )
        #print 'in BOX after test for materials, kwmaterials=', kw['materials']

        vertices = kw.get('vertices')
        if vertices is not None:
            assert len(vertices) == 8
            pt1 = Numeric.array(vertices[2])
            pt2 = Numeric.array(vertices[4])
            self.center = tuple(Numeric.multiply(Numeric.add(pt1, pt2), 0.5))
            self.xside, self.yside, self.zside = \
                Numeric.subtract(pt2,pt1)
        else:
            #set up center
            center = kw.get('center')
            #if not center: center = (0.,0.,0.)
            self.center = center

            #set up sides
            side = kw.get('side')
            if side:
                self.xside = side
                self.yside = side
                self.zside = side
            else:
                xside = kw.get('xside')
                if not xside: xside = 1.0
                self.xside = xside
                yside = kw.get('yside')
                if not yside: yside = 1.0
                self.yside = yside
                zside = kw.get('zside')
                if not zside: zside = 1.0
                self.zside = zside

        #NB faces shouldn't change
        self.faces = ((0, 3, 2, 1), (3, 7, 6, 2), (7, 4, 5, 6), (0, 1, 5, 4),
                      (1, 2, 6, 5), (0, 4, 7, 3))
        self.funcs = {}
        fkeys = ['center', 'origin', 'centerOrigin', 'xside', \
                'yside', 'zside','maxCube', 'minCube']
        fs = [self.getVertsFromCenter, self.getVertsFromOrigin, \
                self.getVertsFromCenterOrigin,
                CallBackFunction(self.getVertsFromSide, 'xside'),
                CallBackFunction(self.getVertsFromSide, 'yside'),
                CallBackFunction(self.getVertsFromSide, 'zside'),
                self.setMaxCube, self.setMinCube]
        for i in range(len(fkeys)):
            self.funcs[fkeys[i]] = fs[i]

        self.pickableVertices = 1
        kw['frontPolyMode'] = 'line'
        apply(IndexedPolygons.__init__, (self, name, check), kw)
        self.inheritMaterial = 0

        #print 'calling self.Set with ', kw.get('materials')
        #apply(self.Set,(), kw)

        # register functions to compute normals
        self.VertexNormalFunction(self.ComputeVertexNormals)
        self.vertexSet.normals.ComputeMode(viewerConst.AUTO)
        self.FaceNormalFunction(self.ComputeFaceNormals)
        self.faceSet.normals.ComputeMode(viewerConst.AUTO)
        self._PrimitiveType()
        self.GetNormals()
        self.oldFPM = GL.GL_LINE
Пример #11
0
 def getVertsFromOrigin(self, origin):
     #set new center here, also
     side = Numeric.array((self.xside, self.yside, self.zside))
     self.center = tuple(Numeric.add(origin, Numeric.multiply(side, 0.5)))
     pt1 = tuple(Numeric.add(origin, side))
     return (origin, pt1)
Пример #12
0
    def Set(self, check=1, redo=1, updateOwnGui=True, **kw):
        """set data for this object: Set polygon's vertices, faces, normals or materials
check=1 : verify that all the keywords present can be handle by this func 
redo=1 : append self to viewer.objectsNeedingRedo
updateOwnGui=True : allow to update owngui at the end this func
"""
        redoFlags = 0

        #newKeyList is list of keys specified in call to Set
        newKeyList = kw.keys()

        # Setting both center AND origin is a special case
        # which sets all side lengths
        centerOrigin = 0
        if 'center' in newKeyList and 'origin' in newKeyList:
            centerOrigin = 1

        side = kw.get('side')
        if side:
            kw['xside'] = side
            kw['yside'] = side
            kw['zside'] = side
            newKeyList.extend(['xside', 'yside', 'zside'])
            newKeyList = uniq(newKeyList)

        apply(self.updateVal, (['xside', 'yside', 'zside'], ), kw)

        #these are either 1 or None
        self.maxCube = kw.get('maxCube')
        self.minCube = kw.get('minCube')
        if self.minCube and self.maxCube:
            self.center = [(self.minCube[0] + self.maxCube[0]) * .5,
                           (self.minCube[1] + self.maxCube[1]) * .5,
                           (self.minCube[2] + self.maxCube[2]) * .5]

        # kl used to implement this precedence:
        # side < [x,y,z]side < center < origin < cornerPoints < vertices
        # vertices are dealt with last
        cornerPoints = None
        kl = [
            'xside', 'yside', 'zside', 'minCube', 'maxCube', 'center', 'origin'
        ]
        for key in kl:
            if key in newKeyList:
                newVal = kw.get(key)
                if not newVal: continue
                if key in ['center', 'origin'] and centerOrigin:
                    self.center = kw.get('center')
                    newVal = kw.get('origin')
                    newKeyList.remove('center')
                    newKeyList.remove('origin')
                    f = self.funcs['centerOrigin']
                else:
                    del kw[key]
                    f = self.funcs[key]
                cornerPoints = apply(f, (newVal, ), {})

        #if cornerPoints are specified, they override other info
        newcornerPoints = kw.get('cornerPoints')
        if newcornerPoints:
            cornerPoints = newcornerPoints

        if cornerPoints:
            ptList = self.getVertsFromCornerPts(cornerPoints)
        else:
            ptList = None

        #vertices overrides everything: set center+sides
        newVertices = kw.get('vertices')
        if newVertices is not None:
            assert len(newVertices) == 8
            pt1 = Numeric.array(newVertices[2])
            pt2 = Numeric.array(newVertices[4])
            self.center = tuple(Numeric.multiply(Numeric.add(pt1, pt2), 0.5))
            self.xside, self.yside, self.zside = \
                Numeric.subtract(pt2,pt1)
            redoFlags |= self._redoFlags['redoDisplayListFlag']
        elif ptList:
            assert len(ptList) == 8
            kw['vertices'] = ptList
            redoFlags |= self._redoFlags['redoDisplayListFlag']

        if kw.get('faces') is None:
            kw['faces'] = self.faces

        redoFlags |= apply(IndexedPolygons.Set, (self, check, 0), kw)

        return self.redoNow(redo, updateOwnGui, redoFlags)