forked from ADplugin/ADplugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautodock.py
More file actions
4044 lines (3439 loc) · 176 KB
/
autodock.py
File metadata and controls
4044 lines (3439 loc) · 176 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Autodock/Vina plugin Copyright Notice
# ============================
#
# The Autodock/Vina plugin source code is copyrighted, but you can freely use and
# copy it as long as you don't change or remove any of the copyright
# notices.
#
# ----------------------------------------------------------------------
# Autodock/Vina plugin is Copyright (C) 2009 by Daniel Seeliger
#
# All Rights Reserved
#
# Permission to use, copy, modify, distribute, and distribute modified
# versions of this software and its documentation for any purpose and
# without fee is hereby granted, provided that the above copyright
# notice appear in all copies and that both the copyright notice and
# this permission notice appear in supporting documentation, and that
# the name of Daniel Seeliger not be used in advertising or publicity
# pertaining to distribution of the software without specific, written
# prior permission.
#
# DANIEL SEELIGER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS. IN NO EVENT SHALL DANIEL SEELIGER BE LIABLE FOR ANY
# SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# ----------------------------------------------------------------------
#================================================================
import sys,os,math,re, fnmatch, shutil
from os import stat
from os.path import abspath
from stat import ST_SIZE
from time import sleep, time
import Tkinter
import Tkinter,Pmw
from Tkinter import *
import tkMessageBox, tkFileDialog
import Pmw
from threading import Thread
#from commands import getstatusoutput
from pymol import cmd,selector
from pymol.cmd import _feedback,fb_module,fb_mask,is_list,_cmd
from pymol.cgo import *
from pymol import stored
from numpy import *
import tkColorChooser
from pymol.vfont import plain
from glob import glob
import platform
__version__ = "2.2.0_rev_28Mar2015"
#=============================================================================
#
# INITIALISE PLUGIN
#
if os.environ.has_key('ADPLUGIN_PATH'):
os.environ['PATH'] = os.environ['ADPLUGIN_PATH']
if os.environ.has_key('ADPLUGIN_PYTHONHOME'):
os.environ['PYTHONHOME'] = os.environ['ADPLUGIN_PYTHONHOME']
if os.environ.has_key('ADPLUGIN_PYTHONPATH'):
os.environ['PYTHONPATH'] = os.environ['ADPLUGIN_PYTHONPATH']
if os.environ.has_key('ADPLUGIN_FONT'):
adplugin_font_list = os.environ['ADPLUGIN_FONT'].split()
adplugin_font = (adplugin_font_list[0], adplugin_font_list[1])
else:
adplugin_font = ("Courier", 12)
adplugin_font_name = adplugin_font[0]
adplugin_font_size = int(adplugin_font[1])
if not (adplugin_font_name in Pmw.logicalfontnames()):
print "'"+adplugin_font_name+"' not in ", Pmw.logicalfontnames()
print "changing to Courier"
adplugin_font_name = "Courier"
if adplugin_font_size < 4 or adplugin_font_size > 36:
print "'"+str(adplugin_font_size)+ "' not an acceptable font size, changing to 12"
adplugin_font_size = 12
adplugin_font = (adplugin_font_name,adplugin_font_size)
def getstatusoutput(cmd):
"""Return (status, output) of executing cmd in a shell."""
"""This implementation should work on all platforms."""
import subprocess
cur_env = dict(os.environ.copy())
if os.environ.has_key('ADPLUGIN_PATH'):
cur_env['PATH'] = os.environ['ADPLUGIN_PATH']
if os.environ.has_key('ADPLUGIN_PYTHONHOME'):
cur_env['PYTHONHOME'] = os.environ['ADPLUGIN_PYTHONHOME']
if os.environ.has_key('ADPLUGIN_PYTHONPATH'):
cur_env['PYTHONPATH'] = os.environ['ADPLUGIN_PYTHONPATH']
sts = 0
output = ""
try:
output = subprocess.check_output(cmd, shell=True, env=cur_env, \
stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
except subprocess.CalledProcessError as e:
sts = 256
print "getstatusoutput failed"
print output, e.output
return sts, output
def __init__(self):
self.menuBar.addmenuitem('Plugin', 'command',
'Launch Autodock',
label='Autodock/Vina',
command = lambda s=self: Autodock(s))
cmd.set("retain_order") # keep atom ordering
#=============================================================================
#
# SOME BASIC THINGIES
#
global_status = StringVar()
global_status.set("")
transfer_status = {}
transfer_status['log'] = ""
transfer_status['line_count'] = 0
transfer_status['old_line_count'] = 0
intro_text = """
Autodock/Vina plugin is Copyright (C) 2009 -- 2015 by Daniel Seeliger, All Rights Reserved
No warranty. You may redistribute this plugin under the terms of the LGPL.
Welcome to the updated version of the PyMOL Autodock Plugin. The current version has been entirely rewritten and extended. Now you can set up a complete docking run from the very beginning, perform the docking runs from within PyMOL and directly load the results into the viewer. The plugin now supports the novel Autodock spawn \"VINA\" which is orders of magnitudes faster than Autodock4.
To get this plugin to work properly you should have the mgltools (http://mgltools.scripps.edu/) installed and tell the plugin on this page where to find the scripts (usually somewhere in /python/site-packages/AutoDockTools/Utilities24/ ) and make sure that they work. Additionally you should tell the plugin where to find the autogrid4, autodock4, and vina executables. If you do this once and press the \"Save Configuration File\" button this information is present the next time you use the plugin.
A complete setup and execution of a docking run or a virtual screening is basically a walk from the left to the right along the notebook structure if this plugin. Each page is more or less intuitive or contains a description of what to do. The basic workflow is: Load Structure -> Define binding site -> Receptor preparation -> Ligand preparation -> Docking -> Analysis.
To simplify configuration, especially in Windows, you should define the environment variables ADPLUGIN_PATH, ADPLUGIN_PYTHONHOME, and ADPLUGIN_PYTHONPATH to provide the values of PATH, PYTHONHOME, and PYTHONPATH to be used in the plugin and its child threads and processes.
LGPL NOTICES: This plugin is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This plugin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this plugin; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Have fun and contact me (dseelig@gwdg.de) if you find bugs or have any suggestions for future versions.
Daniel
Reference: J. Comput.-Aided Mol. Des. 24:417-422 (2010)
"""
receptor_prep_text = """
Here you can define receptors from PyMOL selections and setup docking runs with flexible sidechains. Pick a selection from the selection list and press the Generate Receptor ->" button to prepare the protein for a docking run. If you want to use flexible sidechains within the binding site just create a PyMOL selection containing the residues you want to be flexible. Then use the "Import Selections" button and andselect the group in the left list. Then press the Select as Flexible->" button. The receptor definition has now changed. You can see which residues are flexible in the right list. (Proline, Glycine and Alanine residues are never defined as flexible). Be patient if you specify a large set of flexible residues. Processing may take a while.\n"""
ligand_prep_text = """
On this page you can prepare ligands for docking.The first way to do so is to load the ligand into PyMOL and select it in the left list (use the "Import Selection" button to synchronize the list with PyMOL). The plugin saves your ligand in as .pdb file and puts it into the ligand list in the middle of the page. If you press the "Generate Ligand" button your ligand will be prepared for docking and appears in the right list. Alternatively to loading a ligand via PyMOL you can choose an entire directory containing compounds in .pdb or .mol2 format. Use the "Import" button to read all compounds in the directory and use the "Generate All" button to prepare each compound for the docking run.\n"""
transfer_docking_text = {}
docking_text = """
This is the docking page. You have to select a receptor and whether you want to use flexible sidechains. You may either dock a single ligand from the list above or all ligands you have prepared. If you use Autodock4 you have to calculate a grid before you can start the actual docking run. Just press "Run AutoGrid" and wait until its finished and then press the "Run AutoDock" button. The generated grid maps can be loaded into PyMOL on the "Grid Maps" page. If you use vina you don't have to calculate a grid. Just press "Run VINA" and wait until it is finished.You can load the generated docking poses into PyMOL on the "View Poses" page\n"""
transfer_docking_text['log'] = docking_text
transfer_docking_text['line_count'] = 0
transfer_docking_text['old_line_count'] = 0
pdb_format="%6s%5d %-4s%1s%3s%2s%4d %11.3f %7.3f %7.3f %5.2f %5.2f"
# get a temporary file directory
if not sys.platform.startswith('win'):
home = os.environ.get('HOME')
else:
home = os.environ.get('PYMOL_PATH')
tmp_dir = os.path.join(home,'.ADplugin')
if not os.path.isdir(tmp_dir):
os.mkdir(tmp_dir)
print "Created temporary files directory: %s" % tmp_dir
default_settings = {
"grid_spacing" : '0.375',
"n_points_X":'60',
"n_points_Y":'60',
"n_points_Z":'60',
"grid_center_selection":'(all)',
"grid_center_X":'0',
"grid_center_Y":'0',
"grid_center_Z":'0',
"dx":'1.0',
"dy":'1.0',
"dz":'1.0',
"box_cylinder_size":'0.2',
"box_mesh_line_width":'1',
"box_mesh_grid_size":'1',
"box_file_name":'box.dat',
"gpf_file_name":'grid.gpf',
"config_file_name":'config.txt',
"rank_dat_file_name":'scores.dat',
"rank_csv_file_name":'scores.csv',
"rank_pose_file_name":'poses.pdb',
"dlg_input_file":'docked.pdbqt',
"map_input_file":'receptor.C.map',
"map_threshold":5.
}
BOX_AS_BOX = 0
BOX_AS_WIREBOX = 1
GRID_CENTER_FROM_SELECTION = 0
GRID_CENTER_FROM_COORDINATES = 1
#==========================================================================
#
# THREAD CLASSES FOR SPAWNING DOCKING JOBS
class Thread_run(Thread):
def __init__ (self,command, previous = None, status_line = None, log_text = None, outlog = None):
Thread.__init__(self)
self.command = command
self.status = -1
self.previous = previous
self.status_line = status_line
self.log_text = log_text
self.outlog = outlog
def run(self):
if self.previous:
self.previous.join()
print "Starting run of ", self.command
self.status, output = getstatusoutput(self.command)
if (self.outlog):
self.outlog[log] = output
class Thread_log(Thread):
def __init__(self, logfile, mythread, timeout):
Thread.__init__(self)
self.logfile = logfile.replace("\\","/")
print "logfile",logfile
print "self.logfile",self.logfile
self.mythread = mythread
self.timeout = timeout
def run(self):
global transfer_status
global transfer_docking_text
if not os.environ.has_key('ADPLUGIN_NO_OUTPUT_REDIRECT'):
seconds = 0
readcount = 0
if platform.system().lower() == "windows":
while self.mythread.is_alive() and seconds < self.timeout:
sleep(2)
seconds = seconds+2
transfer_status['log'] = 'Running for %d seconds'%seconds
seconds = self.timeout
while self.mythread.is_alive() and seconds < self.timeout:
if os.path.getsize(self.logfile) > readcount+20:
f = open(self.logfile,'r')
f.seek(readcount,0)
while readcount < os.path.getsize(self.logfile):
logline = f.readline()
if not logline: break
print logline,
transfer_status['log'] = logline
transfer_status['line_count'] = transfer_status['line_count']+1;
page_text = transfer_docking_text['log'];
transfer_docking_text['log'] = page_text+logline
transfer_docking_text['line_count'] = transfer_docking_text['line_count']+1
readcount = f.tell()
f.close()
seconds = seconds+10
sleep(10)
transfer_status['log'] = 'Running for %d seconds'%seconds
sleep(5)
if os.path.getsize(self.logfile) > 0:
f = open(self.logfile,'r')
f.seek(readcount,0)
while readcount < os.path.getsize(self.logfile):
logline = f.readline()
if not logline: break
print logline,
page_text = transfer_docking_text['log'];
transfer_docking_text['log'] = page_text+logline
transfer_docking_text['line_count'] = transfer_docking_text['line_count']+1
readcount = f.tell()
f.close()
if not self.mythread.is_alive():
transfer_status['log']="Done!!!"
transfer_status['line_count'] = transfer_status['line_count']+1;
else:
line = 'LOG FILE OUTPUT NOT REDIRECTED'
page_text = transfer_docking_text['log'];
transfer_docking_text['log'] = page_text+line
transfer_docking_text['line_count'] = transfer_docking_text['line_count']+1
#==========================================================================
#
# CLASSES FOR HANDLING AUTODOCK FILES
class ADModel:
""" STORAGE CLASS FOR DOCKED LIGANDS """
def __init__(self, lst = None):
self.atomlines = []
self.energy = 0.
self.name = ''
self.poseN = 0
self.info = ''
self.lst = []
self.num = 0
self.as_string = ''
if lst is not None:
self.from_list(lst)
def from_list(self, lst):
self.lst = lst
for line in lst:
self.info+=line
if line.startswith('ATOM') or \
line.startswith('HETATM'):
self.atomlines.append(line)
self.as_string+='ATOM '+line[6:67]+'\n'
elif line.startswith('USER'):
if 'Free Energy of Binding' in line:
entr = line.split('=')[1]
self.energy = float(entr.split()[0])
elif line.startswith('REMARK'):
if 'VINA RESULT' in line:
entr = line.split(':')[1]
self.energy = float(entr.split()[0])
def as_pdb_string(self):
return self.as_string
def info_string(self):
return self.info
#---------------------------------------------------------------------------
class ADGridMap:
""" CLASS FOR HANDLING AUTODOCK GRID MAP FILES"""
def __init__(self, fp = None, name = 'map'):
self.name = ''
self.npts = [0,0,0]
self.n = [0,0,0]
self.center = [0,0,0]
self.origin = [0,0,0]
self.nelem = 0
self.spacing = 0.
self.values = []
self.datafile = ''
self.molecule = ''
self.paramfile = ''
self.precision = 0.0001
if fp is not None:
self.read(fp,name)
def read(self,fp,name='map'):
self.name = name
for i in range(6):
line = fp.readline()
if i == 0:
self.paramfile = line.split()[1]
elif i == 1:
self.datafile = line.split()[1]
elif i == 2:
self.molecule = line.split()[1]
elif i == 3:
self.spacing = float(line.split()[1])
elif i == 4:
self.npts = [int(x) for x in line.split()[1:]]
elif i == 5:
self.center = [float(x) for x in line.split()[1:]]
for i in range(3):
self.n[i] = self.npts[i]+1
self.nelem=self.n[0]*self.n[1]*self.n[2]
i = 0
while i < self.nelem:
val = float(fp.readline())
self.values.append(val)
i+=1
for i in range(3):
self.origin[i] = self.center[i]-self.npts[i]/2*self.spacing
def meta(self):
s= 'GRID_PARAMETER_FILE %s\n' % self.paramfile + \
'GRID_DATA_FILE %s\n' % self.datafile +\
'MACROMOLECULE %s\n' % self.molecule +\
'SPACING %4.3f\n' % self.spacing +\
'NELEMENTS %d %d %d\n' % (self.npts[0],self.npts[1],self.npts[2]) +\
'CENTER %5.3f %5.3f %5.3f\n' % (self.center[0],self.center[1],self.center[2])
return s
def write(self,fp):
print >>fp, 'GRID_PARAMETER_FILE %s' % self.paramfile
print >>fp, 'GRID_DATA_FILE %s' % self.datafile
print >>fp, 'MACROMOLECULE %s' % self.molecule
print >>fp, 'SPACING %4.3f' % self.spacing
print >>fp, 'NELEMENTS %d %d %d' % (self.npts[0],self.npts[1],self.npts[2])
print >>fp, 'CENTER %5.3f %5.3f %5.3f' % (self.center[0],self.center[1],self.center[2])
for x in self.values:
if abs(x) < self.precision:
print >>fp, '0.'
else:
print >>fp, '%.3f' % x
def writeDX(self,fname):
fp = open(fname,'w')
nx = self.n[0]
ny = self.n[1]
nz = self.n[2]
ori = self.origin
spacing = self.spacing
vals = self.values
print >>fp,'#=================================='
print >>fp,'# AutoGrid Map File: %s' % self.name
print >>fp,'# Receptor File Name: %s' % self.molecule
print >>fp,'#=================================='
print >>fp,'object 1 class gridpositions counts %d %d %d' % (nx,ny,nz)
print >>fp,'origin %12.5E %12.5E %12.5E' % (ori[0],ori[1],ori[2])
print >>fp,'delta %12.5E %12.5E %12.5E' % (spacing,0,0)
print >>fp,'delta %12.5E %12.5E %12.5E' % (0,spacing,0)
print >>fp,'delta %12.5E %12.5E %12.5E' % (0,0,spacing)
print >>fp,'object 2 class gridconnections counts %d %d %d' % (nx,ny,nz)
print >>fp,'object 3 class array type double rank 0 items %d data follows' % len(vals)
for k in range(nz):
col=0;
for j in range(ny):
for i in range(nx):
fp.write(" %12.5E" % vals[i*ny*nz + j*nz + k])
col+=1;
if col==3:
print >>fp
col=0
print >>fp,'attribute \"dep\" string \"positions\"'
print >>fp,'object \"regular positions regular connections\" class field'
print >>fp,'component \"positions\" value 1'
print >>fp,'component \"connections\" value 2'
print >>fp,'component \"data\" value 3'
fp.close()
#==========================================================================
#
# CLASSES FOR INTERNAL HANDLING OF RECEPTORS AND LIGANDS
class Receptor:
"""CONTAINS ALL INFORMATION ABOUT A DEFINED RECEPTOR"""
def __init__(self):
self.selection = ''
self.pdb_file = ''
self.receptor_pdbqt = ''
self.receptor_rigid = ''
self.receptor_flexible = ''
self.flexible_residues = {}
self.resi_dic = {}
def flex_res_string(self):
flex_res_str = ''
spacer = os.path.basename(self.receptor_pdbqt)[:-6]
for key, val in self.flexible_residues.items():
s = ''
lst = []
for idx, resname in val:
lst.append( resname + str(idx) )
s+=':'+key+':'+'_'.join(lst)
print "adding '"+spacer+':'+key+':'+'_'.join(lst)+"' to flex_res_str"
flex_res_str+=(spacer + s)
spacer = ','+os.path.basename(self.receptor_pdbqt)[:-6]
return flex_res_str
## lst = []
## for idx, resname in self.flexible_residues:
## lst.append( resname+str(idx) )
## return '_'.join(lst)
def info(self):
s= '#===============================================\n'
s+=' > Receptor : "%s"\n' % self.selection
s+=' > Generated from pdb file : "%s"\n' % self.pdb_file
s+=' > Receptor file : "%s"\n' % self.receptor_pdbqt
s+=' > Receptor rigid : "%s"\n' % self.receptor_rigid
s+=' > Receptor flexible : "%s"\n' % self.receptor_flexible
# s+=' > Number of flex. residues : %d\n' % len(self.flexible_residues)
s+='#===============================================\n'
return s
class Ligand:
"""CONTAINS ALL INFORMATION ABOUT A LIGAND"""
def __init__(self):
self.name = ''
self.selection = ''
self.input_file = ''
self.ligand_pdbqt = ''
self.outfile_poses = ''
def info(self):
s= '#=============================================\n'
s+=' > Ligand : %s\n' % self.name
s+=' > Generated from file : %s\n' % self.input_file
s+=' > Ligand pdbqt file : %s\n' % self.ligand_pdbqt
s+=' > Poses output file : %s\n' % self.outfile_poses
s+='#=============================================\n'
return s
#==========================================================================
#
# THE MAJOR, PRETTY BIG PLUGIN CLASS
class Autodock:
""" THE MAJOR PLUGIN CLASS """
def __init__(self,app):
global transfer_docking_text
global global_status
global adplugin_font
parent = app.root
self.parent = parent
# receptors and ligands
self.receptor_dic = {}
self.ligand_dic = {}
# directory with ligands
self.ligand_dir = StringVar()
# box display settings
self.box_display_mode = IntVar()
self.box_display_mode.set(BOX_AS_BOX)
self.box_color = [1.,1.,1.]
self.box_is_on_display = False
self.box_display_cylinder_size = DoubleVar()
self.box_display_cylinder_size.set(default_settings['box_cylinder_size'])
self.box_display_line_width = DoubleVar()
self.box_display_line_width.set(default_settings['box_mesh_line_width'])
self.box_display_mesh_grid = DoubleVar()
self.box_display_mesh_grid.set(default_settings['box_mesh_grid_size'])
self.box_size = []
# grid definition
self.grid_spacing = DoubleVar()
self.grid_spacing.set(default_settings['grid_spacing'])
self.n_points_X = DoubleVar()
self.n_points_X.set(default_settings['n_points_X'])
self.n_points_Y = DoubleVar()
self.n_points_Y.set(default_settings['n_points_Y'])
self.n_points_Z = DoubleVar()
self.n_points_Z.set(default_settings['n_points_Z'])
self.grid_center = [DoubleVar(), DoubleVar(), DoubleVar()]
self.grid_center[0].set(default_settings['grid_center_X'])
self.grid_center[1].set(default_settings['grid_center_Y'])
self.grid_center[2].set(default_settings['grid_center_Z'])
# paths to executables, working files, etc.
self.config_settings = {}
self.autodock_tools_path = StringVar()
self.autogrid_exe = StringVar()
self.autodock_exe = StringVar()
self.vina_exe = StringVar()
self.work_path_location = StringVar()
# ligand display settings
self.ligand_display_mode = {
'lines':True,
'sticks':False,
'spheres':False,
'surface':False,
'mesh':False
}
# keep in mind what threads are running
self.current_thread = None
# build main window
self.dialog = Pmw.Dialog(parent,
buttons = ('Exit',),
title = 'PyMOL Autodock/Vina Plugin',
command = self.button_pressed)
self.dialog.withdraw()
Pmw.setbusycursorattributes(self.dialog.component('hull'))
self.status_line = Label(self.dialog.interior(),
relief='sunken',
font=adplugin_font, anchor='w',fg='yellow',bg='black')
self.status_line.pack(side=BOTTOM,fill='x', expand=1, padx=0, pady=0)
self.status_line.configure(textvariable=global_status)
self.dialog.geometry('650x780')
self.dialog.bind('<Return>',self.button_pressed)
# the title
self.title_label = Tkinter.Label(self.dialog.interior(),
text = 'PyMOL Autodock/Vina Plugin -- Daniel Seeliger (rev 28 Mar 15) -- <http://wwwuser.gwdg.de/~dseelig>',
background = 'navy',
foreground = 'white',
)
self.title_label.pack(expand = 0, fill = 'both', padx = 4, pady = 4)
# the basic notebook
self.notebook = Pmw.NoteBook(self.dialog.interior())
self.notebook.pack(fill='both',expand=1,padx=3,pady=3)
# build pages
self.configuration_page = self.notebook.add('Configuration')
self.grid_definition_page = self.notebook.add('Grid Settings')
self.receptor_preparation_page = self.notebook.add('Receptor')
self.ligand_preparation_page = self.notebook.add('Ligands')
self.docking_page = self.notebook.add('Docking')
self.pose_viewer_page = self.notebook.add('View Poses')
self.rank_page = self.notebook.add('Score/Rank')
self.map_viewer_page = self.notebook.add('Grid Maps')
#---------------------------------------------------------------
# GRID DEFINITION PAGE
self.grid_page_main_group = Pmw.Group(self.grid_definition_page, tag_text='Grid Definition')
self.grid_page_main_group.pack(fill = 'both', expand = 0, padx=10, pady=5)
# grid parameters on the left
self.grid_page_left_side = Pmw.Group(self.grid_page_main_group.interior(),tag_text = 'Parameters')
self.grid_page_left_side.pack(side = LEFT, fill = 'both',expand = 0, padx = 10, pady = 3)
# grid spacing entry
self.grid_spacing_frame = Tkinter.Frame(self.grid_page_left_side.interior())
self.grid_spacing_label = Label(self.grid_spacing_frame, text='Spacing:', width = 10)
self.grid_spacing_location = Entry(self.grid_spacing_frame, textvariable= self.grid_spacing, bg='black',fg='green', width = 10)
self.grid_spacing_scrollbar = Scrollbar(self.grid_spacing_frame, orient = 'horizontal', command = self.grid_spacing_changed)
self.grid_spacing_label.pack(side = LEFT, anchor='w')
self.grid_spacing_location.pack(side = LEFT, anchor='w')
self.grid_spacing_scrollbar.pack(side = LEFT, anchor='w')
self.grid_spacing_frame.pack(fill = 'x', padx = 4, pady=1)
# n grid points entries
self.n_points_X_frame = Tkinter.Frame(self.grid_page_left_side.interior())
self.n_points_X_label = Label(self.n_points_X_frame, text='X-points:', width = 10)
self.n_points_X_location = Entry(self.n_points_X_frame, textvariable= self.n_points_X, bg='black',fg='green', width = 10)
self.n_points_X_scrollbar = Scrollbar(self.n_points_X_frame, orient = 'horizontal', command = self.n_points_X_changed)
self.n_points_X_label.pack(side = LEFT, anchor='w')
self.n_points_X_location.pack(side = LEFT, anchor='w')
self.n_points_X_scrollbar.pack(side = LEFT, anchor='w')
self.n_points_X_frame.pack(fill = 'x', padx = 4, pady=1)
self.n_points_Y_frame = Tkinter.Frame(self.grid_page_left_side.interior())
self.n_points_Y_label = Label(self.n_points_Y_frame, text='Y-points:', width = 10)
self.n_points_Y_location = Entry(self.n_points_Y_frame, textvariable= self.n_points_Y, bg='black',fg='green', width = 10)
self.n_points_Y_scrollbar = Scrollbar(self.n_points_Y_frame, orient = 'horizontal', command = self.n_points_Y_changed)
self.n_points_Y_label.pack(side = LEFT, anchor='w')
self.n_points_Y_location.pack(side = LEFT, anchor='w')
self.n_points_Y_scrollbar.pack(side = LEFT, anchor='w')
self.n_points_Y_frame.pack(fill = 'x', padx = 4, pady=1)
self.n_points_Z_frame = Tkinter.Frame(self.grid_page_left_side.interior())
self.n_points_Z_label = Label(self.n_points_Z_frame, text='Z-points:', width = 10)
self.n_points_Z_location = Entry(self.n_points_Z_frame, textvariable= self.n_points_Z, bg='black',fg='green', width = 10)
self.n_points_Z_scrollbar = Scrollbar(self.n_points_Z_frame, orient = 'horizontal', command = self.n_points_Z_changed)
self.n_points_Z_label.pack(side = LEFT, anchor='w')
self.n_points_Z_location.pack(side = LEFT, anchor='w')
self.n_points_Z_scrollbar.pack(side = LEFT, anchor='w')
self.n_points_Z_frame.pack(fill = 'x', padx = 4, pady=1)
Pmw.alignlabels( [self.grid_spacing_label,
self.n_points_X_label,
self.n_points_Y_label,
self.n_points_Z_label
])
Pmw.alignlabels( [self.grid_spacing_location,
self.n_points_X_location,
self.n_points_Y_location,
self.n_points_Z_location
])
# display option buttons
self.display_button_box = Pmw.ButtonBox(self.grid_page_main_group.interior(), padx=0, pady=1,orient='vertical')
self.display_button_box.pack(side=LEFT)
self.display_button_box.add('Show Box',command = self.show_box)
self.display_button_box.add('Hide Box',command = self.hide_box)
self.display_button_box.add('Change Box Color',command = self.change_box_color)
# display options on the right
self.grid_page_right_side = Pmw.Group(self.grid_page_main_group.interior(), tag_text = 'Display Options')
self.grid_page_right_side.pack(side = LEFT, fill = 'both', expand = 0, padx = 10, pady = 3)
self.box_display_radiogroups = []
self.box_display_radioframe = Tkinter.Frame(self.grid_page_right_side.interior())
self.box_display_cylinder_frame = Pmw.Group(self.box_display_radioframe,
tag_pyclass = Tkinter.Radiobutton,
tag_text = 'Cylindric Box',
tag_value = 0,
tag_variable = self.box_display_mode
)
self.box_display_cylinder_frame.pack(fill='x',expand = 1,side=TOP)
self.box_display_radiogroups.append(self.box_display_cylinder_frame)
self.box_display_cylinder_size_frame = Tkinter.Frame(self.box_display_cylinder_frame.interior())
self.box_display_cylinder_size_label = Label(self.box_display_cylinder_size_frame, text = 'Size:', width=10)
self.box_display_cylinder_size_location = Entry(self.box_display_cylinder_size_frame,
textvariable = self.box_display_cylinder_size,
bg = 'black',fg = 'green', width = 10)
self.box_display_cylinder_size_scrollbar = Scrollbar(self.box_display_cylinder_size_frame,
orient = 'horizontal',command = self.box_display_cylinder_size_changed)
self.box_display_cylinder_size_label.pack(side = LEFT)
self.box_display_cylinder_size_location.pack(side = LEFT)
self.box_display_cylinder_size_scrollbar.pack(side = LEFT)
self.box_display_cylinder_size_frame.pack(fill='x',padx = 4, pady=1)
self.box_display_wire_frame = Pmw.Group(self.box_display_radioframe,
tag_pyclass = Tkinter.Radiobutton,
tag_text = 'Wired Box',
tag_value = 1,
tag_variable = self.box_display_mode
)
self.box_display_wire_frame.pack(fill='x',expand = 1)
self.box_display_radiogroups.append(self.box_display_wire_frame)
self.box_display_mesh_line_width_frame = Tkinter.Frame(self.box_display_wire_frame.interior())
self.box_display_mesh_line_width_label = Label(self.box_display_mesh_line_width_frame, text = 'Line Width:', width=10)
self.box_display_mesh_line_width_location = Entry(self.box_display_mesh_line_width_frame,
textvariable = self.box_display_line_width,
bg='black', fg='green',width = 10)
self.box_display_mesh_line_width_scrollbar = Scrollbar(self.box_display_mesh_line_width_frame,
orient = 'horizontal',command = self.box_display_line_width_changed)
self.box_display_mesh_line_width_label.pack(side = LEFT)
self.box_display_mesh_line_width_location.pack(side = LEFT)
self.box_display_mesh_line_width_scrollbar.pack(side = LEFT)
self.box_display_mesh_line_width_frame.pack(fill='x',padx=4,pady=1)
self.box_display_mesh_grid_frame = Tkinter.Frame(self.box_display_wire_frame.interior())
self.box_display_mesh_grid_label = Label(self.box_display_mesh_grid_frame, text = 'Grid Size:', width=10)
self.box_display_mesh_grid_location = Entry(self.box_display_mesh_grid_frame,
textvariable = self.box_display_mesh_grid,
bg='black', fg='green',width = 10)
self.box_display_mesh_grid_scrollbar = Scrollbar(self.box_display_mesh_grid_frame,
orient = 'horizontal',command = self.box_display_mesh_grid_changed)
self.box_display_mesh_grid_label.pack(side = LEFT)
self.box_display_mesh_grid_location.pack(side = LEFT)
self.box_display_mesh_grid_scrollbar.pack(side = LEFT)
self.box_display_mesh_grid_frame.pack(fill='x',padx=4,pady=1)
self.box_display_radioframe.pack(padx = 6, pady = 6, expand='yes', fill='both')
Pmw.aligngrouptags( self.box_display_radiogroups )
# grid center definition
self.grid_center_radiogroups = []
self.grid_center_selection_mode = IntVar()
self.grid_center_selection_mode.set(GRID_CENTER_FROM_SELECTION)
self.grid_center_radioframe = Tkinter.Frame(self.grid_definition_page)
self.grid_center_radio_button_pymol_selection = Pmw.Group(self.grid_center_radioframe,
tag_pyclass = Tkinter.Radiobutton,
tag_text = 'Calculate Grid Center by Selection',
tag_value = GRID_CENTER_FROM_SELECTION,
tag_variable = self.grid_center_selection_mode
)
self.grid_center_radio_button_pymol_selection.pack(fill = 'x', expand = 1, side = TOP)
self.grid_center_radiogroups.append(self.grid_center_radio_button_pymol_selection)
self.grid_center_selection_entry = Pmw.EntryField(self.grid_center_radio_button_pymol_selection.interior(),
labelpos = 'w',
label_text = 'Selection',
value = default_settings['grid_center_selection'],
command = self.grid_center_from_selection_changed
)
self.grid_center_selection_entry.pack(fill='x',padx=4,pady=1,expand=0)
self.grid_center_radio_button_coordinates = Pmw.Group(self.grid_center_radioframe,
tag_pyclass = Tkinter.Radiobutton,
tag_text = 'Grid Center Coordinates',
tag_value = GRID_CENTER_FROM_COORDINATES,
tag_variable = self.grid_center_selection_mode
)
self.grid_center_radio_button_coordinates.pack(fill = 'x', expand = 1, side = TOP)
self.grid_center_radiogroups.append(self.grid_center_radio_button_coordinates)
self.grid_center_radioframe.pack(padx = 6, pady = 6, expand='yes', fill='both')
Pmw.aligngrouptags(self.grid_center_radiogroups)
self.grid_center_X_frame = Tkinter.Frame(self.grid_center_radio_button_coordinates.interior())
self.grid_center_X_label = Label(self.grid_center_X_frame, text = 'X:')
self.grid_center_X_location = Entry(self.grid_center_X_frame, textvariable = self.grid_center[0], bg='black', fg='green', width=10)
self.grid_center_X_scrollbar = Scrollbar(self.grid_center_X_frame,orient='horizontal',command = self.grid_center_X_changed)
self.grid_center_Y_frame = Tkinter.Frame(self.grid_center_radio_button_coordinates.interior())
self.grid_center_Y_label = Label(self.grid_center_Y_frame, text = 'Y:')
self.grid_center_Y_location = Entry(self.grid_center_Y_frame, textvariable = self.grid_center[1], bg='black', fg='green', width=10)
self.grid_center_Y_scrollbar = Scrollbar(self.grid_center_Y_frame,orient='horizontal',command = self.grid_center_Y_changed)
self.grid_center_Z_frame = Tkinter.Frame(self.grid_center_radio_button_coordinates.interior())
self.grid_center_Z_label = Label(self.grid_center_Z_frame, text = 'Z:')
self.grid_center_Z_location = Entry(self.grid_center_Z_frame, textvariable = self.grid_center[2], bg='black', fg='green', width=10)
self.grid_center_Z_scrollbar = Scrollbar(self.grid_center_Z_frame,orient='horizontal',command = self.grid_center_Z_changed)
self.grid_center_X_label.pack(side = LEFT)
self.grid_center_X_location.pack(side=LEFT)
self.grid_center_X_scrollbar.pack(side=LEFT)
self.grid_center_X_frame.pack(side=LEFT,padx=4,pady=1)
self.grid_center_Y_label.pack(side = LEFT)
self.grid_center_Y_location.pack(side=LEFT)
self.grid_center_Y_scrollbar.pack(side=LEFT)
self.grid_center_Y_frame.pack(side=LEFT,padx=4,pady=1)
self.grid_center_Z_label.pack(side = LEFT)
self.grid_center_Z_location.pack(side=LEFT)
self.grid_center_Z_scrollbar.pack(side=LEFT)
self.grid_center_Z_frame.pack(side=LEFT,padx=4,pady=1)
self.select_binding_site_button_box = Pmw.ButtonBox(self.grid_center_radio_button_coordinates.interior(),orient='horizontal', padx=0,pady=0)
self.select_binding_site_button_box.add('Select binding site',command = self.select_atoms_within_binding_site)
self.select_binding_site_button_box.pack(side=TOP,expand = 1, padx = 3, pady = 3)
# load/write gpf
self.gpf_file_io = Pmw.Group(self.grid_definition_page, tag_text='GPF File')
self.gpf_file_io.pack(side = TOP,expand=1, fill='x')
self.gpf_file_location = Pmw.EntryField(self.gpf_file_io.interior(),
labelpos = 'w',
label_pyclass = FileDialogButtonClassFactory.get(self.set_gpf_filename,mode='w',filter=[("Grid Parameter File","*.gpf")]),
validate = {'validator':quickFileValidation,},
value = default_settings['gpf_file_name'],
label_text = 'Autodock GPF File:')
self.gpf_file_location.pack(side=LEFT,fill = 'x', expand = 1, padx = 1, pady = 2)
self.gpf_button_box = Pmw.ButtonBox(self.gpf_file_io.interior(),orient='horizontal', padx=0,pady=0)
self.gpf_button_box.add('Load',command = self.load_gpf_file)
self.gpf_button_box.add('Save',command = self.save_gpf_file)
self.gpf_button_box.pack(side=BOTTOM,expand = 1, padx = 10, pady = 2)
# load/write vina config file
self.config_file_io = Pmw.Group(self.grid_definition_page, tag_text='Config File')
self.config_file_io.pack(side = TOP,expand=1, fill='x')
self.config_file_location = Pmw.EntryField(self.config_file_io.interior(),
labelpos = 'w',
label_pyclass = FileDialogButtonClassFactory.get(self.set_config_filename,mode='w',filter=[("Vina Config File","*.txt")]),
validate = {'validator':quickFileValidation,},
value = default_settings['config_file_name'],
label_text = 'VINA config File:')
self.config_file_location.pack(side=LEFT,fill = 'x', expand = 1, padx = 1, pady = 2)
self.config_button_box = Pmw.ButtonBox(self.config_file_io.interior(), padx=0, pady=0,orient='horizontal')
self.config_button_box.pack(side=BOTTOM,expand = 1, padx = 10, pady = 2)
self.config_button_box.add('Load',command = self.load_config_file)
self.config_button_box.add('Save',command = self.save_config_file)
#------------------------------------------------------------------
#
# PLUGIN CONFIGURATION PAGE
self.configuration_top_group = Pmw.Group(self.configuration_page,tag_text='General Notes')
self.configuration_top_group.pack(fill = 'both', expand = 0, padx = 10, pady = 5)
myfont = Pmw.logicalfont(name=adplugin_font[0],size=int(adplugin_font[1]))
self.text_field = Pmw.ScrolledText(self.configuration_top_group.interior(),
borderframe=5,
vscrollmode='dynamic',
hscrollmode='dynamic',
labelpos='n',
text_width=150, text_height=15,
text_wrap='word',
text_background='#000000',
text_foreground='green',
text_font = myfont
)
self.text_field.pack(expand = 0, fill = 'both', padx = 4, pady = 4)
self.text_field.insert('end',intro_text)
self.configuration_group = Pmw.Group(self.configuration_page,tag_text='Scripts and Program Paths')
self.configuration_group.pack(fill = 'both', expand = 0, padx = 10, pady = 2)
self.config_settings = self.read_plugin_config_file()
self.autodock_tools_location = Pmw.EntryField(self.configuration_group.interior(),
labelpos='w',
label_pyclass = DirDialogButtonClassFactory.get(self.set_autodock_tools_path),
value = self.config_settings['autodock_tools_path'],
label_text = 'AutoDockTools:')
self.autogrid_location = Pmw.EntryField(self.configuration_group.interior(),
labelpos='w',
label_pyclass = FileDialogButtonClassFactory.get(self.set_autogrid_location),
value = self.config_settings['autogrid_exe'],
label_text = 'autogrid4 executable:')
self.autodock_location = Pmw.EntryField(self.configuration_group.interior(),
labelpos='w',
label_pyclass = FileDialogButtonClassFactory.get(self.set_autodock_location),
value = self.config_settings['autodock_exe'],
label_text = 'autodock4 executable:')
self.vina_location = Pmw.EntryField(self.configuration_group.interior(),
labelpos='w',
label_pyclass = FileDialogButtonClassFactory.get(self.set_vina_location),
value = self.config_settings['vina_exe'],
label_text = 'vina executable:')
self.work_path_location = Pmw.EntryField(self.configuration_group.interior(),
labelpos='w',
label_pyclass = DirDialogButtonClassFactory.get(self.set_work_path_location),
value = self.config_settings['work_path_location'],
label_text = 'Working Directory:')
for x in [self.autodock_tools_location,
self.autogrid_location,
self.autodock_location,
self.vina_location,
self.work_path_location
]:
x.pack(fill = 'both', expand = 1, padx = 10, pady = 2)
Pmw.alignlabels( [self.autodock_tools_location,
self.autogrid_location,
self.autodock_location,
self.vina_location,
self.work_path_location
] )
self.config_button_box = Pmw.ButtonBox(self.configuration_page, padx=0, pady=0,orient='horizontal')
self.config_button_box.pack(fill='both',expand = 1, padx = 10, pady = 5)
self.config_button_box.add('Save Plugin Configuration File',command = self.save_plugin_config_file)
#------------------------------------------------------------------
#
# RECEPTOR PREPARATION PAGE
self.receptor_preparation_top_group = Pmw.Group(self.receptor_preparation_page, tag_text='Selections')
self.receptor_preparation_top_group.pack(fill = 'both', expand = 0, padx=10, pady=5)
self.receptor_import_selection_button_box = Pmw.ButtonBox(self.receptor_preparation_top_group.interior(),orient='vertical', padx=0,pady=0)
self.receptor_import_selection_button_box.add('Import Selections',command = self.import_selections)
self.receptor_import_selection_button_box.pack(side=LEFT, fill='x', padx = 0, pady = 3)
self.receptor_pdbqt_location = Pmw.EntryField(self.receptor_preparation_top_group.interior(),
labelpos = 'w',
label_pyclass = FileDialogButtonClassFactory.get(self.set_receptor_pdbqt_location,filter=[("PDBQT File","*.pdbqt")]),
validate = {'validator':quickFileValidation,},
value = '',
label_text = 'Receptor:')
self.receptor_pdbqt_location.pack(side=LEFT,fill = 'x', expand = 1, padx = 1, pady = 5)
self.receptor_button_box = Pmw.ButtonBox(self.receptor_preparation_top_group.interior(), padx=0, pady=0,orient='horizontal')
self.receptor_button_box.pack(side=BOTTOM,expand = 1, padx = 10, pady = 5)
self.receptor_button_box.add('Load',command = self.load_receptor_pdbqt)
self.receptor_preparation_center_group = Pmw.Group(self.receptor_preparation_page, tag_text='Receptor Preparation')
self.receptor_preparation_center_group.pack(fill = 'both', expand = 0, padx=10, pady=5)
self.selection_list = Pmw.ComboBox(self.receptor_preparation_center_group.interior(),
scrolledlist_items=cmd.get_names("selections")+cmd.get_names(),
labelpos='nw',
label_text='PyMOL Selections',
listbox_height = 10,
selectioncommand=self.selectionCommand,
dropdown=False
)
self.receptor_list = Pmw.ComboBox(self.receptor_preparation_center_group.interior(),
scrolledlist_items=[],
labelpos='nw',
label_text='Receptors',
listbox_height = 10,
selectioncommand=self.selected_receptor,
dropdown=False
)
self.flexible_residues_list = Pmw.ScrolledListBox(self.receptor_preparation_center_group.interior(),
items=[],
labelpos='nw',
label_text='Flexible Residues',
listbox_height = 11,