Completed
Push — master ( 5b00a3...5fddd3 )
by Rich
14:42
created

modified_burden_matrix()   B

Complexity

Conditions 1

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 30
rs 8.8571
cc 1
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
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...
13
14
from .decorators import (requires_h_depleted, requires_bo_amat,
0 ignored issues
show
Configuration introduced by
Unable to import 'decorators' (invalid syntax (<string>, line 107))

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
                         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.
0 ignored issues
show
Bug introduced by
A suspicious escape sequence \p was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
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
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _bo_amat was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name n does not conform to the argument 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...
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)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _bo_amat was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
81
    res[np.diag_indices_from(res)] = diag
82
83
    return res
84
85
86
def bme(mol, L=15):
0 ignored issues
show
Coding Style Naming introduced by
The name L does not conform to the argument 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...
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.
0 ignored issues
show
Bug introduced by
A suspicious escape sequence \c was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Bug introduced by
A suspicious escape sequence \d was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Bug introduced by
A suspicious escape sequence \p was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
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
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _bo_amat was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
125
    diag = mol.atoms.atomic_number + 0.1 * mol._degrees + \
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _degrees was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
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)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _bcutm was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
151
    return mat
152
153
154
def _bcutp(mol, n=1):
0 ignored issues
show
Coding Style Naming introduced by
The name n does not conform to the argument 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 n seems to be unused.
Loading history...
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)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _bcutm was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
176
    return mat
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...