Coverage for PyRx.vsModel : 63%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#$Id: vsModel.py 280 2016-06-26 18:30:25Z sarkiss $ This module performs Virtual Screening using AutoDock/AutoGrid version 4 """
""" A preference page for AutoDock. """
#### 'IPreferencesPage' interface #########################################
# The page's category (e.g. 'General/Appearence'). The empty string means # that this is a top-level page.
# The page's help identifier (optional). If a help Id *is* provided then # there will be a 'Help' button shown on the preference page.
# The page name (this is what is shown in the preferences dialog.
# The path to the preferences node that contains our preferences.
#### Preferences ##########################################################
#### Traits UI views ######################################################
Group('autodock', 'autogrid', 'vina', Item(name='workspace'), Item(name='cpu_num', label="Available CPUs:")), label="AutoDock Preferences" ), )
startPage = wx.GetApp().GetTopWindow().autodockWiz.book.GetPage(0) if new and which(new) and which(self.autodock): startPage.rb.EnableItem(0, True) else: startPage.rb.EnableItem(0, False) startPage.Update() startPage.rb.SetString(0,which(self.autodock))
startPage = wx.GetApp().GetTopWindow().autodockWiz.book.GetPage(0) if new and which(new) and which(self.autodock): startPage.rb.EnableItem(0, True) else: startPage.rb.EnableItem(0, False) startPage.Update()
startPage = wx.GetApp().GetTopWindow().vinaWiz.book.GetPage(0) if new and which(new) and which(self.vina): startPage.rb.EnableItem(0, True) else: startPage.rb.EnableItem(0, False) startPage.rb.SetString(0,which(self.vina)) startPage.Update()
if new == self.workspace: return frame = wx.GetApp().GetTopWindow() frame.SetAllCursors(wx.StockCursor(wx.CURSOR_WAIT)) frame.Refresh() frame.navigator.SetSelection(frame.navigator.GetPageIndex(frame.autodockNav.autodockTree)) frame.vsModel.__init__() frame.autodockNav.autodockTree.ligandTree.tree.DeleteAllItems() frame.autodockNav.autodockTree.ligandTree.BuildTree(frame.vsModel.ligandsFolder) frame.autodockNav.autodockTree.macromoleculeTree.tree.DeleteAllItems() frame.autodockNav.autodockTree.macromoleculeTree.BuildTree(frame.vsModel.macromoleculesFolder) frame.SetAllCursors(wx.NullCursor)
# The page's help identifier (optional). If a help Id *is* provided then # there will be a 'Help' button shown on the preference page.
# The page name (this is what is shown in the preferences dialog.
# The path to the preferences node that contains our preferences.
#### Preferences ##########################################################
values = [ 'bonds', 'hydrogens',], cols = 2 ) ) #### Traits UI views ######################################################
Item(name='inactivate_all_torsions',), Item(name='limit_torsions', ), Item(name='limit_torsion_number', label="Number of torsions", visible_when ='object.limit_torsions ==True'), label="Ligand Preparation Preferences" ),
)
# The page's help identifier (optional). If a help Id *is* provided then # there will be a 'Help' button shown on the preference page.
# The page name (this is what is shown in the preferences dialog.
# The path to the preferences node that contains our preferences.
#### Preferences ########################################################## values = [ 'nphs', 'lps', 'waters', 'nonstdres'], cols = 2, ), value = ['nphs', 'lps', 'waters'], ) Nphs - merge charges and remove non-polar hydrogens Lps - merge charges and remove lone pairs Waters - remove water molecules Nonstdres - remove chains composed entirely of residues of types other than the standard 20 amino acids""") #### Traits UI views ###################################################### label="Receptor Preparation Preferences" ), Item(name="txt", style='readonly', show_label=False) )
# The page's help identifier (optional). If a help Id *is* provided then # there will be a 'Help' button shown on the preference page.
# The page name (this is what is shown in the preferences dialog.
# The path to the preferences node that contains our preferences.
#### Preferences ##########################################################
#### Traits UI views ######################################################
Item(name='URI', label = "URI"), Item(name='AutoDockService', label = "AutoDock Service"), Item(name='AutoGridService', label = "AutoGrid Service"), Item(name='VinaService', label = "Vina Service"), label="Web Services Preferences" ), )
""" Used for setting up and running Virtual Screening. Example: >>> vs = VSModel(ligands=[ind.pdb],macroMolecule='hsg1.pdb') #creates user.home/AutoDock4Data/ # Macromolecules (stores Macromolecules) # Ligands (stores Ligand) >>> vs.run() #runs AutoGrid followed by AutoDock and stores results in user.home/AutoDock4Data/ hsg1/ hsg1.A.map ... hsg1.gpf (stores AutoGrid runs) hsg1.pdbqt ind/ ind.dlf (stores AutoDock Runs) ind.dpf user.home/AutoDock4Data/ ind.pdbqt """
""" basePath - path for storing the data, if None user.home/AutoDock4Data is used. self.ligandPaths - lists of ligand paths. self.macromoleculePath - path to Macromolecule. """
#Note Folder creation can be done elsewhere os.mkdir(basePath) os.mkdir(self.macromoleculesFolder) os.mkdir(self.ligandsFolder) os.mkdir(self.etcFolder)
"Check to see if all maps dimensions are the same" firstMap = os.path.join(self.macromolecule.receptorFolder, self.macromolecule.receptor_stem+'.'+ligandTypes[0]+'.map') firstMapFile = open(firstMap) lineList = [] numberCheck = 6 for i in range(numberCheck): lineList.append(firstMapFile.readline()) for ligandType in ligandTypes[1:]: mapFile = open(filePath) for i in range(numberCheck): line = mapFile.readline() if line != lineList[i]: mapFile.close() firstMapFile.close() return False mapFile.close() firstMapFile.close() return True
self.PrepareReceptor() self.PrepareGPF() #self.runAutoGrid() #os.waitpid(self.AutoGridProcess.pid,0)
for ligandPath in self.ligandsPaths: if not os.path.exists(ligandPath): else:
mols = Read(ligandFile) if len(mols)>1: print "%d molecules in %s"%(len(mols), ligandFile) print "%s will use the first molecule as ligand"%(self.__module__) mol.buildBondsByDistance()
else: same_outCounter = 1 #this is in case outputfilename exists while os.path.exists(outputfilename): outputfilename = os.path.join(self.ligandsFolder, mol.name + "_"+ str(same_outCounter)+ ".pdbqt") same_outCounter += 1 repairs = '_'.join(ligandPreparationPage.repairs), inactivate_all_torsions = ligandPreparationPage.inactivate_all_torsions, limit_torsions = limit_torsions ) # conectRecords = None # if hasattr(mol, '_openBebel'): # writer = PdbWriter() # writer.defineConnectSection(mol.allAtoms, bondOrigin='File') # conectRecords = writer.recordsToWrite['CONECT'] # #This is needed in order to store autodock_element or TORSDOF in a file that we can access without reading the hole file # if conectRecords: # molDict['CONECT'] = conectRecords txt = "AD4LigandPreparation wrote less atoms that present in the molecule: "+mol.name txt += "\nAD4LigandPreparation wrote less atoms that present in the molecule: "+mol.name txt += "\nLocation:"+__file__ + ":PrepareLigandMol" try: wx.GetTopLevelWindows()[0].log.warning(txt) except: print txt
mol = Read(outputfilename)[0] return mol, molDict
"""Prepares molecule dictionary with key - molecules name value - dictionary ({'autodock_element':...) taken from a pickle file generated with PrepareLigandMol """
else: try: parser = PdbqtParser(ligand) mol = parser.parse()[0] pickleFileName = os.path.join(self.etcFolder, mol.name + ".pkl") #This is needed in order to store autodock_element or TORSDOF in a file that we can access without reading the hole file dict = {'autodock_element':set(mol.allAtoms.autodock_element)} dict['TORSDOF'] = mol.TORSDOF mol.getCenter() dict['center'] = mol.center pickle.dump(dict, open(pickleFileName, 'w'))
cleanup='_'.join(receptorPreparationPage.cleanup))
"Prepares _rigid.pdbqt and _flex.pdbqt files" name = flexRes[0].top.name receptorFolder = os.path.join(self.macromoleculesFolder, name+"_flex") if not os.path.isdir(receptorFolder): os.mkdir(receptorFolder) self.receptorFolder = receptorFolder rigid_filename = os.path.join(receptorFolder, name + "_rigid.pdbqt") AD4ReceptorPreparation(flexRes[0].top, outputfilename=rigid_filename, cleanup='_'.join(receptorPreparationPage.cleanup)) flexres_filename = os.path.join(receptorFolder, name+"_flex.pdbqt") flex_res_lines = [] for residue in flexRes: #handle one residue at a time. prot = Protein() allAtoms = copy.copy(residue.atoms.copy()) chain = Chain(residue.parent.name, prot, top=prot) res = Residue(residue.type, number=residue.number, parent=chain, top=prot) # res.atoms = residue.atoms for atom in allAtoms: res.adopt(atom) for b in atom.bonds: if not b.atom1 in allAtoms or not b.atom2 in allAtoms: atom.bonds.remove(b) prot.allAtoms = allAtoms prot.allAtoms.top = prot prot.parser = flexRes[0].top.parser prot.levels = [Protein, Chain, Residue, Atom] AD4FlexibleReceptorPreparation(prot, residues=[res], rigid_filename=rigid_filename+"_", flexres_filename=flexres_filename) flex_res_lines.extend(open(flexres_filename).readlines()) os.remove(rigid_filename+"_") flexres_file = open(flexres_filename, 'w') for line in flex_res_lines: flexres_file.write(line) flexres_file.close() cmp_flex_res_lines = [] for line in flex_res_lines: if line.startswith("ATOM") or line.startswith("HETATM"): for line in rigid_file_lines: self.flexres_filename = flexres_filename
#set_receptor part #gpo.set_receptor4 part
cwd = os.path.split(self.macromoleculePath)[0] outputFile = self.macromolecule.name + ".glg" cmd = autodockPreferencesPage.autogrid + " -p " + self.gpf_filename + " -l " + outputFile stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, shell=True)
round(cen[2],4)]
cmd = autodockPreferencesPage.autodock + " -p " + self.dpf_filename + " -l " + self.dpf_filename.replace('.dpf','.dlg') if sys.platform != 'win32': cmd = 'ulimit -s unlimited;' + cmd AutoDockProcess = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.dockingFolder, shell=True) return AutoDockProcess
txt = "ulimit -s unlimited\n" txt += "cd " + self.dockingFolder + "\n" txt += autodockPreferencesPage.autodock + " -p " + self.dpf_filename + " -l " + self.dpf_filename.replace('.dpf','.dlg') jobFile = self.dpf_filename.replace('.dpf','_AD') open(jobFile,'w').write(txt) cmd = "chmod +x " + jobFile + "\n" cmd += "qsub -l cput=23:00:00 -l nodes=1:ppn=1 -l walltime=23:30:00 -l mem=512mb " + jobFile #jobIDsName = jobFile + ".jobIDs" #cmd += " >>" + jobIDsName os.system(cmd) |