-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathmw_hac_mp.py
More file actions
executable file
·42 lines (28 loc) · 803 Bytes
/
Copy pathmw_hac_mp.py
File metadata and controls
executable file
·42 lines (28 loc) · 803 Bytes
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
#!/usr/bin/env python3
__author__ = 'Pavel Polishchuk'
import sys
from multiprocessing import Pool
from rdkit import Chem
from rdkit.Chem.rdMolDescriptors import CalcExactMolWt
def process_line(line):
tmp = line.strip().split()
m = Chem.MolFromSmiles(tmp[0])
if m:
mw = CalcExactMolWt(m)
hac = m.GetNumHeavyAtoms()
return tmp[0], tmp[1], mw, hac
else:
return None
def main():
pool = Pool(processes=30)
header = True
with open(sys.argv[1]) as f:
if header:
f.readline()
print('SMILES\tName\tmw\thac')
for res in pool.imap(process_line, f, chunksize=100):
if res:
print('\t'.join(map(str, res)))
pool.close()
if __name__ == '__main__':
main()