/
hbind_pymol_cmds.py
84 lines (69 loc) · 2.48 KB
/
hbind_pymol_cmds.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Sebastian Raschka, 12/22/2016
#
# Tool to create PyMOL commands for visualizing
# hydrogen-bond interactions between a protein
# its ligands from HBind interaction tables
import sys
def generate_pymol_commands(inpath):
with open(inpath, 'r') as f:
txt = f.read()
prot_resid = []
prot_restype = []
prot_chain_id = []
prot_atom = []
lig_atomid = []
interact_type = []
for line in txt.split('\n'):
if line.startswith(('| hbond', '| saltb ',
'| metal', '| metal_ld')):
line = line.split()
interact_type.append(line[1].strip())
lig_atomid.append(line[3].strip())
prot_restype.append(line[6].strip())
prot_chain_id.append(line[7].strip())
prot_resid.append(line[8].strip())
prot_atom.append(line[9].strip())
print('hide lines')
print('show cartoon')
print('show sticks, ligand')
print('set sphere_scale=0.32')
for i in set(prot_resid):
print('show sticks, (protein and chain A and resi %s)' %
(i))
for i in set(lig_atomid):
print('show sphere, (ligand and id %s)' % (i))
ld_metal = False
metal = False
saltb = False
hbond = False
for a, b, c, d, e, f in zip(prot_chain_id, prot_restype, prot_resid,
prot_atom, lig_atomid, interact_type):
print('show sphere, /protein//%s/%s`%s/%s' % (a, b, c, d))
if f == 'hbond':
print('distance hbond, /protein//%s/%s`%s/%s,'
'(ligand and id %s)' % (a, b, c, d, e))
hbond = True
elif f == 'saltb':
print('distance saltb, /protein//%s/%s`%s/%s,'
'(ligand and id %s)' % (a, b, c, d, e))
saltb = True
elif f == 'metal':
print('distance metal, /protein//%s/%s`%s/%s,'
'(ligand and id %s)' % (a, b, c, d, e))
metal = True
elif f == 'ld_metal':
print('distance ld_metal, /protein//%s/%s`%s/%s,'
'(ligand and id %s)' % (a, b, c, d, e))
ld_metal = True
if hbond:
print('set dash_color, yellow, hbond')
if metal:
print('set dash_color, green, saltb')
if saltb:
print('set dash_color, grey, ld_metal')
if ld_metal:
print('set dash_color, white, metal')
print('hide labels')
if __name__ == '__main__':
hbind_tabledir = sys.argv[1]
generate_pymol_commands(hbind_tabledir)