def createParams(self, event): # Change to the sandbox location goToSandbox() # Attempt to generate the params file try: if (os.path.isfile("LG.params")): os.remove("LG.params") if (os.path.isfile("LG.fa.params")): os.remove("LG.fa.params") if (os.path.isfile("LG.cen.params")): os.remove("LG.cen.params") molfile_to_params.main([self.loadedfile, "--no-pdb", "--keep-names", "-c"]) except: wx.MessageBox("The file " + self.loadedfile + " could not be converted to a params file!", "File Cannot Be Processed", wx.OK|wx.ICON_EXCLAMATION) return logInfo("Params file created successfully") # Now read the LG.params file and grab out the atom names and their assigned types # so the user can see them and modify them if desired f = open("LG.fa.params", "r") if (self.grdParamsAtoms.NumberRows > 0): self.grdParamsAtoms.DeleteRows(0, self.grdParamsAtoms.NumberRows) self.atomnames = [] atomtypes = [] for aline in f: if (aline[0:4] == "ATOM"): atomname = aline.split()[1] atomtype = aline.split()[2] self.atomnames.append(atomname) atomtypes.append(atomtype) f.close() # Sort the atomnames to make it easier for the user to find things for i in range(0, len(self.atomnames)-1): lowest = i for j in range(i+1, len(self.atomnames)): if (self.atomnames[j] < self.atomnames[lowest]): lowest = j temp = self.atomnames[i] self.atomnames[i] = self.atomnames[lowest] self.atomnames[lowest] = temp temp = atomtypes[i] atomtypes[i] = atomtypes[lowest] atomtypes[lowest] = temp # Now add things to the grid for i in range(0, len(self.atomnames)): self.grdParamsAtoms.AppendRows(1) self.grdParamsAtoms.SetRowLabelValue(i, self.atomnames[i]) self.grdParamsAtoms.SetCellValue(i, 0, atomtypes[i]) self.grdParamsAtoms.SetCellAlignment(i, 0, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) readOnly = wx.grid.GridCellAttr() readOnly.SetReadOnly(True) self.grdParamsAtoms.SetRowAttr(i, readOnly) # Update some of the atom selection menus with the list of atomnames self.atomMenu.Clear() self.atomMenu.AppendItems(self.atomnames) self.NtermMenu.Clear() self.NtermMenu.AppendItems(self.atomnames) self.CtermMenu.Clear() self.CtermMenu.AppendItems(self.atomnames) self.btnAdd.Enable()
def createParams(self, event): # Change to the sandbox location goToSandbox() self.selectedType = self.resMenu.GetStringSelection().strip() # Before doing any of the following, we should first scan all of the params files in the Rosetta database # to see if a file already exists for this type # If we find a hit, we'll let the user decide based on some filename and directory information if that is the # params file they want, because we should be using Rosetta's files if they are available if (platform.system() == "Windows"): root = os.environ["PYROSETTA_DATABASE"] + "\\chemical\\residue_type_sets\\fa_standard\\residue_types" else: root = os.environ["PYROSETTA_DATABASE"] + "/chemical/residue_type_sets/fa_standard/residue_types" accepted = False for dpath, dnames, fnames in os.walk(root): for fname in fnames: if (platform.system() == "Windows"): fullpath = dpath + "\\" + fname else: fullpath = dpath + "/" + fname if (fname.endswith(".params")): matches = False f = open(fullpath, "r") for aline in f: if (aline[0:4] == "NAME" and aline.split()[1].strip() == self.selectedType): matches = True break if (matches): # Tell the user there is a hit, what the filename was, and what the directory is msg = "Found a parameters file that matches this unrecognized residue in Rosetta's database.\n\nFilename: " + fname.strip() + "\nDirectory: " + dpath.strip() + "\n\nDo you want to import this parameters file?" dlg = wx.MessageDialog(self, msg, "Params File Found", wx.YES_NO | wx.ICON_EXCLAMATION | wx.CENTRE) if (dlg.ShowModal() == wx.ID_YES): accepted = True dlg.Destroy() break dlg.Destroy() if (accepted): break if (accepted): # Copy over the file and we're done goToSandbox("params") f = open(fullpath, "r") f2 = open(self.selectedType + ".fa.params", "w") for aline in f: f2.write(aline.strip() + "\n") f.close() f2.close() wx.MessageBox("Your parameters file was imported successfully! InteractiveROSETTA will now recognize " + self.selectedType + " entries.", "Params Creation Successful", wx.OK|wx.ICON_EXCLAMATION) self.grdParamsAtoms.ClearGrid() self.atomMenu.Clear() self.typeMenu.Clear() self.btnAdd.Disable() self.btnCreate.Disable() self.unrecognized_types.pop(self.selectedType) self.resMenu.Clear() self.resMenu.AppendItems(self.unrecognized_types.keys()) self.removeMenu.Append(self.selectedType) return # First we have to create a temporary PDB file that contains only the ATOM/HETATM # records for the selected unrecognized residue type for aline in self.unrecognized_types[self.selectedType]: if (aline[0:4] == "ATOM" or aline[0:6] == "HETATM"): self.seqpos = int(aline[22:26]) self.chainID = aline[21].strip() break f = open("params.pdb", "w") for aline in self.unrecognized_types[self.selectedType]: f.write(aline + "\n") f.close() self.txtCode.SetValue(str(self.selectedType)) # Now use openbabel to convert this PDB file to a mol2 file obConversion = openbabel.OBConversion() obConversion.SetInAndOutFormats("pdb", "mol2") mol = openbabel.OBMol() obConversion.ReadFile(mol, "params.pdb") obConversion.WriteFile(mol, 'params.mol2') obConversion.CloseOutFile() # Now read the mol2 file as usual # Attempt to generate the params file try: if (os.path.isfile("LG.params")): os.remove("LG.params") if (os.path.isfile("LG.fa.params")): os.remove("LG.fa.params") if (os.path.isfile("LG.cen.params")): os.remove("LG.cen.params") #molfile_to_params.main(["params.mol2", "--no-pdb", "--keep-names"]) molfile_to_params.main(["params.mol2", "--no-pdb", "--keep-names", "-c"]) except: if (platform.system() == "Windows"): dlg = wx.MessageDialog(self, "OpenBabel was not able to convert this residue to a mol2 file!\n\nDid you install OpenBabel separately? If not, would you like to view the download page?", "Params File Found", wx.YES_NO | wx.ICON_EXCLAMATION | wx.CENTRE) if (dlg.ShowModal() == wx.ID_YES): webbrowser.open("http://sourceforge.net/projects/openbabel/files/openbabel/2.3.2/OpenBabel2.3.2a_Windows_Installer.exe/download") dlg.Destroy() else: wx.MessageBox("OpenBabel was not able to convert this residue to a mol2 file!", "File Cannot Be Processed", wx.OK|wx.ICON_EXCLAMATION) return logInfo("Params file created successfully") # Now read the LG.params file and grab out the atom names and their assigned types # so the user can see them and modify them if desired f = open("LG.fa.params", "r") if (self.grdParamsAtoms.NumberRows > 0): self.grdParamsAtoms.DeleteRows(0, self.grdParamsAtoms.NumberRows) self.atomnames = [] atomtypes = [] for aline in f: if (aline[0:4] == "ATOM"): atomname = aline.split()[1] atomtype = aline.split()[2] self.atomnames.append(atomname) atomtypes.append(atomtype) f.close() # Sort the atomnames to make it easier for the user to find things for i in range(0, len(self.atomnames)-1): lowest = i for j in range(i+1, len(self.atomnames)): if (self.atomnames[j] < self.atomnames[lowest]): lowest = j temp = self.atomnames[i] self.atomnames[i] = self.atomnames[lowest] self.atomnames[lowest] = temp temp = atomtypes[i] atomtypes[i] = atomtypes[lowest] atomtypes[lowest] = temp # Now add things to the grid for i in range(0, len(self.atomnames)): self.grdParamsAtoms.AppendRows(1) self.grdParamsAtoms.SetRowLabelValue(i, self.atomnames[i]) self.grdParamsAtoms.SetCellValue(i, 0, atomtypes[i]) self.grdParamsAtoms.SetCellAlignment(i, 0, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) readOnly = wx.grid.GridCellAttr() readOnly.SetReadOnly(True) self.grdParamsAtoms.SetRowAttr(i, readOnly) # Update some of the atom selection menus with the list of atomnames self.atomMenu.Clear() self.atomMenu.AppendItems(self.atomnames) self.NtermMenu.Clear() self.NtermMenu.AppendItems(self.atomnames) self.CtermMenu.Clear() self.CtermMenu.AppendItems(self.atomnames) self.btnAdd.Enable()
def molfile2params_quick(mdlfile, name): molfile_to_params.main([mdlfile, "-n" + name])
def createParams(self, event): # Change to the sandbox location goToSandbox() self.selectedType = self.resMenu.GetStringSelection().strip() # Before doing any of the following, we should first scan all of the params files in the Rosetta database # to see if a file already exists for this type # If we find a hit, we'll let the user decide based on some filename and directory information if that is the # params file they want, because we should be using Rosetta's files if they are available if (platform.system() == "Windows"): root = os.environ[ "PYROSETTA_DATABASE"] + "\\chemical\\residue_type_sets\\fa_standard\\residue_types" else: root = os.environ[ "PYROSETTA_DATABASE"] + "/chemical/residue_type_sets/fa_standard/residue_types" accepted = False for dpath, dnames, fnames in os.walk(root): for fname in fnames: if (platform.system() == "Windows"): fullpath = dpath + "\\" + fname else: fullpath = dpath + "/" + fname if (fname.endswith(".params")): matches = False f = open(fullpath, "r") for aline in f: if (aline[0:4] == "NAME" and aline.split()[1].strip() == self.selectedType): matches = True break if (matches): # Tell the user there is a hit, what the filename was, and what the directory is msg = "Found a parameters file that matches this unrecognized residue in Rosetta's database.\n\nFilename: " + fname.strip( ) + "\nDirectory: " + dpath.strip( ) + "\n\nDo you want to import this parameters file?" dlg = wx.MessageDialog( self, msg, "Params File Found", wx.YES_NO | wx.ICON_EXCLAMATION | wx.CENTRE) if (dlg.ShowModal() == wx.ID_YES): accepted = True dlg.Destroy() break dlg.Destroy() if (accepted): break if (accepted): # Copy over the file and we're done goToSandbox("params") f = open(fullpath, "r") f2 = open(self.selectedType + ".fa.params", "w") for aline in f: f2.write(aline.strip() + "\n") f.close() f2.close() wx.MessageBox( "Your parameters file was imported successfully! InteractiveROSETTA will now recognize " + self.selectedType + " entries.", "Params Creation Successful", wx.OK | wx.ICON_EXCLAMATION) self.grdParamsAtoms.ClearGrid() self.atomMenu.Clear() self.typeMenu.Clear() self.btnAdd.Disable() self.btnCreate.Disable() self.unrecognized_types.pop(self.selectedType) self.resMenu.Clear() self.resMenu.AppendItems(self.unrecognized_types.keys()) self.removeMenu.Append(self.selectedType) return # First we have to create a temporary PDB file that contains only the ATOM/HETATM # records for the selected unrecognized residue type for aline in self.unrecognized_types[self.selectedType]: if (aline[0:4] == "ATOM" or aline[0:6] == "HETATM"): self.seqpos = int(aline[22:26]) self.chainID = aline[21].strip() break f = open("params.pdb", "w") for aline in self.unrecognized_types[self.selectedType]: f.write(aline + "\n") f.close() self.txtCode.SetValue(str(self.selectedType)) # Now use openbabel to convert this PDB file to a mol2 file obConversion = openbabel.OBConversion() obConversion.SetInAndOutFormats("pdb", "mol2") mol = openbabel.OBMol() obConversion.ReadFile(mol, "params.pdb") obConversion.WriteFile(mol, 'params.mol2') obConversion.CloseOutFile() # Now read the mol2 file as usual # Attempt to generate the params file try: if (os.path.isfile("LG.params")): os.remove("LG.params") if (os.path.isfile("LG.fa.params")): os.remove("LG.fa.params") if (os.path.isfile("LG.cen.params")): os.remove("LG.cen.params") #molfile_to_params.main(["params.mol2", "--no-pdb", "--keep-names"]) molfile_to_params.main( ["params.mol2", "--no-pdb", "--keep-names", "-c"]) except: if (platform.system() == "Windows"): dlg = wx.MessageDialog( self, "OpenBabel was not able to convert this residue to a mol2 file!\n\nDid you install OpenBabel separately? If not, would you like to view the download page?", "Params File Found", wx.YES_NO | wx.ICON_EXCLAMATION | wx.CENTRE) if (dlg.ShowModal() == wx.ID_YES): webbrowser.open( "http://sourceforge.net/projects/openbabel/files/openbabel/2.3.2/OpenBabel2.3.2a_Windows_Installer.exe/download" ) dlg.Destroy() else: wx.MessageBox( "OpenBabel was not able to convert this residue to a mol2 file!", "File Cannot Be Processed", wx.OK | wx.ICON_EXCLAMATION) return logInfo("Params file created successfully") # Now read the LG.params file and grab out the atom names and their assigned types # so the user can see them and modify them if desired f = open("LG.fa.params", "r") if (self.grdParamsAtoms.NumberRows > 0): self.grdParamsAtoms.DeleteRows(0, self.grdParamsAtoms.NumberRows) self.atomnames = [] atomtypes = [] for aline in f: if (aline[0:4] == "ATOM"): atomname = aline.split()[1] atomtype = aline.split()[2] self.atomnames.append(atomname) atomtypes.append(atomtype) f.close() # Sort the atomnames to make it easier for the user to find things for i in range(0, len(self.atomnames) - 1): lowest = i for j in range(i + 1, len(self.atomnames)): if (self.atomnames[j] < self.atomnames[lowest]): lowest = j temp = self.atomnames[i] self.atomnames[i] = self.atomnames[lowest] self.atomnames[lowest] = temp temp = atomtypes[i] atomtypes[i] = atomtypes[lowest] atomtypes[lowest] = temp # Now add things to the grid for i in range(0, len(self.atomnames)): self.grdParamsAtoms.AppendRows(1) self.grdParamsAtoms.SetRowLabelValue(i, self.atomnames[i]) self.grdParamsAtoms.SetCellValue(i, 0, atomtypes[i]) self.grdParamsAtoms.SetCellAlignment(i, 0, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) readOnly = wx.grid.GridCellAttr() readOnly.SetReadOnly(True) self.grdParamsAtoms.SetRowAttr(i, readOnly) # Update some of the atom selection menus with the list of atomnames self.atomMenu.Clear() self.atomMenu.AppendItems(self.atomnames) self.NtermMenu.Clear() self.NtermMenu.AppendItems(self.atomnames) self.CtermMenu.Clear() self.CtermMenu.AppendItems(self.atomnames) self.btnAdd.Enable()