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