Exemplo n.º 1
0
 def testTransformTranslation(self):
     aSHSource = emconv.AtomicStructHandler(self.PDBFileName)
     structure = aSHSource.getStructure()
     structure_copy = deepcopy(aSHSource.getStructure())
     shift = [100., 50., 25.]
     #        rotation_matrix = euler_matrix(deg2rad(45.), 0., 0., 'szyz')
     rotation_matrix = emconv.euler_matrix(0., 0., 0., 'szyz')
     translation = emconv.translation_matrix(shift)
     M = emconv.concatenate_matrices(rotation_matrix, translation)
     aSHSource.transform(M)
     for atom1, atom2 in zip(structure.get_atoms(),
                             structure_copy.get_atoms()):
         coord1 = atom1.get_coord()
         coord2 = [sum(x) for x in zip(atom2.get_coord(), shift)]
         for i in range(3):
             self.assertAlmostEqual(coord1[i], coord2[i], 2)
Exemplo n.º 2
0
 def testTransformRotation(self):
     aSHSource = emconv.AtomicStructHandler(self.PDBFileName)
     structure = aSHSource.getStructure()
     structure_copy = deepcopy(structure)
     rot = np.deg2rad(10)
     theta = np.deg2rad(20.)
     psi = np.deg2rad(30.)
     rotation_matrix = emconv.euler_matrix(rot, theta, psi, 'szyz')
     translation = emconv.translation_matrix([0., 0., 0.])
     M = emconv.concatenate_matrices(rotation_matrix, translation)
     aSHSource.transform(M)
     m = M[:3, :3]
     for atom1, atom2 in zip(structure.get_atoms(),
                             structure_copy.get_atoms()):
         coord1 = atom1.get_coord()
         coord2 = m.dot(atom2.get_coord())
         for i in range(3):
             self.assertAlmostEqual(coord1[i], coord2[i], 2)
Exemplo n.º 3
0
        def __applyTransform(suffix, pdbFileName, shift, angles, sampling):
            """ auxiliary function, transform PDB and 3dmap files"""
            # create a Scipion transformation matrix
            from numpy import deg2rad
            rotation_matrix = emconv.euler_matrix(deg2rad(angles[0]),
                                                  deg2rad(angles[1]),
                                                  deg2rad(angles[2]), 'szyz')
            translation = emconv.translation_matrix(shift)
            M = emconv.concatenate_matrices(rotation_matrix, translation)

            # apply it to the pdb file
            # if rotation move to center
            aSH = emconv.AtomicStructHandler(pdbFileName)
            if angles[0] != 0. or angles[1] != 0. or angles[2] != 0.:
                ih = ImageHandler()
                x, y, z, n = ih.getDimensions("emd_%s.map" % EMDBID)
                x /= 2.
                y /= 2.
                z /= 2.
                localShift = [-x, -y, -z]
                rotation_matrix = emconv.euler_matrix(0., 0., 0., 'szyz')
                translation = emconv.translation_matrix(localShift)
                localM = emconv.concatenate_matrices(rotation_matrix,
                                                     translation)
                aSH.transform(localM, sampling=sampling)

            aSH.transform(M, sampling=sampling)

            if angles[0] != 0. or angles[1] != 0. or angles[2] != 0.:
                localShift = [x, y, z]
                rotation_matrix = emconv.euler_matrix(0., 0., 0., 'szyz')
                translation = emconv.translation_matrix(localShift)
                localM = emconv.concatenate_matrices(rotation_matrix,
                                                     translation)
                aSH.transform(localM, sampling=sampling)

            aSH.write("%s_%s_transformed.ent" % (suffix, PDBID.lower()))

            # get equivalent xmipp transformation
            shift, angles = __getXmippEulerAngles(M)
            # shift 3map and set sampling
            __runXmippProgram(
                "xmipp_transform_geometry", '-i emd_%s.map '
                '-o %s_emd_%s_transform.map '
                '--interp linear '
                '--shift %f %f %f '
                '--rotate_volume euler %f %f %f ' %
                (EMDBID, suffix, EMDBID, shift[0], shift[1], shift[2],
                 angles[0], angles[1], angles[2]))
            header = Ccp4Header("%s_emd_%s_transform.map" % (suffix, EMDBID),
                                readHeader=True)
            header.setSampling(sampling)
            # put the sampling back, xmipp_transform_geometry erased it
            header.writeHeader()

            # view the results with chimera
            from pwem.viewers import Chimera
            args = "%s %s %s %s" % (
                pdbFileName, "emd_%s.map" % EMDBID, "%s_%s_transformed.ent" %
                (suffix, PDBID.lower()), "%s_emd_%s_transform.map" %
                (suffix, EMDBID))
            Chimera.runProgram(args)