1
2
3
4
5
6
7
8
9 import sys
10
11 from rdkit import Chem
12 from rdkit.Chem.rdfiltercatalog import *
13
14
16 """FilterMatcher - This class allows creation of Python based
17 filters. Subclass this class to create a Filter useable
18 in a FilterCatalogEntry
19
20 Simple Example:
21
22 from rdkit.Chem import rdMolDescriptors
23 class MWFilter(FilterMatcher):
24 def __init__(self, minMw, maxMw):
25 FilterMatcher.__init__(self, "MW violation")
26 self.minMw = minMw
27 self.maxMw = maxMw
28
29 def IsValid(self):
30 return True
31
32 def HasMatch(self, mol):
33 mw = rdMolDescriptors.CalcExactMolWt(mol)
34 return not self.minMw <= mw <= self.maxMw
35 """
36
37 - def __init__(self, name="Unamed FilterMatcher"):
40
42 """Return True if the filter matches the molecule"""
43 raise NotImplementedError("Need to implement HasMatch(mol) in a subclass of %s",
44 self.__class__.__name__)
45
47 """GetMatches(mol, matchVect) -> returns True if the filter matches
48 (By default, this calls HasMatch and does not modify matchVect)
49
50 matchVect is a vector of FilterMatch's which hold the matching
51 filter and the matched query_atom, mol_atom pairs if applicable.
52 To append to this vector:
53 v = MatchTypeVect()
54 v.append(IntPair( query_atom_idx, mol_atom_idx ) )
55 match = FilterMatch(self, v)
56 matchVect.append( match )
57 """
58 return self.HasMatch(mol)
59
61 """Must override this function"""
62 raise NotImplementedError("IsValid must be implemented in a subclass of %s",
63 self.__class__.__name__)
64
67