-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSMILES2descriptor.py
executable file
·59 lines (37 loc) · 1.27 KB
/
SMILES2descriptor.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
55
56
57
58
59
#!/usr/bin/env python
import sys
import inspect
import numpy as np
from rdkit.Chem import Descriptors, MolFromSmiles
MOL_H2O = MolFromSmiles('O')
def main():
decriptors_names = map(lambda x:x.strip('\n'), open(sys.argv[1]).readlines())
inSMILES = open(sys.argv[2])
inBRD = open(sys.argv[3])
SMILES_dict = {}
for line in inSMILES:
BRD, SMILES = line.strip('\n').split('\t')
SMILES_dict[BRD] = SMILES
BRD_lst = []
for line in inBRD:
BRD_lst.append(line.split('\t')[1])
descriptors = inspect.getmembers(Descriptors, inspect.isfunction)
descriptors_func = []
for pair in descriptors:
name, func = pair
if name in decriptors_names:
descriptors_func.append(func)
for BRD in BRD_lst:
SMILES = SMILES_dict[BRD]
mol = MolFromSmiles(SMILES)
descriptor = []
for func in descriptors_func:
val = func(mol)
if np.isinf(val) or np.isnan(val):
val = func(MOL_H2O)
descriptor.append(val)
print '\t'.join(map(str, descriptor))
inSMILES.close()
inBRD.close()
if __name__ == '__main__':
main()