From a345233a35b6d9395be44358f6e91ebc7df73a47 Mon Sep 17 00:00:00 2001 From: philbiggin Date: Fri, 8 May 2020 12:08:56 -0700 Subject: [PATCH 1/4] refactored for Python 3 - check on ubuntu but problematic on mac --- __init__.py | 34 +++++++++++++++++----------------- addwater.py | 44 ++++++++++++++++++++++---------------------- dockcheck.py | 8 ++++---- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/__init__.py b/__init__.py index 21f35e1..87fa50f 100644 --- a/__init__.py +++ b/__init__.py @@ -1,12 +1,12 @@ -from Tkinter import * +from tkinter import * import scipy.cluster from pymol import cmd import numpy as np import os import sys -import tkSimpleDialog -import tkMessageBox -import tkFileDialog +import tkinter.simpledialog +import tkinter.messagebox +import tkinter.filedialog import distutils.spawn import MDAnalysis @@ -84,7 +84,7 @@ def option1(): numclust1 = np.max(fit1) clustcoods = np.zeros((numclust1,3), dtype = float) - for i in xrange(1,numclust1+1): + for i in range(1,numclust1+1): temp = np.compress(fit1 == i, selectcoods, axis = 0) tempavg = np.mean(temp, axis = 0) @@ -95,7 +95,7 @@ def option1(): numclust2 = np.max(fit2) finalcoods = np.zeros((numclust2,3), dtype = float) - for i in xrange(1,numclust2+1): + for i in range(1,numclust2+1): temp = np.compress(fit2 == i, clustcoods, axis = 0) tempavg = np.mean(temp, axis = 0) @@ -127,13 +127,13 @@ def option2(): global proteinfile, ligandfile - import addwater + from . import addwater addwater.main(ligandfile) waterfile() #Writes the water.pdbqt file - import dockcheck + from . import dockcheck dockcheck.main(proteinfile, ligandfile, vinacomd) os.remove('waterdetails.txt') @@ -199,7 +199,7 @@ def write_waterpdb(waterfilename, coordinates): xyz.write("REMARK Please Cite: Rapid and Accurate Prediction and Scoring of Water Molecules in Protein Binding Sites\n") xyz.write("REMARK DOI:10.1371/journal.pone.0032036\n") - for i in xrange(0,numatom): + for i in range(0,numatom): header = 'HETATM' serial = i+1 name = ' OW ' @@ -276,14 +276,14 @@ def __init__(self): def profilechoose(self): - self.profilenamechoose = tkFileDialog.askopenfilename() + self.profilenamechoose = tkinter.filedialog.askopenfilename() self.E1.delete(0, END) self.E1.insert(0, self.profilenamechoose) def ligfilechoose(self): - self.ligfilename = tkFileDialog.askopenfilename(filetypes=(("pdb files", "*.pdb"), ("pdbqt files", "*.pdbqt"), ("mol2 files", "*.mol2"))) + self.ligfilename = tkinter.filedialog.askopenfilename(filetypes=(("pdb files", "*.pdb"), ("pdbqt files", "*.pdbqt"), ("mol2 files", "*.mol2"))) self.E2.insert(0, self.ligfilename) def byebye(self): @@ -298,14 +298,14 @@ def rungui(self): proteinfile = self.E1.get() if int(os.path.isfile(proteinfile)) == 0: - tkMessageBox.showerror(title='Missing File', message='Protein File does not exist') + tkinter.messagebox.showerror(title='Missing File', message='Protein File does not exist') sys.exit() if ligandoption == '2': if hasattr(self.E2, 'get'): ligandfile = self.E2.get() if int(os.path.isfile(ligandfile)) == 0: - tkMessageBox.showerror(title='Missing File', message='Ligand File does not exist') + tkinter.messagebox.showerror(title='Missing File', message='Ligand File does not exist') sys.exit() elif ligandoption == '1': @@ -371,14 +371,14 @@ def __init__(self): def profilechoose(self): - self.profilenamechoose = tkFileDialog.askopenfilename() + self.profilenamechoose = tkinter.filedialog.askopenfilename() self.E1.delete(0, END) self.E1.insert(0, self.profilenamechoose) def ligfilechoose(self): - self.ligfilename = tkFileDialog.askopenfilename(filetypes=(("pdb files", "*.pdb"), ("pdbqt files", "*.pdbqt"), ("mol2 files", "*.mol2"))) + self.ligfilename = tkinter.filedialog.askopenfilename(filetypes=(("pdb files", "*.pdb"), ("pdbqt files", "*.pdbqt"), ("mol2 files", "*.mol2"))) self.E2.insert(0, self.ligfilename) def byebye(self): @@ -392,13 +392,13 @@ def rungui(self): if int(os.path.isfile(proteinfile)) == 0: - tkMessageBox.showerror(title='Missing File', message='Protein File does not exist') + tkinter.messagebox.showerror(title='Missing File', message='Protein File does not exist') sys.exit() if hasattr(self.E2, 'get'): ligandfile = self.E2.get() if int(os.path.isfile(ligandfile)) == 0: - tkMessageBox.showerror(title='Missing File', message='Ligand File does not exist') + tkinter.messagebox.showerror(title='Missing File', message='Ligand File does not exist') sys.exit() self.window.quit() diff --git a/addwater.py b/addwater.py index 25208c5..041330f 100644 --- a/addwater.py +++ b/addwater.py @@ -17,7 +17,7 @@ def writewaterfile(filename, watercoods): numwater = watercoods.shape[0] f1 = open(filename,'w') - for j in xrange(0,numwater): + for j in range(0,numwater): header = 'HETATM' serial = j+1 name = 'OW' @@ -54,7 +54,7 @@ def carbonylorcarboxyl(allligand,index,bond_dist): tempdist2 = MDAnalysis.lib.distances.distance_array(Omatecood, allligandcoods) B = np.argsort(tempdist2) B = np.delete(B,0,axis = 1) - for i in xrange(0,B.size): + for i in range(0,B.size): if B[0,i] == index: C = np.delete(B,i,axis = 1) break @@ -99,7 +99,7 @@ def matefinder(allligand,index): numatoms = allligand.n_atoms radiimatrix = np.zeros((numatoms), dtype = float) - for i in xrange(0,numatoms): + for i in range(0,numatoms): attype = str(allligand[i].type) variable = 'R' + attype radiimatrix[i] = float(eval(variable)) @@ -109,7 +109,7 @@ def matefinder(allligand,index): offset = np.zeros((numatoms), dtype = float) - for i in xrange(0,numatoms): + for i in range(0,numatoms): if Dij[i,0] < 1.5: offset[i] = 0.15 * Dij[i,0] @@ -264,7 +264,7 @@ def carbonylwaters(allligand,index,bond_dist): tempdist2 = MDAnalysis.lib.distances.distance_array(Omatecood, allligandcoods) B = np.argsort(tempdist2) B = np.delete(B,0,axis = 1) - for i in xrange(0,B.size): + for i in range(0,B.size): if B[0,i] == index: C = np.delete(B,i,axis = 1) @@ -281,7 +281,7 @@ def carbonylwaters(allligand,index,bond_dist): V = (D*yaxis) - for i in xrange(0,5): + for i in range(0,5): degreeangle = -70.0 + (i*35) radangle = np.pi*(degreeangle/180) #Rotation Matrix @@ -296,7 +296,7 @@ def carbonylwaters(allligand,index,bond_dist): partC = (1-np.cos(radangle)) * np.dot(zaxis,np.transpose(V)) * zaxis watercood[i,:] = partA + partB + partC - for i in xrange(5,8): + for i in range(5,8): degreeangle = -35.0 radangle = np.pi*(degreeangle/180) #Rotation Matrix @@ -311,7 +311,7 @@ def carbonylwaters(allligand,index,bond_dist): partZ = (1-np.cos(radangle)) * np.dot(xaxis,np.transpose(watercood[i-4,:])) * xaxis watercood[i,:] = partX + partY + partZ - for i in xrange(8,11): + for i in range(8,11): degreeangle = 35.0 radangle = np.pi*(degreeangle/180) #Rotation Matrix @@ -351,7 +351,7 @@ def carboxylwaters(allligand,index,bond_dist): tempdist2 = MDAnalysis.lib.distances.distance_array(Omatecood, allligandcoods) B = np.argsort(tempdist2) B = np.delete(B,0,axis = 1) - for i in xrange(0,B.size): + for i in range(0,B.size): if B[0,i] == index: C = np.delete(B,i,axis = 1) @@ -369,7 +369,7 @@ def carboxylwaters(allligand,index,bond_dist): V = (D*yaxis) count = 0 - for i in xrange(0,5): + for i in range(0,5): degreeangle1 = -70.0 + (i*35) radangle1 = np.pi*(degreeangle1/180) @@ -386,7 +386,7 @@ def carboxylwaters(allligand,index,bond_dist): V2 = partA + partB + partC - for j in xrange(0,5): + for j in range(0,5): degreeangle2 = -70.0 + (j*35) radangle2 = np.pi*(degreeangle2/180) @@ -503,7 +503,7 @@ def threesecaminewater(allligand,index,bond_dist): tempdist = MDAnalysis.lib.distances.distance_array(allligandcoods,ncoods) A = np.argsort(tempdist[:,0]) - for i in xrange(1,4): + for i in range(1,4): if allligand[A[i]].type == 'H': vector1 = unitvector(allligandcoods[A[i],:] - ncoods[0,:]) watercood[0,:] = ncoods + (D*vector1) @@ -533,7 +533,7 @@ def threepriaminewater(allligand,index,bond_dist): A = np.argsort(tempdist[:,0]) j = 0 - for i in xrange(1,4): + for i in range(1,4): if allligand[A[i]].type == 'H': vector1 = unitvector(allligandcoods[A[i],:] - ncoods[0,:]) watercood[j,:] = ncoods + (D*vector1) @@ -602,7 +602,7 @@ def largeatom(allligand,index,bond_dist): tempdist2 = MDAnalysis.lib.distances.distance_array(Omatecood, allligandcoods) B = np.argsort(tempdist2) B = np.delete(B,0,axis = 1) - for i in xrange(0,B.size): + for i in range(0,B.size): if B[0,i] == index: C = np.delete(B,i,axis = 1) @@ -623,7 +623,7 @@ def largeatom(allligand,index,bond_dist): V = (D*yaxis) count = 0 - for i in xrange(0,5): + for i in range(0,5): degreeangle1 = -70.0 + (i*35) radangle1 = np.pi*(degreeangle1/180) @@ -640,7 +640,7 @@ def largeatom(allligand,index,bond_dist): V2 = partA + partB + partC - for j in xrange(0,5): + for j in range(0,5): degreeangle2 = -70.0 + (j*35) radangle2 = np.pi*(degreeangle2/180) @@ -691,7 +691,7 @@ def etherwater(allligand,index,bond_dist): watercood = np.zeros((5,3), dtype = float) V = D * yaxis - for i in xrange(0,5): + for i in range(0,5): degreeangle = -70.0 + (i*35) radangle = np.pi*(degreeangle/180) #Rotation Matrix @@ -738,7 +738,7 @@ def iminewater(allligand,index,bond_dist): watercood = np.zeros((5,3), dtype = float) V = D * yaxis - for i in xrange(0,5): + for i in range(0,5): degreeangle = -70.0 + (i*35) radangle = np.pi*(degreeangle/180) #Rotation Matrix @@ -772,7 +772,7 @@ def hydroxylwater(allligand,index,bond_dist): base1cood = np.zeros((1,3), dtype = float) base2cood = np.zeros((1,3), dtype = float) - for i in xrange(0,3): + for i in range(0,3): if allligand[A[0,i]].type == 'H': hindex = A[0,i] @@ -790,7 +790,7 @@ def hydroxylwater(allligand,index,bond_dist): V = D * yaxis count = 0 - for i in xrange(0,5): + for i in range(0,5): degreeangle = -70.0 + (i*35) radangle = np.pi*(degreeangle/180) #Rotation Matrix @@ -805,7 +805,7 @@ def hydroxylwater(allligand,index,bond_dist): partC = (1-np.cos(radangle)) * np.dot(xaxis,np.transpose(V)) * xaxis Vec1 = partA + partB + partC - for j in xrange(0,2): + for j in range(0,2): degreeangle2 = -17.5 + (j*35.0) radangle2 = np.pi*(degreeangle2/180) @@ -871,7 +871,7 @@ def main(ligandinputfilename): f1 = open('waterdetails.txt','w') - for i in xrange(0,numatoms): + for i in range(0,numatoms): atype = 'NONE' atom = str(allligand[i].type) if atom == 'O': diff --git a/dockcheck.py b/dockcheck.py index 8c7a926..87f5e3a 100644 --- a/dockcheck.py +++ b/dockcheck.py @@ -9,7 +9,7 @@ def writewaterfile(filename, watercoods, finalwaterscores): numwater = watercoods.shape[0] f1 = open(filename,'w') - for j in xrange(0,numwater): + for j in range(0,numwater): header = 'HETATM' serial = j+1 name = 'OW' @@ -54,7 +54,7 @@ def main(proteinfilename, ligandfilename, vinacomd): tempdist = MDAnalysis.lib.distances.distance_array(trialwatercoods,proteincoods) watprodist = np.amin(tempdist, axis = 1) - for i in xrange(0,numtrialwaters): + for i in range(0,numtrialwaters): if watprodist[i] < 3.6 and watprodist[i] > 2.00: @@ -85,7 +85,7 @@ def main(proteinfilename, ligandfilename, vinacomd): temppredictedwatercoods = np.float32(temppredictedwatercoods) temppredictedwaterscores = np.zeros((numclust,1), dtype = float) - for i in xrange(1,numclust+1): + for i in range(1,numclust+1): clusttemp = np.compress(fit == i, predictedwatercoods, axis = 0) tempavg = np.mean(clusttemp, axis = 0) temppredictedwatercoods[i-1,:] = tempavg @@ -132,7 +132,7 @@ def main(proteinfilename, ligandfilename, vinacomd): if nummates > allowedwaters: numdiscardedwaters = nummates - allowedwaters - for j in xrange(0,numdiscardedwaters): + for j in range(0,numdiscardedwaters): high = np.argmax(matescores) removedindex = mates[high] From 3650e51a74d9892dd8832243fc46f84129e6bf8a Mon Sep 17 00:00:00 2001 From: philbiggin Date: Mon, 11 May 2020 09:19:56 -0700 Subject: [PATCH 2/4] some fixes around the vina path if not in default position --- __init__.py | 711 ++++++++++++++++++++++++++++------------------------ 1 file changed, 382 insertions(+), 329 deletions(-) diff --git a/__init__.py b/__init__.py index 87fa50f..aaed540 100644 --- a/__init__.py +++ b/__init__.py @@ -15,191 +15,206 @@ sys.path.append(path2) #################################################################################################################################################### + + def __init__(self): - self.menuBar.addmenuitem('Plugin', 'command', 'Apo-WaterDock', label = 'Apo-WaterDock', command = lambda s=self : option1()) - self.menuBar.addmenuitem('Plugin', 'command', 'Holo-Waterdock', label = 'Holo-waterdock', command = lambda s= self : option2()) + self.menuBar.addmenuitem('Plugin', 'command', 'Apo-WaterDock', + label='Apo-WaterDock', command=lambda s=self: option1()) + self.menuBar.addmenuitem('Plugin', 'command', 'Holo-Waterdock', + label='Holo-waterdock', command=lambda s=self: option2()) ################################################################################################################################################### + + def option1(): - vinacomd = str(checkutilities()) - A = inputdata1() - - global proteinfile, ligandoption, ligandfile, centerx, centery, centerz - - if ligandoption == '2': - - UL = MDAnalysis.Universe(ligandfile) - if ligandfile[-5:] == 'pdbqt': - heavylig = UL.select_atoms('not type HD') - else: - heavylig = UL.select_atoms('not type H') - - com = np.mean(heavylig.positions, axis = 0) - centerx = com[0] - centery = com[1] - centerz = com[2] - - - waterfile() - proteinpdbqtfile = proteinfile - - f1 = open('vinaconfig.txt','w') - f1.write('receptor = ') - f1.write(str(proteinpdbqtfile)) - f1.write('\nligand = water.pdbqt') - f1.write('\nexhaustiveness = 20') - f1.write('\nnum_modes = 20') - f1.write('\ncenter_x = ') - f1.write(str(centerx)) - f1.write('\ncenter_y = ') - f1.write(str(centery)) - f1.write('\ncenter_z = ') - f1.write(str(centerz)) - f1.write('\nsize_x = 15') - f1.write('\nsize_y = 15') - f1.write('\nsize_z = 15') - f1.write('\nenergy_range = 100') - f1.write('\nlog = outputlog.txt') - f1.write('\nout = waterout.pdbqt') - f1.close() - - for i in range(1,4): - tempcomd = vinacomd + ' --config vinaconfig.txt' - os.system(tempcomd) - os.system("grep 'OW' waterout.pdbqt >> allwater.pdbqt") - os.system("grep 'RESULT' waterout.pdbqt >> result.log") - os.remove('outputlog.txt') - os.remove('waterout.pdbqt') - - os.remove('vinaconfig.txt') - coods = np.genfromtxt('allwater.pdbqt', usecols = (5,6,7), dtype = float) - energy = np.genfromtxt('result.log', usecols = 3, dtype = float) - - selectcoods = np.compress(energy < -0.5, coods, axis = 0) - - fit1 = scipy.cluster.hierarchy.fclusterdata(selectcoods, 0.5, criterion = 'distance', metric = 'euclidean') - fit1 = fit1.astype(int) - numclust1 = np.max(fit1) - - clustcoods = np.zeros((numclust1,3), dtype = float) - for i in range(1,numclust1+1): - - temp = np.compress(fit1 == i, selectcoods, axis = 0) - tempavg = np.mean(temp, axis = 0) - clustcoods[i-1,:] = tempavg - - fit2 = scipy.cluster.hierarchy.fclusterdata(clustcoods, 1.6, criterion = 'distance', metric = 'euclidean') - fit2 = fit2.astype(int) - numclust2 = np.max(fit2) - - finalcoods = np.zeros((numclust2,3), dtype = float) - for i in range(1,numclust2+1): - - temp = np.compress(fit2 == i, clustcoods, axis = 0) - tempavg = np.mean(temp, axis = 0) - finalcoods[i-1,:] = tempavg - - if os.path.isfile('predictedwaters.pdb'): - os.rename('predictedwaters.pdb','#predictedwaters.pdb') - write_waterpdb('predictedwaters.pdb',finalcoods) - - os.remove('allwater.pdbqt') - os.remove('result.log') - os.remove('water.pdbqt') - - cmd.set("retain_order", 1) - cmd.set("pdb_use_ter_records", 0) - cmd.load(proteinfile, 'pro') - cmd.show_as('cartoon', 'pro') - cmd.color('blue','pro') - cmd.load('predictedwaters.pdb','wats') - cmd.color('red','wats') - cmd.center('wats') + vinacomd = str(checkutilities()) + A = inputdata1() + + global proteinfile, ligandoption, ligandfile, centerx, centery, centerz + + if ligandoption == '2': + + UL = MDAnalysis.Universe(ligandfile) + if ligandfile[-5:] == 'pdbqt': + heavylig = UL.select_atoms('not type HD') + else: + heavylig = UL.select_atoms('not type H') + + com = np.mean(heavylig.positions, axis=0) + centerx = com[0] + centery = com[1] + centerz = com[2] + + waterfile() + proteinpdbqtfile = proteinfile + + f1 = open('vinaconfig.txt', 'w') + f1.write('receptor = ') + f1.write(str(proteinpdbqtfile)) + f1.write('\nligand = water.pdbqt') + f1.write('\nexhaustiveness = 20') + f1.write('\nnum_modes = 20') + f1.write('\ncenter_x = ') + f1.write(str(centerx)) + f1.write('\ncenter_y = ') + f1.write(str(centery)) + f1.write('\ncenter_z = ') + f1.write(str(centerz)) + f1.write('\nsize_x = 15') + f1.write('\nsize_y = 15') + f1.write('\nsize_z = 15') + f1.write('\nenergy_range = 100') + f1.write('\nlog = outputlog.txt') + f1.write('\nout = waterout.pdbqt') + f1.close() + + for i in range(1, 4): + tempcomd = vinacomd + ' --config vinaconfig.txt' + os.system(tempcomd) + os.system("grep 'OW' waterout.pdbqt >> allwater.pdbqt") + os.system("grep 'RESULT' waterout.pdbqt >> result.log") + os.remove('outputlog.txt') + os.remove('waterout.pdbqt') + + os.remove('vinaconfig.txt') + coods = np.genfromtxt('allwater.pdbqt', usecols=(5, 6, 7), dtype=float) + energy = np.genfromtxt('result.log', usecols=3, dtype=float) + + selectcoods = np.compress(energy < -0.5, coods, axis=0) + + fit1 = scipy.cluster.hierarchy.fclusterdata( + selectcoods, 0.5, criterion='distance', metric='euclidean') + fit1 = fit1.astype(int) + numclust1 = np.max(fit1) + + clustcoods = np.zeros((numclust1, 3), dtype=float) + for i in range(1, numclust1+1): + + temp = np.compress(fit1 == i, selectcoods, axis=0) + tempavg = np.mean(temp, axis=0) + clustcoods[i-1, :] = tempavg + + fit2 = scipy.cluster.hierarchy.fclusterdata( + clustcoods, 1.6, criterion='distance', metric='euclidean') + fit2 = fit2.astype(int) + numclust2 = np.max(fit2) + + finalcoods = np.zeros((numclust2, 3), dtype=float) + for i in range(1, numclust2+1): + + temp = np.compress(fit2 == i, clustcoods, axis=0) + tempavg = np.mean(temp, axis=0) + finalcoods[i-1, :] = tempavg + + if os.path.isfile('predictedwaters.pdb'): + os.rename('predictedwaters.pdb', '#predictedwaters.pdb') + write_waterpdb('predictedwaters.pdb', finalcoods) + + os.remove('allwater.pdbqt') + os.remove('result.log') + os.remove('water.pdbqt') + + cmd.set("retain_order", 1) + cmd.set("pdb_use_ter_records", 0) + cmd.load(proteinfile, 'pro') + cmd.show_as('cartoon', 'pro') + cmd.color('blue', 'pro') + cmd.load('predictedwaters.pdb', 'wats') + cmd.color('red', 'wats') + cmd.center('wats') ############################################################################################################################# ############################################################################################################################# ############################################################################################################################# -def option2(): - vinacomd = str(checkutilities()) - A = inputdata2() - global proteinfile, ligandfile +def option2(): + + vinacomd = str(checkutilities()) + A = inputdata2() - from . import addwater - addwater.main(ligandfile) + global proteinfile, ligandfile - waterfile() - #Writes the water.pdbqt file + from . import addwater + addwater.main(ligandfile) - from . import dockcheck - dockcheck.main(proteinfile, ligandfile, vinacomd) + waterfile() + # Writes the water.pdbqt file - os.remove('waterdetails.txt') - os.remove('placedwaters.pdb') - os.remove('water.pdbqt') + from . import dockcheck + dockcheck.main(proteinfile, ligandfile, vinacomd) + os.remove('waterdetails.txt') + os.remove('placedwaters.pdb') + os.remove('water.pdbqt') - cmd.set("retain_order", 1) - cmd.set("pdb_use_ter_records", 0) - cmd.load(proteinfile, 'pro') - cmd.show_as('cartoon', 'pro') - cmd.color('blue','pro') - cmd.load('predictedwaters.pdb','wats') - cmd.color('red','wats') - cmd.load(ligandfile,'lig') - cmd.show_as('sticks','lig') - cmd.center('lig') + cmd.set("retain_order", 1) + cmd.set("pdb_use_ter_records", 0) + cmd.load(proteinfile, 'pro') + cmd.show_as('cartoon', 'pro') + cmd.color('blue', 'pro') + cmd.load('predictedwaters.pdb', 'wats') + cmd.color('red', 'wats') + cmd.load(ligandfile, 'lig') + cmd.show_as('sticks', 'lig') + cmd.center('lig') ############################################################################################################################# + + def checkutilities(): - zz = distutils.spawn.find_executable('vina') - homedir = str(os.environ.get('HOME')) - file = homedir + '/pyvina.txt' - if zz: - if os.path.isfile(zz): - vinacomd = zz - - elif os.path.isfile(file): - fzz = open(file,'r') - vinacomd = fzz.read() - fzz.close() - - else: - ZZ = vinapath() - fzz = open(file,'r') - vinacomd = fzz.read() - fzz.close() - - return vinacomd - - + zz = distutils.spawn.find_executable('vina') + homedir = str(os.environ.get('HOME')) + file = homedir + '/pyvina.txt' + if zz: + if os.path.isfile(zz): + vinacomd = zz + + elif os.path.isfile(file): + fzz = open(file, 'r') + vinacomd = fzz.read() + fzz.close() + + else: + ZZ = vinapath() + fzz = open(file, 'r') + vinacomd = fzz.read() + fzz.close() + + return vinacomd + + ############################################################################################################################# def waterfile(): - f1 = open('water.pdbqt', 'w') + f1 = open('water.pdbqt', 'w') - f1.write('REMARK The pdbqt file for using water as a ligand\n') - f1.write('ROOT\n') - f1.write('ATOM 1 OW HOH 231 0.950 11.375 16.494 1.00 0.00 -0.411 OA\n') - f1.write('ATOM 2 HW1 HOH 231 1.766 11.375 17.071 1.00 0.00 0.205 HD\n') - f1.write('ATOM 3 HW2 HOH 231 0.134 11.375 17.071 1.00 0.00 0.205 HD\n') - f1.write('ENDROOT\n') - f1.write('TORSDOF 0') + f1.write('REMARK The pdbqt file for using water as a ligand\n') + f1.write('ROOT\n') + f1.write( + 'ATOM 1 OW HOH 231 0.950 11.375 16.494 1.00 0.00 -0.411 OA\n') + f1.write( + 'ATOM 2 HW1 HOH 231 1.766 11.375 17.071 1.00 0.00 0.205 HD\n') + f1.write( + 'ATOM 3 HW2 HOH 231 0.134 11.375 17.071 1.00 0.00 0.205 HD\n') + f1.write('ENDROOT\n') + f1.write('TORSDOF 0') - f1.close() + f1.close() ############################################################################################################################# + + def write_waterpdb(waterfilename, coordinates): - + numatom = coordinates.shape[0] - xyz = open(waterfilename,'w') + xyz = open(waterfilename, 'w') xyz.write("TITLE Water Molecules Predicted by WaterDock\n") - xyz.write("REMARK Please Cite: Rapid and Accurate Prediction and Scoring of Water Molecules in Protein Binding Sites\n") + xyz.write("REMARK Please Cite: Rapid and Accurate Prediction and Scoring of Water Molecules in Protein Binding Sites\n") xyz.write("REMARK DOI:10.1371/journal.pone.0032036\n") - for i in range(0,numatom): + for i in range(0, numatom): header = 'HETATM' serial = i+1 name = ' OW ' @@ -210,14 +225,17 @@ def write_waterpdb(waterfilename, coordinates): occupancy = 1.0 tempFactor = 0.0 x, y, z = coordinates[i] - xyz.write("%6s%5d %4s%1s%3s %1s%4d%1s %8.3f%8.3f%8.3f%6.2f%6.2f\n" %(header,serial,name,iCode,resname,chainID,resSeq,iCode,x,y,z,occupancy,tempFactor)) + xyz.write("%6s%5d %4s%1s%3s %1s%4d%1s %8.3f%8.3f%8.3f%6.2f%6.2f\n" % ( + header, serial, name, iCode, resname, chainID, resSeq, iCode, x, y, z, occupancy, tempFactor)) xyz.close() ############################################################################################################################# + + def unitvector(v): - normal = np.linalg.norm(v) - UV = v/normal - return UV + normal = np.linalg.norm(v) + UV = v/normal + return UV ############################################################################################################################# @@ -227,213 +245,248 @@ def unitvector(v): ############################################################################################################################# ############################################################################################################################# ############################################################################################################################# -class inputdata1: - def __init__(self): - - global proteinfile - - self.window = Toplevel() - self.window.resizable(0,0) - self.window.title("Welcome to WaterDock 2.0") - Label(self.window, text = "Predicting Waters in Apo-protein Structures").grid(row =1, sticky = E) - - - self.ligopt = StringVar() - self.profilename = StringVar() - self.ligfilename = StringVar() - self.xcom = StringVar() - self.ycom = StringVar() - self.zcom = StringVar() - - self.profilenameentry = StringVar() - - - Label(self.window, text= "Import Protein from File (pdbqt)").grid(row=2, column=0, sticky=E) - self.E1 = Entry(self.window, textvariable=self.profilenameentry) - self.E1.grid(row=2, column=1) - Button(self.window, text="Choose", command=self.profilechoose).grid(row=2, column=2, sticky = W) - - Label(self.window, text = "Identifying the binding site").grid(row=4,column=0, sticky = W) - - Radiobutton(self.window, text="Enter Center of Box (A)", variable = self.ligopt, value = '1').grid(row=5, column=0, sticky=E) - Label(self.window, text='X').grid(row=5, column=1, sticky=E) - Entry(self.window, textvariable=self.xcom).grid(row=5, column=2) - Label(self.window, text='Y').grid(row=5, column=3, sticky=E) - Entry(self.window, textvariable=self.ycom).grid(row=5, column=4) - Label(self.window, text='Z').grid(row=5, column=5, sticky=E) - Entry(self.window, textvariable=self.zcom).grid(row=5, column=6) - - Radiobutton(self.window, text="Co-ordinates from Ligand file (mol2/pdb/pdbqt)", variable = self.ligopt, value = '2').grid(row=6, column=0, sticky=E) - self.E2 = Entry(self.window, textvariable=self.ligfilename) - self.E2.grid(row=6, column=1) - Button(self.window, text="Choose", command=self.ligfilechoose).grid(row=6, column=2, sticky = W) - - - Button(self.window, text="Run", command=self.rungui).grid(row=13, column=3, sticky=E) - Button(self.window, text="Cancel", command=self.byebye).grid(row=13, column=4, sticky=E) - self.window.mainloop() - - def profilechoose(self): - - self.profilenamechoose = tkinter.filedialog.askopenfilename() - - self.E1.delete(0, END) - self.E1.insert(0, self.profilenamechoose) - - - def ligfilechoose(self): - self.ligfilename = tkinter.filedialog.askopenfilename(filetypes=(("pdb files", "*.pdb"), ("pdbqt files", "*.pdbqt"), ("mol2 files", "*.mol2"))) - self.E2.insert(0, self.ligfilename) - - def byebye(self): - self.window.destroy() - - def rungui(self): - - global proteinfile, ligandoption, ligandfile, centerx, centery, centerz - if hasattr(self.ligopt, 'get'): - ligandoption = self.ligopt.get() - - proteinfile = self.E1.get() - - if int(os.path.isfile(proteinfile)) == 0: - tkinter.messagebox.showerror(title='Missing File', message='Protein File does not exist') - sys.exit() - - if ligandoption == '2': - if hasattr(self.E2, 'get'): - ligandfile = self.E2.get() - if int(os.path.isfile(ligandfile)) == 0: - tkinter.messagebox.showerror(title='Missing File', message='Ligand File does not exist') - sys.exit() - - elif ligandoption == '1': - if hasattr(self.xcom,'get'): - centerx = self.xcom.get() - centerx = float(centerx) - if hasattr(self.ycom,'get'): - centery = self.ycom.get() - centery = float(centery) - if hasattr(self.zcom,'get'): - centerz = self.zcom.get() - centerz = float(centerz) - if ligandoption == 2: - - UL = MDAnalysis.Universe(ligandfile) - if ligandfile[-5:] == 'pdbqt': - heavylig = UL.select_atoms('not type HD') - else: - heavylig = UL.select_atoms('not type H') - - com = np.mean(heavylig.positions, axis = 0) - centerx = com[0] - centery = com[1] - centerz = com[2] - - self.window.quit() +class inputdata1: + def __init__(self): + + global proteinfile + + self.window = Toplevel() + self.window.resizable(0, 0) + self.window.title("Welcome to WaterDock 2.0") + Label(self.window, text="Predicting Waters in Apo-protein Structures").grid(row=1, sticky=E) + + self.ligopt = StringVar() + self.profilename = StringVar() + self.ligfilename = StringVar() + self.xcom = StringVar() + self.ycom = StringVar() + self.zcom = StringVar() + + self.profilenameentry = StringVar() + + Label(self.window, text="Import Protein from File (pdbqt)").grid( + row=2, column=0, sticky=E) + self.E1 = Entry(self.window, textvariable=self.profilenameentry) + self.E1.grid(row=2, column=1) + Button(self.window, text="Choose", command=self.profilechoose).grid( + row=2, column=2, sticky=W) + + Label(self.window, text="Identifying the binding site").grid( + row=4, column=0, sticky=W) + + Radiobutton(self.window, text="Enter Center of Box (A)", + variable=self.ligopt, value='1').grid(row=5, column=0, sticky=E) + Label(self.window, text='X').grid(row=5, column=1, sticky=E) + Entry(self.window, textvariable=self.xcom).grid(row=5, column=2) + Label(self.window, text='Y').grid(row=5, column=3, sticky=E) + Entry(self.window, textvariable=self.ycom).grid(row=5, column=4) + Label(self.window, text='Z').grid(row=5, column=5, sticky=E) + Entry(self.window, textvariable=self.zcom).grid(row=5, column=6) + + Radiobutton(self.window, text="Co-ordinates from Ligand file (mol2/pdb/pdbqt)", + variable=self.ligopt, value='2').grid(row=6, column=0, sticky=E) + self.E2 = Entry(self.window, textvariable=self.ligfilename) + self.E2.grid(row=6, column=1) + Button(self.window, text="Choose", command=self.ligfilechoose).grid( + row=6, column=2, sticky=W) + + Button(self.window, text="Run", command=self.rungui).grid( + row=13, column=3, sticky=E) + Button(self.window, text="Cancel", command=self.byebye).grid( + row=13, column=4, sticky=E) + self.window.mainloop() + + def profilechoose(self): + + self.profilenamechoose = tkinter.filedialog.askopenfilename() + + self.E1.delete(0, END) + self.E1.insert(0, self.profilenamechoose) + + def ligfilechoose(self): + self.ligfilename = tkinter.filedialog.askopenfilename(filetypes=( + ("pdb files", "*.pdb"), ("pdbqt files", "*.pdbqt"), ("mol2 files", "*.mol2"))) + self.E2.insert(0, self.ligfilename) + + def byebye(self): + self.window.destroy() + + def rungui(self): + + global proteinfile, ligandoption, ligandfile, centerx, centery, centerz + if hasattr(self.ligopt, 'get'): + ligandoption = self.ligopt.get() + + proteinfile = self.E1.get() + + if int(os.path.isfile(proteinfile)) == 0: + tkinter.messagebox.showerror( + title='Missing File', message='Protein File does not exist') + sys.exit() + + if ligandoption == '2': + if hasattr(self.E2, 'get'): + ligandfile = self.E2.get() + if int(os.path.isfile(ligandfile)) == 0: + tkinter.messagebox.showerror( + title='Missing File', message='Ligand File does not exist') + sys.exit() + + elif ligandoption == '1': + if hasattr(self.xcom, 'get'): + centerx = self.xcom.get() + centerx = float(centerx) + if hasattr(self.ycom, 'get'): + centery = self.ycom.get() + centery = float(centery) + if hasattr(self.zcom, 'get'): + centerz = self.zcom.get() + centerz = float(centerz) + + if ligandoption == 2: + + UL = MDAnalysis.Universe(ligandfile) + if ligandfile[-5:] == 'pdbqt': + heavylig = UL.select_atoms('not type HD') + else: + heavylig = UL.select_atoms('not type H') + + com = np.mean(heavylig.positions, axis=0) + centerx = com[0] + centery = com[1] + centerz = com[2] + + self.window.quit() ######################################################################################################################## ############################################################################################################################# ############################################################################################################################# -class inputdata2: - def __init__(self): - global proteinfile - self.window = Toplevel() - self.window.resizable(0,0) - self.window.title("Welcome to WaterDock 2.0") - Label(self.window, text = "Predicting Waters in Holo-protein Structures").grid(row =1, sticky = E) +class inputdata2: + def __init__(self): - - self.profilename = StringVar() - self.ligfilename = StringVar() + global proteinfile - self.profilenameentry = StringVar() + self.window = Toplevel() + self.window.resizable(0, 0) + self.window.title("Welcome to WaterDock 2.0") + Label(self.window, text="Predicting Waters in Holo-protein Structures").grid(row=1, sticky=E) - - Label(self.window, text= "Import Protein from File (pdbqt)").grid(row=2, column=0, sticky=E) - self.E1 = Entry(self.window, textvariable=self.profilenameentry) - self.E1.grid(row=2, column=1) - Button(self.window, text="Choose", command=self.profilechoose).grid(row=2, column=2, sticky = W) + self.profilename = StringVar() + self.ligfilename = StringVar() - - Label(self.window, text= "Import Ligand from File (pdb/mol2)").grid(row=3, column=0, sticky=E) - self.E2 = Entry(self.window, textvariable=self.ligfilename) - self.E2.grid(row=3, column=1) - Button(self.window, text="Choose", command=self.ligfilechoose).grid(row=3, column=2, sticky = W) - + self.profilenameentry = StringVar() - Button(self.window, text="Run", command=self.rungui).grid(row=4, column=3, sticky=E) - Button(self.window, text="Cancel", command=self.byebye).grid(row=4, column=4, sticky=E) - self.window.mainloop() + Label(self.window, text="Import Protein from File (pdbqt)").grid( + row=2, column=0, sticky=E) + self.E1 = Entry(self.window, textvariable=self.profilenameentry) + self.E1.grid(row=2, column=1) + Button(self.window, text="Choose", command=self.profilechoose).grid( + row=2, column=2, sticky=W) - def profilechoose(self): + Label(self.window, text="Import Ligand from File (pdb/mol2)").grid(row=3, + column=0, sticky=E) + self.E2 = Entry(self.window, textvariable=self.ligfilename) + self.E2.grid(row=3, column=1) + Button(self.window, text="Choose", command=self.ligfilechoose).grid( + row=3, column=2, sticky=W) - self.profilenamechoose = tkinter.filedialog.askopenfilename() + Button(self.window, text="Run", command=self.rungui).grid( + row=4, column=3, sticky=E) + Button(self.window, text="Cancel", command=self.byebye).grid( + row=4, column=4, sticky=E) + self.window.mainloop() - self.E1.delete(0, END) - self.E1.insert(0, self.profilenamechoose) + def profilechoose(self): + self.profilenamechoose = tkinter.filedialog.askopenfilename() - def ligfilechoose(self): - self.ligfilename = tkinter.filedialog.askopenfilename(filetypes=(("pdb files", "*.pdb"), ("pdbqt files", "*.pdbqt"), ("mol2 files", "*.mol2"))) - self.E2.insert(0, self.ligfilename) + self.E1.delete(0, END) + self.E1.insert(0, self.profilenamechoose) - def byebye(self): - self.window.destroy() + def ligfilechoose(self): + self.ligfilename = tkinter.filedialog.askopenfilename(filetypes=( + ("pdb files", "*.pdb"), ("pdbqt files", "*.pdbqt"), ("mol2 files", "*.mol2"))) + self.E2.insert(0, self.ligfilename) - def rungui(self): + def byebye(self): + self.window.destroy() - global proteinfile, ligandfile + def rungui(self): - proteinfile = self.E1.get() + global proteinfile, ligandfile + proteinfile = self.E1.get() - if int(os.path.isfile(proteinfile)) == 0: - tkinter.messagebox.showerror(title='Missing File', message='Protein File does not exist') - sys.exit() - - if hasattr(self.E2, 'get'): - ligandfile = self.E2.get() - if int(os.path.isfile(ligandfile)) == 0: - tkinter.messagebox.showerror(title='Missing File', message='Ligand File does not exist') - sys.exit() + if int(os.path.isfile(proteinfile)) == 0: + tkinter.messagebox.showerror( + title='Missing File', message='Protein File does not exist') + sys.exit() - self.window.quit() + if hasattr(self.E2, 'get'): + ligandfile = self.E2.get() + if int(os.path.isfile(ligandfile)) == 0: + tkinter.messagebox.showerror( + title='Missing File', message='Ligand File does not exist') + sys.exit() + + self.window.quit() ######################################################################################################################## ############################################################################################################################# ############################################################################################################################# -class vinapath: - def __init__(self): - self.window = Toplevel() - self.window.resizable(0,0) - self.window.title('Unable to find Vina executable') - - self.vinapathway = StringVar() +class vinapath: + def __init__(self): - Label(self.window, text = "Enter the path to the vina executable").grid(row = 1, column = 0, sticky = E) + self.window = Toplevel() + self.window.resizable(0, 0) + self.window.title('Unable to find Vina executable') - self.L1 = Entry(self.window, textvariable=self.vinapathway) - self.L1.grid(row = 1, column = 1) + self.vinapathway = StringVar() - Button(self.window, text="OK", command=self.okay).grid(row=2, column=1, sticky=E) - self.window.mainloop() + Label(self.window, text="Enter the path to the vina executable").grid( + row=2, column=0, sticky=E) + self.L1 = Entry(self.window, textvariable=self.vinapathway) + self.L1.grid(row=2, column=1) - def okay(self): +# Button(self.window, text="OK", command=self.okay).grid(row=2, column=1, sticky=E) +# Use dialog to force selection of something an restrict false entries - if hasattr(self.L1,'get'): - self.vinapathway = self.L1.get() + Button(self.window, text="Choose", command=self.vinafilechoose).grid( + row=2, column=2, sticky=W) - homedir = str(os.environ.get('HOME')) - file = homedir + '/pyvina.txt' + Button(self.window, text="OK", command=self.okay).grid( + row=4, column=3, sticky=E) + Button(self.window, text="Cancel", command=self.byebye).grid( + row=4, column=4, sticky=E) - f1 = open(file,'w') - f1.write(str(self.vinapathway)) - f1.close() + self.window.mainloop() - self.window.quit() + def vinafilechoose(self): + self.vinafilenamechoose = tkinter.filedialog.askopenfilename() + + self.L1.delete(0, END) + self.L1.insert(0, self.vinafilenamechoose) + + def byebye(self): + self.window.destroy() + + def okay(self): + + if hasattr(self.L1, 'get'): + self.vinapathway = self.L1.get() + else: + tkinter.messagebox.showerror( + title='Missing File', message='Ligand File does not exist') + sys.exit() + + homedir = str(os.environ.get('HOME')) + file = homedir + '/pyvina.txt' + f1 = open(file, 'w') + f1.write(str(self.vinapathway)) + f1.close() + self.window.quit() From e6b6b7fb8da837f8a69c819e1476c9aed293ea6d Mon Sep 17 00:00:00 2001 From: philbiggin Date: Mon, 11 May 2020 10:09:59 -0700 Subject: [PATCH 3/4] tk window refinement --- __init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/__init__.py b/__init__.py index aaed540..8c3097c 100644 --- a/__init__.py +++ b/__init__.py @@ -124,6 +124,7 @@ def option1(): cmd.load('predictedwaters.pdb', 'wats') cmd.color('red', 'wats') cmd.center('wats') + ############################################################################################################################# ############################################################################################################################# ############################################################################################################################# @@ -252,6 +253,7 @@ def __init__(self): global proteinfile + tkinter.Tk().withdraw() self.window = Toplevel() self.window.resizable(0, 0) self.window.title("Welcome to WaterDock 2.0") @@ -369,6 +371,7 @@ def __init__(self): global proteinfile + tkinter.Tk().withdraw() self.window = Toplevel() self.window.resizable(0, 0) self.window.title("Welcome to WaterDock 2.0") @@ -468,7 +471,7 @@ def __init__(self): def vinafilechoose(self): self.vinafilenamechoose = tkinter.filedialog.askopenfilename() - + self.L1.delete(0, END) self.L1.insert(0, self.vinafilenamechoose) From 795460b52190db7672c159eb2aaab85646967d13 Mon Sep 17 00:00:00 2001 From: mccubbinp <52162736+mccubbinp@users.noreply.github.com> Date: Sat, 11 Sep 2021 13:49:29 +0100 Subject: [PATCH 4/4] Update __init__.py --- __init__.py | 583 +++++++++++++++++++++++++++------------------------- 1 file changed, 301 insertions(+), 282 deletions(-) diff --git a/__init__.py b/__init__.py index 8c3097c..b7b5f12 100644 --- a/__init__.py +++ b/__init__.py @@ -1,12 +1,11 @@ -from tkinter import * -import scipy.cluster +from pymol.Qt import QtWidgets as qtw +from pymol.Qt import QtCore as qtc from pymol import cmd +from pymol import plugins import numpy as np +import scipy.cluster import os import sys -import tkinter.simpledialog -import tkinter.messagebox -import tkinter.filedialog import distutils.spawn import MDAnalysis @@ -16,43 +15,30 @@ #################################################################################################################################################### - -def __init__(self): - - self.menuBar.addmenuitem('Plugin', 'command', 'Apo-WaterDock', - label='Apo-WaterDock', command=lambda s=self: option1()) - self.menuBar.addmenuitem('Plugin', 'command', 'Holo-Waterdock', - label='Holo-waterdock', command=lambda s=self: option2()) +def __init_plugin__(app=None): + plugins.addmenuitemqt('Apo-WaterDock', option1) + plugins.addmenuitemqt('Holo-waterdock', option2) + +dialog = None #global reference avoids garbage collection ################################################################################################################################################### - def option1(): - + + global dialog vinacomd = str(checkutilities()) - A = inputdata1() - - global proteinfile, ligandoption, ligandfile, centerx, centery, centerz - - if ligandoption == '2': - - UL = MDAnalysis.Universe(ligandfile) - if ligandfile[-5:] == 'pdbqt': - heavylig = UL.select_atoms('not type HD') - else: - heavylig = UL.select_atoms('not type H') - - com = np.mean(heavylig.positions, axis=0) - centerx = com[0] - centery = com[1] - centerz = com[2] + dialog = inputdata1() + + if dialog.result() == 1: + runapowaterdock(vinacomd, dialog.proteinfile, dialog.centerx, dialog.centery, dialog.centerz) + +def runapowaterdock(vinacomd, proteinfile, centerx, centery, centerz): waterfile() - proteinpdbqtfile = proteinfile f1 = open('vinaconfig.txt', 'w') f1.write('receptor = ') - f1.write(str(proteinpdbqtfile)) + f1.write(str(proteinfile)) f1.write('\nligand = water.pdbqt') f1.write('\nexhaustiveness = 20') f1.write('\nnum_modes = 20') @@ -126,16 +112,17 @@ def option1(): cmd.center('wats') ############################################################################################################################# -############################################################################################################################# -############################################################################################################################# - def option2(): - + + global dialog vinacomd = str(checkutilities()) - A = inputdata2() + dialog = inputdata2() + + if dialog.result() == 1: + runholowaterdock(vinacomd, dialog.proteinfile, dialog.ligandfile) - global proteinfile, ligandfile +def runholowaterdock(vinacomd, proteinfile, ligandfile): from . import addwater addwater.main(ligandfile) @@ -166,26 +153,31 @@ def option2(): def checkutilities(): zz = distutils.spawn.find_executable('vina') - homedir = str(os.environ.get('HOME')) - file = homedir + '/pyvina.txt' - if zz: + homedir = str(os.path.expanduser('~')) + file = os.path.join(homedir, 'pyvina.txt') + + if zz: # Found vina under command 'vina' if os.path.isfile(zz): vinacomd = zz - elif os.path.isfile(file): - fzz = open(file, 'r') - vinacomd = fzz.read() - fzz.close() - - else: - ZZ = vinapath() + elif os.path.isfile(file): # Previously stored the path to vina executible in pyvina.txt file fzz = open(file, 'r') vinacomd = fzz.read() fzz.close() + else: # Needs user to input path to vina executable + + vinapath_dialog = vinapath() + vinapath_dialog.show() + vinapath_dialog.raise_() + + if vinapath_dialog.result() == 1: + fzz = open(file, 'r') + vinacomd = fzz.read() + fzz.close() + return vinacomd - ############################################################################################################################# def waterfile(): f1 = open('water.pdbqt', 'w') @@ -230,15 +222,6 @@ def write_waterpdb(waterfilename, coordinates): header, serial, name, iCode, resname, chainID, resSeq, iCode, x, y, z, occupancy, tempFactor)) xyz.close() -############################################################################################################################# - - -def unitvector(v): - normal = np.linalg.norm(v) - UV = v/normal - return UV - -############################################################################################################################# ############################################################################################################################# ############################################################################################################################# @@ -247,249 +230,285 @@ def unitvector(v): ############################################################################################################################# ############################################################################################################################# - -class inputdata1: - def __init__(self): - - global proteinfile - - tkinter.Tk().withdraw() - self.window = Toplevel() - self.window.resizable(0, 0) - self.window.title("Welcome to WaterDock 2.0") - Label(self.window, text="Predicting Waters in Apo-protein Structures").grid(row=1, sticky=E) - - self.ligopt = StringVar() - self.profilename = StringVar() - self.ligfilename = StringVar() - self.xcom = StringVar() - self.ycom = StringVar() - self.zcom = StringVar() - - self.profilenameentry = StringVar() - - Label(self.window, text="Import Protein from File (pdbqt)").grid( - row=2, column=0, sticky=E) - self.E1 = Entry(self.window, textvariable=self.profilenameentry) - self.E1.grid(row=2, column=1) - Button(self.window, text="Choose", command=self.profilechoose).grid( - row=2, column=2, sticky=W) - - Label(self.window, text="Identifying the binding site").grid( - row=4, column=0, sticky=W) - - Radiobutton(self.window, text="Enter Center of Box (A)", - variable=self.ligopt, value='1').grid(row=5, column=0, sticky=E) - Label(self.window, text='X').grid(row=5, column=1, sticky=E) - Entry(self.window, textvariable=self.xcom).grid(row=5, column=2) - Label(self.window, text='Y').grid(row=5, column=3, sticky=E) - Entry(self.window, textvariable=self.ycom).grid(row=5, column=4) - Label(self.window, text='Z').grid(row=5, column=5, sticky=E) - Entry(self.window, textvariable=self.zcom).grid(row=5, column=6) - - Radiobutton(self.window, text="Co-ordinates from Ligand file (mol2/pdb/pdbqt)", - variable=self.ligopt, value='2').grid(row=6, column=0, sticky=E) - self.E2 = Entry(self.window, textvariable=self.ligfilename) - self.E2.grid(row=6, column=1) - Button(self.window, text="Choose", command=self.ligfilechoose).grid( - row=6, column=2, sticky=W) - - Button(self.window, text="Run", command=self.rungui).grid( - row=13, column=3, sticky=E) - Button(self.window, text="Cancel", command=self.byebye).grid( - row=13, column=4, sticky=E) - self.window.mainloop() - +class inputdata1(qtw.QDialog): + + def __init__(self, *args, **kwargs): + + super().__init__(*args, **kwargs) + + self.setWindowTitle("Welcome to WaterDock 2.0") + + #Interactive Widgets + self.protein_file_input = qtw.QLineEdit() + self.protein_file_choose_button = qtw.QPushButton('Choose') + self.ligand_coordinates_inputted = qtw.QRadioButton('Enter center of box (A)') + self.coordinates_widget = qtw.QWidget() + self.xcom_input = qtw.QLineEdit() + self.ycom_input = qtw.QLineEdit() + self.zcom_input = qtw.QLineEdit() + self.ligand_file_inputted = qtw.QRadioButton( + 'Coordinates from ligand file (mol2/pdb/pdbqt)') + self.ligand_file_input = qtw.QLineEdit() + self.ligand_file_choose_button = qtw.QPushButton('Choose') + self.cancelrun_widget = qtw.QWidget() + self.run_button = qtw.QPushButton('Run') + self.cancel_button = qtw.QPushButton('Cancel') + self.coordinates_widget.setEnabled(False) + self.ligand_file_input.setEnabled(False) + self.ligand_file_choose_button.setEnabled(False) + self.ligopt = 0 + + #Layout + layout = qtw.QGridLayout() + layout.addWidget(qtw.QLabel('Predicting Waters in Apo-protein Structures'), 0,0) + layout.addWidget(qtw.QLabel('Import protein from File (pdbqt)'),3,0) + layout.addWidget(self.protein_file_input, 3,1) + layout.addWidget(self.protein_file_choose_button, 3,2) + + layout.addWidget(qtw.QLabel('Identify the ligand binding site'), 6,0) + self.coordinates_widget.setLayout(qtw.QHBoxLayout()) + self.coordinates_widget.layout().addWidget(qtw.QLabel('X')) + self.coordinates_widget.layout().addWidget(self.xcom_input) + self.coordinates_widget.layout().addWidget(qtw.QLabel('Y')) + self.coordinates_widget.layout().addWidget(self.ycom_input) + self.coordinates_widget.layout().addWidget(qtw.QLabel('Z')) + self.coordinates_widget.layout().addWidget(self.zcom_input) + layout.addWidget(self.ligand_coordinates_inputted, 7,0) + layout.addWidget(self.coordinates_widget, 7,1) + layout.addWidget(self.ligand_file_inputted, 8,0) + layout.addWidget(self.ligand_file_input, 8,1) + layout.addWidget(self.ligand_file_choose_button, 8,2) + + self.cancelrun_widget.setLayout(qtw.QHBoxLayout()) + self.cancelrun_widget.layout().addWidget(self.run_button) + self.cancelrun_widget.layout().addWidget(self.cancel_button) + layout.addWidget(self.cancelrun_widget, 10,0,1,4, qtc.Qt.AlignHCenter) + + layout.setSizeConstraint(layout.SetFixedSize) + for row in range(0,8): + layout.setRowMinimumHeight(row, 15) + self.setLayout(layout) + + # Connect signals to functions/slots + self.protein_file_choose_button.clicked.connect(self.profilechoose) + self.ligand_coordinates_inputted.clicked.connect(self.coordinpoptionchecked) + self.ligand_file_inputted.clicked.connect(self.ligfileoptionchecked) + self.ligand_file_choose_button.clicked.connect(self.ligfilechoose) + self.run_button.clicked.connect(self.rungui) + self.cancel_button.clicked.connect(self.reject) + + # Display + self.exec() + self.raise_() + def profilechoose(self): - - self.profilenamechoose = tkinter.filedialog.askopenfilename() - - self.E1.delete(0, END) - self.E1.insert(0, self.profilenamechoose) - + self.protein_file_input.clear() + file_filter = "pdbqt files (*.pdbqt)" + profilenamechoose = qtw.QFileDialog().getOpenFileName(None, '', '', file_filter)[0] + self.protein_file_input.insert(profilenamechoose) + def ligfilechoose(self): - self.ligfilename = tkinter.filedialog.askopenfilename(filetypes=( - ("pdb files", "*.pdb"), ("pdbqt files", "*.pdbqt"), ("mol2 files", "*.mol2"))) - self.E2.insert(0, self.ligfilename) - - def byebye(self): - self.window.destroy() - + self.ligand_file_input.clear() + file_filter = "pdb files (*.pdb);; pdbqt files (*.pdbqt);; mol2 files (*.mol2)" + ligfilenamechoose = qtw.QFileDialog().getOpenFileName(None, '', '', file_filter)[0] + self.ligand_file_input.insert(ligfilenamechoose) + + def coordinpoptionchecked(self): + self.coordinates_widget.setEnabled(True) + self.ligand_file_input.setEnabled(False) + self.ligand_file_choose_button.setEnabled(False) + self.ligopt = int(1) + + def ligfileoptionchecked(self): + self.coordinates_widget.setEnabled(False) + self.ligand_file_input.setEnabled(True) + self.ligand_file_choose_button.setEnabled(True) + self.ligopt = int(2) + def rungui(self): - - global proteinfile, ligandoption, ligandfile, centerx, centery, centerz - if hasattr(self.ligopt, 'get'): - ligandoption = self.ligopt.get() - - proteinfile = self.E1.get() - - if int(os.path.isfile(proteinfile)) == 0: - tkinter.messagebox.showerror( - title='Missing File', message='Protein File does not exist') - sys.exit() - - if ligandoption == '2': - if hasattr(self.E2, 'get'): - ligandfile = self.E2.get() - if int(os.path.isfile(ligandfile)) == 0: - tkinter.messagebox.showerror( - title='Missing File', message='Ligand File does not exist') - sys.exit() - - elif ligandoption == '1': - if hasattr(self.xcom, 'get'): - centerx = self.xcom.get() - centerx = float(centerx) - if hasattr(self.ycom, 'get'): - centery = self.ycom.get() - centery = float(centery) - if hasattr(self.zcom, 'get'): - centerz = self.zcom.get() - centerz = float(centerz) - - if ligandoption == 2: - - UL = MDAnalysis.Universe(ligandfile) - if ligandfile[-5:] == 'pdbqt': - heavylig = UL.select_atoms('not type HD') + + self.proteinfile = '' + self.centerx = None + self.centery = None + self.centerz = None + + if os.path.isfile(self.protein_file_input.text()): + self.proteinfile = self.protein_file_input.text() + else: + warning_proteinfile = qtw.QMessageBox(2, 'Missing File', 'Absolute path to protein File has not been inputted or file does not exist') + warning_proteinfile.exec() + + if self.ligopt == 1: + if self.xcom_input.text() and self.ycom_input.text() and self.zcom_input.text(): + try: + self.centerx = float(self.xcom_input.text()) + self.centery = float(self.ycom_input.text()) + self.centerz = float(self.zcom_input.text()) + except ValueError: + warning_coord_NaN = qtw.QMessageBox(2, 'Incorrect Coordinate(s)', 'Please use integer or decimal for every ligand binding site coordinate') + warning_coord_NaN.exec() + else: + warning_missing_coord = qtw.QMessageBox(2, 'Missing Coordinate(s)', 'Please specify X, Y, Z for center of box') + warning_missing_coord.exec() + + elif self.ligopt == 2: + if os.path.isfile(self.ligand_file_input.text()): + ligandfile = self.ligand_file_input.text() + + UL = MDAnalysis.Universe(ligandfile) + + if ligandfile[-5:] == 'pdbqt': + heavylig = UL.select_atoms('not type HD') + else: + heavylig = UL.select_atoms('not type H') + + com = np.mean(heavylig.positions, axis=0) + self.centerx = float(com[0]) + self.centery = float(com[1]) + self.centerz = float(com[2]) + else: - heavylig = UL.select_atoms('not type H') + warning_ligandfile = qtw.QMessageBox(2, 'Missing File', 'Absolute path to ligand file has not been inputted or file does not exist') + warning_ligandfile.exec() + + else: + warning_ligoption = qtw.QMessageBox(2, 'Missing Ligand Binding Site Information', 'Please select an option for identifying the ligand binding site') + warning_ligoption.exec() + + coord_test = isinstance(self.centerx, float) and isinstance(self.centery, float) and isinstance(self.centerz, float) + if os.path.isfile(self.proteinfile) and coord_test: + self.accept() - com = np.mean(heavylig.positions, axis=0) - centerx = com[0] - centery = com[1] - centerz = com[2] - self.window.quit() ######################################################################################################################## ############################################################################################################################# ############################################################################################################################# - -class inputdata2: - def __init__(self): - - global proteinfile - - tkinter.Tk().withdraw() - self.window = Toplevel() - self.window.resizable(0, 0) - self.window.title("Welcome to WaterDock 2.0") - Label(self.window, text="Predicting Waters in Holo-protein Structures").grid(row=1, sticky=E) - - self.profilename = StringVar() - self.ligfilename = StringVar() - - self.profilenameentry = StringVar() - - Label(self.window, text="Import Protein from File (pdbqt)").grid( - row=2, column=0, sticky=E) - self.E1 = Entry(self.window, textvariable=self.profilenameentry) - self.E1.grid(row=2, column=1) - Button(self.window, text="Choose", command=self.profilechoose).grid( - row=2, column=2, sticky=W) - - Label(self.window, text="Import Ligand from File (pdb/mol2)").grid(row=3, - column=0, sticky=E) - self.E2 = Entry(self.window, textvariable=self.ligfilename) - self.E2.grid(row=3, column=1) - Button(self.window, text="Choose", command=self.ligfilechoose).grid( - row=3, column=2, sticky=W) - - Button(self.window, text="Run", command=self.rungui).grid( - row=4, column=3, sticky=E) - Button(self.window, text="Cancel", command=self.byebye).grid( - row=4, column=4, sticky=E) - self.window.mainloop() - +class inputdata2(qtw.QDialog): + def __init__(self, *args, **kwargs): + + super().__init__(*args, **kwargs) + + self.setWindowTitle("Welcome to WaterDock 2.0") + + # Interactive widgets + self.protein_file_input = qtw.QLineEdit() + self.protein_file_choose_button = qtw.QPushButton('Choose') + self.ligand_file_input = qtw.QLineEdit() + self.ligand_file_choose_button = qtw.QPushButton('Choose') + self.run_button = qtw.QPushButton('Run') + self.cancel_button = qtw.QPushButton('Cancel') + + #Layout + layout = qtw.QGridLayout() + layout.addWidget(qtw.QLabel("Predicting Waters in Holo-protein Structures"), 0,0,1,5) + layout.addWidget(qtw.QLabel("Import protein from File (pdbqt)"), 1,0) + layout.addWidget(self.protein_file_input,1,1) + layout.addWidget(self.protein_file_choose_button,1,2) + layout.addWidget(qtw.QLabel("Import ligand from File (pdb/pdbqt/mol2)"),2,0) # Need to deduce if can take pdbqt file + layout.addWidget(self.ligand_file_input,2,1) + layout.addWidget(self.ligand_file_choose_button,2,2) + layout.addWidget(self.run_button,3,3) + layout.addWidget(self.cancel_button,3,4) + layout.setSizeConstraint(layout.SetFixedSize) + self.setLayout(layout) + + # Connect signals to functions/slots + self.protein_file_choose_button.clicked.connect(self.profilechoose) + self.ligand_file_choose_button.clicked.connect(self.ligfilechoose) + self.run_button.clicked.connect(self.rungui) + self.cancel_button.clicked.connect(self.reject) + + # Display + self.exec() + self.raise_() + def profilechoose(self): - - self.profilenamechoose = tkinter.filedialog.askopenfilename() - - self.E1.delete(0, END) - self.E1.insert(0, self.profilenamechoose) - + self.protein_file_input.clear() + file_filter = "pdbqt files (*.pdbqt)" # required input for Vina + protfilenamechoose = qtw.QFileDialog().getOpenFileName(None, '', '', file_filter)[0] + self.protein_file_input.insert(protfilenamechoose) + def ligfilechoose(self): - self.ligfilename = tkinter.filedialog.askopenfilename(filetypes=( - ("pdb files", "*.pdb"), ("pdbqt files", "*.pdbqt"), ("mol2 files", "*.mol2"))) - self.E2.insert(0, self.ligfilename) - - def byebye(self): - self.window.destroy() - + self.ligand_file_input.clear() + file_filter = "pdb files (*.pdb);; pdbqt files (*.pdbqt);; mol2 files (*.mol2)" + ligfilenamechoose = qtw.QFileDialog.getOpenFileName(None, '', '', file_filter)[0] + self.ligand_file_input.insert(ligfilenamechoose) + def rungui(self): - - global proteinfile, ligandfile - - proteinfile = self.E1.get() - - if int(os.path.isfile(proteinfile)) == 0: - tkinter.messagebox.showerror( - title='Missing File', message='Protein File does not exist') - sys.exit() - - if hasattr(self.E2, 'get'): - ligandfile = self.E2.get() - if int(os.path.isfile(ligandfile)) == 0: - tkinter.messagebox.showerror( - title='Missing File', message='Ligand File does not exist') - sys.exit() - - self.window.quit() + + self.proteinfile = '' + self.ligandfile = '' + + if os.path.isfile(self.protein_file_input.text()): + self.proteinfile = self.protein_file_input.text() + else: + warning_proteinfile = qtw.QMessageBox(2, 'Missing File', 'Absolute path to protein file has not been inputted or file does not exist') + warning_proteinfile.exec() + + if os.path.isfile(self.ligand_file_input.text()): + self.ligandfile = self.ligand_file_input.text() + else: + warning_ligandfile = qtw.QMessageBox(2, 'Missing File', 'Absolute path to ligand file has not been inputted or file does not exist') + warning_ligandfile.exec() + + if os.path.isfile(self.proteinfile) and os.path.isfile(self.ligandfile): + self.accept() + ######################################################################################################################## ############################################################################################################################# ############################################################################################################################# - -class vinapath: - def __init__(self): - - self.window = Toplevel() - self.window.resizable(0, 0) - self.window.title('Unable to find Vina executable') - - self.vinapathway = StringVar() - - Label(self.window, text="Enter the path to the vina executable").grid( - row=2, column=0, sticky=E) - self.L1 = Entry(self.window, textvariable=self.vinapathway) - self.L1.grid(row=2, column=1) - -# Button(self.window, text="OK", command=self.okay).grid(row=2, column=1, sticky=E) -# Use dialog to force selection of something an restrict false entries - - Button(self.window, text="Choose", command=self.vinafilechoose).grid( - row=2, column=2, sticky=W) - - Button(self.window, text="OK", command=self.okay).grid( - row=4, column=3, sticky=E) - Button(self.window, text="Cancel", command=self.byebye).grid( - row=4, column=4, sticky=E) - - self.window.mainloop() - +class vinapath(qtw.QDialog): + + def __init__(self, *args, **kwargs): + + super().__init__(*args, **kwargs) + + self.setWindowTitle('Unable to find Vina executable') + + #Widgets + self.vinapath_input = qtw.QLineEdit() + self.choose_button = qtw.QPushButton('Choose') + self.cancel_button = qtw.QPushButton('Cancel') + self.okay_button = qtw.QPushButton('OK') + + #Layout + layout = qtw.QGridLayout() + layout.addWidget(qtw.QLabel("Enter absolute path to the vina executable." + + "\nPath will be written to file 'pyvina.txt' to save for future runs"),0,0,1,4) + layout.addWidget(self.vinapath_input,1,0) + layout.addWidget(self.choose_button,1,1) + layout.addWidget(self.cancel_button,2,2) + layout.addWidget(self.okay_button,2,3) + layout.setSizeConstraint(layout.SetFixedSize) + self.setLayout(layout) + + #Connect signals to functions + self.choose_button.clicked.connect(self.vinafilechoose) + self.cancel_button.clicked.connect(self.reject) + self.okay_button.clicked.connect(self.okay) + + self.exec() + self.raise_() + def vinafilechoose(self): - self.vinafilenamechoose = tkinter.filedialog.askopenfilename() - - self.L1.delete(0, END) - self.L1.insert(0, self.vinafilenamechoose) - - def byebye(self): - self.window.destroy() - + self.vinapath_input.clear() + vinafilenamechoose = qtw.QFileDialog().getOpenFileName()[0] + self.vinapath_input.insert(vinafilenamechoose) + def okay(self): - if hasattr(self.L1, 'get'): - self.vinapathway = self.L1.get() + if os.path.isfile(self.vinapath_input.text()): + self.vinapathway = self.vinapath_input.text() + homedir = str(os.path.expanduser('~')) + file = os.path.join(homedir, 'pyvina.txt') + f1 = open(file, 'w') + f1.write(str(self.vinapathway)) + f1.close() + self.accept() else: - tkinter.messagebox.showerror( - title='Missing File', message='Ligand File does not exist') - sys.exit() - - homedir = str(os.environ.get('HOME')) - file = homedir + '/pyvina.txt' - f1 = open(file, 'w') - f1.write(str(self.vinapathway)) - f1.close() - self.window.quit() + warning = qtw.QMessageBox(2, 'Missing Path', 'Path to vina executable has not been specified') + warning.exec() +