1
2
3
4
5
6
7
8
9
10
11
12
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
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
67
68
69
70
71 sp2Donors = ['Nam', 'Ng+', 'Npl']
72 sp3Donors = ['N3+', 'O3','S3']
73 allDonors = []
74 allDonors.extend(sp2Donors)
75 allDonors.extend(sp3Donors)
76
77
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
92
93
115
116
120
121
129
130
131
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
148
150 if not self.vf.commands.has_key('typeAtoms'):
151 self.vf.loadCommand('editCommands', 'typeAtoms', 'Pmv',
152 topCommand=0)
153
154
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
172
173
174 probAts = AtomSet(ats.get(lambda x, blen=blen: len(x.bonds)==blen))
175
176
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
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
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
223
225 if not self.vf.commands.has_key('typeAtoms'):
226 self.vf.loadCommand('editCommands', 'typeAtoms', 'Pmv',
227 topCommand=0)
228
229
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
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
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
252 restAts = accAts.get(lambda x, ntypes=ntypes: x.babel_type not in ntypes)
253 if not restAts: restAts = AtomSet([])
254
255 if npls:
256
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
264
265 if s<4:
266 restAts.append(at)
267 if nams:
268
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
276 if s<3:
277 restAts.append(at)
278 return restAts
279
280
281
282 - def doit(self, ats, acceptorList):
283
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
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
317
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
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
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
350 if b.dlen is None:
351 b.dlen = dist(getTransformedCoords(b.donAt),
352 getTransformedCoords(b.accAt))
353
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
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
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
408 energyList = []
409 hbonds = hats.hbonds
410
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
419 return energyList
420
421
422
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
435 self.vf.loadModule('editCommands', 'Pmv', log=0)
436 self.vf.loadCommand('interactiveCommands','setICOM', 'Pmv', log=0)
437
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
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
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
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
498
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
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
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
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
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
558
559
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
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
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
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
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
796
797
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
808
809
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
840 anodesToCheck = self.ifd.entryByName['keyASelector']['widget'].get()
841 if not len(anodesToCheck):
842 self.warningMsg('no acceptor atoms specified')
843 acats = AtomSet([])
844
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:
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
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
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
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
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
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
943
944
946 from DejaVu.IndexedPolylines import IndexedPolylines
947
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
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
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
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
1149
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
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
1170 else:
1171 lineVerts = (getTransformedCoords(b.donAt).tolist(), getTransformedCoords(b.accAt).tolist())
1172
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
1195
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
1218 self.labels.Set(visible=self.showDistLabels.get(), tagModified=False)
1219 self.vf.GUI.VIEWER.Redraw()
1220
1221
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
1235
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
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
1258
1259
1260
1261
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
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
1284
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
1297
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
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
1336 faces.append((atCtr, atCtr+1))
1337
1338 c1 = getTransformedCoords(at)
1339 c3 = aCoords
1340
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
1347
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
1354
1355
1356
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
1375
1376
1378
1379 if not len(self.vf.Mols):
1380 self.warningMsg('no molecules in viewer')
1381 return
1382 sel = self.vf.getSelection()
1383
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
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
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
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
1443
1444
1445
1446
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