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

Source Code for Module Pmv.amberCommands

   1  ############################################################################ 
   2  # 
   3  # Author: Ruth HUEY, Michel F. SANNER 
   4  # 
   5  # Copyright: M. Sanner TSRI 2000 
   6  # 
   7  ############################################################################# 
   8   
   9  # $Header: /opt/cvs/python/packages/share1.5/Pmv/amberCommands.py,v 1.39 2007/05/03 21:52:06 vareille Exp $ 
  10  # 
  11  # $Id: amberCommands.py,v 1.39 2007/05/03 21:52:06 vareille Exp $ 
  12  # 
  13   
  14  import Tkinter, Numeric 
  15  import Pmw 
  16  import glob 
  17  from math import pi, sqrt, ceil 
  18  from string import split, strip 
  19  from os.path import basename, exists 
  20  from types import StringType 
  21   
  22  from sff.amber import Amber94, AmberParm 
  23  from sff.amber import prmlib 
  24  from sff.amber import BinTrajectory 
  25   
  26  from ViewerFramework.VFCommand import CommandGUI 
  27   
  28  from Pmv.mvCommand import MVCommand 
  29  from Pmv.stringSelectorGUI import StringSelectorGUI 
  30   
  31  from MolKit.molecule import Atom, AtomSet, Bond 
  32  from MolKit.protein import Chain,Residue 
  33  from MolKit.amberPrmTop import Parm 
  34  from MolKit import data 
  35   
  36  from mglutil.gui.InputForm.Tk.gui import InputFormDescr 
  37  from mglutil.gui.BasicWidgets.Tk.customizedWidgets import ListChooser 
  38  from mglutil.gui.BasicWidgets.Tk.thumbwheel import ThumbWheel 
  39  from mglutil.util.callback import CallBackFunction 
  40   
  41  from DejaVu.Geom import Geom 
  42  from DejaVu.Spheres import Spheres 
  43  from DejaVu.IndexedPolylines import IndexedPolylines 
  44   
  45  from DejaVu.glfLabels import GlfLabels 
  46   
  47  Amber94Config = {} 
  48  CurrentAmber94 = {} 
  49   
  50   
  51   
52 -class SetupAmber94(MVCommand):
53 """This command creates an instance of Amber94 class and enters it in Amber94Config dictionary with specified name as the key. The Amber94 instance requires a Parm instance, which can be built from scratch or readin from a file. 54 \nPackage : Pmv 55 \nModule : amberCommands 56 \nClass : SetupAmber94 57 \nCommand : setupAmber94 58 \nSynopsis:\n 59 None<-setup_Amber94(chains, key, filename=None, dataDict={}, **kw)\n 60 \nArguments:\n 61 chains --- atoms to be minimized\n 62 key --- identifier to be key for this Amber94 instance in Amber94Config dictionary\n 63 filename --- optional filename to read in for prmtop\n 64 dataDict --- optional dictionary of parameter data to use for Parm instance\n 65 """ 66 67 68 from Pmv.amberCommands import CurrentAmber94 69 70
71 - def __init__(self):
72 MVCommand.__init__(self) 73 self.useFile = Tkinter.IntVar() 74 self.useFile.set(0) 75 self.specData = Tkinter.IntVar() 76 self.specData.set(0) 77 self.file = None 78 self.keyStr = Tkinter.StringVar() 79 self.fileTypes = [('prm files:', '*.prm'), ('prmtop files:', '*.prmtop'), ('allfiles', '*')] 80 self.fileBrowserTitle = "Read Amber PrmTop File" 81 self.lastDir = "."
82 83
84 - def __call__(self, chains, key, filename=None, dataDict = {},**kw):
85 """None<---setup_Amber94(chains, key, filename=None, dataDict={}, **kw) 86 \nchains --- atoms to be minimized 87 \nkey --- identifier to be key for this Amber94 instance in Amber94Config dictionary 88 \nfilename --- optional filename to read in for prmtop 89 \ndataDict --- optional dictionary of parameter data to use for Parm instance 90 """ 91 chains = self.vf.expandNodes(chains) 92 if not len(chains): 93 return 'ERROR' 94 chains = chains.findType(Chain) 95 kw['dataDict'] = dataDict 96 kw['filename'] = filename 97 return apply(self.doitWrapper, (chains, key), kw)
98 99
100 - def doit(self, chains, key, **kw):
101 atoms = chains.residues.atoms 102 filename = kw['filename'] 103 if filename is not None: 104 if not exists(filename): 105 print filename, " does not exist" 106 return "ERROR" 107 amb_ins = Amber94(atoms, prmfile=filename) 108 #this doesn't work!!! 109 #parmtop.loadFromFile(filename) 110 else: 111 dataDict = kw.get('dataDict', {}) 112 print 'calling Amber94 init with dataDict=', dataDict 113 amb_ins = Amber94(atoms, dataDict = dataDict) 114 amb_ins.key = key 115 Amber94Config[key] = [amb_ins] 116 self.CurrentAmber94 = amb_ins 117 print 'set CurrentAmber94 to', self.CurrentAmber94
118 #Amber94Config values will be a list where instance is list[0] and 119 #sets of parms used for minimizations the rest.... 120 121
122 - def getFile(self, event=None):
123 if self.useFile.get(): 124 self.file = self.vf.askFileOpen(types=self.fileTypes, 125 idir = self.lastDir, 126 title=self.fileBrowserTitle)
127 128
129 - def guiCallback(self):
130 # a molecule must present first 131 if not len(self.vf.Mols): 132 self.warningMsg('must load molecule first') 133 return "ERROR" 134 nodes = self.vf.getSelection() 135 if not len(nodes): 136 self.warningMsg('nothing in the selection') 137 return "ERROR" 138 #FIX THIS: need to process atoms in units of whole chains 139 chains = nodes.findType(Chain).uniq() 140 ifd = self.ifd = InputFormDescr(title = " Set Up Amber94 instance:") 141 ifd.append({'name':'fileRB0', 142 'widgetType':Tkinter.Radiobutton, 143 'wcfg':{'text':'Read from file', 144 'variable': self.useFile, 145 'command': self.getFile, 146 'value':1, 147 }, 148 'gridcfg':{'sticky':'w'}}) 149 ifd.append({'name':'fileRB1', 150 'widgetType':Tkinter.Radiobutton, 151 'wcfg':{'text':'Build from atoms', 152 'variable': self.useFile, 153 'value':0, 154 }, 155 'gridcfg':{'sticky':'w', 'row':-1, 'column':1}}) 156 ifd.append({'name':'parmDCB', 157 'widgetType':Tkinter.Checkbutton, 158 'wcfg':{'text':'Specify parm data', 159 'variable': self.specData, 160 'command': self.setData, 161 }, 162 'gridcfg':{'sticky':'w', 'row':-1, 'column':2}}) 163 ifd.append({'name': 'nameStr', 164 'widgetType':Tkinter.Entry, 165 'wcfg':{ 166 'label': 'Enter identifier', 167 'textvariable': self.keyStr, 168 }, 169 'gridcfg':{'sticky':'we', 'columnspan':3}}) 170 vals = self.vf.getUserInput(self.ifd, modal=0, blocking=1, okcancel=1) 171 if len(vals)>0: 172 if not self.useFile.get(): 173 file = None 174 else: 175 file = self.file 176 key = vals['nameStr'] 177 kw = {} 178 if hasattr(self, 'dataDict'): 179 kw['dataDict'] = self.dataDict 180 kw['filename'] = file 181 return apply(self.doitWrapper, (chains, key), kw) 182 else: 183 return 'ERROR'
184 185
186 - def setData(self, event=None):
187 print 'in setData' 188 #self.ifd.entryByName['parmDCB']['widget'].toggle() 189 if not self.specData.get(): 190 return 191 192 #build lists of available data parameter files 193 #which are in MolKit/data and end in [nt,ct,,]_dat.py 194 #nt files end in nt_dat.py 195 #ct files end in ct_dat.py 196 #the rest _dat.py 197 ntList = [] 198 for i in glob.glob(data.__path__[0] + '/*nt_dat.py'): 199 ent = split(basename(i),'.')[0] 200 ntList.append((ent, None)) 201 #ntList.append((basename(i), None)) 202 for i in glob.glob(data.__path__[0] + '/*nt94_dat.py'): 203 ent = split(basename(i),'.')[0] 204 ntList.append((ent, None)) 205 #ntList.append((basename(i), None)) 206 ctList = [] 207 for i in glob.glob(data.__path__[0] + '/*ct_dat.py'): 208 ent = split(basename(i),'.')[0] 209 ctList.append((ent, None)) 210 #ctList.append((basename(i), None)) 211 for i in glob.glob(data.__path__[0] + '/*ct94_dat.py'): 212 ent = split(basename(i),'.')[0] 213 ctList.append((ent, None)) 214 #ctList.append((basename(i), None)) 215 allList = [] 216 for i in glob.glob(data.__path__[0] + '/*_dat.py'): 217 n = basename(i) 218 ent = split(basename(i),'.')[0] 219 t = (ent, None) 220 if not (t in ntList) and not (t in ctList): 221 allList.append(t) 222 #allList.append((n, None)) 223 ifd2 = InputFormDescr(title = " Select Amber94 data dictionaries:") 224 ifd2.append({'name':'allDictLB', 225 'widgetType':ListChooser, 226 'wcfg':{'entries':allList, 227 'mode': 'multiple', 228 'title': 'data files for\n\nnon-terminal residues:', 229 #'command': 230 'lbwcfg':{'height':5, 231 'selectforeground': 'red', 232 'exportselection': 0, 233 'width': 30}, 234 }, 235 'gridcfg':{'sticky':'we'}}) 236 ifd2.append({'name':'ntDictLB', 237 'widgetType':ListChooser, 238 'wcfg':{'entries':ntList, 239 'mode': 'multiple', 240 'title': 'n-terminus residues:', 241 #'command': 242 'lbwcfg':{'height':5, 243 'selectforeground': 'red', 244 'exportselection': 0, 245 'width': 30}, 246 }, 247 'gridcfg':{'sticky':'we'}}) 248 ifd2.append({'name': 'ctDictLB', 249 'widgetType':ListChooser, 250 'wcfg':{'entries':ctList, 251 'mode': 'multiple', 252 'title': 'c-terminus residues:', 253 #'command': 254 'lbwcfg':{'height':5, 255 'selectforeground': 'red', 256 'exportselection': 0, 257 'width': 30}, 258 }, 259 'gridcfg':{'sticky':'we'}}) 260 vals2 = self.vf.getUserInput(ifd2, modal=0, blocking=1, okcancel=1) 261 if len(vals2)>0: 262 dataDict = self.dataDict = {} 263 dataDict['allDictList'] = vals2['allDictLB'] 264 dataDict['ntDictList'] = vals2['ntDictLB'] 265 dataDict['ctDictList'] = vals2['ctDictLB']
266 267 268 269 SetupAmber94CommandGUI = CommandGUI() 270 SetupAmber94CommandGUI.addMenuCommand('menuRoot', 'Amber', 'Setup Amber94') 271 272 273
274 -class SetMinimOptsAmber94(MVCommand):
275 """ 276 This class allows you to set minimization options of a Amber94 instance 277 These options include cut, nsnb, dield and verbose. NB: this is written as 278 a separate class in order to create a clear log. 279 \nPackage : Pmv 280 \nModule : amberCommands 281 \nClass : SetMinimOptsAmber94 282 \nCommand : setMinimOptsAmber94 283 \nSynopsis:\n 284 None<-setminimOpts_Amber94(key, **kw) 285 \nArguments:\n 286 key --- identifier to be key for this Amber94 instance in Amber94Config dictionary\n 287 """ 288 289 from Pmv.amberCommands import CurrentAmber94 290 291
292 - def __call__(self, key, **kw):
293 """ 294 None<-setminimOpts_Amber94(key, **kw) 295 296 """ 297 return apply(self.doitWrapper, (key,), kw)
298 299
300 - def doit(self, key, **kw):
301 if key not in Amber94Config.keys(): 302 print 'key: ', key, " is not in current Amber94Config " 303 return 'ERROR' 304 amber94instance = Amber94Config[key][0] 305 amb_ins = self.CurrentAmber94 = amber94instance 306 for k in kw.keys(): 307 assert k in ['cut', 'nsnb', 'ntpr', 'scnb','scee', 308 'mme_init_first', 'dield', 'verbosemm'] 309 apply(amb_ins.setMinimizeOptions, (), kw)
310 311
312 - def Close_cb(self, ifd, event=None):
313 form = ifd.form 314 form.withdraw()
315 316
317 - def buildForm(self):
318 ifd = self.ifd = InputFormDescr(title = "Set parameters for amber94 minimization:") 319 self.verbose = Tkinter.StringVar() 320 self.verbose.set('print summary') 321 self.verbose_list = ['no print out', 'print summary', 'print summary w/energies'] 322 self.dield = Tkinter.IntVar() 323 self.dield.set(1) 324 self.id = Tkinter.StringVar() 325 self.id.set(self.CurrentAmber94.key) 326 #self.id.set(Amber94Config.keys()[0]) 327 ifd.append({'widgetType':Pmw.ComboBox, 328 'name':'amberIds', 329 'wcfg':{'label_text':'Amber94 ids', 330 'entryfield_value':self.id.get(), 331 'labelpos':'w', 332 'listheight':'80', 333 'scrolledlist_items': Amber94Config.keys(), 334 'selectioncommand': self.update, 335 }, 336 'gridcfg':{'sticky':'w'}}) 337 ifd.append({'widgetType':Pmw.ComboBox, 338 'name':'verbose_cb', 339 'wcfg':{'label_text':'', 340 'entryfield_value':self.verbose.get(), 341 'labelpos':'w', 342 'listheight':'80', 343 'scrolledlist_items': self.verbose_list, 344 }, 345 'gridcfg':{'sticky':'w'}}) 346 ifd.append({'name':'dield_cb', 347 'widgetType':Tkinter.Checkbutton, 348 'wcfg':{'text':'dield -constant dielectric function', 349 'variable': self.dield, 350 }, 351 'gridcfg':{'sticky':'w', 'row':-1, 'column':1 }}) 352 ifd.append({'name':'cut_tw', 353 'widgetType':ThumbWheel, 354 'wType':ThumbWheel, 355 'wcfg':{ 'labCfg':{ 356 'text': 'cut -cutoff distance non-bonded interactions', 357 }, 358 'type':'float', 359 'min':1.0,'max':3000.0, 360 'precision':2, 361 'width':100, 362 'continuous':1, 363 'wheelPad':2, 364 'height':20, 365 'value':8., 366 'oneTurn':50.,}, 367 'gridcfg':{'columnspan':2,'sticky':'e'}}) 368 ifd.append({'name':'nsnb_tw', 369 'widgetType':ThumbWheel, 370 'wType':ThumbWheel, 371 'wcfg':{ 'labCfg':{ 372 'text': 'nsnb -number of steps between non-bonded pairlist updates', 373 }, 374 'type':'int', 375 'min':1,'max':5000, 376 #'precision':2, 377 'width':100, 378 'continuous':1, 379 'wheelPad':2, 380 'height':20, 381 'value':25, 382 'oneTurn':50.,}, 383 'gridcfg':{'columnspan':2,'sticky':'e'}}) 384 ifd.append({'name':'ntpr_tw', 385 'widgetType':ThumbWheel, 386 'wType':ThumbWheel, 387 'wcfg':{ 'labCfg':{ 388 'text': 'ntpr -number of steps between print out of energy information', 389 }, 390 'type':'int', 391 'min':5,'max':5000, 392 #'precision':2, 393 'width':100, 394 'continuous':1, 395 'wheelPad':2, 396 'height':20, 397 'value':50, 398 'oneTurn':50.,}, 399 'gridcfg':{'columnspan':2,'sticky':'e'}}) 400 ifd.append({'widgetType': Tkinter.Button, 401 'text':'Accept', 402 'wcfg':{'bd':6}, 403 'gridcfg':{'sticky':'we'}, 404 'command':self.Accept_cb}) 405 ifd.append({'widgetType': Tkinter.Button, 406 'text':'Cancel', 407 'wcfg':{'bd':6}, 408 'gridcfg':{'sticky':'we', 'column':1,'row':-1}, 409 'command':CallBackFunction(self.Close_cb, ifd)}) 410 self.form = self.vf.getUserInput(self.ifd, modal=0, blocking=0) 411 self.form.root.protocol('WM_DELETE_WINDOW', CallBackFunction(self.Close_cb,ifd))
412 413
414 - def Accept_cb(self, event=None):
415 #FIX THIS!! 416 self.form.withdraw() 417 #get the setupAmber94instance 418 key = self.ifd.entryByName['amberIds']['widget'].get() 419 amb_ins = Amber94Config[key][0] 420 #update minimization Options 421 minOptD = {} 422 for v in ['cut_tw', 'nsnb_tw','ntpr_tw']: 423 val = self.ifd.entryByName[v]['widget'].get() 424 s = split(v,'_')[0] 425 minOptD[s] = val 426 #ideally want to set amber.prmlib.cvar.nsnb etc...??? 427 w = self.ifd.entryByName['verbose_cb']['widget'].get() 428 if w not in self.verbose_list: 429 minOptD['verbosemm'] = 1 430 else: 431 minOptD['verbosemm'] = self.verbose_list.index(w) 432 minOptD['dield'] = self.dield.get() 433 apply(self.doitWrapper, (key,), minOptD )
434 #apply(amb_ins.setMinimizeOptions,(),minOptD) 435 436
437 - def update(self, event=None):
438 key = self.ifd.entryByName['amberIds']['widget'].get() 439 amb_ins = Amber94Config[key] 440 self.CurrentAmber94 = amb_ins
441 #THIS SHOULD ADJUST THE DISPLAYED PARAMETERS.... 442 #for w in []: 443 #FIX THIS!!! 444 #newval = amber.prmlib.cvar.+ key 445 446
447 - def guiCallback(self):
448 if not len(Amber94Config.keys()): 449 self.warningMsg('no Amber94 objects present: SetupAmber94 first') 450 return 'ERROR' 451 452 if self.CurrentAmber94=={}: 453 self.CurrentAmber94 = Amber94Config.values()[0][0] 454 455 #ALLOW USER TO SET parameters here 456 if not hasattr(self, 'ifd'): 457 self.buildForm() 458 else: 459 lb = self.ifd.entryByName['amberIds']['widget']._list 460 #make sure to update the listbox: 461 lb.delete(0, 'end') 462 for k in Amber94Config.keys(): 463 lb.insert('end', k) 464 self.form.deiconify()
465 466 467 SetMinimOptsAmber94CommandGUI = CommandGUI() 468 SetMinimOptsAmber94CommandGUI.addMenuCommand('menuRoot', 'Amber', 'Minimization', 469 cascadeName = 'Set Options') 470 471 472
473 -class MinimizeAmber94(MVCommand):
474 """ 475 This class allows you to select an Amber94 instance from Amber94Config 476 whose keys are ids specified in setup_Amber94 for the Amber94 instances. 477 You can also set minimization options, freeze atoms, specify constrained 478 atoms and anchor atoms and set maxIter, drms and dfpred. The minimization 479 can be run repeatedly. 480 \nPackage : Pmv 481 \nModule : amberCommands 482 \nClass : MinimizeAmber94 483 \nCommand : minimizeAmber94 484 \nSynopsis:\n 485 return_code<-minimize_amber94(key, **kw) 486 \nArguments:\n 487 key --- key into Amber94Config dictionary\n 488 """ 489 490 from Pmv.amberCommands import CurrentAmber94 491
492 - def onAddCmdToViewer(self):
493 self.energyLabel = GlfLabels('minimize Energy', 494 inheritMaterial=0, 495 shape=(0,3)) 496 self.vf.GUI.VIEWER.AddObject(self.energyLabel)
497 498
499 - def __call__(self, key, **kw):
500 """return_code<-minimize_amber94(key, **kw) 501 502 \npossible return codes:\n 503 >0 converged, final iteration number\n 504 -1 bad line search, probably an error in the relation 505 of the funtion to its gradient (perhaps from 506 round-off if you push too hard on the minimization).\n 507 -2 search direction was uphill\n 508 -3 exceeded the maximum number of iterations\n 509 -4 could not further reduce function value\n 510 -5 stopped via signal (bsd)\n 511 512 key is key into Amber94Config dictionary\n 513 \nkw is dictionary with keys:\n 514 maxIter -maximum number of iterations\n 515 drms -convergence criterion for energy gradient\n 516 dfpred -predicted drop in conj grad func on 1st iteration\n 517 \nkeys removed before call to minimize:\n 518 callback\n 519 callback_freq\n 520 """ 521 return apply(self.doitWrapper, (key,), kw)
522 523
524 - def doit(self, key, **kw):
525 if key not in Amber94Config.keys(): 526 print 'key: ', key, " is not in current Amber94Config " 527 return 'ERROR' 528 amber94instance = Amber94Config[key][0] 529 amb = self.CurrentAmber94 = amber94instance 530 531 #FIX THIS: 532 #HOW DO YOU TURN OFF THE CALLBACK???? by setting freq to 0? 533 freq = int(kw.get('callback_freq', 0)) 534 callback = kw.get('callback') 535 536 for k in ['callback_freq', 'callback']: 537 if kw.has_key(k): 538 del kw[k] 539 #if kw.has_key('callback'): 540 #del kw['callback'] 541 #del kw['callback'] 542 if callback: 543 #add the coords here 544 if not hasattr(amb, 'coord_index'): 545 amb.atoms.addConformation(amb.atoms.coords[:]) 546 amb.coord_index = len(amb.atoms[0]._coords)-1 547 #freq = int(self.callbackFreq.get()) 548 print 'setting callback to updateCoords' 549 amb.setCallback(self.updateCoords, freq) 550 551 return_code = apply(amber94instance.minimize,(), kw) 552 print 'return_code=', return_code 553 return return_code
554 555
556 - def updateCoords(self, cbNum=0, nbat=300, coords=[], energies=[], step=[]):
557 #FIX THIS 558 #print 'in updateCoords' 559 amb = self.CurrentAmber94 560 mols = amb.atoms.top.uniq() 561 allAtoms = mols.chains.residues.atoms 562 newcoords = Numeric.array(amb.coords[:]) 563 newcoords.shape = (-1,3) 564 allAtoms.updateCoords(newcoords.tolist(), amb.coord_index) 565 self.vf.displayLines(allAtoms, topCommand=0) 566 pos = Numeric.maximum.reduce(amb.atoms.coords).astype('f') 567 self.energyLabel.Set(vertices=[pos], 568 labels=[str(amb.energies[8])], tagModified=False) 569 self.vf.GUI.VIEWER.currentCamera.update()
570 571
572 - def Close_cb(self, ifd, event=None):
573 form = ifd.form 574 form.withdraw()
575 576
577 - def buildForm(self):
578 ifd = self.ifd = InputFormDescr(title = "Minimize amber94:") 579 self.verbose = Tkinter.StringVar() 580 self.verbose.set('print summary') 581 self.dield = Tkinter.IntVar() 582 self.dield.set(1) 583 self.callback = Tkinter.IntVar() 584 self.callbackFreq = Tkinter.StringVar() 585 self.callbackFreq.set('10') 586 self.id = Tkinter.StringVar() 587 #self.id.set(Amber94Config.keys()[0]) 588 self.id.set(self.CurrentAmber94.key) 589 frozNum = Numeric.add.reduce(self.CurrentAmber94.frozen) 590 self.frozenLab = Tkinter.StringVar() 591 fstr = 'Currently ' + str(frozNum) + ' frozen atoms' 592 self.constrLab = Tkinter.StringVar() 593 constrNum = Numeric.add.reduce(self.CurrentAmber94.constrained) 594 cstr = 'Currently ' + str(constrNum) + ' constrained atoms' 595 self.constrLab.set(cstr) 596 ifd.append({'widgetType':Pmw.ComboBox, 597 'name':'amberIds', 598 'wcfg':{'label_text':'Amber94 ids', 599 'entryfield_value':self.id.get(), 600 'labelpos':'w', 601 'listheight':'80', 602 'scrolledlist_items': Amber94Config.keys(), 603 'selectioncommand': self.update, 604 }, 605 'gridcfg':{'sticky':'w'}}) 606 #'gridcfg':{'sticky':'nesw','row':-1, 'column':1}}), 607 ifd.append({'name':'setminopts_cb', 608 'widgetType':Tkinter.Checkbutton, 609 'wcfg':{'text':'set minimization options', 610 'command': self.setMinOpts, 611 }, 612 'gridcfg':{'sticky':'w', 'row':-1,'column':1}}) 613 ifd.append({'name':'frozen_lab', 614 'widgetType': Tkinter.Label, 615 'textvariable':self.frozenLab, 616 'wcfg':{'font':('Helvetica',12,'bold') }, 617 'gridcfg':{'sticky':'w'}}) 618 ifd.append({'name':'const_lab', 619 'widgetType': Tkinter.Label, 620 'textvariable':self.constrLab, 621 'wcfg':{'font':('Helvetica',12,'bold') }, 622 'gridcfg':{'sticky':'w','row':-1,'column':1}}) 623 ifd.append({'name':'setfroz_cb', 624 'widgetType':Tkinter.Checkbutton, 625 'wcfg':{'text':'set frozen atoms', 626 'command': self.setFrozenAtoms, 627 }, 628 'gridcfg':{'sticky':'w'}}) 629 ifd.append({'name':'setcons_cb', 630 'widgetType':Tkinter.Checkbutton, 631 'wcfg':{'text':'set constrained atoms', 632 'command': self.setConstrainedAtoms, 633 }, 634 'gridcfg':{'sticky':'w', 'row':-1,'column':1}}) 635 #widgets for the run parameters: 636 ifd.append({'name':'maxIter_tw', 637 'widgetType':ThumbWheel, 638 'wType':ThumbWheel, 639 'wcfg':{ 640 'labCfg':{ 641 'text': 'maxIter -maximum number of iterations:', 642 }, 643 'type':'int', 644 'min':100, 645 'max':20000 , 646 'value':10000, 647 'width':100, 648 'continuous':1, 649 'wheelPad':2, 650 'height':20, 651 'oneTurn':1000,}, 652 'gridcfg':{'columnspan':2,'sticky':'e'}}) 653 ifd.append({'name':'drms_tw', 654 'widgetType':ThumbWheel, 655 'wType':ThumbWheel, 656 'wcfg':{ 657 'labCfg':{ 658 'text': 'drms -convergence criterion for energy gradient', 659 }, 660 'type':'float', 661 'min':0.0000001,'max':0.000002, 662 'value':0.000001, 663 'precision':6, 664 'width':100, 665 'continuous':1, 666 'wheelPad':2, 667 'height':20, 668 'oneTurn':.001,}, 669 'gridcfg':{'columnspan':2,'sticky':'e'}}) 670 ifd.append({'name':'dfpred_tw', 671 'widgetType':ThumbWheel, 672 'wType':ThumbWheel, 673 'wcfg':{ 674 'labCfg':{ 675 'text': 'dfpred -predicted drop in conj grad func on 1st iteration', 676 }, 677 'type':'float', 678 'min':0.1,'max':20.0, 679 'precision':4, 680 'width':100, 681 'continuous':1, 682 'wheelPad':2, 683 'height':20, 684 'value':10., 685 'oneTurn':1.,}, 686 'gridcfg':{'columnspan':2,'sticky':'e'}}) 687 ifd.append({'name':'callback_cb', 688 'widgetType':Tkinter.Checkbutton, 689 'wcfg':{'text':'update geometries', 690 'variable': self.callback, 691 'command': self.disableCallbackFreq, 692 }, 693 'gridcfg':{'sticky':'w'}}) 694 ifd.append({'name': 'callback_ent', 695 'widgetType':Tkinter.Entry, 696 'wcfg':{ 697 'label': 'update frequency', 698 #'label': 'callback frequency', 699 'textvariable': self.callbackFreq, 700 'width':7, 701 'fg':'grey', 702 'state':'disabled', 703 'selectbackground':'#d9d9d9', 704 'selectforeground':'grey', 705 }, 706 'gridcfg':{'sticky':'we', 'row':-1, 'column':1}}) 707 708 ifd.append({'widgetType': Tkinter.Button, 709 'text':'Minimize', 710 'wcfg':{'bd':6}, 711 'gridcfg':{'sticky':'we'}, 712 'command':self.Accept_cb}) 713 ifd.append({'widgetType': Tkinter.Button, 714 'text':'Cancel', 715 'wcfg':{'bd':6}, 716 'gridcfg':{'sticky':'we', 'column':1,'row':-1}, 717 'command':CallBackFunction(self.Close_cb, ifd)}) 718 self.form = self.vf.getUserInput(self.ifd, modal=0, blocking=0) 719 self.form.root.protocol('WM_DELETE_WINDOW', CallBackFunction(self.Close_cb,ifd))
720 #self.ifd.entryByName['amberIds']['widget'].component('entryfield')._entryFieldEntry.config(width=10) 721 722
723 - def disableCallbackFreq(self, event=None):
724 w = self.ifd.entryByName['callback_ent']['widget'] 725 if self.callback.get(): 726 w.config(state='normal', fg='black', selectbackground='#c3c3c3', 727 selectforeground='black') 728 else: 729 w.config(state='disabled', fg='grey', selectbackground='#d9d9d9', 730 selectforeground='grey')
731 732
733 - def Accept_cb(self, event=None):
734 self.form.withdraw() 735 #FIX THIS!! 736 key = self.ifd.entryByName['amberIds']['widget'].get() 737 #if self.callback.get(): 738 ##add the coords here 739 #amb = Amber94Config[key][0] 740 #if not hasattr(amb, 'coord_index'): 741 #amb.atoms.addConformation(amb.atoms.coords) 742 #amb.coord_index = len(amb.atoms[0]._coords)-1 743 ##amb.atoms.setConformation(amb.coord_index) 744 #freq = int(self.callbackFreq.get()) 745 #print 'setting callback to updateCoords' 746 #amb.setCallback(self.updateCoords, freq) 747 #start minimization 748 d = {} 749 #for v in [ 'maxIter_esw','drms_esw','dfpred_esw']: 750 for v in [ 'maxIter_tw','drms_tw','dfpred_tw']: 751 s = split(v,'_')[0] 752 val = self.ifd.entryByName[v]['widget'].get() 753 #FIX THIS!!! 754 ##amber.prmlib.cvar.+ key = v 755 d[s] = val 756 d['callback'] = self.callback.get() 757 d['callback_freq'] = self.callbackFreq.get() 758 return apply(self.doitWrapper, (key,), d)
759 760
761 - def setMinOpts(self, event=None):
762 #turn off button 763 self.ifd.entryByName['setminopts_cb']['widget'].toggle() 764 self.vf.setminimOpts_Amber94.guiCallback()
765 766
767 - def setFrozenAtoms(self, event=None):
768 #turn off button 769 self.ifd.entryByName['setfroz_cb']['widget'].toggle() 770 print 'calling freezeAtoms' 771 numFroz = self.vf.freezeAtoms_Amber94.guiCallback()
772 #fstr = 'Currently ' + str(numFroz) + ' frozen atoms' 773 #self.frozenLab.set(fstr) 774 775
776 - def setConstrainedAtoms(self, event=None):
777 #turn off button 778 self.ifd.entryByName['setcons_cb']['widget'].toggle() 779 print 'calling constrainAtoms' 780 numConstr = self.vf.constrainAtoms_Amber94.guiCallback() 781 cstr = 'Currently ' + str(numConstr) + ' constrained atoms' 782 self.constrLab.set(cstr)
783 784
785 - def update(self, event=None):
786 key = self.ifd.entryByName['amberIds']['widget'].get() 787 amb_ins = Amber94Config[key] 788 self.CurrentAmber94 = amb_ins
789 #THIS SHOULD ADJUST THE DISPLAYED PARAMETERS.... 790 #for w in []: 791 #FIX THIS!!! 792 #newval = amber.prmlib.cvar.+ key 793 794
795 - def guiCallback(self):
796 if not len(Amber94Config.keys()): 797 self.warningMsg('no Amber94 objects present: SetupAmber94 first') 798 return 'ERROR' 799 800 if self.CurrentAmber94=={}: 801 self.CurrentAmber94 = Amber94Config.values()[0][0] 802 803 #ALLOW USER TO SET parameters here 804 if not hasattr(self, 'ifd'): 805 self.buildForm() 806 else: 807 lb = self.ifd.entryByName['amberIds']['widget']._list 808 #make sure to update the listbox: 809 lb.delete(0, 'end') 810 for k in Amber94Config.keys(): 811 lb.insert('end', k) 812 self.form.deiconify()
813 814 815 MinimizeAmber94CommandGUI = CommandGUI() 816 MinimizeAmber94CommandGUI.addMenuCommand('menuRoot', 'Amber', 'Minimize') 817 818 819 820
821 -class FreezeAtomsAmber94(MVCommand):
822 """ 823 This class allows you to freeze atoms of an Amber94 instance 824 \nPackage : Pmv 825 \nModule : amberCommands 826 \nClass : FreezeAtomsAmber94 827 \nCommand : freezeAtomsAmber94 828 \nSynopsis:\n 829 len(frozenAtoms)<-freezeAtoms_amber94(key, atsToFreeze)\n 830 \nArguments:\n 831 key --- identifier to be key for this Amber94 instance in Amber94Config dictionary\n 832 """ 833 834 from Pmv.amberCommands import CurrentAmber94 835 836
837 - def __call__(self, key, atsToFreeze, **kw):
838 """ 839 len(frozenAtoms)<-freezeAtoms_amber94(key, atsToFreeze) 840 """ 841 842 if key not in Amber94Config.keys(): 843 print 'key: ', key, " is not in current Amber94Config " 844 return 'ERROR' 845 846 atsToFreeze = self.vf.expandNodes(atsToFreeze) 847 if not len(atsToFreeze): 848 return 'ERROR' 849 850 atsToFreeze = atsToFreeze.findType(Atom) 851 return apply(self.doitWrapper, (key, atsToFreeze), kw)
852 853
854 - def doit(self, key, atsToFreeze, **kw):
855 amb_ins = Amber94Config[key][0] 856 self.CurrentAmber94 = amb_ins 857 858 #check that all the atsToFreeze are in amber instances' atoms 859 chain_ids = {} 860 for c in amb_ins.atoms.parent.uniq().parent.uniq(): 861 chain_ids[id(c)] = 0 862 863 for c in atsToFreeze.parent.uniq().parent.uniq(): 864 assert chain_ids.has_key(id(c)), 'atoms to freeze not in Amber94 instance.atoms' 865 866 atsToFreezeIDS = {} 867 for at in atsToFreeze: 868 atsToFreezeIDS[id(at)] = 0 869 atomIndices = map(lambda x, d=atsToFreezeIDS: d.has_key(id(x)), amb_ins.atoms) 870 #FIX THIS: it has to be put into the correct c-structure 871 #print 'setting ', key, ' frozen to ', atomIndices 872 #amb_ins.frozen = atomIndices 873 apply(amb_ins.freezeAtoms, (atomIndices,), {}) 874 numFrozen = Numeric.add.reduce(Numeric.array(amb_ins.frozen)) 875 print 'numFrozen=', numFrozen 876 return numFrozen
877 878
879 - def Close_cb(self, ifd, event=None):
880 form = ifd.form 881 form.withdraw()
882 883
884 - def buildForm(self, tstr, mols, amb_ins):
885 ifd = self.ifd = InputFormDescr(title = tstr) 886 self.id = Tkinter.StringVar() 887 #self.id.set(self.CurrentAmber94.key) 888 self.id.set(amb_ins.key) 889 890 frozNum = Numeric.add.reduce(amb_ins.frozen) 891 self.frozenLab = Tkinter.StringVar() 892 fstr = 'Currently ' + str(frozNum) + ' frozen atoms' 893 self.frozenLab.set(fstr) 894 ##self.frozenLab.set('Currently 0 frozen atoms') 895 #self.constrLab = Tkinter.StringVar() 896 #constrNum = Numeric.add.reduce(self.CurrentAmber94.constrained) 897 #cstr = 'Currently ' + str(constrNum) + ' constrained atoms' 898 #self.constrLab.set(cstr) 899 ifd.append({'widgetType':Pmw.ComboBox, 900 'name':'amberIds', 901 'wcfg':{'label_text':'Amber94 ids', 902 'entryfield_value':self.id.get(), 903 'labelpos':'w', 904 'listheight':'80', 905 'scrolledlist_items': Amber94Config.keys(), 906 'selectioncommand': self.update, 907 }, 908 'gridcfg':{'sticky':'w','columnspan':2}}) 909 ifd.append({'name':'frozen_lab', 910 'widgetType': Tkinter.Label, 911 'textvariable':self.frozenLab, 912 'wcfg':{'font':('Helvetica',12,'bold') }, 913 'gridcfg':{'sticky':'w'}}) 914 #one string selector: 915 ifd.append({'name':'frozAtsLab', 916 'widgetType':Tkinter.Label, 917 'text':'Specify Frozen Atoms:\n', 918 'gridcfg':{'sticky':'w'}}) 919 ifd.append({ 'widgetType':StringSelectorGUI, 920 'name':'frozAts','required':1, 921 'wcfg':{ 'molSet': mols, 922 'vf': self.vf, 923 'all':1, 924 'crColor':(0.4,.8,1.), 925 }, 926 'gridcfg':{'sticky':'we','columnspan':3 }}) 927 ifd.append({'widgetType': Tkinter.Button, 928 'text':'Freeze', 929 'wcfg':{'bd':6}, 930 'gridcfg':{'sticky':'we'}, 931 'command':self.Accept_cb}) 932 ifd.append({'widgetType': Tkinter.Button, 933 'text':'Unfreeze all', 934 'wcfg':{'bd':6}, 935 'gridcfg':{'sticky':'we','row':-1,'column':1}, 936 'command':self.Unfreeze_cb}) 937 ifd.append({'widgetType': Tkinter.Button, 938 'text':'Cancel', 939 'wcfg':{'bd':6}, 940 'gridcfg':{'sticky':'we', 'column':2,'row':-1}, 941 'command':CallBackFunction(self.Close_cb, ifd)}) 942 self.form = self.vf.getUserInput(ifd, modal=0, blocking=0) 943 self.form.root.protocol('WM_DELETE_WINDOW', CallBackFunction(self.Close_cb,ifd))
944 945
946 - def updateLabels(self, numFroz):
947 for c in [self, self.vf.minimize_Amber94, self.vf.md_Amber94]: 948 if hasattr(c, 'frozenLab'): 949 fstr = 'Currently ' + str(numFroz) + ' frozen Atoms' 950 c.frozenLab.set(fstr)
951 952
953 - def Accept_cb(self, event=None):
954 #FIX THIS!! 955 self.form.withdraw() 956 #get the setupAmber94instance 957 key = self.ifd.entryByName['amberIds']['widget'].get() 958 #amb_ins = Amber94Config[key][0] 959 #set frozen atoms: 960 frozAts = self.ifd.entryByName['frozAts']['widget'].get() 961 if len(frozAts): 962 frozAts = frozAts.findType(Atom) 963 numFroz = self.doitWrapper(key, frozAts) 964 #at this point update whatever you can 965 self.updateLabels(numFroz) 966 else: 967 self.Unfreeze_cb()
968 969
970 - def Unfreeze_cb(self, event=None):
971 key = self.ifd.entryByName['amberIds']['widget'].get() 972 amb_ins = self.CurrentAmber94 973 l = [] 974 for i in range(len(amb_ins.atoms)): 975 l.append(0) 976 apply(amb_ins.freezeAtoms, (l,), {}) 977 numFrozen = Numeric.add.reduce(Numeric.array(amb_ins.frozen)) 978 self.updateLabels(numFrozen)
979 980
981 - def update(self, event=None):
982 key = self.ifd.entryByName['amberIds']['widget'].get() 983 amb_ins= Amber94Config[key] 984 self.CurrentAmber94 = amb_ins 985 print 'set CurrentAmber94 to', self.CurrentAmber94
986 #THIS SHOULD ADJUST THE DISPLAYED PARAMETERS.... 987 #for w in []: 988 #FIX THIS!!! 989 #newval = amber.prmlib.cvar.+ key 990 991
992 - def guiCallback(self):
993 if not len(Amber94Config.keys()): 994 self.warningMsg('no Amber94 objects present: SetupAmber94 first') 995 return 'ERROR' 996 #if not self.CurrentAmber94: 997 # self.warningMsg('no CurrentAmber94 object: SetupAmber94 first') 998 # return 'ERROR' 999 #if not len(self.CurrentAmber94): 1000 # self.CurrentAmber94 = Amber94Config.keys()[0][0] 1001 1002 if self.CurrentAmber94=={}: 1003 self.CurrentAmber94 = Amber94Config.values()[0][0] 1004 1005 #amb_ins = Amber94Config.values()[0][0] 1006 amb_ins = self.CurrentAmber94 1007 key = amb_ins.key 1008 mols = amb_ins.atoms.top.uniq() 1009 #ALLOW USER TO SET parameters here 1010 tstr = "Set atoms to be frozen for " + key + ":" 1011 if not hasattr(self, 'ifd'): 1012 self.buildForm(tstr, mols, amb_ins) 1013 else: 1014 lb = self.ifd.entryByName['amberIds']['widget']._list 1015 #make sure to update the listbox: 1016 lb.delete(0, 'end') 1017 for k in Amber94Config.keys(): 1018 lb.insert('end', k) 1019 self.ifd.entryByName['frozAts']['widget'].molSet = mols 1020 self.ifd.title = tstr 1021 self.ifd.form.root.title(tstr) 1022 self.form.deiconify()
1023 1024 1025 FreezeAtomsAmber94CommandGUI = CommandGUI() 1026 FreezeAtomsAmber94CommandGUI.addMenuCommand('menuRoot', 'Amber', 'Freeze Atoms', 1027 cascadeName = 'Set Options') 1028 1029 1030
1031 -class ConstrainAtomsAmber94(MVCommand):
1032 """ 1033 This class allows you to constrain atoms of an Amber94 instance 1034 \nPackage : Pmv 1035 \nModule : amberCommands 1036 \nClass : ConstrainAtomsAmber94 1037 \nCommand : constrainAtomsAmber94 1038 \nSynopsis:\n 1039 NumConstr<---constrainAtoms_amber94(key, atsToConstrain, anchorPts)\n 1040 \nArguments:\n 1041 key --- identifier to be key for this Amber94 instance in Amber94Config dictionary\n 1042 atsToConstrain --- atomset for which 3D-constrain points are specified in\n 1043 anchorPts --- a list of 3-D points, one per atsToConstrain\n 1044 kw --- possible md options\n 1045 """ 1046 1047 1048 from Pmv.amberCommands import CurrentAmber94 1049 1050
1051 - def onAddCmdToViewer(self):
1052 if self.vf.hasGui: 1053 self.masterGeom = Geom('constrAtsGeom',shape=(0,0), 1054 pickable=0, protected=True) 1055 self.masterGeom.isScalable = 0 1056 self.vf.GUI.VIEWER.AddObject(self.masterGeom) 1057 1058 self.lines = IndexedPolylines('constrAtsLines', materials = ((1,1,0),), 1059 inheritMaterial=0, lineWidth=3, 1060 stippleLines=1, protected=True) 1061 self.spheres = Spheres(name='constrAtsSpheres', shape=(0,3), 1062 inheritMaterial=0, radii=0.2, quality=15, 1063 materials = ((1.,1.,0.),), protected=True) 1064 for item in [self.lines, self.spheres]: 1065 self.vf.GUI.VIEWER.AddObject(item, parent=self.masterGeom) 1066 #constrList will start with coords of ats to constrain, then 1067 #be adjusted by user to some other 3D points 1068 self.constrList = []
1069 1070
1071 - def __call__(self, key, atsToConstrain, anchorPts, **kw):
1072 """NumConstr<-constrainAtoms_amber94(key, atsToConstrain, anchorPts) 1073 \nkey --- identifier to be key for this Amber94 instance in Amber94Config dictionary 1074 \natsToConstrain --- atomset for which 3D-constrain points are specified in 1075 \nanchorPts: a list of 3-D points, one per atsToConstrain 1076 \nkw: possible md options 1077 """ 1078 atsToConstrain = self.vf.expandNodes(atsToConstrain) 1079 if not len(atsToConstrain): 1080 return 'ERROR' 1081 if key not in Amber94Config.keys(): 1082 print 'key: ', key, " is not in current Amber94Config " 1083 return 'ERROR' 1084 #assert key in Amber94Config.keys() 1085 1086 return apply(self.doitWrapper, (key, atsToConstrain, anchorPts), kw)
1087 1088
1089 - def doit(self, key, atsToConstrain, anchorPts,**kw):
1090 amb_ins = Amber94Config[key][0] 1091 self.CurrentAmber94 = amb_ins 1092 #check that all the atsToConstrain are in amber instances' atoms 1093 chain_ids = {} 1094 for c in amb_ins.atoms.parent.uniq().parent.uniq(): 1095 chain_ids[id(c)] = 0 1096 1097 for c in atsToConstrain.parent.uniq().parent.uniq(): 1098 assert chain_ids.has_key(id(c)), 'atoms to constrain not in Amber94 instance.atoms' 1099 1100 atsToConstrainIDS = {} 1101 for at in atsToConstrain: 1102 atsToConstrainIDS[id(at)] = 0 1103 atomIndices = map(lambda x, d=atsToConstrainIDS: d.has_key(id(x)), amb_ins.atoms) 1104 1105 if len(kw): 1106 apply(amb_ins.setMinimizeOptions,(), kw) 1107 1108 #warn if wcons is 0: 1109 #if getattr(prmlib.cvar, 'wcons')==0: 1110 if prmlib.SFFoptions_wcons_get(amb_ins.sff_opts) == 0: 1111 self.warningMsg(" currently 0 constraint weight!") 1112 1113 #anchors have 3 correct values when atomIndex is 1, else garbage 1114 clist = [] 1115 k = 0 1116 junkCoords = amb_ins.atoms.coords[:] 1117 for i in range(len(amb_ins.atoms)): 1118 if atomIndices[i]: 1119 clist.append(anchorPts[k]) 1120 k = k + 1 1121 else: 1122 clist.append(junkCoords[i]) 1123 anchors = Numeric.array(clist).flat 1124 apply(amb_ins.constrainAtoms, (atomIndices, anchors), {}) 1125 numConstr = Numeric.add.reduce(Numeric.array(amb_ins.constrained)) 1126 print 'returning numConstr=', numConstr 1127 return numConstr
1128 1129
1130 - def Close_cb(self, ifd, event=None):
1131 form = ifd.form 1132 form.withdraw()
1133 1134
1135 - def buildForm(self, tstr, mols):
1136 ifd = self.ifd = InputFormDescr(title = tstr) 1137 self.id = Tkinter.StringVar() 1138 #self.id.set(self.CurrentAmber94.key) 1139 #self.id.set(Amber94Config.keys()[0]) 1140 self.id.set(self.CurrentAmber94.key) 1141 self.constrLab = Tkinter.StringVar() 1142 cnum = Numeric.add.reduce(self.CurrentAmber94.constrained) 1143 cstr = 'Currently ' + str(cnum) + ' constrained atoms' 1144 self.constrLab.set(cstr) 1145 self.adjustAnchor = Tkinter.StringVar() 1146 self.adjAnchors = Tkinter.IntVar() 1147 #self.constrLab.set('Currently 0 constrained atoms') 1148 ifd.append({'widgetType':Pmw.ComboBox, 1149 'name':'amberIds', 1150 'wcfg':{'label_text':'Amber94 ids', 1151 'entryfield_value':self.id.get(), 1152 'labelpos':'w', 1153 'listheight':'80', 1154 'scrolledlist_items': Amber94Config.keys(), 1155 'selectioncommand': self.update, 1156 }, 1157 'gridcfg':{'sticky':'w','columnspan':3}}) 1158 #one string selector: 1159 ifd.append({'name':'constr_lab', 1160 'widgetType': Tkinter.Label, 1161 'textvariable':self.constrLab, 1162 'wcfg':{'font':('Helvetica',12,'bold') }, 1163 'gridcfg':{'sticky':'w','columnspan':3}}) 1164 ifd.append({'name':'constrAtsLab', 1165 'widgetType':Tkinter.Label, 1166 'text':'Specify Constrained Atoms:\n', 1167 'gridcfg':{'sticky':'w','columnspan':3}}) 1168 ifd.append({ 'widgetType':StringSelectorGUI, 1169 'name':'constrAts','required':1, 1170 'wcfg':{ 'molSet': mols, 1171 'vf': self.vf, 1172 'all':1, 1173 'crColor':(1.,0.,0.), 1174 }, 1175 'gridcfg':{'sticky':'we' ,'columnspan':3}}) 1176 ifd.append({'name':'anchorCB', 1177 'widgetType':Tkinter.Checkbutton, 1178 'wcfg':{'text':'Adjust anchorPts ', 1179 'variable': self.adjAnchors, 1180 'command': self.setAnchors, 1181 }, 1182 'gridcfg':{'sticky':'w' }}) 1183 #'gridcfg':{'sticky':'w' ,'columnspan':3}}) 1184 ##Should THIS go here? 1185 ifd.append({'name':'wcons_tw', 1186 'widgetType':ThumbWheel, 1187 'wType':ThumbWheel, 1188 'wcfg':{ 'labCfg':{ 1189 'text':'wcons -restraint weight \nfor keeping atoms close\nto their position in xyz_ref', 1190 }, 1191 'type':'float', 1192 'min':0.0,'max':10., 1193 'value':0.0, 1194 'precision':2, 1195 'width':100, 1196 'continuous':1, 1197 'wheelPad':2, 1198 'height':20, 1199 'oneTurn':.5,}, 1200 'gridcfg':{'columnspan':2,'sticky':'w','row':-1,'column':1}}) 1201 ifd.append({'widgetType': Tkinter.Button, 1202 'text':'Ok', 1203 'wcfg':{'bd':6}, 1204 'gridcfg':{'sticky':'we'}, 1205 'command':self.Accept_cb}) 1206 ifd.append({'widgetType': Tkinter.Button, 1207 'text':'Unconstrain all', 1208 'wcfg':{'bd':6}, 1209 'gridcfg':{'sticky':'we','row':-1, 'column':1}, 1210 'command':self.Unconstrain_cb}) 1211 ifd.append({'widgetType': Tkinter.Button, 1212 'text':'Cancel', 1213 'wcfg':{'bd':6}, 1214 'gridcfg':{'sticky':'we', 'column':2,'row':-1}, 1215 'command':CallBackFunction(self.Close_cb, ifd)}) 1216 self.form = self.vf.getUserInput(ifd, modal=0, blocking=0) 1217 self.form.root.protocol('WM_DELETE_WINDOW', CallBackFunction(self.Close_cb,ifd)) 1218 #keep a handle to string selector 1219 self.ss = self.ifd.entryByName['constrAts']['widget'] 1220 self.ss.bind('<ButtonPress>', self.updateForm2, add='+') 1221 self.ss.sets = self.vf.sets
1222 1223
1224 - def update(self, event=None):
1225 key = self.ifd.entryByName['amberIds']['widget'].get() 1226 amb_ins = Amber94Config[key] 1227 self.CurrentAmber94 = amb_ins
1228 1229
1230 - def Unconstrain_cb(self, event=None):
1231 amb_ins = self.CurrentAmber94 1232 ats = amb_ins.atoms 1233 atInd = map(lambda x:x==2, ats) 1234 anchors = Numeric.array(ats.coords).flat 1235 apply(amb_ins.constrainAtoms, (atInd, anchors,), {}) 1236 numConstr = Numeric.add.reduce(amb_ins.constrained) 1237 self.updateLabels(numConstr)
1238 1239
1240 - def updateLabels(self, numConstr):
1241 print 'in updateLabels' 1242 if numConstr==None: 1243 print 'skipping update to None' 1244 raise 'abc' 1245 return 1246 cstr = 'Currently ' + str(numConstr) + ' constrained Atoms' 1247 for c in [self.vf.minimize_Amber94, self.vf.md_Amber94, self]: 1248 if hasattr(c, 'constrLab'): 1249 c.constrLab.set(cstr)
1250 #self.constrLab.set(cstr) 1251 1252
1253 - def Accept_cb(self, event=None):
1254 #FIX THIS!! 1255 self.form.withdraw() 1256 #get the setupAmber94instance 1257 key = self.ifd.entryByName['amberIds']['widget'].get() 1258 amb_ins = Amber94Config[key][0] 1259 1260 kw = {} 1261 #update wcons 1262 wcons = round(self.ifd.entryByName['wcons_tw']['widget'].get(),4) 1263 if wcons: 1264 kw['wcons'] = wcons 1265 #apply(amb_ins.setMinimizeOptions,(), mmOptD) 1266 1267 constrAts = self.ifd.entryByName['constrAts']['widget'].get() 1268 constrAts = constrAts.findType(Atom) 1269 if hasattr(self, 'geomDict'): 1270 anchorPts = [] 1271 for a in constrAts: 1272 anchorPts.append(self.geomDict[id(a)]) 1273 else: 1274 anchorPts = constrAts.coords[:] 1275 #numConst = self.doitWrapper(key, constrAts, anchorPts) 1276 numConstr = apply(self.doitWrapper,(key, constrAts, anchorPts,), kw) 1277 print 'updating labels with ', numConstr 1278 if numConstr!=None: 1279 self.updateLabels(numConstr)
1280 1281 1282 1283 ########################################################################## 1284 ###ANCHOR COMMANDS: 1285 ### 1286 ###setAnchors 1287 ### 1288 ###initializes spheres + lines at ats.coords 1289 ### 1290 ###initializes geomDict: keys=id(at), values=anchor xyz 1291 ### 1292 ###initializes Form2 1293 ##########################################################################
1294 - def setAnchors(self, event=None):
1295 #print 'in setAnchors' 1296 if self.adjAnchors.get(): 1297 self.ifd.entryByName['anchorCB']['widget'].toggle() 1298 self.ss.sets = self.vf.sets 1299 ats = self.atSET = self.ss.get().findType(Atom) 1300 ok = 0 1301 self.spheres.Set(visible=1, tagModified=False) 1302 if hasattr(self, 'form2') and hasattr(self, 'geomDict'): 1303 #check that every at is in current geomDict 1304 ok = 1 1305 for a in ats: 1306 if not self.geomDict.has_key(id(a)): 1307 ok = 0 1308 break 1309 for g in [self.spheres, self.lines]: 1310 g.Set(visible=1, tagModified=False) 1311 g.RedoDisplayList() 1312 if not ok: 1313 #have to rebuild here 1314 self.spheres.Set(vertices=ats.coords, visible=1, tagModified=False) 1315 numAts = 2*len(ats) 1316 fcs = [] 1317 for i in range(0, numAts): 1318 if i%2==1: 1319 fcs.append((i-1, i)) 1320 #print 'fcs=', fcs 1321 linePts = [] 1322 for a in ats: 1323 linePts.append(a.coords[:]) 1324 linePts.append(a.coords[:]) 1325 self.lines.Set(vertices=linePts, faces=fcs, visible=1, 1326 tagModified=False) 1327 #self.lines.Set(vertices=ats.coords, faces=fcs, tagModified=False) 1328 self.geomDict = {} 1329 for a in ats: 1330 self.geomDict[id(a)] = a.coords[:] 1331 self.updateForm2() 1332 self.vf.GUI.VIEWER.Redraw()
1333 #else: 1334 #self.spheres.Set(vertices=[], tagModified=False) 1335 1336 1337 ########################################################################## 1338 ###ANCHOR: FORM2 COMMANDS: 1339 ### 1340 ###updateForm2 1341 ### 1342 ###checks that some anchors have been specified 1343 ### 1344 ###IF NOT: return 1345 ### 1346 ###calls buildForm2 if form2 hasn't been created 1347 ### 1348 ###deiconifies form2 if it has been created 1349 ### 1350 ###updates entries in form2: 1351 ### 1352 ###in case specified anchors have changed 1353 ##########################################################################
1354 - def updateForm2(self, event=None):
1355 #if the string selector Show button is not on, do nothing 1356 if not self.ss.showCurrent.get(): 1357 self.warningMsg("'Show' anchors before setting them") 1358 return 1359 if not hasattr(self, 'form2'): 1360 self.buildForm2() 1361 else: 1362 self.form2.deiconify() 1363 ##fix up entries in form2 + deiconify it 1364 self.updateForm2Entries()
1365 ###################################################################### 1366 ###buildForm2 1367 ### 1368 ###builds framework of form2 : x,y,z thumbwheels and close button 1369 ### 1370 ###initializes : 1371 ### 1372 ###currentAt - Tk variable for current rb choice 1373 ### 1374 ###cur_at - Atom instance corresponding to currentAt 1375 ### 1376 ###x,y,z_tw - coords of ats[ 0 ] 1377 #######################################################################
1378 - def buildForm2(self):
1379 tstr = 'Adjust Anchor Positions' 1380 self.currentAt = Tkinter.IntVar() 1381 self.curAtLab = Tkinter.StringVar() 1382 self.cur_at = self.ss.get().findType(Atom)[0] 1383 lstr= 'current atom: '+ self.cur_at.full_name() 1384 self.curAtLab.set(lstr) 1385 coords = self.cur_at.coords[:] 1386 ifd2 = self.ifd2 = InputFormDescr(title = tstr) 1387 ifd2.append({'name':'curAtlab', 1388 'widgetType': Tkinter.Label, 1389 'textvariable':self.curAtLab, 1390 'wcfg':{'font':('Helvetica',12,'bold') }, 1391 'gridcfg':{'sticky':'w','columnspan':2}}) 1392 ifd2.append({'name':'x_tw', 1393 'widgetType':ThumbWheel, 1394 'wType':ThumbWheel, 1395 'wcfg':{ 'labCfg':{ 'text':'x', }, 1396 'type':'float', 'value':coords[0], 1397 'precision':3, 'width':100, 1398 'continuous':1, 'wheelPad':2, 1399 'callback':self.updateGeoms, 1400 'height':20, 'oneTurn':4.,}, 1401 'gridcfg':{'sticky':'w'}}) 1402 ifd2.append({'name':'y_tw', 1403 'widgetType':ThumbWheel, 1404 'wType':ThumbWheel, 1405 'wcfg':{ 'labCfg':{ 'text':'y', }, 1406 'type':'float', 'value':coords[1], 1407 'precision':3, 'width':100, 1408 'continuous':1, 'wheelPad':2, 1409 'callback':self.updateGeoms, 1410 'height':20, 'oneTurn':4.,}, 1411 'gridcfg':{'sticky':'w', 'row':-1, 'column':1}}) 1412 ifd2.append({'name':'z_tw', 1413 'widgetType':ThumbWheel, 1414 'wType':ThumbWheel, 1415 'wcfg':{ 'labCfg':{ 'text':'z', }, 1416 'type':'float', 'value': coords[2], 1417 'precision':3, 'width':100, 1418 'continuous':1, 'wheelPad':2, 1419 'callback':self.updateGeoms, 1420 'height':20, 'oneTurn':4.,}, 1421 'gridcfg':{'sticky':'w', 'row':-1, 'column':2}}) 1422 ifd2.append({ 1423 'name':'resetbut', 1424 'widgetType': Tkinter.Button, 1425 'text':'Reset All', 1426 'wcfg':{'bd':6}, 1427 'gridcfg':{'sticky':'we','columnspan':2}, 1428 'command':self.Reset_cb}) 1429 ifd2.append({ 1430 'name':'cancelbut', 1431 'widgetType': Tkinter.Button, 1432 'text':'Close', 1433 'wcfg':{'bd':6}, 1434 'gridcfg':{'sticky':'we', 'row':-1, 'column':2}, 1435 #'gridcfg':{'sticky':'we', 'column':2,'row':-1}, 1436 'command':self.Accept_cb2}) 1437 #'command':CallBackFunction(self.Close_cb, ifd2)}) 1438 self.form2 = self.vf.getUserInput(ifd2, modal=0, width=400, 1439 height=400, blocking=0, scrolledFrame=1) 1440 self.form2.root.protocol('WM_DELETE_WINDOW', CallBackFunction(self.Close_cb,ifd2)) 1441 for tw in ['x_tw','y_tw','z_tw']: 1442 setattr(self, tw, self.ifd2.entryByName[tw]['widget'])
1443 1444 1445 ########################################################################## 1446 ###updateForm2Entries 1447 ### 1448 ###ungrids framework of form2 1449 ### 1450 ###removes all previous rb 1451 ### 1452 ###builds new rb 1453 ### 1454 ###regrids framework of form2 1455 ##########################################################################
1456 - def updateForm2Entries(self, event=None):
1457 #first forget the bottom buttons: 1458 bButtons = ['resetbut','cancelbut'] 1459 #bButtons = ['okbut','cancelbut'] 1460 for b in bButtons: 1461 self.ifd2.entryByName[b]['widget'].grid_forget() 1462 #next remove former rb_* buttons: 1463 for k,v in self.ifd2.entryByName.items(): 1464 if k[:3]=='rb_': 1465 v['widget'].grid_forget() 1466 del self.ifd2.entryByName[k] 1467 #build new radiobuttons 1468 rowctr = 1 1469 ats = self.ss.get().findType(Atom) 1470 nameLabs = [] 1471 atCtr = 0 1472 for at in ats: 1473 entry = {'name':'rb_%s'%id(at), 1474 'widgetType':Tkinter.Radiobutton, 1475 'text':at.full_name(), 1476 'variable': self.currentAt, 1477 'value':atCtr, 1478 'gridcfg':{'sticky':'w','columnspan':3}, 1479 'command':CallBackFunction(self.setCurrentAt, at)} 1480 self.ifd2.entryByName[entry['name']] = entry 1481 self.form2.addEntry(entry) 1482 rowctr = rowctr+1 1483 atCtr = atCtr + 1 1484 #repack the bottom buttons: 1485 for b in bButtons: 1486 item = self.ifd2.entryByName[b] 1487 gridcfg = item['gridcfg'] 1488 gridcfg['row'] = gridcfg['row'] + rowctr + 2 1489 item['widget'].grid(gridcfg)
1490 1491 1492 ########################################################################## 1493 ###setCurrentAt : 1494 ### 1495 ###callback for rb in form2 1496 ### 1497 ###sets cur_at 1498 ### 1499 ###sets x,y,z_tw to cur_at coords 1500 ### 1501 ###calls updateGeoms 1502 ##########################################################################
1503 - def setCurrentAt(self, at, event=None):
1504 self.cur_at = at 1505 lstr= 'current atom: '+ self.cur_at.full_name() 1506 self.curAtLab.set(lstr) 1507 #get last specified anchor point for this atom 1508 coords = self.geomDict[id(at)] 1509 #coords = at.coords[:] 1510 self.x_tw.set(coords[0]) 1511 self.y_tw.set(coords[1]) 1512 self.z_tw.set(coords[2]) 1513 self.updateGeoms()
1514 1515 1516 ########################################################################## 1517 ###updateGeoms 1518 ###called by: 1519 ### 1520 ###setCurrentAt 1521 ### 1522 ###resets spheres and lines to current vertices 1523 ### 1524 ###calls Redraw 1525 ##########################################################################
1526 - def updateGeoms(self, event=None):
1527 key = id(self.cur_at) 1528 ind = self.currentAt.get() 1529 #ind = self.atSET.index(self.cur_at) 1530 currentPos = self.geomDict[key] 1531 newPos = ( self.x_tw.get(), self.y_tw.get(), self.z_tw.get()) 1532 self.geomDict[key] = newPos 1533 self.spheres.vertexSet.vertices.array[ind] = newPos 1534 self.spheres.RedoDisplayList() 1535 #the moving pt is the odd one of face pair: (0,1), (2,3) etc 1536 lineInd = 2*ind + 1 1537 #print 'updating vertex ', lineInd 1538 self.lines.vertexSet.vertices.array[lineInd] = newPos 1539 self.lines.RedoDisplayList() 1540 #self.spheres.Set(vertices = (newPos,), tagModified=False) 1541 #self.lines.Set(vertices = (self.cur_at.coords, newPos,), 1542 # faces=((0,1),), tagModified=False) 1543 self.vf.GUI.VIEWER.Redraw()
1544 1545 1546 ########################################################################## 1547 ###Reset_cb 1548 ### 1549 ###restores geomDict to original coords 1550 ### 1551 ###resets spheres and lines to original coords 1552 ### 1553 ###calls Redraw 1554 ##########################################################################
1555 - def Reset_cb(self, event=None):
1556 ats = self.atSET = self.ss.get().findType(Atom) 1557 self.geomDict = {} 1558 for a in ats: 1559 self.geomDict[id(a)] = a.coords[:] 1560 self.spheres.Set(vertices=ats.coords, visible=1, tagModified=False) 1561 linePts = [] 1562 for a in ats: 1563 linePts.append(a.coords[:]) 1564 linePts.append(a.coords[:]) 1565 self.lines.Set(vertices=linePts,visible=1, tagModified=False) 1566 self.vf.GUI.VIEWER.Redraw()
1567 1568
1569 - def Accept_cb2(self, event=None):
1570 for g in [self.spheres, self.lines]: 1571 g.Set(visible=0, tagModified=False) 1572 self.vf.GUI.VIEWER.Redraw() 1573 self.form2.withdraw()
1574 1575 1576
1577 - def guiCallback(self):
1578 if not len(Amber94Config.keys()): 1579 self.warningMsg('no Amber94 objects present: SetupAmber94 first') 1580 return 'ERROR' 1581 #amb_ins = Amber94Config.values()[0][0] 1582 #key = amb_ins.key 1583 #mols = amb_ins.atoms.top.uniq() 1584 if self.CurrentAmber94=={}: 1585 self.CurrentAmber94 = Amber94Config.values()[0][0] 1586 key = self.CurrentAmber94.key 1587 mols = self.CurrentAmber94.atoms.top.uniq() 1588 tstr = "Set atoms to be constrained for " + key + ":" 1589 if not hasattr(self, 'ifd'): 1590 self.buildForm(tstr, mols) 1591 else: 1592 lb = self.ifd.entryByName['amberIds']['widget']._list 1593 #make sure to update the listbox: 1594 lb.delete(0, 'end') 1595 for k in Amber94Config.keys(): 1596 lb.insert('end', k) 1597 self.ifd.entryByName['constrAts']['widget'].molSet = mols 1598 self.ifd.title = tstr 1599 self.ifd.form.root.title(tstr) 1600 self.form.deiconify()
1601 1602 1603 ConstrainAtomsAmber94CommandGUI = CommandGUI() 1604 ConstrainAtomsAmber94CommandGUI.addMenuCommand('menuRoot', 'Amber', 'Constrain Atoms', 1605 cascadeName = 'Set Options') 1606 1607 1608
1609 -class SetMDOptsAmber94(MVCommand):
1610 """This class allows you to set md options of a Amber94 instance these options include t, dt, tautp, temp0, verbose, vlimit, ntpr_md, zerov,tempi and idum. NB: this is written as a separate class in order to create a straight-forward log. 1611 \nPackage : Pmv 1612 \nModule : amberCommands 1613 \nClass : SetMDOptsAmber94 1614 \nCommand : setMDOptsAmber94 1615 \nSynopsis:\n 1616 None<-setmdOpts_Amber94(key, **kw)\n 1617 \nArguments:\n 1618 key --- identifier to be key for this Amber94 instance in Amber94Config dictionary\n 1619 """ 1620 1621 from Pmv.amberCommands import CurrentAmber94 1622 1623
1624 - def __call__(self, key, **kw):
1625 """None<-setmdOpts_Amber94(key, **kw) 1626 \nkey --- identifier to be key for this Amber94 instance in Amber94Config dictionary\n 1627 """ 1628 return apply(self.doitWrapper, (key,), kw)
1629 1630
1631 - def doit(self, key, **kw):
1632 if key not in Amber94Config.keys(): 1633 print 'key: ', key, " is not in current Amber94Config " 1634 return 'ERROR' 1635 amber94instance = Amber94Config[key][0] 1636 amb_ins = self.CurrentAmber94 = amber94instance 1637 for k in kw.keys(): 1638 assert k in ['t','dt','tautp','temp0','verbosemd','ntwx', 1639 'vlimit', 'ntpr_md', 1640 'zerov', 'tempi', 'idum'] 1641 apply(amb_ins.setMdOptions, (), kw)
1642 1643
1644 - def Close_cb(self, ifd, event=None):
1645 form = ifd.form 1646 form.withdraw()
1647 1648
1649 - def buildForm(self):
1650 ifd = self.ifd = InputFormDescr(title = "Set parameters for amber94 molecular dynamics:") 1651 self.verbose = Tkinter.StringVar() 1652 self.verbose.set('print summary') 1653 self.verbose_list = ['no print out', 'print summary', 'print summary w/energies'] 1654 self.zerov = Tkinter.IntVar() 1655 self.id = Tkinter.StringVar() 1656 self.id.set(self.CurrentAmber94.key) 1657 1658 ifd.append({'widgetType':Pmw.ComboBox, 1659 'name':'amberIds', 1660 'wcfg':{'label_text':'Amber94 ids', 1661 'entryfield_value':self.id.get(), 1662 'labelpos':'w', 1663 'listheight':'80', 1664 'scrolledlist_items': Amber94Config.keys(), 1665 'selectioncommand': self.update, 1666 }, 1667 'gridcfg':{'sticky':'w'}}) 1668 ifd.append({'widgetType':Pmw.ComboBox, 1669 'name':'verbose_cb', 1670 'wcfg':{'label_text':'', 1671 'entryfield_value':self.verbose.get(), 1672 'labelpos':'w', 1673 'listheight':'80', 1674 'scrolledlist_items': self.verbose_list, 1675 }, 1676 'gridcfg':{'sticky':'w'}}) 1677 1678 ifd.append({'name':'zerov_cb', 1679 'widgetType':Tkinter.Checkbutton, 1680 'wcfg':{'text':'zerov - use zero initial velocities', 1681 'variable': self.zerov, 1682 }, 1683 'gridcfg':{'sticky':'w', 'row':-1, 'column':1 }}) 1684 ifd.append({'name':'t_tw', 1685 'widgetType':ThumbWheel, 1686 'wType':ThumbWheel, 1687 'wcfg':{ 'labCfg':{ 1688 'text': 't - initial time', 1689 }, 1690 'type':'float', 1691 'min':0.0,'max':30.0, 1692 'lockmin':1, 1693 'precision':2, 1694 'width':100, 1695 'continuous':1, 1696 'wheelPad':2, 1697 'height':20, 1698 'value':0.0, 1699 'oneTurn':10.,}, 1700 'gridcfg':{'columnspan':2,'sticky':'e'}}) 1701 ifd.append({'name':'dt_tw', 1702 'widgetType':ThumbWheel, 1703 'wType':ThumbWheel, 1704 'wcfg':{ 'labCfg':{ 1705 'text': 'dt - time step, ps', 1706 }, 1707 'type':'float', 1708 'min':0.00001,'max':1.0, 1709 'precision':6, 1710 'width':100, 1711 'continuous':1, 1712 'wheelPad':2, 1713 'height':20, 1714 'value':0.001, 1715 'oneTurn':.1,}, 1716 'gridcfg':{'columnspan':2,'sticky':'e'}}) 1717 ifd.append({'name':'tautp_tw', 1718 'widgetType':ThumbWheel, 1719 'wType':ThumbWheel, 1720 'wcfg':{ 'labCfg':{ 1721 'text': 'tautp - temp. coupling parm., ps', 1722 }, 1723 'type':'float', 1724 'min':0.001,'max':5.0, 1725 'precision':6, 1726 'width':100, 1727 'continuous':1, 1728 'wheelPad':2, 1729 'height':20, 1730 'value':0.2, 1731 'oneTurn':.1,}, 1732 'gridcfg':{'columnspan':2,'sticky':'e'}}) 1733 ifd.append({'name':'temp0_tw', 1734 'widgetType':ThumbWheel, 1735 'wType':ThumbWheel, 1736 'wcfg':{ 'labCfg':{ 1737 'text': 'temp0 - target temperature, K', 1738 }, 1739 'type':'float', 1740 'min':0.0,'max':1000.0, 1741 'precision':3, 1742 'width':100, 1743 'continuous':1, 1744 'wheelPad':2, 1745 'height':20, 1746 'value':300., 1747 'oneTurn':100.,}, 1748 'gridcfg':{'columnspan':2,'sticky':'e'}}) 1749 ifd.append({'name':'vlimit_tw', 1750 'widgetType':ThumbWheel, 1751 'wType':ThumbWheel, 1752 'wcfg':{ 'labCfg':{ 1753 'text': 'vlimit - maximum velocity component', 1754 }, 1755 'type':'float', 1756 'min':0.0,'max':100.0, 1757 'precision':3, 1758 'width':100, 1759 'continuous':1, 1760 'wheelPad':2, 1761 'height':20, 1762 'value':10., 1763 'oneTurn':10.,}, 1764 'gridcfg':{'columnspan':2,'sticky':'e'}}) 1765 ifd.append({'name':'ntpr_md_tw', 1766 'widgetType':ThumbWheel, 1767 'wType':ThumbWheel, 1768 'wcfg':{ 'labCfg':{ 1769 'text': 'ntpr_md - print frequency', 1770 }, 1771 'type':'int', 1772 'min':0,'max':5000, 1773 #'precision':3, 1774 'width':100, 1775 'continuous':1, 1776 'wheelPad':2, 1777 'height':20, 1778 'value':10, 1779 'oneTurn':500.,}, 1780 'gridcfg':{'columnspan':2,'sticky':'e'}}) 1781 ifd.append({'name':'ntwx_tw', 1782 'widgetType':ThumbWheel, 1783 'wType':ThumbWheel, 1784 'wcfg':{ 'labCfg':{ 1785 'text': 'ntwx - trajectory snapshot frequency', 1786 }, 1787 'type':'int', 1788 'min':0,'max':5000, 1789 'lockmin':1, 1790 #'precision':3, 1791 'width':100, 1792 'continuous':1, 1793 'wheelPad':2, 1794 'height':20, 1795 'value':0, 1796 'oneTurn':500.,}, 1797 'gridcfg':{'columnspan':2,'sticky':'e'}}) 1798 ifd.append({'name':'tempi_tw', 1799 'widgetType':ThumbWheel, 1800 'wType':ThumbWheel, 1801 'wcfg':{ 'labCfg':{ 1802 'text': 'tempi- initial temperature', 1803 }, 1804 'type':'float', 1805 'min':0.,'max':1000., 1806 'precision':3, 1807 'width':100, 1808 'continuous':1, 1809 'wheelPad':2, 1810 'height':20, 1811 'value':0, 1812 'oneTurn':500.,}, 1813 'gridcfg':{'columnspan':2,'sticky':'e'}}) 1814 ifd.append({'name':'idum_tw', 1815 'widgetType':ThumbWheel, 1816 'wType':ThumbWheel, 1817 'wcfg':{ 'labCfg':{ 1818 'text': 'idum - random number seed', 1819 }, 1820 'type':'int', 1821 'min':-1,'max':1, 1822 #'precision':3, 1823 'width':100, 1824 'continuous':1, 1825 'wheelPad':2, 1826 'height':20, 1827 'value':-1, 1828 'oneTurn':1,}, 1829 'gridcfg':{'columnspan':2,'sticky':'e'}}) 1830 ifd.append({'widgetType': Tkinter.Button, 1831 'text':'Accept', 1832 'wcfg':{'bd':6}, 1833 'gridcfg':{'sticky':'we'}, 1834 'command':self.Accept_cb}) 1835 ifd.append({'widgetType': Tkinter.Button, 1836 'text':'Cancel', 1837 'wcfg':{'bd':6}, 1838 'gridcfg':{'sticky':'we', 'column':1,'row':-1}, 1839 'command':CallBackFunction(self.Close_cb, ifd)}) 1840 self.form = self.vf.getUserInput(self.ifd, modal=0, blocking=0) 1841 self.form.root.protocol('WM_DELETE_WINDOW', CallBackFunction(self.Close_cb,ifd))
1842 1843
1844 - def Accept_cb(self, event=None):
1845 #FIX THIS!! 1846 self.form.withdraw() 1847 #get the setupAmber94instance 1848 key = self.ifd.entryByName['amberIds']['widget'].get() 1849 #amb_ins = Amber94Config[key][0] 1850 #update minimization Options 1851 #SKIPPED: boltz2 1852 mdOptD = {} 1853 for v in ['t_tw','dt_tw', 'tautp_tw','temp0_tw','vlimit_tw', 1854 'ntwx_tw', 'tempi_tw','idum_tw']: 1855 val = self.ifd.entryByName[v]['widget'].get() 1856 s = split(v,'_')[0] 1857 mdOptD[s] = val 1858 mdOptD['ntpr_md'] = self.ifd.entryByName['ntpr_md_tw']['widget'].get() 1859 w = self.ifd.entryByName['verbose_cb']['widget'].get() 1860 if w not in self.verbose_list: 1861 mdOptD['verbosemd'] = 1 1862 else: 1863 mdOptD['verbosemd'] = self.verbose_list.index(w) 1864 mdOptD['zerov'] = self.zerov.get() 1865 #apply(amb_ins.setMdOptions, (), mdOptD) 1866 apply(self.doitWrapper, (key,), mdOptD)
1867 1868
1869 - def update(self, event=None):
1870 key = self.ifd.entryByName['amberIds']['widget'].get() 1871 amb_ins = Amber94Config[key] 1872 self.CurrentAmber94 = amb_ins
1873 #THIS SHOULD ADJUST THE DISPLAYED PARAMETERS.... 1874 #for w in []: 1875 #FIX THIS!!! 1876 #newval = amber.prmlib.cvar.+ key 1877 1878 1879
1880 - def guiCallback(self):
1881 if not len(Amber94Config.keys()): 1882 self.warningMsg('no Amber94 objects present: SetupAmber94 first') 1883 return 'ERROR' 1884 1885 if self.CurrentAmber94=={}: 1886 self.CurrentAmber94 = Amber94Config.values()[0][0] 1887 1888 #ALLOW USER TO SET parameters here 1889 if not hasattr(self, 'ifd'): 1890 self.buildForm() 1891 else: 1892 lb = self.ifd.entryByName['amberIds']['widget']._list 1893 #make sure to update the listbox: 1894 lb.delete(0, 'end') 1895 for k in Amber94Config.keys(): 1896 lb.insert('end', k) 1897 self.form.deiconify()
1898 1899 1900 SetMDOptsAmber94CommandGUI = CommandGUI() 1901 SetMDOptsAmber94CommandGUI.addMenuCommand('menuRoot', 'Amber', 'Molecular Dynamics', 1902 cascadeName = 'Set Options') 1903 1904 1905
1906 -class MolecularDynamicsAmber94(MVCommand):
1907 """ 1908 This class allows you to select an Amber94 instance from Amber94Config whose keys are ids specified in setup_Amber94 for the Amber94 instances.You can also set md options, freeze atoms, specify constrained atoms and anchor atoms and set maxStep. The md 1909 can be run repeatedly. 1910 \nPackage : Pmv 1911 \nModule : amberCommands 1912 \nClass : MolecularDynamicsAmber94 1913 \nCommand : molecularDynamicsAmber94 1914 \nSynopsis:\n 1915 return_code<-md_Amber94(key, maxStep, **kw)\n 1916 \nArguments\n: 1917 key --- is key into Amber94Config dictionary\n 1918 """ 1919 1920 1921 from Pmv.amberCommands import CurrentAmber94 1922 1923
1924 - def __call__(self, key, maxStep, **kw):
1925 """return_code<-md_Amber94(key, maxStep, **kw)\n 1926 \npossible return codes:\n 1927 >0 converged, final iteration number\n 1928 -1 bad line search, probably an error in the relation 1929 of the funtion to its gradient (perhaps from 1930 round-off if you push too hard on the minimization).\n 1931 -2 search direction was uphill\n 1932 -3 exceeded the maximum number of iterations\n 1933 -4 could not further reduce function value\n 1934 -5 stopped via signal (bsd)\n 1935 key is key into Amber94Config dictionary\n 1936 """ 1937 #FIX THESE! 1938 1939 return apply(self.doitWrapper, (key, maxStep,), kw)
1940 1941
1942 - def doit(self, key, maxStep, **kw):
1943 if key not in Amber94Config.keys(): 1944 print 'key: ', key, " is not in current Amber94Config " 1945 return 'ERROR' 1946 amb_ins = Amber94Config[key][0] 1947 self.CurrentAmber94 = amb_ins 1948 ##do you need to retrieve a set of minimization parms, too? 1949 #if self.callback.get(): 1950 # mols = amb_ins.atoms.top.uniq() 1951 # print 'calling updateCoords)' 1952 # cbNum=0 1953 # nbat=len(amb_ins.atoms) 1954 # coords = amb_ins.atoms.coords 1955 # energies = [] 1956 # step = 49 1957 # self.updateCoords(cbNum, nbat, coords, energies, step) 1958 # self.vf.displayLines(mols, negate=1, topCommand=0) 1959 # self.vf.displayLines(mols, negate=0, topCommand=0) 1960 freq = kw.get('callback_freq', 0) 1961 del kw['callback_freq'] 1962 callback = kw.get('callback') 1963 del kw['callback'] 1964 wcons = kw.get('wcons') 1965 if wcons: 1966 del kw['wcons'] 1967 #check here if anything has been constrained 1968 numConst = Numeric.add.reduce(amb_ins.constrained) 1969 if numConst: 1970 mdopt={} 1971 mdopt['wcons'] = wcons 1972 apply(amb_ins.setMinimizeOptions, (), mdopt) 1973 1974 if callback: 1975 #add the coords here 1976 if not hasattr(amb_ins, 'coord_index'): 1977 amb_ins.atoms.addConformation(amb_ins.atoms.coords[:]) 1978 amb_ins.coord_index = len(amb_ins.atoms[0]._coords)-1 1979 #freq = int(self.callbackFreq.get()) 1980 print 'setting callback to updateCoords' 1981 amb_ins.setCallback(self.updateCoords, freq) 1982 1983 return_code = apply(amb_ins.md,(maxStep,), kw) 1984 print 'return_code=', return_code 1985 return return_code
1986 1987
1988 - def updateCoords(self, cbNum=0, nbat=300, coords=[], energies=[], step=[]):
1989 #FIX THIS 1990 #print 'in updateCoords' 1991 amb = self.CurrentAmber94 1992 mols = amb.atoms.top.uniq() 1993 allAtoms = mols.chains.residues.atoms 1994 newcoords = Numeric.array(amb.coords[:]) 1995 newcoords.shape = (-1,3) 1996 allAtoms.updateCoords(newcoords.tolist(), amb.coord_index) 1997 self.vf.displayLines(allAtoms, topCommand=0) 1998 self.vf.GUI.VIEWER.currentCamera.update()
1999 2000
2001 - def Close_cb(self, ifd, event=None):
2002 form = ifd.form 2003 form.withdraw()
2004 2005
2006 - def buildForm(self):
2007 ifd = self.ifd = InputFormDescr(title = "Set parameters for amber94 md:") 2008 self.verbose = Tkinter.IntVar() 2009 self.verbose.set('print summary') 2010 self.dield = Tkinter.IntVar() 2011 self.dield.set(1) 2012 self.callback = Tkinter.IntVar() 2013 self.callbackFreq = Tkinter.StringVar() 2014 self.callbackFreq.set('10') 2015 self.TrjFilename = Tkinter.StringVar() 2016 self.TrjFilename.set('') 2017 self.id = Tkinter.StringVar() 2018 #self.id.set(Amber94Config.keys()[0]) 2019 self.id.set(self.CurrentAmber94.key) 2020 frozNum = Numeric.add.reduce(self.CurrentAmber94.frozen) 2021 self.frozenLab = Tkinter.StringVar() 2022 fstr = 'Currently ' + str(frozNum) + ' frozen atoms' 2023 self.constrLab = Tkinter.StringVar() 2024 constrNum = Numeric.add.reduce(self.CurrentAmber94.constrained) 2025 cstr = 'Currently ' + str(constrNum) + ' constrained atoms' 2026 self.constrLab.set(cstr) 2027 ifd.append({'widgetType':Pmw.ComboBox, 2028 'name':'amberIds', 2029 'wcfg':{'label_text':'Amber94 ids', 2030 'entryfield_value':self.id.get(), 2031 'labelpos':'w', 2032 'listheight':'80', 2033 'scrolledlist_items': Amber94Config.keys(), 2034 'selectioncommand': self.update, 2035 }, 2036 'gridcfg':{'sticky':'w'}}) 2037 #'gridcfg':{'sticky':'nesw','row':-1, 'column':1}}), 2038 ifd.append({'name':'setmdopts_cb', 2039 'widgetType':Tkinter.Checkbutton, 2040 'wcfg':{'text':'set molecular dynamics options', 2041 'command': self.setMdOpts, 2042 }, 2043 'gridcfg':{'sticky':'w', 'row':-1,'column':1}}) 2044 ifd.append({'name':'frozen_lab', 2045 'widgetType': Tkinter.Label, 2046 'textvariable':self.frozenLab, 2047 'wcfg':{'font':('Helvetica',12,'bold') }, 2048 'gridcfg':{'sticky':'w'}}) 2049 ifd.append({'name':'const_lab', 2050 'widgetType': Tkinter.Label, 2051 'textvariable':self.constrLab, 2052 'wcfg':{'font':('Helvetica',12,'bold') }, 2053 'gridcfg':{'sticky':'w','row':-1,'column':1}}) 2054 ifd.append({'name':'setfroz_cb', 2055 'widgetType':Tkinter.Checkbutton, 2056 'wcfg':{'text':'set frozen atoms', 2057 'command': self.setFrozenAtoms, 2058 }, 2059 'gridcfg':{'sticky':'w'}}) 2060 ifd.append({'name':'setcons_cb', 2061 'widgetType':Tkinter.Checkbutton, 2062 'wcfg':{'text':'set constrained atoms', 2063 'command': self.setConstrainedAtoms, 2064 }, 2065 'gridcfg':{'sticky':'w', 'row':-1,'column':1}}) 2066 #widgets for the run parameters: 2067 ifd.append({'name':'maxStep_tw', 2068 'widgetType':ThumbWheel, 2069 'wType':ThumbWheel, 2070 'wcfg':{ 'labCfg':{ 2071 'text': 'maxStep -maximum number of steps:', 2072 }, 2073 'type':'int', 2074 #'min':100, 2075 'max':20000, 2076 #'precision':2, 2077 'width':100, 2078 'continuous':1, 2079 'wheelPad':2, 2080 'height':20, 2081 'value':100.0, 2082 'oneTurn':1000,}, 2083 'gridcfg':{'columnspan':2,'sticky':'e'}}) 2084 #Should THIS go here? 2085 ifd.append({'name':'wcons_tw', 2086 'widgetType':ThumbWheel, 2087 'wType':ThumbWheel, 2088 'wcfg':{ 'labCfg':{ 2089 'text':'wcons -restraint weight \nfor keeping atoms close\nto their position in xyz_ref', 2090 }, 2091 'type':'float', 2092 'min':0.0,'max':10., 2093 'value':0.0, 2094 'precision':2, 2095 'width':100, 2096 'continuous':1, 2097 'wheelPad':2, 2098 'height':20, 2099 'oneTurn':.5,}, 2100 'gridcfg':{'columnspan':2,'sticky':'e'}}) 2101 #'gridcfg':{'columnspan':2,'sticky':'w','row':-1,'column':1}}) 2102 ifd.append({'name':'trjCB', 2103 'widgetType': Tkinter.Checkbutton, 2104 'wcfg':{'text':'Specify trajectory filename', 2105 'variable': self.TrjFilename, 2106 'command': self.set_filename, 2107 }, 2108 'gridcfg':{'sticky':'w'}}) 2109 ifd.append({'name':'callback_cb', 2110 'widgetType':Tkinter.Checkbutton, 2111 'wcfg':{'text':'update geometries', 2112 'variable': self.callback, 2113 'command': self.disableCallbackFreq, 2114 }, 2115 'gridcfg':{'sticky':'w'}}) 2116 ifd.append({'name': 'callback_ent', 2117 'widgetType':Tkinter.Entry, 2118 'wcfg':{ 2119 'label': 'update frequency', 2120 #'label': 'callback frequency', 2121 'textvariable': self.callbackFreq, 2122 'width':7, 2123 'fg':'grey', 2124 'state':'disabled', 2125 'selectbackground':'#d9d9d9', 2126 'selectforeground':'grey', 2127 }, 2128 'gridcfg':{'sticky':'we', 'row':-1, 'column':1}}) 2129 2130 ifd.append({'widgetType': Tkinter.Button, 2131 'text':'Run MD', 2132 'wcfg':{'bd':6}, 2133 'gridcfg':{'sticky':'we'}, 2134 'command':self.Accept_cb}) 2135 ifd.append({'widgetType': Tkinter.Button, 2136 'text':'Cancel', 2137 'wcfg':{'bd':6}, 2138 'gridcfg':{'sticky':'we', 'column':1,'row':-1}, 2139 'command':CallBackFunction(self.Close_cb, ifd)}) 2140 self.form = self.vf.getUserInput(self.ifd, modal=0, blocking=0) 2141 self.form.root.protocol('WM_DELETE_WINDOW', CallBackFunction(self.Close_cb,ifd))
2142 2143
2144 - def disableCallbackFreq(self, event=None):
2145 w = self.ifd.entryByName['callback_ent']['widget'] 2146 if self.callback.get(): 2147 w.config(state='normal', fg='black', selectbackground='#c3c3c3', 2148 selectforeground='black') 2149 else: 2150 w.config(state='disabled', fg='grey', selectbackground='#d9d9d9', 2151 selectforeground='grey')
2152 2153
2154 - def set_filename(self, event=None):
2155 self.ifd.entryByName['trjCB']['widget'].toggle() 2156 #if getattr(prmlib.cvar, 'ntwx')==0: 2157 if prmlib.SFFoptions_ntwx_get(self.CurrentAmber94.sff_opts) == 0: 2158 self.warningMsg("must set ntwx first!") 2159 return 2160 file = self.vf.askFileSave(types=[('trj files:', '*.trj'),('allfiles:','*.*')], 2161 title='amber94 md trajectory file:') 2162 if file: 2163 self.TrjFilename.set(file) #this has the whole pathname etc 2164 else: 2165 self.TrjFilename.set('')
2166 2167
2168 - def Accept_cb(self, event=None):
2169 self.form.withdraw() 2170 #FIX THIS!! 2171 key = self.ifd.entryByName['amberIds']['widget'].get() 2172 amb_ins = Amber94Config[key][0] 2173 if self.callback.get(): 2174 #add the coords here 2175 amb_ins = Amber94Config[key][0] 2176 if not hasattr(amb_ins, 'coord_index'): 2177 amb_ins.atoms.addConformation(amb_ins.atoms.coords[:]) 2178 amb_ins.coord_index = len(amb_ins.atoms[0]._coords)-1 2179 #newConfNum = len(allAtoms[0]._coords)-1 2180 #allAtoms.setConformation(newConfNum) 2181 freq = int(self.callbackFreq.get()) 2182 print 'setting callback to updateCoords' 2183 amb_ins.setCallback(self.updateCoords, freq) 2184 else: 2185 amb_ins.coord_index = 1 2186 #start md 2187 d = {} 2188 d['callback'] = self.callback.get() 2189 d['callback_freq'] = int(self.callbackFreq.get()) 2190 #put wcons into dictionary 2191 wcons = round(self.ifd.entryByName['wcons_tw']['widget'].get(),4) 2192 if wcons: 2193 d['wcons'] = wcons 2194 maxStep = self.ifd.entryByName['maxStep_tw']['widget'].get() 2195 if hasattr(self, 'TrjFilename'): 2196 filename = self.TrjFilename.get() 2197 if len(filename): 2198 d['filename'] = filename 2199 return apply(self.doitWrapper, (key, maxStep,), d)
2200 2201
2202 - def setMdOpts(self, event=None):
2203 #turn off button 2204 self.ifd.entryByName['setmdopts_cb']['widget'].toggle() 2205 self.vf.setmdOpts_Amber94.guiCallback()
2206 2207
2208 - def setFrozenAtoms(self, event=None):
2209 #turn off button 2210 self.ifd.entryByName['setfroz_cb']['widget'].toggle() 2211 print 'calling freezeAtoms' 2212 numFrozen = self.vf.freezeAtoms_Amber94.