-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path__init__.py
1452 lines (1320 loc) · 75.7 KB
/
__init__.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
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
# This Python 3.x file uses the following encoding: utf-8
# Smina-plugin for PyMol 3.x (Windows version avec WSL2) Copyright Notice.
# ====================================================================
#
# The smina-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.
#
# ----------------------------------------------------------------------
# Smina plugin is Copyright (C) 2020 by Goetz Parsiegla
#
# 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 Goetz Parsiegla not be used in advertising or publicity
# pertaining to distribution of the software without specific, written
# prior permission.
#
# GOETZ PARSIEGLA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS. IN NO EVENT SHALL GOETZ PARSIEGLA 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.
# ----------------------------------------------------------------------
#
# Executes smina for molecular docking.
# If you find bugs or have any suggestions for future versions contact me:
import sys
import os
import time
# pymol.Qt is a wrapper which provides the PySide2/Qt5/Qt4 interface
# if it has been installed in python before !
from pymol.Qt import QtWidgets, QtCore
from pymol import cmd
from glob import glob
from pymol.cgo import *
from pymol.vfont import plain
__version__ = "0.9.8.0"
def __init_plugin__(app=None):
'''
Add an entry to the PyMOL "Plugin" menu
'''
from pymol.plugins import addmenuitemqt
addmenuitemqt('Smina', run_plugin_gui)
# global reference to avoid garbage collection of our dialog
dialog = None
def run_plugin_gui():
global dialog
if dialog is None:
dialog = QtWidgets.QDialog() # now global dialog holds a Qtobject
# filename of our UI file
uifile = os.path.join(os.path.dirname(__file__), 'form.ui')
# load the UI file into our dialog
from pymol.Qt.utils import loadUi
form = loadUi(uifile, dialog)
Smina(form) # call the plugin class and pass the form as an argument
dialog.show()
# --------------- Plugin code starts here --------------------
class Smina:
def __init__(self, form):
self.form = form
# get a temporary file directory
if not sys.platform.startswith('win'):
home = os.environ.get('HOME')
else:
home = os.environ.get('HOMEPATH')
tmp_dir = os.path.join(home,'.PyMol_plugin')
if not os.path.isdir(tmp_dir):
os.mkdir(tmp_dir)
print("Created temporary files directory: %s" % tmp_dir)
# Assign variables to lineEdits and spinBoxes
statusline = self.form.lineEdit
self.smina_location = self.form.lineEdit_2
self.openbabel_location = self.form.lineEdit_3
self.ligand_dir_location = self.form.lineEdit_4
self.scoring_table_dir_location = self.form.lineEdit_8
self.center_selection = self.form.lineEdit_5
self.form.doubleSpinBox.setMinimum(-1000)
self.form.doubleSpinBox.setMaximum(1000)
self.form.doubleSpinBox_2.setMinimum(-1000)
self.form.doubleSpinBox_2.setMaximum(1000)
self.form.doubleSpinBox_3.setMinimum(-1000)
self.form.doubleSpinBox_3.setMaximum(1000)
self.form.doubleSpinBox_4.setMaximum(14)
self.form.doubleSpinBox_4.setSingleStep(0.1)
self.form.doubleSpinBox_5.setMaximum(0)
self.form.doubleSpinBox_5.setMinimum(-1000000)
self.form.doubleSpinBox_5.setSingleStep(1)
# make Buttongroups
self.Buttongroup_1 = QtWidgets.QButtonGroup()
self.Buttongroup_1.addButton(self.form.radioButton)
self.Buttongroup_1.addButton(self.form.radioButton_2)
self.Buttongroup_2 = QtWidgets.QButtonGroup()
self.Buttongroup_2.addButton(self.form.radioButton_3)
self.Buttongroup_2.addButton(self.form.radioButton_4)
# defaults
self.config_settings = {}
self.smina_config = {}
self.ligand_dir_path = ""
self.scoring_table_dir_path = ""
self.current_flexibles = []
self.form.doubleSpinBox_4.setValue(7.00)
self.current_ligands = []
self.loaded_poses_list = []
self.firstrun = True
self.form.spinBox.setValue(8) # exhaustiveness
self.form.spinBox_2.setValue(9) # maxposes
self.form.spinBox_3.setValue(4) # autobox_buf
self.form.doubleSpinBox_5.setValue(0) # seed
self.scoring_table_file = ""
vinascr = [[-0.035579,'gauss(o=0,_w=0.5,_c=8)'],[-0.005156,'gauss(o=3,_w=2,_c=8)'],\
[0.840245,'repulsion(o=0,_c=8)'],[-0.035069,'hydrophobic(g=0.5,_b=1.5,_c=8)'],\
[-0.587439,'non_dir_h_bond(g=-0.7,_b=0,_c=8)'],[1.923000,'num_tors_div']]
approx_methods_list = ['linear', 'spline', 'exact']
self.scoring_list = vinascr
self.current_poses_list = []
#-----------------------------------------------------------
# Config page
install_text = """
<html><body>This is the PyMol 2.x plugin for smina. It needs at least
Windows 10 build 2004 (The may 2020 update) with the wsl2 (Windows
subsystem for linux version 2) component activated.<br> An Ubuntu >14.04
installation is required to work with smina (18.04. confirmed).<br>You find
instructions to install wsl2 at: <a href="https://docs.microsoft.com/fr-fr/windows/wsl/install-win10">
docs.microsoft.com/fr-fr/windows/wsl/install-win10</a>.<br>
The Openbabel executive (obabel.exe) as well as the smina.static
executive for linux must be located in a Windows directory. You will find
the latest stable version of Openbabel at :<br> <a href="https://github.com/openbabel/openbabel/releases">
github.com/openbabel/openbabel/releases</a>
and smina.static at : <a href="https://sourceforge.net/projects/smina/files/">
sourceforge.net/projects/smina/files/</a>.
</body></html>
"""
def set_statusline(text):
statusline.clear()
statusline.insert(text)
# Config functions
def get_smina_location():
filedialog = QtWidgets.QFileDialog()
filename = filedialog.getOpenFileName(None, "smina.static location", os.getcwd(), 'linux.static files (*.static)')
filename = filename[0]
set_smina_location(filename)
def get_openbabel_location():
filedialog = QtWidgets.QFileDialog()
filename = filedialog.getOpenFileName(None, "obabel.exe location", 'C:\\Program Files', 'exe files (*.exe)')
filename = filename[0]
set_openbabel_location(filename)
def get_ligand_dir_path():
dirdialog = QtWidgets.QFileDialog()
dirname = dirdialog.getExistingDirectory(None, "Ligand directory", os.getcwd())+'/'
set_ligand_dir_path(dirname)
def get_scoring_table_dir_path():
dirdialog = QtWidgets.QFileDialog()
dirname = dirdialog.getExistingDirectory(None, "Scoring-table directory", os.getcwd())+'/'
set_scoring_table_dir_path(dirname)
def set_smina_location(filename):
self.smina_location.clear()
self.smina_location.insert(filename)
self.smina_exe = filename
self.config_settings['smina_exe'] = filename
def set_openbabel_location(filename):
self.openbabel_location.clear()
self.openbabel_location.insert(filename)
self.openbabel_exe = filename
self.config_settings['openbabel_exe'] = filename
def set_ligand_dir_path(dirname):
self.ligand_dir_location.clear()
self.ligand_dir_location.insert(dirname)
self.ligand_dir_path = dirname
self.config_settings['ligand_dir_path'] = dirname
def set_scoring_table_dir_path(dirname):
self.scoring_table_dir_location.clear()
self.scoring_table_dir_location.insert(dirname)
self.scoring_table_dir_path = dirname
self.config_settings['scoring_table_dir_path'] = dirname
def read_plugin_config_file():
config_file_name = os.path.join(tmp_dir,"smina_plugin.conf")
self.config_settings = {}
self.config_settings['smina_exe'] = ''
self.config_settings['openbabel_exe'] = ''
self.config_settings['ligand_dir_path'] = ''
self.config_settings['scoring_table_dir_path'] = ''
if os.path.isfile(config_file_name):
set_statusline('Reading configuration file: %s' % config_file_name)
with open(config_file_name,'r') as f:
lst = f.readlines()
for line in lst:
if line[0]!='#':
entr = line.split('=')
self.config_settings[entr[0].strip()] = entr[1].strip()
set_smina_location(self.config_settings['smina_exe'])
set_openbabel_location(self.config_settings['openbabel_exe'])
set_ligand_dir_path(self.config_settings['ligand_dir_path'])
set_scoring_table_dir_path(self.config_settings['scoring_table_dir_path'])
else:
set_statusline('ERROR : Plugin configuration file not found')
return self.config_settings
def save_plugin_config_file():
config_file_name = os.path.join(tmp_dir,"smina_plugin.conf")
with open(config_file_name,'w') as fp:
print('#========================================', file=fp)
print('# Smina Plugin configuration file', file=fp)
self.config_settings['smina_exe'] = self.smina_location.text()
self.config_settings['openbabel_exe'] = self.openbabel_location.text()
self.config_settings['ligand_dir_path'] = self.ligand_dir_location.text()
self.config_settings['scoring_table_dir_path'] = self.scoring_table_dir_location.text()
for key, val in self.config_settings.items():
print(key, '=', val, file=fp)
set_statusline('Wrote smina-plugin configuration file %s' % config_file_name)
# Run page buildup
self.form.textBrowser.setHtml(install_text)
self.form.textBrowser.setOpenExternalLinks(True)
self.config_settings = read_plugin_config_file()
# Box page
Box_text = """
<html><body>This is the page for the creation of a Box parameter file ('receptor'_config.txt),
containing the coordinates of the Box defining the search space for
docking.<br> * By default a standard box is centered around the COM of the selected receptor.
The box can be centered around a selection of a residue imported from Pymol or entered manually
in the coordinate input spaces.<br> * Existing parameter files for selected receptor objects are
loaded automatically.<br> * An existing parameter file may also be loaded from eleswhere using
'Load config file'.<br>Don't forget to write the current parameter file in the current directory
with 'Write config file' beforre procceding. </body></html>
"""
# Box functions
def read_config_file(filename):
Box_settings = {}
with open(filename, 'r') as f:
lst = f.readlines()
for line in lst:
entr = line.split('=')
Box_settings[entr[0].strip()] = entr[1].strip()
self.form.doubleSpinBox.setValue(float(Box_settings['center_x']))
self.form.doubleSpinBox_2.setValue(float(Box_settings['center_y']))
self.form.doubleSpinBox_3.setValue(float(Box_settings['center_z']))
self.form.spinBox_4.setValue(int(Box_settings['size_x']))
self.form.spinBox_5.setValue(int(Box_settings['size_y']))
self.form.spinBox_6.setValue(int(Box_settings['size_z']))
def load_smina_config_file():
prot = self.form.comboBox_3.currentText()
filename = prot+"_config.txt"
read_config_file(filename)
def load_custom_config_file():
filedialog = QtWidgets.QFileDialog()
filename = filedialog.getOpenFileName(None, "load custom_config file", os.getcwd(), 'config files (*.txt)')
filename = filename[0]
read_config_file(filename)
def get_Boxcenter_selection():
prot = self.form.comboBox_3.currentText()
if cmd.get_names("selections"):
cmd.create("box_center", "sele")
myspace ={'lst': []}
cmd.iterate("box_center", "lst.append(resn+resi)", space=myspace)
sel=[(myspace["lst"][0])]
for i in range(len(myspace["lst"])-1):
if (myspace["lst"][i]) == (myspace["lst"][i+1]):
continue
else:
sel.append(myspace["lst"][i+1])
self.form.lineEdit_5.clear()
self.form.lineEdit_5.insert(",".join(sel))
cmd.delete("box_center")
Boxcenter_on_selection()
def Boxcenter_on_selection():
res_center = self.form.lineEdit_5.text()
res_i = res_center.strip('ACEGHILMNOPRSTUVY')
cmd.select("sele",("resi "+res_i))
cmd.create("box_center","sele")
cmd.delete("sele")
myspace ={'lst': []}
cmd.iterate_state(0,"box_center", "lst.append((x,y,z))", space=myspace)
self.form.doubleSpinBox.setValue(float(myspace["lst"][1][0]))
self.form.doubleSpinBox_2.setValue(float(myspace["lst"][1][1]))
self.form.doubleSpinBox_3.setValue(float(myspace["lst"][1][2]))
cmd.delete("box_center")
def set_Receptor():
prot = self.form.comboBox_3.currentText()
if prot != "":
if os.path.isfile(prot+"_config.txt"):
set_statusline('Reading configuration file: %s' % (prot+"_config.txt"))
load_smina_config_file()
else:
com = cmd.centerofmass(prot)
self.form.doubleSpinBox.setValue(com[0])
self.form.doubleSpinBox_2.setValue(com[1])
self.form.doubleSpinBox_3.setValue(com[2])
else:
None
def set_Boxsize_defaults():
self.form.spinBox_4.setValue(20)
self.form.spinBox_5.setValue(20)
self.form.spinBox_6.setValue(20)
# ---- The following code of the box calculation and th CGO object is extracted
# ---- from the Autodock/Vina plugin copyrighted by Daniel Seeliger :
#
# 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.
# ----------------------------------------------------------------------
def calculate_Box():
x = float(self.form.doubleSpinBox.value())
y = float(self.form.doubleSpinBox_2.value())
z = float(self.form.doubleSpinBox_3.value())
xpts = int(self.form.spinBox_4.value())
ypts = int(self.form.spinBox_5.value())
zpts = int(self.form.spinBox_6.value())
size = [xpts, ypts, zpts]
xmax = x + size[0]/2.
xmin = x - size[0]/2.
ymax = y + size[1]/2.
ymin = y - size[1]/2.
zmax = z + size[2]/2.
zmin = z - size[2]/2.
box_edge_x = [xmin,xmax]
box_edge_y = [ymin,ymax]
box_edge_z = [zmin,zmax]
box_coords = [box_edge_x,box_edge_y,box_edge_z]
cmd.delete('box')
display_Box(box_coords)
def display_Box(box):
view = cmd.get_view()
name = "box"
obj = []
# build cgo object
color = [1.,1.,1.]
cylinder_size = 0.2
for i in range(2):
for k in range (2):
for j in range(2):
if i != 1:
obj.append(CYLINDER)
obj.extend([box[0][i],box[1][j],box[2][k]])
obj.extend([box[0][i+1],box[1][j],box[2][k]])
obj.append(cylinder_size)
obj.extend(color)
obj.extend(color)
obj.append(COLOR)
obj.extend(color)
obj.append(SPHERE)
obj.extend([box[0][i],box[1][j],box[2][k],cylinder_size])
if j != 1:
obj.append(CYLINDER)
obj.extend([box[0][i],box[1][j],box[2][k]])
obj.extend([box[0][i],box[1][j+1],box[2][k]])
obj.append(cylinder_size)
obj.extend(color)
obj.extend(color)
obj.append(COLOR)
obj.extend(color)
obj.append(SPHERE)
obj.extend([box[0][i],box[1][j+1],box[2][k],cylinder_size])
if k != 1:
obj.append(CYLINDER)
obj.extend([box[0][i],box[1][j],box[2][k]])
obj.extend([box[0][i],box[1][j],box[2][k+1]])
obj.append(cylinder_size)
obj.extend(color)
obj.extend(color)
obj.append(COLOR)
obj.extend(color)
obj.append(SPHERE)
obj.extend([box[0][i],box[1][j],box[2][k+1],cylinder_size])
axes = [[2.0,0.0,0.0],[0.0,2.0,0.0],[0.0,0.0,2.0]]
xpos = [box[0][1]+(box[0][1]-box[0][0])/5.,box[1][0],box[2][0]]
cyl_text(obj,plain,xpos,'X',0.10,axes=axes)
ypos = [box[0][0],box[1][1]+(box[1][1]-box[1][0])/5,box[2][0]]
cyl_text(obj,plain,ypos,'Y',0.10,axes=axes)
zpos = [box[0][0],box[1][0],box[2][1]+(box[2][1]-box[2][0])/5]
cyl_text(obj,plain,zpos,'Z',0.10,axes=axes)
cmd.load_cgo(obj,name)
cmd.set_view(view)
def hide_Box():
cmd.delete("box")
# Autodock/Vina code ends here
# ---------------------------------------------------------------------------------
def save_smina_config_file():
prot = self.form.comboBox_3.currentText()
if prot == "":
set_statusline("No structure selected")
else:
smina_config_file_name = prot+"_config.txt"
with open(smina_config_file_name,'w') as fp:
self.smina_config['center_x'] = self.form.doubleSpinBox.value()
self.smina_config['center_y'] = self.form.doubleSpinBox_2.value()
self.smina_config['center_z'] = self.form.doubleSpinBox_3.value()
self.smina_config['size_x'] = self.form.spinBox_4.value()
self.smina_config['size_y'] = self.form.spinBox_5.value()
self.smina_config['size_z'] = self.form.spinBox_6.value()
for key, val in self.smina_config.items():
print(key, '=', val, file=fp)
set_statusline('Wrote smina configuration file %s' % smina_config_file_name)
# Run page buildup
self.form.textBrowser_3.setHtml(Box_text)
set_Boxsize_defaults()
# Receptor page
receptor_text = """
<html><body> * Objects already loaded in PyMol are imported in the smina-plugin when opening it.<br>
* You may import other receptors from Pymol by using 'Import object'.<br>
* The selected receptor in the receptor Window will be used in all other plugin pages.<br>
* If no 'receptor'.pdbqt file of the 'receptor' is present in the working directory, it will be automatically
created with openbabel.<br> * If no flexible residues are entered, 'Rigid Sidechains' are selected for docking.<br>
* To use 'Flexible sidechains' for docking, select flexible residues of the receptor in PyMol and import them
in the flexible residues window. You can still delete residues in the window.<br> * Actually only
'gasteiger' charges are supported in the .pdbqt file, but you might select a pH for the protonation state
of the receptor and the ligand when automatically creating their '.pdbqt' files. </body></html>
"""
# Receptor functions
def import_objects():
self.form.comboBox.clear()
self.form.comboBox_3.clear()
lst = cmd.get_names()
if 'sele' in lst:
lst.remove('sele')
if 'cgo' in lst:
lst.remove('cgo')
object_list = lst
self.form.comboBox.addItems(object_list)
self.form.comboBox_3.addItems(object_list)
def import_charge_models():
charge_model_list= ["gasteiger"]
self.form.comboBox_5.addItems(charge_model_list)
def select_current_flexibles():
flex_id = []
for i in range(len(self.current_flexibles)):
flex_id.append("resi "+self.current_flexibles[i].strip(':ABCDEFGHIJKLMNOPQRSTUVWXYZ'))
sel = str(flex_id).strip('[]').translate(str.maketrans('','', "'"))
cmd.select("flexres", (sel))
cmd.disable("flexres")
return sel
def import_flexibles():
prot = self.form.comboBox_3.currentText()
if cmd.get_names("selections"):
cmd.create("flexibles", "sele")
cmd.delete("sele")
myspace ={'lst': []}
cmd.iterate("flexibles", "lst.append(chain+':'+resn+resi)", space=myspace)
cmd.delete("flexibles")
flex = [(myspace["lst"][0])]
for i in range(len(myspace["lst"])-1):
if (myspace["lst"][i]) == (myspace["lst"][i+1]):
continue
else:
flex.append(myspace["lst"][i+1])
for i in range(len(flex)):
self.form.listWidget.addItem(flex[i])
self.current_flexibles.append(flex[i])
select_current_flexibles()
self.form.radioButton_2.setChecked(True)
self.form.radioButton_4.setChecked(True)
else:
set_statusline('ERROR : Could not find selection in PyMol')
def clear_flexibles():
cmd.delete("flexres")
self.form.listWidget.clear()
self.current_flexibles = []
def delete_flexible():
sel = self.form.listWidget.selectedItems()
if not sel:
return
for item in sel:
del_flex = self.form.listWidget.currentItem().text()
self.current_flexibles.remove(del_flex)
print("deleted: "+del_flex)
self.form.listWidget.takeItem(self.form.listWidget.row(item))
select_current_flexibles()
def synchronize_Radiobuttons_2():
self.Buttongroup_2.setExclusive(False)
self.form.radioButton_3.setChecked(self.form.radioButton.isChecked())
self.form.radioButton_4.setChecked(self.form.radioButton_2.isChecked())
self.Buttongroup_2.setExclusive(True)
# Run page buildup
self.form.comboBox.setCurrentText("")
self.form.comboBox_2.setCurrentText("")
self.form.textBrowser_2.setHtml(receptor_text)
import_charge_models()
# Ligand page
ligand_text = """
<html><body> * Ligands are loaded from and are saved into the Ligand directory.<br>
* If ligands are selected in .pdb format and their file in .pdbqt format is missing, the latter
is automatically generated in the Ligand directory : either before docking or when adding them to the
multirun list.<br> * When the multirun list is checked, ligands of the list are consecutively docked to the
receptor in the selected docking configuration (rigid or flexible SC).<br>
* Ligands have no more limits in torsion angles like it was in vina.
</body></html>
"""
def File_type_selector_buildup():
File_type_list = ['pdbqt','pdb','sdf']
self.form.comboBox_4.addItems(File_type_list)
def import_ligands():
self.form.comboBox_2.clear()
ligand_list =[]
list_raw = glob(os.path.join(self.ligand_dir_path,"*."+self.form.comboBox_4.currentText()))
for item in list_raw:
ligand_name_raw = item.split("\\")[-1]
ligand_name = ligand_name_raw.split(".")[0]
ligand_list.append(ligand_name)
self.form.comboBox_2.addItems(ligand_list)
def make_ligand_pdbqt(ligand):
charge_model = self.form.comboBox_5.currentText()
ligand_pdbqt = ligand.split(".")[0]+".pdbqt"
print("Running openbable to create ligand.pdbqt :")
command = 'call "%s" %s -O %s --partialcharge %s' % (self.openbabel_exe, ligand, ligand_pdbqt, charge_model)
if self.form.groupBox_17.isChecked() == True:
command = command+' -p %s' % (float(self.form.doubleSpinBox_4.value()))
else :
command = command+' -h'
print(command)
os.system(command)
if os.path.isfile(ligand_pdbqt):
set_statusline("Created %s" % ligand_pdbqt)
else :
set_statusline("ERROR when trying to create %s" % ligand_pdbqt)
def clear_multirun_list():
self.form.listWidget_2.clear()
self.current_ligands = []
def delete_ligands_from_list():
sel = self.form.listWidget_2.selectedItems()
if not sel: return
for item in sel:
del_lig = self.form.listWidget_2.currentItem().text()
self.current_ligands.remove(del_lig)
print("deleted: "+del_lig)
self.form.listWidget_2.takeItem(self.form.listWidget_2.row(item))
def make_multirun_list():
self.form.groupBox_14.setChecked(True)
ligand = self.ligand_dir_path+self.form.comboBox_2.currentText()+"."+self.form.comboBox_4.currentText()
if not (os.path.isfile(ligand.split(".")[0]+".pdbqt") or self.form.comboBox_4.currentText() == "pdbqt"):
make_ligand_pdbqt(ligand)
self.form.listWidget_2.addItem(self.form.comboBox_2.currentText())
self.current_ligands.append(self.form.comboBox_2.currentText())
def set_lig_directory_indicator(path):
self.form.lineEdit_6.clear()
self.form.lineEdit_6.insert(path)
self.ligand_dir_path = path # refresh
import_ligands() # new list when path changed
# Run page buildup
self.form.textBrowser_4.setHtml(ligand_text)
File_type_selector_buildup()
set_lig_directory_indicator(self.ligand_dir_path)
import_ligands()
# Smina page
docking_text = """
<html><body>Smina is a fork of vina including advanced scoring and minimization :<br>
* Docking with Smina allows the use of user customed scoring tables.
The actual scoring table might be edited or new scoring tables can be created or loaded.<br>
* A log-file containing all docking parameters is created if this option is checked.<br>
* Results are selectable and ancient results can be loaded on the results page.<br>
* All results can be post refined.
</body></html>
"""
def make_receptor_pdbqt(prot):
cmd.save(prot+".pdb", prot)
receptor = os.getcwd()+"\\"+prot+".pdbqt"
charge_model = self.form.comboBox_5.currentText()
print("running openbable to create %s.pdbqt :" % prot)
command = 'call "%s" %s.pdb -O %s --partialcharge %s' % (self.openbabel_exe, prot, receptor, charge_model)
if self.form.groupBox_17.isChecked() == True:
command = command+' -p %s' % (float(self.form.doubleSpinBox_4.value()))
else :
command = command+' -h'
print(command)
os.system(command)
if os.path.isfile(receptor):
set_statusline("Created %s" % receptor)
else :
set_statusline("ERROR when trying to create %s" % receptor)
def use_custom_scoring():
if self.form.groupBox_26.isChecked() == True:
scoring_table = self.form.tableView
scoring_model = ScoringTableModel(self.scoring_list)
scoring_table.setModel(scoring_model)
scoring_table.resizeColumnsToContents()
def show_scoring_tables(path):
self.scoring_table_dir_path = str(path) # refresh
self.form.comboBox_6.clear()
self.form.comboBox_7.clear()
scoring_table_list = ["vina"] # current table is default
list_raw = glob(os.path.join(self.scoring_table_dir_path,"*.scr"))
for item in list_raw:
scoring_table_name = item.split(".")[0].split("\\")[-1]
scoring_table_list.append(scoring_table_name)
self.form.comboBox_6.addItems(scoring_table_list)
self.form.comboBox_7.addItems(scoring_table_list)
self.form.comboBox_7.addItems(["new"])
change_current_score_table()
def change_current_score_table():
scoring_table_name = self.form.comboBox_6.currentText()
if scoring_table_name == 'vina':
self.scoring_list = vinascr
use_custom_scoring()
set_statusline('Default scoring table: vina')
else :
if os.path.isfile(os.path.join(self.scoring_table_dir_path,scoring_table_name+".scr")):
set_statusline('Reading scoring table: %s' % scoring_table_name)
self.scoring_list = []
filename = os.path.join(self.scoring_table_dir_path,scoring_table_name+".scr")
with open(filename,'r') as f:
lst = f.readlines()
for line in lst:
weight = line.split(' ')[0].translate(str.maketrans('','', "\n"))
potential = line.split(' ')[-1].translate(str.maketrans('','', "\n"))
self.scoring_list.append([weight, potential])
self.scoring_table_file = filename
use_custom_scoring()
else:
set_statusline('ERROR : Could not find scoring table: %s' % scoring_table_name)
def select_scoring_table():
selected_scoring_table = self.form.comboBox_7.currentText()
if selected_scoring_table == 'vina':
edit_scoring_list = vinascr
elif selected_scoring_table == 'new':
edit_scoring_list = ['','']
else :
edit_scoring_list = []
if os.path.isfile(os.path.join(self.scoring_table_dir_path,selected_scoring_table+".scr")):
filename = os.path.join(self.scoring_table_dir_path,selected_scoring_table+".scr")
with open(filename,'r') as f:
lst = f.readlines()
for line in lst:
weight = line.split(' ')[0].translate(str.maketrans('','', "\n"))
potential = line.split(' ')[-1].translate(str.maketrans('','', "\n"))
edit_scoring_list.append([weight, potential])
else:
set_statusline('ERROR : Could not find scoring table %s for editing' % selected_scoring_table)
return edit_scoring_list
def edit_score_table():
data = select_scoring_table()
selected_scoring_table = self.form.comboBox_7.currentText()
editor = Editor(data, self.scoring_table_dir_path, selected_scoring_table)
editor.show()
show_scoring_tables(self.scoring_table_dir_path)
def load_docked(outfile):
if ( not os.path.isfile(outfile)):
set_statusline('ERROR : Could not find %s in current directory' % outfile)
cmd.load(outfile)
def fill_score_list(outfile):
filename = ""
if outfile == "": # load _docked file
filedialog = QtWidgets.QFileDialog()
if filedialog.exec_():
filename = ''.join(map(str, filedialog.selectedFiles()))
cmd.load(filename)
else:
filename = outfile
lst = open(filename, 'r').readlines()
score_list = []
for line in lst:
if 'MODEL' in line:
modnum = line.strip(" MODEL\n")
if 'minimizedAffinity' in line:
modE = line.strip('REMAK minzedAfty\n')
score_list.append(modnum+";"+modE)
if filename.split('.')[0].rsplit('_', 1)[-1] != "docked": # not a '_docked.pdbqt' file
ligand_name = filename.translate(str.maketrans('\\','/','')).rsplit('/', 1)[-1].split('.')[0]
else :
ligand_name = filename.translate(str.maketrans('\\','/','')).rsplit('_', 1)[0].rsplit('/', 1)[-1] # normal outfile
if self.firstrun == True: # only at first cyle of fill to get rid of tab1
self.form.tabWidget_2.clear()
self.firstrun = False
score_table = QtWidgets.QTableWidget(parent = self.form.tabWidget_2)
self.form.tabWidget_2.addTab(score_table,ligand_name)
score_table.setGeometry(QtCore.QRect(0, 0, 450, 310))
score_table.setColumnCount(3)
score_table.setRowCount(len(score_list))
score_table.setHorizontalHeaderLabels(["Model","Affinty","Select"])
score_table.setMouseTracking(True)
score_table.setEditTriggers(QtWidgets.QTableWidget.NoEditTriggers) # no doubleclick editing
for i in range(len(score_list)):
mod = QtWidgets.QTableWidgetItem(score_list[i].split(";")[0])
aff = QtWidgets.QTableWidgetItem(score_list[i].split(";")[-1])
check = QtWidgets.QTableWidgetItem("[ ]")
mod.setTextAlignment(QtCore.Qt.AlignCenter)
aff.setTextAlignment(QtCore.Qt.AlignCenter)
check.setTextAlignment(QtCore.Qt.AlignCenter)
score_table.setItem(i,0,mod)
score_table.setItem(i,1,aff)
score_table.setItem(i,2,check)
score_table.cellClicked.connect(check_button_select) # this gets the current cell for selection
def combine_flexres(flexout): # merges all residues of the same model into a multi-model file starting with model 1
flexres_merged_name = "" # just in case no flexres is selected
if os.path.isfile(flexout.split(".")[0]+"_merged.pdbqt"):
os.remove(flexout.split(".")[0]+"_merged.pdbqt")
if os.path.isfile(flexout):
with open(flexout, 'r') as file:
oldfile = file.readlines()
flexres_merged_name = flexout.split(".")[0]+"_merged.pdbqt"
for line in oldfile:
if 'MODEL' in line:
actual_model = line
break
first_model = 1
with open(flexres_merged_name, 'a') as newfile:
newfile.write("MODEL "+str(first_model)+"\n")
for line in oldfile:
if 'MODEL' in line and line != actual_model:
newfile.write('ENDMDL\n')
first_model = first_model + 1
actual_model = line
newfile.write("MODEL "+str(first_model)+"\n")
continue
if 'MODEL' in line and line == actual_model:
continue
if 'ENDMDL' in line:
continue
else :
newfile.write(line)
newfile.write('ENDMDL\n')
return flexres_merged_name
def smina_loop(ligand):
prot = self.form.comboBox.currentText()
if prot == "":
set_statusline("ERROR : No structure selected")
return
else:
receptor = os.getcwd()+"\\"+prot+".pdbqt"
if ( not os.path.isfile(receptor)):
make_receptor_pdbqt(prot)
ligand_name = ligand.split("/")[-1]
config = os.getcwd()+"\\"+prot+"_config.txt"
if self.form.groupBox_15.isChecked() == True: # add suffix to outfile
ligand_name = ligand_name+"_"+self.form.lineEdit_7.text()
outfile = os.getcwd()+"\\"+ligand_name+"_docked.pdbqt"
if ( not os.path.isfile(config)): # check presence of smina config file for receptor
set_statusline('ERROR : Could not find %s_config.txt in current directory' % prot)
return
else:
print("running smina :")
receptor_wsl = "/mnt/c"+receptor.split(":")[-1].translate(str.maketrans('\\','/','')) # format receptor path for wsl
config_wsl = "/mnt/c"+config.split(":")[-1].translate(str.maketrans('\\','/','')) # format config path for wsl
outfile_wsl = "/mnt/c"+outfile.split(":")[-1].translate(str.maketrans('\\','/','')) # format outfile path for wsl
smina = "/mnt/c"+self.smina_exe.split(":")[-1] # format smina_path for wsl
ligand = "/mnt/c"+ligand.split(":")[-1] # format ligand_dir_path for wsl
exhaust = self.form.spinBox.value()
maxmodes = self.form.spinBox_2.value()
command = 'call wsl %s -r %s -l %s.pdbqt --config %s -o %s --flex_hydrogens --exhaustiveness %s --num_modes %s ' % (smina,
receptor_wsl, ligand, config_wsl, outfile_wsl, exhaust, maxmodes)
if self.form.radioButton_2.isChecked() == True: # run smina with flexibles
if self.current_flexibles != []:
flex_raw = []
for i in range(len(self.current_flexibles)):
A = self.current_flexibles[i].split(":")[0]
B = self.current_flexibles[i].split(":")[-1].strip(':ABCDEFGHIJKLMNOPQRSTUVWXYZ')
flex_raw.append(A+":"+B)
flexibles = str(flex_raw).strip('[]').translate(str.maketrans('','', "'")).translate(str.maketrans('','', " "))
flexout = os.getcwd()+"\\"+ligand_name+"_flexres.pdbqt"
flexout_wsl = "/mnt/c"+flexout.split(":")[-1].translate(str.maketrans('\\','/','')) # format outfile path for wsl
command = command+' --flexres %s --out_flex %s' % (flexibles, flexout_wsl)
else:
set_statusline("ERROR : No flexibles selected -> using rigid side chains")
self.Buttongroup_1.setExclusive(False)
self.form.radioButton.setChecked(True)
self.form.radioButton_2.setChecked(False)
self.Buttongroup_1.setExclusive(True)
print("Missing flexible residues switched to rigid side chains")
return
if self.form.groupBox_25.isChecked() == True: # set seed
seed = int(self.form.doubleSpinBox_5.value())
command = command+' --seed %s' % (seed)
if self.form.groupBox_26.isChecked() == True: # custom score table
if self.form.comboBox_6.currentText() == "vina":
None
else:
custscrtbl = "/mnt/c"+self.scoring_table_file.split(":")[-1] # format score_table_path for wsl
command = command+' --custom_scoring %s' % (custscrtbl)
if self.form.checkBox.isChecked() == True: # write smina Logfile
if self.form.groupBox_15.isChecked() == True: # add suffix to logfile too !
logfile = receptor.split(".")[0]+'_'+ligand.split('/')[-1].split('.')[0]+"_"+self.form.lineEdit_7.text()+'.log'
else :
logfile = receptor.split(".")[0]+'_'+ligand.split('/')[-1].split('.')[0]+'.log'
logfile_wsl = "/mnt/c"+logfile.split(":")[-1].translate(str.maketrans('\\','/','')) # format receptor path for wsl
command = command+' --log %s' % (logfile_wsl)
# print(command)
os.system(command)
if self.form.checkBox.isChecked() == True:
if os.path.isfile(logfile):
lst = []
with open(config, 'r') as f:
lst = f.readlines()
with open (logfile, 'a') as log_file:
log_file.write("Parameters : \n"+command+"\n"+str(lst))
else:
set_statusline("ERROR : Could not find "+logfile)
load_docked(outfile)
fill_score_list(outfile)
if self.form.radioButton_2.isChecked() == True:
flexres_merged = combine_flexres(flexout) # still has "_merged" in title !
if os.path.isfile(flexres_merged):
flexres_name = flexres_merged.rsplit("_",maxsplit=1)[0].split('\\')[-1]
if self.form.groupBox_15.isChecked() == True: # add suffix
flexres_name = flexres_name+'_'+self.form.lineEdit_7.text()
cmd.load(flexres_merged, flexres_name)
else :
set_statusline('ERROR : Could not find %s in current directory' % flexres_merged)
def run_smina():
if self.form.groupBox_14.isChecked() == True: # Multirun
for i in range(self.form.listWidget_2.count()):
ligand = self.ligand_dir_path+self.form.listWidget_2.item(i).text()
smina_loop(ligand)
else:
if ( not os.path.isfile(self.ligand_dir_path+self.form.comboBox_2.currentText()+".pdbqt")):
ligand = self.ligand_dir_path+self.form.comboBox_2.currentText()+"."+self.form.comboBox_4.currentText()
make_ligand_pdbqt(ligand)
ligand = self.ligand_dir_path+self.form.comboBox_2.currentText()
smina_loop(ligand)
def synchronize_Radiobuttons_1():
self.Buttongroup_1.setExclusive(False)
self.form.radioButton.setChecked(self.form.radioButton_3.isChecked())
self.form.radioButton_2.setChecked(self.form.radioButton_4.isChecked())
self.Buttongroup_1.setExclusive(True)
# Run page buildup
self.form.textBrowser_5.setHtml(docking_text)
show_scoring_tables(self.scoring_table_dir_path)
# Results Page
def set_checked(row):
current_widget = self.form.tabWidget_2.currentWidget()
score_table = current_widget
checked = QtWidgets.QTableWidgetItem("[X]")
checked.setTextAlignment(QtCore.Qt.AlignCenter)
score_table.setItem(row,2,checked)
modnr = score_table.item(row,0).text()
ligand_name = self.form.tabWidget_2.tabText(self.form.tabWidget_2.currentIndex())
if ligand_name.rsplit("_", 1)[-1] == ("minimized" or "localdocked" or "randomized"): # select a post-refined ligand
None
else :
ligand = ligand_name+"_docked"
cmd.select("selection", ligand, 1, 1, 0, modnr)
cmd.disable(ligand)
if self.form.radioButton_2.isChecked() == True: # result has flexres
residues = self.form.tabWidget_2.tabText(self.form.tabWidget_2.currentIndex())+"_flexres"
cmd.select("selection", residues, 1, 1, 1, modnr)
cmd.disable(residues)
cmd.disable(ligand)
cmd.create ("pose"+modnr+"_"+ligand_name, "selection", modnr, 1)
cmd.delete("selection")
def set_unchecked(row):
check = QtWidgets.QTableWidgetItem("[ ]")
check.setTextAlignment(QtCore.Qt.AlignCenter)
current_widget = self.form.tabWidget_2.currentWidget()
score_table = current_widget
score_table.setItem(row,2,check)
modnr = score_table.item(row,0).text()
ligand_name = self.form.tabWidget_2.tabText(self.form.tabWidget_2.currentIndex())
if ligand_name.rsplit("_", 1)[-1] == ("minimized" or "localdocked" or "randomized"): # select a post-refined ligand
None
else :
cmd.delete ("pose"+modnr+"_"+ligand_name)
def check_button_select(row,column):
current_widget = self.form.tabWidget_2.currentWidget() # score_table
check_item = current_widget.item(row,2)
if check_item.text() == "[X]":
set_unchecked(row)
else :
set_checked(row)
if self.form.checkBox_2.isChecked() == True: # update Postrefinement list if checked
show_current_poses()
def get_docked_file():
outfile = ""
fill_score_list(outfile)
def export_current_results():
score_list = []
sel = self.form.tabWidget_2.currentIndex()
for i in range(self.form.tabWidget_2.widget(sel).rowCount()):
score_list.append(self.form.tabWidget_2.widget(sel).item(i, 0).text()
+","+self.form.tabWidget_2.widget(sel).item(i, 1).text())
fp = open(self.form.tabWidget_2.tabText(sel)+".csv",'w')
print("model,Affinity", file=fp)
for i in range(len(score_list)):
print(score_list[i], file=fp)
fp.close()
set_statusline('Wrote results for docking as %s.csv file' % self.form.tabWidget_2.tabText(sel))
def get_selected_poses():
current_widget = self.form.tabWidget_2.currentWidget() # score_table
ligand_name = self.form.tabWidget_2.tabText(self.form.tabWidget_2.currentIndex())
ligand_poses_selected_list =[]
for i in range(current_widget.rowCount()):