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

Source Code for Module Pmv.splineCommands

   1  ############################################################################# 
   2  # 
   3  # Author: Sophie COON, Michel F. SANNER 
   4  # 
   5  # Copyright: M. Sanner TSRI 2000 
   6  # 
   7  ############################################################################# 
   8   
   9  # 
  10  #$Header: /opt/cvs/python/packages/share1.5/Pmv/splineCommands.py,v 1.49 2006/04/07 23:53:45 sanner Exp $ 
  11  # 
  12  #$Id: splineCommands.py,v 1.49 2006/04/07 23:53:45 sanner Exp $ 
  13  # 
  14  # 
  15   
  16  from MolKit.molecule import Atom,AtomSet 
  17  from MolKit.protein import Protein,Residue, Chain, ProteinSet 
  18  from MolKit.tree import TreeNode, TreeNodeSet 
  19  from MolKit.stringSelector import StringSelector 
  20   
  21  from DejaVu.Polylines import Polylines 
  22  from DejaVu.IndexedPolylines import IndexedPolylines 
  23  from DejaVu.spline import DialASpline 
  24  from DejaVu.GleObjects import GleExtrude, GleObject 
  25  from DejaVu.Points import Points 
  26  from DejaVu.Geom import Geom 
  27  from DejaVu.spline import SplineObject 
  28  from DejaVu.Shapes import Shape2D, Triangle2D, Circle2D, Rectangle2D,\ 
  29       Square2D, Ellipse2D 
  30   
  31   
  32   
  33  from Pmv.mvCommand import MVCommand 
  34  #from Pmv.selectionCommands import MVStringSelector 
  35  from Pmv.displayCommands import DisplayCommand 
  36   
  37  from ViewerFramework.VFCommand import CommandGUI 
  38  ##  from ViewerFramework.gui import InputFormDescr 
  39  from mglutil.gui.InputForm.Tk.gui import InputFormDescr 
  40   
  41  from mglutil.gui.BasicWidgets.Tk.customizedWidgets import ListChooser, \ 
  42       ExtendedSliderWidget 
  43  from mglutil.gui.BasicWidgets.Tk.thumbwheel import ThumbWheel 
  44  import Tkinter, Pmw, string, Numeric,types 
  45   
46 -class ComputeSplineCommand(MVCommand):
47 """The CompueSplineCommand omplements a set of method to create an DejaVu.splineObject per chain given:a TreeNodeSet,type of control Atoms (atmtype),number of points per control point in the smooth array (nbchords),continuity of the curves (continuity). 48 \nPackage : Pmv 49 \nModule : splineCommands 50 \nClass : ComputeSplineCommand 51 \nCommand : computeSpline 52 \nkeywords: compute spline 53 \nSynopsis:\nNone <- computeSpline(nodes, atmtype='CA', nbchords=4, 54 interp='interpolation' 55 continuity=2, closedSpline=0, **kw) 56 \nRequired Arguments:\n 57 nodes --- self.getSelection() 58 \nOptional Arguments:\n 59 \natmtype --- specifies the atom type of the control points. 60 the atoms of the current selection of the given 61 atom type are used as the control points. 62 atmtype can be 'CA'(default value) 'CA,N' 'O' etc.... 63 64 \ncurSel --- Boolean flag to use the atoms in current selection as control 65 points. (default=False) 66 \nnbchords --- number of point per control points in the smooth array 67 \ninterp --- flag if set to 'interpolation' interpolate the control 68 points. 69 \ncontinuity --- specifies the continuity of the curve. 70 \nclosedSpline --- Boolean flag when set to True the spline will be closed (1st atom will be connected to the last atom. (default = False) 71 \nsortAtms --- Boolean flag to sort the ctlAtms or not. (default = True) 72 """
73 - def __init__(self, func=None):
74 MVCommand.__init__(self, func=func) 75 self.flag = self.flag | self.objArgOnly
76
77 - def onRemoveObjectFromViewer(self, obj):
78 # check if the memory is freed 79 for c in obj.chains: 80 if hasattr(c, 'spline'): 81 delattr(c,'spline') 82 else: 83 continue
84 85
86 - def doit(self, nodes, atmtype="", curSel=False, nbchords=4, 87 interp='interpolation', continuity=2, 88 closedSpline=False, sortAtms = True):
89 molecules, atomSets = self.vf.getNodesByMolecule(nodes, Atom) 90 # Build the query that will be passed to MVStringSelector. 91 # args ["molname","chainname", "residuename", "atomname"] 92 #args = ["","","",""] 93 # Build string that will be passed to 94 # MolKit.stringSelector.StringSelector 95 args = ":::" 96 # get the CtlPoints for all the molecules loaded in the 97 if not curSel and atmtype: 98 #args[3] = atmtype 99 args = args + atmtype 100 # get the CtlPoints of all the molecules 101 #stringAtms = MVStringSelector(self.vf, molecules, args).go() 102 stringAtms = StringSelector().select(molecules, args) 103 # No atoms found. 104 if stringAtms is None or stringAtms[0] is None or len(stringAtms)==0: 105 return 106 107 elif not curSel and not atmtype: 108 # curSel checkbutton not selected but not atomtype given 109 return 110 111 112 for mol, atoms in map(None, molecules, atomSets): 113 # Get a handle on the molecule geomContainer. 114 geomC = mol.geomContainer 115 # chainsInSel is the ChainSet of the chain having at least one 116 # node in the current selection 117 chainsInSel = atoms.findType(Chain).uniq() 118 # Loop over the chains in the current selection. 119 for chain in chainsInSel: 120 atmsInChain = chain.findType(Atom).inter(atoms) 121 if curSel == 1: 122 # Only computing the spline per chain. 123 atms = atmsInChain 124 125 else: 126 # get the CtlPoints in the selection. 127 atms = stringAtms[0].inter(atmsInChain) 128 129 # Compute the Spline Object. 130 if not atms or not len(atms)>3: 131 # needs to have more than 3 atms to compute a spline. 132 # Could be changed 133 chain.spline = None 134 else: 135 136 # 1- sort the atoms. 137 if sortAtms: 138 atms.sort() 139 140 # 2- get there coordinates 141 atmCoords = atms.coords 142 143 # 3- Create a DejaVu SplineObject. 144 splineName = 'spline' + chain.id 145 splineObject = SplineObject(atmCoords, name=splineName, 146 nbchords=nbchords, 147 interp=interp, 148 continuity=continuity, 149 closed=closedSpline) 150 151 if not hasattr(chain, 'spline') \ 152 or not chain.spline is None: 153 chain.spline = {splineName:(splineObject, atms)} 154 else: 155 chain.spline[splineName] = (splineObject, atms)
156 157 158
159 - def __call__(self, nodes, atmtype="CA", curSel=False, nbchords=4, 160 interp='interpolation', continuity=2, closedSpline=False, 161 sortAtms=True, **kw):
162 """None <- computeSpline(nodes, atmtype='CA', nbchords=4, 163 interp='interpolation' 164 continuity=2, closedSpline=0, **kw) 165 \nRequired Arguments:\n 166 nodes --- self.getSelection() 167 \nOptional Arguments:\n 168 atmtype --- specifies the atom type of the control points. 169 the atoms of the current selection of the given 170 atom type are used as the control points. 171 atmtype can be 'CA'(default value) 'CA,N' 'O' etc.... 172 173 \ncurSel --- Boolean flag to use the atoms in current selection as control 174 points. (default=False) 175 \nnbchords --- number of point per control points in the smooth array 176 \ninterp --- flag if set to 'interpolation' interpolate the control 177 points. 178 \ncontinuity --- specifies the continuity of the curve. 179 \nclosedSpline --- Boolean flag when set to True the spline will be closed (1st atom will be connected to the last atom. (default = False) 180 \nsortAtms --- Boolean flag to sort the ctlAtms or not. (default = True) 181 182 """ 183 kw['redraw'] = 0 184 kw['nbchords'] = nbchords 185 kw['interp'] = interp 186 kw['continuity'] = continuity 187 kw['atmtype'] = atmtype 188 kw['curSel'] = curSel 189 kw['closedSpline'] = closedSpline 190 if type(nodes) is types.StringType: 191 self.nodeLogString = "'" + nodes +"'" 192 expnodes = self.vf.expandNodes(nodes) 193 if len(expnodes)==0: return 194 apply(self.doitWrapper, (expnodes, ), kw)
195 196 197
198 -class ComputeSplineGUICommand(MVCommand):
199 """ The ComputeSplineGUICommand provides a GUI to the user and calls computeSplineCommand to compute the splineObject. This class also implement a createGeometries method to create the geometrie to represent the splineObject here a IndexedPolylines. 200 \nPackage : Pmv 201 \nModule : splineCommands 202 \nClass : ComputeSplineGUICommand 203 \nCommand : computeSplineGC 204 \nSynopsis:\nNone <- computeSpline(nodes,atmtype='CA',nbchords=4,interp='interpolation',continuity=2,closedSpline=0, **kw) 205 \nRequired Arguments:\n 206 nodes --- self.getSelection() 207 \nOptional Arguments:\n 208 \natmtype --- specifies the atom type of the control points. 209 the atoms of the current selection of the given 210 atom type are used as the control points. 211 atmtype can be 'CA'(default value) 'CA,N' 'O' etc.... 212 213 \ncurSel --- Boolean flag to use the atoms in current selection as control 214 points. (default=False) 215 \nnbchords --- number of point per control points in the smooth array 216 \ninterp --- flag if set to 'interpolation' interpolate the control 217 points. 218 \ncontinuity --- specifies the continuity of the curve. 219 \nclosedSpline --- Boolean flag when set to True the spline will be closed (1st atom will be connected to the last atom. (default = False) 220 \nsortAtms --- Boolean flag to sort the ctlAtms or not. (default = True) 221 222 """ 223
224 - def __init__(self, func=None):
225 MVCommand.__init__(self, func=func) 226 self.flag = self.flag | self.objArgOnly
227
228 - def onAddCmdToViewer(self):
229 if not self.vf.commands.has_key('computeSpline'): 230 self.vf.loadCommand("splineCommands", 'computeSpline', 231 "Pmv", topCommand = 0) 232 if self.vf .hasGui and \ 233 not self.vf.commands.has_key('displaySplineAsLine'): 234 self.vf.loadCommand("splineCommands",'displaySplineAsLine','Pmv', 235 topCommand = 0)
236 237
238 - def cursel_cb(self, event = None):
239 """ if the use curSel checkbutton is on: the entryFiedl should be 240 disabled.""" 241 if self.cmdForms.has_key('spline'): 242 idf = self.cmdForms['spline'].descr 243 cbVar =idf.entryByName['curSel']['wcfg']['variable'] 244 entry = idf.entryByName['atmtype']['widget'] 245 246 if cbVar.get() == 1: 247 entry._entryFieldEntry.configure(state = Tkinter.DISABLED) 248 entry.configure(label_fg = 'darkgray') 249 250 else: 251 entry._entryFieldEntry.configure(state = Tkinter.NORMAL) 252 entry.configure(label_fg = 'black')
253 254
255 - def buildFormDescr(self, formName):
256 if formName == 'spline': 257 idf = InputFormDescr(title="Compute Spline:") 258 nbchordEntryVar = Tkinter.StringVar() 259 idf.append({'name':'curSel', 260 'widgetType':Tkinter.Checkbutton, 261 'defaultValue':0, 262 'wcfg':{'text':'Current Selection', 263 'variable':Tkinter.IntVar(), 264 'command':self.cursel_cb}, 265 'gridcfg':{'sticky':'we'}}) 266 267 # ? maybe a list of checkbox Entryfield to choose the atomType. 268 idf.append({'widgetType':Pmw.EntryField, 269 'name':'atmtype', 270 'wcfg':{'labelpos':'w', 271 'label_text':'Enter atom types: ', 272 'validate':None, 273 }, 274 'gridcfg':{'sticky':'we','row':-1}}) 275 276 # number of points per residue 277 idf.append( {'name': 'nbchords', 278 'widgetType':ExtendedSliderWidget, 279 'type':int, 280 'wcfg':{'label': 'nb. Pts Per Residue: ', 281 'minval':4,'maxval':15, 'incr': 1, 'init':4, 282 'labelsCursorFormat':'%d', 'sliderType':'int', 283 'entrywcfg':{'textvariable':nbchordEntryVar, 284 'width':4}, 285 'entrypackcfg':{'side':'right'}}, 286 'gridcfg':{'sticky':'we'} 287 }) 288 # Continuity 289 idf.append( {'name': 'continuity', 290 'widgetType':ExtendedSliderWidget, 291 'type':int, 292 'wcfg':{'label': 'Continuity', 293 'minval':0,'maxval':5, 'incr': 1, 'init':2, 294 'labelsCursorFormat':'%d', 'sliderType':'int', 295 'entrywcfg':{'width':4}, 296 'entrypackcfg':{'side':'right'}}, 297 'gridcfg':{'sticky':'we', 'row':-1} 298 }) 299 300 idf.append({'name':'closedSpline', 301 'widgetType':Tkinter.Checkbutton, 302 'defaultValue':0, 303 'wcfg':{'text':'Closed Spline ', 304 'variable':Tkinter.IntVar()}, 305 'gridcfg':{'sticky':'we'}}) 306 307 idf.append({'name':'sortAtms', 308 'widgetType':Tkinter.Checkbutton, 309 'defaultValue':1, 310 'wcfg':{'text':'Sort control Atoms', 311 'variable':Tkinter.IntVar()}, 312 'gridcfg':{'sticky':'we', 'row':-1}}) 313 314 ## idf.append({'name': 'interp', 315 ## 'widgetType':Pmw.RadioSelect, 316 ## 'defaultValue':'interpolation', 317 ## 'listtext':['interpolation'],#,'approximation'], 318 ## 'wcfg':{'orient':'horizontal', 319 ## 'buttontype':'radiobutton'}, 320 ## 'gridcgf':{'columnspan':2,'sticky':'w'} 321 ## }) 322 323 return idf
324
325 - def guiCallback(self):
326 327 nodes = self.vf.getSelection() 328 if not nodes: return 329 val = self.showForm('spline') 330 if val: 331 if val['curSel']==0 and \ 332 (val['atmtype']=='' or val['atmtype']== ' '): 333 # if no atmtype given and not cursel checked nothing 334 # happens 335 return 336 337 val['redraw']=0 338 apply(self.doitWrapper, (nodes,), val)
339 340
341 - def doit(self,nodes, atmtype="", curSel=False, nbchords=4, 342 interp='interpolation', continuity=2, 343 closedSpline=False, sortAtms=True):
344 345 self.vf.computeSpline(nodes, atmtype=atmtype, curSel=curSel, 346 nbchords=nbchords,interp= interp, 347 continuity=continuity, 348 closedSpline=closedSpline, sortAtms= sortAtms, 349 topCommand=0)
350
351 - def __call__(self,nodes, atmtype="CA",curSel=False, nbchords=4, 352 interp='interpolation', continuity=2, closedSpline=False, 353 sortAtms=True, **kw):
354 """None <- computeSpline(nodes,atmtype,nbchords=4,interp='interpolation',continuity=2,closedSpline=False,**kw) 355 \nRequired Arguments:\n 356 nodes --- self.getSelection() 357 \nOptional Arguments:\n 358 \natmtype --- specifies the atom type of the control points. 359 the atoms of the current selection of the given 360 atom type are used as the control points. 361 atmtype can be 'CA'(default value) 'CA,N' 'O' etc.... 362 363 \ncurSel --- Boolean flag to use the atoms in current selection as control 364 points. (default=False) 365 \nnbchords --- number of point per control points in the smooth array 366 \ninterp --- flag if set to 'interpolation' interpolate the control 367 points. 368 \ncontinuity --- specifies the continuity of the curve. 369 \nclosedSpline --- Boolean flag when set to True the spline will be closed (1st atom will be connected to the last atom. (default = False) 370 \nsortAtms --- Boolean flag to sort the ctlAtms or not. (default = True) 371 """ 372 kw['redraw'] = 0 373 kw['nbchords'] = nbchords 374 kw['interp'] = interp 375 kw['continuity'] = continuity 376 kw['atmtype'] = atmtype 377 kw['curSel'] = curSel 378 kw['closedSpline'] = closedSpline 379 if type(nodes) is types.StringType: 380 self.nodeLogString = "'" + nodes +"'" 381 nodes = self.vf.expandNodes(nodes) 382 if len(nodes)==0: return 383 apply(self.doitWrapper, (nodes, ), kw)
384 385
386 -class ExtrudeSplineCommand(MVCommand):
387 """ 388 The extrudeSplineCommand implements a set of method to create the 389 extrude Geometries DejaVu.GleExtrude resulting of the extrusion of a 390 shape2D along a path3D computed by the DejaVu.SplineObject using the GLE 391 library. 392 \nPackage : Pmv 393 \nModule : splineCommands 394 \nClass : ExtrudeSplineCommand 395 \nCommand : extrudeSpline 396 \nkeywords: extrude spline 397 \nSynopsis:\nNone <- extrudeSpline(nodes, shape2D=None, display=True, **kw) 398 \nRequired Arguments:\n 399 nodes --- treeNodeSet holding the current selection, or string 400 representing a treeNodeSet. 401 \nOptional Arguments:\n 402 shape2D --- instance of a DejaVu.Shapes class (Triangle2DDup, Circle2D...)the default shape is a circle2D 403 \ncapsFlag --- Boolean flag to add caps at the end of the spline (default=False) 404 \ndisplay --- Boolean flag to call or not the displayExtrudedSpline command default value is True. 405 """
406 - def __init__(self, func=None):
407 MVCommand.__init__(self, func=func) 408 self.flag = self.flag | self.objArgOnly
409
410 - def onRemoveObjectFromViewer(self, obj):
411 gc = obj.geomContainer 412 for c in obj.chains: 413 splineName = 'spline'+c.id 414 if gc.geoms.has_key(splineName): 415 g = gc.geoms[splineName] 416 if hasattr(g, 'spline'): 417 delattr(g,'spline')
418
419 - def onAddCmdToViewer(self):
420 if self.vf.hasGui and not self.vf.commands.has_key('computeSplineGC'): 421 self.vf.loadCommand("splineCommands", 'computeSplineGC', 422 "Pmv", topCommand = 0) 423 424 if self.vf.hasGui and \ 425 not self.vf.commands.has_key('displayExtrudedSpline'): 426 self.vf.loadCommand("splineCommands", 'displayExtrudedSpline', 427 'Pmv', topCommand = 0)
428
429 - def createGeometries(self, chain):
430 """Method to create the extrude geometry""" 431 geomC = chain.parent.geomContainer 432 if not hasattr(chain, 'spline') or chain.spline is None: 433 return 434 name = "spline"+chain.id 435 if geomC.geoms.has_key(name) and geomC.atoms.has_key(name): 436 g = geomC.geoms[name] 437 if g.spline == chain.spline['spline'+chain.id]: 438 return 439 else: 440 geomC.VIEWER.RemoveObject(g) 441 del geomC.geoms[name] 442 443 g = GleExtrude(name=name, visible=0) 444 445 446 geomC.geomPickToAtoms[name] = self.pickedVerticesToAtoms 447 geomC.atomPropToVertices[name] = self.atomPropToVertices 448 geomC.geomPickToBonds[name] = None 449 geomC.addGeom(g, parent=geomC.masterGeom, redo=0) 450 self.managedGeometries.append(g) 451 #geomC.VIEWER.AddObject( g, parent = geomC.masterGeom, 452 #replace=True, redo=0) 453 for atm in chain.findType(Atom): 454 atm.colors[name] = (1.0, 1.0, 1.0) 455 atm.opacities[name] = 1.0
456 457
458 - def pickedVerticesToAtoms(self, geom, vertInd):
459 """Function called to convert a picked vertex into an atom""" 460 # Need to change this if there is a cap or not ! 461 # this function gets called when a picking or drag select event has 462 # happened. It gets called with a geometry and the list of vertex 463 # indices of that geometry that have been selected. 464 # This function is in charge of turning these indices into an AtomSet 465 lshape = self.shape.lenShape 466 pickedAtms = AtomSet() 467 nbchords = geom.spline[0].nbchords 468 lastVertices = geom.spline[2].index(geom.spline[2][-1]) 469 closed = geom.spline[0].closed 470 for v in vertInd: 471 # 1- needs to know what is the corresponding index of the picked 472 # vertex in the path3D 473 splinePts = v/(2*lshape) 474 # 2- need to convert that index into an atom indices in the 475 # set of 476 # atoms used as control points to compute the spline. 477 if closed == 0: 478 if splinePts>=nbchords/2 and \ 479 splinePts <(lastVertices)*nbchords - nbchords/2: 480 # normal points 481 atmIndex = (splinePts-nbchords/2)/nbchords + 1 482 483 484 elif splinePts<nbchords/2: 485 atmIndex = 0 486 487 elif splinePts >= (lastVertices)*nbchords - nbchords/2: 488 atmIndex = -1 489 490 elif closed == 1: 491 492 lastIndex = (lastVertices)*nbchords - nbchords/2 493 if splinePts>=nbchords/2 and \ 494 splinePts <lastIndex: 495 # normal points 496 atmIndex = (splinePts-nbchords/2)/nbchords + 1 497 498 elif splinePts >= lastIndex and \ 499 splinePts < lastIndex + nbchords: 500 atmIndex = -1 501 502 elif splinePts<nbchords/2 or \ 503 splinePts >= lastIndex + nbchords: 504 atmIndex = 0 505 506 507 # atoms used as control points to compute the spline. 508 atm = geom.spline[1][atmIndex] 509 pickedAtms.append(atm) 510 511 # 3- need to return the corresponding atomset. 512 return pickedAtms
513
514 - def atomPropToVertices(self, geom, atoms, propName, propIndex = None):
515 propVect = [] 516 ctlAtms = geom.spline[2] 517 closed = geom.spline[0].closed 518 atoms.sort() 519 for a in atoms: 520 if closed == 0: 521 if a==ctlAtms[0] or a == ctlAtms[-1]: 522 if geom.capsFlag == 1: 523 nbchords = geom.spline[0].nbchords/2 + 1 524 else: 525 nbchords = geom.spline[0].nbchords/2 526 527 else: 528 nbchords = geom.spline[0].nbchords 529 else: 530 nbchords = geom.spline[0].nbchords 531 532 prop = getattr(a, propName) 533 534 if not propIndex is None: 535 prop = prop[propIndex] 536 for n in range(nbchords): 537 propVect.append(prop) 538 return(propVect)
539 540
541 - def __call__(self, nodes, shape2D=None, capsFlag=False, display=True, **kw):
542 """None <- extrudeSpline(nodes, shape2D=None, display=True, **kw) 543 \nRequired Arguments:\n 544 nodes --- treeNodeSet holding the current selection, or string 545 representing a treeNodeSet. 546 \nOptional Arguments:\n 547 shape2D --- instance of a DejaVu.Shapes class (Triangle2DDup, Circle2D...)the default shape is a circle2D 548 \ncapsFlag --- Boolean flag to add caps at the end of the spline (default=False) 549 \ndisplay --- Boolean flag to call or not the displayExtrudedSpline command default value is True. 550 """ 551 if type(nodes) is types.StringType: 552 self.nodeLogString = "'"+nodes+"'" 553 554 nodes = self.vf.expandNodes(nodes) 555 kw['shape2D'] = shape2D 556 kw['display'] = display 557 kw['capsFlag']=capsFlag 558 apply(self.doitWrapper, (nodes,), kw)
559 560
561 - def doit(self, nodes, shape2D=None, capsFlag=False, display=True):
562 if shape2D is None: 563 shape2D = Circle2D(radius=0.1, firstDup=1) 564 molecules, atomsSet = self.vf.getNodesByMolecule(nodes, Atom) 565 self.shape = shape2D 566 for mol, atoms in map(None, molecules, atomsSet): 567 #self.createGeometries(mol) 568 chains = atoms.findType(Chain).uniq() 569 gc = mol.geomContainer 570 for chain in chains: 571 if not hasattr(chain, 'spline'): 572 # should call the guiCallback of compute Spline. 573 print 'cannot do the extrusion the spline has not been computed for %s '%chain.full_name() 574 continue 575 576 if chain.spline is None: 577 print "the %s chain has no spline"%chain.full_name() 578 continue 579 self.createGeometries(chain) 580 atmInSel = atoms.inter(chain.findType(Atom)) 581 ctlAtms = chain.spline['spline'+chain.id][1] 582 ctlAtmsInSel = ctlAtms.inter(atmInSel) 583 ctlAtmsInSel.sort() 584 # here later you could let the user choose the spline 585 # he wishes to extrude. 586 name = 'spline'+chain.id 587 smooth = chain.spline[name][0].smooth 588 #atms = chain.spline[name][1] 589 pts_smooth = Numeric.array((smooth),'f') 590 #gc.atoms[name] = AtomSet() 591 g = gc.geoms[name] 592 contpts = Numeric.array(shape2D.contpts) 593 contourPoints = contpts[:,:2] 594 contnorm = Numeric.array(shape2D.contnorm) 595 contourNormals = contnorm[:,:2] 596 g.Set(trace3D = pts_smooth, 597 shape2D = self.shape, 598 contourUp = (0.,0.,1.), 599 capsFlag = capsFlag, tagModified=False) 600 # add an attribute shape2D to the gleExtrude geometry to 601 # have knowledge on the shape extruded 602 g.shape2D = self.shape 603 g.spline = (chain.spline[name][0], ctlAtmsInSel, ctlAtms) 604 605 if display: 606 self.vf.displayExtrudedSpline(nodes, negate=0, setupUndo=1, 607 topCommand=0)
608
609 - def buildFormDescr(self, formName):
610 if formName == 'geomChooser': 611 # Build the imputForm letting the user to choose the shape to 612 # be extruded 613 nbchordEntryVar = Tkinter.StringVar() 614 idf = InputFormDescr(title ="Choose a shape :") 615 616 entries = [('rectangle',None), 617 ('circle',None), ('ellipse',None), 618 ('square',None),('triangle',None), 619 #('other', None) 620 ] 621 622 idf.append({'name':'shape', 623 'widgetType':ListChooser, 624 'defaultValue':'circle', 625 'wcfg':{'entries': entries, 626 'title':'Choose a shape'} 627 }) 628 629 else: 630 # Create the description of the inputForm letting the user 631 # modify the parameter describing the shape to be extruded. 632 initRadius = 0.1 633 radiusWidgetDescr = ({'name':'radius', 634 'widgetType':ThumbWheel, 635 'wcfg':{ 'labCfg':{'text':'Radius:', 636 'font':('Helvetica',12,'bold')}, 637 'showLabel':1, 'width':100, 638 'min':0.05, 'max':10.0, 639 'type':float, 'precision':2, 640 'value':initRadius, 641 'continuous':1, 642 'oneTurn':2, 'wheelPad':2, 643 'height':20}, 644 'gridcfg':{'columnspan':2,'sticky':'we'}}) 645 initWidth = 1.2 646 widthWidgetDescr = ({'name':'width', 647 'widgetType':ThumbWheel, 648 'wcfg':{ 'labCfg':{'text':'Width:', 649 'font':('Helvetica',12,'bold')}, 650 'showLabel':1, 'width':100, 651 'min':0.05, 'max':10.0, 652 'type':float, 'precision':2, 653 'value':initWidth, 654 'continuous':1, 655 'oneTurn':2, 'wheelPad':2, 656 'height':20}, 657 'gridcfg':{'columnspan':2,'sticky':'we'}}) 658 initHeight = 0.2 659 heightWidgetDescr = ({'name':'height', 660 'widgetType':ThumbWheel, 661 'wcfg':{ 'labCfg':{'text':'Height:', 662 'font':('Helvetica',12,'bold')}, 663 'showLabel':1, 'width':100, 664 'min':0.05, 'max':10.0, 665 'type':float, 'precision':2, 666 'value':initHeight, 667 'continuous':1, 668 'oneTurn':2, 'wheelPad':2, 669 'height':20}, 670 'gridcfg':{'columnspan':2,'sticky':'we'}}) 671 initSide = 1.0 672 sideWidgetDescr = ({'name':'sidelength', 673 'widgetType':ThumbWheel, 674 'wcfg':{ 'labCfg':{'text':'Length of side:', 675 'font':('Helvetica',12,'bold')}, 676 'showLabel':1, 'width':100, 677 'min':0.05, 'max':10.0, 678 'type':float, 'precision':2, 679 'value':initSide, 680 'continuous':1, 681 'oneTurn':2, 'wheelPad':2, 682 'height':20}, 683 'gridcfg':{'columnspan':2,'sticky':'we'}}) 684 685 capsWidgetDescr = {'name':'capsFlag', 686 'widgetType':Tkinter.Checkbutton, 687 'defaultValue':0, 688 'wcfg':{'text':'caps', 689 'variable': Tkinter.IntVar()}, 690 'gridcfg':{'sticky':'we'}} 691 692 if formName == 'rectangle': 693 idf = InputFormDescr(title ="Rectangle size :") 694 idf.append(widthWidgetDescr) 695 initHeight = 0.4 696 idf.append(heightWidgetDescr) 697 698 elif formName == 'circle': 699 idf = InputFormDescr(title="Circle size :") 700 idf.append(radiusWidgetDescr) 701 702 elif formName == 'ellipse': 703 idf = InputFormDescr(title="Ellipse size") 704 idf.append({'name':'grand', 705 'widgetType':ThumbWheel, 706 'wcfg':{ 'labCfg':{'text':'Demi-grand Axis:', 707 'font':('Helvetica',12,'bold')}, 708 'showLabel':1, 'width':100, 709 'min':0.05, 'max':10.0, 710 'type':float, 'precision':2, 711 'value':0.5, 712 'continuous':1, 713 'oneTurn':2, 'wheelPad':2, 714 'height':20}, 715 'gridcfg':{'columnspan':2,'sticky':'we'}}) 716 717 idf.append({'name':'small', 718 'widgetType':ThumbWheel, 719 'wcfg':{ 'labCfg':{'text':'Demi-small Axis:', 720 'font':('Helvetica',12,'bold')}, 721 'showLabel':1, 'width':100, 722 'min':0.05, 'max':10.0, 723 'type':float, 'precision':2, 724 'value':0.2, 725 'continuous':1, 726 'oneTurn':2, 'wheelPad':2, 727 'height':20}, 728 'gridcfg':{'columnspan':2,'sticky':'we'}}) 729 elif formName == 'square': 730 idf = InputFormDescr(title="Square size :") 731 idf.append(sideWidgetDescr) 732 733 elif formName == 'triangle': 734 idf = InputFormDescr(title="Triangle size :") 735 idf.append(sideWidgetDescr) 736 737 738 # These widgets are present in everyInputForm. 739 idf.append(capsWidgetDescr) 740 741 return idf
742
743 - def guiCallback(self):
744 # Write a shape chooser method that should be reused in 745 # secondaryStructureCommands, CATrace commands, and splineCommands. 746 typeshape = self.showForm('geomChooser') 747 if typeshape == {} or typeshape['shape'] == []: return 748 # Shape is a Rectangle 749 if typeshape['shape'][0]=='rectangle': 750 val = self.showForm('rectangle') 751 if val: 752 shape = Rectangle2D(width = val['width'], 753 height = val['height'], 754 firstDup=1, vertDup=1) 755 capsFlag = val['capsFlag'] 756 757 # Shape is a Circle: 758 elif typeshape['shape'][0]=='circle': 759 760 val = self.showForm('circle') 761 if val: 762 shape = Circle2D(radius=val['radius'], firstDup=1) 763 capsFlag = val['capsFlag'] 764 765 # Shape is an Ellipse 766 elif typeshape['shape'][0]=='ellipse': 767 val = self.showForm('ellipse') 768 if val: 769 shape = Ellipse2D(demiGrandAxis= val['grand'], 770 demiSmallAxis=val['small'], firstDup = 1) 771 capsFlag = val['capsFlag'] 772 773 # Shape is a Square: 774 elif typeshape['shape'][0]=='square': 775 val = self.showForm('square') 776 if val: 777 shape = Square2D(side=val['sidelength'], firstDup=1, vertDup=1) 778 capsFlag = val['capsFlag'] 779 780 # Shape is a Triangle: 781 elif typeshape['shape'][0]=='triangle': 782 val = self.showForm('triangle') 783 if val: 784 shape = Triangle2D(side=val['sidelength'], firstDup=1, 785 vertDup=1) 786 capsFlag = val['capsFlag'] 787 788 789 else: return 790 791 if val: 792 nodes = self.vf.getSelection() 793 self.doitWrapper(nodes, shape2D=shape, 794 capsFlag=capsFlag, redraw=1)
795 796
797 -class DisplayExtrudedSplineCommand(DisplayCommand):
798 """ The DisplayExtrudeSplineCommand implements a set of methods to display/undisplay part of the geometries created by the ExtrudeSplineCommand. This command is undoable. 799 \nPackage : Pmv 800 \nModule : splineCommands 801 \nClass : DisplaySplineCommand 802 \nCommand : displaySpline 803 \nSynopsis:\nNone<- displaySpline(nodes, negate=False, only=False, **kw) 804 \nRequired Arguments:\n 805 nodes --- TreeNodeSet holding the current selection. Can also be a string representing the current selection. 806 \nOptional Arguments:\n 807 only --- flag when set to 1 only the current selection will be displayed 808 \nnegate --- flag when set to 1 undisplay the current selection 809 """ 810 811
812 - def setupUndoBefore(self, nodes, only=False, negate=False):
813 """ This method makes the command undoable""" 814 if len(nodes)==0 : return 815 geomSet = [] 816 for mol in self.vf.Mols: 817 gc = mol.geomContainer 818 for chain in mol.chains: 819 if not hasattr(chain,'spline') or chain.spline is None: 820 continue 821 geomSet = geomSet + gc.atoms['spline'+chain.id] 822 kw = {'redraw':1} 823 if len(geomSet) == 0: 824 # The undo of a display command is undisplay what you just 825 # displayed if nothing was displayed before. 826 kw['negate'] = True 827 self.addUndoCall( (nodes,), kw, self.name) 828 else: 829 # The undo of a display command is to display ONLY what was 830 # displayed before, if something was already displayed 831 kw['only'] = True 832 self.addUndoCall( (geomSet,), kw, self.name)
833 834
835 - def onAddCmdToViewer(self):
836 if self.vf.hasGui and not self.vf.commands.has_key('computeSplineGC'): 837 self.vf.loadCommand("splineCommands", "computeSplineGC", "Pmv", 838 topCommand = 0)
839 840
841 - def __call__(self, nodes, only=False, negate=False, **kw):
842 """None<- displaySpline(nodes, negate=False, only=False, **kw) 843 \nRequired Arguments:\n 844 nodes --- TreeNodeSet holding the current selection. Can also be a string representing the current selection. 845 \nOptional Arguments:\n 846 only --- flag when set to 1 only the current selection will be displayed 847 \nnegate --- flag when set to 1 undisplay the current selection 848 """ 849 if type(nodes) is types.StringType: 850 self.nodeLogString = "'"+nodes+"'" 851 852 nodes = self.vf.expandNodes(nodes) 853 kw['only'] = only 854 kw['negate'] = negate 855 if not kw.has_key('redraw') : kw['redraw']=1 856 apply(self.doitWrapper, (nodes,), kw)
857 858
859 - def doit(self, nodes, only=False, negate=False):
860 ##################################################### 861 def drawAtoms(chain, atmInCurSel, splineName, only, negate): 862 # Get a handle on the geomContainer 863 gc = chain.parent.geomContainer 864 closed = gc.geoms[splineName].spline[0].closed 865 shape2D = gc.geoms[splineName].shape2D 866 lshape = shape2D.lenShape 867 # 1- Get the right sets of atoms. 868 # Set of ctlPts displayed 869 set = gc.atoms[splineName] 870 871 # Set of control points used to compute the spline. 872 # right now the 'spline'+chain.id is hard coded 873 ctlAtms = chain.spline['spline'+chain.id][1] 874 875 # Set of control points used to compute the spline contained 876 # in the current selection: 877 ctlAtmsInSel = ctlAtms.inter(atmInCurSel) 878 879 ##if negate, remove current atms from displayed set 880 if negate: set = set - ctlAtmsInSel 881 882 ##if only, replace displayed set with current atms 883 else: 884 if only: 885 set = ctlAtmsInSel 886 else: 887 set = ctlAtmsInSel.union(set) 888 889 # 2- Now Update the GleExtrude Geometry: 890 if len(set)==0: 891 # no atms no GleExtrude Geometry: 892 #gc.geoms[splineName].Set(visible = 0, tagModified=False) 893 gc.geoms[splineName].Set(stripBegin=[], stripEnd = [], 894 visible=0, tagModified=False) 895 gc.atoms[splineName] = set 896 return 897 # the rest is done only if there are some atoms: 898 # compute the faces indices for the atoms to be displayed. 899 #set.sort() 900 caps = gc.geoms[splineName].capsFlag 901 nbchords = chain.spline['spline'+chain.id][0].nbchords 902 stripBegin = [] 903 stripEnd = [] 904 dlshape = lshape*2 905 test = [] 906 for a in set: 907 atmIndex = ctlAtms.index(a) 908 if atmIndex == 0: 909 # 1s point 910 length = nbchords/2 911 912 for n in range(length): 913 # last 2 strips and 2 first strips 914 sB = (atmIndex + n)*dlshape 915 sE = sB+dlshape 916 stripBegin.append(sB) 917 stripEnd.append(sE) 918 919 if closed: 920 # 2 first faces and 3 last. 921 index = len(ctlAtms) 922 start = (index - 1)*nbchords + nbchords/2 923 for n in range(nbchords/2): 924 sB = (start +n)*dlshape 925 sE = sB+dlshape 926 stripBegin.append(sB) 927 stripEnd.append(sE) 928 929 elif atmIndex == len(ctlAtms)-1: 930 #last point 931 if closed ==1: 932 length = nbchords 933 elif caps == 1: 934 length = nbchords/2+2 935 else: 936 length = nbchords/2 937 938 start = (atmIndex-1)*nbchords + nbchords/2 939 for n in range(length): 940 sB = (start + n)*dlshape 941 stripBegin.append(sB) 942 sE = sB+dlshape 943 stripEnd.append(sE) 944 945 else: 946 start = (atmIndex-1)*nbchords + nbchords/2 947 for n in range(nbchords): 948 sB = (start + n)*dlshape 949 sE = sB+dlshape 950 stripBegin.append(sB) 951 stripEnd.append(sE) 952 gc.atoms[splineName] = set 953 g = gc.geoms[splineName] 954 g.Set(stripBegin=stripBegin, stripEnd=stripEnd, visible=1, 955 tagModified=False) 956 stripBegin.sort() 957 stripEnd.sort()
958 959 ################################################################## 960 961 962 molecules, atomSets = self.vf.getNodesByMolecule(nodes, Atom) 963 for mol, atoms in map(None, molecules, atomSets): 964 gc = mol.geomContainer 965 chains = atoms.findType(Chain).uniq() 966 for chain in chains: 967 atomsInSel = atoms.inter(chain.findType(Atom)) 968 if not hasattr(chain,'spline') or chain.spline is None: 969 # maybe fixe that. 970 continue 971 splineName = 'spline'+chain.id 972 if not gc.atoms.has_key(splineName) \ 973 or not gc.geoms.has_key(splineName): 974 continue 975 drawAtoms(chain, atomsInSel, splineName, only, negate)
976 977
978 -class UndisplayExtrudedSplineCommand(DisplayCommand):
979 """ UndisplayExtrudeSplineCommand is the interactive command to undisplay part of the molecule when displayed as an extruded spline.It calls the displatExtrudedSpline with negate =1 980 \nPackage : Pmv 981 \nModule : splineCommands 982 \nClass : UnDisplaySplineCommand 983 \nCommand : undisplaySpline 984 \nSynopsis:\nNone <- undisplayExtrudedSpline(nodes, **kw) 985 \nRequired Arguments:\n 986 nodes --- TreeNodeSet holding the current selection. Can also be a string representing the current selection. 987 """
988 - def onAddCmdToViewer(self):
989 if not self.vf.hasGui: return 990 if not self.vf.commands.has_key('displayExtrudedSpline'): 991 self.vf.loadCommand('splineCommands', 992 ['displayExtrudedSpline'], 'Pmv', 993 topCommand=0)
994
995 - def __call__(self, nodes, **kw):
996 """ None <- undisplayExtrudedSpline(nodes, **kw) 997 \nRequired Arguments:\n 998 nodes --- TreeNodeSet holding the current selection. Can also be a string representing the current selection. 999 """ 1000 if type(nodes) is types.StringType: 1001 self.nodeLogString = "'" + nodes +"'" 1002 kw['negate']= 1 1003 apply(self.vf.displayExtrudedSpline, (nodes,),kw)
1004 1005
1006 -class DisplaySplineAsLineCommand(DisplayCommand):
1007 """ DisplaySplineAsLineCommand implements a set of method to display/ 1008 undisplay part of the spline when represented as line. 1009 \nPackage : Pmv 1010 \nModule : splineCommands 1011 \nClass : DisplaySplineAsLineCommand 1012 \nCommand : displaySplineAsLine 1013 \nSynopsis:\nNone<- displaySplineAsLine(nodes, lineWidth=3, only=0, negate=0,**kw) 1014 \nRequired Arguments:\n 1015 nodes --- TreeNodeSet holding the current selection. Can also be a string representing the current selection. 1016 \nOptional Arguments:\n 1017 only --- Boolean flag when set to True only the current selection will be displayed 1018 \nnegate --- Boolean flag when set to True undisplay the current selection lineWidth: width of the line representing the spline. 1019 """ 1020
1021 - def onRemoveObjectFromViewer(self, obj):
1022 gc = obj.geomContainer 1023 for c in obj.chains: 1024 splineName = 'linespline'+c.id 1025 if gc.geoms.has_key(splineName): 1026 g = gc.geoms[splineName] 1027 if hasattr(g, 'spline'): 1028 delattr(g,'spline')
1029 1030
1031 - def createGeometries(self, obj):
1032 """ Methdo creating the lineSpline geometry.""" 1033 geomC = obj.geomContainer 1034 for chain in obj.chains: 1035 addGeom = False 1036 if not hasattr(chain, 'spline') or chain.spline is None: 1037 # no spline Object computed for that chain. 1038 continue 1039 name = "lineSpline" + chain.id 1040 if geomC.geoms.has_key(name) and geomC.atoms.has_key(name): 1041 g = geomC.geoms[name] 1042 addGeom = True 1043 if g.spline == chain.spline['spline'+chain.id]: 1044 # same spline Object doesn't need to reconstruct the 1045 # geometry 1046 continue 1047 else: 1048 # need create the geometry again and to add it again: 1049 # so need to first remove it from the viewer then delete 1050 # it. 1051 geomC.VIEWER.RemoveObject(g) 1052 del geomC.geoms[name] 1053 1054 smooth = chain.spline['spline'+chain.id][0].smooth 1055 vertices = smooth[1:-1] 1056 g = IndexedPolylines(name=name, 1057 vertices = vertices, inheritLineWidth=0) 1058 #protected=True fail a test in test_splineCommands.py" 1059 1060 1061 #3/7/05: commented out setting geomC.geoms[name] directly 1062 # this is handled by the geomContainer.addGeom method now... 1063 #if not addGeom: 1064 # geomC.geoms[name] = g 1065 1066 # need for coloring and picking. 1067 g.spline = chain.spline['spline'+chain.id] 1068 1069 #geomC.atoms[name] = AtomSet() 1070 geomC.geomPickToAtoms[name] = self.pickedVerticesToAtoms 1071 geomC.atomPropToVertices[name] = self.atomPropToVertices 1072 geomC.geomPickToBonds[name] = None 1073 geomC.addGeom(g, parent=geomC.masterGeom, redo=0) 1074 self.managedGeometries.append(g) 1075 1076 for atm in chain.parent.findType(Atom): 1077 atm.colors[name] = (1.0, 1.0, 1.0) 1078 atm.opacities[name] = 1.0
1079 1080
1081 - def pickedVerticesToAtoms(self, geom, vertInd):
1082 """Function called to convert a picked vertex into an atom""" 1083 1084 # this function gets called when a picking or drag select event has 1085 # happened. It gets called with a geometry and the list of vertex 1086 # indices of that geometry that have been selected. 1087 # This function is in charge of turning these indices into an AtomSet 1088 pickedAtms = AtomSet() 1089 nbchords = geom.spline[0].nbchords 1090 lastVertices = geom.spline[1].index(geom.spline[1][-1]) 1091 closed = geom.spline[0].closed 1092 for v in vertInd: 1093 splinePts = v 1094 # 2- need to convert that index into an atom indices in the 1095 # set 1096 if not closed: 1097 if splinePts>=nbchords/2 and \ 1098 splinePts <(lastVertices)*nbchords - nbchords/2: 1099 # normal points 1100 atmIndex = (splinePts-nbchords/2)/nbchords + 1 1101 1102 1103 elif splinePts<nbchords/2: 1104 atmIndex = 0 1105 1106 elif splinePts >= (lastVertices)*nbchords - nbchords/2: 1107 atmIndex = -1 1108 1109 else: 1110 lastIndex = (lastVertices)*nbchords - nbchords/2 1111 if splinePts>=nbchords/2 and \ 1112 splinePts <lastIndex: 1113 # normal points 1114 atmIndex = (splinePts-nbchords/2)/nbchords + 1 1115 1116 elif splinePts >= lastIndex and \ 1117 splinePts < lastIndex + nbchords: 1118 atmIndex = -1 1119 elif splinePts<nbchords/2 or \ 1120 splinePts >= lastIndex + nbchords: 1121 atmIndex = 0 1122 1123 atm = geom.spline[1][atmIndex] 1124 pickedAtms.append(atm) 1125 1126 # 3- need to return the corresponding atomset. 1127 return pickedAtms
1128 1129
1130 - def atomPropToVertices(self, geom, atoms, propName, propIndex=None):
1131 """Function called to compute the array of colors""" 1132 # geom: IndexedPolylines 1133 # atoms: list of the atoms in the current selection. 1134 if len(atoms)==0: return 1135 propVect = [] 1136 1137 # same number of vertices than point in the path3D : 1138 # (nb of atoms used as control points used to compute the spline 1139 # * nbchord) 1140 ctlAtms = geom.spline[1] 1141 closed = geom.spline[0].closed 1142 for a in atoms: 1143 if not closed: 1144 if a==ctlAtms[0] or a == ctlAtms[-1]: 1145 nbchords = geom.spline[0].nbchords/2 1146 else: 1147 nbchords = geom.spline[0].nbchords 1148 else: 1149 nbchords = geom.spline[0].nbchords 1150 1151 prop = getattr(a, propName) 1152 1153 if not propIndex is None: 1154 prop = prop[propIndex] 1155 1156 for n in range(nbchords): 1157 propVect.append(prop) 1158 return propVect
1159
1160 - def setupUndoBefore(self, nodes, lineWidth=3, only=False, negate=False):
1161 if len(nodes)==0 : return 1162 kw = {} 1163 kw['lineWidth'] = lineWidth 1164 kw['redraw'] = True 1165 geomSet = [] 1166 for mol in self.vf.Mols: 1167 gc = mol.geomContainer 1168 for chain in mol.chains: 1169 if not hasattr(chain, 'spline') or chain.spline is None: 1170 continue 1171 name = 'lineSpline%s'%chain.id 1172 if not gc.atoms.has_key(name): 1173 continue 1174 geomSet = geomSet + gc.atoms[name] 1175 1176 if len(geomSet) == 0: 1177 # The undo of a display command is undisplay what you just 1178 # displayed if nothing was displayed before. 1179 kw['negate'] = True 1180 self.addUndoCall( (nodes,), kw, self.name) 1181 else: 1182 # The undo of a display command is to display ONLY what was 1183 # displayed before, if something was already displayed 1184 kw['only'] = True 1185 self.addUndoCall( (geomSet,), kw, self.name)
1186 1187
1188 - def guiCallback(self):
1189 idf = InputFormDescr(title="Display Spline As Line :") 1190 idf.append({'name':'display', 1191 'widgetType':Pmw.RadioSelect, 1192 'listtext':['display','display only', 'undisplay'], 1193 'defaultValue':'display', 1194 'wcfg':{'orient':'horizontal', 1195 'buttontype':'radiobutton'}, 1196 'gridcfg':{'sticky': 'we'}}) 1197 1198 idf.append( {'name': 'lineWidth', 1199 'widgetType':ExtendedSliderWidget, 1200 'wcfg':{'label': 'Line width: ', 1201 'minval':1,'maxval':10, 1202 'init':3, 1203 'labelsCursorFormat':'%d', 1204 'sliderType':'int', 1205 'entrywcfg':{'width':4}, 1206 'entrypackcfg':{'side':'right'}}, 1207 'gridcfg':{'sticky':'we'} 1208 }) 1209 1210 val = self.vf.getUserInput(idf) 1211 1212 if val: 1213 val['redraw'] = 1 1214 if val['display']=='display': 1215 val['only']= 0 1216 val['negate'] = 0 1217 del val['display'] 1218 elif val['display']=='display only': 1219 val['only']= 1 1220 val['negate'] = 0 1221 del val['display'] 1222 elif val['display']== 'undisplay': 1223 val['negate'] = 1 1224 val['only'] = 0 1225 del val['display'] 1226 apply( self.doitWrapper, (self.vf.getSelection(),), val)
1227 1228 1229 1230
1231 - def __call__(self, nodes, lineWidth=3, only=False, negate=False, **kw):
1232 """None<- displaySplineAsLine(nodes,lineWidth=3,only=0,negate=0,**kw) 1233 \nRequired Arguments:\n 1234 nodes --- TreeNodeSet holding the current selection. Can also be a string representing the current selection. 1235 \nOptional Arguments:\n 1236 only --- Boolean flag when set to True only the current selection will be displayed 1237 \nnegate --- Boolean flag when set to True undisplay the current selection 1238 \nlineWidth --- width of the line representing the spline. 1239 """ 1240 if type(nodes) is types.StringType: 1241 self.nodeLogString = "'"+nodes+"'" 1242 1243 nodes = self.vf.expandNodes(nodes) 1244 kw['only'] = only 1245 kw['negate'] = negate 1246 kw['lineWidth']=lineWidth 1247 if not kw.has_key('redraw'):kw['redraw'] = 1 1248 apply(self.doitWrapper, (nodes,), kw)
1249 1250
1251 - def doit(self, nodes, lineWidth=3, only=False, negate=False):
1252 1253 ####################################################### 1254 1255 def drawAtoms(chain, atmInCurSel, splineName, lineWidth, 1256 only, negate): 1257 # Get a handle on the geomContainer 1258 gc = chain.parent.geomContainer 1259 1260 # 1- Get the right sets of atoms. 1261 # Set of ctlPts displayed 1262 set = gc.atoms[splineName] 1263 1264 # Set of control points used to compute the spline. 1265 # right now the 'spline'+chain.id is hard coded 1266 ctlAtms = chain.spline['spline'+chain.id][1] 1267 1268 # Set of control points used to compute the spline contained 1269 # in the current selection: 1270 ctlAtmsInSel = ctlAtms.inter(atmInCurSel) 1271 1272 ##if negate, remove current atms from displayed set 1273 if negate: set = set - ctlAtmsInSel 1274 1275 ##if only, replace displayed set with current atms 1276 else: 1277 if only: 1278 set = ctlAtmsInSel 1279 else: 1280 set = ctlAtmsInSel.union(set) 1281 1282 # 2- Now Update the IndexedPolyLines geometry: 1283 if len(set)==0: 1284 # no atms no IndexedPolylines: 1285 gc.geoms[splineName].Set(faces=[], tagModified=False) 1286 gc.atoms[splineName] = set 1287 return 1288 1289 # the rest is done only if there are some atoms: 1290 # compute the faces indices for the atoms to be displayed. 1291 #set.sort() 1292 nbchords = chain.spline['spline'+chain.id][0].nbchords 1293 closed = gc.geoms[splineName].spline[0].closed 1294 faces = [] 1295 for a in set: 1296 atmIndex = ctlAtms.index(a) 1297 if atmIndex == 0: 1298 # first point or last points only have 2 faces. 1299 start = atmIndex 1300 end = nbchords/2 1301 for x in range(start, end): 1302 faces.append((x, x+1)) 1303 1304 if closed ==1: 1305 index = len(ctlAtms) 1306 start = (index - 1)*nbchords + nbchords/2 1307 end = start + nbchords/2 1308 for x in range(start, end): 1309 faces.append((x, x+1)) 1310 1311 elif atmIndex == len(ctlAtms)-1: 1312 start = (atmIndex-1)*nbchords + nbchords/2 1313 if closed ==1: 1314 end = start+nbchords 1315 else: 1316 end = start + nbchords/2 1317 1318 for x in range(start, end): 1319 faces.append((x, x+1)) 1320 1321 else: 1322 1323 start = (atmIndex-1)*nbchords + nbchords/2 1324 end = start + nbchords 1325 for x in range(start, end): 1326 faces.append((x, x+1)) 1327 #faces = faces + map(lambda x: (x,x+1), range(start, end)) 1328 gc.atoms[splineName] = set 1329 g = gc.geoms[splineName] 1330 1331 g.Set(faces=faces, lineWidth=lineWidth, visible=1, 1332 tagModified=False)
1333 1334 ############################################################## 1335 1336 molecules, atomssSet = self.vf.getNodesByMolecule(nodes, Atom) 1337 for mol, atoms in map(None, molecules, atomssSet): 1338 self.createGeometries(mol) 1339 chains = atoms.findType(Chain).uniq() 1340 gc = mol.geomContainer 1341 for chain in chains: 1342 splineName = 'lineSpline'+chain.id 1343 atomsInSel = atoms.inter(chain.findType(Atom)) 1344 if not hasattr(chain, 'spline') or chain.spline is None: 1345 print 'the spline has not been computed for %s '%chain.full_name() 1346 continue 1347 1348 drawAtoms(chain, atomsInSel, splineName, lineWidth, only, 1349 negate)
1350
1351 -class UndisplaySplineAsLineCommand(DisplayCommand):
1352 """ UndisplaySPlineAsLineCommand calls the displaySplineAsLine command with the flag negate set to 1 1353 \nPackage : Pmv 1354 \nModule : splineCommands 1355 \nClass : UndisplaySplineAsLineSplineCommand 1356 \nCommand : undisplaySplineAsLineSpline 1357 \nSynopsis:\n 1358 None <- undisplaySplineAsLine(nodes, **kw) 1359 \nRequired Arguments:\n 1360 nodes --- TreeNodeSet holding the current selection. Can also be a 1361 string representing the current selection. 1362 """ 1363
1364 - def onAddCmdToViewer(self):
1365 if not self.vf.hasGui: return 1366 if not self.vf.commands.has_key('displaySplineAsLine'): 1367 self.vf.loadCommand('splineCommands', 1368 ['displaySplineAsLine'], 'Pmv', 1369 topCommand=0)
1370 1371
1372 - def __call__(self, nodes, **kw):
1373 """ None <- undisplaySplineAsLine(nodes, **kw) 1374 \nRequired Arguments:\n 1375 nodes --- TreeNodeSet holding the current selection. Can also be a 1376 string representing the current selection. 1377 """ 1378 if type(nodes) is types.StringType: 1379 self.nodeLogString = "'" + nodes +"'" 1380 kw['negate']= 1 1381 if not nodes: return 1382 apply(self.vf.displaySplineAsLine, (nodes,),kw)
1383 1384 1385 1386
1387 -class CustomSplineCommand(MVCommand):
1388 """This command computes and extrudes spline using the values given or from the widget. 1389 \nPackage : Pmv 1390 \nModule : splineCommands 1391 \nClass : CustomSplineCommand 1392 \nCommand : customSpline 1393 \nSynopsis:\nNone<---customTrace(nodes, atmtype="CA", curSel=False, nbchords=4,interp='interpolation', continuity=2, closedSpline=False,sortAtms=True, shape2D=None, capsFlag=False, display=True,**kw) 1394 \nRequired Arguments:\n 1395 nodes --- self.getSelection() 1396 \nOptional Arguments:\n 1397 \natmtype --- specifies the atom type of the control points. 1398 the atoms of the current selection of the given 1399 atom type are used as the control points. 1400 atmtype can be 'CA'(default value) 'CA,N' 'O' etc.... 1401 1402 \ncurSel --- Boolean flag to use the atoms in current selection as control 1403 points. (default=False) 1404 \nnbchords --- number of point per control points in the smooth array 1405 \ninterp --- flag if set to 'interpolation' interpolate the control 1406 points. 1407 \ncontinuity --- specifies the continuity of the curve. 1408 \nclosedSpline --- Boolean flag when set to True the spline will be closed (1st atom will be connected to the last atom. (default = False) 1409 \nsortAtms --- Boolean flag to sort the ctlAtms or not. (default = True) 1410 \nshape2D --- instance of a DejaVu.Shapes class (Triangle2DDup, Circle2D...)the default shape is a circle2D 1411 \ncapsFlag --- Boolean flag to add caps at the end of the spline (default=False) 1412 \ndisplay --- Boolean flag to call or not the displayExtrudedSpline command default value is True. 1413 """ 1414
1415 - def __init__(self):
1416 MVCommand.__init__(self) 1417 self.flag = self.flag | self.objArgOnly 1418 self.flag = self.flag | self.negateKw
1419 1420 1421
1422 - def onAddCmdToViewer(self):
1423 if self.vf.hasGui and \ 1424 not self.vf.commands.has_key('computeSpline'): 1425 self.vf.loadCommand("splineCommands", 1426 "computeSpline", "Pmv", 1427 topCommand = 0) 1428 if self.vf.hasGui and \ 1429 not self.vf.commands.has_key('extrudeSpline'): 1430 self.vf.loadCommand("splineCommands", 1431 "extrudeSpline", "Pmv", 1432 topCommand = 0) 1433 if self.vf.hasGui and \ 1434 not self.vf.commands.has_key('displaySpline'): 1435 self.vf.loadCommand("splineCommands", 1436 "displayExtrudedSpline", "Pmv", 1437 topCommand = 0)
1438
1439 - def buildFormDescr(self, formName):
1440 if formName == 'customSpline': 1441 idf = InputFormDescr(title="Custom Spline:") 1442 nbchordEntryVar = Tkinter.StringVar() 1443 idf.append({'name':'curSel', 1444 'widgetType':Tkinter.Checkbutton, 1445 'defaultValue':0, 1446 'wcfg':{'text':'Current Selection', 1447 'variable':Tkinter.IntVar(), 1448 'command':self.cursel_cb}, 1449 'gridcfg':{'sticky':'we'}}) 1450 1451 # ? maybe a list of checkbox Entryfield to choose the atomType. 1452 idf.append({'widgetType':Pmw.EntryField, 1453 'name':'atmtype', 1454 'wcfg':{'labelpos':'w', 1455 'label_text':'Enter atom types: ', 1456 'validate':None, 1457 }, 1458 'gridcfg':{'sticky':'we'}}) 1459 1460 # number of points per residue 1461 idf.append( {'name': 'nbchords', 1462 'widgetType':ExtendedSliderWidget, 1463 'type':int, 1464 'wcfg':{'label': 'nb. Pts Per Residue: ', 1465 'minval':4,'maxval':15, 'incr': 1, 'init':4, 1466 'labelsCursorFormat':'%d', 'sliderType':'int', 1467 'entrywcfg':{'textvariable':nbchordEntryVar, 1468 'width':4}, 1469 'entrypackcfg':{'side':'right'}}, 1470 'gridcfg':{'sticky':'we'} 1471 }) 1472 # Continuity 1473 idf.append( {'name': 'continuity', 1474 'widgetType':ExtendedSliderWidget, 1475 'type':int, 1476 'wcfg':{'label': 'Continuity', 1477 'minval':0,'maxval':5, 'incr': 1, 'init':2, 1478 'labelsCursorFormat':'%d', 'sliderType':'int', 1479 'entrywcfg':{'width':4}, 1480 'entrypackcfg':{'side':'right'}}, 1481 'gridcfg':{'sticky':'we'} 1482 }) 1483 1484 idf.append({'name':'closedSpline', 1485 'widgetType':Tkinter.Checkbutton, 1486 'defaultValue':0, 1487 'wcfg':{'text':'Closed Spline ', 1488 'variable':Tkinter.IntVar()}, 1489 'gridcfg':{'sticky':'we'}}) 1490 1491 idf.append({'name':'sortAtms', 1492 'widgetType':Tkinter.Checkbutton, 1493 'defaultValue':1, 1494 'wcfg':{'text':'Sort control Atoms', 1495 'variable':Tkinter.IntVar()}, 1496 'gridcfg':{'sticky':'we'}}) 1497 1498 1499 1500 nbchordEntryVar = Tkinter.StringVar() 1501 1502 1503 entries = [('rectangle',None), 1504 ('circle',None), ('ellipse',None), 1505 ('square',None),('triangle',None), 1506 #('other', None) 1507 ] 1508 1509 idf.append({'name':'shape', 1510 'widgetType':ListChooser, 1511 'defaultValue':'circle', 1512 'wcfg':{'entries': entries, 1513 'title':'Choose a shape'} 1514 }) 1515 1516 else: 1517 # Create the description of the inputForm letting the user 1518 # modify the parameter describing the shape to be extruded. 1519 initRadius = 0.1 1520 radiusWidgetDescr = ({'name':'radius', 1521 'widgetType':ThumbWheel, 1522 'wcfg':{ 'labCfg':{'text':'Radius:', 1523 'font':('Helvetica',12,'bold')}, 1524 'showLabel':1, 'width':100, 1525 'min':0.05, 'max':10.0, 1526 'type':float, 'precision':2, 1527 'value':initRadius, 1528 'continuous':1, 1529 'oneTurn':2, 'wheelPad':2, 1530 'height':20}, 1531 'gridcfg':{'columnspan':2,'sticky':'we'}}) 1532 initWidth = 1.2 1533 widthWidgetDescr = ({'name':'width', 1534 'widgetType':ThumbWheel, 1535 'wcfg':{ 'labCfg':{'text':'Width:', 1536 'font':('Helvetica',12,'bold')}, 1537 'showLabel':1, 'width':100, 1538 'min':0.05, 'max':10.0, 1539 'type':float, 'precision':2, 1540 'value':initWidth, 1541 'continuous':1, 1542 'oneTurn':2, 'wheelPad':2, 1543 'height':20}, 1544 'gridcfg':{'columnspan':2,'sticky':'we'}}) 1545 initHeight = 0.2 1546 heightWidgetDescr = ({'name':'height', 1547 'widgetType':ThumbWheel, 1548 'wcfg':{ 'labCfg':{'text':'Height:', 1549 'font':('Helvetica',12,'bold')}, 1550 'showLabel':1, 'width':100, 1551 'min':0.05, 'max':10.0, 1552 'type':float, 'precision':2, 1553 'value':initHeight, 1554 'continuous':1, 1555 'oneTurn':2, 'wheelPad':2, 1556 'height':20}, 1557 'gridcfg':{'columnspan':2,'sticky':'we'}}) 1558 initSide = 1.0 1559 sideWidgetDescr = ({'name':'sidelength', 1560 'widgetType':ThumbWheel, 1561 'wcfg':{ 'labCfg':{'text':'Length of side:', 1562 'font':('Helvetica',12,'bold')}, 1563 'showLabel':1, 'width':100, 1564 'min':0.05, 'max':10.0, 1565 'type':float, 'precision':2, 1566 'value':initSide, 1567 'continuous':1, 1568 'oneTurn':2, 'wheelPad':2, 1569 'height':20}, 1570 'gridcfg':{'columnspan':2,'sticky':'we'}}) 1571 1572 capsWidgetDescr = {'name':'capsFlag', 1573 'widgetType':Tkinter.Checkbutton, 1574 'defaultValue':0, 1575 'wcfg':{'text':'caps', 1576 'variable': Tkinter.IntVar()}, 1577 'gridcfg':{'sticky':'we'}} 1578 1579 if formName == 'rectangle': 1580 idf = InputFormDescr(title ="Rectangle size :") 1581 idf.append(widthWidgetDescr) 1582 initHeight = 0.4 1583 idf.append(heightWidgetDescr) 1584 1585 elif formName == 'circle': 1586 idf = InputFormDescr(title="Circle size :") 1587 idf.append(radiusWidgetDescr) 1588 1589 elif formName == 'ellipse': 1590 idf = InputFormDescr(title="Ellipse size") 1591 idf.append({'name':'grand', 1592 'widgetType':ThumbWheel, 1593 'wcfg':{ 'labCfg':{'text':'Demi-grand Axis:', 1594 'font':('Helvetica',12,'bold')}, 1595 'showLabel':1, 'width':100, 1596 'min':0.05, 'max':10.0, 1597 'type':float, 'precision':2, 1598 'value':0.5, 1599 'continuous':1, 1600 'oneTurn':2, 'wheelPad':2, 1601 'height':20}, 1602 'gridcfg':{'columnspan':2,'sticky':'we'}}) 1603 1604 idf.append({'name':'small', 1605 'widgetType':ThumbWheel, 1606 'wcfg':{ 'labCfg':{'text':'Demi-small Axis:', 1607 'font':('Helvetica',12,'bold')}, 1608 'showLabel':1, 'width':100, 1609 'min':0.05, 'max':10.0, 1610 'type':float, 'precision':2, 1611 'value':0.2, 1612 'continuous':1, 1613 'oneTurn':2, 'wheelPad':2, 1614 'height':20}, 1615 'gridcfg':{'columnspan':2,'sticky':'we'}}) 1616 elif formName == 'square': 1617 idf = InputFormDescr(title="Square size :") 1618 idf.append(sideWidgetDescr) 1619 1620 elif formName == 'triangle': 1621 idf = InputFormDescr(title="Triangle size :") 1622 idf.append(sideWidgetDescr) 1623 1624 1625 # These widgets are present in everyInputForm. 1626 idf.append(capsWidgetDescr) 1627 1628 return idf
1629 - def cursel_cb(self, event = None):
1630 """ if the use curSel checkbutton is on: the entryField should be 1631 disabled.""" 1632 if self.cmdForms.has_key('customSpline'): 1633 idf = self.cmdForms['customSpline'].descr 1634 cbVar =idf.entryByName['curSel']['wcfg']['variable'] 1635 entry = idf.entryByName['atmtype']['widget'] 1636 1637 if cbVar.get() == 1: 1638 entry._entryFieldEntry.configure(state = Tkinter.DISABLED) 1639 entry.configure(label_fg = 'darkgray') 1640 1641 else: 1642 entry._entryFieldEntry.configure(state = Tkinter.NORMAL) 1643 entry.configure(label_fg = 'black')
1644
1645 - def guiCallback(self):
1646 1647 nodes = self.vf.getSelection() 1648 if not nodes: return 1649 typeshape = self.showForm('customSpline') 1650 if typeshape: 1651 if typeshape['curSel']==0 and \ 1652 (typeshape['atmtype']=='' or typeshape['atmtype']== ' '): 1653 # if no atmtype given and not cursel checked nothing 1654 # happens 1655 return 1656 1657 typeshape['redraw']=0 1658 1659 # Write a shape chooser method that should be reused in 1660 # secondaryStructureCommands, CATrace commands, and splineCommands. 1661 if typeshape == {} or typeshape['shape'] == []: return 1662 # Shape is a Rectangle 1663 if typeshape['shape'][0]=='rectangle': 1664 val = self.showForm('rectangle') 1665 if val: 1666 shape = Rectangle2D(width = val['width'], 1667 height = val['height'], 1668 firstDup=1, vertDup=1) 1669 capsFlag = val['capsFlag'] 1670 1671 # Shape is a Circle: 1672 elif typeshape['shape'][0]=='circle': 1673 1674 val = self.showForm('circle') 1675 if val: 1676 shape = Circle2D(radius=val['radius'], firstDup=1) 1677 capsFlag = val['capsFlag'] 1678 1679 # Shape is an Ellipse 1680 elif typeshape['shape'][0]=='ellipse': 1681 val = self.showForm('ellipse') 1682 if val: 1683 shape = Ellipse2D(demiGrandAxis= val['grand'], 1684 demiSmallAxis=val['small'], firstDup = 1) 1685 capsFlag = val['capsFlag'] 1686 1687 # Shape is a Square: 1688 elif typeshape['shape'][0]=='square': 1689 val = self.showForm('square') 1690 if val: 1691 shape = Square2D(side=val['sidelength'], firstDup=1, vertDup=1) 1692 capsFlag = val['capsFlag'] 1693 1694 # Shape is a Triangle: 1695 elif typeshape['shape'][0]=='triangle': 1696 val = self.showForm('triangle') 1697 if val: 1698 shape = Triangle2D(side=val['sidelength'], firstDup=1, 1699 vertDup=1) 1700 capsFlag = val['capsFlag'] 1701 1702 1703 else: return 1704 self.vf.computeSpline(nodes,atmtype=typeshape['atmtype'],curSel=typeshape['curSel'], nbchords=4, interp='interpolation', continuity=2, closedSpline=False, sortAtms=True) 1705 if val: 1706 self.vf.extrudeSpline(nodes, shape2D=shape, capsFlag=capsFlag, display=True)
1707
1708 - def __call__(self,nodes, atmtype="CA", curSel=False, nbchords=4, 1709 interp='interpolation', continuity=2, closedSpline=False, 1710 sortAtms=True, shape2D=None, capsFlag=False, display=True,**kw):
1711 """None<---customTrace(nodes, atmtype="CA", curSel=False, nbchords=4,interp='interpolation', continuity=2, closedSpline=False,sortAtms=True, shape2D=None, capsFlag=False, display=True,**kw) 1712 \nRequired Arguments:\n 1713 nodes --- self.getSelection() 1714 \nOptional Arguments:\n 1715 \natmtype --- specifies the atom type of the control points. 1716 the atoms of the current selection of the given 1717 atom type are used as the control points. 1718 atmtype can be 'CA'(default value) 'CA,N' 'O' etc.... 1719 1720 \ncurSel --- Boolean flag to use the atoms in current selection as control 1721 points. (default=False) 1722 \nnbchords --- number of point per control points in the smooth array 1723 \ninterp --- flag if set to 'interpolation' interpolate the control 1724 points. 1725 \ncontinuity --- specifies the continuity of the curve. 1726 \nclosedSpline --- Boolean flag when set to True the spline will be closed (1st atom will be connected to the last atom. (default = False) 1727 \nsortAtms --- Boolean flag to sort the ctlAtms or not. (default = True) 1728 \nshape2D --- instance of a DejaVu.Shapes class (Triangle2DDup, Circle2D...)the default shape is a circle2D 1729 \ncapsFlag --- Boolean flag to add caps at the end of the spline (default=False) 1730 \ndisplay --- Boolean flag to call or not the displayExtrudedSpline command default value is True. 1731 """ 1732 1733 nodes = self.vf.expandNodes(nodes) 1734 if not nodes: 1735 return "ERROR" 1736 kw['atmtype']=atmtype 1737 kw['curSel']=curSel 1738 kw['nbchords']=nbchords 1739 kw['interp']=interp 1740 kw['continuity']=continuity 1741 kw['closedSpline']=closedSpline 1742 kw['sortAtms']=sortAtms 1743 kw['shape2D']=shape2D 1744 kw['capsFlag']=capsFlag 1745 kw['display']=display 1746 apply(self.doitWrapper, (nodes,), kw)
1747
1748 - def doit(self, nodes,**kw):
1749 nkw={} 1750 if kw!={}: 1751 if kw['display']==0: 1752 nkw['negate']=1 1753 apply(self.vf.displayExtrudedSpline,(nodes,),nkw) 1754 return 1755 1756 elif kw['display']==1: 1757 if kw.has_key('negate'): 1758 if kw['negate']==1: 1759 nkw['negate']=1 1760 apply(self.vf.displayExtrudedSpline,(nodes,),nkw) 1761 return 1762 1763 self.vf.computeSpline(nodes,atmtype=kw['atmtype'],curSel=kw['curSel'], nbchords=kw['nbchords'], interp= kw['interp'], continuity=kw['continuity'], closedSpline=kw['closedSpline'], sortAtms=kw['sortAtms']) 1764 self.vf.extrudeSpline(nodes, shape2D=kw['shape2D'], capsFlag=kw['capsFlag'], display=kw['display'])
1765 1766 1767
1768 -class ComputeExtrudeSplineCommand(MVCommand):
1769 """This command computes and extrudes spline with default arguements. 1770 \nPackage : Pmv 1771 \nModule : splineCommands 1772 \nClass : ComputeExtrudeSplineCommand 1773 \nCommand : computeExtrudeSpline 1774 \nSynopsis:\nNone <- computeExtrudeSpline(nodes, only=False, negate=False, **kw) 1775 \nRequired Arguments:\n 1776 nodes --- TreeNodeSet holding the current selection 1777 \nOptional Arguments:\n 1778 only --- flag when set to 1 only the current selection 1779 will be displayed 1780 \nnegate --- flag when set to 1 undisplay the current selection 1781 """
1782 - def __init__(self):
1783 MVCommand.__init__(self) 1784 self.flag = self.flag | self.objArgOnly 1785 self.flag = self.flag | self.negateKw
1786 1787 1788
1789 - def onAddCmdToViewer(self):
1790 if self.vf.hasGui and \ 1791 not self.vf.commands.has_key('computeSpline'): 1792 self.vf.loadCommand("splineCommands", 1793 "computeSpline", "Pmv", 1794 topCommand = 0) 1795 if self.vf.hasGui and \ 1796 not self.vf.commands.has_key('extrudeSpline'): 1797 self.vf.loadCommand("splineCommands", 1798 "extrudeSpline", "Pmv", 1799 topCommand = 0) 1800 if self.vf.hasGui and \ 1801 not self.vf.commands.has_key('displaySpline'): 1802 self.vf.loadCommand("splineCommands", 1803 "extrudeSpline", "Pmv", 1804 topCommand = 0)
1805 1806
1807 - def __call__(self, nodes, only=False, negate=False, **kw):
1808 """None <- computeExtrudeSpline(nodes, only=False, negate=False, **kw) 1809 \nRequired Arguments:\n 1810 nodes --- TreeNodeSet holding the current selection 1811 \nOptional Arguments:\n 1812 only --- flag when set to 1 only the current selection 1813 will be displayed 1814 \nnegate --- flag when set to 1 undisplay the current selection 1815 """ 1816 if type(nodes) is types.StringType: 1817 self.nodeLogString = "'"+nodes+"'" 1818 1819 if not kw.has_key('redraw'): kw['redraw']=1 1820 nodes = self.vf.expandNodes(nodes) 1821 if not nodes: return "ERROR" 1822 kw['only']=only 1823 kw['negate']=negate 1824 #print "in ribbon with only=", only 1825 apply(self.doitWrapper, (nodes,), kw)
1826
1827 - def doit(self, nodes, **kw):
1828 if kw!={}: 1829 if kw['negate']==1: 1830 apply(self.vf.displayExtrudedSpline,(nodes,), kw) 1831 return 1832 apply(self.vf.computeSpline,(nodes,), {'topCommand':False}) 1833 kw['topCommand'] = 0 1834 apply(self.vf.extrudeSpline,(nodes,), {})
1835 1836 1837 computeSplineCommandGuiDescr = {'widgetType':'Menu', 1838 'menuBarName':'menuRoot', 1839 'menuButtonName':'Spline', 1840 'menuEntryLabel':'Build Spline'} 1841 1842 ComputeSplineGUICommandGUI = CommandGUI() 1843 ComputeSplineGUICommandGUI.addMenuCommand('menuRoot', 'Compute', 1844 'Spline', cascadeName='Spline') 1845 ExtrudeSplineCommandGUI = CommandGUI() 1846 ExtrudeSplineCommandGUI.addMenuCommand('menuRoot', 'Compute', 1847 'Extrude Spline', 1848 cascadeName='Spline') 1849 DisplayExtrudedSplineCommandGUI = CommandGUI() 1850 DisplayExtrudedSplineCommandGUI.addMenuCommand('menuRoot', 'Display', 1851 'Extruded Spline') 1852 1853 computeExtrudeSplineGuiDescr = {'widgetType':'Menu', 'menuBarName':'menuRoot', 1854 'menuButtonName':'ComputeExtrude CA Spline', 1855 'menuEntryLabel':'ComputeExtrude Spline'} 1856 1857 1858 ComputeExtrudeSplineGUI = CommandGUI() 1859 ComputeExtrudeSplineGUI.addMenuCommand('menuRoot','Compute','ComputeExtrude Spline',cascadeName ='Spline') 1860 customSplineGuiDescr = {'widgetType':'Menu', 'menuBarName':'menuRoot', 1861 'menuButtonName':'Custom CA Spline', 1862 'menuEntryLabel':'Custom Spline'} 1863 1864 1865 CustomSplineGUI = CommandGUI() 1866 CustomSplineGUI.addMenuCommand('menuRoot','Compute','Custom Spline',cascadeName ='Spline') 1867 DisplaySplineAsLineCommandGUI = CommandGUI() 1868 DisplaySplineAsLineCommandGUI.addMenuCommand('menuRoot', 'Display', 1869 'Spline as Line') 1870 1871 1872 commandList = [ 1873 {'name': 'computeSpline','cmd':ComputeSplineCommand(), 'gui':None}, 1874 {'name': 'computeSplineGC','cmd':ComputeSplineGUICommand(), 1875 'gui':ComputeSplineGUICommandGUI}, 1876 {'name': 'extrudeSpline','cmd':ExtrudeSplineCommand(), 1877 'gui':ExtrudeSplineCommandGUI}, 1878 {'name': 'computeExtrudeSpline', 'cmd': ComputeExtrudeSplineCommand(), 1879 'gui':ComputeExtrudeSplineGUI}, 1880 {'name': 'customSpline', 'cmd': CustomSplineCommand(), 1881 'gui':CustomSplineGUI}, 1882 {'name': 'displayExtrudedSpline','cmd':DisplayExtrudedSplineCommand(), 1883 'gui':DisplayExtrudedSplineCommandGUI}, 1884 {'name': 'undisplayExtrudedSpline', 1885 'cmd':UndisplayExtrudedSplineCommand(), 'gui':None}, 1886 {'name':'displaySplineAsLine','cmd':DisplaySplineAsLineCommand(), 1887 'gui':DisplaySplineAsLineCommandGUI}, 1888 {'name':'undisplaySplineAsLine','cmd':UndisplaySplineAsLineCommand(), 1889 'gui':None} 1890 ] 1891 1892
1893 -def initModule(viewer):
1894 """ initializes commands for secondary structure and extrusion. Also 1895 imports the commands for Secondary Structure specific coloring, and 1896 initializes these commands also. """ 1897 1898 for dict in commandList: 1899 viewer.addCommand(dict['cmd'], dict['name'], dict['gui'])
1900