def _RotateDelta(self, delta): """ Responds to a change in mouse position of delta. """ if delta.y() != 0: gfx.Scene().Apply( gfx.InputEvent(gfx.INPUT_DEVICE_MOUSE, gfx.INPUT_COMMAND_ROTX, delta.y() * 0.5), False) if delta.x() != 0: gfx.Scene().Apply( gfx.InputEvent(gfx.INPUT_DEVICE_MOUSE, gfx.INPUT_COMMAND_ROTY, delta.x() * 0.5), False) self.update()
def Changed(self, tx, ty, tz, rx, ry, rz): scene = gfx.Scene() tf = scene.transform def d(r): if r == 0.0: return 0.0 rr = r / abs(r) * max(0.0, abs(r) - 0.9) if abs(rr) > 0: return rr / abs(rr) * (math.pow(1.01, abs(rr)) - 1.0) * 40.0 / self.speed return 0.0 if (self.trans): tf.ApplyXAxisTranslation(d(tx)) tf.ApplyYAxisTranslation(d(ty)) # adjust translation speed to distance from viewpoint currz = tf.trans[2] delta = currz * math.pow(1.01, d(tz)) - currz tf.ApplyZAxisTranslation(delta) # adjust near and far clipping planes together with z trans scene.SetNearFar(scene.near - delta, scene.far - delta) if (self.rot): tf.ApplyXAxisRotation(d(rx)) tf.ApplyYAxisRotation(d(ry)) tf.ApplyZAxisRotation(d(rz)) scene.transform = tf scene.RequestRedraw()
def wheelEvent(self, event): """ Scrolling zooming is... """ gfx.Scene().Apply( gfx.InputEvent(gfx.INPUT_DEVICE_MOUSE, gfx.INPUT_COMMAND_TRANSZ, -0.1 * event.delta()), False) self.update()
def _UniqueName(self, ent): """ Returns a name based on ent that is unique within the scene """ ent_name=ent.GetName() num=2 while True: candidate_name='%s-%d' % (ent_name, num) if not gfx.Scene().HasNode(candidate_name): return candidate_name num+=1
def _CopyViews(self): views_to_add=[] scene_selection=gui.SceneSelection.Instance() ent=scene_selection.GetActiveNode(0) dialog=QueryDialog('Select...') if dialog.exec_(): q=mol.Query(dialog.query) if q.IsValid(): for i in range(scene_selection.GetActiveNodeCount()): ent=scene_selection.GetActiveNode(i) selected=ent.view.Select(q, dialog.query_flags) gfx_ent=gfx.Entity(self._UniqueName(ent),selected) gfx.Scene().Add(gfx_ent) else: ost.LogError("invalid query: %s" % q.error)
def _DoLoad(self): split_ids = [] for p in str(self._line.text()).split(','): for k in p.split(): if len(k.strip()): split_ids.append(k.strip()) self._line.setText('') for split_id in split_ids: try: ent = RemoteLoad(split_id, from_repo=self._current_repo) except Exception as e: LogError(str(e)) continue g = gfx.Entity(split_id, ent) try: gfx.Scene().Add(g) except Exception as e: LogError(str(e))
def __CalculateSurface(self,ent_list,name,msms_exe,density, radius,selection,noh,nohet,nowat): for entity in ent_list: if isinstance(entity, gfx.Entity): try: s=msms.CalculateSurface(entity.view, msms_exe=msms_exe, density=density, radius=radius, selection=selection, no_hydrogens=noh, no_hetatoms=nohet, no_waters=nowat)[0] gfx.Scene().Add(gfx.Surface("%s_%s"%(entity.GetName(),name),s)) except (RuntimeError, msms.MsmsProcessError): LogError("WARNING: Surface could not be calculated") return except UserWarning: LogError("WARNING: Entry with the same name already present in scene") return
if os.path.exists(_ostrc): try: exec(compile(open(_ostrc).read(), _ostrc, 'exec')) except Exception as e: print(e) else: rcfile = open(_ostrc, "w") print('# This python file is parsed by ost and dng at startup', file=rcfile) print('# Its content is made available in the global namespace', file=rcfile) print('# It can be used to define custom variables and functions', file=rcfile) print('# For example:', file=rcfile) print('# IMPORTANT_DIR="path/to/important/dir"', file=rcfile) rcfile.close() ost.gui.PushVerbosityLevel(options.vlevel) working_dir = settings.GetValue("DNG_WORKING_DIR", None) if working_dir != None and os.path.isdir(working_dir): os.chdir(working_dir) _InitFrontEnd(options.try_stereo) if len(loading_list) != 0: _load_files() gfx.Scene().Autoslab() if len(script_argv) != 0: _execute_script()
def mousePressEvent(self, event): self._last_pos = QPoint(event.x(), event.y()) gfx_obj, atom = gfx.PickAtom(gfx.Scene(), event.x(), self.height() - event.y()) if gfx_obj: print 'picked: ', gfx_obj.name, atom
def mouseDoubleClickEvent(self, event): self._last_pos = QPoint(event.x(), event.y()) gfx_obj, atom = gfx.PickAtom(gfx.Scene(), event.x(), self.height() - event.y()) if gfx_obj: gfx.Scene().SetCenter(atom.pos)
def test_custom_gfx_obj(self): myobj=MyGfxObj("foo") gfx.Scene().Add(myobj)
def paintGL(self): gfx.Scene().SetShadingMode('hemilight') gfx.Scene().RenderGL()
def initializeGL(self): gfx.Scene().InitGL(True) gfx.Scene().fogno = 10
def __init__(self, threed_widget): gfx.GLWinBase.__init__(self) self._threed_widget = weakref.proxy(threed_widget) gfx.Scene().Register(self)
delta.x() * 0.5), False) self.update() def App(title='OST Viewer', width=800, height=600): """ """ import sys app = QApplication(sys.argv) fmt = QGLFormat() fmt.setAlpha(True) fmt.setSampleBuffers(True) wnd = ThreeDWidget(fmt) wnd.resize(width, height) wnd.setWindowTitle(title) wnd.show() app.threed = wnd return app if __name__ == '__main__': from ost import io # example use app = App() structure = io.LoadPDB('1crn.pdb') obj = gfx.Entity('structure', gfx.HSC, structure) obj.SetColor(gfx.YELLOW, 'rtype=H,E') obj.SetDetailColor(gfx.RED, 'rtype=H,E') gfx.Scene().Add(obj) app.exec_()
def resizeGL(self, w, h): gfx.Scene().Resize(w, h)
def test_gfxobj_conv(self): e=mol.CreateEntity() gfx.Scene().Add(gfx.Entity("foo2",e)) gfx.Scene()["foo2"].SetColor(gfx.YELLOW)