rdkit.Chem.FilterCatalog

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
    15 -class FilterMatcher(PythonFilterMatcher):
    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"):
    38      self.name = name
    39      PythonFilterMatcher.__init__(self, self)
    40
    41 -  def HasMatch(self, mol):
    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
    46 -  def GetMatches(self, mol, matchVect):
    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
    60 -  def IsValid(self, mol):
    61      """Must override this function"""
    62      raise NotImplementedError("IsValid must be implemented in a subclass of %s",
    63                                self.__class__.__name__)
    64
    65 -  def GetName(self):
    66      return self.name
    67