Package Pmv :: Module coarseMolSurfaceCommands
[hide private]
[frames] | no frames]

Source Code for Module Pmv.coarseMolSurfaceCommands

  1  from mglutil.gui.InputForm.Tk.gui import InputFormDescr, InputForm, \ 
  2  CallBackFunction 
  3  from mglutil.gui.BasicWidgets.Tk.thumbwheel import ThumbWheel 
  4  from mglutil.gui.BasicWidgets.Tk.customizedWidgets import LoadButton, \ 
  5  SaveButton, SliderWidget, ExtendedSliderWidget 
  6  from mglutil.util.callback import CallBackFunction 
  7  import Pmw, Tkinter 
  8  import types 
  9  from Pmv.mvCommand import MVCommand 
 10  from ViewerFramework.VFCommand import CommandGUI 
 11  from MolKit.molecule import Atom, Molecule 
 12  from Pmv.computeIsovalue import computeIsovalue 
 13   
14 -class coarseMolSurface(MVCommand):
15 """Command to compute a coarse molecular surface. 16 Selected atoms are first blurred as gaussians into a grid. 17 The grid is then isocontoured at a user specified value. 18 An indexed polygon geometry is added to the viewer. """ 19 20
21 - def __init__(self, func=None):
22 MVCommand.__init__(self) 23 self.cms_network = None 24 self.ifd = None 25 self.resolutions={"very smooth":-0.1, "medium smooth": -0.3, "smooth": -0.5} 26 self.resolution_type = "medium smooth" 27 self.surf_resolution = self.resolutions[self.resolution_type] 28 self.isovalue=1 29 self.isovalue_type = "fast approximation" 30 self.precise_isovalues = {} 31 self.custom_isovalue_flag = 0 32 self.custom_resolution_flag = 0 33 self.surfName = None 34 self.surfNameList = [] 35 self.mol_surfNames = {} 36 self.molName = None 37 self.selection = None 38 self.atomSet = None 39 self.bindFlag = Tkinter.BooleanVar() 40 self.bindFlag.set(False) 41 self.bindGeom = False 42 self.perMol = True 43 self.immediate = False 44 self.network_nodes = {"gridSize":[2, 'Dial'], 45 "resolution":[3,'UT Blur'], 46 "isovalue": [4, 'UT-Isocontour'], 47 "surfName": [5, self.surfName]} 48 self.gridSize = (32, 32, 32) 49 self.buildFormFlag = False 50 self.newSelection =False 51 self.padding = 0.0
52 53 54
55 - def onAddCmdToViewer(self):
56 if self.vf.vision.ed is None: 57 self.vf.vision(log=False) 58 self.vf.browseCommands('displayCommands', commands=('DisplayBoundGeom',), log=0, package='Pmv')
59
60 - def loadNetwork(self):
61 self.cms_network = self.vf.vision.ed.getNetworkByName("CoarseMolSurface") 62 if self.cms_network: 63 self.cms_network = self.cms_network[0] 64 else: 65 from mglutil.util.packageFilePath import findFilePath 66 network_path = findFilePath("CoarseMolSurface_net.py", "Pmv.VisionInterface") 67 self.vf.vision.ed.loadNetwork(network_path) 68 self.cms_network = self.vf.vision.ed.getNetworkByName("CoarseMolSurface")[0] 69 res = self.resolutions[self.resolution_type] 70 self.cms_network.getNodeByName('UT Blur')[0].inputPorts[5].widget.set(res, run=0) 71 isoval = self.isovalue = self.piecewiseLinearInterpOnIsovalue(res) 72 self.cms_network.getNodeByName('UT-Isocontour')[0].inputPorts[1].widget.set(isoval,run=0 ) 73 self.cms_network.getNodeByName('UT-Isocontour')[0].inputPorts[2].widget.set(0, run = 0) 74 self.cms_network.nodes[4].inputPortByName['name'].widget.set("coarseMolSurface", run = 0) 75 self.cms_network.getNodeByName("Dial")[0].run() 76 self.cms_network.freeze()
77 78 ## def checkDependencies(self): 79 ## """check availability of mdules the command depends on""" 80 ## from UTpackages.UTisocontour import isocontour 81 ## from UTpackages.UTblur import blur 82 ## from mslib import MSMS 83 ## from QSlimLib import qslimlib 84
85 - def onAddObjectToViewer(self, obj):
86 pass
87
88 - def guiCallback(self):
89 selection = self.vf.getSelection() 90 if not selection: 91 return 92 if not self.cms_network: 93 self.loadNetwork() 94 self.buildFormFlag = 1 95 self.cms_network.unfreeze() 96 val = self.showForm( modal = 0, blocking=0, force = 1) 97 if not self.custom_isovalue_flag: 98 self.disableThumbWheel(self.ifd.entryByName['customIsovalue']['widget']) 99 if not self.custom_resolution_flag: 100 self.disableThumbWheel(self.ifd.entryByName['customResolution']['widget']) 101 if self.ifd: 102 bindmol = self.ifd.entryByName['bindToMolecule'] 103 if len(selection.top.uniq()) > 1: 104 # selected more than one molecule -> 105 # disable "Bind to molecule" chekbutton 106 107 bindmol['widget'].configure(state='disabled') 108 bindmol['wcfg']['state']='disabled' 109 else: 110 if bindmol['wcfg']['state']=='disabled': 111 bindmol['widget'].configure(state='normal') 112 bindmol['wcfg']['state']='normal' 113 self.buildFormFlag = 0
114 115
116 - def buildFormDescr(self, formName="default"):
117 118 if formName == 'default': 119 ifd = self.ifd = InputFormDescr(title ="Compute Coarse Molecular Surface") 120 #defaultValues = self.getLastUsedValues() 121 #print "default values:", defaultValues 122 if self.surfName: 123 surfName = self.surfName 124 else: 125 surfName = "CoarseMolSurface" 126 self.immediate = False 127 ifd.append({'widgetType':Tkinter.Checkbutton, 128 'tooltip':"""enables immediate update of the selected\n input parameter""", 129 'name': 'mode', 130 'defaultValue': self.immediate, 131 'wcfg':{'text':'Immediate', 132 'command':self.mode_cb, 133 'variable':Tkinter.BooleanVar()}, 134 'gridcfg':{'sticky':'w','columnspan':2 } 135 }) 136 137 ifd.append({'widgetType':Pmw.ComboBox, 138 'name':'surfName', 139 'required':1, 140 'tooltip': "Type-in a new name or chose one \nfrom the list below,\n '_' are not accepted.", 141 'wcfg':{'labelpos':'n', 142 'label_text':'Select/type surface name: ', 143 'entryfield_validate':self.entryValidate, 144 'entryfield_value':surfName, 145 'scrolledlist_items':self.surfNameList, 146 'fliparrow':1, 147 'selectioncommand': self.select_surfname 148 }, 149 'gridcfg':{'sticky':'we', 'columnspan':2}, 150 151 }) 152 153 ifd.append({'name':'perMol', 154 'tooltip':"""When checked, surfaces will be computed using all atoms\n of each selected molecule.\nIf unchecked, the unselected atoms are ignored during the 155 calculation.""", 156 'widgetType':Tkinter.Checkbutton, 157 'defaultValue': self.perMol, 158 'wcfg':{'text':'Per Molecule', 159 'variable':Tkinter.BooleanVar(), 160 'command':self.perMol_cb}, 161 'gridcfg':{'sticky':'w','columnspan':2} 162 }) 163 164 ifd.append({'widgetType':Pmw.EntryField, 165 'name':'gridsize', 166 'tooltip':'Type-in the grid size', 167 'wcfg':{'labelpos':'w', 168 'label_text':'Grid size: ', 169 'entry_width':8, 170 'value': self.gridSize[0], 171 'validate':{'validator': 'numeric',}, 172 'command':self.set_gridsize}, 173 'gridcfg':{'column':0, 'columnspan':2, 'sticky':'w'} 174 }) 175 ifd.append({ 176 'widgetType':ThumbWheel, 177 'name':'padding', 178 'tooltip': 179 """size of the padding around the molecule """, 180 'gridcfg':{'sticky':'w','column':0, 'columnspan':2}, 181 'wcfg':{'value':self.padding, 182 'oneTurn':10, 'min':0.0, 'lockMin':True, 183 'type':'float', 'precision':1, 184 'continuous':False, 185 'wheelPad':1,'width':90,'height':15, 186 'callback': self.set_padding, 187 'labCfg':{'text':'padding:'}, 188 } 189 }) 190 ifd.append({'name':'resolutionGroup', 191 'widgetType':Pmw.Group, 192 'container':{'resolutionGroup':"w.interior()"}, 193 194 'wcfg':{'tag_text':"Surface resolution:", 'ring_borderwidth':3,}, 195 'gridcfg':{'sticky':'we', 'columnspan':2}}) 196 197 ifd.append({'name':'resolution_type', 198 'widgetType':Pmw.RadioSelect, 199 'parent':'resolutionGroup', 200 'tooltip': 201 """ very smooth, medium smooth and smooth correspond to the blobbyness\n value (used in the gaussian blurring) of -0.1, -0.3, and -0.5 respectively""", 202 'listtext':['very smooth', 'medium smooth', 'smooth', 'custom'], 203 'defaultValue':self.resolution_type, 204 'wcfg':{'orient':'vertical','labelpos':'n', 205 'labelpos':None, 206 #'label_text':'Surface resolution: ', 207 'command':self.set_resolution, 208 #'hull_relief':'ridge', 209 #'hull_borderwidth':2, 210 'padx':0, 211 'buttontype':'radiobutton'}, 212 'gridcfg':{'sticky': 'nw','column':0, 'columnspan':2} 213 }) 214 215 ifd.append({'name':'customResolution', 216 'parent':'resolutionGroup', 217 'widgetType':ThumbWheel, 218 'tooltip': 219 """Set custom resolution value""", 220 'gridcfg':{'sticky':'w','column':0, 'columnspan':2}, 221 'wcfg':{'value':self.surf_resolution,'oneTurn':2, 222 'type':'float', 223 'increment':0.1, 224 'precision':1, 225 'continuous':False, 226 "max":-0.009, 227 'wheelPad':2,'width':145,'height':18, 228 'showLabel':self.custom_resolution_flag, 'lockShowLabel':1, 229 'callback': self.set_custom_resolution 230 #'labCfg':{'text':'Surface Resolution:'}, 231 } 232 }) 233 234 235 ifd.append({'name':'isovalueGroup', 236 'widgetType':Pmw.Group, 237 'container':{'isovalueGroup':"w.interior()"}, 238 'wcfg':{'tag_text':"Isocontour values:",'ring_borderwidth':3}, 239 'gridcfg':{'sticky':'we', 'columnspan':2}}) 240 ifd.append({'name':'isovalue_type', 241 'widgetType':Pmw.RadioSelect, 242 'parent': 'isovalueGroup', 243 'tooltip': "select isovalue option", 244 'listtext':['fast approximation', 245 'precise value', 'custom'], 246 'defaultValue':self.isovalue_type, 247 'wcfg':{'orient':'vertical','labelpos':'n', 248 #'label_text':'Isocontour values:', 249 'labelpos':None, 250 'command':self.set_isovalue, 251 #'hull_relief':'ridge', 252 #'hull_borderwidth':2, 253 'padx':0, 254 'buttontype':'radiobutton'}, 255 'gridcfg':{'sticky': 'nw','column':0, 'columnspan':2} 256 }) 257 ifd.append({'name':'customIsovalue', 258 'widgetType':ThumbWheel, 259 'parent': 'isovalueGroup', 260 'tooltip': 261 """Set custom isovalue""", 262 'gridcfg':{'sticky':'w','column':0, 'columnspan':2}, 263 'wcfg':{'value':self.isovalue,'oneTurn':2, 264 'type':'float', 265 'increment':0.1, 266 'precision':1, 267 'continuous':False, 268 'wheelPad':2,'width':145,'height':18, 269 'showLabel':self.custom_isovalue_flag, 'lockShowLabel':1, 270 'callback': self.set_custom_isovalue, 271 } 272 }) 273 274 275 ifd.append({'widgetType':Tkinter.Checkbutton, 276 'tooltip':"""Select/deselect this button to bind/unbind\nsurface to molecule""", 277 'name': 'bindToMolecule', 278 'wcfg':{'text':'Bind Surface to molecule', 279 'command':self.bind_cb, 280 'variable':self.bindFlag, 281 'state':'normal'}, 282 'gridcfg':{'sticky':'w', 'pady': 10,'columnspan':2 } 283 }) 284 ifd.append({'name':'compute', 285 'widgetType':Tkinter.Button, 286 'wcfg':{'text':'Compute', 287 'state': 'normal', 288 'command':self.compute}, 289 'gridcfg':{'sticky':'wne','column':0} 290 }) 291 292 ifd.append({'name':'dismiss', 293 'widgetType':Tkinter.Button, 294 'wcfg':{'text':'Dismiss', 295 'command':self.dismiss}, 296 'gridcfg':{'sticky':'wne','row': -1, 'column':1} 297 }) 298 299 return ifd
300 301 302
303 - def doit(self, **kw):
304 """list of keywords: nodes, surfName, perMol, gridZise, isovalue, 305 resolution, bindGeom, immediate, padding. 306 """ 307 #print "in doit kw:", kw 308 if self.cms_network.isFrozen(): 309 self.cms_network.unfreeze() 310 perMol = kw.get("perMol", None) 311 nodes_to_run = [] 312 if perMol == None: 313 perMol = self.perMol 314 nodes = kw.get("nodes", None) 315 immediate = kw.get("immediate", None) 316 if immediate is None: 317 immediate = self.immediate 318 if nodes: 319 if perMol: 320 atomSet = nodes.top.uniq() 321 else: 322 atomSet = nodes 323 if atomSet != self.atomSet: 324 self.atomSet = atomSet 325 self.newSelection = True 326 molecules = nodes.top.uniq() 327 for mol in molecules: 328 mol.defaultRadii() 329 selection_node = self.cms_network.getNodeByName("Get Selection")[0] 330 if selection_node.frozen: 331 selection_node.toggleFrozen_cb() #unfreeze 332 selection_node.outputPorts[0].data = atomSet 333 selection_node.toggleFrozen_cb() #freeze 334 if immediate: 335 self.cms_network.getNodeByName("UT Blur")[0].schedule_cb() 336 surfName = kw.get("surfName") 337 if surfName: 338 if surfName not in self.surfNameList: 339 self.surfNameList.append(surfName) 340 if surfName != self.surfName: 341 self.surfName = surfName 342 # the Indexed Polygons node's name changes when it is set to 343 # a new geometry name. 344 self.network_nodes["surfName"][1] = surfName 345 nodes_to_run.append("surfName") 346 # Indexed Polygons node: 347 self.cms_network.nodes[4].inputPortByName['name'].widget.set(surfName, run = 0) 348 if immediate: 349 #run the network 350 #self.cms_network.run() 351 self.cms_network.getNodeByName("UT Blur")[0].schedule_cb() 352 353 gs = kw.get("gridSize", None) 354 if gs: 355 gridSize = (gs, gs, gs) 356 if gridSize != self.gridSize: 357 self.gridSize = gridSize 358 nodes_to_run.append("gridSize") 359 if immediate: 360 if self.newSelection: 361 #set the node value and run the network 362 self.cms_network.getNodeByName('Dial')[0].inputPorts[0].widget.set(gs, run=0) 363 #self.cms_network.run() 364 self.cms_network.getNodeByName("UT Blur")[0].schedule_cb() 365 else: # run the node 366 self.cms_network.getNodeByName('Dial')[0].inputPorts[0].widget.set(gs, run=1) 367 else: # set the node value 368 self.cms_network.getNodeByName('Dial')[0].inputPorts[0].widget.set(gs, run=0) 369 370 pd = kw.get("padding", None) 371 if pd is not None: 372 if pd != self.padding: 373 self.padding = pd 374 nodes_to_run.append("resolution") 375 if immediate: 376 #if self.newSelection: 377 #set the node value and run the network 378 #self.cms_network.getNodeByName("UT Blur")[0].inputPorts[4].widget.set(pd, run=0) 379 #self.cms_network.run() 380 381 #else: # run the node 382 self.cms_network.getNodeByName("UT Blur")[0].inputPorts[4].widget.set(pd, run=1) 383 else: # set the node value 384 self.cms_network.getNodeByName("UT Blur")[0].inputPorts[4].widget.set(pd, run=0) 385 resolution = kw.get("resolution", None) 386 isotype = kw.get("isovalue", None) 387 if resolution: 388 if resolution != self.surf_resolution: 389 self.surf_resolution = resolution 390 nodes_to_run.append("resolution") 391 if not isotype: 392 #check if we need to recompute isovalue: 393 if self.isovalue_type != "custom": 394 if self.isovalue_type == 'fast approximation': 395 isovalue = self.piecewiseLinearInterpOnIsovalue(resolution) 396 else: 397 isovalue = self.get_precise_isovalue(resolution) 398 399 if isovalue is not None: 400 self.isovalue = isovalue 401 self.cms_network.getNodeByName('UT-Isocontour')[0].inputPorts[1].widget.set(isovalue, run = 0) 402 else: 403 print "Setting isocontour value to custom" 404 self.set_isovalue("custom") 405 self.isovalue_type = "custom" 406 407 if immediate: 408 #if self.newSelection : 409 # set the node value and run the network 410 # self.cms_network.getNodeByName('UT Blur')[0].inputPorts[5].widget.\ 411 # set(resolution, run = 0) 412 # self.cms_network.run() 413 #else: 414 # run the node 415 self.cms_network.getNodeByName('UT Blur')[0].inputPorts[5].widget.\ 416 set(resolution, run = 1) 417 else: # not immediate 418 # set the node value 419 self.cms_network.getNodeByName('UT Blur')[0].inputPorts[5].widget.\ 420 set(resolution, run = 0) 421 if isotype: 422 if type(isotype) == types.StringType: 423 self.isovalue_type = isotype 424 if isotype == 'fast approximation': 425 isovalue = self.piecewiseLinearInterpOnIsovalue(self.surf_resolution) 426 else: 427 #check if we need to recompute precise isovalue: 428 isovalue = self.get_precise_isovalue(self.surf_resolution) 429 else: 430 self.isovalue_type = "custom" 431 isovalue = isotype 432 if isovalue is not None: 433 if isovalue != self.isovalue: 434 nodes_to_run.append("isovalue") 435 self.isovalue = isovalue 436 self.cms_network.getNodeByName('UT-Isocontour')[0].inputPorts[1].widget.set(isovalue, run = immediate) 437 if immediate and self.newSelection: 438 #self.cms_network.run() 439 self.cms_network.getNodeByName("UT Blur")[0].schedule_cb() 440 441 else: 442 print "Setting isocontour value to custom" 443 self.set_isovalue("custom") 444 self.isovalue_type = "custom" 445 446 if not immediate: 447 #run the network 448 if "gridSize" in nodes_to_run: 449 self.cms_network.getNodeByName('Dial')[0].schedule_cb() 450 else: 451 self.cms_network.getNodeByName("UT Blur")[0].schedule_cb() 452 # find out if we need to bind/unbind the geometry to the molecule 453 bindGeom = kw.get("bindGeom", None) 454 if bindGeom == None: 455 bindGeom = self.bindGeom 456 bindcmd = self.vf.bindGeomToMolecularFragment 457 surf = self.vf.GUI.VIEWER.GUI.objectByName(self.surfName) 458 if bindGeom : 459 #if self.newSelection or len(nodes_to_run): 460 if len(self.atomSet.top.uniq()) > 1: 461 msg = "More than one molecule selected -can not bind the geometry" 462 self.vf.warningMsg(msg) 463 else: 464 bindcmd(surf, self.atomSet) 465 else: 466 if hasattr(surf, "mol"): 467 mol = surf.mol 468 if mol.geomContainer.geoms.has_key(self.surfName): 469 if surf.parent != mol.geomContainer.masterGeom: 470 oldname = mol.geomContainer.masterGeom.fullName+ '|' + self.surfName 471 else: 472 oldname = surf.fullName 473 #reparent the surface to root: 474 self.vf.GUI.VIEWER.ReparentObject(surf, self.vf.GUI.VIEWER.rootObject) 475 surf.fullName = surf.parent.fullName+'|'+self.surfName 476 # unbind 477 if bindcmd.data.has_key(oldname): 478 bindcmd.data[oldname].clear() 479 bindcmd.data.pop(oldname) 480 del(surf.mol) 481 if perMol: 482 if not nodes: 483 nodes = self.vf.getSelection() 484 boundgeom = False 485 for mol in self.atomSet.top.uniq(): 486 if surf.parent == mol.geomContainer.masterGeom: 487 boundgeom = True 488 break 489 if boundgeom: 490 try: 491 self.vf.DisplayBoundGeom(nodes, negate=False, geomNames=[surf.fullName,], only=True, log=1, nbVert=1) 492 except: 493 pass 494 self.newSelection = False
495
496 - def __call__(self, **kw):
497 """None <- mv.coarseMolSurface(**kw)\n 498 list of available keywords: 499 nodes -- atomic fragment; \n 500 surfName -- string - name of created surface; \n 501 perMol -- True or False; if True, a surface is computed for each 502 molecule having at least one node in the current selection, 503 else the surface is computed for the current selection;\n 504 gridZise -- integer; Size of computed grid will be: gridSize x gridSize x gridSize;\n 505 isovalue -- can be one of the following: 'fast approximation', 'precise value' or 506 a numeric value specifying the isovalue;\n 507 resolution -- resolution of the blurred surface - a negative value; \n 508 bindGeom -- True or False; if True - the surface is bound to the selected molecule. 509 """ 510 if not self.cms_network: 511 self.loadNetwork() 512 nodes = kw.get("nodes") 513 if nodes: 514 kw["nodes"] = self.vf.expandNodes(nodes) 515 apply(self.doitWrapper, (), kw)
516 517 # Callbacks 518 519
520 - def perMol_cb(self, event=None):
521 """calback of perMol check button of the input form""" 522 ebn = self.ifd.entryByName 523 perMol = self.perMol = ebn['perMol']['wcfg']['variable'].get() 524 self.perMol = perMol 525 ebn = self.ifd.entryByName 526 immediate = ebn['mode']['wcfg']['variable'].get() 527 if immediate: 528 self.doitWrapper(nodes = self.vf.getSelection(), perMol = perMol,immediate=True)
529 530
531 - def mode_cb (self, event=None):
532 """callback of the input form's immediate mode check button""" 533 ebn = self.ifd.entryByName 534 immediate = ebn['mode']['wcfg']['variable'].get() 535 computeButton = ebn['compute']['widget'] 536 if immediate: 537 computeButton.configure(state='disabled') 538 ebn['compute']['wcfg']['state']='disabled' 539 else: 540 computeButton.configure(state='normal') 541 ebn['compute']['wcfg']['state']='normal' 542 self.immediate = immediate
543
544 - def select_surfname(self, surfName):
545 """callback of surface name ComboBox """ 546 if surfName: 547 if surfName in self.surfNameList: 548 surf = self.vf.GUI.VIEWER.GUI.objectByName(surfName) 549 if surf: 550 for mol in self.atomSet.top.uniq(): 551 if surf.parent == mol.geomContainer.masterGeom: 552 # the surfName geometry is bound to mol - make sure to check the 553 # 'bindToMolecule' checkbutton 554 self.bindFlag.set(True) 555 break 556 immediate = self.ifd.entryByName['mode']['wcfg']['variable'].get() 557 if immediate: 558 selection = self.vf.getSelection() 559 self.doitWrapper(nodes=selection, surfName = surfName, immediate = immediate, bindGeom = self.bindFlag.get())
560
561 - def set_gridsize(self):
562 """callback of the 'grid size' entry field""" 563 val = self.ifd.entryByName['gridsize']['widget'].get() 564 if val: 565 immediate = self.ifd.entryByName['mode']['wcfg']['variable'].get() 566 if immediate: 567 selection = self.vf.getSelection() 568 #check if self.surfName corresponds to the name typed in the entryform: 569 surfName = self.ifd.entryByName['surfName']['widget'].get() 570 if surfName != self.surfName: 571 self.doitWrapper(nodes=selection, surfName = surfName, immediate =False)#do not run the network yet 572 573 self.doitWrapper(nodes=selection, immediate = True, gridSize = int(val), bindGeom = self.bindFlag.get())
574
575 - def set_resolution(self, val):
576 """callback of the input form's resolution radio buttons""" 577 #print "in set_resolution val = ", val 578 if self.buildFormFlag: 579 return 580 self.resolution_type = val 581 if val == "custom": 582 self.custom_resolution_flag = 1 583 self.enableThumbWheel(self.ifd.form.descr.entryByName['customResolution']['widget'], 584 val = self.surf_resolution) 585 else: 586 self.custom_resolution_flag = 0 587 self.disableThumbWheel(self.ifd.form.descr.entryByName['customResolution']['widget']) 588 surf_resolution = self.resolutions[val] 589 cb = self.ifd.entryByName['isovalue_type']['widget'] 590 if surf_resolution < -3.0 or surf_resolution > -0.1: 591 # resolution is out of range of values for isovalue fast approximation - 592 # need to disable the check button: 593 cb.component('fast approximation').configure(state='disabled') 594 if cb.getvalue() == "fast approximation": 595 self.set_isovalue("custom") 596 else: 597 if cb.component('fast approximation').cget('state') == 'disabled': 598 cb.component('fast approximation').configure(state = "normal") 599 immediate = self.ifd.entryByName['mode']['wcfg']['variable'].get() 600 if immediate: 601 selection = self.vf.getSelection() 602 #check if self.surfName corresponds to the name typed in the entryform: 603 surfName = self.ifd.entryByName['surfName']['widget'].get() 604 if surfName != self.surfName: 605 self.doitWrapper(nodes=selection,surfName = surfName, immediate =False)#do not run the network yet 606 self.doitWrapper(nodes=selection, resolution = surf_resolution, immediate = True, bindGeom = self.bindFlag.get())
607
608 - def set_isovalue(self, val):
609 """ callback of the input form's isovalue radio buttons """ 610 #print "in set_isovalue val = ", val 611 if self.buildFormFlag: 612 return 613 if val == "custom": 614 self.isovalue_type = "custom" 615 self.custom_isovalue_flag = 1 616 if self.ifd: 617 self.enableThumbWheel(self.ifd.entryByName['customIsovalue']['widget'], 618 val = self.isovalue) 619 else: 620 self.custom_isovalue_flag = 0 621 self.disableThumbWheel(self.ifd.entryByName['customIsovalue']['widget']) 622 immediate = self.ifd.entryByName['mode']['wcfg']['variable'].get() 623 if immediate: 624 #check if self.surfName corresponds to the name typed in the entryform: 625 surfName = self.ifd.entryByName['surfName']['widget'].get() 626 selection = self.vf.getSelection() 627 if surfName != self.surfName: 628 self.doitWrapper(nodes=selection,surfName = surfName, immediate =False)#do not run the network yet 629 self.doitWrapper(nodes=selection, isovalue=val, immediate = True, bindGeom = self.bindFlag.get())
630 631
632 - def set_padding(self, val):
633 """callback of the thumbwheel widget for setting padding around the molecule.""" 634 print "calls set_padding" 635 immediate = self.ifd.entryByName['mode']['wcfg']['variable'].get() 636 if immediate: 637 #check if self.surfName corresponds to the name typed in the entryform: 638 surfName = self.ifd.entryByName['surfName']['widget'].get() 639 selection = self.vf.getSelection() 640 if surfName != self.surfName: 641 self.doitWrapper(nodes=selection,surfName = surfName, immediate =False)#do not run the network yet 642 self.doitWrapper(nodes=selection,padding=val, immediate = True, bindGeom = self.bindFlag.get() )
643 644
645 - def set_custom_isovalue(self, val):
646 """callback of the thumbwheel widget used for setting custom isovalue """ 647 #print "in set_custom_isovalue val = ", val 648 immediate = self.ifd.entryByName['mode']['wcfg']['variable'].get() 649 if immediate: 650 #check if self.surfName corresponds to the name typed in the entryform: 651 surfName = self.ifd.entryByName['surfName']['widget'].get() 652 selection = self.vf.getSelection() 653 if surfName != self.surfName: 654 self.doitWrapper(nodes=selection,surfName = surfName, immediate =False)#do not run the network yet 655 self.doitWrapper(nodes=selection,isovalue=val, immediate = True, bindGeom = self.bindFlag.get() )
656
657 - def set_custom_resolution(self, val):
658 """callback of the thumbwheel widget used for setting custom resolution""" 659 #print "in set_custom_resolution val = ", val 660 cb = self.ifd.entryByName['isovalue_type']['widget'].component('fast approximation') 661 if val < -3.0 or val > -0.1: 662 # resolution is out of range of values for isovalue fast approximation - 663 # need to disable the check button: 664 cb.configure(state='disabled') 665 if self.ifd.entryByName['isovalue_type']['widget'].getvalue() == "fast approximation": 666 self.set_isovalue("custom") 667 self.isovalue_type = "custom" 668 else: 669 if cb.cget('state') == 'disabled': 670 cb.configure(state = "normal") 671 immediate = self.ifd.entryByName['mode']['wcfg']['variable'].get() 672 if immediate: 673 #check if self.surfName corresponds to the name typed in the entryform: 674 surfName = self.ifd.entryByName['surfName']['widget'].get() 675 selection = self.vf.getSelection() 676 if surfName != self.surfName: 677 self.doitWrapper(nodes=selection,surfName = surfName, immediate =False)#do not run the network yet 678 self.doitWrapper(nodes=selection,resolution = val, immediate = True, bindGeom = self.bindFlag.get())
679
680 - def dismiss (self, event = None):
681 """Withdraws the input form""" 682 683 self.cmdForms['default'].withdraw()
684
685 - def bind_cb(self):
686 """callback of the 'bind surface to molecule' check button """ 687 #immediate = self.ifd.entryByName['mode']['wcfg']['variable'].get() 688 self.bindGeom = self.bindFlag.get()
689 ## if immediate: 690 ## #check if self.surfName corresponds to the name typed in the entryform: 691 ## surfName = self.ifd.entryByName['surfName']['widget'].get() 692 ## if surfName != self.surfName: 693 ## self.doitWrapper(surfName = surfName, immediate =False)#do not run the network yet 694 ## self.doitWrapper(immediate = True, bindMol = self.bindFlag.get()) 695 696
697 - def get_precise_isovalue(self, resolution):
698 """Computes precise isovalue using methods from computeIsovalue.py """ 699 mols = [] 700 for mol in self.atomSet.top.uniq(): 701 mols.append(mol.name) 702 703 ri = self.precise_isovalues.get(tuple(mols)) 704 res_str = "%.2f"%resolution 705 if ri: 706 isovalue = ri.get(res_str) 707 if not isovalue: 708 isovalue = computeIsovalue(self.atomSet, resolution, self.gridSize) 709 if isovalue is not None: 710 self.precise_isovalues[tuple(mols)][res_str] = isovalue 711 else: 712 self.precise_isovalues[tuple(mols)]={} 713 isovalue = computeIsovalue(self.atomSet, resolution, self.gridSize) 714 if isovalue is not None: 715 self.precise_isovalues[tuple(mols)][res_str] = isovalue 716 return isovalue
717
718 - def entryValidate(self, text):
719 """ 720 Method to validate the name of the msms surface. This name 721 will be used by other command to build Pmw widget so it can't 722 contain an '_'. 723 """ 724 if '_' in text: 725 return Pmw.ERROR 726 else: 727 return Pmw.OK
728
729 - def compute(self, event = None):
730 """callback of 'Compute' button of the input form """ 731 kw = {} 732 surfName = self.ifd.entryByName['surfName']['widget'].get() 733 if surfName != self.surfName: 734 kw['surfName']=surfName 735 736 restype = self.ifd.entryByName['resolution_type']['widget'].getvalue() 737 if restype == "custom": 738 resolution = self.ifd.entryByName['customResolution']['widget'].get() 739 else: 740 resolution = self.resolutions[restype] 741 kw['resolution'] = resolution 742 isovalue = self.ifd.entryByName['isovalue_type']['widget'].getvalue() 743 if isovalue == "custom": 744 isovalue = self.ifd.entryByName['customIsovalue']['widget'].get() 745 kw['isovalue'] = isovalue 746 perMol = self.ifd.entryByName['perMol']['wcfg']['variable'].get() 747 kw['perMol'] = perMol 748 kw['immediate'] = False 749 gs= self.ifd.entryByName['gridsize']['widget'].get() 750 if gs: 751 kw['gridSize'] = int(gs) 752 kw['bindGeom'] = self.bindFlag.get() 753 kw['nodes'] = self.vf.getSelection() 754 kw['padding'] = self.ifd.entryByName['padding']['widget'].get() 755 apply(self.doitWrapper, (), kw) 756 self.dismiss()
757 758
759 - def disableThumbWheel(self, tw):
760 """disables a thumbwheel widgets used to specify custom resolution/isovalue""" 761 def foo(val): 762 pass
763 tw.configure(showLabel=0) 764 tw.canvas.bind("<ButtonPress-1>", foo) 765 tw.canvas.bind("<ButtonRelease-1>", foo) 766 tw.canvas.bind("<B1-Motion>", foo) 767 tw.canvas.bind("<Button-3>", foo)
768 769
770 - def enableThumbWheel(self, tw, val =None):
771 """enables a thumbwheel widgets used to specify custom resolution/isovalue""" 772 tw.canvas.bind("<ButtonPress-1>", tw.mouseDown) 773 tw.canvas.bind("<ButtonRelease-1>", tw.mouseUp) 774 tw.canvas.bind("<B1-Motion>", tw.mouseMove) 775 tw.canvas.bind("<Button-3>", tw.toggleOptPanel) 776 tw.configure(showLabel=1) 777 if val: 778 tw.set(val, update=0)
779
780 - def piecewiseLinearInterpOnIsovalue(self, x):
781 """Piecewise linear interpretation on isovalue that is a function 782 blobbyness. 783 """ 784 import sys 785 X = [-3.0, -2.5, -2.0, -1.5, -1.3, -1.1, -0.9, -0.7, -0.5, -0.3, -0.1] 786 Y = [0.6565, 0.8000, 1.0018, 1.3345, 1.5703, 1.8554, 2.2705, 2.9382, 4.1485, 7.1852, 26.5335] 787 if x<X[0] or x>X[-1]: 788 print "WARNING: Fast approximation :blobbyness is out of range [-3.0, -0.1]" 789 return None 790 i = 0 791 while x > X[i]: 792 i +=1 793 x1 = X[i-1] 794 x2 = X[i] 795 dx = x2-x1 796 y1 = Y[i-1] 797 y2 = Y[i] 798 dy = y2-y1 799 return y1 + ((x-x1)/dx)*dy
800 801 802 coarseMolSurfaceGUI = CommandGUI() 803 coarseMolSurfaceGUI.addMenuCommand('menuRoot','Compute', 'Coarse Molecular Surface') 804 commandList = [{'name':'coarseMolSurface','cmd':coarseMolSurface(),'gui':coarseMolSurfaceGUI},] 805
806 -def initModule(viewer):
807 for com in commandList: 808 viewer.addCommand(com['cmd'],com['name'],com['gui'])
809