Completed
Push — master ( 360284...546a0f )
by Rich
05:22
created

local_dipole_index()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.125

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
c 1
b 0
f 1
dl 0
loc 5
ccs 1
cts 2
cp 0.5
crap 1.125
rs 9.4285
1
#! /usr/bin/env python
2
#
3
# Copyright (C) 2016 Rich Lewis <[email protected]>
4
# License: 3-clause BSD
5
6 1
"""
7
# skchem.features.descriptors.charge
8
9
Charge descriptors for scikit-chem.
10
"""
11
12 1
from collections import OrderedDict
13
14 1
import numpy as np
0 ignored issues
show
Configuration introduced by
The import numpy could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
15 1
from rdkit.Chem import rdPartialCharges
0 ignored issues
show
Configuration introduced by
The import rdkit.Chem could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
16
17 1
from .caching import cache
18 1
from .fundamentals import geometric_matrix, adjacency_matrix
19
20
# TODO: consider using population analysis for 'proper' charge indices
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
21
22
23 1
def hstackable(res):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
24
    return res if isinstance(res, np.ndarray) else np.array([res])
25
26
27 1
@cache
28
def gasteiger_charges(mol):
29
30
    """ The gasteiger partial charges for the atoms of the molecule.
31
32
    Args:
33
        mol (skchem.Mol):
34
            The molecule for which to calculate the descriptors.
35
36
    Returns:
37
        float
38
    """
39
40
    rdPartialCharges.ComputeGasteigerCharges(mol)
41
    return mol.atoms.props.pop('_GasteigerCharge')
42
43
44 1
@cache.inject(gasteiger_charges)
45
def max_partial_charge(mol, g_charges):
0 ignored issues
show
Unused Code introduced by
The argument mol seems to be unused.
Loading history...
46
47
    """ The maximum gasteiger partial charge of all atoms.
48
49
    Args:
50
        mol (skchem.Mol):
51
            The molecule for which to calculate the descriptor.
52
53
    Returns:
54
        float
55
    """
56
57
    return g_charges.max()
58
59
60 1
@cache
61 1
@cache.inject(gasteiger_charges)
62
def min_partial_charge(mol, g_charges):
0 ignored issues
show
Unused Code introduced by
The argument mol seems to be unused.
Loading history...
63
64
    """ The minimum gasteiger partial charge of all atoms.
65
66
    Args:
67
        mol (skchem.Mol):
68
            The molecule for which to calculate the descriptor.
69
70
    Returns:
71
        float
72
    """
73
74
    return g_charges.min()
75
76
77 1
@cache.inject(gasteiger_charges)
78
def total_positive_charge(mol, g_charges):
0 ignored issues
show
Unused Code introduced by
The argument mol seems to be unused.
Loading history...
79
80
    """ The total positive gasteiger partial charges of all atoms.
81
82
    Args:
83
        mol (skchem.Mol):
84
            The molecule for which to calculate the descriptor.
85
86
    Returns:
87
        float
88
    """
89
90
91
    return g_charges[g_charges > 0].sum()
92
93
94 1
@cache.inject(gasteiger_charges)
95
def total_negative_charge(mol, g_charges):
0 ignored issues
show
Unused Code introduced by
The argument mol seems to be unused.
Loading history...
96
97
    """ The total negative gasteiger partial charges of all atoms.
98
99
    Args:
100
        mol (skchem.Mol):
101
            The molecule for which to calculate the descriptor.
102
103
    Returns:
104
        float
105
    """
106
107
    return g_charges[g_charges > 0].sum()
108
109
110 1
@cache.inject(gasteiger_charges)
111
def total_absolute_charge(mol, g_charges):
0 ignored issues
show
Unused Code introduced by
The argument mol seems to be unused.
Loading history...
112
113
    """ The total absolute gasteiger partial charges of all atoms.
114
115
    This may be considered the electronic charge index (ECI).
116
117
    Args:
118
        mol (skchem.Mol):
119
            The molecule for which to calculate the descriptor.
120
121
    Returns:
122
        float
123
    """
124
    return np.abs(g_charges).sum()
125
126
127 1
@cache.inject(gasteiger_charges)
128
def mean_absolute_charge(mol, g_charges):
0 ignored issues
show
Unused Code introduced by
The argument mol seems to be unused.
Loading history...
129
130
    """ The mean absolute gasteiger partial charges of all atoms.
131
132
    This may be considered the 'charge polarization'.
133
134
    Args:
135
        mol (skchem.Mol):
136
            The molecule for which to calculate the descriptor.
137
138
    Returns:
139
        float
140
    """
141
142
    return np.abs(g_charges).mean()
143
144
145 1
@cache.inject(gasteiger_charges)
146
def total_squared_charge(mol, g_charges):
0 ignored issues
show
Unused Code introduced by
The argument mol seems to be unused.
Loading history...
147
148
    """ The total of the squared  gasteiger partial charges of all atoms.
149
150
    Args:
151
        mol (skchem.Mol):
152
            The molecule for which to calculate the descriptor.
153
154
    Returns:
155
        float
156
    """
157
158
    return np.power(g_charges, 2).sum()
159
160
161 1
@cache.inject(gasteiger_charges, adjacency_matrix)
162
def submolecular_polarity_parameter(mol, g_charges, a_mat):
0 ignored issues
show
Unused Code introduced by
The argument mol seems to be unused.
Loading history...
163
164
    """ The submolecular polarity parameter.
165
166
    This is the greatest difference in partial charges of bonded atoms in the
167
    molecule.
168
169
    Args:
170
        mol (skchem.Mol):
171
            The molecule for which to calculate the descriptor.
172
173
    Returns:
174
        float
175
    """
176
177
    return (np.abs(g_charges - g_charges[:, np.newaxis]) * a_mat).max()
178
179
180 1
@cache
181 1
@cache.inject(gasteiger_charges, geometric_matrix)
182 1
def _topographic_electron_matrix(mol, g_charges, g_mat, conformer=-1):
0 ignored issues
show
Unused Code introduced by
The argument conformer seems to be unused.
Loading history...
Unused Code introduced by
The argument mol seems to be unused.
Loading history...
183
184
    """ The matrix of topographic charge interactions.
185
186
    Args:
187
        mol (skchem.Mol):
188
            The molecule for which to calculate the descriptor.
189
190
    Returns:
191
        float
192
    """
193
    g_mat = g_mat ** -2
194
    np.fill_diagonal(g_mat, 0)
195
    return np.abs(g_charges - g_charges[:, np.newaxis]) * g_mat
196
197
198 1
@cache
199 1
@cache.inject(_topographic_electron_matrix)
200
def topographic_electronic_descriptor(mol, tem):
0 ignored issues
show
Coding Style Naming introduced by
The name topographic_electronic_descriptor does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Unused Code introduced by
The argument mol seems to be unused.
Loading history...
201
202
    """ The topolographic electronic descriptor.
203
204
    The sum of the differences in charges of all atoms in the molecule, scaled
205
    by the inverse square of their distances, i.e. a  measure of the coulombic
206
    interactions.
207
208
    Args:
209
        mol (skchem.Mol):
210
            The molecule for which to calculate the descriptor.
211
212
    Returns:
213
        float
214
    """
215
    return 0.5 * tem.sum()
216
217
218 1
@cache
219 1
@cache.inject(_topographic_electron_matrix, adjacency_matrix)
220
def br_topographic_electronic_descriptor(mol, tem, a_mat):
0 ignored issues
show
Coding Style Naming introduced by
The name br_topographic_electronic_descriptor does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Unused Code introduced by
The argument mol seems to be unused.
Loading history...
221
222
    """ The bond restricted topographic electronic descriptor.
223
224
    As the topographic electronic descriptor, except restricted only to bonded
225
    atoms.
226
227
    Args:
228
        mol (skchem.Mol):
229
            The molecule for which to calculate the descriptor.
230
231
    Returns:
232
        float
233
234
    See Also:
235
        skchem.features.descriptors.charge.topographic_electronic_descriptor
236
    """
237
238
239
    return 0.5 * (tem * a_mat).sum()
240
241
242 1
@cache.inject(topographic_electronic_descriptor, min_partial_charge)
243
def pcw_topological_electronic_index(mol, tem, q_min):
0 ignored issues
show
Coding Style Naming introduced by
The name pcw_topological_electronic_index does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Unused Code introduced by
The argument mol seems to be unused.
Loading history...
244
245
    """ Partial charge weighted topological electronic index.
246
247
    The topographic electronic index, scaled by the maximum negative partial
248
    charge in the molecule.
249
250
    Args:
251
        mol (skchem.Mol):
252
            The molecule for which to calculate the descriptor.
253
254
    Returns:
255
        float
256
257
    See Also:
258
        skchem.features.descriptors.charge.topographic_electronic_descriptor
259
    """
260
261
    return np.abs(tem / q_min)
262
263
264 1
@cache.inject(br_topographic_electronic_descriptor, min_partial_charge)
265
def br_pcw_topological_electronic_index(mol, brtem, q_min):
0 ignored issues
show
Coding Style Naming introduced by
The name br_pcw_topological_electronic_index does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Unused Code introduced by
The argument mol seems to be unused.
Loading history...
266
267
    """ Bond restricted partial charge weighted topological electronic index.
268
269
    The partial charge weighted topological electronic index, with the
270
    summation restricted to bonded atom pairs.
271
272
    Args:
273
        mol (skchem.Mol):
274
            The molecule for which to calculate the descriptor.
275
276
    Returns:
277
        float
278
279
    See Also:
280
        skchem.features.descriptors.charge.topographic_electronic_descriptor
281
    """
282
    return np.abs(brtem / q_min)
283
284
285 1
@cache.inject(gasteiger_charges, adjacency_matrix)
286
def local_dipole_index(mol, g_charges, a_mat):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The argument mol seems to be unused.
Loading history...
287
288
    # cancel out 0.5s
289
    return (a_mat * np.abs(g_charges - g_charges[:, np.newaxis])).sum() / a_mat.sum()
290
291
292 1
@cache.inject(gasteiger_charges)
293
def min_abs_partial_charge(mol, g_charges):
0 ignored issues
show
Unused Code introduced by
The argument mol seems to be unused.
Loading history...
294
295
    """ The minimum absolute gasteiger partial charge of all atoms.
296
297
    Args:
298
        mol (skchem.Mol):
299
            The molecule for which to calculate the descriptor.
300
301
    Returns:
302
        float
303
    """
304
305
    return np.abs(g_charges).min()
306
307
308 1
@cache.inject(gasteiger_charges)
309
def max_abs_partial_charge(mol, g_charges):
0 ignored issues
show
Unused Code introduced by
The argument mol seems to be unused.
Loading history...
310
311
    """ The maximum absolute gasteiger partial charge of all atoms.
312
313
    Args:
314
        mol (skchem.Mol):
315
            The molecule for which to calculate the descriptor.
316
317
    Returns:
318
        float
319
    """
320
321
    return np.abs(g_charges).max()
322
323
324 1
all_feats = OrderedDict(
0 ignored issues
show
Coding Style Naming introduced by
The name all_feats does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
325
    (('max_partial_charge', max_partial_charge),
326
     ('min_partial_charge', min_partial_charge),
327
     ('total_positive_charge', total_positive_charge),
328
     ('total_negative_charge', total_negative_charge),
329
     ('total_absolute_charge', total_absolute_charge),
330
     ('total_squared_charge', total_squared_charge),
331
     ('submolecular_polarity_parameter', submolecular_polarity_parameter),
332
     ('topographic_electronic_descriptor', topographic_electronic_descriptor),
333
     ('br_topographic_electronic_descriptor',
334
      br_topographic_electronic_descriptor),
335
     ('pcw_topological_electronic_index', pcw_topological_electronic_index),
336
     ('br_pcw_topological_electronic_index',
337
      br_pcw_topological_electronic_index),
338
     ('local_dipole_index', local_dipole_index),
339
     ('min_abs_partial_charge', min_abs_partial_charge),
340
     ('max_abs_partial_charge', max_abs_partial_charge))
341
)
342
343
344 1
__all__ = ['gasteiger_charges', 'max_partial_charge', 'min_partial_charge',
345
           'total_positive_charge', 'total_negative_charge',
346
           'total_absolute_charge', 'total_squared_charge',
347
           'submolecular_polarity_parameter',
348
           'topographic_electronic_descriptor',
349
           'br_topographic_electronic_descriptor',
350
           'pcw_topological_electronic_index',
351
           'br_pcw_topological_electronic_index',
352
           'local_dipole_index',
353
           'min_abs_partial_charge', 'max_abs_partial_charge']
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...