Chem.Graphs

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

# Source Code for Module Chem.Graphs

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