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

Source Code for Module Pmv.extrusionCommands

  1  ############################################################################# 
  2  # 
  3  # Author: Sophie COON, Michel F. SANNER 
  4  # 
  5  # Copyright: M. Sanner TSRI 2000 
  6  # 
  7  ############################################################################# 
  8   
  9  # $Header: /opt/cvs/python/packages/share1.5/Pmv/extrusionCommands.py,v 1.39 2007/05/31 19:56:55 sargis Exp $ 
 10  # 
 11  # $Id: extrusionCommands.py,v 1.39 2007/05/31 19:56:55 sargis Exp $ 
 12  # 
 13  import Tkinter, Numeric,Pmw 
 14  import types, string 
 15  from tkColorChooser import askcolor 
 16  from Pmv.mvCommand import MVCommand 
 17  from ViewerFramework.VFCommand import CommandGUI 
 18   
 19  from MolKit.molecule import Atom, AtomSet 
 20  from MolKit.protein import Protein, Residue, Chain, ResidueSet, ProteinSet 
 21  from mglutil.gui.BasicWidgets.Tk.customizedWidgets import SliderWidget, \ 
 22       ExtendedSliderWidget 
 23  from mglutil.gui.InputForm.Tk.gui import InputFormDescr 
 24  from Pmv.extruder import Sheet2D 
 25  from Pmv.displayCommands import DisplayCommand 
 26  from DejaVu.Spheres import Spheres 
 27   
 28   
29 -class ComputeSheet2DCommand(MVCommand):
30 """The ComputeSheet2DCommand class implements methods to compute the sheet2D for each chain of the contained in the current selection. Need to specify two control atoms. 31 \nPackage : Pmv 32 \nModule : extrusionCommands 33 \nClass : ComputeSheet2DCommand 34 \nCommand name : computeSheet2D 35 \nSynopsis:\n 36 None <- ComputeSheet2D(nodes, buildIsHelix=1, nbrib=2, 37 nbchords=4, width=1.5, offset=1.2, **kw) 38 \nRequired Arguments:\n 39 nodes --- any set for MolKit nodes describing molecular components 40 \nOptional Arguments:\n 41 ctlAtmsName --- tuple of two atom name specifying the two control atoms 42 the second atom is used to limit the torsion of the sheet 43 2D. 44 \nbuildIsHelix --- flag when set to 1 specifies that an helix is defined. 45 \nnbrib --- integer specifying the number of ribbon of the sheet2D. 46 \nnbchords --- integer specifying the number of points per residues 47 \nwidth --- float specifying the width of the sheet2D 48 \noffset --- float specifying the offset of ? 49 50 \nRequired Packages:\n 51 MolKit, DejaVu, mglutil, OpenGL, Tkinter, Pmw, types, ViewerFramework 52 \nRequired Commands:\n 53 ExtrusionCommands.ComputeSheet2D, 54 \nKnown bugs:\n 55 None 56 \nExamples:\n 57 mol = mv.Mols[0] 58 \nmv.extrudeCATrace(mv.getSelection()) 59 60 """
61 - def __init__(self):
62 MVCommand.__init__(self)
63
64 - def __call__(self, nodes, sheet2DName, ctlAtmName, torsAtmName, 65 buildIsHelix=False, nbrib=2, nbchords=4, width=1.5, offset=1.2, 66 **kw):
67 """None <- ComputeSheet2D(nodes, sheet2DName, ctlAtmName, torsAtmName, 68 buildIsHelix=0, nbrib=2, nbchords=4, 69 width=1.5, offset=1.2, **kw) 70 \nnodes --- any set for MolKit nodes describing molecular components 71 \nctlAtmName --- tuple of two atom name specifying the two control atoms 72 the second atom is used to limit the torsion of the sheet 73 2D. 74 \nbuildIsHelix ---- Boolean flag when set to True specifies that an helix is defined. 75 \nnbrib --- integer specifying the number of ribbon of the sheet2D. 76 \nnbchords --- integer specifying the number of points per residues 77 \nwidth --- float specifying the width of the sheet2D 78 \noffset --- float specifying the offset of ? 79 """ 80 kw['buildIsHelix'] = buildIsHelix 81 kw['nbrib'] = nbrib 82 kw['nbchords'] = nbchords 83 kw['width'] = width 84 kw['offset'] = offset 85 if type(nodes) is types.StringType: 86 self.nodeLogString = "'"+nodes+"'" 87 88 nodes = self.vf.expandNodes(nodes) 89 apply(self.doitWrapper, (nodes, sheet2DName, ctlAtmName, torsAtmName), 90 kw)
91
92 - def getSheet2DRes(self, chain, ctlAtmName, torsAtmName, buildIsHelix=False):
93 isHelix = [] 94 sheetCoords = [] 95 from MolKit.protein import ResidueSet 96 sheet2DRes = ResidueSet() 97 residues = chain.residues 98 sheet2DResappend = sheet2DRes.append 99 isHelixappend = isHelix.append 100 for res in residues: 101 hasAtm, rCoords = res.getAtmsAndCoords([ctlAtmName, torsAtmName]) 102 if hasAtm == 0: 103 if len(sheet2DRes)== 0 or res.atoms[0].hetatm: 104 # if the residue without CA and O is at the beginning 105 # go on until you find the right residue 106 # or res.atoms[0].hetatm added ti fix bug#779 107 continue 108 else: 109 # Stop the sheet2D right there 110 return sheet2DRes, sheetCoords, isHelix 111 else: 112 sheet2DResappend(res) 113 sheetCoords = sheetCoords + rCoords 114 if buildIsHelix and hasattr(res, 'secondarystructure'): 115 sr = res.secondarystructure.structureType 116 isHelixappend(sr=='Helix') 117 else: 118 isHelixappend(0) 119 120 return sheet2DRes, sheetCoords, isHelix
121
122 - def doit(self, nodes, sheet2DName, ctlAtmName, torsAtmName, 123 buildIsHelix=False, nbrib=2, nbchords=4, width=1.5, offset=1.2):
124 from MolKit.protein import Chain 125 from types import StringType, IntType 126 """ Function that will compute the sheet2D elements for a molecule. 127 1- Get the residues with a CA and O and the coordinates of these 128 atoms. 129 """ 130 # Make sure that the given arguments are from the right type. 131 if not type(sheet2DName) is StringType: return 132 if not type(ctlAtmName) is StringType or not ctlAtmName: return 133 if not type(torsAtmName) is StringType or not torsAtmName: return 134 if not type(nbchords) is IntType: return 135 if len(nodes)==0: return 136 137 # Get the molecules having at least one node in the selection 138 139 # loop over the chains of the molecules. We want to compute 140 # the sheet2D for all the molecules not only the chain in the 141 # current selection. 142 chains = nodes.findType(Chain).uniq() 143 for chain in chains: 144 # Do not recompute the sheet2D if a entry with the same 145 # sheet2DName exists in the dictionary and the sheet2D 146 # has been computed with the same chords, ctlAtms... 147 if not hasattr(chain, 'sheet2D'): 148 chain.sheet2D = {} 149 150 if not chain.sheet2D.has_key(sheet2DName): 151 chain.sheet2D[sheet2DName] = Sheet2D() 152 else: 153 # If one of the parameter of the sheet2D is different then... 154 pass 155 156 sheet2DRes, sheetCoords, inHelix = self.getSheet2DRes(chain, 157 ctlAtmName, 158 torsAtmName, 159 buildIsHelix) 160 if sheetCoords is None or len(sheetCoords)<=2: 161 chain.sheet2D[sheet2DName] = None 162 continue 163 164 s = chain.sheet2D[sheet2DName] 165 s.compute(sheetCoords, inHelix, nbchords=nbchords, 166 nbrib=nbrib, width=width, offset=offset ) 167 s.resInSheet = sheet2DRes
168
169 - def buildFormDescr(self, formName):
170 if formName == 'computesheet2D': 171 172 idf = InputFormDescr(title ="Sheet 2D parameters :") 173 idf.append( {'name':'sheet2DName', 174 'widgetType':Pmw.EntryField, 175 'tooltip':'Name of the sheet2D', 176 'wcfg':{'label_text':"Name of the sheet2D:", 177 'labelpos':'w', 178 'entry_width':15 179 }, 180 'gridcfg':{'sticky':'w', "columnspan":2}}) 181 idf.append( {'name':'ctlAtms', 182 'widgetType':Pmw.EntryField, 183 'tooltip':'Type the name of atom to use as control atom.\n\ 184 (CA or C or O etc...)', 185 'wcfg':{'value':'CA', 186 'label_text':"Name of the control atom:", 187 'labelpos':'w', 188 'entry_width':3 189 }, 190 'gridcfg':{'sticky':'w'}}) 191 192 idf.append( {'name':'torsAtms', 193 'widgetType':Pmw.EntryField, 194 'tooltip':'Type the name of the atom to control the torsion of the sheet', 195 'wcfg':{'value':'O', 196 'label_text':"Name of the control atom:", 197 'labelpos':'w', 198 'entry_width':3 199 }, 200 'gridcfg':{'sticky':'w', 'row':-1}}) 201 202 idf.append( {'name': 'nbchords', 203 'widgetType':ExtendedSliderWidget, 204 'type':int, 205 'wcfg':{'label': 'nb. Pts Per Residue: ', 206 'minval':4,'maxval':15, 'incr': 1, 'init':4, 207 'labelsCursorFormat':'%d', 'sliderType':'int', 208 'entrywcfg':{'width':4}, 209 'entrypackcfg':{'side':'right'}}, 210 'gridcfg':{'columnspan':2,'sticky':'we'} 211 }) 212 213 idf.append( {'name': 'width', 214 'widgetType':ExtendedSliderWidget, 215 'type':float, 216 'wcfg':{'label': 'width ', 217 'minval':0.5,'maxval':5., 'incr':0.1, 218 'init':1.5, 219 'labelsCursorFormat':'%4.1f', 220 'sliderType':'float', 221 'entrywcfg':{'width':4}, 222 'entrypackcfg':{'side':'right'}}, 223 'gridcfg':{'columnspan':2,'sticky':'we'} 224 }) 225 226 idf.append( {'name': 'nbrib', 227 'widgetType':ExtendedSliderWidget, 228 'type':int, 229 'wcfg':{'label': 'Number of ribbons ', 230 'minval':2,'maxval':10, 'incr': 1, 'init':2, 231 'labelsCursorFormat':'%d', 'sliderType':'int', 232 'entrywcfg':{'width':4}, 233 'entrypackcfg':{'side':'right'}}, 234 'gridcfg':{'columnspan':2,'sticky':'we'} 235 }) 236 237 idf.append( {'name': 'offset', 238 'widgetType':ExtendedSliderWidget, 239 'type':float, 240 'wcfg':{'label': 'width ', 241 'minval':0.5,'maxval':5., 242 'incr':0.1, 'init':1.2, 243 'labelsCursorFormat':'%4.1f', 244 'sliderType':'float', 245 'entrywcfg':{'width':4}, 246 'entrypackcfg':{'side':'right'}}, 247 'gridcfg':{'columnspan':2,'sticky':'we'} 248 }) 249 idf.append( {'name': 'offset', 250 'widgetType':ExtendedSliderWidget, 251 'type':float, 252 'wcfg':{'label': 'width ', 253 'minval':0.5,'maxval':5., 254 'incr':0.1, 'init':1.2, 255 'labelsCursorFormat':'%4.1f', 256 'sliderType':'float', 257 'entrywcfg':{'width':4}, 258 'entrypackcfg':{'side':'right'}}, 259 'gridcfg':{'columnspan':2,'sticky':'we'} 260 }) 261 262 263 return idf
264
265 - def guiCallback(self):
266 val = self.showForm('computesheet2D') 267 if val == {}: 268 return 269 val['buildIsHelix']=0 270 sheet2DName = val['sheet2DName'] 271 del val['sheet2DName'] 272 ctlAtmName = val['ctlAtms'] 273 del val['ctlAtms'] 274 torsAtmName = val['torsAtms'] 275 del val['torsAtms'] 276 if self.vf.userpref['expandNodeLogString']['value'] == 0: 277 self.nodeLogString = "self.getSelection()" 278 279 apply(self.doitWrapper,(self.vf.getSelection(),sheet2DName , 280 ctlAtmName, torsAtmName), val)
281 282 ComputeSheet2DGUI = CommandGUI() 283 ComputeSheet2DGUI.addMenuCommand('menuRoot', 'Compute', 'sheet2D') 284
285 -class DisplayPath3DCommand(MVCommand):
286 """This Command displays the computed sheet2D for each chain of the contained in the current selection. 287 \nPackage : Pmv 288 \nModule : extrusionCommands 289 \nClass : DisplayPath3DCommand 290 \nCommand name : displayPath3D 291 \nSynopsis:\n 292 None <- displayPath3D(self, nodes, negate=False, only=False, **kw) 293 \nRequired Arguments:\n 294 nodes --- any set for MolKit nodes describing molecular components 295 """ 296
297 - def __init__(self, func=None):
298 MVCommand.__init__(self, func) 299 self.flag = self.flag | self.objArgOnly
300
301 - def onAddCmdToViewer(self):
302 if self.vf.hasGui and \ 303 not self.vf.commands.has_key('computeSheet2D'): 304 self.vf.loadCommand("extrusionCommands", 305 ["computeSheet2D",], "Pmv", 306 topCommand = 0)
307
308 - def onAddObjectToViewer(self,obj):
309 for c in obj.chains: 310 c.residues.rindex = range(len(c.residues))
311
312 - def createGeometries(self, obj):
313 from DejaVu.Geom import Geom 314 geomC = obj.geomContainer 315 c = Geom('path', shape=(0,0), protected=True) 316 c.replace = 'force' 317 geomC.addGeom(c, parent=geomC.masterGeom) 318 for a in obj.allAtoms: 319 a.colors['path']=(1.,1.,1.) 320 a.opacities['path']=1.0 321 322 for chain in obj.chains: 323 if not hasattr(chain, 'sheet2D') or chain.sheet2D is None: 324 continue 325 # HACK TO DEBUG SECONDARYSTRUCTURE 326 if not chain.sheet2D.has_key('ssSheet2D') or \ 327 chain.sheet2D['ssSheet2D'] is None: 328 continue 329 330 # Create a geometry per sheet2D 331 name = 'path'+ chain.id 332 g = Spheres( name, quality = 10, radii = 0.15, protected=True) 333 g.replace = 'force' 334 geomC.addGeom( g, parent=c) 335 self.managedGeometries.append(g) 336 # FIXME to update this geom we would have to implement 337 # self.updateGeom specifically for this command 338 339 geomC.atoms[name] = ResidueSet() 340 g.chain = chain 341 geomC.atomPropToVertices[name] = self.atomPropToVertices 342 geomC.geomPickToAtoms[name] = self.pickedVerticesToAtoms 343 geomC.geomPickToBonds[name] = None
344 345
346 - def pickedVerticesToAtoms(self, geom, vertInd):
347 """Function called to convert a picked vertex into an atom""" 348 349 # this function gets called when a picking or drag select event has 350 # happened. It gets called with a geometry and the list of vertex 351 # indices of that geometry that have been selected. 352 # This function is in charge of turning these indices into an AtomSet 353 chain = geom.chain 354 l = [] 355 for vi in vertInd: 356 resInd = self.getResInd( vi, chain ) 357 l.append(chain.residues[resInd].atoms[0]) 358 return AtomSet( AtomSet( l ) )
359
360 - def atomPropToVertices(self, geom, residues, propName, propIndex=None):
361 """Function called to compute the array of colors""" 362 if residues is None or len(residues)==0 : return None 363 residues.sort() 364 if not propIndex is None: 365 propIndex = geom.name 366 # chords = residues[0].parent.sheet2D.chords 367 chords = residues[0].parent.sheet2D['ssSheet2D'].chords 368 col = [residues[0].atoms[0].colors['path'],]*(chords/2+1) 369 for r in residues[1:-1]: 370 col = col + ([r.atoms[0].colors['path'],]*chords) 371 372 col = col + [residues[-1].atoms[0].colors['path'],]*(chords+chords/2) 373 # here need to compute the number of colors corresponding to the 374 # number of vertices. 375 return col
376 377
378 - def getResInd(self, vi, chain):
379 assert vi < len(chain.sheet2D['ssSheet2D'].path) 380 #assert vi < len(chain.sheet2D.path) 381 chords = chain.sheet2D['ssSheet2D'].chords 382 lengthPath = chain.sheet2D['ssSheet2D'].path.shape[0] 383 #chords = chain.sheet2D.chords 384 #lengthPath = chain.sheet2D.path.shape[0] 385 if vi < (chords/2 + 1 ): 386 # first residue 387 resIndex = 0 388 elif vi > ((lengthPath-1)-\ 389 (chords + chords/2)): 390 # last residue 391 resIndex = len(chain.residues)-1 392 else: 393 # all the other nbchords 394 resIndex = (vi-(2+ chords/2))/chords + 1 395 396 return resIndex
397
398 - def getResPts(self, residueindex, chain):
399 """ return the index of the first and the last point in the 400 Sheet2D.path for the residue whose index is specified""" 401 # a residue is represented in the path3D by chords points. 402 # first residue represented by nbchords/2 + 1 403 # last residue represented by nbchords+nbchords/2 404 # all other by nbchords. 405 #chords = chain.sheet2D.chords 406 chords = chain.sheet2D['ssSheet2D'].chords 407 #lengthPath = chain.sheet2D.path.shape[0] 408 lengthPath = chain.sheet2D['ssSheet2D'].path.shape[0] 409 if residueindex == 0: 410 fromPts = 0 411 toPts = chords/2 + 2 412 413 elif residueindex == len(chain.residues)-1: 414 fromPts = (residueindex-1) * chords + chords/2 +1 415 toPts = lengthPath-1 416 417 else: 418 fromPts = (residueindex-1) * chords + chords/2 +1 419 toPts = fromPts + chords +1 420 421 return fromPts,toPts
422
423 - def drawResidues(self,chain, res, only, negate):
424 mol = chain.parent 425 name = 'path'+chain.id 426 set = mol.geomContainer.atoms[name] 427 if negate : 428 set = set - res 429 ##if only, replace displayed set with current atms 430 else: 431 if only: 432 set = res 433 else: 434 set = res.union(set) 435 if len(set)==0: 436 mol.geomContainer.geoms[name].Set(visible=0, tagModified=False) 437 mol.geomContainer.atoms[name] = set 438 return 439 set.sort() 440 g = mol.geomContainer.geoms[name] 441 mol.geomContainer.atoms[name] = set 442 resVert = [] 443 lastres = chain.residues[-1].rindex 444 #p = chain.sheet2D.path 445 p = chain.sheet2D['ssSheet2D'].path 446 for res in set: 447 fromPts, toPts = self.getResPts(res.rindex, 448 chain) 449 if res.rindex == lastres: 450 resVert = resVert + (p[fromPts:].tolist()) 451 else: 452 resVert = resVert + (p[fromPts:toPts-1].tolist()) 453 454 g.Set(vertices = resVert, tagModified=False)
455
456 - def __call__(self, nodes, negate=False, only=False, **kw):
457 """ 458 None <- displayPath3D(self, nodes, negate=False, only=False, **kw) 459 460 """ 461 kw['negate'] = negate 462 kw['only'] = only 463 kw['redraw'] = True 464 nodes = self.vf.expandNodes(nodes) 465 if type(nodes) is types.StringType: 466 self.nodeLogString = "'" + nodes +"'" 467 apply(self.doitWrapper, (nodes,), kw)
468 469
470 - def doit(self, nodes, negate=False, only=False):
471 ################################################################# 472 473 molecules, residueSets = self.vf.getNodesByMolecule(nodes, Residue) 474 for mol,residues in map(None, molecules, residueSets): 475 for chain in mol.chains: 476 if not hasattr(chain, 'sheet2D'): 477 chain.sheet2D = {} 478 ## if not hasattr(mol, 'hasSheet2D') or not mol.hasSheet2D: 479 ## # compute a sheet2D need to put buildIsHelix = 0 here. 480 ## self.vf.ComputeSheet2D(mol, nbchords = 10, 481 ## buildIsHelix = 0, 482 ## topCommand=0,log=0) 483 if not chain.sheet2D.has_key('ssSheet2D'): 484 self.vf.computeSheet2D(chain, 'ssSheet2D', 485 'CA','O', buildIsHelix=1, 486 nbchords=4, 487 topCommand=0,log=0) 488 489 #if chain.sheet2D is None : continue 490 if chain.sheet2D['ssSheet2D'] is None : continue 491 492 self.createGeometries(mol) 493 self.drawResidues(chain, residues, only, negate)
494 495
496 - def buildFormDescr(self, formName):
497 if formName == 'display': 498 idf = InputFormDescr(title = self.name) 499 idf.append({'name':'display', 500 'widgetType':Pmw.RadioSelect, 501 'listtext':['display','display only', 'undisplay'], 502 'defaultValue':'display', 503 'wcfg':{'orient':'horizontal', 504 'buttontype':'radiobutton'}, 505 'gridcfg':{'sticky': 'we'}}) 506 return idf
507
508 - def guiCallback(self):
509 val = self.showForm('display') 510 511 if val: 512 if val['display']=='display': 513 val['only']= 0 514 val['negate'] = 0 515 del val['display'] 516 elif val['display']=='display only': 517 val['only']= 1 518 val['negate'] = 0 519 del val['display'] 520 elif val['display']== 'undisplay': 521 val['negate'] = 1 522 val['only'] = 0 523 del val['display'] 524 525 val['redraw'] = 1 526 apply( self.doitWrapper, (self.vf.getSelection(),), val )
527 528 DisplayPathGUI = CommandGUI() 529 DisplayPathGUI.addMenuCommand('menuRoot', 'Display', 'Path3D', 530 index = 0) 531
532 -class Nucleic_Acids_properties(MVCommand):
533 """The Nucleic_Acids_properties class implements methods for setting 534 Nucleic Acids colors and scaling factor. 535 \nPackage : Pmv 536 \nModule : extrusionCommands 537 \nClass : Nucleic_Acids_properties 538 \nCommand name : Nucleic_Acids_properties 539 """
540 - def __init__(self):
541 "Constructor for Nucleic_Acids_properties" 542 MVCommand.__init__(self) 543 self.color_A = [1,0,0] 544 self.color_C = [1,1,0] 545 self.color_U = [1,0.5,0] 546 self.color_G = [0,0,1] 547 self.color_T = [0,1,0] 548 self.scale_purine = self.scale_pyrimidine = 1.3 549 self.height_purine = self.height_pyrimidine = 0.4 550 self.color_backbone = 1
551 552
553 - def __call__(self, color_A = [1,0,0], color_G = [0,0,1], color_T = [0,1,0], 554 color_C = [1,1,0], color_U = [1,0.5,0], 555 scale_purine = 1.3, scale_pyrimidine = 1.3, 556 height_purine = 0.4, height_pyrimidine = 0.4, 557 color_backbone = 1, **kw):
558 """None <- Nucleic_Acids_properties(color_A = [1,0,0], 559 color_G = [0,0,1], color_T = [0,1,0], 560 color_C = [1,1,0], color_U = [1,0.5,0], 561 scale_purine = 1.3, scale_pyrimidine = 1.3, 562 height_purine = 0.4, height_pyrimidine = 0.4, 563 color_backbone = 1) 564 """ 565 566 apply(self.doitWrapper, (color_A, color_G, color_T, color_C, color_U, 567 height_purine, height_pyrimidine, 568 scale_purine, scale_pyrimidine), kw)
569 570
571 - def doit(self, color_A = [1,0,0], color_G = [0,0,1], color_T = [0,1,0], 572 color_C = [1,1,0], color_U = [1,0.5,0], 573 scale_purine = 1.3, scale_pyrimidine = 1.3, 574 height_purine = 0.4, height_pyrimidine = 0.4, 575 color_backbone = 1):
576 self.color_A = color_A 577 self.color_C = color_C 578 self.color_U = color_U 579 self.color_G = color_G 580 self.color_T = color_T 581 self.scale_purine = scale_purine 582 self.scale_pyrimidine = scale_pyrimidine 583 self.height_purine = height_purine 584 self.height_pyrimidine = height_pyrimidine 585 586 self.color_backbone = color_backbone
587
588 - def buildFormDescr(self, formName):
589 if formName == 'Display': 590 idf = InputFormDescr(title = 591 "Set Nucleic Acids colors and scaling factor") 592 idf.append( {'name':'Purines', 593 'widgetType':Pmw.Group, 594 'container':{'Purines':'w.interior()'}, 595 'wcfg':{'tag_text':'Purines', 596 }, 597 'gridcfg':{'sticky':'wens'} 598 }) 599 self.A_rgb = (255*self.color_A[0], 255*self.color_A[1], 600 255*self.color_A[2]) 601 self.hex_color_A = "#%02x%02x%02x" % (self.A_rgb) 602 idf.append( {'name':'colorA', 603 'widgetType':Tkinter.Button, 604 'tooltip':'Click to change the color', 605 'parent':'Purines', 606 'wcfg':{'text':'Adenine', 607 'command':self.set_color_A, 608 'font':'Helvetica 12 bold', 609 'bg':self.hex_color_A, 610 'width':8, 611 'relief':'ridge' 612 }, 613 'gridcfg':{'sticky':'w', 'row':0,'column':0}}) 614 615 self.G_rgb = (255*self.color_G[0], 255*self.color_G[1], 616 255*self.color_G[2]) 617 self.hex_color_G = "#%02x%02x%02x" % (self.G_rgb) 618 idf.append( {'name':'colorG', 619 'widgetType':Tkinter.Button, 620 'tooltip':'Click to change the color', 621 'parent':'Purines', 622 'wcfg':{'text':'Guanine', 623 'command':self.set_color_G, 624 'font':'Helvetica 12 bold', 625 'bg':self.hex_color_G, 626 'width':8, 627 'relief':'ridge' 628 }, 629 'gridcfg':{'sticky':'w', 'row':1,'column':0}}) 630 631 idf.append( {'name': 'height_purine', 632 'widgetType':ExtendedSliderWidget, 633 'parent':'Purines', 634 'wcfg':{'label': "Height", 635 'minval':0.01,'maxval':1, 'incr': 0.01, 'init':0.4, 636 'labelsCursorFormat':'%1.2f', 'sliderType':'float', 637 'entrywcfg':{'width':4}, 638 'entrypackcfg':{'side':'right'}}, 639 'gridcfg':{'row':0,'column':1,'sticky':'we'} 640 }) 641 642 idf.append( {'name': 'scale_purine', 643 'widgetType':ExtendedSliderWidget, 644 'parent':'Purines', 645 'wcfg':{'label': " Scale", 646 'minval':0.5,'maxval':2, 'incr': 0.01, 'init':1.3, 647 'labelsCursorFormat':'%1.2f', 'sliderType':'float', 648 'entrywcfg':{'width':4}, 649 'entrypackcfg':{'side':'right'}}, 650 'gridcfg':{'row':1,'column':1,'sticky':'we'} 651 }) 652 653 idf.append( {'name':'Pyrimidines', 654 'widgetType':Pmw.Group, 655 'container':{'Pyrimidines':'w.interior()'}, 656 'wcfg':{'tag_text':'Pyrimidines', 657 }, 658 'gridcfg':{'sticky':'wens'} 659 }) 660 661 self.T_rgb = (255*self.color_T[0], 255*self.color_T[1], 662 255*self.color_T[2]) 663 self.hex_color_T = "#%02x%02x%02x" % (self.T_rgb) 664 idf.append( {'name':'colorT', 665 'widgetType':Tkinter.Button, 666 'tooltip':'Click to change the color', 667 'parent':'Pyrimidines', 668 'wcfg':{'text':'Thymine', 669 'command':self.set_color_T, 670 'font':'Helvetica 12 bold', 671 'bg':self.hex_color_T, 672 'width':8, 673 'relief':'ridge' 674 }, 675 'gridcfg':{'sticky':'w', 'row':2,'column':0}}) 676 677 self.C_rgb = (255*self.color_C[0], 255*self.color_C[1], 678 255*self.color_C[2]) 679 self.hex_color_C = "#%02x%02x%02x" % (self.C_rgb) 680 idf.append( {'name':'colorC', 681 'widgetType':Tkinter.Button, 682 'tooltip':'Click to change the color', 683 'parent':'Pyrimidines', 684 'wcfg':{'text':'Cytosine', 685 'command':self.set_color_C, 686 'font':'Helvetica 12 bold', 687 'bg':self.hex_color_C, 688 'width':8, 689 'relief':'ridge' 690 }, 691 'gridcfg':{'sticky':'w', 'row':3,'column':0}}) 692 self.U_rgb = (255*self.color_U[0], 255*self.color_U[1], 693 255*self.color_U[2]) 694 self.hex_color_U = "#%02x%02x%02x" % (self.U_rgb) 695 idf.append( {'name':'colorU', 696 'widgetType':Tkinter.Button, 697 'tooltip':'Click to change the color', 698 'parent':'Pyrimidines', 699 'wcfg':{'text':'Uracil', 700 'command':self.set_color_U, 701 'font':'Helvetica 12 bold', 702 'bg':self.hex_color_U, 703 'width':8, 704 'relief':'ridge' 705 }, 706 'gridcfg':{'sticky':'w', 'row':4,'column':0}}) 707 708 709 idf.append( {'name': 'height_pyrimidine', 710 'widgetType':ExtendedSliderWidget, 711 'parent':'Pyrimidines', 712 'type':int, 713 'wcfg':{'label': "Height", 714 'minval':0.01,'maxval':1, 'incr': 0.01, 'init':0.4, 715 'labelsCursorFormat':'%1.2f', 'sliderType':'float', 716 'entrywcfg':{'width':4}, 717 'entrypackcfg':{'side':'right'}}, 718 'gridcfg':{'row':3,'column':1,'sticky':'we'} 719 }) 720 721 idf.append( {'name': 'scale_pyrimidine', 722 'widgetType':ExtendedSliderWidget, 723 'parent':'Pyrimidines', 724 'type':int, 725 'wcfg':{'label': " Scale", 726 'minval':0.5,'maxval':2, 'incr': 0.01, 'init':1.3, 727 'labelsCursorFormat':'%1.2f', 'sliderType':'float', 728 'entrywcfg':{'width':4}, 729 'entrypackcfg':{'side':'right'}}, 730 'gridcfg':{'row':4,'column':1,'sticky':'we'} 731 }) 732 733 idf.append( {'name':'color_backbone', 734 'widgetType':Tkinter.Checkbutton, 735 'defaultValue':1, 736 'wcfg':{'text':'Color ribbon using these colors', 737 'variable': Tkinter.IntVar() 738 }, 739 'gridcfg':{'sticky':'ew', 'row':5,'column':0}}) 740 741 self.idf = idf 742 return idf
743
744 - def guiCallback(self):
745 val = self.showForm('Display') 746 if val: 747 color_A = [self.A_rgb[0]/255.,self.A_rgb[1]/255.,self.A_rgb[2]/255.] 748 color_G = [self.G_rgb[0]/255.,self.G_rgb[1]/255.,self.G_rgb[2]/255.] 749 color_T = [self.T_rgb[0]/255.,self.T_rgb[1]/255.,self.T_rgb[2]/255.] 750 color_C = [self.C_rgb[0]/255.,self.C_rgb[1]/255.,self.C_rgb[2]/255.] 751 color_U = [self.U_rgb[0]/255.,self.U_rgb[1]/255.,self.U_rgb[2]/255.] 752 scale_purine = self.idf.entryByName['scale_purine']['widget'].get() 753 scale_pyrimidine = self.idf.entryByName['scale_pyrimidine']\ 754 ['widget'].get() 755 height_purine = self.idf.entryByName['height_purine']['widget'].get() 756 height_pyrimidine = self.idf.entryByName['height_pyrimidine']\ 757 ['widget'].get() 758 759 color_backbone = val['color_backbone'] 760 apply(self.doitWrapper,(color_A, color_G, color_T, color_C, color_U, 761 scale_purine, scale_pyrimidine, 762 height_purine, height_pyrimidine, 763 color_backbone))
764
765 - def set_color_A(self):
766 rgb, hex = askcolor(self.hex_color_A) 767 if hex: 768 self.A_rgb = rgb 769 self.idf.entryByName['colorA']['widget'].config(bg=hex)
770
771 - def set_color_G(self):
772 rgb, hex = askcolor(self.hex_color_G) 773 if hex: 774 self.G_rgb = rgb 775 self.idf.entryByName['colorG']['widget'].config(bg=hex)
776
777 - def set_color_T(self):
778 rgb, hex = askcolor(self.hex_color_T) 779 if hex: 780 self.T_rgb = rgb 781 self.idf.entryByName['colorT']['widget'].config(bg=hex)
782
783 - def set_color_C(self):
784 rgb, hex = askcolor(self.hex_color_C) 785 if hex: 786 self.C_rgb = rgb 787 self.idf.entryByName['colorC']['widget'].config(bg=hex)
788
789 - def set_color_U(self):
790 rgb, hex = askcolor(self.hex_color_U) 791 if hex: 792 self.U_rgb = rgb 793 self.idf.entryByName['colorU']['widget'].config(bg=hex)
794 795 commandList = [{'name': 'computeSheet2D','cmd': ComputeSheet2DCommand(), 796 'gui':None}, 797 {'name': 'displayPath3D','cmd': DisplayPath3DCommand(), 798 'gui':DisplayPathGUI}, 799 {'name': 'Nucleic_Acids_properties', 800 'cmd': Nucleic_Acids_properties(), 'gui':None} 801 ] 802
803 -def initModule(viewer):
804 """ initializes commands for secondary structure and extrusion. Also 805 imports the commands for Secondary Structure specific coloring, and 806 initializes these commands also. """ 807 for dict in commandList: 808 viewer.addCommand(dict['cmd'], dict['name'], dict['gui'])
809