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

Source Code for Module Pmv.hbondCommands

   1   
   2  ############################################################################ 
   3  # 
   4  # Author: Ruth HUEY 
   5  # 
   6  # Copyright: M. Sanner TSRI 2000 
   7  # 
   8  ############################################################################# 
   9   
  10  # $Header 
  11  # 
  12  # $Id: hbondCommands.py,v 1.84.4.2 2007/09/21 22:30:06 sargis Exp $ 
  13  # 
  14   
  15   
  16  from ViewerFramework.VFCommand import CommandGUI 
  17  from ViewerFramework.VF import AddAtomsEvent 
  18  from mglutil.gui.BasicWidgets.Tk.colorWidgets import ColorChooser 
  19   
  20  from mglutil.gui.InputForm.Tk.gui import InputFormDescr 
  21  from mglutil.util.callback import CallBackFunction 
  22  from mglutil.gui.BasicWidgets.Tk.customizedWidgets \ 
  23      import ExtendedSliderWidget, ListChooser 
  24  from mglutil.gui.BasicWidgets.Tk.thumbwheel import ThumbWheel 
  25   
  26  from Pmv.mvCommand import MVCommand, MVAtomICOM, MVBondICOM 
  27  from Pmv.measureCommands import MeasureAtomCommand 
  28   
  29  from MolKit.molecule import Atom, AtomSet, Bond 
  30  from MolKit.molecule import BondSet, HydrogenBond, HydrogenBondSet 
  31  from MolKit.distanceSelector import DistanceSelector 
  32  from MolKit.hydrogenBondBuilder import HydrogenBondBuilder 
  33  from MolKit.pdbWriter import PdbWriter 
  34   
  35  from DejaVu.Geom import Geom 
  36  from DejaVu.Spheres import Spheres 
  37  from DejaVu.Points import CrossSet 
  38  from DejaVu.Cylinders import Cylinders 
  39  from DejaVu.spline import DialASpline, SplineObject 
  40  from DejaVu.GleObjects import GleExtrude, GleObject 
  41  from DejaVu.Shapes import Shape2D, Triangle2D, Circle2D, Rectangle2D,\ 
  42       Square2D, Ellipse2D 
  43   
  44  from Pmv.stringSelectorGUI import StringSelectorGUI 
  45  from PyBabel.util import vec3 
  46   
  47  import Tkinter, Numeric, math, string, os 
  48  from string import strip, split 
  49  from types import StringType 
  50   
  51  from opengltk.OpenGL import GL 
  52   
  53  from DejaVu.glfLabels import GlfLabels 
  54   
  55   
56 -def check_hbond_geoms(VFGUI):
57 hbond_geoms_list = VFGUI.VIEWER.findGeomsByName('hbond_geoms') 58 if hbond_geoms_list==[]: 59 hbond_geoms = Geom("hbond_geoms", shape=(0,0), protected=True) 60 VFGUI.VIEWER.AddObject(hbond_geoms, parent=VFGUI.miscGeom) 61 hbond_geoms_list = [hbond_geoms] 62 return hbond_geoms_list[0]
63 64 65 66 # lists of babel_types for donor-acceptor 67 # derived from MacDonald + Thornton 68 # 'Atlas of Side-Chain + Main-Chain Hydrogen Bonding' 69 # plus sp2Acceptor Nam 70 71 sp2Donors = ['Nam', 'Ng+', 'Npl'] 72 sp3Donors = ['N3+', 'O3','S3'] 73 allDonors = [] 74 allDonors.extend(sp2Donors) 75 allDonors.extend(sp3Donors) 76 #added Nam because of bdna cytidine N3 77 #NB: Npl cannot be an acceptor if the sum of its bonds' bondOrder>2 78 sp2Acceptors = ['O2', 'O-', 'Npl', 'Nam'] 79 sp3Acceptors = ['S3', 'O3'] 80 allAcceptors = [] 81 allAcceptors.extend(sp2Acceptors) 82 allAcceptors.extend(sp3Acceptors) 83 a_allAcceptors = [] 84 for n in allAcceptors: 85 a_allAcceptors.append('a'+n) 86 87
88 -def dist(c1, c2):
89 d = Numeric.array(c2) - Numeric.array(c1) 90 ans = math.sqrt(Numeric.sum(d*d)) 91 return round(ans, 3)
92 93
94 -def getAngle(ac, hat, don ):
95 acCoords = getTransformedCoords(ac) 96 hCoords = getTransformedCoords(hat) 97 dCoords = getTransformedCoords(don) 98 pt1 = Numeric.array(acCoords, 'f') 99 pt2 = Numeric.array(hCoords, 'f') 100 pt3 = Numeric.array(dCoords, 'f') 101 #pt1 = Numeric.array(ac.coords, 'f') 102 #pt2 = Numeric.array(hat.coords, 'f') 103 #pt3 = Numeric.array(don.coords, 'f') 104 v1 = Numeric.array(pt1 - pt2) 105 v2 = Numeric.array(pt3 - pt2) 106 dist1 = math.sqrt(Numeric.sum(v1*v1)) 107 dist2 = math.sqrt(Numeric.sum(v2*v2)) 108 sca = Numeric.dot(v1, v2)/(dist1*dist2) 109 if sca>1.0: 110 sca = 1.0 111 elif sca<-1.0: 112 sca = -1.0 113 ang = math.acos(sca)*180./math.pi 114 return round(ang, 5)
115 116
117 -def applyTransformation(pt, mat):
118 pth = [pt[0], pt[1], pt[2], 1.0] 119 return Numeric.matrixmultiply(mat, pth)[:3]
120 121
122 -def getTransformedCoords(atom):
123 # when there is no viewer, the geomContainer is None 124 if atom.top.geomContainer is None: 125 return atom.coords 126 g = atom.top.geomContainer.geoms['master'] 127 c = applyTransformation(atom.coords, g.GetMatrix(g)) 128 return c.astype('f')
129 130 131
132 -class GetHydrogenBondDonors(MVCommand):
133 """This class allows user to get AtomSets of sp2 hydridized and sp3 hybridized hydrogenBond Donors able. 134 \nPackage : Pmv 135 \nModule : bondsCommands 136 \nClass : GetHydrogenBondDonors 137 \nCommand :getHBDonors 138 \nSynopsis:\n 139 sp2Donors, sp3Donors <- getHBDonors(nodes, donorList, **kw) 140 \nRequired Arguments:\n 141 nodes --- 142 donorList --- 143 """ 144
145 - def __init__(self, func=None):
146 MVCommand.__init__(self, func) 147 self.flag = self.flag | self.objArgOnly
148
149 - def onAddCmdToViewer(self):
150 if not self.vf.commands.has_key('typeAtoms'): 151 self.vf.loadCommand('editCommands', 'typeAtoms', 'Pmv', 152 topCommand=0)
153 154
155 - def __call__(self, nodes, donorList=allDonors,**kw):
156 """sp2Donors, sp3Donors <- getHBDonors(nodes, donorList, **kw) """ 157 if type(nodes) is StringType: 158 self.nodeLogString = "'"+nodes+"'" 159 nodes = self.vf.expandNodes(nodes) 160 if not len(nodes): return 'ERROR' 161 ats = nodes.findType(Atom) 162 try: 163 ats.babel_type 164 except AttributeError: 165 tops = ats.top.uniq() 166 for t in tops: 167 self.vf.typeAtoms(t.allAtoms, topCommand=0) 168 return apply(self.doitWrapper, (ats, donorList), kw)
169 170
171 - def checkForPossibleH(self, ats, blen):
172 #check that if at has all bonds, at least one is to a hydrogen 173 # have to do this by element?? 174 probAts = AtomSet(ats.get(lambda x, blen=blen: len(x.bonds)==blen)) 175 #probOAts = ats.get(lambda x, blen=blen: len(x.bonds)==blen) 176 #probSAts = ats.get(lambda x, blen=blen: len(x.bonds)==blen) 177 if probAts: 178 rAts = AtomSet([]) 179 for at in probAts: 180 if not len(at.findHydrogens()): 181 rAts.append(at) 182 if len(rAts): 183 ats = ats.subtract(rAts) 184 return ats
185 186
187 - def doit(self, ats, donorList):
188 #getHBDonors 189 sp2 = [] 190 sp3 = [] 191 for item in sp2Donors: 192 if item in donorList: sp2.append(item) 193 for item in sp3Donors: 194 if item in donorList: sp3.append(item) 195 196 dAts2 = ats.get(lambda x, l=sp2: x.babel_type in l) 197 if not dAts2: dAts2=AtomSet([]) 198 else: 199 dAts2 = self.checkForPossibleH(dAts2, 3) 200 201 dAts3 = ats.get(lambda x, l=sp3: x.babel_type in l) 202 if not dAts3: dAts3=AtomSet([]) 203 else: dAts3 = self.checkForPossibleH(dAts3, 4) 204 205 return dAts2, dAts3
206 207 208
209 -class GetHydrogenBondAcceptors(MVCommand):
210 """This class allows user to get AtomSets of sp2 hydridized and sp3 hybridized 211 hydrogenBond Acceptors. 212 \nPackage : Pmv 213 \nModule : hbondCommands 214 \nClass : GetHydrogenBondEnergies 215 \nCommand : getHBondEnergies 216 \nSynopsis:\n 217 sp2Acceptors, sp3Acceptors <- getHBAcceptors(nodes, acceptorList, **kw) 218 """ 219
220 - def __init__(self, func=None):
221 MVCommand.__init__(self, func) 222 self.flag = self.flag | self.objArgOnly
223
224 - def onAddCmdToViewer(self):
225 if not self.vf.commands.has_key('typeAtoms'): 226 self.vf.loadCommand('editCommands', 'typeAtoms', 'Pmv', 227 topCommand=0)
228 229
230 - def __call__(self, nodes, acceptorList=allAcceptors,**kw):
231 """sp2Acceptors, sp3Acceptors <- getHBAcceptors(nodes, acceptorList, **kw) """ 232 if type(nodes) is StringType: 233 self.nodeLogString = "'"+nodes+"'" 234 nodes = self.vf.expandNodes(nodes) 235 if not len(nodes): return 'ERROR' 236 ats = nodes.findType(Atom) 237 #no way to know if typeBonds has been called on each molecule! 238 try: 239 ats._bndtyped 240 except: 241 tops = ats.top.uniq() 242 for t in tops: 243 self.vf.typeBonds(t.allAtoms, topCommand=0) 244 return apply(self.doitWrapper, (ats, acceptorList), kw)
245 246
247 - def filterAcceptors(self, accAts):
248 ntypes = ['Npl', 'Nam'] 249 npls = accAts.get(lambda x, ntypes=ntypes: x.babel_type=='Npl') 250 nams = accAts.get(lambda x, ntypes=ntypes: x.babel_type=='Nam') 251 #nAts = accAts.get(lambda x, ntypes=ntypes: x.babel_type in ntypes) 252 restAts = accAts.get(lambda x, ntypes=ntypes: x.babel_type not in ntypes) 253 if not restAts: restAts = AtomSet([]) 254 #if nAts: 255 if npls: 256 #for at in nAts: 257 for at in npls: 258 s = 0 259 for b in at.bonds: 260 if b.bondOrder=='aromatic': 261 s = s + 2 262 else: s = s + b.bondOrder 263 #if s<3: 264 #apparently this is wrong 265 if s<4: 266 restAts.append(at) 267 if nams: 268 #for at in nAts: 269 for at in nams: 270 s = 0 271 for b in at.bonds: 272 if b.bondOrder=='aromatic': 273 s = s + 2 274 else: s = s + b.bondOrder 275 #s = s + b.bondOrder 276 if s<3: 277 restAts.append(at) 278 return restAts
279 280 281
282 - def doit(self, ats, acceptorList):
283 #getHBAcceptors 284 sp2 = [] 285 sp3 = [] 286 for item in sp2Acceptors: 287 if item in acceptorList: sp2.append(item) 288 for item in sp3Acceptors: 289 if item in acceptorList: sp3.append(item) 290 291 dAts2 = AtomSet(ats.get(lambda x, l=sp2: x.babel_type in l)) 292 if dAts2: 293 dAts2 = self.filterAcceptors(dAts2) 294 dAts3 = AtomSet(ats.get(lambda x, l=sp3: x.babel_type in l)) 295 return dAts2, dAts3
296 297 298
299 -class GetHydrogenBondEnergies(MVCommand):
300 """This class allows user to get a list of energies of HydrogenBonds. For this calculation, the bond must have a hydrogen atom AND it must know its type. 301 Energy calculation based on "Protein Flexibility and dynamics using constraint 302 theory", J. Molecular Graphics and Modelling 19, 60-69, 2001. MF Thorpe, Ming 303 Lei, AJ Rader, Donald J.Jacobs and Leslie A. Kuhn. 304 \nPackage : Pmv 305 \nModule : hbondCommands 306 \nClass : GetHydrogenBondEnergies 307 \nCommand : getHBondEnergies 308 \nSynopsis:\n 309 [energies] <- getHBondEnergies(nodes, **kw) 310 \nRequired Arguments:\n 311 nodes --- TreeNodeSet holding the current selection 312 """ 313
314 - def __init__(self, func=None):
315 MVCommand.__init__(self, func) 316 self.flag = self.flag | self.objArgOnly
317
318 - def onAddCmdToViewer(self):
319 self.vf.loadModule('measureCommands', 'Pmv', log=0) 320 if not self.vf.commands.has_key('typeAtoms'): 321 self.vf.loadCommand('editCommands', 'typeAtoms', 'Pmv', 322 topCommand=0, log=0)
323 324
325 - def __call__(self, nodes, **kw):
326 """[energies] <- getHBondEnergies(nodes, **kw) 327 \nnodes --- TreeNodeSet holding the current selection 328 """ 329 if type(nodes) is StringType: 330 self.nodeLogString = "'"+nodes+"'" 331 nodes = self.vf.expandNodes(nodes) 332 if not len(nodes): return 'ERROR' 333 ats = nodes.findType(Atom) 334 hats = AtomSet([]) 335 for at in ats: 336 if hasattr(at, 'hbonds'): hats.append(at) 337 if not len(hats): 338 self.warningMsg('no hbonds in specified nodes') 339 return 'ERROR' 340 return apply(self.doitWrapper, (hats,), kw)
341 342
343 - def getEnergy(self, b):
344 accAt = b.accAt 345 b0 = accAt.bonds[0] 346 acN = b0.atom1 347 if id(acN)==id(accAt): acN = b0.atom2 348 b.acN = acN 349 #b.acN = b.accAt.bonds[0].neighborAtom(b.accAt) 350 if b.dlen is None: 351 b.dlen = dist(getTransformedCoords(b.donAt), 352 getTransformedCoords(b.accAt)) 353 #b.dlen = dist(b.donAt.coords, b.accAt.coords) 354 r = 2.8/b.dlen 355 if b.phi is None: b.phi = self.vf.measureAngle(b.hAt, b.accAt, 356 acN, topCommand=0) 357 if b.theta is None: b.theta = self.vf.measureAngle(b.donAt, b.hAt, 358 b.accAt, topCommand=0) 359 b.gamma = self.vf.measureTorsion(b.donAt, b.hAt, b.accAt, 360 acN, topCommand=0) 361 #make all angles into radians 362 theta = b.theta * math.pi/180. 363 newAngle = math.pi - theta 364 gamma = b.gamma * math.pi/180. 365 phi = b.phi * math.pi/180. 366 n = 109.5*math.pi/180. 367 368 if b.type is None: 369 #get # of donAt+# of accAt 370 try: 371 b.donAt.babel_type 372 b.accAt.babel_type 373 except AttributeError: 374 b_ats = AtomSet([b.donAt, b.accAt]) 375 tops = b_ats.top.uniq() 376 for t in tops: 377 self.vf.typeAtoms(t.allAtoms, topCommand=0) 378 if b.donAt.babel_type in sp2Donors: 379 d1=20 380 else: 381 d1=30 382 if b.accAt.babel_type in sp2Acceptors: 383 d2=2 384 else: 385 d2=3 386 b.type = d1+d2 387 388 389 if b.type==33: 390 f = (math.cos(theta)**2)*\ 391 (math.e**(-(newAngle)**6))*(math.cos(phi-n)**2) 392 elif b.type==32: 393 f = (math.cos(theta)**2)*\ 394 (math.e**(-(newAngle)**6))*(math.cos(phi)**2) 395 elif b.type==23: 396 f = ((math.cos(theta)**2)*\ 397 (math.e**(-(newAngle)**6)))**2 398 else: 399 f = (math.cos(theta)**2)*\ 400 (math.e**(-(newAngle)**6))*(math.cos(max(theta, gamma))**2) 401 newVal = 8.*(5.*(r**12) - 6.*(r**10))*f 402 b.energy = round(newVal, 3) 403 return b.energy
404 405
406 - def doit(self, hats):
407 #getHBondEnergies 408 energyList = [] 409 hbonds = hats.hbonds 410 #SHOULD hbonds be checked for type??? HERE??????? 411 for b in hbonds: 412 if b.energy: 413 energyList.append(b.energy) 414 elif b.hAt is None: 415 energyList.append(None) 416 else: 417 energyList.append(self.getEnergy(b)) 418 #print 'returning ', len(energyList), ' hbond energies: ', energyList 419 return energyList
420 421 422
423 -class ShowHBDonorsAcceptors(MVCommand):
424 """This class allows user to show AtomSets of HydrogenBond donors and acceptors. 425 \nPackage : Pmv 426 \nModule : hbondCommands 427 \nClass : ShowHBDonorsAcceptors 428 \nCommand : showHBDA 429 \nSynopsis:\n 430 None <- showHBDA(dnodes, anodes, donorList, acceptorList, **kw) 431 """ 432 433
434 - def onAddCmdToViewer(self):
435 self.vf.loadModule('editCommands', 'Pmv', log=0) 436 self.vf.loadCommand('interactiveCommands','setICOM', 'Pmv', log=0) 437 #setup geoms 438 miscGeom = self.vf.GUI.miscGeom 439 hbond_geoms = check_hbond_geoms(self.vf.GUI) 440 self.masterGeom = Geom('hbondDonorAcceptorGeoms',shape=(0,0), 441 pickable=0, protected=True) 442 self.masterGeom.isScalable = 0 443 self.vf.GUI.VIEWER.AddObject(self.masterGeom, parent=hbond_geoms) 444 self.hbdonor2=CrossSet('hbSP2Donors', 445 materials=((0.,1.,1.),), offset=0.4, lineWidth=2, 446 inheritMaterial=0, protected=True) 447 self.hbdonor2.Set(visible=1, tagModified=False) 448 self.hbdonor2.pickable = 0 449 self.hbdonor3=CrossSet('hbSP3Donors', 450 materials=((0.,.3,1.),), offset=0.4, lineWidth=2, 451 inheritMaterial=0, protected=True) 452 self.hbacceptor2=Spheres('hbSP2Acceptors', shape=(0,3), 453 radii=0.2, quality=15, materials=((1.,.8,0.),), inheritMaterial=0, protected=True) 454 self.hbacceptor3=Spheres('hbSP3Acceptors', shape=(0,3), 455 radii=0.2, quality=15, materials=((1.,.2,0.),), inheritMaterial=0, protected=True) 456 for item in [self.hbdonor2, self.hbdonor3, self.hbacceptor2,\ 457 self.hbacceptor3]: 458 item.Set(visible=1, tagModified=False) 459 item.pickable = 0 460 self.vf.GUI.VIEWER.AddObject(item, parent=self.masterGeom) 461 #setup Tkinter variables 462 varNames = ['hideDSel', 'N3', 'O3','S3','Nam', 'Ng', 'Npl',\ 463 'hideASel', 'aS3', 'aO3', 'aO2', 'aO', 'aNpl', 464 'aNam', 'sp2D', 'sp3D', 'sp2A', 'sp3A','useSelection'] 465 466 for n in varNames: 467 exec('self.'+n+'=Tkinter.IntVar()') 468 exec('self.'+n+'.set(1)') 469 self.showDTypeSel = Tkinter.IntVar() 470 self.showATypeSel = Tkinter.IntVar()
471 472
473 - def __call__(self, dnodes, anodes, donorList=allDonors, 474 acceptorList=allAcceptors, **kw):
475 """None <- showHBDA(dnodes, anodes, donorList, acceptorList, **kw) """ 476 477 dnodes = self.vf.expandNodes(dnodes) 478 donats = dnodes.findType(Atom) 479 anodes = self.vf.expandNodes(anodes) 480 acats = anodes.findType(Atom) 481 if not (len(donats) or len(acats)): return 'ERROR' 482 apply(self.doitWrapper, (donats, acats, donorList, acceptorList), kw)
483 484
485 - def doit(self, donats, acats, donorList, acceptorList):
486 #showHBDA 487 if len(donats): 488 dAts2, dAts3 = self.vf.getHBDonors(donats, 489 donorList=donorList, topCommand=0) 490 msg = '' 491 if dAts2: 492 newVerts = [] 493 for at in dAts2: 494 newVerts.append(getTransformedCoords(at).tolist()) 495 self.hbdonor2.Set(vertices=newVerts, visible=1, 496 tagModified=False) 497 #self.hbdonor2.Set(vertices = dAts2.coords, visible=1, 498 # tagModified=False) 499 else: 500 msg = msg + 'no sp2 donors found ' 501 dAts2 = AtomSet([]) 502 self.hbdonor2.Set(vertices=[], tagModified=False) 503 if dAts3: 504 newVerts = [] 505 for at in dAts3: 506 newVerts.append(getTransformedCoords(at).tolist()) 507 self.hbdonor3.Set(vertices=newVerts, visible=1, 508 tagModified=False) 509 #self.hbdonor3.Set(vertices = dAts3.coords, visible=1, tagModified=False 510 else: 511 if len(msg): msg = msg + ';' 512 msg = msg + 'no sp3 donors found' 513 dAts3 = AtomSet([]) 514 self.hbdonor3.Set(vertices=[], tagModified=False) 515 if len(msg): 516 self.warningMsg(msg) 517 else: 518 dAts2 = AtomSet([]) 519 dAts3 = AtomSet([]) 520 self.hbdonor2.Set(vertices=[], tagModified=False) 521 self.hbdonor3.Set(vertices=[], tagModified=False) 522 #NOW THE ACCEPTORS: 523 if len(acats): 524 acAts2, acAts3 = self.vf.getHBAcceptors(acats, 525 acceptorList=acceptorList, topCommand=0) 526 msg = '' 527 if acAts2: 528 newVerts = [] 529 for at in acAts2: 530 newVerts.append(getTransformedCoords(at).tolist()) 531 self.hbacceptor2.Set(vertices = newVerts, visible=1, 532 tagModified=False) 533 #self.hbacceptor2.Set(vertices = acAts2.coords, visible=1, tagModified=False) 534 else: 535 msg = msg + 'no sp2 acceptors found ' 536 acAts2 = AtomSet([]) 537 self.hbacceptor2.Set(vertices=[], tagModified=False) 538 if acAts3: 539 newVerts = [] 540 for at in acAts3: 541 newVerts.append(getTransformedCoords(at).tolist()) 542 self.hbacceptor3.Set(vertices = newVerts, visible=1, 543 tagModified=False) 544 #self.hbacceptor3.Set(vertices = acAts3.coords, visible=1, tagModified=False) 545 else: 546 if len(msg): msg = msg + ';' 547 msg = msg + 'no sp3 acceptors found' 548 acAts3 = AtomSet([]) 549 self.hbacceptor3.Set(vertices=[], tagModified=False) 550 if len(msg): self.warningMsg(msg) 551 else: 552 acAts2 = AtomSet([]) 553 acAts3 = AtomSet([]) 554 self.hbacceptor2.Set(vertices=[], tagModified=False) 555 self.hbacceptor3.Set(vertices=[], tagModified=False) 556 self.vf.GUI.VIEWER.Redraw() 557 #PUT UP A FORM TO TOGGLE Visibility etc (?) 558 # show/hide sp2/sp3 559 # select, save 560 if not len(dAts2) and not len(dAts3) and not len(acAts2)\ 561 and not len(acAts3): 562 self.warningMsg('no donors or acceptors found') 563 return 564 ifd2 = self.ifd2 = InputFormDescr(title = "Show/Hide Donors and Acceptors") 565 if len(dAts2): 566 ifd2.append({'name':'donor2', 567 'widgetType':Tkinter.Checkbutton, 568 'wcfg':{'text':'sp2 donors ', 569 'variable': self.sp2D, 570 'command': CallBackFunction(self.showGeom, 571 self.hbdonor2, self.sp2D), 572 }, 573 'gridcfg':{'sticky':'w'}}) 574 if len(dAts3): 575 ifd2.append({'name':'donor3', 576 'widgetType':Tkinter.Checkbutton, 577 'wcfg':{'text':'sp3 donors ', 578 'variable': self.sp3D, 579 'command': CallBackFunction(self.showGeom, 580 self.hbdonor3, self.sp3D), 581 }, 582 'gridcfg':{'sticky':'w'}}) 583 # 'gridcfg':{'sticky':'w', 'row':-1, 'column':1}}) 584 if len(acAts2): 585 ifd2.append({'name':'accept2', 586 'widgetType':Tkinter.Checkbutton, 587 'wcfg':{'text':'sp2 acceptors ', 588 'variable': self.sp2A, 589 'command': CallBackFunction(self.showGeom, 590 self.hbacceptor2, self.sp2A), 591 }, 592 'gridcfg':{'sticky':'w'}}) 593 if len(acAts3): 594 ifd2.append({'name':'accept3', 595 'widgetType':Tkinter.Checkbutton, 596 'wcfg':{'text':'sp3 acceptors ', 597 'variable': self.sp3A, 598 'command': CallBackFunction(self.showGeom, 599 self.hbacceptor3, self.sp3A), 600 }, 601 'gridcfg':{'sticky':'w'}}) 602 #'gridcfg':{'sticky':'w', 'row':-1, 'column':1}}) 603 ifd2.append({'widgetType': Tkinter.Button, 604 'text':'Select', 605 'wcfg':{'bd':6}, 606 'gridcfg':{'sticky':'ew' }, 607 'command':CallBackFunction(self.select_cb,dAts2,dAts3,acAts2,acAts3)}) 608 ifd2.append({'widgetType': Tkinter.Button, 609 'text':'Cancel', 610 'wcfg':{'bd':6}, 611 'gridcfg':{'sticky':'ew', 'column':1,'row':-1}, 612 'command':self.cancel_cb}) 613 self.form2 = self.vf.getUserInput(self.ifd2, modal=0, blocking=0) 614 self.form2.root.protocol('WM_DELETE_WINDOW',self.cancel_cb)
615 616 617
618 - def showGeom(self, geom, var, event=None):
619 geom.Set(visible=var.get(), tagModified=False) 620 self.vf.GUI.VIEWER.Redraw()
621 622
623 - def select_cb(self, dAts2, dAts3, acAts2, acAts3):
624 #NB need to set level to Atom 625 self.vf.setIcomLevel(Atom) 626 vars = [self.sp2D, self.sp2D, self.sp2A, self.sp3A] 627 atL = [dAts2, dAts3, acAts2, acAts3] 628 for i in range(4): 629 if vars[i].get() and len(atL[i]): 630 self.vf.select(atL[i])
631 632
633 - def cancel_cb(self, event=None):
634 for g in [self.hbdonor2, self.hbdonor3, self.hbacceptor2,\ 635 self.hbacceptor3]: 636 g.Set(vertices=[], tagModified=False) 637 self.vf.GUI.VIEWER.Redraw() 638 self.form2.destroy()
639 640
641 - def buildForm(self):
642 ifd = self.ifd = InputFormDescr(title = "Select nodes + types of donor-acceptors:") 643 ifd.append({'name':'DkeyLab', 644 'widgetType':Tkinter.Label, 645 'text':'For Hydrogen Bonds Donors:', 646 'gridcfg':{'sticky':'w','columnspan':3}}) 647 ifd.append({'name':'selDRB0', 648 'widgetType':Tkinter.Radiobutton, 649 'wcfg':{'text':'Use all atoms', 650 'variable': self.hideDSel, 651 'value':1, 652 'command':self.hideDSelector 653 }, 654 'gridcfg':{'sticky':'w'}}) 655 ifd.append({'name':'selDRB1', 656 'widgetType':Tkinter.Radiobutton, 657 'wcfg':{'text':'Set atoms to use', 658 'variable': self.hideDSel, 659 'value':0, 660 'command':self.hideDSelector 661 }, 662 'gridcfg':{'sticky':'w', 'row':-1, 'column':1}}) 663 ifd.append({'name': 'keyDSelector', 664 'wtype':StringSelectorGUI, 665 'widgetType':StringSelectorGUI, 666 'wcfg':{ 'molSet': self.vf.Mols, 667 'vf': self.vf, 668 'all':1, 669 'crColor':(0.,1.,.2), 670 }, 671 'gridcfg':{'sticky':'we', 'columnspan':2 }}) 672 ifd.append({'name':'limitDTypes', 673 'widgetType':Tkinter.Checkbutton, 674 'wcfg':{'text':'Limit donor types ', 675 'variable': self.showDTypeSel, 676 'command':self.hideDTypes 677 }, 678 'gridcfg':{'sticky':'w', 'columnspan':2}}) 679 ifd.append({'name':'N3+', 680 'widgetType':Tkinter.Checkbutton, 681 'wcfg':{'text':'N3+', 682 'variable': self.N3, }, 683 'gridcfg':{'sticky':'w'}}) 684 ifd.append({'name':'O3', 685 'widgetType':Tkinter.Checkbutton, 686 'wcfg':{'text':'O3', 687 'variable': self.O3, }, 688 'gridcfg':{'sticky':'w','row':-1, 'column':1}}) 689 ifd.append({'name':'S3', 690 'widgetType':Tkinter.Checkbutton, 691 'wcfg':{'text':'S3', 692 'variable': self.S3, }, 693 'gridcfg':{'sticky':'w','row':-1, 'column':2}}) 694 ifd.append({'name':'Nam', 695 'widgetType':Tkinter.Checkbutton, 696 'wcfg':{'text':'Nam', 697 'variable': self.Nam, }, 698 'gridcfg':{'sticky':'w'}}) 699 ifd.append({'name':'Ng+', 700 'widgetType':Tkinter.Checkbutton, 701 'wcfg':{'text':'Ng+', 702 'variable': self.Ng, }, 703 'gridcfg':{'sticky':'w','row':-1, 'column':1}}) 704 ifd.append({'name':'Npl', 705 'widgetType':Tkinter.Checkbutton, 706 'wcfg':{'text':'Npl', 707 'variable': self.Npl, }, 708 'gridcfg':{'sticky':'w','row':-1, 'column':2}}) 709 #now the acceptors 710 ifd.append({'name':'AkeyLab', 711 'widgetType':Tkinter.Label, 712 'text':'For Hydrogen Bonds Acceptors:', 713 'gridcfg':{'sticky':'w','columnspan':3}}) 714 ifd.append({'name':'selARB0', 715 'widgetType':Tkinter.Radiobutton, 716 'wcfg':{'text':'Use all atoms', 717 'variable': self.hideASel, 718 'value':1, 719 'command':self.hideASelector 720 }, 721 'gridcfg':{'sticky':'w'}}) 722 ifd.append({'name':'selARB1', 723 'widgetType':Tkinter.Radiobutton, 724 'wcfg':{'text':'Set atoms to use', 725 'variable': self.hideASel, 726 'value':0, 727 'command':self.hideASelector 728 }, 729 'gridcfg':{'sticky':'w', 'row':-1, 'column':1}}) 730 ifd.append({'name': 'keyASelector', 731 'wtype':StringSelectorGUI, 732 'widgetType':StringSelectorGUI, 733 'wcfg':{ 'molSet': self.vf.Mols, 734 'vf': self.vf, 735 'all':1, 736 'crColor':(0.,1.,.2), 737 }, 738 'gridcfg':{'sticky':'we', 'columnspan':2 }}) 739 ifd.append({'name':'limitTypes', 740 'widgetType':Tkinter.Checkbutton, 741 'wcfg':{'text':'Limit acceptor types ', 742 'variable': self.showATypeSel, 743 'command':self.hideATypes 744 }, 745 'gridcfg':{'sticky':'w', 'columnspan':2}}) 746 ifd.append({'name':'aO3', 747 'widgetType':Tkinter.Checkbutton, 748 'wcfg':{'text':'O3', 749 'variable': self.aO3, }, 750 'gridcfg':{'sticky':'w'}}) 751 ifd.append({'name':'aS3', 752 'widgetType':Tkinter.Checkbutton, 753 'wcfg':{'text':'S3', 754 'variable': self.aS3, }, 755 'gridcfg':{'sticky':'w','row':-1, 'column':1}}) 756 ifd.append({'name':'aO2', 757 'widgetType':Tkinter.Checkbutton, 758 'wcfg':{'text':'O2', 759 'variable': self.aO2, }, 760 'gridcfg':{'sticky':'w','row':-1, 'column':2}}) 761 ifd.append({'name':'aO-', 762 'widgetType':Tkinter.Checkbutton, 763 'wcfg':{'text':'O-', 764 'variable': self.aO,}, 765 'gridcfg':{'sticky':'w'}}) 766 ifd.append({'name':'aNpl', 767 'widgetType':Tkinter.Checkbutton, 768 'wcfg':{'text':'Npl', 769 'variable': self.aNpl, }, 770 'gridcfg':{'sticky':'w', 'row':-1, 'column':1}}) 771 ifd.append({'name':'aNam', 772 'widgetType':Tkinter.Checkbutton, 773 'wcfg':{'text':'Nam', 774 'variable': self.aNam, }, 775 'gridcfg':{'sticky':'w','row':-1, 'column':2}}) 776 ifd.append({'name':'useSelCB', 777 'widgetType':Tkinter.Checkbutton, 778 'wcfg':{'text':'select from current selection', 779 'variable': self.useSelection, }, 780 'gridcfg':{'sticky':'w'}}) 781 ifd.append({'widgetType': Tkinter.Button, 782 'text':'Ok', 783 'wcfg':{'bd':6}, 784 'gridcfg':{'sticky':'ew', 'columnspan':2 }, 785 'command':self.Accept_cb}) 786 ifd.append({'widgetType': Tkinter.Button, 787 'text':'Cancel', 788 'wcfg':{'bd':6}, 789 'gridcfg':{'sticky':'ew', 'column':2,'row':-1}, 790 'command':self.Close_cb}) 791 self.form = self.vf.getUserInput(self.ifd, modal=0, blocking=0) 792 self.hideDSelector() 793 self.hideDTypes() 794 self.hideASelector() 795 self.hideATypes()
796 797
798 - def guiCallback(self):
799 if not len(self.vf.Mols): 800 self.warningMsg('no molecules in viewer') 801 return 802 if not hasattr(self, 'ifd'): 803 self.buildForm()
804 805
806 - def Close_cb(self, event=None):
807 self.form.destroy()
808 809
810 - def Accept_cb(self, event=None):
811 self.form.withdraw() 812 dnodesToCheck = self.ifd.entryByName['keyDSelector']['widget'].get() 813 if not len(dnodesToCheck): 814 self.warningMsg('no donor atoms specified') 815 dats = AtomSet([]) 816 else: 817 dats = dnodesToCheck.findType(Atom) 818 if self.useSelection.get(): 819 curSel = self.vf.getSelection() 820 if len(curSel): 821 curAts = curSel.findType(Atom) 822 if curAts != self.vf.allAtoms: 823 dats = curAts.inter(dats) 824 if dats is None: 825 msg = 'no specified donor atoms in current selection' 826 self.warningMsg(msg) 827 dats = AtomSet([]) 828 else: 829 msg = 'no current selection' 830 self.warningMsg(msg) 831 dats = AtomSet([]) 832 donorList = [] 833 for n in allDonors: 834 v = self.ifd.entryByName[n]['wcfg']['variable'] 835 if v.get(): 836 donorList.append(n) 837 if not len(donorList): 838 self.warningMsg('no donor types selected') 839 ###FIX THIS!!! 840 anodesToCheck = self.ifd.entryByName['keyASelector']['widget'].get() 841 if not len(anodesToCheck): 842 self.warningMsg('no acceptor atoms specified') 843 acats = AtomSet([]) 844 #return 845 else: 846 acats = anodesToCheck.findType(Atom) 847 if self.useSelection.get(): 848 curSel = self.vf.getSelection() 849 if len(curSel): 850 curAts = curSel.findType(Atom) 851 if curAts != self.vf.allAtoms: 852 acats = curAts.inter(acats) 853 if not acats: #NB inter returns empty set! 854 msg = 'no specified acceptor atoms in current selection' 855 self.warningMsg(msg) 856 acats = AtomSet([]) 857 else: 858 msg = 'no current selection' 859 self.warningMsg(msg) 860 acats = AtomSet([]) 861 acceptorList = [] 862 for n in allAcceptors: 863 name = 'a' + n 864 v = self.ifd.entryByName[name]['wcfg']['variable'] 865 if v.get(): 866 acceptorList.append(n) 867 if not len(acceptorList): 868 self.warningMsg('no acceptor types selected') 869 if not (len(donorList) or len(acceptorList)): 870 return 871 self.Close_cb() 872 return self.doitWrapper(dats, acats, donorList, acceptorList, topCommand=0)
873 874
875 - def hideDSelector(self, event=None):
876 e = self.ifd.entryByName['keyDSelector'] 877 if self.hideDSel.get(): 878 e['widget'].grid_forget() 879 else: 880 e['widget'].grid(e['gridcfg']) 881 self.form.autoSize()
882 883
884 - def hideDTypes(self, event=None):
885 for n in allDonors: 886 e = self.ifd.entryByName[n] 887 if not self.showDTypeSel.get(): 888 e['wcfg']['variable'].set(1) 889 e['widget'].grid_forget() 890 else: 891 e['widget'].grid(e['gridcfg']) 892 self.form.autoSize()
893 894
895 - def hideASelector(self, event=None):
896 e = self.ifd.entryByName['keyASelector'] 897 if self.hideASel.get(): 898 e['widget'].grid_forget() 899 else: 900 e['widget'].grid(e['gridcfg']) 901 self.form.autoSize()
902 903
904 - def hideATypes(self, event=None):
905 for n in a_allAcceptors: 906 e = self.ifd.entryByName[n] 907 if not self.showATypeSel.get(): 908 e['wcfg']['variable'].set(1) 909 e['widget'].grid_forget() 910 else: 911 e['widget'].grid(e['gridcfg']) 912 self.form.autoSize()
913 914 915 916 ShowHBDonorsAcceptorsGuiDescr = {'widgetType':'Menu', 917 'menuBarName':'menuRoot', 918 'menuButtonName':'Hydrogen Bonds', 919 'menuEntryLabel':'Show Donors + Acceptors', 920 'menuCascadeName': 'Build'} 921 922 923 ShowHBDonorsAcceptorsGUI = CommandGUI() 924 ShowHBDonorsAcceptorsGUI.addMenuCommand('menuRoot','Hydrogen Bonds','Show Donors + Acceptors', cascadeName = 'Build') 925 926 927 928
929 -class ShowHydrogenBonds(MVCommand):
930 """This class allows user to visualize pre-existing HydrogenBonds between 931 atoms in viewer 932 \nPackage : Pmv 933 \nModule : hbondCommands 934 \nClass : ShowHydrogenBonds 935 \nCommand : showHBonds 936 \nSynopsis:\n 937 None <- showHBonds(nodes, **kw) 938 """ 939
940 - def __init__(self, func=None):
941 MVCommand.__init__(self, func) 942 self.flag = self.flag | self.objArgOnly
943 944
945 - def onAddCmdToViewer(self):
946 from DejaVu.IndexedPolylines import IndexedPolylines 947 #from DejaVu.Labels import Labels 948 miscGeom = self.vf.GUI.miscGeom 949 hbond_geoms = check_hbond_geoms(self.vf.GUI) 950 self.masterGeom = Geom('HbondsAsLinesGeoms',shape=(0,0), 951 pickable=0, protected=True) 952 self.masterGeom.isScalable = 0 953 self.vf.GUI.VIEWER.AddObject(self.masterGeom, parent=hbond_geoms) 954 self.lines = IndexedPolylines('showHbondLines', 955 materials = ((0,1,0),), lineWidth=4, 956 stippleLines=1, inheritMaterial=0, protected=True) 957 self.labels = GlfLabels(name='showHbondLabs', shape=(0,3), 958 materials = ((0,1,1),), inheritMaterial=0, 959 billboard=True, fontStyle='solid', 960 fontScales=(.3,.3,.3,)) 961 self.labels.font = 'arial1.glf' 962 self.thetaLabs = GlfLabels(name='hbondThetaLabs', shape=(0,3), 963 materials = ((1,1,0),), inheritMaterial=0, 964 billboard=True, fontStyle='solid', 965 fontScales=(.3,.3,.3,)) 966 self.thetaLabs.font = 'arial1.glf' 967 self.phiLabs = GlfLabels(name='hbondPhiLabs', shape=(0,3), 968 materials = ((1,.2,0),), inheritMaterial=0, 969 billboard=True, fontStyle='solid', 970 fontScales=(.3,.3,.3,)) 971 self.phiLabs.font = 'arial1.glf' 972 self.engLabs = GlfLabels(name='hbondELabs', shape=(0,3), 973 materials = ((1,1,1),), inheritMaterial=0, 974 billboard=True, fontStyle='solid', 975 fontScales=(.3,.3,.3,)) 976 self.engLabs.font = 'arial1.glf' 977 978 geoms = [self.lines, self.labels, self.thetaLabs, 979 self.phiLabs, self.engLabs] 980 for item in geoms: 981 self.vf.GUI.VIEWER.AddObject(item, parent=self.masterGeom) 982 983 self.vf.loadModule('labelCommands', 'Pmv', log=0) 984 self.showAll = Tkinter.IntVar() 985 self.showAll.set(1) 986 self.showDistLabels = Tkinter.IntVar() 987 self.showDistLabels.set(1) 988 self.dispTheta = Tkinter.IntVar() 989 self.dispTheta.set(0) 990 self.dispPhi = Tkinter.IntVar() 991 self.dispPhi.set(0) 992 self.dispEnergy = Tkinter.IntVar() 993 self.dispEnergy.set(0) 994 self.dverts = [] 995 self.dlabs = [] 996 self.angVerts = [] 997 self.phi_labs = [] 998 self.theta_labs = [] 999 self.e_labs = [] 1000 self.hasDist = 0 1001 self.hasAngles = 0 1002 self.hasEnergies = 0 1003 self.height = None 1004 self.width = None 1005 self.winfo_x = None 1006 self.winfo_y = None
1007 1008
1009 - def __call__(self, nodes, **kw):
1010 """None <- showHBonds(nodes, **kw) """ 1011 if type(nodes) is StringType: 1012 self.nodeLogString = "'"+nodes+"'" 1013 nodes =self.vf.expandNodes(nodes) 1014 if not len(nodes): return 'ERROR' 1015 ats = nodes.findType(Atom) 1016 apply(self.doitWrapper, (ats,), kw)
1017 1018
1019 - def reset(self):
1020 self.hasAngles = 0 1021 self.hasEnergies = 0 1022 self.hasDist = 0 1023 self.lines.Set(vertices=[], tagModified=False) 1024 self.labels.Set(vertices=[], tagModified=False) 1025 self.engLabs.Set(vertices=[], tagModified=False) 1026 self.dverts = [] 1027 self.dlabs = [] 1028 self.angVerts = [] 1029 self.phi_labs = [] 1030 self.theta_labs = [] 1031 self.e_labs = []
1032 1033
1034 - def doit(self, ats):
1035 #asLines: ShowHBonds 1036 hbats = AtomSet(ats.get(lambda x: hasattr(x, 'hbonds'))) 1037 self.reset() 1038 if not hbats: 1039 self.warningMsg('1:no hydrogen bonds found') 1040 return 'ERROR' 1041 hats = AtomSet(hbats.get(lambda x: x.element=='H')) 1042 atNames = [] 1043 if hats: 1044 for h in hats: 1045 atNames.append((h.full_name(), None)) 1046 else: 1047 hats = AtomSet([]) 1048 bnds = [] 1049 for at in hbats: 1050 bnds.extend(at.hbonds) 1051 bndD = {} 1052 for b in bnds: 1053 bndD[b] = 0 1054 hbnds2 = bndD.keys() 1055 hbnds2.sort() 1056 for b in hbnds2: 1057 atNames.append((b.donAt.full_name(), None)) 1058 hats.append(b.donAt) 1059 self.showAllHBonds(hats) 1060 if not hasattr(self, 'ifd'): 1061 ifd = self.ifd=InputFormDescr(title = 'Hydrogen Bonds:') 1062 ifd.append({'name': 'hbondLabel', 1063 'widgetType': Tkinter.Label, 1064 'wcfg':{'text': str(len(atNames)) + ' Atoms in hbonds:'}, 1065 'gridcfg':{'sticky': 'we', 'columnspan':2}}) 1066 ifd.append({'name': 'atsLC', 1067 'widgetType':ListChooser, 1068 'wcfg':{ 1069 'entries': atNames, 1070 'mode': 'single', 1071 'title': '', 1072 'command': CallBackFunction(self.showHBondLC, atNames), 1073 'lbwcfg':{'height':5, 1074 'selectforeground': 'red', 1075 'exportselection': 0, 1076 'width': 30}, 1077 }, 1078 'gridcfg':{'sticky':'we', 'weight':2,'row':2, 1079 'column':0, 'columnspan':2}}) 1080 ifd.append({'name':'showAllBut', 1081 'widgetType':Tkinter.Checkbutton, 1082 'wcfg': { 'text':'Show All ', 1083 'variable': self.showAll, 1084 'command': CallBackFunction(self.showAllHBonds, \ 1085 hats)}, 1086 'gridcfg':{'sticky':'we','weight':2}}) 1087 ifd.append({'name':'showDistBut', 1088 'widgetType':Tkinter.Checkbutton, 1089 'wcfg': { 'text':'Show Distances ', 1090 'variable': self.showDistLabels, 1091 'command': self.showDistances}, 1092 'gridcfg':{'sticky':'we', 'row':-1, 'column':1,'weight':2}}) 1093 ifd.append({'name':'showThetaBut', 1094 'widgetType':Tkinter.Checkbutton, 1095 'wcfg': { 'text':'Show theta\n(don-h->acc)', 1096 'variable': self.dispTheta, 1097 'command': CallBackFunction(self.showAngles, hats)}, 1098 'gridcfg':{'sticky':'we','weight':2}}) 1099 ifd.append({'name':'showPhiBut', 1100 'widgetType':Tkinter.Checkbutton, 1101 'wcfg': { 'text':'Show phi\n(h->acc-accN)', 1102 'variable': self.dispPhi, 1103 'command': CallBackFunction(self.showAngles, hats)}, 1104 'gridcfg':{'sticky':'we', 'row':-1, 'column':1,'weight':2}}) 1105 ifd.append({'name':'showEnBut', 1106 'widgetType':Tkinter.Checkbutton, 1107 'wcfg': { 'text':'Show Energy', 1108 'variable': self.dispEnergy, 1109 'command': CallBackFunction(self.showEnergies, hats)}, 1110 'gridcfg':{'sticky':'we','weight':2}}) 1111 ifd.append({'name':'selAllBut', 1112 'widgetType':Tkinter.Button, 1113 'wcfg': { 'text':'Select All ', 1114 'command': CallBackFunction(self.selAllHBonds, hats)}, 1115 'gridcfg':{'sticky':'we','weight':2}}) 1116 ifd.append({'name':'closeBut', 1117 'widgetType':Tkinter.Button, 1118 'wcfg': { 'text':'Dismiss', 1119 'command': self.dismiss_cb}, 1120 'gridcfg':{'sticky':'we', 'row':-1, 'column':1,'weight':2}}) 1121 self.form = self.vf.getUserInput(ifd, modal=0, blocking=0, 1122 width=350, height=350) 1123 self.form.root.protocol('WM_DELETE_WINDOW',self.dismiss_cb) 1124 self.toplevel = self.form.f.master.master 1125 self.toplevel.positionfrom(who='user') 1126 if self.winfo_x is not None and self.winfo_y is not None: 1127 geom = self.width +'x'+ self.height +'+' 1128 geom += self.winfo_x + '+' + self.winfo_y 1129 self.toplevel.geometry(newGeometry=geom) 1130 1131 else: 1132 self.ifd.entryByName['showAllBut']['widget'].config(command= \ 1133 CallBackFunction(self.showAllHBonds, hats)) 1134 self.ifd.entryByName['showThetaBut']['widget'].config(command= \ 1135 CallBackFunction(self.showAngles, hats)) 1136 self.ifd.entryByName['showPhiBut']['widget'].config(command= \ 1137 CallBackFunction(self.showAngles, hats)) 1138 self.ifd.entryByName['showEnBut']['widget'].config(command= \ 1139 CallBackFunction(self.showEnergies, hats)) 1140 self.ifd.entryByName['selAllBut']['widget'].config(command= \ 1141 CallBackFunction(self.selAllHBonds, hats)) 1142 if self.winfo_x is not None and self.winfo_y is not None: 1143 geom = self.width +'x'+ self.height +'+' 1144 geom += self.winfo_x + '+' + self.winfo_y 1145 self.toplevel.geometry(newGeometry=geom)
1146 1147
1148 - def showHBondLC(self, hats, event=None):
1149 #this caused infinite loop: 1150 if not hasattr(self, 'ifd'): 1151 self.doit(hats) 1152 lb = self.ifd.entryByName['atsLC']['widget'].lb 1153 if lb.curselection() == (): return 1154 self.showAll.set(0) 1155 atName = lb.get(lb.curselection()) 1156 ind = int(lb.curselection()[0]) 1157 ats = self.vf.Mols.NodesFromName(atName) 1158 at = ats[0] 1159 #to deal with two atoms with the exact same name: 1160 if len(ats)>1: 1161 for a in ats: 1162 if hasattr(a, 'hbonds'): 1163 at = a 1164 break 1165 b = at.hbonds[0] 1166 faces = ((0,1),) 1167 if b.hAt is not None: 1168 lineVerts = (getTransformedCoords(b.hAt).tolist(), getTransformedCoords(b.accAt).tolist()) 1169 #lineVerts = (b.hAt.coords, b.accAt.coords) 1170 else: 1171 lineVerts = (getTransformedCoords(b.donAt).tolist(), getTransformedCoords(b.accAt).tolist()) 1172 #lineVerts = (b.donAt.coords, b.accAt.coords) 1173 faces = ((0,1),) 1174 if self.hasAngles: 1175 verts = [self.angVerts[ind]] 1176 labs = [self.theta_labs[ind]] 1177 self.thetaLabs.Set(vertices=verts, labels=labs, tagModified=False) 1178 labs = [self.phi_labs[ind]] 1179 self.phiLabs.Set(vertices=verts, labels=labs, tagModified=False) 1180 if self.hasEnergies: 1181 labs = [self.e_labs[ind]] 1182 verts = [self.dverts[ind]] 1183 self.engLabs.Set(vertices=verts,labels=labs,\ 1184 visible=self.dispEnergy.get(), tagModified=False) 1185 labelVerts = [self.dverts[ind]] 1186 labelStrs = [self.dlabs[ind]] 1187 self.labels.Set(vertices=labelVerts, labels=labelStrs, 1188 tagModified=False) 1189 self.lines.Set(vertices=lineVerts, type=GL.GL_LINE_STRIP, 1190 faces=faces, freshape=1, tagModified=False) 1191 self.vf.GUI.VIEWER.Redraw()
1192 1193
1194 - def dismiss_cb(self, event=None, **kw):
1195 #showHBonds 1196 self.lines.Set(vertices=[], tagModified=False) 1197 self.labels.Set(vertices=[], tagModified=False) 1198 self.thetaLabs.Set(vertices=[], tagModified=False) 1199 self.phiLabs.Set(vertices=[], tagModified=False) 1200 self.engLabs.Set(vertices=[], tagModified=False) 1201 try: 1202 self.width = str(self.form.f.master.master.winfo_width()) 1203 self.height = str(self.form.f.master.master.winfo_height()) 1204 self.winfo_x = str(self.form.f.master.master.winfo_x()) 1205 self.winfo_y = str(self.form.f.master.master.winfo_y()) 1206 except: 1207 pass 1208 self.vf.GUI.VIEWER.Redraw() 1209 if hasattr(self, 'ifd'): 1210 delattr(self, 'ifd') 1211 if hasattr(self, 'form'): 1212 self.form.destroy() 1213 if hasattr(self, 'palette'): 1214 self.palette.hide()
1215 1216
1217 - def showDistances(self, event=None):
1218 self.labels.Set(visible=self.showDistLabels.get(), tagModified=False) 1219 self.vf.GUI.VIEWER.Redraw()
1220 1221
1222 - def showEnergies(self, hats):
1223 if not self.hasEnergies: 1224 self.buildEnergies(hats) 1225 self.hasEnergies = 1 1226 if not self.showAll.get(): 1227 self.showHBondLC(hats) 1228 else: 1229 self.engLabs.Set(labels = self.e_labs, vertices = self.dverts, 1230 visible=self.dispEnergy.get(), tagModified=False) 1231 self.vf.GUI.VIEWER.Redraw()
1232 1233
1234 - def buildEnergies(self, hats):
1235 #FIX THIS: for some reason, eList is disordered...??? 1236 eList = self.vf.getHBondEnergies(hats, topCommand=0) 1237 for hat in hats: 1238 self.e_labs.append(str(hat.hbonds[0].energy))
1239 1240
1241 - def showAngles(self, hats, event=None):
1242 if not self.hasAngles: 1243 self.buildAngles(hats) 1244 self.hasAngles = 1 1245 if not self.showAll.get(): 1246 self.showHBondLC(hats) 1247 else: 1248 self.thetaLabs.Set(vertices=self.angVerts, labels=self.theta_labs, 1249 tagModified=False) 1250 self.phiLabs.Set(vertices = self.angVerts, labels = self.phi_labs, 1251 tagModified=False) 1252 self.thetaLabs.Set(visible=self.dispTheta.get(), tagModified=False) 1253 self.phiLabs.Set(visible=self.dispPhi.get(), tagModified=False) 1254 self.vf.GUI.VIEWER.Redraw()
1255 1256
1257 - def buildAngles(self, hats):
1258 #NB: hats are either donAts or hAts 1259 # theta is don-h->acc, phi is h->acc-accN 1260 # calc 1 angle for each closeAt 1261 # hat is h, 1262 if self.hasAngles: return 1263 tlabs = [] 1264 plabs = [] 1265 verts = [] 1266 for hat in hats: 1267 b = hat.hbonds[0] 1268 accAt = b.accAt 1269 donAt = b.donAt 1270 if b.hAt is not None: 1271 ang = getAngle(donAt, hat, accAt) 1272 ang = round(ang, 3) 1273 b.theta = ang 1274 b0 = accAt.bonds[0] 1275 accN = b0.atom1 1276 if id(accN)==id(accAt): accN = b0.atom2 1277 #accN = b.accAt.bonds[0].neighborAtom(b.accAt) 1278 ang = getAngle(hat, accAt, accN) 1279 ang = round(ang, 3) 1280 b.phi = ang 1281 p1=Numeric.array(getTransformedCoords(hat)) 1282 p2=Numeric.array(getTransformedCoords(accAt)) 1283 #p1=Numeric.array(hat.coords) 1284 #p2=Numeric.array(accAt.coords) 1285 newVert = tuple((p1+p2)/2.0 + .2) 1286 tlabs.append(str(b.theta)) 1287 verts.append(newVert) 1288 plabs.append(str(b.phi)) 1289 self.thetaLabs.Set(vertices=verts, labels=tlabs, tagModified=False) 1290 self.angVerts = verts 1291 self.theta_labs = tlabs 1292 self.phi_labs = plabs 1293 self.phiLabs.Set(vertices=verts, labels=plabs, tagModified=False)
1294 1295
1296 - def setupDisplay(self):
1297 #draw lines between hAts OR donAts and accAts 1298 self.labels.Set(vertices=self.dverts, labels=self.dlabs, 1299 tagModified=False) 1300 self.lines.Set(vertices=self.lineVerts, type=GL.GL_LINE_STRIP, 1301 faces=self.faces, freshape=1, tagModified=False) 1302 if self.hasAngles: 1303 self.thetaLabs.Set(vertices=self.angVerts, labels=self.theta_labs, 1304 tagModified=False) 1305 self.phiLabs.Set(vertices=self.angVerts, labels=self.theta_labs, 1306 tagModified=False) 1307 1308 if self.hasEnergies: 1309 self.engLabs.Set(vertices=self.dverts, labels=self.e_labs, 1310 tagModified=False) 1311 1312 self.vf.GUI.VIEWER.Redraw()
1313 1314
1315 - def showAllHBonds(self, hats, event=None):
1316 if not self.showAll.get() and hasattr(self, 'ifd'): 1317 self.showHBondLC(hats) 1318 elif not self.hasDist: 1319 lineVerts = [] 1320 faces = [] 1321 labelVerts = [] 1322 labelStrs = [] 1323 dlabelStrs = [] 1324 atCtr = 0 1325 for at in hats: 1326 for b in at.hbonds: 1327 dCoords = getTransformedCoords(b.donAt) 1328 aCoords = getTransformedCoords(b.accAt) 1329 if b.hAt is not None: 1330 hCoords = getTransformedCoords(b.hAt) 1331 lineVerts.append(hCoords) 1332 else: 1333 lineVerts.append(dCoords) 1334 lineVerts.append(aCoords) 1335 #lineVerts.append(b.accAt.coords) 1336 faces.append((atCtr, atCtr+1)) 1337 #c1 = Numeric.array(at.coords, 'f') 1338 c1 = getTransformedCoords(at) 1339 c3 = aCoords 1340 #c3 = Numeric.array(b.accAt.coords, 'f') 1341 labelVerts.append(tuple((c1 + c3)/2.0)) 1342 if b.hAt is not None: 1343 if b.hlen is not None: 1344 labelStrs.append(str(b.hlen)) 1345 else: 1346 #d = dist(hCoords,aCoords) 1347 #d=self.vf.measureDistance(b.hAt,b.accAt, topCommand=0) 1348 b.hlen=round(dist(hCoords, aCoords),3) 1349 labelStrs.append(str(b.hlen)) 1350 if b.dlen is not None: 1351 dlabelStrs.append(str(b.dlen)) 1352 else: 1353 #d = dist(dCoords, aCoords) 1354 ##d = dist(b.donAt.coords, b.accAt.coords) 1355 #d=self.vf.measureDistance(b.donAt,b.accAt, topCommand=0) 1356 #b.dlen=round(d,3) 1357 b.dlen=round(dist(dCoords, aCoords) ,3) 1358 dlabelStrs.append(str(b.dlen)) 1359 atCtr = atCtr + 2 1360 self.lineVerts = lineVerts 1361 self.faces = faces 1362 self.dverts = labelVerts 1363 if len(labelStrs): 1364 self.dlabs = labelStrs 1365 else: 1366 self.dlabs = dlabelStrs 1367 self.hasDist = 1 1368 self.setupDisplay() 1369 else: 1370 self.setupDisplay()
1371 1372
1373 - def selAllHBonds(self, hats, event=None):
1374 self.vf.select(hats)
1375 1376
1377 - def guiCallback(self):
1378 #showHbonds 1379 if not len(self.vf.Mols): 1380 self.warningMsg('no molecules in viewer') 1381 return 1382 sel = self.vf.getSelection() 1383 #put a selector here 1384 if len(sel): 1385 ats = sel.findType(Atom) 1386 apply(self.doitWrapper, (ats,), {})
1387 1388 1389 ShowHydrogenBondsGuiDescr = {'widgetType':'Menu', 1390 'menuBarName':'menuRoot', 1391 'menuButtonName':'Hydrogen Bonds', 1392 'menuEntryLabel':'As Lines', 1393 'menuCascadeName': 'Display'} 1394 1395 1396 ShowHydrogenBondsGUI = CommandGUI() 1397 ShowHydrogenBondsGUI.addMenuCommand('menuRoot', 'Hydrogen Bonds', 1398 'As Lines', cascadeName='Display') 1399 1400 1401
1402 -class BuildHydrogenBondsGUICommand(MVCommand):
1403 """This class provides Graphical User Interface to BuildHydrogenBonds which is invoked by it. 1404 \nPackage : Pmv 1405 \nModule : hbondCommands 1406 \nClass : BuildHydrogenBondsGUICommand 1407 \nCommand : buildHydrogenBondsGC 1408 \nSynopsis:\n 1409 None<---buildHydrogenBondsGC(nodes1, nodes2, paramDict, reset=1) 1410 """ 1411 1412
1413 - def onAddCmdToViewer(self):
1414 self.showSel = Tkinter.IntVar() 1415 self.resetVar = Tkinter.IntVar() 1416 self.resetVar.set(1) 1417 self.showDef = Tkinter.IntVar() 1418 self.distOnly = Tkinter.IntVar() 1419 self.hideDTypeSel = Tkinter.IntVar() 1420 self.hideATypeSel = Tkinter.IntVar() 1421 self.showTypes = Tkinter.IntVar() 1422 varNames = ['hideDSel', 'N3', 'O3','S3','Nam', 'Ng', 'Npl',\ 1423 'hideASel', 'aS3', 'aO3', 'aO2', 'aO', 'aNpl', 1424 'aNam'] 1425 for n in varNames: 1426 exec('self.'+n+'=Tkinter.IntVar()') 1427 exec('self.'+n+'.set(1)')
1428 1429 1430
1431 - def doit(self, nodes1, nodes2, paramDict, reset=1):
1432 #buildHbondGC 1433 self.hasAngles = 0 1434 atDict = self.vf.buildHBonds(nodes1, nodes2, paramDict, reset) 1435 if not len(atDict.keys()): 1436 self.warningMsg('3:no hydrogen bonds found') 1437 return 'ERROR' 1438 else: 1439 msg = str(len(atDict.keys()))+' hydrogen bonds formed' 1440 self.warningMsg(msg)
1441 1442 #ats = AtomSet(atDict.keys()) 1443 #ats.parent.sort() 1444 #self.vf.showHBonds(ats) 1445 1446
1447 - def guiCallback(self):
1448 if not len(self.vf.Mols): 1449 self.warningMsg('no molecules in viewer') 1450 return 1451 if not hasattr(self, 'ifd'): 1452 self.buildForm() 1453 else: 1454 self.form.deiconify()
1455 1456
1457 - def buildForm(self):
1458 ifd = self.ifd = InputFormDescr(title = "Select nodes + change parameters(optional):") 1459 ifd.append({'name':'keyLab', 1460 'widgetType':Tkinter.Label, 1461 'text':'For Hydrogen Bond detection:', 1462 'gridcfg':{'sticky':'w'}}) 1463 ifd.append({'name':'selRB0', 1464 'widgetType':Tkinter.Radiobutton, 1465 'wcfg':{'text':'Use all atoms', 1466 'variable': self.showSel, 1467 'value':0, 1468 'command':self.hideSelector 1469 }, 1470 'gridcfg':{'sticky':'w'}}) 1471 ifd.append({'name':'selRB1', 1472 'widgetType':Tkinter.Radiobutton, 1473 'wcfg':{'text':'Specify two sets:', 1474 'variable': self.showSel, 1475 'value':1, 1476 'command':self.hideSelector 1477 }, 1478 'gridcfg':{'sticky':'w', 'row':-1, 'column':1}}) 1479 ifd.append({'name': 'group1', 1480 'wtype':StringSelectorGUI, 1481 'widgetType':StringSelectorGUI, 1482 'wcfg':{ 'molSet': self.vf.Mols, 1483 'vf': self.vf, 1484 'all':1, 1485 'crColor':(0.,1.,.2), 1486 }, 1487 'gridcfg':{'sticky':'we', 'columnspan':2 }}) 1488 ifd.append({'name': 'group2', 1489 'wtype':StringSelectorGUI, 1490 'widgetType':StringSelectorGUI, 1491 'wcfg':{ 'molSet': self.vf.Mols, 1492 'vf': self.vf, 1493 'all':1, 1494 'crColor':(1.,2.,0.), 1495 }, 1496 'gridcfg':{'sticky':'we', 'columnspan':2}}) 1497 1498 ifd.append({'name':'typeRB0', 1499 'widgetType':Tkinter.Radiobutton, 1500 'wcfg':{'text':'Use all donor-acceptorTypes', 1501 'variable': self.showTypes, 1502 'value':0, 1503 'command':self.hideTypeCBs, 1504 }, 1505 'gridcfg':{'sticky':'w'}}) 1506 ifd.append({'name':'selRB1', 1507 'widgetType':Tkinter.Radiobutton, 1508 'wcfg':{'text':'Limit types:', 1509 'variable': self.showTypes, 1510 'value':1, 1511 'command':self.hideTypeCBs 1512 }, 1513 'gridcfg':{'sticky':'w', 'row':-1, 'column':1}}) 1514 ifd.append({'name':'limitDTypes', 1515 'widgetType':Tkinter.Checkbutton, 1516 'wcfg':{'text':'Limit donor types ', 1517 'variable': self.hideDTypeSel, 1518 'command':self.hideDTypes 1519 }, 1520 'gridcfg':{'sticky':'w', 'columnspan':2}}) 1521 ifd.append({'name':'N3+', 1522 'widgetType':Tkinter.Checkbutton, 1523 'wcfg':{'text':'N3+', 1524 'variable': self.N3, }, 1525 'gridcfg':{'sticky':'w'}}) 1526 ifd.append({'name':'O3', 1527 'widgetType':Tkinter.Checkbutton, 1528 'wcfg':{'text':'O3', 1529 'variable': self.O3, }, 1530 'gridcfg':{'sticky':'w','row':-1, 'column':1}}) 1531 ifd.append({'name':'S3', 1532 'widgetType':Tkinter.Checkbutton, 1533 'wcfg':{'text':'S3', 1534 'variable': self.S3, }, 1535 'gridcfg':{'sticky':'w','row':-1, 'column':2}}) 1536 ifd.append({'name':'Nam', 1537 'widgetType':Tkinter.Checkbutton, 1538 'wcfg':{'text':'Nam', 1539 'variable': self.Nam, }, 1540 'gridcfg':{'sticky':'w'}}) 1541 ifd.append({'name':'Ng+', 1542 'widgetType':Tkinter.Checkbutton, 1543 'wcfg':{'text':'Ng+', 1544 'variable': self.Ng, }, 1545 'gridcfg':{'sticky':'w','row':-1, 'column':1}}) 1546 ifd.append({'name':'Npl', 1547 'widgetType':Tkinter.Checkbutton, 1548 'wcfg':{'text':'Npl', 1549 'variable': self.Npl, }, 1550 'gridcfg':{'sticky':'w','row':-1, 'column':2}}) 1551 1552 #now the acceptors 1553 ifd.append({'name':'limitATypes', 1554 'widgetType':Tkinter.Checkbutton, 1555 'wcfg':{'text':'Limit acceptor types ', 1556 'variable': self.hideATypeSel, 1557 'command':self.hideATypes 1558 }, 1559 'gridcfg':{'sticky':'w', 'columnspan':2}}) 1560 ifd.append({'name':'aO3', 1561 'widgetType':Tkinter.Checkbutton, 1562 'wcfg':{'text':'O3', 1563 'variable': self.aO3, }, 1564 'gridcfg':{'sticky':'w'}}) 1565 ifd.append({'name':'aS3', 1566 'widgetType':Tkinter.Checkbutton, 1567 'wcfg':{'text':'S3', 1568 'variable': self.aS3, }, 1569 'gridcfg':{'sticky':'w','row':-1, 'column':1}}) 1570 ifd.append({'name':'aO2', 1571 'widgetType':Tkinter.Checkbutton, 1572 'wcfg':{'text':'O2', 1573 'variable': self.aO2, }, 1574 'gridcfg':{'sticky':'w','row':-1, 'column':2}}) 1575 ifd.append({'name':'aO-', 1576 'widgetType':Tkinter.Checkbutton, 1577 'wcfg':{'text':'O-', 1578 'variable': self.aO,}, 1579 'gridcfg':{'sticky':'w'}}) 1580 ifd.append({'name':'aNpl', 1581 'widgetType':Tkinter.Checkbutton, 1582 'wcfg':{'text':'Npl', 1583 'variable': self.aNpl, }, 1584 'gridcfg':{'sticky':'w', 'row':-1, 'column':1}}) 1585 ifd.append({'name':'aNam', 1586 'widgetType':Tkinter.Checkbutton, 1587 'wcfg':{'text':'Nam', 1588 'variable': self.aNam, }, 1589 'gridcfg':{'sticky':'w','row':-1, 'column':2}}) 1590 1591 ifd.append({'name':'distOnly', 1592 'widgetType':Tkinter.Checkbutton, 1593 'wcfg':{'text':'Use distance as only criteria', 1594 'variable': self.distOnly, 1595 }, 1596 'gridcfg':{'sticky':'w', 'columnspan':2}}) 1597 1598 ifd.append({'name':'defRB0', 1599 'widgetType':Tkinter.Checkbutton, 1600 'wcfg':{'text':'Adjust default hydrogen bond parameters', 1601 'variable': self.showDef, 1602 'command':self.hideDefaults 1603 }, 1604 'gridcfg':{'sticky':'w', 'columnspan':2}}) 1605 ifd.append({'name':'distCutoff', 1606 'widgetType':ExtendedSliderWidget, 1607 'wcfg':{'label': 'H-Acc Distance Cutoff', 1608 'minval':1.5,'maxval':3.0 , 1609 'init':2.25, 1610 'labelsCursorFormat':'%1.2f', 1611 'sliderType':'float', 1612 'entrywcfg':{'width':4}, 1613 'entrypackcfg':{'side':'right'}}, 1614 'gridcfg':{'columnspan':2,'sticky':'we'}}) 1615 ifd.append({'name':'distCutoff2', 1616 'widgetType':ExtendedSliderWidget, 1617 'wcfg':{'label': 'Donor-Acc Distance Cutoff', 1618 'minval':1.5,'maxval':5.0 , 1619 'init':3.00, 1620 'labelsCursorFormat':'%1.2f', 1621 'sliderType':'float', 1622 'entrywcfg':{'width':4}, 1623 'entrypackcfg':{'side':'right'}}, 1624 'gridcfg':{'columnspan':2,'sticky':'we'}}) 1625 #min+max theta values for sp2 and for sp3 donors: 1626 ifd.append({ 'name':'d2lab', 1627 'widgetType':Tkinter.Label, 1628 'wcfg':{ 'text': 'sp2 donor-hydrogen-acceptor angle limits:', 1629 'font':('Helvetica',12,'bold')}, 1630 'gridcfg':{'sticky':'w', 'columnspan':2}}) 1631 ifd.append({'name':'d2min', 1632 'wtype':ThumbWheel, 1633 'widgetType':ThumbWheel, 1634 'wcfg':{ 'labCfg':{'text':'min', 1635 'font':('Helvetica',12,'bold')}, 1636 'showLabel':2, 'width':100, 1637 'min':100, 'max':180, 'type':float, 'precision':3, 1638 'value':120, 1639 'showLabel':1, 1640 'continuous':1, 'oneTurn':2, 'wheelPad':2, 'height':20}, 1641 'gridcfg':{'sticky':'we'}}) 1642 #modified this 10/1 because of 1crn:ILE35NH to THR1:O hbond 1643 ifd.append({'name':'d2max', 1644 'wtype':ThumbWheel, 1645 'widgetType':ThumbWheel, 1646 'wcfg':{ 'labCfg':{'text':'max', 1647 'font':('Helvetica',12,'bold')}, 1648 'showLabel':2, 'width':100, 1649 'min':100, 'max':190, 'type':float, 'precision':3, 1650 'value':180, 1651 'showLabel':1, 1652 'continuous':1, 'oneTurn':2, 'wheelPad':2, 'height':20}, 1653 'gridcfg':{'sticky':'we', 'row':-1, 'column':1}}) 1654 ifd.append({ 'name':'d3lab', 1655 'widgetType':Tkinter.Label, 1656 'wcfg':{ 'text': 'sp3 donor-hydrogen-acceptor angle limits:', 1657 'font':('Helvetica',12,'bold')}, 1658 'gridcfg':{'sticky':'w', 'columnspan':2}}) 1659 ifd.append({'name':'d3min', 1660 'wtype':ThumbWheel, 1661 'widgetType':ThumbWheel, 1662 'wcfg':{ 'labCfg':{'text':'min', 1663 'font':('Helvetica',12,'bold')}, 1664 'showLabel':2, 'width':100, 1665 'min':100, 'max':180, 'type':float, 'precision':3, 1666 'value':120, 1667 'showLabel':1, 1668 'continuous':1, 'oneTurn':2, 'wheelPad':2, 'height':20}, 1669 'gridcfg':{'sticky':'we'}}) 1670 ifd.append({'name':'d3max', 1671 'wtype':ThumbWheel, 1672 'widgetType':ThumbWheel, 1673 'wcfg':{ 'labCfg':{'text':'max', 1674 'font':('Helvetica',12,'bold')}, 1675 'showLabel':2, 'width':100, 1676 'min':100, 'max':180, 'type':float, 'precision':3, 1677 'value':180, 1678 'showLabel':1, 1679 'continuous':1, 'oneTurn':2, 'wheelPad':2, 'height':20}, 1680 'gridcfg':{'sticky':'we', 'row':-1, 'column':1}}) 1681 #min+max phi values for sp2 and for sp3 donors: 1682 ifd.append({ 'name':'a2lab', 1683 'widgetType':Tkinter.Label, 1684 'wcfg':{ 'text': 'sp2 donor-acceptor-acceptorN angle limits:', 1685 'font':('Helvetica',12,'bold')}, 1686 'gridcfg':{'sticky':'w', 'columnspan':2}}) 1687 ifd.append({'name':'a2min', 1688 'wtype':ThumbWheel, 1689 'widgetType':ThumbWheel, 1690 'wcfg':{ 'labCfg':{'text':'min', 1691 'font':('Helvetica',12,'bold')}, 1692 'showLabel':2, 'width':100, 1693 'min':90, 'max':180, 'type':float, 'precision':