/
ABCIndex.py
78 lines (55 loc) · 1.57 KB
/
ABCIndex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
r"""
References
* :cite:`furtula_atom-bond_2016`
"""
import numpy as np
from ._base import Descriptor
from ._graph_matrix import DistanceMatrix
__all__ = ('ABCIndex', 'ABCGGIndex',)
class ABCIndexBase(Descriptor):
__slots__ = ()
@classmethod
def preset(cls):
yield cls()
explicit_hydrogens = False
def as_key(self):
return self.__class__, ()
def __str__(self):
return self.__class__.__name__[:-5]
rtype = float
class ABCIndex(ABCIndexBase):
r"""atom-bond connectivity indez descriptor.
"""
__slots__ = ()
@staticmethod
def _each_bond(bond):
du = bond.GetBeginAtom().GetDegree()
dv = bond.GetEndAtom().GetDegree()
return np.sqrt((du + dv - 2.0) / (du * dv))
def calculate(self):
return np.float(
np.sum(
self._each_bond(bond)
for bond in self.mol.GetBonds()
)
)
class ABCGGIndex(ABCIndexBase):
r"""Graovac-Ghorbani atom-bond connectivity index descriptor.
"""
__slots__ = ()
def dependencies(self):
return {'D': DistanceMatrix(self.explicit_hydrogens)}
@staticmethod
def _each_bond(bond, D):
u = bond.GetBeginAtomIdx()
v = bond.GetEndAtomIdx()
nu = np.sum(D[u, :] < D[v, :])
nv = np.sum(D[v, :] < D[u, :])
return np.sqrt((nu + nv - 2.0) / (nu * nv))
def calculate(self, D):
return np.float(
np.sum(
self._each_bond(bond, D)
for bond in self.mol.GetBonds()
)
)