-
Notifications
You must be signed in to change notification settings - Fork 1
/
rev_docking_p.py
115 lines (99 loc) · 3.68 KB
/
rev_docking_p.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python3
import re, sys, os, subprocess, glob, configparser
from multiprocessing import Pool
cwd = os.getcwd()
##### config parser ####
config = configparser.ConfigParser(inline_comment_prefixes="#")
config.optionxform = str
config.read(sys.argv[1])
locals().update(dict(config.items('DOCKING')))
#### call to scripts ####
pythonsh = MGL_ROOT+'/bin/pythonsh'
u24 = MGL_ROOT+'/MGLToolsPckgs/AutoDockTools/Utilities24/'
def prepare_receptor(inf,outf):
subprocess.run([pythonsh,u24+'prepare_receptor4.py',
'-A "checkhydrogens" -e',
'-r',inf,
'-o',outf])
def prepare_gpf(receptor, ligand, coord, output):
os.chdir(out_dir)
subprocess.run([pythonsh,u24+'prepare_gpf4.py',
'-l',ligand,
' '.join(['-p '+'='.join(i) for i in config.items('GPF')]),
'-p gridcenter='+coord,
'-r',receptor,
'-o',output])
os.chdir(cwd)
def prepare_dpf(receptor, ligand, output):
os.chdir(out_dir)
subprocess.run([pythonsh,u24+'prepare_dpf4.py',
'-l',ligand,
' '.join(['-p '+'='.join(i) for i in config.items('DPF')]),
'-r',receptor,
'-o',output])
os.chdir(cwd)
def autogrid(gpf, glg):
os.chdir(out_dir)
subprocess.run(['autogrid4',
'-p',gpf,
'-l',glg])
os.chdir(cwd)
def autodock(dpf, dlg):
os.chdir(out_dir)
subprocess.run(['autodock4',
'-p',dpf,
'-l',dlg])
os.chdir(cwd)
#### make outdir ####
i = 1
while os.path.exists(outdir+'_%s' % i):
i += 1
out_dir = outdir+'_%s' % i+'/'
os.makedirs(out_dir)
if os.path.exists(outdir+'_%s' % i):
print('writing output in '+out_dir)
#### read coordinates ####
coordinates = {}
try:
for line in open(coord_file):
if '#' in line: #skip comments
next
else:
name, x, y, z = line.split()
coordinates.setdefault(name, []).append([x,y,z])
print('Reading '+coord_file+' ...')
except:
print(coord_file+" doesn't exist")
try:
os.system('cp '+ligand+' '+out_dir)
lig_name = os.path.splitext(os.path.basename(ligand))[0]
except:
print(ligand+" doesn't exist")
#### reverse docking ####
def reverse_docking(pdb):
xyz = coordinates.get(pdb)
pdb_name = os.path.splitext(pdb)[0]
for c in xyz:
#### prepare receptor, gpf and dpf ####
i=1
while os.path.exists(out_dir+pdb_name+'_%s.pdbqt' %i):
i += 1 # incrementing file number
print(re.sub('HETATM', '#HETATM', open(receptor_dir+'/'+pdb, 'r').read()),
file=open(out_dir+pdb, 'w')) # comment HETATM in pdb file
prepare_receptor(out_dir+pdb, out_dir+pdb_name+'_%s.pdbqt' %i)
prepare_gpf(pdb_name+'_%s.pdbqt' %i,
os.path.basename(ligand),
','.join(map(str,c)),
pdb_name+'_%s.gpf' % i)
prepare_dpf(pdb_name+'_%s.pdbqt' %i,
os.path.basename(ligand),
pdb_name+'_'+lig_name+'_%s.dpf' % i)
## solve bug space in dpf ##
print(re.sub('#', ' #', open(out_dir+pdb_name+'_'+lig_name+'_%s.dpf' % i).read()),
file=open(out_dir+pdb_name+'_'+lig_name+'_%s.dpf' % i, 'w'))
#### autogrid ####
autogrid(pdb_name+'_%s.gpf' % i, pdb_name+'_%s.glg' % i)
#### autodock ####
autodock(pdb_name+'_'+lig_name+'_%s.dpf' % i, pdb_name+'_'+lig_name+'_%s.dlg' % i)
#### multiprocessing ####
Pool(int(processes)).map(reverse_docking,coordinates)