Coverage for PyRx.traitedBabel : 58%
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: traitedBabel.py 259 2015-11-15 22:58:59Z sarkiss $ RuleFilterTemplate, RuleTableFilter, MenuTableFilter
else: self.title = molecule.formula
parent.Open() return None
columns=[ ObjectColumn(name='id', editable=False), ObjectColumn(name='title', editable=False), ObjectColumn(name='formula', editable=False), ObjectColumn(name='weight', editable=False) , #ObjectColumn( name = 'energy' ) , ObjectColumn(name='number_of_atoms', editable=False), ], reorderable = False, sort_model = True, auto_size = False, on_select = parent.OnSelect, editable = True, show_toolbar = True, row_factory = my_row_factory, filters = [FilterTemplate] , deletable = True, ) Group( Item('molecules', show_label=False, editor=table_editor ) ) )
shortHelp="Load Structures Data File (SDF) or other OpenBabel supported file", longHelp="Load Structures Data File (SDF) or other OpenBabel supported file")
#self.editor.toolbar.control.Realize()
row, col = evt.GetRow(), evt.GetCol() # A row value of -1 means this click happened on a column. # vice versa, a col value of -1 means a row click. if row == -1: self.grid._editors[0].grid._column_sort( col )
"""Internal update to the selection tracking list""" # adding to the list... self.wxGrid.currentSelection.append(index) else: # removal from list for index in range(event.GetTopRow(), event.GetBottomRow() + 1): while index in self.wxGrid.currentSelection: self.wxGrid.currentSelection.remove(index)
"""Internal update to the selection tracking list"""
last_OpenBabelFolder = self.frame.wxcfg.Read("last_OpenBabelFolder") dlg = wx.FileDialog(self, "Choose OpenBabel Supported File", last_OpenBabelFolder, "", wildcard, wx.OPEN) if dlg.ShowModal() == wx.ID_OK: filePath = dlg.GetPath() self.frame.SetAllCursors(wx.StockCursor(wx.CURSOR_WAIT)) self.frame.Update() try: self.Read(filePath) except: self.frame.log.error("Error reading " + filePath) self.frame.SetAllCursors(wx.NullCursor) self.frame.wxcfg.Write("last_OpenBabelFolder", os.path.split(filePath)[0]) dlg.Destroy()
self.frame.mayaviEngine.handle_pick(data) self.scene.picker.show_gui = False
self.editor.toolbar.control.EnableTool(ID_MIN, False) self.editor.toolbar.control.EnableTool(ID_SAVE, False)
#self.frame.view.SetSelection(self.frame.view.GetPageIndex(self.scene.control))
"""Converts OBMol molecule to MolKit molecule""" else: residue = Residue(type="UNK", number=1) for atom in openbabel.OBMolAtomIter(molecule.OBMol): name = self.etab.GetSymbol(atom.GetAtomicNum()) a = Atom(name, residue, name, top=mol) a._coords = [[atom.x(), atom.y(), atom.z()]] a._charges = {} a.hetatm = 1 a.number = atom.GetIdx() mol.atmNum[a.number - 1] = a chain.adopt(residue, setChildrenTop=1) #-1 since openbable qatom index starts with 1
"""Converts MolKit molecule to OBMol molecule""" molecule = openbabel.OBMol() for atom in mol.allAtoms: a = molecule.NewAtom() a.SetAtomicNum(atom.atomicNumber) a.SetVector(atom._coords[conformation][0], atom._coords[conformation][1], atom._coords[conformation][2]) molecule.ConnectTheDots() molecule.PerceiveBondOrders() for atom in openbabel.OBMolAtomIter(molecule):#get rid of radicals atom.SetSpinMultiplicity(0) return molecule
"""Converts MolKit molecule to OBMol molecule using coords provided""" molecule = openbabel.OBMol() for index, atom in enumerate(mol.allAtoms): a = molecule.NewAtom() a.SetAtomicNum(atom.atomicNumber) a.SetVector(coords[index][0], coords[index][1], coords[index][2]) molecule.ConnectTheDots() molecule.PerceiveBondOrders() for atom in openbabel.OBMolAtomIter(molecule):#get rid of radicals atom.SetSpinMultiplicity(0) return molecule
if len(self.wxGrid.currentSelection) > 1: # menu = wx.Menu() # sMenu = menu.Append(wx.ID_ANY, "Superimpose") # self.Bind(wx.EVT_MENU, self.OnSuperimpose, sMenu) # self.PopupMenu(menu) return
#self.editor.set_selection(self.moleculesList.molecules[event.Row]) #not sure why this code is here if not self.editor.selected_row: return #self.editor.set_selection(self.editor.selected_row) menu = wx.Menu() moveMenu = menu.Append(wx.ID_ANY, "Move to 3D Scene") self.Bind(wx.EVT_MENU, self.OnMove, moveMenu) displayDataMenu = menu.Append(wx.ID_ANY, "Show Associated Data") self.Bind(wx.EVT_MENU, self.OnDisplayData, displayDataMenu) saveAsMenu = menu.Append(wx.ID_ANY, "Save As...") self.Bind(wx.EVT_MENU, self.OnSaveAs, saveAsMenu)
menu.AppendSeparator() minSelectedMenu = menu.Append(wx.ID_ANY, "Minimize Selected") self.Bind(wx.EVT_MENU, self.OnMinimize, minSelectedMenu) minAllMenu = menu.Append(wx.ID_ANY, "Minimize All") self.Bind(wx.EVT_MENU, self.OnMinAll, minAllMenu)
menu.AppendSeparator() converSelectedMenu = menu.Append(wx.ID_ANY, "Convert Selected to AutoDock Ligand (pdbqt)") self.Bind(wx.EVT_MENU, self.OnConverSelected, converSelectedMenu) converAllMenu = menu.Append(wx.ID_ANY, "Convert All to AutoDock Ligand (pdbqt)") self.Bind(wx.EVT_MENU, self.OnConvertAll, converAllMenu) menu.AppendSeparator() removeAllMenu = menu.Append(wx.ID_ANY, "Delete All") self.Bind(wx.EVT_MENU, self.OnRemoveAll, removeAllMenu) self.PopupMenu(menu)
self.moleculesList.molecules = [] self.scene.renderer._vtk_obj.RemoveActor(self.assembly) self.scene.renderer._vtk_obj.RemoveActor2D(self.textActor) self.textActor = None self.scene.control.Refresh()
import wx.lib.sized_controls as sc molecule = self.editor.selected_row class FormDialog(wx.ScrolledWindow, sc.SizedDialog): def __init__(self): sc.SizedDialog.__init__(self, None, -1, molecule.title, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) pane = self.GetContentsPane() pane.SetSizerType("form") dataList = molecule.OBMol.GetData() for data in dataList: wx.StaticText(pane, -1, data.GetAttribute()) textCtrl = wx.TextCtrl(pane, -1, data.GetValue(), style=wx.TE_READONLY) textCtrl.SetSizerProps(expand=True) self.SetButtonSizer(self.CreateStdDialogButtonSizer(wx.OK)) self.Fit() self.SetMinSize([self.GetSize()[0] + 300, self.GetSize()[1] ]) dlg = FormDialog() dlg.CenterOnScreen() val = dlg.ShowModal() dlg.Destroy()
self.frame.molNav.ext = '' self.frame.molNav.AddMolecule(self.mol) self.frame.view.SetSelection(0)# 3D Viewer self.frame.navigator.SetSelection(0)# Molecules
molecule = self.editor.selected_row self.StripConvert(molecule) self.frame.navigator.SetSelection(1) #AutoDock
"AutoDock Ligand Conversion in Progress. Please Wait...", maximum=maximum, parent=self, style=wx.PD_CAN_ABORT | wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME #| wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME )
break use_ = True else: except Exception, inst: self.frame.log.error(str(inst) + " : " + __file__)
if not openbabelParameters.configure_traits(kind='livemodal'): #shows energy minimization parameters return force_field = openbabelParameters.force_field ff = openbabel.OBForceField.FindForceField(openbabelParameters.force_field) ff.SetLogLevel(openbabel.OBFF_LOGLVL_NONE) ff.SetLogToStdErr() molecule = self.editor.selected_row mol = molecule.OBMol if ff.Setup(mol) == 0: self.frame.log.error("Could not setup forcefield for " + molecule.title) return step = 0 self.frame.Refresh() startEnergy = ff.Energy() self.textActor.SetInput(molecule.title + "\n E = " + str(startEnergy))
while step < openbabelParameters.stepsTotal: if openbabelParameters.optAlgo == 'Steepest Descent': ff.SteepestDescent(openbabelParameters.stepsInter) else: ff.ConjugateGradients(openbabelParameters.stepsInter) step += openbabelParameters.stepsInter ff.GetCoordinates(mol) i = 0 for atom in openbabel.OBMolAtomIter(mol): self.assembly.points.SetPoint(i, [atom.x(), atom.y(), atom.z()]) i += 1 if hasattr(self.assembly, 'glyph'): self.assembly.glyph.Modified() if hasattr(self.assembly, 'tuber'): self.assembly.tuber.Modified() energy = ff.Energy() try: self.scene.render() except: pass #to avoid a possible RuntimeError
self.textActor.SetInput(molecule.title + "\n Steps =" + str(step) + " E = " + str(energy)) if abs(startEnergy - energy) < openbabelParameters.tolerance: break startEnergy = energy molecule.title += "_" + openbabelParameters.force_field + "_E=" + "%.2f" % energy self.scene.renderer.reset_camera()
"Minimizing All Molecules. Please Wait...", maximum=maximum, parent=self, style=wx.PD_CAN_ABORT | wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME #| wx.PD_REMAINING_TIME )
break
ff.SteepestDescent(openbabelParameters.stepsInter) else:
dlg = wx.FileDialog(self, "Save File As", os.getcwd(), "", outFileType, wx.SAVE) if dlg.ShowModal() == wx.ID_OK: filePath = dlg.GetPath() ext = os.path.splitext(filePath)[1] if not ext: ext = '.sdf' filePath = filePath + ext if os.path.exists(filePath): dlg1 = wx.MessageDialog(self, filePath + " already exists. Overwrite File?", 'Overwrite File?', wx.YES_NO | wx.ICON_INFORMATION ) if dlg1.ShowModal() != wx.ID_YES: dlg1.Destroy() dlg.Destroy() return import copy molecule = self.editor.selected_row mol = openbabel.OBMol(molecule.OBMol) #otherwise .write changes OBMol try: pybelmol = pybel.Molecule(mol) pybelmol.write(str(ext[1:]), str(filePath), overwrite=True) except Exception, inst: self.frame.log.error(str(inst) + " : " + __file__) dlg.Destroy()
# a.babel_type = atom.GetType() # a.babel_atomic_number = atom.GetAtomicNum() #a.charge = atom.GetPartialCharge() for index, atom in enumerate(openbabel.OBMolAtomIter(molecule.OBMol)): mol.allAtoms[index].chargeSet = "OBgasteiger" mol.allAtoms[index]._charges["OBgasteiger"] = atom.GetPartialCharge() mol.name = mol.name + "_obQ" self.frame.autodockNav.AddLigand(mol, charges_to_add=None, use_=use_) else:
""" 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 ###################################################### label="Optimization Algorithm", show_border=True) label="Force Field", show_border=True)
Item('stepsTotal', label="Total number of steps") , Item('stepsInter', label="Number of steps for update") , Item('tolerance', label="Stop if energy difference is less than"), label="Energy Minimization Parameters" )
""" 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 ######################################################
label="Removes Fragments Smaller Than") , Item('partialCharges', label="Partial Charges"), label="Parameters for Converting to PDBQT"), Group(Item('numberOfPoses', style="custom", label="Number of Poses to Retain", tooltip="Set this number to zero to retain all the poses.") , label="When Exporting SDF in Analyze Results")) )
#this is needed to avoid "...instance must be 'UFF' or 'MMFF94' or 'Ghemical', but a value of 'uff'..." Traceback except: from preferences import rcFile import pybel txt = open(rcFile).read() txt = txt.replace("uff", pybel.forcefields[0]) txt = txt.replace("mmff94", pybel.forcefields[1]) txt = txt.replace("UFF", pybel.forcefields[0]) txt = txt.replace("MMFF94", pybel.forcefields[1]) open(rcFile, 'w').write(txt) from enthought.preferences.api import set_default_preferences from enthought.preferences.api import Preferences set_default_preferences(Preferences(filename=rcFile)) openbabelParameters = OpenBabelParameters()
|