Package rdkit :: Package Chem :: Package EState :: Module Fingerprinter

[hide private]
[frames] | no frames]

# Source Code for Module rdkit.Chem.EState.Fingerprinter

     1  ## Automatically adapted for numpy.oldnumeric Jun 27, 2008 by -c
     2
     3  # $Id$
     4  #
     5  #  Copyright (C) 2002-2006  greg Landrum and Rational Discovery LLC
     6  #
     7  #   @@ All Rights Reserved @@
     8  #  This file is part of the RDKit.
     9  #  The contents are covered by the terms of the BSD license
    10  #  which is included in the file license.txt, found at the root
    11  #  of the RDKit source tree.
    12  #
    13  """  EState fingerprinting
    14
    15  """
    16  from __future__ import print_function
    17  import numpy
    18  from rdkit.Chem.EState import EStateIndices
    19  from rdkit.Chem.EState import AtomTypes
    20
    21 -def FingerprintMol(mol):
    22    """ generates the EState fingerprints for the molecule
    23
    24    Concept from the paper: Hall and Kier JCICS _35_ 1039-1045 (1995)
    25
    26    two numeric arrays are returned:
    27      The first (of ints) contains the number of times each possible atom type is hit
    28      The second (of floats) contains the sum of the EState indices for atoms of
    29        each type.
    30
    31    """
    32    if AtomTypes.esPatterns is None:
    33      AtomTypes.BuildPatts()
    34    esIndices = EStateIndices(mol)
    35
    36    nPatts = len(AtomTypes.esPatterns)
    37    counts = numpy.zeros(nPatts,numpy.int)
    38    sums = numpy.zeros(nPatts,numpy.float)
    39
    40    for i,(name,pattern) in enumerate(AtomTypes.esPatterns):
    41      matches = mol.GetSubstructMatches(pattern,uniquify=1)
    42      counts[i] = len(matches)
    43      for match in matches:
    44        sums[i] += esIndices[match[0]]
    45    return counts,sums
    46
    47
    48  if __name__ == '__main__':
    49    from rdkit import Chem
    50    smis = ['CC','CCC','c1[nH]cnc1CC(N)C(O)=O','NCCc1ccc(O)c(O)c1']
    51    for smi in smis:
    52      m = Chem.MolFromSmiles(smi)
    53      print(smi,Chem.MolToSmiles(m))
    54      types = AtomTypes.TypeAtoms(m)
    55      for i in range(m.GetNumAtoms()):
    56        print('%d %4s: %s'%(i+1,m.GetAtomWithIdx(i).GetSymbol(),str(types[i])))
    57      es = EStateIndices(m)
    58      counts,sums = FingerprintMol(m)
    59      for i in range(len(AtomTypes.esPatterns)):
    60        if counts[i]:
    61          name,patt = AtomTypes.esPatterns[i]
    62          print('%6s, % 2d, % 5.4f'%(name,counts[i],sums[i]))
    63      for i in range(len(es)):
    64        print('% 2d, % 5.4f'%(i+1,es[i]))
    65      print('--------')
    66