-
Notifications
You must be signed in to change notification settings - Fork 31
/
cal_prop.py
37 lines (31 loc) · 1.23 KB
/
cal_prop.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
from rdkit.Chem.Descriptors import ExactMolWt
from rdkit.Chem.Crippen import MolLogP
from rdkit.Chem.rdMolDescriptors import CalcNumHBD
from rdkit.Chem.rdMolDescriptors import CalcNumHBA
from rdkit.Chem.rdMolDescriptors import CalcTPSA
from rdkit import Chem
from multiprocessing import Pool
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--input_filename', help='filename for smiles', type=str, default='smiles.txt')
parser.add_argument('--output_filename', help='name of output file', type=str, default='smiles_prop.txt')
parser.add_argument('--ncpus', help='number of cpus', type=int, default=1)
args = parser.parse_args()
def cal_prop(s):
m = Chem.MolFromSmiles(s)
if m is None : return None
return Chem.MolToSmiles(m), ExactMolWt(m), MolLogP(m), CalcTPSA(m)
#return Chem.MolToSmiles(m), ExactMolWt(m), MolLogP(m), CalcNumHBD(m), CalcNumHBA(m), CalcTPSA(m)
with open(args.input_filename) as f:
smiles = f.read().split('\n')[:-1]
pool = Pool(8)
r = pool.map_async(cal_prop, smiles)
data = r.get()
pool.close()
pool.join()
w = open(args.output_filename, 'w')
for d in data:
if d is None:
continue
w.write(d[0] + '\t' + str(d[1]) + '\t'+ str(d[2]) + '\t'+ str(d[3]) + '\n')
w.close()