def testPreprocess(self): testFile = os.path.join(RDConfig.RDCodeDir, 'Chem', 'SimpleEnum', 'test_data', 'boronic1.rxn') rxn = rdChemReactions.ReactionFromRxnFile(testFile) rxn.Initialize() res = rdChemReactions.PreprocessReaction(rxn) self.assertEquals(res, (0, 0, 2, 1, (((0, 'halogen.bromine.aromatic'), ), ((1, 'boronicacid'), ))))
def testGitHub1868(self): fileN = os.path.join(self.dataDir, 'v3k.AmideBond.rxn') for i in range(100): _rxn = rdChemReactions.ReactionFromRxnFile(fileN) _rxn.Initialize() _reacts = [Chem.MolToSmarts(r) for r in _rxn.GetReactants()] _prods = [Chem.MolToSmarts(p) for p in _rxn.GetProducts()]
def test3MDLParsers(self): fileN = os.path.join(self.dataDir, 'AmideBond.rxn') rxna = rdChemReactions.ReactionFromRxnFile(fileN) print("*" * 44) print(fileN) print(rxna) for rxn in [rxna, rdChemReactions.ChemicalReaction(rxna)]: self.assertTrue(rxn) self.assertFalse(rxn._getImplicitPropertiesFlag()) self.assertTrue(rxn.GetNumReactantTemplates() == 2) self.assertTrue(rxn.GetNumProductTemplates() == 1) reacts = (Chem.MolFromSmiles('C(=O)O'), Chem.MolFromSmiles('N')) ps = rxn.RunReactants(reacts) self.assertTrue(len(ps) == 1) self.assertTrue(len(ps[0]) == 1) self.assertTrue(ps[0][0].GetNumAtoms() == 3) with open(fileN, 'r') as rxnF: rxnBlock = rxnF.read() rxn = rdChemReactions.ReactionFromRxnBlock(rxnBlock) self.assertTrue(rxn) self.assertTrue(rxn.GetNumReactantTemplates() == 2) self.assertTrue(rxn.GetNumProductTemplates() == 1) reacts = (Chem.MolFromSmiles('C(=O)O'), Chem.MolFromSmiles('N')) ps = rxn.RunReactants(reacts) self.assertTrue(len(ps) == 1) self.assertTrue(len(ps[0]) == 1) self.assertTrue(ps[0][0].GetNumAtoms() == 3)
def getReaction(rfile): rxn = rdChemReactions.ReactionFromRxnFile(rfile) smi = rdChemReactions.ReactionToSmiles(rxn) return storeReaction(smi, rfile), smi
def create_reaction_image(rxn_path, image_path): from rdkit.Chem import rdChemReactions as Reactions react = Reactions.ReactionFromRxnFile(rxn_path) from rdkit.Chem.Draw import ReactionToImage image = ReactionToImage(react, subImgSize=(150, 150)) image.save(image_path)