コード例 #1
0
    def getMatrices(self):
        angle=360.0/self.symmetry
        m=[]
        t=Numeric.array(self.point)*-1

        if self.identity == 1:
            mat = Numeric.identity(4).astype('f')
            m.append(mat)
               
        T = Transformation(trans=t)
        T1 = T.inverse()
        for i in range(self.symmetry-1):
            newList=[]
            newList.extend(list(self.vector))
            newList.append(angle)

            R = Transformation(quaternion=newList)
            
            mt = T1 * R * T
            #newmat = mt.getMatrix()
            newmat = mt.getDejaVuMatrix()
            m.append(newmat)
            angle=angle+360.0/self.symmetry
            
        return m
コード例 #2
0
    def applyStateOld(self, state):
        """
        """
        q = state.quaternion
        t = numpy.array(state.translation)
        o = numpy.array(state.origin)

        # center the coordinates
        ##          self.resultCoords = (self.resultCoords -
        ##                               numpy.array([o[0], o[1], o[2], 0.0]))

        # center the coordinates (node-by-node)
        def __center(node, o):
            node.coords = node.coords - o

        root = self.torTree.rootNode
        root.pre_traverse(__center, root, numpy.array([o[0], o[1], o[2], 0.0]))

        # construct rootNode transformation matrix
        mtx = Transformation(t + o, q).getMatrix(transpose=1)

        # apply the torsions
        coords = self.applyAngList(state.torsions, mtx)

        # must "reset" each nodes coords
        def __uncenter(node, o):
            node.coords = node.coords + o

        root.pre_traverse(__uncenter, root,
                          numpy.array([o[0], o[1], o[2], 0.0]))

        return coords
コード例 #3
0
 def applyQuaternion(self, q, o=(0., 0., 0.)):
     """Apply the given quaterion.
     """
     # center the coordinates
     self.resultCoords = (self.resultCoords -
                          numpy.array([o[0], o[1], o[2], 0.0]))
     self.resultCoords = Transformation(o, q).apply(self.resultCoords)
     return self.getResultCoords()
コード例 #4
0
    def getTorsionOnlyCoords(self):
        """Return your coordinates with no quaterion.

        Don't save these coords, compute them every time.
        """
        self.mol.allAtoms.setConformation(self.mol.stoc.confIndex)
        self.mol.stoc.applyAngList(self.torsions,
            Transformation(trans=self.origin).getMatrix(transpose=1))
        return self.mol.allAtoms.coords
コード例 #5
0
 def applyOrientation(self, q=(0.,0.,0.,0.), t=(0.,0.,0.), o=(0.,0.,0.)):
     """origin specifies where the local origin is in world coordinates
     (i.e., where is this object's origin in the world)
     """
     # center the coordinates
     self.resultCoords = (self.resultCoords -
                          Numeric.array([o[0], o[1], o[2], 0.0]))
     sum = Numeric.array(t) + Numeric.array(o)
     self.resultCoords = Transformation(sum, q).apply(self.resultCoords)
     return self.getResultCoords()
コード例 #6
0
    def getMatrices(self):
        m=[]
        newList=[]
        mat = Numeric.identity(4).astype('f')
        if self.identity == 1:
            m.append(mat)

        newList.extend(list(self.vector))
        newList.append(self.angle)
        t=Numeric.array(self.center)*-1
        
        T = Transformation(trans=t)
        R = Transformation(quaternion=newList)

        mt = T.inverse() * R * T
        newmat = mt.getMatrix()

        m.append(newmat)
        return m
コード例 #7
0
    def applyState(self, state):
        """
        """
        q = state.quaternion
        t = numpy.array(state.translation)
        o = numpy.array(state.origin)

        # construct rootNode transformation matrix
        # mtx = Transformation(t+o, q).getMatrix(transpose=1)
        # Corrected by AG 08/28/2008
        mtx = Transformation(t, q).getMatrix().transpose()

        # apply the torsions
        self.applyAngList(state.torsions, mtx)
コード例 #8
0
    def setUp(self):
        """Called for every test."""
        self.decimals = 4  # for numpy.around; 7 is SciPy default.
        self.idmtx = Transformation().getMatrix(transpose=1)

        self.known_points = [[1., 0., 2.], [1., 0., 1.], [1., 1., 1.],
                             [0., 0., 1.], [0., 0., 0.], [0., 1., 0.],
                             [0., 1., -1.], [1., 1., -1.], [1., 2., -1.],
                             [1., 1., -2.]]
        npts = len(self.known_points)
        dim = 3
        self.max = 9999999.
        self.min = -self.max
        self.random_points = RandomArray.uniform(self.min, self.max,
                                                 (npts, dim)).tolist()

        # create a simple torsion system for both point lists
        torTree = TestTorTree()
        torTree.append(TestTorsion(4, 3, [0, 1, 2]))
        torTree.append(TestTorsion(3, 1, [0, 2]))
        torTree.append(TestTorsion(6, 7, [8, 9]))
        self.torTree = torTree
コード例 #9
0
    def asIndexedPolygons(self, run=1, quality=None, radius=None, **kw):
        """ run=0 returns 1 if this geom can be represented as an
        IndexedPolygon and None if not. run=1 returns the IndexedPolygon
        object."""

        #print "Cylinders.asIndexedPolygons", quality

        if run == 0:
            return 1  # yes, I can be represented as IndexedPolygons

        import numpy.oldnumeric as Numeric, math
        from mglutil.math.transformation import Transformation

        if quality in [1, 2, 3, 4, 5]:
            quality = quality
        elif quality < 0 and self.quality in [2, 3, 4, 5]:
            quality = self.quality - 2
        else:
            quality = self.quality - 1
        quality *= 5

        # make a copy of the cylinderTemplate
        tmpltVertices, tmpltFaces = self._cylinderTemplateDaniel(\
            quality=quality)

        centers = self.vertexSet.vertices.array
        faces = self.faceSet.faces.array

        tmpltVertices = Numeric.array(tmpltVertices).astype('f')
        tmpltFaces = Numeric.array(tmpltFaces).astype('f')

        addToFaces = Numeric.ones((tmpltFaces.shape)) * 2 * len(tmpltVertices)

        VV = []  # this list stores all vertices of all cylinders
        FF = []  # this list stores all faces of all cylinders

        # now loop over all cylinders in self
        for index in xrange(len(faces)):
            # tv temporarily stores the transformed unit cylinder vertices
            tv = tmpltVertices.__copy__()

            pt0 = centers[faces[index][0]]  # bottom of cylinder
            pt1 = centers[faces[index][1]]  # top of cylinder

            # get radius for cylinder
            if radius is not None:
                radx = rady = radius  #override radii
            elif self.oneRadius:
                radx = rady = radius = self.vertexSet.radii.array[0]
            else:
                radx = self.vertexSet.radii.array[faces[index][1]]
                rady = self.vertexSet.radii.array[faces[index][0]]

            # determine scale and rotation of current cylinder
            sz = 0.0
            for nbr in (0, 1, 2):
                sz = sz + (pt0[nbr] - pt1[nbr]) * (pt0[nbr] - pt1[nbr])
            if sz <= 0.0: return
            sz = math.sqrt(sz)

            rx = -180.0 * math.acos((pt1[2] - pt0[2]) / sz) / math.pi
            dx = pt1[0] - pt0[0]
            dy = pt1[1] - pt0[1]

            if math.fabs(dx) < 0.00001 and math.fabs(dy) < 0.00001:
                rz = 0.0
            else:
                rz = -180.0 * math.atan2(dx, dy) / math.pi

            # prepare rotations matrices of current cylinder
            Rx = Transformation(quaternion=[1, 0, 0, rx])
            if rz <= 180.0 and rz >= -180.0:
                Rz = Transformation(quaternion=[0, 0, 1, rz])
                R = Rz * Rx
            else:
                R = Rx
            r = R.getMatrix()

            k = 0
            for v in tmpltVertices:  # I DO NOT use Numeric.matrixmultiply
                # here, in order to gain significant speed
                v0x, v0y, v0z = v[0]  # saves some lookups
                v1x, v1y, v1z = v[1]

                tv[k][0]=\
                ([r[0][0]*v0x*radx+r[1][0]*v0y*radx+r[2][0]*v0z*sz+pt0[0],
                  r[0][1]*v0x*radx+r[1][1]*v0y*radx+r[2][1]*v0z*sz+pt0[1],
                  r[0][2]*v0x*radx+r[1][2]*v0y*radx+r[2][2]*v0z*sz+pt0[2]])

                tv[k][1]=\
                ([r[0][0]*v1x*rady+r[1][0]*v1y*rady+r[2][0]*v1z+pt0[0],
                  r[0][1]*v1x*rady+r[1][1]*v1y*rady+r[2][1]*v1z+pt0[1],
                  r[0][2]*v1x*rady+r[1][2]*v1y*rady+r[2][2]*v1z+pt0[2]])

                k = k + 1

            ctv = None
            ctv = Numeric.concatenate((tv[:, 1], tv[:, 0]))

            # now add the data to the big lists
            VV.extend(list(ctv))
            FF.extend(list(tmpltFaces))

            # increase face indices by lenght of vertices
            tmpltFaces = tmpltFaces + addToFaces

        VV = Numeric.array(VV).astype('f')
        FF = Numeric.array(FF).astype('f')
        # FIXME: should I compute normals?

        # now we can build the IndexedPolygon geom
        from DejaVu.IndexedPolygons import IndexedPolygons
        cylGeom = IndexedPolygons("cyl",
                                  vertices=VV,
                                  faces=FF,
                                  visible=1,
                                  invertNormals=self.invertNormals)

        # copy Cylinders materials into cylGeom
        matF = self.materials[GL.GL_FRONT]
        matB = self.materials[GL.GL_BACK]
        cylGeom.materials[GL.GL_FRONT].binding = matF.binding[:]
        cylGeom.materials[GL.GL_FRONT].prop = matF.prop[:]
        cylGeom.materials[GL.GL_BACK].binding = matB.binding[:]
        cylGeom.materials[GL.GL_BACK].prop = matB.prop[:]

        # if binding per vertex:
        if cylGeom.materials[GL.GL_FRONT].binding[1] == viewerConst.PER_VERTEX:
            newprop = []
            props = cylGeom.materials[GL.GL_FRONT].prop[1]

            for i in xrange(len(faces)):
                for j in xrange(len(faces[i]) - 1):
                    vi1 = self.faceSet.faces.array[i][j]
                    vi2 = self.faceSet.faces.array[i][j + 1]
                    colx = props[vi2]
                    coly = props[vi1]

                    # add second color to first half of cyl vertices
                    for k in range(len(tmpltVertices)):
                        newprop.append(coly)
                    # add first color to second half of cyl vertices
                    for l in range(len(tmpltVertices)):
                        newprop.append(colx)

            cylGeom.materials[GL.GL_FRONT].prop[1] = newprop

        # and finally...
        #print "Cylinders.asIndexedPolygons out", quality
        return cylGeom