コード例 #1
0
ファイル: molecule.py プロジェクト: zhenhai-wang/PyXtal
    def get_orientation(self, xyz, rtol=0.15):
        """
        get orientation, needs to check the tolerance
        """
        from rdkit.Geometry import Point3D
        from rdkit.Chem import rdMolAlign, RemoveHs, rdmolfiles, rdMolTransforms
        mol = self.rdkit_mol(self.smile)
        
        conf0 = mol.GetConformer(0)
        conf1 = mol.GetConformer(1)
        conf2 = mol.GetConformer(2)
        angs = self.get_torsion_angles(xyz)
        xyz0 = self.set_torsion_angles(conf0, angs) #conf0 with aligned
        xyz1 = self.set_torsion_angles(conf0, angs, True) #conf0 with aligned

        for i in range(len(self.mol)):
            x0,y0,z0 = xyz0[i]
            x1,y1,z1 = xyz1[i]
            x,y,z = xyz[i]
            conf0.SetAtomPosition(i,Point3D(x0,y0,z0))
            conf1.SetAtomPosition(i,Point3D(x,y,z))
            conf2.SetAtomPosition(i,Point3D(x1,y1,z1))

        mol = RemoveHs(mol)
        rmsd1, trans1 = rdMolAlign.GetAlignmentTransform(mol, mol, 1, 0)
        rmsd2, trans2 = rdMolAlign.GetAlignmentTransform(mol, mol, 1, 2)
        tol = rtol*mol.GetNumAtoms()

        #print(rmsd1, rmsd2)
        if rmsd1 < tol:
            trans = trans1[:3,:3].T
            r = Rotation.from_matrix(trans)
            return r.as_euler('zxy', degrees=True), rmsd1, False
        elif rmsd2 < tol:
            trans = trans2[:3,:3].T
            r = Rotation.from_matrix(trans)
            return r.as_euler('zxy', degrees=True), rmsd2, True
        else:
            print(rmsd1, rmsd2)
            #rdmolfiles.MolToXYZFile(mol, '1.xyz', 0)
            #rdmolfiles.MolToXYZFile(mol, '2.xyz', 1)
            #rdmolfiles.MolToXYZFile(mol, '3.xyz', 2)
            print(self.get_torsion_angles(xyz))   
            print(self.get_torsion_angles(xyz0))   
            print(self.get_torsion_angles(xyz1))   
            raise ValueError("Problem in conformer")
コード例 #2
0
ファイル: get_rmsd.py プロジェクト: WhitestoneYang/e3fp-paper
def get_rmsd(mol1, mol2):
    mols = [mol1, mol2]
    mcs = rdFMCS.FindMCS(mols)
    match = rdkit.Chem.MolFromSmarts(mcs.smartsString)
    match1 = mol1.GetSubstructMatch(match)
    match2 = mol2.GetSubstructMatch(match)
    atom_map = zip(match1, match2)
    if len(atom_map) == 0:
        return np.nan
    return rdMolAlign.GetAlignmentTransform(mol1, mol2, atomMap=atom_map)[0]
コード例 #3
0
ファイル: testMolAlign.py プロジェクト: zxye3389/rdkit-orig
    def test1Basic(self):
        file1 = os.path.join(RDConfig.RDBaseDir,'Code','GraphMol',
                             'MolAlign', 'test_data', '1oir.mol')
        file2 = os.path.join(RDConfig.RDBaseDir,'Code','GraphMol',
                             'MolAlign', 'test_data', '1oir_conf.mol')

        mol1 = Chem.MolFromMolFile(file1)
        mol2 = Chem.MolFromMolFile(file2)

        rmsd = rdMolAlign.AlignMol(mol2, mol1)
        self.failUnless(feq(rmsd, 0.6578))

        file3 = os.path.join(RDConfig.RDBaseDir,'Code','GraphMol',
                             'MolAlign', 'test_data', '1oir_trans.mol')
        mol3 = Chem.MolFromMolFile(file3)
        conf2 = mol2.GetConformer()
        conf3 = mol3.GetConformer()

        for i in range(mol2.GetNumAtoms()):
            self.failUnless(lstFeq(conf2.GetAtomPosition(i), conf3.GetAtomPosition(i)))

        rmsd, trans = rdMolAlign.GetAlignmentTransform(mol2, mol1)
        self.failUnless(feq(rmsd, 0.6578))
コード例 #4
0
 def __get_transformation_matrix(self, model, mapping):
     return rdMolAlign.GetAlignmentTransform(self.get_mol(), self.get_mol(model), atomMap=tuple(mapping.items()))[1]
コード例 #5
0
def get_rmsd(mol):
    rms, tmat = rdMolAlign.GetAlignmentTransform(mol, mol, prbCid=0, refCid=1)
    return rms