Package rdkit :: Package Chem :: Module FilterCatalog
[hide private]
[frames] | no frames]

Source Code for Module rdkit.Chem.FilterCatalog

 1  #  Copyright (C) 2015 Novartis Institute for BioMedical Research 
 2  # 
 3  #   @@ All Rights Reserved @@ 
 4  #  This file is part of the RDKit. 
 5  #  The contents are covered by the terms of the BSD license 
 6  #  which is included in the file license.txt, found at the root 
 7  #  of the RDKit source tree. 
 8  # 
 9  import sys 
10   
11  from rdkit import Chem 
12  from rdkit.Chem.rdfiltercatalog import * 
13   
14 -class FilterMatcher(PythonFilterMatcher):
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"):
36 self.name = name 37 PythonFilterMatcher.__init__(self, self)
38
39 - def HasMatch(self, mol):
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
44 - def GetMatches(self, mol, matchVect):
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
58 - def IsValid(self, mol):
59 """Must override this function""" 60 raise NotImplementedError("IsValid must be implemented in a subclass of %s", 61 self.__class__.__name__)
62
63 - def GetName(self):
64 return self.name
65