1
2
3
4
5
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 from Numeric import *
14 import Chem
15 import DataStructs
16 import types
17
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
32
33 pass
34 else:
35 A = mat
36 I = 1.*identity(nAtoms)
37 An = A
38 res = zeros(nAtoms+1,Float)
39 res[0] = 1.0
40 for n in xrange(1,nAtoms+1):
41 res[n] = 1./n*trace(An)
42 Bn = An - res[n]*I
43 An = matrixmultiply(A,Bn)
44
45 res[1:] *= -1
46 return res
47