|
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 |
|
|
|
|
|
|
13
|
|
|
from rdkit.Chem import rdMolDescriptors |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
from .decorators import requires_h_filled, requires_h_depleted |
|
|
|
|
|
|
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 |
|
|
|
|
|
|
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 |
|
|
|
|
|
|
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): |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
# TODO: memoize |
|
|
|
|
|
|
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', |
|
|
|
|
|
|
144
|
|
|
'unsaturation_index', 'hydrophilic_index', 'mcgowan_volume', |
|
|
|
|
|
|
145
|
|
|
'DESCRIPTORS'] |
|
|
|
|
|
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.