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

hydrophilic_factor()   B

Complexity

Conditions 5

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 23
rs 8.2508
cc 5
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.properties
8
9
Molecular properties 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
from rdkit.Chem import rdMolDescriptors
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...
14
15
from .decorators import requires_h_filled, requires_h_depleted
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...
16
17
18
def molar_refractivity(mol):
19
20
    """ The molar refractivity.
21
22
        Args:
23
        mol (skchem.Mol):
24
            The molecule for which to calculate the descriptor.
25
26
    Returns:
27
        float
28
    """
29
30
    return rdMolDescriptors.CalcCrippenDescriptors(mol)[1]
31
32
33
def a_log_p(mol):
34
35
    """ Ghose-Crippen octanol-water partition coefficient.
36
37
    Args:
38
        mol (skchem.Mol):
39
            The molecule for which to calculate the descriptor.
40
41
    Returns:
42
        float
43
    """
44
    return rdMolDescriptors.CalcCrippenDescriptors(mol)[0]
45
46
47
def a_log_p2(mol):
48
    # TODO: memoize
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
49
    """ Square of the Ghose-Crippen octanol-water partition coefficient.
50
51
    Args:
52
        mol (skchem.Mol):
53
            The molecule for which to calculate the descriptor.
54
55
    Returns:
56
        float
57
    """
58
59
    return log_p(mol) ** 2
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'log_p'
Loading history...
60
61
62
@requires_h_depleted
63
def unsaturation_count(mol):
64
65
    """ Unsaturation count according to dProperties.
66
67
    Args:
68
        mol (skchem.Mol):
69
            The molecule for which to calculate the descriptor.
70
71
    Returns:
72
        float
73
    """
74
75
    return np.log2(1 + len(mol.bonds) - sum(mol.bonds.order == 1))
76
77
78
def unsaturation_index(mol):
79
80
    """ Unsaturation index according to dProperties.
81
82
    Args:
83
        mol (skchem.Mol):
84
            The molecule for which to calculate the descriptor.
85
86
    Returns:
87
        float
88
    """
89
90
    return np.log2(1 + sum(mol.bonds.order) - len(mol.bonds))
91
92
93
@requires_h_filled
94
def hydrophilic_factor(x):
0 ignored issues
show
Coding Style Naming introduced by
The name x 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...
95
96
    # TODO: memoize
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
97
    """ Hydrophilicity factor.
98
99
    Args:
100
        mol (skchem.Mol):
101
            The molecule for which to calculate the descriptor.
102
103
    Returns:
104
        float
105
    """
106
107
    n_heavy = sum(x.atoms.atomic_number != 1)
108
    n_carbs = sum(x.atoms.atomic_number == 6)
109
    n_hbonds = sum(1 for atom in x.atoms
110
                   for neighbor in atom.neighbours()
111
                   if atom.atomic_number in (7, 8, 16) and
112
                   neighbor.atomic_number == 1)
113
114
    return (1 + n_hbonds) * np.log2(1 + n_hbonds) + \
115
           n_carbs * np.log2(1/n_heavy) / n_heavy + np.sqrt(n_hbonds)/ n_heavy
116
117
118
def mcgowan_volume(mol):
119
120
    """ McGowan's characteristic volume.
121
122
    Args:
123
        mol (skchem.Mol):
124
            The molecule for which to calculate the descriptor.
125
126
    Returns:
127
        float
128
    """
129
130
    return mol.atoms.mcgowan.sum() - 6.56 * len(mol.bonds)
131
132
133
DESCRIPTORS = {
134
    'mol_ref': molar_refractivity,
135
    'a_log_p': a_log_p,
136
    'a_log_p2': a_log_p2,
137
    'unsat_count': unsaturation_count,
138
    'unsat': unsaturation_index,
139
    'hy': hydrophilic_factor,
140
    'mcgowan_volume': mcgowan_volume
141
}
142
143
__all__ = ['molar_refractivity', 'log_p', 'log_p2', 'unsaturation_count',
0 ignored issues
show
Bug introduced by
Undefined variable name 'log_p' in __all__
Loading history...
Bug introduced by
Undefined variable name 'log_p2' in __all__
Loading history...
144
           'unsaturation_index', 'hydrophilic_index', 'mcgowan_volume',
0 ignored issues
show
Bug introduced by
Undefined variable name 'hydrophilic_index' in __all__
Loading history...
145
           'DESCRIPTORS']
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...