forked from mordred-descriptor/mordred
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path020-single_mol-multiple_desc.py
54 lines (36 loc) · 1.33 KB
/
020-single_mol-multiple_desc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from multiprocessing import freeze_support
from rdkit import Chem
from mordred import Chi, ABCIndex, RingCount, Calculator, is_missing, descriptors
if __name__ == "__main__":
freeze_support()
benzene = Chem.MolFromSmiles("c1ccccc1")
# Create empty Calculator instance
calc1 = Calculator()
# Register descriptor instance
calc1.register(Chi.Chi(type="path_cluster", order=4))
# Register descriptor class using preset
calc1.register(RingCount.RingCount)
# Register all descriptors in module
calc1.register(ABCIndex)
# Calculate descriptors
result = calc1(benzene)
print(result)
# >>> [0.0, 1, 0, 0, 0, 1, (snip)
# Calculator constructor can register descriptors
calc2 = Calculator(Chi.Chi)
# Descriptors module contains all descriptors
calc3 = Calculator(descriptors)
# User can access all descriptor instances by descriptors property
print(calc3.descriptors)
# >>> (mordred.EccentricConnectivityIndex.EccentricConnectivityIndex(), (snip)
# Calculate descriptors
result = calc3(benzene)
# get first missing value
na1 = next(r for r in result if is_missing(r))
# get reason
print(na1.error)
# >>> missing 3D coordinate
# Delete all missing value
result = result.drop_missing()
# convert to dict
print(result.asdict())