def __init__( self, pubchem_templates_path: str = '', general_templates_path: str = config.general_templates) -> None: """ Initialize component which does the ligand depiction. If Nones is provided as parameters just the defalt RDKit functionality is going to be used. Args: pubchem_templates_path (str, optional): Defaults to ''. Path to the library with 2D structures downloaded from PubChem. Use `setup_pubchem_library` for this task. general_templates_path (str, optional): Defaults to config.general_templates (supplied with the pdbeccdutils). Path to the library with general templates to be used for depicting ligand e.g. porphyrin rings. """ self.coordgen_params = rdCoordGen.CoordGenParams() self.coordgen_params.coordgenScaling = 50 / 1.5 self.coordgen_params.templateFileDir = config.coordgen_templates self.pubchem_templates = pubchem_templates_path if os.path.isdir( pubchem_templates_path) else '' self.templates: Dict[str, rdkit.Chem.rdchem.Mol] = OrderedDict() if os.path.isdir(general_templates_path): for k in sorted(os.listdir(general_templates_path)): template = self._load_template( os.path.join(general_templates_path, k)) template_name = k.split('.')[0] self.templates[template_name] = template
def test_template3(self): # the easier way, test lifetime... template = Chem.MolFromSmiles('C1OCOCOCOCCCNCCC1') mol = Chem.MolFromSmiles('C1OCOCOCOCCCNC(OC(=O)C2CC2)CC1') rdCoordGen.AddCoords(template) template2 = Chem.Mol(template) ps = rdCoordGen.CoordGenParams() ps.SetTemplateMol(template2) template2 = None ps.dbg_useFixed = True rdCoordGen.AddCoords(mol,ps) self.assertTrue(compareConfs(mol.GetConformer(),template.GetConformer(),mol.GetSubstructMatch(template)))
def test_template2(self): # the easier way... template = Chem.MolFromSmiles('C1OCOCOCOCCCNCCC1') template.SetProp("_Name",'template') mol = Chem.MolFromSmiles('C1OCOCOCOCCCNC(OC(=O)C2CC2)CC1') mol.SetProp("_Name","mol") rdCoordGen.AddCoords(template) ps = rdCoordGen.CoordGenParams() ps.SetTemplateMol(template) ps.dbg_useFixed = True rdCoordGen.AddCoords(mol,ps) self.assertTrue(compareConfs(mol.GetConformer(),template.GetConformer(),mol.GetSubstructMatch(template)))
def test_template1(self): template = Chem.MolFromSmiles('C1OCOCOCOCCCNCCC1') template.SetProp("_Name",'template') mol = Chem.MolFromSmiles('C1OCOCOCOCCCNC(OC(=O)C2CC2)CC1') mol.SetProp("_Name","mol") rdCoordGen.AddCoords(template) rdCoordGen.AddCoords(mol) self.assertFalse(compareConfs(mol.GetConformer(),template.GetConformer(),mol.GetSubstructMatch(template))) match = mol.GetSubstructMatch(template) mapd = dict() for i,aid in enumerate(match): p = template.GetConformer().GetAtomPosition(i) mapd[aid] = Geometry.Point2D(p.x,p.y) ps = rdCoordGen.CoordGenParams() ps.SetCoordMap(mapd) ps.dbg_useFixed = True rdCoordGen.AddCoords(mol,ps) self.assertTrue(compareConfs(mol.GetConformer(),template.GetConformer(),mol.GetSubstructMatch(template)))
def testMinimizeOnly(self): m = Chem.MolFromMolBlock(''' Mrv2014 08052005392D 0 0 0 0 0 999 V3000 M V30 BEGIN CTAB M V30 COUNTS 14 15 0 0 0 M V30 BEGIN ATOM M V30 1 C -1.4287 -1.4523 0 0 M V30 2 C -2.9638 -1.5752 0 0 M V30 3 C -3.8377 -0.3072 0 0 M V30 4 C -3.1766 1.0837 0 0 M V30 5 C -1.6416 1.2066 0 0 M V30 6 C -0.7675 -0.0614 0 0 M V30 7 C 0.7675 0.0614 0 0 M V30 8 C 1.6416 -1.2066 0 0 M V30 9 C 0.9804 -2.5975 0 0 M V30 10 N 3.1766 -1.0837 0 0 M V30 11 C 3.8377 0.3072 0 0 M V30 12 C 2.9638 1.5752 0 0 M V30 13 C 1.4287 1.4523 0 0 M V30 14 F -0.5548 -2.7203 0 0 M V30 END ATOM M V30 BEGIN BOND M V30 1 2 1 2 M V30 2 1 2 3 M V30 3 2 3 4 M V30 4 1 4 5 M V30 5 2 5 6 M V30 6 1 6 7 M V30 7 2 7 8 M V30 8 1 8 9 M V30 9 1 8 10 M V30 10 2 10 11 M V30 11 1 11 12 M V30 12 2 12 13 M V30 13 1 6 1 M V30 14 1 13 7 M V30 15 1 1 14 M V30 END BOND M V30 END CTAB M END ''') ref = Chem.MolFromMolBlock(''' RDKit 2D 14 15 0 0 0 0 0 0 0 0999 V2000 -1.5379 -1.4859 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -3.1218 -1.5958 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -3.9595 -0.2554 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -3.2641 1.1663 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -1.6778 1.2217 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -0.7941 -0.0886 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 0.7983 0.0383 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 1.7524 -1.2209 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 1.1246 -2.6443 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 3.3306 -1.0787 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 3.9439 0.3747 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 3.0337 1.6656 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 1.4617 1.4692 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -0.6924 -2.7917 0.0000 F 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 0 2 3 1 0 3 4 2 0 4 5 1 0 5 6 2 0 6 7 1 0 7 8 2 0 8 9 1 0 8 10 1 0 10 11 2 0 11 12 1 0 12 13 2 0 6 1 1 0 13 7 1 0 1 14 1 0 M END''') ps = rdCoordGen.CoordGenParams() ps.minimizeOnly = True m2 = Chem.Mol(m) rdCoordGen.AddCoords(m2, ps) self.assertGreater(rdMolAlign.AlignMol(m, ref), 0.1) self.assertLess(rdMolAlign.AlignMol(m2, ref), 0.1)
def testMinimizeOnly(self): m = Chem.MolFromMolBlock(''' Mrv2014 03252113022D 14 15 0 0 0 0 999 V2000 -0.7654 -0.7780 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -1.5877 -0.8439 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -2.0559 -0.1646 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -1.7017 0.5805 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -0.8794 0.6464 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -0.4112 -0.0329 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 0.4112 0.0329 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 0.8794 -0.6464 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 0.7771 -1.4237 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 1.7017 -0.5805 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 2.0559 0.1646 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 1.5877 0.8439 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 0.7654 0.7780 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -0.7654 -1.6519 0.0000 F 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 0 0 0 0 2 3 1 0 0 0 0 3 4 2 0 0 0 0 4 5 1 0 0 0 0 5 6 2 0 0 0 0 6 7 1 0 0 0 0 7 8 2 0 0 0 0 8 9 1 0 0 0 0 8 10 1 0 0 0 0 10 11 2 0 0 0 0 11 12 1 0 0 0 0 12 13 2 0 0 0 0 6 1 1 0 0 0 0 13 7 1 0 0 0 0 1 14 1 0 0 0 0 M END ''') ref = Chem.MolFromMolBlock(''' RDKit 2D 14 15 0 0 0 0 0 0 0 0999 V2000 -0.5957 -0.8221 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -1.4185 -0.8441 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -1.8520 -0.1434 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -1.4595 0.5814 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -0.6368 0.6072 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -0.2063 -0.0955 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 0.2087 -0.0625 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 0.7102 -0.7158 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 0.4040 -1.4774 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 1.5259 -0.6099 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 1.8401 0.1516 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 1.3405 0.8062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 0.5252 0.6981 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 -0.1735 -1.5240 0.0000 F 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 0 2 3 1 0 3 4 2 0 4 5 1 0 5 6 2 0 6 7 1 0 7 8 2 0 8 9 1 0 8 10 1 0 10 11 2 0 11 12 1 0 12 13 2 0 6 1 1 0 13 7 1 0 1 14 1 0 M END ''') ps = rdCoordGen.CoordGenParams() ps.minimizeOnly = True m2 = Chem.Mol(m) rdCoordGen.AddCoords(m2, ps) self.assertGreater(rdMolAlign.AlignMol(m, ref), 0.1) self.assertLess(rdMolAlign.AlignMol(m2, ref), 0.1)