-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_chem.py
executable file
·57 lines (44 loc) · 1.25 KB
/
draw_chem.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
#!/usr/bin/python
'''
File name: draw_chem.py
Author: Jose G. Macia-Vicente
Date created: 2017-03-03
Date last modified: 2017-03-03
Python Version: 2.7
'''
import argparse
from rdkit.Chem import AllChem as Chem
from rdkit.Chem import Draw
# input arguments parameters
parser = argparse.ArgumentParser(
description='Draw chemical structures from provided file.')
parser.add_argument(
"cid",
help = 'input CID from list')
parser.add_argument(
"-i", help = 'input file',
type=str,
default='smiles.txt')
parser.add_argument(
"-o", help = 'output file',
type=str,
default='output.pdf')
args = parser.parse_args()
# process query
handle = open(args.i)
# for black and white (comment for color):
opt = Draw.DrawingOptions()
from collections import defaultdict
dd = defaultdict(lambda:(0,0,0)) # <- use a default color of black
opt.elemDict = dd
# draw compound
for line in handle:
if line.split()[0] in args.cid:
smile = Chem.MolFromSmiles(line.split()[1])
#smile = Chem.AddHs(smile)
Chem.Compute2DCoords(smile)
#Chem.EmbedMolecule(smile)
#Chem.MMFFOptimizeMolecule(smile)
#Chem.UFFOptimizeMolecule(smile)
#smile = Chem.RemoveHs(smile)
Draw.MolToFile(smile, args.o, options = opt)