def test3MDLParsers(self): fileN = os.path.join(self.dataDir, 'AmideBond.rxn') rxn = rdChemReactions.ReactionFromRxnFile(fileN) self.failUnless(rxn) self.failIf(rxn._getImplicitPropertiesFlag()) self.failUnless(rxn.GetNumReactantTemplates() == 2) self.failUnless(rxn.GetNumProductTemplates() == 1) reacts = (Chem.MolFromSmiles('C(=O)O'), Chem.MolFromSmiles('N')) ps = rxn.RunReactants(reacts) self.failUnless(len(ps) == 1) self.failUnless(len(ps[0]) == 1) self.failUnless(ps[0][0].GetNumAtoms() == 3) rxnBlock = file(fileN, 'r').read() rxn = rdChemReactions.ReactionFromRxnBlock(rxnBlock) self.failUnless(rxn) self.failUnless(rxn.GetNumReactantTemplates() == 2) self.failUnless(rxn.GetNumProductTemplates() == 1) reacts = (Chem.MolFromSmiles('C(=O)O'), Chem.MolFromSmiles('N')) ps = rxn.RunReactants(reacts) self.failUnless(len(ps) == 1) self.failUnless(len(ps[0]) == 1) self.failUnless(ps[0][0].GetNumAtoms() == 3)
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 testV3000Reactions(self): reaction = rdChemReactions.ReactionFromSmarts( '[cH:1]1[cH:2][cH:3][cH:4][cH:5][c:6]1-[Br].[#6:7]B(O)O>>[cH:1]1[cH:2][cH:3][cH:4][cH:5][c:6]1-[#6:7]' ) self.assertIsNotNone(reaction) mb1 = rdChemReactions.ReactionToRxnBlock(reaction, forceV3000=True) mb2 = rdChemReactions.ReactionToV3KRxnBlock(reaction) self.assertEqual(mb1, mb2) reaction2 = rdChemReactions.ReactionFromRxnBlock(mb1) self.assertIsNotNone(reaction2) self.assertEqual(reaction.GetNumReactantTemplates(), reaction2.GetNumReactantTemplates())
def test20CheckCopyConstructedReactionAtomProps(self): RLABEL = "_MolFileRLabel" amine_rxn = '$RXN\n\n ISIS 090220091541\n\n 2 1\n$MOL\n\n -ISIS- 09020915412D\n\n 3 2 0 0 0 0 0 0 0 0999 V2000\n -2.9083 -0.4708 0.0000 R# 0 0 0 0 0 0 0 0 0 1 0 0\n -2.3995 -0.1771 0.0000 C 0 0 0 0 0 0 0 0 0 2 0 0\n -2.4042 0.4125 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 1 0 0 0 0\n 2 3 2 0 0 0 0\nV 2 aldehyde\nM RGP 1 1 1\nM END\n$MOL\n\n -ISIS- 09020915412D\n\n 2 1 0 0 0 0 0 0 0 0999 V2000\n 2.8375 -0.2500 0.0000 R# 0 0 0 0 0 0 0 0 0 3 0 0\n 3.3463 0.0438 0.0000 N 0 0 0 0 0 0 0 0 0 4 0 0\n 1 2 1 0 0 0 0\nV 2 amine\nM RGP 1 1 2\nM END\n$MOL\n\n -ISIS- 09020915412D\n\n 4 3 0 0 0 0 0 0 0 0999 V2000\n 13.3088 0.9436 0.0000 C 0 0 0 0 0 0 0 0 0 2 0 0\n 13.8206 1.2321 0.0000 R# 0 0 0 0 0 0 0 0 0 1 0 0\n 13.3028 0.3561 0.0000 N 0 0 0 0 0 0 0 0 0 4 0 0\n 12.7911 0.0676 0.0000 R# 0 0 0 0 0 0 0 0 0 3 0 0\n 1 3 1 0 0 0 0\n 1 2 1 0 0 0 0\n 3 4 1 0 0 0 0\nM RGP 2 2 1 4 2\nM END\n' rxn = rdChemReactions.ReactionFromRxnBlock(amine_rxn) res = [] for atom in rxn.GetReactantTemplate(0).GetAtoms(): if atom.HasProp(RLABEL): res.append((atom.GetIdx(), atom.GetProp(RLABEL))) rxn2 = rdChemReactions.ChemicalReaction(rxn) res2 = [] for atom in rxn2.GetReactantTemplate(0).GetAtoms(): if atom.HasProp(RLABEL): res2.append((atom.GetIdx(), atom.GetProp(RLABEL))) self.assertEquals(res, res2)
def test21CheckRawIters(self): RLABEL = "_MolFileRLabel" amine_rxn = '$RXN\n\n ISIS 090220091541\n\n 2 1\n$MOL\n\n -ISIS- 09020915412D\n\n 3 2 0 0 0 0 0 0 0 0999 V2000\n -2.9083 -0.4708 0.0000 R# 0 0 0 0 0 0 0 0 0 1 0 0\n -2.3995 -0.1771 0.0000 C 0 0 0 0 0 0 0 0 0 2 0 0\n -2.4042 0.4125 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 1 0 0 0 0\n 2 3 2 0 0 0 0\nV 2 aldehyde\nM RGP 1 1 1\nM END\n$MOL\n\n -ISIS- 09020915412D\n\n 2 1 0 0 0 0 0 0 0 0999 V2000\n 2.8375 -0.2500 0.0000 R# 0 0 0 0 0 0 0 0 0 3 0 0\n 3.3463 0.0438 0.0000 N 0 0 0 0 0 0 0 0 0 4 0 0\n 1 2 1 0 0 0 0\nV 2 amine\nM RGP 1 1 2\nM END\n$MOL\n\n -ISIS- 09020915412D\n\n 4 3 0 0 0 0 0 0 0 0999 V2000\n 13.3088 0.9436 0.0000 C 0 0 0 0 0 0 0 0 0 2 0 0\n 13.8206 1.2321 0.0000 R# 0 0 0 0 0 0 0 0 0 1 0 0\n 13.3028 0.3561 0.0000 N 0 0 0 0 0 0 0 0 0 4 0 0\n 12.7911 0.0676 0.0000 R# 0 0 0 0 0 0 0 0 0 3 0 0\n 1 3 1 0 0 0 0\n 1 2 1 0 0 0 0\n 3 4 1 0 0 0 0\nM RGP 2 2 1 4 2\nM END\n' rxn = rdChemReactions.ReactionFromRxnBlock(amine_rxn) reactants = rxn.GetReactants() self.assertEquals(len(reactants), rxn.GetNumReactantTemplates()) products = rxn.GetProducts() self.assertEquals(len(products), rxn.GetNumProductTemplates()) agents = rxn.GetAgents() self.assertEquals(len(agents), rxn.GetNumAgentTemplates()) for i in range(rxn.GetNumReactantTemplates()): p = rxn.GetReactantTemplate(i) mb1 = Chem.MolToMolBlock(p) mb2 = Chem.MolToMolBlock(reactants[i]) self.assertEquals(mb1, mb2)
def test4ErrorHandling(self): self.failUnlessRaises( ValueError, lambda x='[C:1](=[O:2])Q.[N:3]>>[C:1](=[O:2])[N:3]': rdChemReactions.ReactionFromSmarts(x)) self.failUnlessRaises( ValueError, lambda x='[C:1](=[O:2])O.[N:3]>>[C:1](=[O:2])[N:3]Q': rdChemReactions.ReactionFromSmarts(x)) self.failUnlessRaises( ValueError, lambda x='[C:1](=[O:2])O.[N:3]>>[C:1](=[O:2])[N:3]>>CC': rdChemReactions.ReactionFromSmarts(x)) block = """$RXN ISIS 082120061354 3 1 $MOL -ISIS- 08210613542D 3 2 0 0 0 0 0 0 0 0999 V2000 -1.4340 -0.6042 0.0000 C 0 0 0 0 0 0 0 0 0 2 0 0 -0.8639 -0.9333 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 -1.4340 0.0542 0.0000 O 0 0 0 0 0 0 0 0 0 1 0 0 1 2 1 0 0 0 0 1 3 2 0 0 0 0 M END $MOL -ISIS- 08210613542D 1 0 0 0 0 0 0 0 0 0999 V2000 2.2125 -0.7833 0.0000 N 0 0 0 0 0 0 0 0 0 3 0 0 M END $MOL -ISIS- 08210613542D 3 2 0 0 0 0 0 0 0 0999 V2000 9.5282 -0.8083 0.0000 N 0 0 0 0 0 0 0 0 0 3 0 0 8.9579 -0.4792 0.0000 C 0 0 0 0 0 0 0 0 0 2 0 0 8.9579 0.1792 0.0000 O 0 0 0 0 0 0 0 0 0 1 0 0 1 2 1 0 0 0 0 2 3 2 0 0 0 0 M END """ self.failUnlessRaises( ValueError, lambda x=block: rdChemReactions.ReactionFromRxnBlock(x)) block = """$RXN ISIS 082120061354 2 1 $MOL -ISIS- 08210613542D 4 2 0 0 0 0 0 0 0 0999 V2000 -1.4340 -0.6042 0.0000 C 0 0 0 0 0 0 0 0 0 2 0 0 -0.8639 -0.9333 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 -1.4340 0.0542 0.0000 O 0 0 0 0 0 0 0 0 0 1 0 0 1 2 1 0 0 0 0 1 3 2 0 0 0 0 M END $MOL -ISIS- 08210613542D 1 0 0 0 0 0 0 0 0 0999 V2000 2.2125 -0.7833 0.0000 N 0 0 0 0 0 0 0 0 0 3 0 0 M END $MOL -ISIS- 08210613542D 3 2 0 0 0 0 0 0 0 0999 V2000 9.5282 -0.8083 0.0000 N 0 0 0 0 0 0 0 0 0 3 0 0 8.9579 -0.4792 0.0000 C 0 0 0 0 0 0 0 0 0 2 0 0 8.9579 0.1792 0.0000 O 0 0 0 0 0 0 0 0 0 1 0 0 1 2 1 0 0 0 0 2 3 2 0 0 0 0 M END """ #self.failUnlessRaises(ValueError,lambda x=block:rdChemReactions.ReactionFromRxnBlock(x)) block = """$RXN
def test_rxnblock_removehs(self): rxnblock = """$RXN Dummy 0 Dummy 0123456789 1 1 $MOL Dummy 01234567892D 10 10 0 0 0 0 999 V2000 7.0222 -11.1783 0.0000 C 0 0 0 0 0 0 0 0 0 1 0 0 8.0615 -11.7783 0.0000 O 0 0 0 0 0 0 0 0 0 2 0 0 7.0222 -9.6783 0.0000 N 0 0 0 0 0 0 0 0 0 3 0 0 5.7231 -8.9283 0.0000 C 0 0 0 0 0 0 0 0 0 4 0 0 5.7231 -7.7283 0.0000 A 0 0 0 0 0 0 0 0 0 5 0 0 4.4242 -9.6783 0.0000 C 0 0 0 0 0 0 0 0 0 6 0 0 4.4242 -11.1783 0.0000 C 0 0 0 0 0 0 0 0 0 7 0 0 3.3849 -11.7783 0.0000 A 0 0 0 0 0 0 0 0 0 8 0 0 5.7231 -11.9283 0.0000 N 0 0 0 0 0 0 0 0 0 9 0 0 5.7231 -13.1094 0.0000 H 0 0 1 2 2 0 0 0 8 1 3 1 0 0 0 8 3 4 2 0 0 0 8 4 5 1 0 0 0 2 4 6 1 0 0 0 8 6 7 2 0 0 0 8 7 8 1 0 0 0 2 7 9 1 0 0 0 8 9 1 1 0 0 0 8 9 10 1 0 M SUB 1 9 2 M END $MOL Dummy 01234567892D 9 9 0 0 0 0 999 V2000 17.0447 -11.1783 0.0000 C 0 0 0 0 0 0 0 0 0 1 0 0 18.0840 -11.7783 0.0000 O 0 0 0 0 0 0 0 0 0 2 0 0 17.0447 -9.6783 0.0000 N 0 0 0 0 0 0 0 0 0 3 0 0 15.7457 -8.9283 0.0000 C 0 0 0 0 0 0 0 0 0 4 0 0 15.7457 -7.7283 0.0000 A 0 0 0 0 0 0 0 0 0 5 0 0 14.4467 -9.6783 0.0000 C 0 0 0 0 0 0 0 0 0 6 0 0 14.4467 -11.1783 0.0000 C 0 0 0 0 0 0 0 0 0 7 0 0 13.4074 -11.7783 0.0000 A 0 0 0 0 0 0 0 0 0 8 0 0 15.7457 -11.9283 0.0000 N 0 0 0 0 0 0 0 0 0 9 0 0 1 2 1 0 0 0 8 1 3 1 0 0 0 8 3 4 2 0 0 0 8 4 5 1 0 0 0 2 4 6 1 0 0 0 8 6 7 2 0 0 0 8 7 8 1 0 0 0 2 7 9 1 0 0 0 8 9 1 2 0 0 0 8 M END """ mol = Chem.MolFromSmiles("c1(=O)nc([Cl])cc([F])[nH]1") rxn = rdChemReactions.ReactionFromRxnBlock(rxnblock) self.assertIsNotNone(rxn) prods = rxn.RunReactants((mol, )) # if the explicit hydrogen is not removed and the reactant template # is not sanitized, the reactant template is not aromatic and our # aromatic reactant won't match self.assertEqual(len(prods), 0) rxn = rdChemReactions.ReactionFromRxnBlock(rxnblock, removeHs=True, sanitize=True) self.assertIsNotNone(rxn) prods = rxn.RunReactants((mol, )) self.assertEqual(len(prods), 2)