|
1
|
|
|
#! /usr/bin/env python |
|
2
|
|
|
# |
|
3
|
|
|
# Copyright (C) 2016 Rich Lewis <[email protected]> |
|
4
|
|
|
# License: 3-clause BSD |
|
5
|
|
|
|
|
6
|
|
|
""" |
|
7
|
|
|
# skchem.features.descriptors.spectral |
|
8
|
|
|
|
|
9
|
|
|
Spectral descriptors for scikit-chem. |
|
10
|
|
|
""" |
|
11
|
|
|
|
|
12
|
|
|
import numpy as np |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
from .decorators import (requires_h_depleted, requires_bo_amat, |
|
|
|
|
|
|
15
|
|
|
requires_h_filled, requires_degrees) |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
@requires_h_depleted |
|
19
|
|
|
@requires_bo_amat |
|
20
|
|
|
def original_burden_matrix(mol): |
|
21
|
|
|
|
|
22
|
|
|
""" The original burden matrix. |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
$$ [B]_{ii} = Z_i |
|
25
|
|
|
[B]_{ij} = \frac{\pi^*}{10} $$ |
|
26
|
|
|
|
|
27
|
|
|
Where $Z_i$ is the atomic number of the $i$th atom and $\pi^*_{ij}$ is the |
|
28
|
|
|
conventional bond order between the $i$th and $j$th atoms. |
|
29
|
|
|
|
|
30
|
|
|
Args: |
|
31
|
|
|
mol (skchem.Mol): |
|
32
|
|
|
The molecule for which to calculate the modified burden matrix. |
|
33
|
|
|
|
|
34
|
|
|
Returns: |
|
35
|
|
|
np.ndarray |
|
36
|
|
|
|
|
37
|
|
|
References: |
|
38
|
|
|
Molecular Descriptors for Cheminformatics p720 |
|
39
|
|
|
""" |
|
40
|
|
|
res = mol._bo_amat / 10 |
|
|
|
|
|
|
41
|
|
|
res[np.diag_indices_from(res)] = mol.atoms.atomic_number |
|
42
|
|
|
res[res == 0] = 0.001 |
|
43
|
|
|
return res |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
def burden(mol, n=1): |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
""" Spectral descriptors using the original burden matrix. """ |
|
49
|
|
|
|
|
50
|
|
|
eigs = np.linalg.eigvals(original_burden_matrix(mol)) |
|
51
|
|
|
eigs.sort() |
|
52
|
|
|
eigs = eigs[::-1] |
|
53
|
|
|
diff = n - len(eigs) |
|
54
|
|
|
print(diff, eigs) |
|
55
|
|
|
if diff > 0: |
|
56
|
|
|
res = np.pad(eigs, (diff, diff), 'edge') |
|
57
|
|
|
return np.concatenate((res[diff:], res[:diff])) |
|
58
|
|
|
else: |
|
59
|
|
|
return np.array(eigs[:n] + eigs[-n:]) |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
@requires_h_filled |
|
63
|
|
|
@requires_bo_amat |
|
64
|
|
|
def burden_matrix(mol, diag='electronegativity'): |
|
65
|
|
|
|
|
66
|
|
|
""" The Burden matrix, with variable diagonal elements. |
|
67
|
|
|
|
|
68
|
|
|
Args: |
|
69
|
|
|
mol (skchem.Mol): |
|
70
|
|
|
The molecule for which to calculate the modified burden matrix. |
|
71
|
|
|
|
|
72
|
|
|
Returns: |
|
73
|
|
|
np.ndarray |
|
74
|
|
|
|
|
75
|
|
|
References: |
|
76
|
|
|
Molecular Descriptors for Cheminformatics p720""" |
|
77
|
|
|
|
|
78
|
|
|
diag = getattr(mol.atoms, diag) |
|
79
|
|
|
|
|
80
|
|
|
res = np.sqrt(mol._bo_amat) |
|
|
|
|
|
|
81
|
|
|
res[np.diag_indices_from(res)] = diag |
|
82
|
|
|
|
|
83
|
|
|
return res |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
def bme(mol, L=15): |
|
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
""" The L highest Burden modified eigenvalues of the burden matrix. |
|
89
|
|
|
|
|
90
|
|
|
Args: |
|
91
|
|
|
|
|
92
|
|
|
""" |
|
93
|
|
|
|
|
94
|
|
|
res = np.zeros(L) |
|
95
|
|
|
eigs = np.linalg.eigvals(burden_matrix(mol)) |
|
96
|
|
|
res[:len(eigs)] = eigs |
|
97
|
|
|
return np.sort(eigs)[:-L-1:-1] |
|
98
|
|
|
|
|
99
|
|
|
@requires_h_depleted |
|
100
|
|
|
@requires_bo_amat |
|
101
|
|
|
@requires_degrees |
|
102
|
|
|
def modified_burden_matrix(mol): |
|
103
|
|
|
|
|
104
|
|
|
""" The modified burden matrix, Q. |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
$$ [Q]_{ii} = Z_i + 0.1 \cdot \delta_i + 0.01 \cdot n_i^{\pi} |
|
107
|
|
|
[Q]_{ij} = 0.4 / d_{ij}$$ |
|
108
|
|
|
|
|
109
|
|
|
Where Z_i is the atomic number of $i$th atom, $\delta_i$ is the vertex |
|
110
|
|
|
degree, $n_i^\pi$ is the number of $\pi$ electrons and d_{ij} is the |
|
111
|
|
|
topological distance between $i$th and $j$th atoms |
|
112
|
|
|
|
|
113
|
|
|
Args: |
|
114
|
|
|
mol (skchem.Mol): |
|
115
|
|
|
The molecule for which to calculate the modified burden matrix. |
|
116
|
|
|
|
|
117
|
|
|
Returns: |
|
118
|
|
|
np.ndarray |
|
119
|
|
|
|
|
120
|
|
|
References: |
|
121
|
|
|
Molecular Descriptors for Cheminformatics p720 |
|
122
|
|
|
""" |
|
123
|
|
|
|
|
124
|
|
|
res = 0.4 / mol._bo_amat |
|
|
|
|
|
|
125
|
|
|
diag = mol.atoms.atomic_number + 0.1 * mol._degrees + \ |
|
|
|
|
|
|
126
|
|
|
0.01 * mol.atoms.n_pi_electrons |
|
127
|
|
|
res[np.diag_indices_from(res)] = diag |
|
128
|
|
|
return res |
|
129
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
def _bcutm(mol): |
|
132
|
|
|
|
|
133
|
|
|
""" BCUT descriptors for atomic masses. |
|
134
|
|
|
|
|
135
|
|
|
Args: |
|
136
|
|
|
mol (skchem.Mol): |
|
137
|
|
|
The molecule for which to calculate the modified burden matrix. |
|
138
|
|
|
|
|
139
|
|
|
Returns: |
|
140
|
|
|
np.ndarray |
|
141
|
|
|
|
|
142
|
|
|
Note: |
|
143
|
|
|
These memoize. |
|
144
|
|
|
|
|
145
|
|
|
References: |
|
146
|
|
|
Molecular Descriptors for Cheminformatics p720 |
|
147
|
|
|
""" |
|
148
|
|
|
|
|
149
|
|
|
mat = burden_matrix(mol, mol.atoms.atomic_mass) |
|
150
|
|
|
mat._bcutm = np.linalg.eigvals(mat) |
|
|
|
|
|
|
151
|
|
|
return mat |
|
152
|
|
|
|
|
153
|
|
|
|
|
154
|
|
|
def _bcutp(mol, n=1): |
|
|
|
|
|
|
155
|
|
|
|
|
156
|
|
|
""" BCUT descriptors using atomic polarizability. |
|
157
|
|
|
|
|
158
|
|
|
Args: |
|
159
|
|
|
mol (skchem.Mol): |
|
160
|
|
|
The molecule for which to calculate the modified burden matrix. |
|
161
|
|
|
n (skchem.Mol): |
|
162
|
|
|
The number of highest and lowest eigenvalues to use. |
|
163
|
|
|
|
|
164
|
|
|
Returns: |
|
165
|
|
|
np.ndarray |
|
166
|
|
|
|
|
167
|
|
|
Note: |
|
168
|
|
|
These memoize. |
|
169
|
|
|
|
|
170
|
|
|
References: |
|
171
|
|
|
Molecular Descriptors for Cheminformatics p720 |
|
172
|
|
|
""" |
|
173
|
|
|
|
|
174
|
|
|
mat = burden_matrix(mol, mol.atoms.atomic_mass) |
|
175
|
|
|
mat._bcutm = np.linalg.eigvals(mat) |
|
|
|
|
|
|
176
|
|
|
return mat |
|
|
|
|
|
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.pyfiles in your module folders. Make sure that you place one file in each sub-folder.