2 This module defines a widget used for visualization of trajectories.
6 __all__=(
'TrajWidget',
'SetTimeUnit',
'AddTrajectory',
'RemoveTrajectory',
'SetSpeed',
'ReleaseGfxEntity',
'FixGfxEntity')
27 import PyQt5
as _PyQt5
37 def __init__(self, trajlist=None, golist=None, parent=None,ref_index=0):
38 _QWidget.__init__(self, parent, _Qt.Tool)
39 self.setFocusPolicy(_Qt.ClickFocus)
47 for i,go
in enumerate(self.
golist_):
49 vb=_PyQt5.QtWidgets.QVBoxLayout()
50 hb=_PyQt5.QtWidgets.QHBoxLayout()
51 hb1=_PyQt5.QtWidgets.QHBoxLayout()
52 hb2=_PyQt5.QtWidgets.QHBoxLayout()
53 hb3=_PyQt5.QtWidgets.QHBoxLayout()
54 hb4=_PyQt5.QtWidgets.QHBoxLayout()
56 self.
_slider=_PyQt5.QtWidgets.QSlider(self)
57 self._slider.setOrientation(_Qt.Horizontal)
59 self._speed_slider.setOrientation(_Qt.Horizontal)
61 self._speedLabel.setText(
'Speed:')
62 self._speedLabel.setAlignment(_Qt.AlignLeft)
63 self.
_play=_PyQt5.QtWidgets.QToolButton(self)
64 self.
_repeat=_PyQt5.QtWidgets.QCheckBox(self)
68 self._repeat.setText(
'Repeat')
69 self._slider.setTracking(
True)
70 self._play.setText(
'Play')
71 self._play.setCheckable(
True)
72 self._frame.setText(
'Frame: ')
73 self._frameNo.setNum(0)
74 self._frameNo.setAlignment(_Qt.AlignRight)
75 self._frameEnd.setAlignment(_Qt.AlignLeft)
80 self._timeLabel.setText(
'Time: ')
81 self._timeNo.setNum(0)
82 self._timeNo.setAlignment(_Qt.AlignRight)
83 self._timeEnd.setAlignment(_Qt.AlignLeft)
84 self._timeUnit.setAlignment(_Qt.AlignLeft)
85 self._speed_slider.setTracking(
True)
96 self.
_align=_QPushButton(
"Align")
98 self._align_label.setText(
'Selection:')
100 for go
in self.
golist_:self._ref_entity_selection.addItem(go.name)
102 self._ref_entity_selection_label.setText(
'Ref. Entity:')
103 hb.addWidget(self.
_play)
113 hb2.addWidget(self.
_frame)
124 hb4.addWidget(self.
_align)
143 self._ref_entity_selection.currentIndexChanged.connect(self.
_EntitySelected)
144 self._slider.setMinimum(0)
163 raise RuntimeError(
"expected one of s,ms,us,ns,ps or fs for unit")
169 self._timeUnit.setText(
'['+u+
']')
171 def _SetSpeedSliderPos(self,pos):
172 self._speed_slider.setSliderPosition(pos)
175 def _SpeedSliderValChanged(self,speed_pos):
176 self.
time=_math.exp(-0.15*speed_pos)
177 if self._play.isChecked():
181 def _SetTime(self,t):
183 self._speed_slider.setSliderPosition(-1./0.15*_math.log(t))
184 if self._play.isChecked():
189 def _SliderValueChanged(self, pos):
192 if go.name
in self.
fix_dict:
continue
196 def _GetCurrentFrame(self):
197 return self._slider.sliderPosition()
199 def _SetCurrentFrame(self, pos):
200 if self._slider.maximum()<pos:
201 if self._repeat.isChecked():
204 pos=self._slider.maximum()
205 self._slider.setSliderPosition(pos)
206 self._frameNo.setNum(pos)
209 current_frame=property(_GetCurrentFrame, _SetCurrentFrame)
211 def _GetReferenceTraj(self):
213 traj_=property(_GetReferenceTraj)
220 if go.name
in self.
fix_dict:
continue
224 def _TogglePlay(self, playing):
230 def _LeftClicked(self):
234 def _RightClicked(self):
238 def _Left2Clicked(self):
242 def _Right2Clicked(self):
246 def _LeftEndClicked(self):
250 def _RightEndClicked(self):
254 def _AlignClicked(self):
256 ref_v=ref_eh.Select(str(self._align_selection.text()))
257 if ref_v.GetAtomCount()<=3:
258 print 'not enough atoms for alignment'
261 t=_ost.mol.alg.SuperposeFrames(t,eh.Select(str(self._align_selection.text())),ref_v)
264 def _SetBlur(self, blur):
269 return self.gfx_entity.GetBlur()
271 blur=property(_GetBlur, _SetBlur)
274 if type(ref_index)==type(
''):
283 self._ref_entity_selection.setCurrentIndex(self.
ref_index_)
285 def _EntitySelected(self,index):
286 ref_index=self.
index_dict[str(self._ref_entity_selection.currentText())]
291 if event.modifiers()==_Qt.ControlModifier:
294 if key==_Qt.Key_Left:
296 elif key==_Qt.Key_Right:
299 if key==_Qt.Key_Left:
301 elif key==_Qt.Key_Right:
303 elif key==_Qt.Key_Space:
304 self._play.setChecked(
not self._play.isChecked())
306 _QWidget.keyPressEvent(self, event)
309 if event.key()==_Qt.Key_Control:
312 _QWidget.keyPressEvent(self, event)
316 if type(index)==type(
''):
322 self.
trajlist_[i].CopyFrame(frame_number)
323 self.
golist_[i].UpdatePositions()
326 if type(index)==type(
''):self.fix_dict.pop(index)
327 else:self.fix_dict.pop(self.
golist_[index].name)
330 self.trajlist_.append(traj)
331 self.golist_.append(go)
332 self.ehlist_.append(go.GetView().handle)
336 if type(index)==type(
''):
338 self.trajlist_.pop(index)
339 self.golist_.pop(index)
340 self.ehlist_.pop(index)
344 if not (val<=1.
and val >=0.):
345 print 'Speed should be set between 0 and 1'