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

Source Code for Module Pmv.traceCommands

   1  ############################################################################# 
   2  # 
   3  # author: Sophie COON, Michel F. SANNER 
   4  # 
   5  # Copyright: M. Sanner TSRI 2000 
   6  # 
   7  ############################################################################# 
   8  """Module for Compute,Extrude and Display Trace. 
   9  This module provides a set of commands: 
  10  - ComputeTraceCommand (computeTrace) to compute a trace and the corresponding 
  11    sheet2D using the given control atoms and torsion atoms. Typically used to 
  12    compute a CA trace for a protein 
  13  - ExtrudeTraceCommand (extrudeTrace) to extrude a 2D geometry along the 3D 
  14    path to represent the given trace. 
  15  - DisplayTraceCommand (displayTrace) to display, undisplay or display only 
  16    parts of the molecule using the geometry created to represent the given 
  17    trace. 
  18    Keywords: 
  19    Trace, CA  
  20     
  21  """ 
  22  # 
  23  #$Header: /opt/cvs/python/packages/share1.5/Pmv/traceCommands.py,v 1.27 2007/05/15 17:39:37 vareille Exp $ 
  24  # 
  25  #$Id: traceCommands.py,v 1.27 2007/05/15 17:39:37 vareille Exp $ 
  26  # 
  27   
  28  from MolKit.protein import Coil, Chain, ResidueSet, SecondaryStructureSet 
  29  from MolKit.protein import Residue 
  30  from MolKit.tree import TreeNode, TreeNodeSet 
  31  from MolKit.molecule import Atom, AtomSet 
  32   
  33  from DejaVu.Shapes import Shape2D, Triangle2D, Circle2D, Rectangle2D,\ 
  34       Square2D, Ellipse2D 
  35   
  36  from DejaVu.IndexedPolygons import IndexedPolygons 
  37  from DejaVu.Geom import Geom 
  38   
  39  from Pmv.mvCommand import MVCommand 
  40  from Pmv.displayCommands import DisplayCommand 
  41  from Pmv.extruder import ExtrudeSSElt, Sheet2D 
  42   
  43  from mglutil.gui.BasicWidgets.Tk.customizedWidgets import ExtendedSliderWidget 
  44  from mglutil.gui.InputForm.Tk.gui import InputFormDescr 
  45  from mglutil.gui.BasicWidgets.Tk.customizedWidgets import ListChooser 
  46   
  47  from ViewerFramework.VFCommand import CommandGUI 
  48  from opengltk.OpenGL import GL 
  49  from types import StringType 
  50  import Tkinter, Pmw,types 
  51   
  52   
  53   
54 -class ComputeTraceCommand(MVCommand):
55 """This command computes the oriented spline (trace) for the molecules in the current selection. It creates a Coil object for each chaine of the molecule having at least one node in the current selection.The Coil object can only be created for the residues having the chosen ctlAtm and torsAtm. 56 \nPackage : Pmv 57 \nModule : traceCommands 58 \nClass : ComputeTraceCommand 59 \nCommand : computeTrace 60 \nkeywords: compute trace 61 \nSynopsis:\n 62 None <- computeTrace(nodes, traceName='CATrace', ctlAtmName='CA', 63 torsAtmName='O',nbchords = 4, **kw) 64 \nRequired Arguments:\n 65 nodes --- any set of MolKit nodes describing molecular components 66 \nOptional Arguments:\n 67 traceName --- string representing the name of the computed trace. 68 default 'CATrace' 69 \nctlAtmName --- name of the atom to be used for control (defaul='CA') 70 \ntorsAtmName --- name of the atom to be used to control the torsion. 71 default='O' 72 \nnbchords --- number of points per residue. The higher the number the 73 smoother the trace will be. 74 """ 75
76 - def __init__(self):
77 MVCommand.__init__(self) 78 self.flag = self.flag | self.objArgOnly
79
80 - def pickedVerticesToAtoms(self, geom, vertInd ):
81 """ 82 Function called to convert a picked vertex into the first atom 83 of the picked residue 84 """ 85 trace = geom.trace 86 l = [] 87 for vi in vertInd: 88 resInd = trace.exElt.getResIndexFromExtrudeVertex( vi ) 89 l.append(trace.children[resInd].atoms[0]) 90 return AtomSet( AtomSet( l ) )
91 92
93 - def onAddCmdToViewer(self):
94 if self.vf.hasGui and not self.vf.commands.has_key('computeSheet2D'): 95 self.vf.loadCommand("extrusionCommands", 'computeSheet2D', 96 "Pmv", topCommand = 0)
97 98 99
100 - def atomPropToVertices(self, geom, residues, propName, propIndex = None):
101 """ 102 Function called to compute the array of property for the given 103 residues 104 """ 105 106 if residues is None or len(residues)==0 : return None 107 propVect = [] 108 if not propIndex is None: 109 propIndex = self.traceName 110 for r in residues: 111 prop = getattr(r.atoms[0], propName) 112 if not propIndex is None: 113 propVect.append(prop[propIndex]) 114 else: 115 propVect.append(prop) 116 117 geom.trace.exElt.setResProperties(propVect, propName, residues) 118 properties = geom.trace.exElt.getExtrudeProperties( residues, 119 propName ) 120 return properties
121 122 123
124 - def dialog(self,mol):
125 msg ="Use Previous Trace for %s" %(mol.name) 126 from SimpleDialog import SimpleDialog 127 d = SimpleDialog(self.vf.GUI.ROOT, text=msg, 128 buttons=['No','Yes'], default=1, 129 title='Display?') 130 ok =d.go() 131 if ok ==0: 132 self.disp = False 133 else: 134 self.disp = True 135 return self.disp
136
137 - def createGeometries(self, mol,nodes):
138 """ 139 Initialize the geometries that will be used to represent the CA Trace 140 objects for the given molecule mol. 141 """ 142 traceName = self.traceName 143 # get a handle on the geomContainer 144 geomC = mol.geomContainer 145 # Create a trace parent geometry for the molecule if doesn't 146 # exist already 147 if not geomC.geoms.has_key('trace'): 148 p = Geom('trace', shape=(0,0), protected=True) 149 geomC.addGeom( p, parent=geomC.masterGeom,redo=0 ) 150 else: 151 p = geomC.geoms['trace'] 152 153 # Then create a traceName parent geometry 154 if not geomC.geoms.has_key(traceName) : 155 c = Geom(traceName, shape=(0,0), protected=True) 156 geomC.addGeom(c, parent=p,redo=0) 157 self.managedGeometries.append(c) 158 159 for a in mol.allAtoms: 160 a.colors[traceName]=(1.,1.,1.) 161 a.opacities[traceName]=1.0 162 else: 163 newval =0 164 self.mol=mol 165 c = geomC.geoms[traceName] 166 for chain in mol.chains: 167 cname = traceName+chain.id 168 #if geomC.geoms.keys has cname 169 if geomC.geoms.has_key(cname): 170 #if morethan one chain not to display dialogbox for each 171 #chain ,newval var is initialized to zero.If No selected in #dialog box(doesn't want to use existing same trace and want to compute new one) 172 #then newvar set to 1 173 if newval ==0 and geomC.atoms[cname]!=[]: 174 rval =self.dialog(mol) 175 #if doesn't want to use existing trace 176 #trace is made invisible 177 #and is removed since in color commands for coloring geom 178 #checks for coords so trace is removed 179 if rval ==False: 180 newval =1 181 geomC.geoms[cname].Set(visible=0,tagModified=False) 182 self.vf.GUI.VIEWER.RemoveObject(geomC.geoms[cname]) 183 del geomC.geoms[cname] 184 del geomC.atoms[cname] 185 else: 186 return 187 # Initialize the atom colors and opacities dictionary for the 188 # 'trace' entry 189 190 # loop over the chain of the given molecule 191 for chain in mol.chains: 192 if not hasattr(chain, 'trace') or \ 193 not chain.trace.has_key(traceName): continue 194 if chain.trace[traceName] is None: continue 195 # get a handle on the trace object 196 trace = chain.trace[traceName] 197 # name of the geometry representing the catrace is the 198 # concatenation of the catrace object name and the chain id. 199 name = traceName+chain.id 200 # Create an empty IndexedPolygons to represent the ca trace of the 201 # chain and add it to the Viewer 202 g = IndexedPolygons(name, visible=0, pickableVertices=1, protected=True,) 203 if self.vf.userpref['sharpColorBoundariesForMsms']['value'] == 'blur': 204 g.Set(inheritSharpColorBoundaries=False, sharpColorBoundaries=False,) 205 if not geomC.geoms.has_key(name) or (geomC.geoms.has_key(name) and (geomC.atoms[name] == [])): 206 geomC.addGeom(g, parent=c) 207 self.managedGeometries.append(g) 208 209 #g.RenderMode(GL.GL_FILL, face=GL.GL_FRONT) 210 geomC.atoms[name] = ResidueSet() 211 g.Set(frontPolyMode=GL.GL_FILL) 212 g.trace = trace 213 g.mol = mol #need for backtracking picking 214 geomC.atomPropToVertices[name] = self.atomPropToVertices 215 geomC.geoms[name] = g 216 geomC.geomPickToAtoms[name] = self.pickedVerticesToAtoms 217 geomC.geomPickToBonds[name] = None 218 219 childtrace=traceName+chain.id 220 if not hasattr(chain, 'trace') or \ 221 not chain.trace.has_key(traceName): continue
222
223 - def doit(self, nodes, traceName='CATrace', ctlAtmName = 'CA', 224 torsAtmName='O', nbchords = 4):
225 if len(nodes) == 0: 226 return 227 self.vf.computeSheet2D(nodes, traceName, ctlAtmName, torsAtmName, 228 nbchords=nbchords, topCommand=0) 229 j = 0 230 231 self.traceName = traceName 232 molecules, chainSet = self.vf.getNodesByMolecule(nodes, Chain) 233 for mol, chains in map(None, molecules, chainSet): 234 for chain in chains: 235 if not hasattr(chain, 'trace'): chain.trace = {} 236 if chain.sheet2D[traceName] is None: 237 chain.trace[traceName]=None 238 msg = "WARNING: the %s for the chain %s of the molecule %s\ncould not be computed with the given parameters"%(traceName,chain.id, mol.name) 239 self.warningMsg(msg) 240 continue 241 else: 242 res = chain.sheet2D[traceName].resInSheet 243 chain.trace[traceName] = Coil(chain=chain, 244 structureType=traceName, 245 index = j, start = res[0], 246 end = res[-1], 247 createNewLevel=0) 248 j = j+1 249 chain.trace[traceName].sheet2D = chain.sheet2D[traceName] 250 251 self.createGeometries(mol,nodes)
252
253 - def getAvailableTrace(self):
254 mols = self.vf.getSelection().top.uniq() 255 tracesName = [] 256 for m in mols: 257 if not m.geomContainer.geoms.has_key('trace'): continue 258 names = map(lambda x: x.name, 259 m.geomContainer.geoms['trace'].children) 260 for n in names: 261 if not n in tracesName: tracesName.append(n) 262 return tracesName
263 264
265 - def buildFormDescr(self, formName):
266 if formName == 'traceForm': 267 idf = InputFormDescr('Compute Trace') 268 idf.append({'name':'traceName', 269 'widgetType':Pmw.ComboBox, 270 'tooltip':'Create a new trace by typing a new trace \n\ 271 name in the entry of the combobox. \nHit the Enter key to add it to the list \ 272 of trace name. \nYou can also choose from the existing list of trace names.\n\ 273 To see the list click on the down arrow.', 274 'defaultValue':self.traceNames[0], 275 'wcfg':{'label_text':'Choose a trace: ', 276 'labelpos':'w', 277 'scrolledlist_items': self.traceNames, 278 }, 279 'gridcfg':{'sticky':'w','columnspan':2}}) 280 281 idf.append({'name':'ctlAtmName', 282 'widgetType':Pmw.EntryField, 283 'tooltip':'String representing the name of the atom \n\ 284 to be used as control atom. Specify only one atom name.', 285 'wcfg':{'label_text':'Control atom name:', 286 'labelpos':'w', 'entry_width':4, 287 'value':'CA'}, 288 'gridcfg':{'sticky':'w'}}) 289 290 idf.append({'name':'torsAtmName', 291 'widgetType':Pmw.EntryField, 292 'tooltip':'String representing the name of the atom \n\ 293 to be used to control the torsion. Specify only one atom name.', 294 'wcfg':{'label_text':'Torsion atom name:', 295 'labelpos':'w', 'entry_width':4, 296 'value':'O'}, 297 'gridcfg':{'sticky':'w', 'row':-1}}) 298 299 300 idf.append( {'name': 'nbchords', 301 'widgetType':ExtendedSliderWidget, 302 'type':int, 303 'tooltip':'Specifies the number of points per \ 304 residues.\n The higher the number the smoother the trace will be.', 305 'wcfg':{'label': 'nb points per residues', 306 'minval':4,'maxval':15, 307 'incr': 1, 'init':4, 308 'labelsCursorFormat':'%d', 309 'sliderType':'int' 310 }, 311 'gridcfg':{'sticky':'w', 'columnspan':2}, 312 }) 313 314 return idf
315
316 - def guiCallback(self):
317 self.traceNames = self.getAvailableTrace() 318 if not self.traceNames:self.traceNames = ['CATrace',] 319 if self.cmdForms.has_key('traceForm'): 320 form = self.cmdForms['traceForm'] 321 combo = form.descr.entryByName['traceName']['widget'] 322 if self.traceNames != combo.get(): 323 combo.setlist(self.traceNames) 324 325 val = self.showForm('traceForm') 326 if not val: return 327 if len(val['traceName']) == 0: 328 return 329 val['traceName'] = val['traceName'][0] 330 if not val['ctlAtmName'] or not val['torsAtmName']: return 331 val['redraw']=0 332 apply(self.doitWrapper, (self.vf.getSelection(), ), val)
333 334
335 - def __call__(self, nodes, traceName='CATrace', ctlAtmName='CA', 336 torsAtmName='O', nbchords=4, **kw):
337 """None <- computeTrace(nodes, traceName='CATrace', ctlAtmName='CA', 338 torsAtmName='O',nbchords = 4, **kw) 339 \nRequired Arguments:\n 340 nodes : any set of MolKit nodes describing molecular components 341 \nOptional Arguments:\n 342 traceName : string representing the name of the computed trace. 343 (default 'CATrace') 344 \nctlAtmName : name of the atom to be used for control (defaul='CA') 345 \ntorsAtmName: name of the atom to be used to control the torsion. 346 (default='O') 347 \nnbchords : number of points per residue. The higher the number the smoother the trace will be. (default = 4) 348 """ 349 if nodes is None: 350 return 351 nodes=self.vf.expandNodes(nodes) 352 if not nodes: 353 return "ERROR" 354 kw['traceName'] = traceName 355 kw['ctlAtmName'] = ctlAtmName 356 kw['torsAtmName'] = torsAtmName 357 kw['nbchords'] = nbchords 358 kw['redraw']=0 359 if type(nodes) is StringType: 360 self.nodeLogString = "'" + nodes +"'" 361 apply (self.doitWrapper, (nodes,), kw )
362 363
364 -class ExtrudeTraceCommand(MVCommand):
365 """This command extrude a shape 2D along the path 3D of a given trace computed by the computeTrace command. 366 \nPackage : Pmv 367 \nModule : traceCommands 368 \nClass : ExtrudeTraceCommand 369 \nCommand : extrudeTrace 370 \nSynopsis: 371 None <- extrudeTrace(nodes, traceName='CATrace', shape2D=None, 372 frontCap=1, endCap=1, display=1, **kw) 373 \nRequired Arguments:\n 374 nodes --- any set of MolKit nodes describing molecular components. 375 \nOptional Arguments:\n 376 traceName --- string representing the name of the trace to be represented 377 the default value is 'CATrace'. 378 \nshape2D --- instance of a DejaVu.Shape class describing the shape 2D 379 to be extruded along the path3D of the selected trace. 380 By default a Circle2D will be extruded 381 \nfrontCap --- when set to 1 a cap is added to all the front of the extruded 382 geometry created to represent the selected trace. 383 \nendCap --- when set to 1 a cap is added to all the end of the extruded 384 geometry representing the selected trace. 385 \ndisplay --- when set to 1 the displayTrace command is called. 386 """
387 - def __init__(self, func=None):
388 MVCommand.__init__(self, func=func) 389 self.flag = self.flag | self.objArgOnly
390 391
392 - def onAddCmdToViewer(self):
393 if self.vf.hasGui and not self.vf.commands.has_key('computeTrace'): 394 self.vf.loadCommand("traceCommands", 'computeTrace', 395 "Pmv", topCommand = 0) 396 397 if self.vf.hasGui and \ 398 not self.vf.commands.has_key('displayTrace'): 399 self.vf.loadCommand("traceCommands", 'displayTrace', 400 'Pmv', topCommand = 0)
401 402 403
404 - def __call__(self, nodes, traceName='CATrace', shape2D=None, 405 frontCap=True, endCap=True, display=True, **kw):
406 """None <- extrudeTrace(nodes, traceName='CATrace', shape2D=None, 407 frontCap=1, endCap=1, display=1, **kw) 408 \nRequired Arguments:\n 409 nodes --- any set of MolKit nodes describing molecular components. 410 \nOptional Arguments:\n 411 traceName --- string representing the name of the trace to be represented 412 the default value is 'CATrace'. 413 \nshape2D --- instance of a DejaVu.Shape class describing the shape 2D 414 to be extruded along the path3D of the selected trace. 415 By default a Circle2D will be extruded 416 \nfrontCap --- when set to True a cap is added to all the front of the 417 extruded geometry created to represent the selected trace. 418 \nendCap --- when set to True a cap is added to all the end of the extruded 419 geometry representing the selected trace. 420 \ndisplay --- when set to True the displayTrace command is called. 421 """ 422 nodes = self.vf.expandNodes(nodes) 423 if not nodes: 424 return "ERROR" 425 kw['shape2D'] = shape2D 426 kw['display'] = display 427 kw['traceName'] = traceName 428 kw['frontCap'] = frontCap 429 kw['endCap'] = endCap 430 if type(nodes) is StringType: 431 self.nodeLogString = "'" + nodes +"'" 432 apply(self.doitWrapper, (nodes,), kw)
433 434
435 - def doit(self, nodes, traceName='CATrace', shape2D=None, frontCap=True, 436 endCap=True, display=True):
437 438 if shape2D is None: 439 shape2D = Circle2D(radius=0.1) 440 molecules, atomsSet = self.vf.getNodesByMolecule(nodes, Atom) 441 self.shape = shape2D 442 arrowf = 0 443 for mol, atoms in map(None, molecules, atomsSet): 444 chains = atoms.findType(Chain).uniq() 445 gc = mol.geomContainer 446 for chain in chains: 447 # Cannot get the trace thing id no trace has been computed. 448 if not hasattr(chain, 'trace'): 449 continue 450 elif not chain.trace.has_key(traceName) or \ 451 chain.trace[traceName] is None: 452 continue 453 454 name = traceName + chain.id 455 trace = chain.trace[traceName] 456 trace.exElt = ExtrudeSSElt(trace, shape2D, cap1=frontCap, 457 cap2=endCap, arrow=arrowf) 458 resfaces = trace.exElt.getExtrudeResidues(trace.residues) 459 g = mol.geomContainer.geoms[name] 460 g.Set(vertices=trace.exElt.vertices, 461 faces=resfaces, vnormals=trace.exElt.vnormals, 462 redo=0, tagModified=False) 463 if display: 464 self.vf.displayTrace(nodes, traceName, negate=False, 465 setupUndo=True, topCommand=False, redraw=True)
466
467 - def getAvailableTrace(self):
468 mols = self.vf.getSelection().top.uniq() 469 tracesName = [] 470 for m in mols: 471 if not m.geomContainer.geoms.has_key('trace'): continue 472 names = map(lambda x: x.name, 473 m.geomContainer.geoms['trace'].children) 474 for n in names: 475 if not n in tracesName: tracesName.append(n) 476 return tracesName
477 478
479 - def buildFormDescr(self, formName):
480 if formName == 'geomChooser': 481 nbchordEntryVar = Tkinter.StringVar() 482 idf = InputFormDescr(title ="Choose a shape :") 483 idf.append({'name':'traceName', 484 'widgetType':Pmw.ComboBox, 485 'tooltip':'Choose a trace to extrude.', 486 'defaultValue':self.traceNames[0], 487 'wcfg':{'label_text':'Choose a trace: ', 488 'labelpos':'w', 489 'scrolledlist_items': self.traceNames, 490 }, 491 'gridcfg':{'sticky':'w'}}) 492 493 entries = ['circle','rectangle','ellipse', 'square','triangle'] 494 495 idf.append({'name':'shape', 496 'widgetType':Pmw.ComboBox, 497 'tooltip':'Choose a shape2D to be extruded.', 498 'defaultValue':entries[0], 499 'wcfg':{'label_text':'Choose a shape', 500 'labelpos':'w', 501 'scrolledlist_items':entries}, 502 'gridcfg':{'sticky':'w'} 503 }) 504 505 else: 506 initRadius = 0.1 507 radiusWidgetDescr = {'name': 'radius', 508 'widgetType':ExtendedSliderWidget, 509 'wcfg':{'label': 'Radius', 510 'minval':0.05,'maxval':3.0 , 511 'init':initRadius, 512 'labelsCursorFormat':'%1.2f', 513 'sliderType':'float', 514 'entrywcfg':{'width':4}, 515 'entrypackcfg':{'side':'right'}}, 516 'gridcfg':{'columnspan':2,'sticky':'we'} 517 } 518 initWidth = 1.2 519 widthWidgetDescr = {'name': 'width', 520 'widgetType':ExtendedSliderWidget, 521 'wcfg':{'label': 'Width', 522 'minval':0.05,'maxval':3.0 , 523 'init':initWidth, 524 'labelsCursorFormat':'%1.2f', 525 'sliderType':'float', 526 'entrywcfg':{'width':4}, 527 'entrypackcfg':{'side':'right'}}, 528 'gridcfg':{'columnspan':2,'sticky':'we'} 529 } 530 initHeight = 0.2 531 heightWidgetDescr = {'name': 'height', 532 'widgetType':ExtendedSliderWidget, 533 'wcfg':{'label': 'Height', 534 'minval':0.05,'maxval':3.0 , 535 'init':initHeight, 536 'labelsCursorFormat':'%1.2f', 537 'sliderType':'float' , 538 'entrywcfg':{'width':4}, 539 'entrypackcfg':{'side':'right'}}, 540 'gridcfg':{'columnspan':2,'sticky':'we'} 541 } 542 initSide = 1.0 543 sideWidgetDescr = {'name': 'sidelength', 544 'widgetType':ExtendedSliderWidget, 545 'wcfg':{'label': 'Length of side:', 546 'minval':0.05,'maxval':3.0 , 547 'init':initSide, 548 'labelsCursorFormat':'%1.2f', 549 'sliderType':'float', 550 'entrywcfg':{'width':4}, 551 'entrypackcfg':{'side':'right'}}, 552 'gridcfg':{'columnspan':2,'sticky':'we'} 553 } 554 555 frontCapWidgetDescr = {'name':'frontcap', 556 'widgetType':Tkinter.Checkbutton, 557 'tooltip':'when set to 1 a cap is added \nat the front', 558 'defaultValue':1, 559 'wcfg':{'text':'front cap', 560 'variable': Tkinter.IntVar()}, 561 'gridcfg':{'sticky':'we'}} 562 endCapWidgetDescr = {'name':'endcap', 563 'widgetType':Tkinter.Checkbutton, 564 'defaultValue':1, 565 'tooltip':"""when set to 1 a cap is added 566 at the end""", 567 'wcfg':{'text':'end cap ', 568 'variable': Tkinter.IntVar()}, 569 'gridcfg':{'sticky':'we','row':-1}} 570 571 572 if formName == 'rectangle': 573 idf = InputFormDescr(title ="Rectangle size :") 574 idf.append(widthWidgetDescr) 575 initHeight = 0.4 576 idf.append(heightWidgetDescr) 577 578 elif formName == 'circle': 579 idf = InputFormDescr(title="Circle size :") 580 idf.append(radiusWidgetDescr) 581 582 elif formName == 'ellipse': 583 idf = InputFormDescr(title="Ellipse size") 584 idf.append( {'name': 'grand', 585 'widgetType':ExtendedSliderWidget, 586 'wcfg':{'label': 'demiGrandAxis', 587 'minval':0.05,'maxval':3.0 , 588 'init':0.5, 589 'labelsCursorFormat':'%1.2f', 590 'sliderType':'float', 591 'entrywcfg':{'width':4}, 592 'entrypackcfg':{'side':'right'}}, 593 'gridcfg':{'columnspan':2,'sticky':'we'} 594 }) 595 idf.append( {'name': 'small', 596 'widgetType':ExtendedSliderWidget, 597 'wcfg':{'label': 'demiSmallAxis', 598 'minval':0.05,'maxval':3.0 , 599 'init':0.2, 600 'labelsCursorFormat':'%1.2f', 601 'sliderType':'float', 602 'entrywcfg':{'width':4}, 603 'entrypackcfg':{'side':'right'}}, 604 'gridcfg':{'columnspan':2,'sticky':'we'} 605 }) 606 elif formName == 'square': 607 idf = InputFormDescr(title="Square size :") 608 idf.append(sideWidgetDescr) 609 610 elif formName == 'triangle': 611 idf = InputFormDescr(title="Triangle size :") 612 idf.append(sideWidgetDescr) 613 614 615 # These widgets are present in everyInputForm. 616 idf.append(frontCapWidgetDescr) 617 idf.append(endCapWidgetDescr) 618 return idf
619
620 - def guiCallback(self):
621 from ViewerFramework.drawShape import DrawShape 622 self.traceNames = self.getAvailableTrace() 623 if not self.traceNames : return 624 if self.cmdForms.has_key('geomChooser'): 625 form = self.cmdForms['geomChooser'] 626 combo = form.descr.entryByName['traceName']['widget'] 627 if self.traceNames != combo.get(): 628 combo.setlist(self.traceNames) 629 630 typeshape = self.showForm('geomChooser') 631 632 if typeshape == {} or typeshape['shape'] == []: return 633 traceName = typeshape['traceName'][0] 634 if not traceName or traceName == " ": 635 return 636 637 # Shape is a Rectangle 638 if typeshape['shape'][0]=='rectangle': 639 val = self.showForm('rectangle') 640 if val: 641 shape2D = Rectangle2D(width = val['width'], 642 height = val['height'], 643 vertDup=1) 644 frontCap, endCap = int(val['frontcap']),int(val['endcap']) 645 646 # Shape is a Circle: 647 elif typeshape['shape'][0]=='circle': 648 649 val = self.showForm('circle') 650 if val: 651 shape2D = Circle2D(radius=val['radius']) 652 frontCap, endCap = val['frontcap'],val['endcap'] 653 654 # Shape is an Ellipse 655 elif typeshape['shape'][0]=='ellipse': 656 val = self.showForm('ellipse') 657 if val: 658 shape2D = Ellipse2D(demiGrandAxis= val['grand'], 659 demiSmallAxis=val['small']) 660 frontCap, endCap = val['frontcap'],val['endcap'] 661 662 # Shape is a Square: 663 elif typeshape['shape'][0]=='square': 664 val = self.showForm('square') 665 if val: 666 shape2D = Square2D(side=val['sidelength'], vertDup=1) 667 frontCap, endCap = val['frontcap'],val['endcap'] 668 669 # Shape is a Triangle: 670 elif typeshape['shape'][0]=='triangle': 671 val = self.showForm('triangle') 672 if val: 673 shape2D = Triangle2D(side=val['sidelength'], vertDup=1) 674 frontCap, endCap = val['frontcap'], val['endcap'] 675 676 else: return 677 678 if val: 679 self.doitWrapper(self.vf.getSelection(),traceName=traceName, 680 shape2D=shape2D, 681 frontCap=frontCap, endCap=endCap, 682 redraw=0) 683 else: return
684 685
686 -class DisplayTraceCommand(DisplayCommand):
687 """This command allows the user to display, undisplay or display only the current selection using the extruded trace representation of the given 688 traceName. 689 \nPackage : Pmv 690 \nModule : traceCommands 691 \nClass : DisplayTraceCommand 692 \nCommand : displayTrace 693 \nkeywords: display trace CA... 694 \nSynopsis:\n 695 None <- displayTrace(nodes, traceName, negate=0, only=0, **kw) 696 \nRequired Arguments:\n 697 nodes --- any set of MolKit nodes describing molecular components. 698 \nOptional Arguments:\n 699 traceName --- string representing the extruded trace to be displayed, 700 undisplayed or displayed only 701 \nnegate --- flag when set to 1 undisplay the trace corresponding to 702 the current selection 703 \nonly --- flag when set to 1 the part of the trace geometry 704 corresponding to the current selection will be displayed 705 only. 706 """
707 - def onAddCmdToViewer(self):
708 if self.vf.hasGui and not self.vf.commands.has_key('computeTrace'): 709 self.vf.loadCommand("traceCommands", 'computeTrace', 710 "Pmv", topCommand = 0) 711 712 if self.vf.hasGui and not self.vf.commands.has_key('extrudeTrace'): 713 self.vf.loadCommand("traceCommands", 'extrudeTrace', 714 "Pmv", topCommand = 0)
715
716 - def setupUndoBefore(self, nodes, traceName='CATrace', only=False, 717 negate=False):
718 if len(nodes)==0: return 719 kw = {'redraw':1} 720 kw['traceName']=traceName 721 geomSet=[] 722 for mol in self.vf.Mols: 723 gc = mol.geomContainer 724 for chain in mol.chains: 725 if not hasattr(chain, 'trace'): continue 726 if not chain.trace.has_key(traceName): continue 727 if not hasattr(chain.trace[traceName], 'exElt'): 728 continue 729 name = "%s%s"%(traceName, chain.id) 730 geomSet = geomSet + gc.atoms[name] 731 732 if len(geomSet) == 0: 733 # The undo of a display command is undisplay what you just 734 # displayed if nothing was displayed before. 735 kw['negate'] = True 736 self.addUndoCall( (nodes,), kw, self.name) 737 else: 738 # The undo of a display command is to display ONLY what was 739 # displayed before, if something was already displayed 740 kw['only'] = True 741 self.addUndoCall( (geomSet,), kw, self.name)
742
743 - def doit(self, nodes, traceName='CATrace', only=False, negate=False ):
744 """ displays the secondary structure for the selected treenodes """ 745 746 ############################################################### 747 def drawResidues(trace, traceName, res, only, negate): 748 mol = trace.chain.parent 749 name = '%s%s'%(traceName, trace.chain.id) 750 set = mol.geomContainer.atoms[name] 751 if negate : 752 set = set - res 753 754 ##if only, replace displayed set with current atms 755 else: 756 if only: 757 set = res 758 else: 759 set = res.union(set) 760 ##now, update the geometries: 761 # draw residues' secondary strucuture 762 if len(set)==0: 763 mol.geomContainer.geoms[name].Set(visible=0, 764 tagModified=False) 765 mol.geomContainer.atoms[name] = set 766 return 767 768 #the rest is done only if there are some residues 769 g = mol.geomContainer.geoms[name] 770 mol.geomContainer.atoms[name] = set 771 772 #resfaces = catrace.getExtrudeResidues(set) 773 resfaces = trace.exElt.getExtrudeResidues(set) 774 col = mol.geomContainer.getGeomColor(name) 775 g.Set(faces=resfaces, vnormals=trace.exElt.vnormals, 776 visible=1, materials=col, tagModified=False)
777 778 ############################################################### 779 780 molecules, residueSets = self.vf.getNodesByMolecule(nodes, Residue) 781 for mol,residues in map(None,molecules, residueSets): 782 for chain in mol.chains: 783 if not hasattr(chain, 'trace'): continue 784 if not chain.trace.has_key(traceName): 785 continue 786 if not hasattr(chain.trace[traceName], 'exElt'): 787 continue 788 trace = chain.trace[traceName] 789 res = residues.get(lambda x, tr = trace: 790 x in tr.residues) 791 if not res: 792 res = ResidueSet() 793 drawResidues(trace, traceName,res, only, negate)
794 795
796 - def buildFormDescr(self, formName):
797 if formName == 'displayTrace': 798 idf = InputFormDescr(title='Display Extruded Trace') 799 idf.append({'name':'display', 800 'widgetType':Pmw.RadioSelect, 801 'listtext':['display','display only', 'undisplay'], 802 'defaultValue':'display', 803 'wcfg':{'orient':'horizontal', 804 'buttontype':'radiobutton'}, 805 'gridcfg':{'sticky': 'we','columnspan':3}}) 806 807 idf.append({'name':'traceName', 808 'widgetType':Pmw.ComboBox, 809 'tooltip':'Choose a trace to extrude.', 810 'defaultValue':self.traceNames[0], 811 'wcfg':{'label_text':'Choose a trace: ', 812 'labelpos':'w', 813 'scrolledlist_items': self.traceNames, 814 }, 815 'gridcfg':{'sticky':'w','columnspan':2}}) 816 return idf
817
818 - def guiCallback(self):
819 self.traceNames = self.vf.extrudeTrace.getAvailableTrace() 820 if not self.traceNames: return 821 if self.cmdForms.has_key('displayTrace'): 822 form = self.cmdForms['displayTrace'] 823 combo = form.descr.entryByName['traceName']['widget'] 824 if self.traceNames != combo.get(): 825 combo.setlist(self.traceNames) 826 827 val = self.showForm('displayTrace') 828 if not val: return 829 display = val['display'] 830 del val['display'] 831 if display == 'undisplay': 832 val['negate'] = 1 833 val['only'] = 0 834 elif display == 'display only': 835 val['negate'] = 0 836 val['only'] = 1 837 elif display == 'display': 838 val['negate'] = 0 839 val['only'] = 0 840 val['traceName'] = val['traceName'][0] 841 if not val['traceName']: return 842 val['redraw']=1 843 844 apply(self.doitWrapper, (self.vf.getSelection(),), val)
845
846 - def __call__(self, nodes, traceName='CATrace', only=False, 847 negate=False, **kw):
848 """None <- displayTrace(nodes, traceName, negate=False, only=False, **kw) 849 \nRequired Arguments:\n 850 nodes --- any set of MolKit nodes describing molecular components. 851 \nOptional Arguments:\n 852 traceName --- string representing the extruded trace to be displayed, 853 undisplayed or displayed only 854 \nnegate --- flag when set to True undisplay the trace corresponding to 855 the current selection 856 \nonly --- flag when set to True the part of the trace geometry 857 corresponding to the current selection will be displayed 858 only. 859 """ 860 kw['only'] = only 861 kw['negate'] = negate 862 kw['traceName'] = traceName 863 kw['redraw'] = True 864 if type(nodes) is StringType: 865 self.nodeLogString = "'" + nodes +"'" 866 apply ( self.doitWrapper, (nodes,), kw )
867
868 -class CustomTraceCommand(MVCommand):
869 """This command computes and extrudes Trace 870 \nPackage : Pmv 871 \nModule : traceCommands 872 \nClass : CustomTraceCommand 873 \nCommand : customTrace 874 \nkeywords: custom trace 875 \nSynopsis:\n 876 None<---customTrace(nodes,traceName='CATrace',shape2D=None,frontCap=1, endCap=1,ctlAtmName='CA',torsAtmName='O',nbchords=4,display=1,**kw) 877 \nRequired Arguments:\n 878 nodes --- TreeNodeSet holding the current selection 879 \nOptional Arguments:\n: 880 traceName --- string representing the name of the computed trace. 881 default 'CATrace' 882 \nctlAtmName --- name of the atom to be used for control (defaul='CA') 883 \ntorsAtmName --- name of the atom to be used to control the torsion. 884 default='O' 885 \nnbchords --- number of points per residue. The higher the number the 886 smoother the trace will be. 887 \nshape2D --- instance of a DejaVu.Shape class describing the shape 2D 888 to be extruded along the path3D of the selected trace. 889 By default a Circle2D will be extruded 890 \nfrontCap --- when set to True a cap is added to all the front of the 891 extruded geometry created to represent the selected trace. 892 \nendCap --- when set to True a cap is added to all the end of the extruded 893 geometry representing the selected trace. 894 \ndisplay --- when set to True the displayTrace command is called. 895 """
896 - def __init__(self):
897 MVCommand.__init__(self) 898 self.flag = self.flag | self.objArgOnly 899 self.flag = self.flag | self.negateKw
900
901 - def onAddCmdToViewer(self):
902 if self.vf.hasGui and \ 903 not self.vf.commands.has_key('computeTrace'): 904 self.vf.loadCommand("traceCommands", 905 "computeTrace", "Pmv", 906 topCommand = 0) 907 if self.vf.hasGui and \ 908 not self.vf.commands.has_key('extrudeTrace'): 909 self.vf.loadCommand("traceCommands", 910 "extrudeTrace", "Pmv", 911 topCommand = 0) 912 if self.vf.hasGui and \ 913 not self.vf.commands.has_key('displayTrace'): 914 self.vf.loadCommand("traceCommands", 915 "displayTrace", "Pmv",topCommand = 0)
916 - def buildFormDescr(self, formName):
917 if formName == 'CustomTraceForm': 918 idf = InputFormDescr('Custom Trace') 919 idf.append({'name':'traceName', 920 'widgetType':Pmw.ComboBox, 921 'tooltip':'Create a new trace by typing a new trace \n\ 922 name in the entry of the combobox. \nHit the Enter key to add it to the list \ 923 of trace name. \nYou can also choose from the existing list of trace names.\n\ 924 To see the list click on the down arrow.', 925 'defaultValue':self.traceNames[0], 926 'wcfg':{'label_text':'Choose a trace: ', 927 'labelpos':'w', 928 'scrolledlist_items': self.traceNames, 929 }, 930 'gridcfg':{'sticky':'w','columnspan':2}}) 931 932 idf.append({'name':'ctlAtmName', 933 'widgetType':Pmw.EntryField, 934 'tooltip':'String representing the name of the atom \n\ 935 to be used as control atom. Specify only one atom name.', 936 'wcfg':{'label_text':'Control atom name:', 937 'labelpos':'w', 'entry_width':4, 938 'value':'CA'}, 939 'gridcfg':{'sticky':'w'}}) 940 941 idf.append({'name':'torsAtmName', 942 'widgetType':Pmw.EntryField, 943 'tooltip':'String representing the name of the atom \n\ 944 to be used to control the torsion. Specify only one atom name.', 945 'wcfg':{'label_text':'Torsion atom name:', 946 'labelpos':'w', 'entry_width':4, 947 'value':'O'}, 948 'gridcfg':{'sticky':'w'}}) 949 950 951 idf.append( {'name': 'nbchords', 952 'widgetType':ExtendedSliderWidget, 953 'type':int, 954 'tooltip':'Specifies the number of points per \ 955 residues.\n The higher the number the smoother the trace will be.', 956 'wcfg':{'label': 'nb points per residues', 957 'minval':4,'maxval':15, 958 'incr': 1, 'init':4, 959 'labelsCursorFormat':'%d', 960 'sliderType':'int' 961 }, 962 'gridcfg':{'sticky':'w', 'columnspan':2}, 963 }) 964 965 966 nbchordEntryVar = Tkinter.StringVar() 967 entries = ['circle','rectangle','ellipse', 'square','triangle'] 968 969 idf.append({'name':'shape', 970 'widgetType':Pmw.ComboBox, 971 'tooltip':'Choose a shape2D to be extruded.', 972 'defaultValue':entries[0], 973 'wcfg':{'label_text':'Choose a shape', 974 'labelpos':'w', 975 'scrolledlist_items':entries}, 976 'gridcfg':{'sticky':'w'} 977 }) 978 979 else: 980 initRadius = 0.1 981 radiusWidgetDescr = {'name': 'radius', 982 'widgetType':ExtendedSliderWidget, 983 'wcfg':{'label': 'Radius', 984 'minval':0.05,'maxval':3.0 , 985 'init':initRadius, 986 'labelsCursorFormat':'%1.2f', 987 'sliderType':'float', 988 'entrywcfg':{'width':4}, 989 'entrypackcfg':{'side':'right'}}, 990 'gridcfg':{'columnspan':2,'sticky':'we'} 991 } 992 initWidth = 1.2 993 widthWidgetDescr = {'name': 'width', 994 'widgetType':ExtendedSliderWidget, 995 'wcfg':{'label': 'Width', 996 'minval':0.05,'maxval':3.0 , 997 'init':initWidth, 998 'labelsCursorFormat':'%1.2f', 999 'sliderType':'float', 1000 'entrywcfg':{'width':4}, 1001 'entrypackcfg':{'side':'right'}}, 1002 'gridcfg':{'columnspan':2,'sticky':'we'} 1003 } 1004 initHeight = 0.2 1005 heightWidgetDescr = {'name': 'height', 1006 'widgetType':ExtendedSliderWidget, 1007 'wcfg':{'label': 'Height', 1008 'minval':0.05,'maxval':3.0 , 1009 'init':initHeight, 1010 'labelsCursorFormat':'%1.2f', 1011 'sliderType':'float' , 1012 'entrywcfg':{'width':4}, 1013 'entrypackcfg':{'side':'right'}}, 1014 'gridcfg':{'columnspan':2,'sticky':'we'} 1015 } 1016 initSide = 1.0 1017 sideWidgetDescr = {'name': 'sidelength', 1018 'widgetType':ExtendedSliderWidget, 1019 'wcfg':{'label': 'Length of side:', 1020 'minval':0.05,'maxval':3.0 , 1021 'init':initSide, 1022 'labelsCursorFormat':'%1.2f', 1023 'sliderType':'float', 1024 'entrywcfg':{'width':4}, 1025 'entrypackcfg':{'side':'right'}}, 1026 'gridcfg':{'columnspan':2,'sticky':'we'} 1027 } 1028 1029 frontCapWidgetDescr = {'name':'frontcap', 1030 'widgetType':Tkinter.Checkbutton, 1031 'tooltip':'when set to 1 a cap is added \nat the front', 1032 'defaultValue':1, 1033 'wcfg':{'text':'front cap', 1034 'variable': Tkinter.IntVar()}, 1035 'gridcfg':{'sticky':'we'}} 1036 endCapWidgetDescr = {'name':'endcap', 1037 'widgetType':Tkinter.Checkbutton, 1038 'defaultValue':1, 1039 'tooltip':"""when set to 1 a cap is added 1040 at the end""", 1041 'wcfg':{'text':'end cap ', 1042 'variable': Tkinter.IntVar()}, 1043 'gridcfg':{'sticky':'we','row':-1}} 1044 1045 1046 if formName == 'rectangle': 1047 idf = InputFormDescr(title ="Rectangle size :") 1048 idf.append(widthWidgetDescr) 1049 initHeight = 0.4 1050 idf.append(heightWidgetDescr) 1051 1052 elif formName == 'circle': 1053 idf = InputFormDescr(title="Circle size :") 1054 idf.append(radiusWidgetDescr) 1055 1056 elif formName == 'ellipse': 1057 idf = InputFormDescr(title="Ellipse size") 1058 idf.append( {'name': 'grand', 1059 'widgetType':ExtendedSliderWidget, 1060 'wcfg':{'label': 'demiGrandAxis', 1061 'minval':0.05,'maxval':3.0 , 1062 'init':0.5, 1063 'labelsCursorFormat':'%1.2f', 1064 'sliderType':'float', 1065 'entrywcfg':{'width':4}, 1066 'entrypackcfg':{'side':'right'}}, 1067 'gridcfg':{'columnspan':2,'sticky':'we'} 1068 }) 1069 idf.append( {'name': 'small', 1070 'widgetType':ExtendedSliderWidget, 1071 'wcfg':{'label': 'demiSmallAxis', 1072 'minval':0.05,'maxval':3.0 , 1073 'init':0.2, 1074 'labelsCursorFormat':'%1.2f', 1075 'sliderType':'float', 1076 'entrywcfg':{'width':4}, 1077 'entrypackcfg':{'side':'right'}}, 1078 'gridcfg':{'columnspan':2,'sticky':'we'} 1079 }) 1080 elif formName == 'square': 1081 idf = InputFormDescr(title="Square size :") 1082 idf.append(sideWidgetDescr) 1083 1084 elif formName == 'triangle': 1085 idf = InputFormDescr(title="Triangle size :") 1086 idf.append(sideWidgetDescr) 1087 1088 1089 # These widgets are present in everyInputForm. 1090 idf.append(frontCapWidgetDescr) 1091 idf.append(endCapWidgetDescr) 1092 return idf
1093 1094 1095
1096 - def guiCallback(self):
1097 self.traceNames = self.vf.extrudeTrace.getAvailableTrace() 1098 if not self.traceNames:self.traceNames = ['CATrace',] 1099 if self.cmdForms.has_key('CustomTraceForm'): 1100 form = self.cmdForms['CustomTraceForm'] 1101 combo = form.descr.entryByName['traceName']['widget'] 1102 if self.traceNames != combo.get(): 1103 combo.setlist(self.traceNames) 1104 1105 typeshape = self.showForm('CustomTraceForm') 1106 if not typeshape: return 1107 if len(typeshape['traceName']) == 0: 1108 return 1109 typeshape['traceName'] = typeshape['traceName'][0] 1110 if not typeshape['ctlAtmName'] or not typeshape['torsAtmName']: return 1111 typeshape['redraw']=0 1112 self.vf.computeTrace(self.vf.getSelection(),traceName=typeshape['traceName'],ctlAtmName=typeshape['ctlAtmName'],torsAtmName=typeshape['torsAtmName'],nbchords=typeshape['nbchords']) 1113 1114 from ViewerFramework.drawShape import DrawShape 1115 1116 # Shape is a Rectangle 1117 if typeshape['shape'][0]=='rectangle': 1118 val = self.showForm('rectangle') 1119 if val: 1120 shape2D = Rectangle2D(width = val['width'], 1121 height = val['height'], 1122 vertDup=1) 1123 frontCap, endCap = int(val['frontcap']),int(val['endcap']) 1124 1125 # Shape is a Circle: 1126 elif typeshape['shape'][0]=='circle': 1127 1128 val = self.showForm('circle') 1129 if val: 1130 shape2D = Circle2D(radius=val['radius']) 1131 frontCap, endCap = val['frontcap'],val['endcap'] 1132 1133 # Shape is an Ellipse 1134 elif typeshape['shape'][0]=='ellipse': 1135 val = self.showForm('ellipse') 1136 if val: 1137 shape2D = Ellipse2D(demiGrandAxis= val['grand'], 1138 demiSmallAxis=val['small']) 1139 frontCap, endCap = val['frontcap'],val['endcap'] 1140 1141 # Shape is a Square: 1142 elif typeshape['shape'][0]=='square': 1143 val = self.showForm('square') 1144 if val: 1145 shape2D = Square2D(side=val['sidelength'], vertDup=1) 1146 frontCap, endCap = val['frontcap'],val['endcap'] 1147 1148 # Shape is a Triangle: 1149 elif typeshape['shape'][0]=='triangle': 1150 val = self.showForm('triangle') 1151 if val: 1152 shape2D = Triangle2D(side=val['sidelength'], vertDup=1) 1153 frontCap, endCap = val['frontcap'], val['endcap'] 1154 1155 else: return 1156 1157 if val: 1158 self.vf.extrudeTrace(self.vf.getSelection(),traceName=typeshape['traceName'], 1159 shape2D=shape2D, 1160 frontCap=frontCap, endCap=endCap, 1161 redraw=0) 1162 else: return
1163
1164 - def __call__(self, nodes,traceName='CATrace',shape2D=None,frontCap=1, endCap=1,ctlAtmName='CA',torsAtmName='O',nbchords=4,display=1,**kw):
1165 """None<---customTrace(nodes,traceName='CATrace',shape2D=None,frontCap=1, endCap=1,ctlAtmName='CA',torsAtmName='O',nbchords=4,display=1,**kw) 1166 \nRequired Arguments:\n 1167 nodes --- TreeNodeSet holding the current selection 1168 \nOptional Arguments:\n 1169 traceName --- string representing the name of the computed trace. 1170 default 'CATrace' 1171 \nctlAtmName --- name of the atom to be used for control (defaul='CA') 1172 \ntorsAtmName --- name of the atom to be used to control the torsion. 1173 default='O' 1174 \nnbchords --- number of points per residue. The higher the number the 1175 smoother the trace will be. 1176 \nshape2D --- instance of a DejaVu.Shape class describing the shape 2D 1177 to be extruded along the path3D of the selected trace. 1178 By default a Circle2D will be extruded 1179 \nfrontCap --- when set to True a cap is added to all the front of the 1180 extruded geometry created to represent the selected trace. 1181 \nendCap --- when set to True a cap is added to all the end of the extruded 1182 geometry representing the selected trace. 1183 \ndisplay --- when set to True the displayTrace command is called. 1184 """ 1185 nodes = self.vf.expandNodes(nodes) 1186 if not nodes: 1187 return "ERROR" 1188 kw['traceName']=traceName 1189 kw['ctlAtmName']=ctlAtmName 1190 kw['torsAtmName']=torsAtmName 1191 kw['nbchords']=nbchords 1192 kw['frontCap']=frontCap 1193 kw['endCap']=endCap 1194 kw['display']=display 1195 kw['shape2D']=shape2D 1196 if type(nodes) is StringType: 1197 self.nodeLogString = "'" + nodes +"'" 1198 apply(self.doitWrapper, (nodes,), kw)
1199
1200 - def doit(self, nodes,**kw):
1201 nkw={} 1202 if kw!={}: 1203 if kw['display']==0: 1204 nkw['negate']=1 1205 apply(self.vf.displayTrace,(nodes,),nkw) 1206 return 1207 1208 elif kw['display']==1: 1209 if kw.has_key('negate'): 1210 if kw['negate']==1: 1211 nkw['negate']=1 1212 apply(self.vf.displayTrace,(nodes,),nkw) 1213 return 1214 self.vf.computeTrace(nodes,traceName=kw['traceName'],ctlAtmName=kw['ctlAtmName'],torsAtmName=kw['torsAtmName'],nbchords=kw['nbchords']) 1215 self.vf.extrudeTrace(nodes,traceName=kw['traceName'],shape2D=kw['shape2D'],frontCap=kw['frontCap'], endCap=kw['endCap'],display = kw['display']) 1216 1217
1218 -class ComputeExtrudeTraceCommand(MVCommand):
1219 """This command computes and Extrudes Trace with default arguements 1220 \nPackage : Pmv 1221 \nModule : traceCommands 1222 \nClass : ComputeExtrudeTraceCommand 1223 \nCommand : computeExtrudeTrace 1224 \nkeywords: computeExtrude trace 1225 \nSynopsis:\n 1226 None<---computeExtrudeTrace(nodes, only=False, negate=False, **kw) 1227 \nRequired Arguments:\n 1228 nodes --- TreeNodeSet holding the current selection 1229 \nOptional Arguments:\n 1230 only --- flag when set to 1 only the current selection 1231 will be displayed 1232 \nnegate --- flag when set to 1 undisplay the current selection 1233 """
1234 - def __init__(self):
1235 MVCommand.__init__(self) 1236 self.flag = self.flag | self.objArgOnly 1237 self.flag = self.flag | self.negateKw
1238 1239 1240
1241 - def onAddCmdToViewer(self):
1242 if self.vf.hasGui and \ 1243 not self.vf.commands.has_key('computeTrace'): 1244 self.vf.loadCommand("traceCommands", 1245 "computeTrace", "Pmv", 1246 topCommand = 0) 1247 if self.vf.hasGui and \ 1248 not self.vf.commands.has_key('extrudeTrace'): 1249 self.vf.loadCommand("traceCommands", 1250 "extrudeTrace", "Pmv", 1251 topCommand = 0) 1252 if self.vf.hasGui and \ 1253 not self.vf.commands.has_key('displayTrace'): 1254 self.vf.loadCommand("traceCommands", 1255 "displayTrace", "Pmv", 1256 topCommand = 0)
1257
1258 - def __call__(self, nodes, only=False, negate=False,**kw):
1259 """None <- computeExtrudeTrace(nodes, only=False, negate=False, **kw) 1260 \nRequired Arguments:\n 1261 nodes --- TreeNodeSet holding the current selection 1262 \nOptional Arguments:\n 1263 only --- flag when set to 1 only the current selection 1264 will be displayed 1265 \nnegate --- flag when set to 1 undisplay the current selection 1266 """ 1267 if type(nodes) is types.StringType: 1268 self.nodeLogString = "'"+nodes+"'" 1269 1270 if not kw.has_key('redraw'): kw['redraw']=1 1271 nodes = self.vf.expandNodes(nodes) 1272 if not nodes: return "ERROR" 1273 kw['only']=only 1274 kw['negate']=negate 1275 apply(self.doitWrapper, (nodes,), kw)
1276
1277 - def doit(self, nodes, **kw):
1278 if kw!={}: 1279 if kw['negate']==1: 1280 apply(self.vf.displayTrace,(nodes,), kw) 1281 return 1282 apply(self.vf.computeTrace,(nodes,), {'topCommand':False}) 1283 kw['topCommand'] = 0 1284 apply(self.vf.extrudeTrace,(nodes,),{})
1285 1286 1287 1288 1289 computeTraceGuiDescr = {'widgetType':'Menu', 'menuBarName':'Compute', 1290 'menuButtonName':'Compute CA Trace', 1291 'separatorAbove':1} 1292 1293 ComputeTraceGUI = CommandGUI() 1294 ComputeTraceGUI.addMenuCommand('menuRoot', 'Compute', 'Compute Trace', 1295 cascadeName = 'Trace') 1296 1297 extrudeTraceGuiDescr = {'widgetType':'Menu', 'menuBarName':'menuRoot', 1298 'menuButtonName':'Compute', 1299 'menuEntryLabel':'Extrude Trace'} 1300 1301 ExtrudeTraceGUI = CommandGUI() 1302 ExtrudeTraceGUI.addMenuCommand('menuRoot', 'Compute', 'Extrude Trace', 1303 cascadeName = 'Trace') 1304 1305 computeExtrudeTraceGuiDescr = {'widgetType':'Menu', 'menuBarName':'menuRoot', 1306 'menuButtonName':'ComputeExtrude CA Trace', 1307 'menuEntryLabel':'ComputeExtrude Trace'} 1308 ComputeExtrudeTraceGUI = CommandGUI() 1309 ComputeExtrudeTraceGUI.addMenuCommand('menuRoot','Compute','ComputeExtrude Trace',cascadeName ='Trace') 1310 1311 customTraceGuiDescr = {'widgetType':'Menu', 'menuBarName':'menuRoot', 1312 'menuButtonName':'Custom CA Trace', 1313 'menuEntryLabel':'Custom Trace'} 1314 CustomTraceGUI = CommandGUI() 1315 CustomTraceGUI.addMenuCommand('menuRoot','Compute','Custom Trace',cascadeName ='Trace') 1316 1317 displayTraceGuiDescr = {'widgetType':'Menu', 'menuBarName':'menuRoot', 1318 'menuButtonName':'Display', 1319 'menuEntryLabel':'Display Trace'} 1320 1321 DisplayTraceGUI = CommandGUI() 1322 DisplayTraceGUI.addMenuCommand('menuRoot', 'Display','Trace') 1323 1324 1325 1326 commandList = [ 1327 {'name': 'computeTrace','cmd':ComputeTraceCommand(), 1328 'gui':ComputeTraceGUI}, 1329 {'name': 'extrudeTrace','cmd': ExtrudeTraceCommand(), 1330 'gui':ExtrudeTraceGUI}, 1331 {'name': 'displayTrace', 'cmd': DisplayTraceCommand(), 1332 'gui':DisplayTraceGUI}, 1333 {'name': 'computeExtrudeTrace', 'cmd': ComputeExtrudeTraceCommand(), 1334 'gui':ComputeExtrudeTraceGUI}, 1335 {'name': 'customTrace', 'cmd': CustomTraceCommand(), 1336 'gui':CustomTraceGUI} 1337 ] 1338
1339 -def initModule(viewer):
1340 """ initializes commands for secondary structure and extrusion. Also 1341 imports the commands for Secondary Structure specific coloring, and 1342 initializes these commands also. """ 1343 1344 for dict in commandList: 1345 viewer.addCommand(dict['cmd'], dict['name'], dict['gui'])
1346