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