2 This module defines a widget used for visualization of trajectories.
6 __all__=(
'TrajWidget',
'SetTimeUnit',
'AddTrajectory',
'RemoveTrajectory',
'SetSpeed',
'ReleaseGfxEntity',
'FixGfxEntity')
28 import PyQt4
as _PyQt4
41 def __init__(self, trajlist=None, golist=None, parent=None,ref_index=0):
42 _QWidget.__init__(self, parent, _Qt.Tool)
43 self.setFocusPolicy(_Qt.ClickFocus)
51 for i,go
in enumerate(self.
golist_):
53 vb=_PyQt4.QtGui.QVBoxLayout()
54 hb=_PyQt4.QtGui.QHBoxLayout()
55 hb1=_PyQt4.QtGui.QHBoxLayout()
56 hb2=_PyQt4.QtGui.QHBoxLayout()
57 hb3=_PyQt4.QtGui.QHBoxLayout()
58 hb4=_PyQt4.QtGui.QHBoxLayout()
60 self.
_slider=_PyQt4.QtGui.QSlider(self)
61 self._slider.setOrientation(_Qt.Horizontal)
63 self._speed_slider.setOrientation(_Qt.Horizontal)
65 self._speedLabel.setText(
'Speed:')
66 self._speedLabel.setAlignment(_Qt.AlignLeft)
67 self.
_play=_PyQt4.QtGui.QToolButton(self)
68 self.
_repeat=_PyQt4.QtGui.QCheckBox(self)
72 self._repeat.setText(
'Repeat')
73 self._slider.setTracking(
True)
74 self._play.setText(
'Play')
75 self._play.setCheckable(
True)
76 self._frame.setText(
'Frame: ')
77 self._frameNo.setNum(0)
78 self._frameNo.setAlignment(_Qt.AlignRight)
79 self._frameEnd.setAlignment(_Qt.AlignLeft)
84 self._timeLabel.setText(
'Time: ')
85 self._timeNo.setNum(0)
86 self._timeNo.setAlignment(_Qt.AlignRight)
87 self._timeEnd.setAlignment(_Qt.AlignLeft)
88 self._timeUnit.setAlignment(_Qt.AlignLeft)
89 self._speed_slider.setTracking(
True)
100 self.
_align=_QPushButton(
"Align")
102 self._align_label.setText(
'Selection:')
104 for go
in self.
golist_:self._ref_entity_selection.addItem(go.name)
106 self._ref_entity_selection_label.setText(
'Ref. Entity:')
107 hb.addWidget(self.
_play)
117 hb2.addWidget(self.
_frame)
128 hb4.addWidget(self.
_align)
137 _QObject.connect(self.
_play, _SIGNAL(
'toggled(bool)'),
139 _QObject.connect(self.
_slider, _SIGNAL(
'valueChanged(int)'),
150 self._slider.setMinimum(0)
169 raise RuntimeError(
"expected one of s,ms,us,ns,ps or fs for unit")
175 self._timeUnit.setText(
'['+u+
']')
177 def _SetSpeedSliderPos(self,pos):
178 self._speed_slider.setSliderPosition(pos)
181 def _SpeedSliderValChanged(self,speed_pos):
182 self.
time=_math.exp(-0.15*speed_pos)
183 if self._play.isChecked():
187 def _SetTime(self,t):
189 self._speed_slider.setSliderPosition(-1./0.15*_math.log(t))
190 if self._play.isChecked():
195 def _SliderValueChanged(self, pos):
198 if go.name
in self.
fix_dict:
continue
202 def _GetCurrentFrame(self):
203 return self._slider.sliderPosition()
205 def _SetCurrentFrame(self, pos):
206 if self._slider.maximum()<pos:
207 if self._repeat.isChecked():
210 pos=self._slider.maximum()
211 self._slider.setSliderPosition(pos)
212 self._frameNo.setNum(pos)
215 current_frame=property(_GetCurrentFrame, _SetCurrentFrame)
217 def _GetReferenceTraj(self):
219 traj_=property(_GetReferenceTraj)
226 if go.name
in self.
fix_dict:
continue
230 def _TogglePlay(self, playing):
236 def _LeftClicked(self):
240 def _RightClicked(self):
244 def _Left2Clicked(self):
248 def _Right2Clicked(self):
252 def _LeftEndClicked(self):
256 def _RightEndClicked(self):
260 def _AlignClicked(self):
262 ref_v=ref_eh.Select(str(self._align_selection.text()))
263 if ref_v.GetAtomCount()<=3:
264 print 'not enough atoms for alignment'
267 t=_ost.mol.alg.SuperposeFrames(t,eh.Select(str(self._align_selection.text())),ref_v)
270 def _SetBlur(self, blur):
275 return self.gfx_entity.GetBlur()
277 blur=property(_GetBlur, _SetBlur)
280 if type(ref_index)==type(
''):
289 self._ref_entity_selection.setCurrentIndex(self.
ref_index_)
291 def _EntitySelected(self,index):
292 ref_index=self.
index_dict[str(self._ref_entity_selection.currentText())]
297 if event.modifiers()==_Qt.ControlModifier:
300 if key==_Qt.Key_Left:
302 elif key==_Qt.Key_Right:
305 if key==_Qt.Key_Left:
307 elif key==_Qt.Key_Right:
309 elif key==_Qt.Key_Space:
310 self._play.setChecked(
not self._play.isChecked())
312 _QWidget.keyPressEvent(self, event)
315 if event.key()==_Qt.Key_Control:
318 _QWidget.keyPressEvent(self, event)
322 if type(index)==type(
''):
328 self.
trajlist_[i].CopyFrame(frame_number)
329 self.
golist_[i].UpdatePositions()
332 if type(index)==type(
''):self.fix_dict.pop(index)
333 else:self.fix_dict.pop(self.
golist_[index].name)
336 self.trajlist_.append(traj)
337 self.golist_.append(go)
338 self.ehlist_.append(go.GetView().handle)
342 if type(index)==type(
''):
344 self.trajlist_.pop(index)
345 self.golist_.pop(index)
346 self.ehlist_.pop(index)
350 if not (val<=1.
and val >=0.):
351 print 'Speed should be set between 0 and 1'