1
2
3
4
5
6
7
8
9
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 import types
21
23 """ calculates the characteristic polynomial for a molecular graph
24
25 if mat is not passed in, the molecule's Weighted Adjacency Matrix will
26 be used.
27
28 The approach used is the Le Verrier-Faddeev-Frame method described
29 in _Chemical Graph Theory, 2nd Edition_ by Nenad Trinajstic (CRC Press,
30 1992), pg 76.
31
32 """
33 nAtoms = mol.GetNumAtoms()
34 if mat is None:
35
36
37 pass
38 else:
39 A = mat
40 I = 1.*numpy.identity(nAtoms)
41 An = A
42 res = numpy.zeros(nAtoms+1,numpy.float)
43 res[0] = 1.0
44 for n in xrange(1,nAtoms+1):
45 res[n] = 1./n*numpy.trace(An)
46 Bn = An - res[n]*I
47 An = numpy.dot(A,Bn)
48
49 res[1:] *= -1
50 return res
51