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_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_slider=_PyQt5.QtWidgets.QSlider(self)
57 self.
_slider_slider.setOrientation(_Qt.Horizontal)
58 self.
_speed_slider_speed_slider=_PyQt5.QtWidgets.QSlider(self)
59 self.
_speed_slider_speed_slider.setOrientation(_Qt.Horizontal)
62 self.
_speedLabel_speedLabel.setAlignment(_Qt.AlignLeft)
63 self.
_play_play=_PyQt5.QtWidgets.QToolButton(self)
64 self.
_repeat_repeat=_PyQt5.QtWidgets.QCheckBox(self)
65 self.
_frame_frame=_QLabel(self)
68 self.
_repeat_repeat.setText(
'Repeat')
69 self.
_slider_slider.setTracking(
True)
70 self.
_play_play.setText(
'Play')
71 self.
_play_play.setCheckable(
True)
72 self.
_frame_frame.setText(
'Frame: ')
74 self.
_frameNo_frameNo.setAlignment(_Qt.AlignRight)
75 self.
_frameEnd_frameEnd.setAlignment(_Qt.AlignLeft)
77 self.
_timeNo_timeNo=_QLabel(self)
82 self.
_timeNo_timeNo.setAlignment(_Qt.AlignRight)
83 self.
_timeEnd_timeEnd.setAlignment(_Qt.AlignLeft)
84 self.
_timeUnit_timeUnit.setAlignment(_Qt.AlignLeft)
94 self.
_left_end_left_end=_QPushButton(
"|<")
96 self.
_align_align=_QPushButton(
"Align")
103 hb.addWidget(self.
_play_play)
104 hb.addWidget(self.
_repeat_repeat)
113 hb2.addWidget(self.
_frame_frame)
114 hb2.addWidget(self.
_frameNo_frameNo)
117 hb2.addWidget(self.
_timeNo_timeNo)
118 hb2.addWidget(self.
_timeEnd_timeEnd)
124 hb4.addWidget(self.
_align_align)
128 vb.addWidget(self.
_slider_slider)
144 self.
_slider_slider.setMinimum(0)
163 raise RuntimeError(
"expected one of s,ms,us,ns,ps or fs for unit")
169 self.
_timeUnit_timeUnit.setText(
'['+u+
']')
171 def _SetSpeedSliderPos(self,pos):
175 def _SpeedSliderValChanged(self,speed_pos):
176 self.
timetime=_math.exp(-0.15*speed_pos)
177 if self.
_play_play.isChecked():
181 def _SetTime(self,t):
183 self.
_speed_slider_speed_slider.setSliderPosition(-1./0.15*_math.log(t))
184 if self.
_play_play.isChecked():
189 def _SliderValueChanged(self, pos):
192 if go.name
in self.
fix_dictfix_dict:
continue
196 def _GetCurrentFrame(self):
197 return self.
_slider_slider.sliderPosition()
199 def _SetCurrentFrame(self, pos):
200 if self.
_slider_slider.maximum()<pos:
201 if self.
_repeat_repeat.isChecked():
204 pos=self.
_slider_slider.maximum()
205 self.
_slider_slider.setSliderPosition(pos)
209 current_frame=property(_GetCurrentFrame, _SetCurrentFrame)
211 def _GetReferenceTraj(self):
213 traj_=property(_GetReferenceTraj)
220 if go.name
in self.
fix_dictfix_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):
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_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(
''):
285 def _EntitySelected(self,index):
291 if event.modifiers()==_Qt.ControlModifier:
292 self.
modifiersmodifiers=event.modifiers()
293 if self.
modifiersmodifiers==_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_play.setChecked(
not self.
_play_play.isChecked())
306 _QWidget.keyPressEvent(self, event)
309 if event.key()==_Qt.Key_Control:
312 _QWidget.keyPressEvent(self, event)
315 if not frame_number:frame_number=self.
current_framecurrent_frame
316 if type(index)==type(
''):
317 self.
fix_dictfix_dict[index]=frame_number
322 self.
trajlist_trajlist_[i].CopyFrame(frame_number)
323 self.
golist_golist_[i].UpdatePositions()
326 if type(index)==type(
''):self.
fix_dictfix_dict.pop(index)
332 self.
ehlist_ehlist_.append(go.GetView().handle)
336 if type(index)==type(
''):
344 if not (val<=1.
and val >=0.):
345 print(
'Speed should be set between 0 and 1')