|
1
|
|
|
#! /usr/bin/env python |
|
2
|
|
|
# |
|
3
|
|
|
# Copyright (C) 2007-2009 Rich Lewis <[email protected]> |
|
4
|
|
|
# License: 3-clause BSD |
|
5
|
|
|
|
|
6
|
|
|
""" |
|
7
|
|
|
## skchem.descriptors.fingerprints |
|
8
|
|
|
|
|
9
|
|
|
Fingerprinting classes and associated functions are defined. |
|
10
|
|
|
""" |
|
11
|
|
|
|
|
12
|
|
|
from functools import wraps |
|
13
|
|
|
|
|
14
|
|
|
import pandas as pd |
|
|
|
|
|
|
15
|
|
|
from rdkit.Chem import DataStructs, GetDistanceMatrix |
|
|
|
|
|
|
16
|
|
|
from rdkit.Chem.rdMolDescriptors import (GetMorganFingerprint, |
|
|
|
|
|
|
17
|
|
|
GetHashedMorganFingerprint, |
|
18
|
|
|
GetAtomPairFingerprint, |
|
19
|
|
|
GetHashedAtomPairFingerprint, |
|
20
|
|
|
GetTopologicalTorsionFingerprint, |
|
21
|
|
|
GetHashedTopologicalTorsionFingerprint, |
|
22
|
|
|
GetMACCSKeysFingerprint, |
|
23
|
|
|
GetFeatureInvariants, |
|
24
|
|
|
GetConnectivityInvariants) |
|
25
|
|
|
from rdkit.Chem.rdReducedGraphs import GetErGFingerprint |
|
|
|
|
|
|
26
|
|
|
from rdkit.Chem.rdmolops import RDKFingerprint |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
import numpy as np |
|
|
|
|
|
|
29
|
|
|
import skchem |
|
30
|
|
|
|
|
31
|
|
|
def skchemize(func, columns=None, *args, **kwargs): |
|
32
|
|
|
""" |
|
33
|
|
|
|
|
34
|
|
|
transform an RDKit fingerprinting function to work well with pandas |
|
35
|
|
|
|
|
36
|
|
|
>>> from rdkit import Chem |
|
37
|
|
|
>>> import skchem |
|
38
|
|
|
>>> from skchem.descriptors import skchemize |
|
39
|
|
|
>>> from skchem.core import Mol |
|
40
|
|
|
>>> f = skchemize(Chem.RDKFingerprint) |
|
41
|
|
|
>>> m = Mol.from_smiles('c1ccccc1') |
|
42
|
|
|
>>> f(m) |
|
43
|
|
|
0 0 |
|
44
|
|
|
1 0 |
|
45
|
|
|
2 0 |
|
46
|
|
|
3 0 |
|
47
|
|
|
4 0 |
|
48
|
|
|
5 0 |
|
49
|
|
|
6 0 |
|
50
|
|
|
7 0 |
|
51
|
|
|
8 0 |
|
52
|
|
|
9 0 |
|
53
|
|
|
10 0 |
|
54
|
|
|
11 0 |
|
55
|
|
|
12 0 |
|
56
|
|
|
13 0 |
|
57
|
|
|
14 0 |
|
58
|
|
|
15 0 |
|
59
|
|
|
16 0 |
|
60
|
|
|
17 0 |
|
61
|
|
|
18 0 |
|
62
|
|
|
19 0 |
|
63
|
|
|
20 0 |
|
64
|
|
|
21 0 |
|
65
|
|
|
22 0 |
|
66
|
|
|
23 0 |
|
67
|
|
|
24 0 |
|
68
|
|
|
25 0 |
|
69
|
|
|
26 0 |
|
70
|
|
|
27 0 |
|
71
|
|
|
28 0 |
|
72
|
|
|
29 0 |
|
73
|
|
|
.. |
|
74
|
|
|
2018 0 |
|
75
|
|
|
2019 0 |
|
76
|
|
|
2020 0 |
|
77
|
|
|
2021 0 |
|
78
|
|
|
2022 0 |
|
79
|
|
|
2023 0 |
|
80
|
|
|
2024 0 |
|
81
|
|
|
2025 0 |
|
82
|
|
|
2026 0 |
|
83
|
|
|
2027 0 |
|
84
|
|
|
2028 0 |
|
85
|
|
|
2029 0 |
|
86
|
|
|
2030 0 |
|
87
|
|
|
2031 0 |
|
88
|
|
|
2032 0 |
|
89
|
|
|
2033 0 |
|
90
|
|
|
2034 0 |
|
91
|
|
|
2035 0 |
|
92
|
|
|
2036 0 |
|
93
|
|
|
2037 0 |
|
94
|
|
|
2038 0 |
|
95
|
|
|
2039 0 |
|
96
|
|
|
2040 0 |
|
97
|
|
|
2041 0 |
|
98
|
|
|
2042 0 |
|
99
|
|
|
2043 0 |
|
100
|
|
|
2044 0 |
|
101
|
|
|
2045 0 |
|
102
|
|
|
2046 0 |
|
103
|
|
|
2047 0 |
|
104
|
|
|
dtype: int64 |
|
105
|
|
|
>>> from skchem.data import resource |
|
106
|
|
|
>>> df = skchem.read_sdf(resource('test_sdf', 'multi_molecule-simple.sdf')) |
|
107
|
|
|
>>> df.structure.apply(f) |
|
108
|
|
|
0 1 2 3 4 5 6 7 8 9 ... 2038 |
|
109
|
|
|
name ... |
|
110
|
|
|
297 0 0 0 0 0 0 0 0 0 0 ... 0 |
|
111
|
|
|
6324 0 0 0 0 0 0 0 0 0 0 ... 0 |
|
112
|
|
|
6334 0 0 0 0 0 0 0 0 0 0 ... 0 |
|
113
|
|
|
<BLANKLINE> |
|
114
|
|
|
2039 2040 2041 2042 2043 2044 2045 2046 2047 |
|
115
|
|
|
name |
|
116
|
|
|
297 0 0 0 0 0 0 0 0 0 |
|
117
|
|
|
6324 0 0 0 0 0 0 0 0 0 |
|
118
|
|
|
6334 0 0 0 0 0 0 0 0 0 |
|
119
|
|
|
<BLANKLINE> |
|
120
|
|
|
[3 rows x 2048 columns] |
|
121
|
|
|
|
|
122
|
|
|
""" |
|
123
|
|
|
@wraps(func) |
|
124
|
|
|
def func_wrapper(m): |
|
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
""" Function that wraps an rdkit function allowing it to produce dataframes. """ |
|
127
|
|
|
|
|
128
|
|
|
arr = np.array(0) |
|
129
|
|
|
DataStructs.ConvertToNumpyArray(func(m, *args, **kwargs), arr) |
|
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
return pd.Series(arr, index=columns) |
|
132
|
|
|
|
|
133
|
|
|
return func_wrapper |
|
134
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
class Fingerprinter(object): |
|
137
|
|
|
|
|
138
|
|
|
""" Fingerprinter Base class. """ |
|
139
|
|
|
|
|
140
|
|
|
def __init__(self, func, name=None): |
|
141
|
|
|
|
|
142
|
|
|
""" A generic fingerprinter. Create with a function. |
|
143
|
|
|
|
|
144
|
|
|
Args: |
|
145
|
|
|
func (callable): |
|
146
|
|
|
A fingerprinting function that takes an skchem.Mol argument, and |
|
147
|
|
|
returns an iterable of values. |
|
148
|
|
|
name (str): |
|
149
|
|
|
The name of the fingerprints that are being calculated""" |
|
150
|
|
|
|
|
151
|
|
|
self.NAME = name |
|
|
|
|
|
|
152
|
|
|
self.func = func |
|
153
|
|
|
|
|
154
|
|
|
def __call__(self, obj): |
|
155
|
|
|
|
|
156
|
|
|
""" Call the fingerprinter directly. |
|
157
|
|
|
|
|
158
|
|
|
This is a shorthand for transform. """ |
|
159
|
|
|
|
|
160
|
|
|
return self.transform(obj) |
|
161
|
|
|
|
|
162
|
|
|
def __add__(self, other): |
|
163
|
|
|
|
|
164
|
|
|
""" Add fingerprinters together to create a fusion fingerprinter. |
|
165
|
|
|
|
|
166
|
|
|
Fusion featurizers will transform molecules to series with all |
|
167
|
|
|
features from all component featurizers. |
|
168
|
|
|
""" |
|
169
|
|
|
|
|
170
|
|
|
fpers = [] |
|
171
|
|
|
for fper in (self, other): |
|
172
|
|
|
if isinstance(fper, FusionFingerprinter): |
|
173
|
|
|
fpers += fper.fingerprinters |
|
|
|
|
|
|
174
|
|
|
else: |
|
175
|
|
|
fpers.append(fper) |
|
176
|
|
|
|
|
177
|
|
|
return FusionFingerprinter(fpers) |
|
178
|
|
|
|
|
179
|
|
|
def fit(self, X, y): |
|
|
|
|
|
|
180
|
|
|
return self |
|
181
|
|
|
|
|
182
|
|
|
def transform(self, obj): |
|
183
|
|
|
|
|
184
|
|
|
""" calculate the fingerprint for the given object. """ |
|
185
|
|
|
|
|
186
|
|
|
if isinstance(obj, skchem.Mol): |
|
187
|
|
|
return self._transform(obj) |
|
188
|
|
|
|
|
189
|
|
|
elif isinstance(obj, pd.DataFrame): |
|
190
|
|
|
return obj.structure.apply(self.transform) |
|
191
|
|
|
|
|
192
|
|
|
elif isinstance(obj, pd.Series): |
|
193
|
|
|
return obj.apply(self.transform) |
|
194
|
|
|
|
|
195
|
|
|
else: |
|
196
|
|
|
raise NotImplementedError |
|
197
|
|
|
|
|
198
|
|
|
def _transform(self, mol): |
|
199
|
|
|
|
|
200
|
|
|
""" Calculate the fingerprint on a molecule. """ |
|
201
|
|
|
|
|
202
|
|
|
return pd.Series(list(self.func(mol)), name=mol.name) |
|
203
|
|
|
|
|
204
|
|
|
|
|
205
|
|
|
class FusionFingerprinter(Fingerprinter): |
|
|
|
|
|
|
206
|
|
|
|
|
207
|
|
|
def __init__(self, fingerprinters): |
|
|
|
|
|
|
208
|
|
|
|
|
209
|
|
|
self.fingerprinters = fingerprinters |
|
210
|
|
|
|
|
211
|
|
|
def transform(self, obj): |
|
212
|
|
|
|
|
213
|
|
|
if isinstance(obj, skchem.Mol): |
|
214
|
|
|
return pd.concat([fp.transform(obj) for fp in self.fingerprinters], |
|
215
|
|
|
keys=[fp.NAME for fp in self.fingerprinters]) |
|
216
|
|
|
|
|
217
|
|
|
elif isinstance(obj, pd.DataFrame): |
|
218
|
|
|
return pd.concat([fp.transform(obj) for fp in self.fingerprinters], |
|
219
|
|
|
keys=[fp.NAME for fp in self.fingerprinters], |
|
220
|
|
|
axis=1) |
|
221
|
|
|
|
|
222
|
|
|
elif isinstance(obj, pd.Series): |
|
223
|
|
|
return pd.concat([fp.transform(obj.structure) \ |
|
224
|
|
|
for fp in self.fingerprinters], |
|
225
|
|
|
keys=[fp.NAME for fp in self.fingerprinters], |
|
226
|
|
|
axis=1) |
|
227
|
|
|
|
|
228
|
|
|
else: |
|
229
|
|
|
raise NotImplementedError |
|
230
|
|
|
|
|
231
|
|
|
def _transform(self, mol): |
|
232
|
|
|
|
|
233
|
|
|
return pd.concat([fp.transform(mol) for fp in self.fingerprinters]) |
|
234
|
|
|
|
|
235
|
|
|
class MorganFingerprinter(Fingerprinter): |
|
236
|
|
|
|
|
237
|
|
|
""" Morgan Fingerprint Transformer. """ |
|
238
|
|
|
|
|
239
|
|
|
NAME = 'morgan' |
|
240
|
|
|
|
|
241
|
|
|
def __init__(self, radius=2, n_feats=2048, as_bits=False, |
|
|
|
|
|
|
242
|
|
|
use_features=False, use_bond_types=True, use_chirality=False): |
|
243
|
|
|
|
|
244
|
|
|
""" |
|
245
|
|
|
Args: |
|
246
|
|
|
radius (int): |
|
247
|
|
|
The maximum radius for atom environments. |
|
248
|
|
|
Default is `2`. |
|
249
|
|
|
n_feats (int): |
|
250
|
|
|
The number of features to which to fold the fingerprint down. |
|
251
|
|
|
For unfolded, use `-1`. |
|
252
|
|
|
Default is `2048`. |
|
253
|
|
|
as_bits (bool): |
|
254
|
|
|
Whether to return bits (`True`) or counts (`False`). |
|
255
|
|
|
Default is `True`. |
|
256
|
|
|
use_features (bool): |
|
257
|
|
|
Whether to use map atom types to generic features (FCFP analog). |
|
258
|
|
|
Default is `False`. |
|
259
|
|
|
use_bond_types (bool): |
|
260
|
|
|
Whether to use bond types to differentiate environments. |
|
261
|
|
|
Default is `False`. |
|
262
|
|
|
use_chirality (bool): |
|
263
|
|
|
Whether to use chirality to differentiate environments. |
|
264
|
|
|
Default is `False`. |
|
265
|
|
|
""" |
|
266
|
|
|
|
|
267
|
|
|
self.radius = radius |
|
268
|
|
|
self.n_feats = n_feats |
|
269
|
|
|
self.as_bits = as_bits |
|
270
|
|
|
self.use_features = use_features |
|
271
|
|
|
self.use_bond_types = use_bond_types |
|
272
|
|
|
self.use_chirality = use_chirality |
|
273
|
|
|
|
|
274
|
|
|
def _transform(self, mol): |
|
275
|
|
|
|
|
276
|
|
|
"""Private method to transform a skchem molecule. |
|
277
|
|
|
|
|
278
|
|
|
Use transform` for the public method, which genericizes the argument to |
|
279
|
|
|
iterables of mols. |
|
280
|
|
|
|
|
281
|
|
|
Args: |
|
282
|
|
|
mol (skchem.Mol): Molecule to calculate fingerprint for. |
|
283
|
|
|
|
|
284
|
|
|
Returns: |
|
285
|
|
|
pandas.Series: |
|
286
|
|
|
Fingerprint as a series. |
|
287
|
|
|
""" |
|
288
|
|
|
|
|
289
|
|
|
if self.n_feats < 0: |
|
290
|
|
|
|
|
291
|
|
|
res = GetMorganFingerprint(mol, self.radius, |
|
292
|
|
|
useFeatures=self.use_features, |
|
293
|
|
|
useBondTypes=self.use_bond_types, |
|
294
|
|
|
useChirality=self.use_chirality).GetNonzeroElements() |
|
295
|
|
|
idx = pd.Index(list(res.keys()), name='features') |
|
296
|
|
|
|
|
297
|
|
|
else: |
|
298
|
|
|
res = list(GetHashedMorganFingerprint(mol, self.radius, |
|
299
|
|
|
nBits=self.n_feats, |
|
|
|
|
|
|
300
|
|
|
useFeatures=self.use_features, |
|
|
|
|
|
|
301
|
|
|
useBondTypes=self.use_bond_types, |
|
|
|
|
|
|
302
|
|
|
useChirality=self.use_chirality)) |
|
|
|
|
|
|
303
|
|
|
idx = pd.Index(range(self.n_feats), name='features') |
|
304
|
|
|
|
|
305
|
|
|
res = pd.Series(res, name=mol.name, index=idx).astype(int) |
|
306
|
|
|
|
|
307
|
|
|
if self.as_bits: |
|
308
|
|
|
res = (res > 0).astype(np.uint8) #smallest memory size |
|
309
|
|
|
|
|
310
|
|
|
return res |
|
311
|
|
|
|
|
312
|
|
|
def grad(self, mol): |
|
313
|
|
|
|
|
314
|
|
|
""" Calculate the pseudo gradient with resepect to the atoms. |
|
315
|
|
|
|
|
316
|
|
|
The pseudo gradient is the number of times the atom set that particular |
|
317
|
|
|
bit. |
|
318
|
|
|
|
|
319
|
|
|
Args: |
|
320
|
|
|
mol (skchem.Mol): |
|
321
|
|
|
The molecule for which to calculate the pseudo gradient. |
|
322
|
|
|
|
|
323
|
|
|
Returns: |
|
324
|
|
|
pandas.DataFrame: |
|
325
|
|
|
Dataframe of pseudogradients, with columns corresponding to |
|
326
|
|
|
atoms, and rows corresponding to features of the fingerprint. |
|
327
|
|
|
""" |
|
328
|
|
|
|
|
329
|
|
|
cols = pd.Index(list(range(len(mol.atoms))), name='atoms') |
|
330
|
|
|
dist = GetDistanceMatrix(mol) |
|
331
|
|
|
|
|
332
|
|
|
info = {} |
|
333
|
|
|
|
|
334
|
|
|
if self.n_feats < 0: |
|
335
|
|
|
|
|
336
|
|
|
res = GetMorganFingerprint(mol, self.radius, |
|
337
|
|
|
useFeatures=self.use_features, |
|
338
|
|
|
useBondTypes=self.use_bond_types, |
|
339
|
|
|
useChirality=self.use_chirality, |
|
340
|
|
|
bitInfo=info).GetNonzeroElements() |
|
341
|
|
|
idx_list = list(res.keys()) |
|
342
|
|
|
idx = pd.Index(idx_list, name='features') |
|
343
|
|
|
grad = np.zeros((len(idx), len(cols))) |
|
344
|
|
|
for bit in info: |
|
345
|
|
|
for atom_idx, radius in info[bit]: |
|
346
|
|
|
grad[idx_list.index(bit)] += (dist <= radius)[atom_idx] |
|
347
|
|
|
|
|
348
|
|
|
else: |
|
349
|
|
|
|
|
350
|
|
|
res = list(GetHashedMorganFingerprint(mol, self.radius, |
|
351
|
|
|
nBits=self.n_feats, |
|
|
|
|
|
|
352
|
|
|
useFeatures=self.use_features, |
|
|
|
|
|
|
353
|
|
|
useBondTypes=self.use_bond_types, |
|
|
|
|
|
|
354
|
|
|
useChirality=self.use_chirality, |
|
|
|
|
|
|
355
|
|
|
bitInfo=info)) |
|
|
|
|
|
|
356
|
|
|
idx = pd.Index(range(self.n_feats), name='features') |
|
357
|
|
|
grad = np.zeros((len(idx), len(cols))) |
|
358
|
|
|
|
|
359
|
|
|
for bit in info: |
|
360
|
|
|
for atom_idx, radius in info[bit]: |
|
361
|
|
|
grad[bit] += (dist <= radius)[atom_idx] |
|
362
|
|
|
|
|
363
|
|
|
grad = pd.DataFrame(grad, index=idx, columns=cols) |
|
364
|
|
|
|
|
365
|
|
|
if self.as_bits: |
|
366
|
|
|
grad = (grad > 0) |
|
367
|
|
|
|
|
368
|
|
|
return grad.astype(int) |
|
369
|
|
|
|
|
370
|
|
|
class AtomPairFingerprinter(Fingerprinter): |
|
371
|
|
|
|
|
372
|
|
|
""" Atom Pair Tranformer. """ |
|
373
|
|
|
|
|
374
|
|
|
NAME = 'atom_pair' |
|
375
|
|
|
|
|
376
|
|
|
def __init__(self, min_length=1, max_length=30, n_feats=2048, as_bits=False, |
|
|
|
|
|
|
377
|
|
|
use_chirality=False): |
|
378
|
|
|
|
|
379
|
|
|
""" Instantiate an atom pair fingerprinter. |
|
380
|
|
|
|
|
381
|
|
|
Args: |
|
382
|
|
|
min_length (int): |
|
383
|
|
|
The minimum length of paths between pairs. |
|
384
|
|
|
Default is `1`, i.e. pairs can be bonded together. |
|
385
|
|
|
max_length (int): |
|
386
|
|
|
The maximum length of paths between pairs. |
|
387
|
|
|
Default is `30`. |
|
388
|
|
|
n_feats (int): |
|
389
|
|
|
The number of features to which to fold the fingerprint down. |
|
390
|
|
|
For unfolded, use `-1`. |
|
391
|
|
|
Default is `2048`. |
|
392
|
|
|
as_bits (bool): |
|
393
|
|
|
Whether to return bits (`True`) or counts (`False`). |
|
394
|
|
|
Default is `False`. |
|
395
|
|
|
use_chirality (bool): |
|
396
|
|
|
Whether to use chirality to differentiate environments. |
|
397
|
|
|
Default is `False`. |
|
398
|
|
|
""" |
|
399
|
|
|
|
|
400
|
|
|
self.min_length = min_length |
|
401
|
|
|
self.max_length = max_length |
|
402
|
|
|
self.n_feats = n_feats |
|
403
|
|
|
self.as_bits = as_bits |
|
404
|
|
|
self.use_chirality = use_chirality |
|
405
|
|
|
|
|
406
|
|
|
def _transform(self, mol): |
|
407
|
|
|
|
|
408
|
|
|
"""Private method to transform a skchem molecule. |
|
409
|
|
|
|
|
410
|
|
|
Use transform` for the public method, which genericizes the argument to |
|
411
|
|
|
iterables of mols. |
|
412
|
|
|
|
|
413
|
|
|
Args: |
|
414
|
|
|
mol (skchem.Mol): Molecule to calculate fingerprint for. |
|
415
|
|
|
|
|
416
|
|
|
Returns: |
|
417
|
|
|
pandas.Series: |
|
418
|
|
|
Fingerprint as a series. |
|
419
|
|
|
""" |
|
420
|
|
|
|
|
421
|
|
|
if self.n_feats == -1: |
|
422
|
|
|
|
|
423
|
|
|
res = GetAtomPairFingerprint(mol, minLength=self.min_length, |
|
424
|
|
|
maxLength=self.max_length, |
|
425
|
|
|
includeChirality=self.use_chirality) |
|
426
|
|
|
else: |
|
427
|
|
|
res = list(GetHashedAtomPairFingerprint(mol, |
|
428
|
|
|
minLength=self.min_length, |
|
|
|
|
|
|
429
|
|
|
maxLength=self.max_length, |
|
|
|
|
|
|
430
|
|
|
nBits=self.n_feats, |
|
|
|
|
|
|
431
|
|
|
includeChirality=self.use_chirality)) |
|
|
|
|
|
|
432
|
|
|
|
|
433
|
|
|
res = pd.Series(res, name=mol.name) |
|
434
|
|
|
|
|
435
|
|
|
if self.as_bits: |
|
436
|
|
|
return (res > 0).astype(int) |
|
437
|
|
|
else: |
|
438
|
|
|
return res |
|
439
|
|
|
|
|
440
|
|
|
class TopologicalTorsionFingerprinter(Fingerprinter): |
|
|
|
|
|
|
441
|
|
|
|
|
442
|
|
|
NAME = 'topological_torsion' |
|
443
|
|
|
|
|
444
|
|
|
def __init__(self, target_size=4, n_feats=2048, as_bits=False, |
|
|
|
|
|
|
445
|
|
|
use_chirality=False): |
|
446
|
|
|
|
|
447
|
|
|
""" |
|
448
|
|
|
Args: |
|
449
|
|
|
target_size (int): |
|
450
|
|
|
# TODO |
|
451
|
|
|
n_feats (int): |
|
452
|
|
|
The number of features to which to fold the fingerprint down. |
|
453
|
|
|
For unfolded, use `-1`. |
|
454
|
|
|
Default is `2048`. |
|
455
|
|
|
as_bits (bool): |
|
456
|
|
|
Whether to return bits (`True`) or counts (`False`). |
|
457
|
|
|
Default is `False`. |
|
458
|
|
|
use_chirality (bool): |
|
459
|
|
|
Whether to use chirality to differentiate environments. |
|
460
|
|
|
Default is `False`. |
|
461
|
|
|
""" |
|
462
|
|
|
|
|
463
|
|
|
self.target_size = target_size |
|
464
|
|
|
self.n_feats = n_feats |
|
465
|
|
|
self.as_bits = as_bits |
|
466
|
|
|
self.use_chirality = use_chirality |
|
467
|
|
|
|
|
468
|
|
|
def _transform(self, mol): |
|
469
|
|
|
|
|
470
|
|
|
if self.n_feats == -1: |
|
471
|
|
|
|
|
472
|
|
|
res = GetTopologicalTorsionFingerprint(mol, |
|
473
|
|
|
targetSize=self.targetSize, |
|
|
|
|
|
|
474
|
|
|
includeChirality=self.use_chirality) |
|
|
|
|
|
|
475
|
|
|
|
|
476
|
|
|
else: |
|
477
|
|
|
res = list(GetHashedTopologicalTorsionFingerprint(mol, |
|
478
|
|
|
targetSize=self.targetSize, |
|
|
|
|
|
|
479
|
|
|
nBits=self.n_feats)) |
|
|
|
|
|
|
480
|
|
|
|
|
481
|
|
|
res = pd.Series(res, name=mol.name) |
|
482
|
|
|
|
|
483
|
|
|
if self.as_bits: |
|
484
|
|
|
return (res > 0).astype(int) |
|
485
|
|
|
else: |
|
486
|
|
|
return res |
|
487
|
|
|
|
|
488
|
|
|
|
|
489
|
|
|
class MACCSKeysFingerprinter(Fingerprinter): |
|
490
|
|
|
|
|
491
|
|
|
""" MACCS Keys Fingerprints """ |
|
492
|
|
|
|
|
493
|
|
|
NAME = 'maccs' |
|
494
|
|
|
|
|
495
|
|
|
def __init__(self): |
|
|
|
|
|
|
496
|
|
|
pass |
|
497
|
|
|
|
|
498
|
|
|
def _transform(self, mol): |
|
499
|
|
|
|
|
500
|
|
|
return pd.Series(list(GetMACCSKeysFingerprint(mol))) |
|
501
|
|
|
|
|
502
|
|
|
class ErGFingerprinter(Fingerprinter): |
|
503
|
|
|
|
|
504
|
|
|
""" ErG Fingerprints """ |
|
505
|
|
|
|
|
506
|
|
|
NAME = 'erg' |
|
507
|
|
|
|
|
508
|
|
|
def __init__(self): |
|
|
|
|
|
|
509
|
|
|
pass |
|
510
|
|
|
|
|
511
|
|
|
def _transform(self, mol): |
|
512
|
|
|
|
|
513
|
|
|
return pd.Series(GetErGFingerprint(mol)) |
|
514
|
|
|
|
|
515
|
|
|
class FeatureInvariantsFingerprinter(Fingerprinter): |
|
516
|
|
|
|
|
517
|
|
|
""" Feature invariants fingerprints. """ |
|
518
|
|
|
|
|
519
|
|
|
NAME = 'feat_inv' |
|
520
|
|
|
|
|
521
|
|
|
def __init__(self): |
|
|
|
|
|
|
522
|
|
|
pass |
|
523
|
|
|
|
|
524
|
|
|
def _transform(self, mol): |
|
525
|
|
|
|
|
526
|
|
|
return pd.Series(GetFeatureInvariants(mol)) |
|
527
|
|
|
|
|
528
|
|
|
class ConnectivityInvariantsFingerprinter(Fingerprinter): |
|
529
|
|
|
|
|
530
|
|
|
""" Connectivity invariants fingerprints """ |
|
531
|
|
|
|
|
532
|
|
|
NAME = 'conn_inv' |
|
533
|
|
|
|
|
534
|
|
|
def __init__(self): |
|
|
|
|
|
|
535
|
|
|
pass |
|
536
|
|
|
|
|
537
|
|
|
def _transform(self, mol): |
|
538
|
|
|
|
|
539
|
|
|
return pd.Series(GetConnectivityInvariants(mol)) |
|
540
|
|
|
|
|
541
|
|
|
class RDKFingerprinter(Fingerprinter): |
|
|
|
|
|
|
542
|
|
|
|
|
543
|
|
|
""" RDKit fingerprint """ |
|
544
|
|
|
|
|
545
|
|
|
NAME = 'rdk' |
|
546
|
|
|
|
|
547
|
|
|
def __init__(self, min_path=1, max_path=7, n_feats=2048, n_bits_per_hash=2, |
|
|
|
|
|
|
548
|
|
|
use_hs=True, target_density=0.0, min_size=128, |
|
|
|
|
|
|
549
|
|
|
branched_paths=True, use_bond_types=True): |
|
|
|
|
|
|
550
|
|
|
|
|
551
|
|
|
""" RDK fingerprints |
|
552
|
|
|
|
|
553
|
|
|
# TODO |
|
554
|
|
|
|
|
555
|
|
|
Args: |
|
556
|
|
|
min_path (int): |
|
557
|
|
|
|
|
558
|
|
|
max_path (int): |
|
559
|
|
|
|
|
560
|
|
|
n_feats (int): |
|
561
|
|
|
The number of features to which to fold the fingerprint down. |
|
562
|
|
|
For unfolded, use `-1`. |
|
563
|
|
|
Default is `2048`. |
|
564
|
|
|
|
|
565
|
|
|
n_bits_per_hash (int) |
|
566
|
|
|
|
|
567
|
|
|
use_hs (bool): |
|
568
|
|
|
|
|
569
|
|
|
target_density (float): |
|
570
|
|
|
|
|
571
|
|
|
min_size (int): |
|
572
|
|
|
|
|
573
|
|
|
branched_paths (bool): |
|
574
|
|
|
|
|
575
|
|
|
use_bond_types (bool): |
|
576
|
|
|
""" |
|
577
|
|
|
|
|
578
|
|
|
self.min_path = 1 |
|
579
|
|
|
self.max_path = 7 |
|
580
|
|
|
self.n_feats = 2048 |
|
581
|
|
|
self.n_bits_per_hash = 2 |
|
582
|
|
|
self.use_hs = True |
|
583
|
|
|
self.target_density = 0.0 |
|
584
|
|
|
self.min_size = 128 |
|
585
|
|
|
self.branched_paths = True |
|
586
|
|
|
self.use_bond_types = True |
|
587
|
|
|
|
|
588
|
|
|
def _transform(self, mol): |
|
589
|
|
|
|
|
590
|
|
|
return pd.Series(list(RDKFingerprint(mol, minPath=self.min_path, |
|
591
|
|
|
maxPath=self.max_path, |
|
592
|
|
|
fpSize=self.n_feats, |
|
593
|
|
|
nBitsPerHash=self.n_bits_per_hash, |
|
594
|
|
|
useHs=self.use_hs, |
|
595
|
|
|
tgtDensity=self.target_density, |
|
596
|
|
|
minSize=self.min_size, |
|
597
|
|
|
branchedPaths=self.branched_paths, |
|
598
|
|
|
useBondOrder=self.use_bond_types)), |
|
599
|
|
|
name=mol.name) |
|
|
|
|
|
|
600
|
|
|
|
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.