1
|
|
|
#! /usr/bin/env python |
2
|
|
|
# |
3
|
|
|
# Copyright (C) 2015-Rich Lewis <[email protected]> |
4
|
|
|
# License: 3-clause BSD |
5
|
|
|
|
6
|
1 |
|
""" |
7
|
|
|
## skchem.descriptors.physicochemical |
8
|
|
|
|
9
|
|
|
Physicochemical descriptors and associated functions are defined. |
10
|
|
|
|
11
|
|
|
""" |
12
|
|
|
|
13
|
1 |
|
from rdkit.Chem import Descriptors |
|
|
|
|
14
|
1 |
|
import pandas as pd |
|
|
|
|
15
|
1 |
|
import numpy as np |
|
|
|
|
16
|
|
|
|
17
|
1 |
|
from ..base import Transformer, Featurizer |
18
|
1 |
|
from ..utils import camel_to_snail |
19
|
|
|
|
20
|
1 |
|
DESCRIPTORS = {camel_to_snail(s): f for (s, f) in Descriptors.descList} |
21
|
|
|
|
22
|
|
|
|
23
|
1 |
|
class PhysicochemicalFeaturizer(Transformer, Featurizer): |
24
|
|
|
|
25
|
|
|
""" Physicochemical descriptor generator using RDKit descriptor """ |
26
|
|
|
|
27
|
1 |
|
def __init__(self, features='all', **kwargs): |
28
|
|
|
|
29
|
|
|
""" Create a physicochemical descriptor generator. |
30
|
|
|
|
31
|
|
|
Args: |
32
|
|
|
descriptors (list<(str, func)> or 'all'): |
33
|
|
|
Descriptors to calculate, or if 'all', use all descriptors.""" |
34
|
|
|
|
35
|
|
|
super(PhysicochemicalFeaturizer, self).__init__(**kwargs) |
36
|
|
|
|
37
|
|
|
self.features = features |
38
|
|
|
|
39
|
1 |
|
@property |
40
|
|
|
def features(self): |
|
|
|
|
41
|
|
|
return self._features |
42
|
|
|
|
43
|
1 |
View Code Duplication |
@features.setter |
|
|
|
|
44
|
|
|
def features(self, features): |
|
|
|
|
45
|
|
|
if features == 'all': |
46
|
|
|
features = DESCRIPTORS |
47
|
|
|
elif isinstance(features, str): |
48
|
|
|
features = {features: DESCRIPTORS[features]} |
49
|
|
|
elif isinstance(features, list): |
50
|
|
|
features = {feature: DESCRIPTORS[feature] for feature in features} |
51
|
|
|
elif isinstance(features, (dict, pd.Series)): |
52
|
|
|
features = features |
53
|
|
|
else: |
54
|
|
|
raise NotImplementedError('Cannot use features {}'.format(features)) |
55
|
|
|
|
56
|
|
|
self._features = pd.Series(features) |
|
|
|
|
57
|
|
|
self._features.index.name = 'physicochemical_features' |
58
|
|
|
|
59
|
1 |
|
@property |
60
|
|
|
def name(self): |
|
|
|
|
61
|
|
|
return 'physchem' |
62
|
|
|
|
63
|
1 |
|
@property |
64
|
|
|
def columns(self): |
65
|
|
|
return self.features.index |
66
|
|
|
|
67
|
1 |
|
def _transform_mol(self, mol): |
68
|
|
|
res = [] |
69
|
|
|
for (n, f) in self.features.iteritems(): |
|
|
|
|
70
|
|
|
try: |
71
|
|
|
res.append(f(mol)) |
72
|
|
|
except ValueError: |
73
|
|
|
return res.append(np.NaN) |
74
|
|
|
|
75
|
|
|
return np.array(res) |
76
|
|
|
|
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__.py
files in your module folders. Make sure that you place one file in each sub-folder.