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