diff --git a/Code/GraphMol/Wrap/Mol.cpp b/Code/GraphMol/Wrap/Mol.cpp index 23375227c..30fe25e8e 100644 --- a/Code/GraphMol/Wrap/Mol.cpp +++ b/Code/GraphMol/Wrap/Mol.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -374,8 +375,8 @@ struct mol_wrapper { " - useQueryQueryMatches: use query-query matching logic\n\n" " RETURNS: True or False\n") .def("GetSubstructMatch", - (PyObject * (*)(const ROMol &m, const ROMol &query, bool, bool)) - GetSubstructMatch, + (PyObject * (*)(const ROMol &m, const ROMol &query, bool, + bool))GetSubstructMatch, (python::arg("self"), python::arg("query"), python::arg("useChirality") = false, python::arg("useQueryQueryMatches") = false), @@ -398,7 +399,7 @@ struct mol_wrapper { .def("GetSubstructMatches", (PyObject * (*)(const ROMol &m, const ROMol &query, bool, bool, - bool, unsigned int)) GetSubstructMatches, + bool, unsigned int))GetSubstructMatches, (python::arg("self"), python::arg("query"), python::arg("uniquify") = true, python::arg("useChirality") = false, @@ -434,6 +435,29 @@ struct mol_wrapper { " this molecule that matches the first atom in the " "query.\n") + .def("HasSubstructMatch", + (bool (*)(const ROMol &m, const MolBundle &query, bool, bool, + bool))HasSubstructMatch, + (python::arg("self"), python::arg("query"), + python::arg("recursionPossible") = true, + python::arg("useChirality") = false, + python::arg("useQueryQueryMatches") = false)) + .def("GetSubstructMatch", + (PyObject * (*)(const ROMol &m, const MolBundle &query, bool, + bool))GetSubstructMatch, + (python::arg("self"), python::arg("query"), + python::arg("useChirality") = false, + python::arg("useQueryQueryMatches") = false)) + + .def("GetSubstructMatches", + (PyObject * (*)(const ROMol &m, const MolBundle &query, bool, bool, + bool, unsigned int))GetSubstructMatches, + (python::arg("self"), python::arg("query"), + python::arg("uniquify") = true, + python::arg("useChirality") = false, + python::arg("useQueryQueryMatches") = false, + python::arg("maxMatches") = 1000)) + // properties .def("SetProp", MolSetProp, (python::arg("self"), python::arg("key"), python::arg("val"), diff --git a/Code/GraphMol/Wrap/rough_test.py b/Code/GraphMol/Wrap/rough_test.py index f03ead86d..e48f26c45 100644 --- a/Code/GraphMol/Wrap/rough_test.py +++ b/Code/GraphMol/Wrap/rough_test.py @@ -4397,6 +4397,29 @@ M END self.assertEqual(len(b.GetSubstructMatches(Chem.MolFromSmiles('C[C@](Cl)(F)C[C@@H](F)(Br)'),useChirality=True)[0]),8) self.assertEqual(len(b.GetSubstructMatches(Chem.MolFromSmiles('C[C@@](Cl)(F)C[C@@H](F)(Br)'),useChirality=False)[0]),8) + + def testMolBundles2(self): + b = Chem.MolBundle() + smis = ('Fc1c(Cl)cccc1','Fc1cc(Cl)ccc1','Fc1ccc(Cl)cc1') + for smi in smis: + b.AddMol(Chem.MolFromSmiles(smi)) + self.assertEqual(len(b),3) + self.assertEqual(b.Size(),3) + self.failUnless(Chem.MolFromSmiles('Fc1c(Cl)cccc1').HasSubstructMatch(b)) + self.failUnless(Chem.MolFromSmiles('Fc1cc(Cl)ccc1').HasSubstructMatch(b)) + self.failUnless(Chem.MolFromSmiles('Fc1c(Cl)cccc1C').HasSubstructMatch(b)) + self.failUnless(Chem.MolFromSmiles('Fc1cc(Cl)ccc1C').HasSubstructMatch(b)) + self.failIf(Chem.MolFromSmiles('Fc1c(Br)cccc1').HasSubstructMatch(b)) + + self.assertEqual(len(Chem.MolFromSmiles('Fc1c(Cl)cccc1').GetSubstructMatch(b)),8) + self.assertEqual(len(Chem.MolFromSmiles('Fc1c(Cl)cccc1').GetSubstructMatches(b)),1) + self.assertEqual(len(Chem.MolFromSmiles('Fc1c(Cl)cccc1').GetSubstructMatches(b)[0]),8) + self.assertEqual(len(Chem.MolFromSmiles('Fc1ccc(Cl)cc1').GetSubstructMatches(b)),1) + self.assertEqual(len(Chem.MolFromSmiles('Fc1ccc(Cl)cc1').GetSubstructMatches(b,uniquify=False)),2) + + self.assertEqual(len(Chem.MolFromSmiles('Fc1c(C)cccc1').GetSubstructMatch(b)),0) + self.assertEqual(len(Chem.MolFromSmiles('Fc1c(C)cccc1').GetSubstructMatches(b)),0) + if __name__ == '__main__': if "RDTESTCASE" in os.environ: suite = unittest.TestSuite()