mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
add substructure searches of Mols using MolBundles from Python (#1603)
This commit is contained in:
committed by
Brian Kelley
parent
28f8421644
commit
0775cf0da5
@@ -22,6 +22,7 @@
|
||||
#include <GraphMol/RDKitBase.h>
|
||||
#include <GraphMol/QueryOps.h>
|
||||
#include <GraphMol/MolPickler.h>
|
||||
#include <GraphMol/MolBundle.h>
|
||||
#include <GraphMol/Substruct/SubstructMatch.h>
|
||||
#include <boost/python/iterator.hpp>
|
||||
#include <boost/python/copy_non_const_reference.hpp>
|
||||
@@ -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<std::string>,
|
||||
(python::arg("self"), python::arg("key"), python::arg("val"),
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user