1
2
3
4
5
6
7 """ exposes a class for matching fragments of molecules.
8
9 The class exposes a simple API:
10
11 If you want a matcher that hits C=O, you'd do:
12 >>> p = FragmentMatcher()
13 >>> p.Init('C=O')
14
15 you can then match with:
16 >>> mol = Chem.MolFromSmiles('CC(=O)O')
17 >>> p.HasMatch(mol)
18 1
19 >>> p.HasMatch(Chem.MolFromSmiles('CC(C)C'))
20 0
21
22 information about the matches:
23 >>> len(p.GetMatches(Chem.MolFromSmiles('CC=O')))
24 1
25 >>> len(p.GetMatches(Chem.MolFromSmiles('O=CC=O')))
26 2
27
28 or, you can add exclusion fragments (defined as smarts) with:
29 >>> p.AddExclusion('c1ccccc1')
30
31 now the matcher will not hit anything that has a benzene ring.
32 >>> p.HasMatch(Chem.MolFromSmiles('CC=O'))
33 1
34 >>> p.HasMatch(Chem.MolFromSmiles('c1ccccc1CC=O'))
35 0
36
37
38 """
39 from rdkit import Chem
40
41
44 self._onPatt = None
45 self._offPatts = []
46
51
56
57
69
74
79
81 if self._onPatt is None:
82 return None
83 return self._onPatt.GetBondWithIdx(idx)
84
85
86
87
88
89
91 import doctest,sys
92 return doctest.testmod(sys.modules["__main__"])
93
94 if __name__ == '__main__':
95 import sys
96 failed,tried = _test()
97 sys.exit(failed)
98