rdkit.Chem.Graphs

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

# Source Code for Module rdkit.Chem.Graphs

     1  # $Id$
     2  #
     3  # Copyright (C) 2001-2008 greg landrum and rational discovery llc
     4  #
     5  #   @@ All Rights Reserved @@
     6  #  This file is part of the RDKit.
     7  #  The contents are covered by the terms of the BSD license
     8  #  which is included in the file license.txt, found at the root
     9  #  of the RDKit source tree.
    10  #
    11  """ Python functions for manipulating molecular graphs
    12
    13  In theory much of the functionality in here should be migrating into the
    14  C/C++ codebase.
    15
    16  """
    17  import numpy
    18  from rdkit import Chem
    19  from rdkit import DataStructs
    20  from rdkit.six.moves import xrange
    21  import types
    22
    23
    24 -def CharacteristicPolynomial(mol, mat=None):
    25    """ calculates the characteristic polynomial for a molecular graph
    26
    27      if mat is not passed in, the molecule's Weighted Adjacency Matrix will
    28      be used.
    29
    30      The approach used is the Le Verrier-Faddeev-Frame method described
    31      in _Chemical Graph Theory, 2nd Edition_ by Nenad Trinajstic (CRC Press,
    32      1992), pg 76.
    33
    34    """
    35    nAtoms = mol.GetNumAtoms()
    36    if mat is None:
    37      # FIX: complete this:
    38      #A = mol.GetWeightedAdjacencyMatrix()
    39      pass
    40    else:
    41      A = mat
    42    I = 1. * numpy.identity(nAtoms)
    43    An = A
    44    res = numpy.zeros(nAtoms + 1, numpy.float)
    45    res[0] = 1.0
    46    for n in xrange(1, nAtoms + 1):
    47      res[n] = 1. / n * numpy.trace(An)
    48      Bn = An - res[n] * I
    49      An = numpy.dot(A, Bn)
    50
    51    res[1:] *= -1
    52    return res
    53