-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmols2sdf.py
executable file
·52 lines (39 loc) · 1.49 KB
/
mols2sdf.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
#!/usr/bin/env python3
#==============================================================================
# author : Pavel Polishchuk
# date : 20-06-2018
# version :
# python_version :
# copyright : Pavel Polishchuk 2018
# license :
#==============================================================================
__author__ = 'Pavel Polishchuk'
import os
import sys
import argparse
from rdkit import Chem
def calc(input_fnames, output_fname):
w = Chem.SDWriter(output_fname)
for f in input_fnames:
m = Chem.MolFromMolFile(f, sanitize=False, removeHs=False, strictParsing=False)
if m:
name = os.path.basename(f).rsplit('.', 1)[0]
m.SetProp('Code', name)
m.SetProp('_Name', name)
w.write(m)
else:
sys.stderr.write('Molecule in %s cannot be read.' % f)
w.close()
def main():
parser = argparse.ArgumentParser(description='Convert multiple MOL files to SDF. No checks are performed.')
parser.add_argument('-i', '--input', metavar='input.mol', required=True, nargs='*',
help='input MOL files.')
parser.add_argument('-o', '--output', metavar='output.sdf', required=True,
help='output SDF file.')
args = vars(parser.parse_args())
for o, v in args.items():
if o == "input": input_fnames = v
if o == "output": output_fname = v
calc(input_fnames, output_fname)
if __name__ == '__main__':
main()