Skip to content
Snippets Groups Projects
Commit 42385202 authored by marco's avatar marco
Browse files

update paths, and generally improve the user experience when running the demos

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2513 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 2d5a8335
No related branches found
No related tags found
No related merge requests found
sdh=io.LoadPDB('sdh.pdb') # This code example shows how to calculate and display an oriented bounding box
# that contains all the atoms of an entity.
# remove all objects from scene, just in case
scene.RemoveAll()
# Load sdh molecule
sdh=io.LoadPDB('data/sdh.pdb')
# Select backbone atoms of residues 99-128, which form a helix.
helix=sdh.Select('rnum=99:128 and cname=A and aname=CA,C,N,O') helix=sdh.Select('rnum=99:128 and cname=A and aname=CA,C,N,O')
# create a graphical representation of the helix and render it with simple
# lines.
go=gfx.Entity('helix', gfx.SIMPLE, helix) go=gfx.Entity('helix', gfx.SIMPLE, helix)
# add it to the scene
scene.Add(go) scene.Add(go)
# calculate the bounding box for the helix
bbox=mol.BoundingBoxFromEntity(helix) bbox=mol.BoundingBoxFromEntity(helix)
def RenderBBox(bbox): # create a graphical representation of the bounding box and add it to the scene
bb=gfx.Cuboid('xxx', bbox) bb=gfx.Cuboid('xxx', bbox)
bb.SetFillColor(gfx.Color(0.5, 0.8, 0.5, 0.2)) bb.SetFillColor(gfx.Color(0.5, 0.8, 0.5, 0.2))
scene.Add(bb) scene.Add(bb)
print 'Center:',(helix.GetGeometricStart()+helix.GetGeometricEnd())*.5 # center the camera on the graphical object
RenderBBox(bbox)
scene.center=go.center scene.center=go.center
print 'Demo2: Translucent bounding box around an OpenStructure entity'
# trajectory generated by Raimund Dutzler # trajectory generated by Raimund Dutzler
from PyQt4 import QtCore from PyQt4 import QtCore
scene.RemoveAll()
class Anim(QtCore.QTimer): class Anim(QtCore.QTimer):
def __init__(self,cg,go): """
QtCore.QTimer.__init__(self) Timer used to animate the trajectory on screen. Each time the OnTimer
self.cg_=cg method gets called we advance the trajectory by one step and render
self.go_=go the scene on the screen.
self.frame_=0 """
QtCore.QObject.connect(self, QtCore.SIGNAL("timeout()"), self.OnTimer) def __init__(self,cg,go):
QtCore.QTimer.__init__(self)
def OnTimer(self): self.cg_=cg
self.step() self.go_=go
self.frame_=0
QtCore.QObject.connect(self, QtCore.SIGNAL("timeout()"), self.OnTimer)
def OnTimer(self):
self.frame_=(self.frame_+1)%self.cg_.GetFrameCount()
self.go_.BlurSnapshot()
self.cg_.CopyFrame(self.frame_)
self.go_.UpdatePositions()
def step(self):
self.frame_=(self.frame_+1)%self.cg_.GetFrameCount()
go.BlurSnapshot()
self.cg_.CopyFrame(self.frame_)
go.UpdatePositions()
cg = io.LoadCHARMMTraj("sample.pdb","sample.dcd") # load CHARMM trajectory from sample.pdb and sample.dcd
cg = io.LoadCHARMMTraj("data/sample.pdb","data/sample.dcd")
# create graphical representation of the entity
eh=cg.GetEntity() eh=cg.GetEntity()
# we don't want to display the hydrogen atoms, so select everything that is
# not a hydrogen and pass that view to the gfx.Entity() constructor.
ev=eh.Select("not ele=H") ev=eh.Select("not ele=H")
go=gfx.Entity("mol",gfx.SIMPLE, ev) go=gfx.Entity("mol",gfx.SIMPLE, ev)
# enable the blur effect
go.SetBlur(True) go.SetBlur(True)
# add it to the scene for rendering
scene.Add(go) scene.Add(go)
scene.SetCenter(go.GetCenter()) scene.SetCenter(go.GetCenter())
scene.AutoAutoslab(True) scene.AutoAutoslab(True)
# create an animation timer and start it
anim=Anim(cg,go) anim=Anim(cg,go)
print 'Demo 6: Import of a CHARMM trajectory. Type anim.stop() to halt animation, anim.start(100) to start it again with stepsize 100!Starting animation now....' print 'Demo 6: Import of a CHARMM trajectory. Type anim.stop() to halt animation, anim.start(100) to start it again with stepsize 100!Starting animation now....'
anim.start(50) anim.start(50)
from ost.seq import alg from ost.seq import alg
scene.RemoveAll()
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Loading structure and alignment # Loading structure and alignment
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
m=io.LoadPDB('sh2.pdb') m=io.LoadPDB('data/sh2.pdb')
mp=m.Select('ishetatm=false') mp=m.Select('ishetatm=false')
aln=io.LoadAlignment('sh2.aln') aln=io.LoadAlignment('data/sh2.aln')
aln.AttachView(0, mp) aln.AttachView(0, mp)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Calculate conservation of alignment # Calculate conservation of alignment
# First we set all properties to zero, then let alg.Conservation assign the
# conservation scores to the residues
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
for r in m.residues: for r in m.residues:
r.SetFloatProp('cons', 0) r.SetFloatProp('cons', 0)
alg.Conservation(aln) alg.Conservation(aln)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Setup Graphical Objects for Rendering # Setup Graphical Objects for Rendering
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
g=gfx.Entity('SH2', m) g=gfx.Entity('SH2', m)
s=io.LoadSurface('sh2.vert') s=io.LoadSurface('data/sh2.vert')
gs=gfx.Surface('SH2-surf', s) gs=gfx.Surface('SH2-surf', s)
scene.Add(gs) scene.Add(gs)
scene.Add(g) scene.Add(g)
...@@ -36,9 +41,11 @@ g.SetRenderMode(gfx.CUSTOM, ...@@ -36,9 +41,11 @@ g.SetRenderMode(gfx.CUSTOM,
m.Select('ishetatm=true')) m.Select('ishetatm=true'))
g.SetColor(gfx.YELLOW, 'ishetatm=true') g.SetColor(gfx.YELLOW, 'ishetatm=true')
#-------------------------------------------------------------------------------
# Create alignment viewer and show it on the screen
#-------------------------------------------------------------------------------
seq_viewer=gui.SequenceViewer() seq_viewer=gui.SequenceViewer()
seq_viewer.AddAlignment(aln) seq_viewer.AddAlignment(aln)
seq_viewer.Show() seq_viewer.Show()
print 'Colouring the active site according to the level of conservation found inthe sequences shown in the sequence viewer. Highly conserved regions are shown in blue, variable regions in red.'
import math,random import math,random
from ost import img from ost import img
# remove all objects from scene, just in case
scene.RemoveAll()
vmax=-10000.0 vmax=-10000.0
vmin=+10000.0 vmin=+10000.0
mh=img.CreateMap(img.Size(32,32,32)) mh=img.CreateMap(img.Size(32,32,32))
...@@ -45,6 +49,7 @@ go1.SetLineWidth(1.5) ...@@ -45,6 +49,7 @@ go1.SetLineWidth(1.5)
scene.Add(go1) scene.Add(go1)
scene.SetCenter(go1.GetCenter()) scene.SetCenter(go1.GetCenter())
go2 = gfx.MapSlab("slab",mh,geom.Plane(go1.GetCenter(),geom.Vec3(0.0,0.0,1.0))) go2 = gfx.MapSlab("slab",mh,geom.Plane(go1.GetCenter(),geom.Vec3(0.0,0.0,1.0)))
scene.Add(go2) scene.Add(go2)
go2.ColorBy(gfx.YELLOW,gfx.GREEN,0.2,0.8) go2.ColorBy(gfx.YELLOW,gfx.GREEN,0.2,0.8)
......
# remove all objects from scene, just in case
scene.RemoveAll()
# Load chain A of SDH # Load chain A of SDH
ent=io.LoadPDB('sdh.pdb', restrict_chains='A') ent=io.LoadPDB('data/sdh.pdb', restrict_chains='A')
# create graphics object # create graphics object
go=gfx.Entity('SDH', ent) go=gfx.Entity('SDH', ent)
......
# load pdb file # This script shows how to switch between different render modes
eh=io.LoadEntity("sdh.pdb") # programmatically and change render options.
# remove all objects from scene, just in case
scene.RemoveAll()
# load pdb structure
eh=io.LoadPDB("data/sdh.pdb")
sdh_go=gfx.Entity("SDH2", eh.Select("cname=A")) sdh_go=gfx.Entity("SDH2", eh.Select("cname=A"))
...@@ -9,7 +16,7 @@ scene.CenterOn(sdh_go) ...@@ -9,7 +16,7 @@ scene.CenterOn(sdh_go)
def Tube(): def Tube():
sdh_go.SetRenderMode(gfx.TUBE) sdh_go.SetRenderMode(gfx.TUBE)
sdh_go.GetOptions(gfx.TUBE).SetTubeRadius(0.8) sdh_go.tube_options.SetTubeRadius(0.8)
# apply color gradient for the atomic bfactors # apply color gradient for the atomic bfactors
sdh_go.ColorBy("abfac",gfx.BLUE,gfx.RED) sdh_go.ColorBy("abfac",gfx.BLUE,gfx.RED)
# and apply radius gradient as well # and apply radius gradient as well
...@@ -32,15 +39,15 @@ def Cartoon(): ...@@ -32,15 +39,15 @@ def Cartoon():
sdh_go.SetColor(gfx.Color(1,0,0),"rtype=E") sdh_go.SetColor(gfx.Color(1,0,0),"rtype=E")
sdh_go.SetDetailColor(gfx.Color(1.0,0.8,0.2),"rtype=E") sdh_go.SetDetailColor(gfx.Color(1.0,0.8,0.2),"rtype=E")
# these are the default params for the rendering # these are the default params for the rendering
#sdh_go.GetOptions(gfx.HSC).SetArcDetail(4) # circular profile detail #sdh_go.cartoon_options.SetArcDetail(4) # circular profile detail
#sdh_go.GetOptions(gfx.HSC).SetSphereDetail(4) # sphere detail #sdh_go.cartoon_options.SetSphereDetail(4) # sphere detail
#sdh_go.GetOptions(gfx.HSC).SetSplineDetail(8) # segments between backbone atoms #sdh_go.cartoon_options.SetSplineDetail(8) # segments between backbone atoms
#sdh_go.GetOptions(gfx.HSC).SetTubeRadius(0.4) # coil radius #sdh_go.cartoon_options.SetTubeRadius(0.4) # coil radius
#sdh_go.GetOptions(gfx.HSC).SetTubeRatio(1.0) # coil axial ratio #sdh_go.cartoon_options.SetTubeRatio(1.0) # coil axial ratio
#sdh_go.GetOptions(gfx.HSC).SetHelixWidth(1.1) # helical width #sdh_go.cartoon_options.SetHelixWidth(1.1) # helical width
#sdh_go.GetOptions(gfx.HSC).SetHelixThickness(0.2) # helical thickness #sdh_go.cartoon_options.SetHelixThickness(0.2) # helical thickness
#sdh_go.GetOptions(gfx.HSC).SetStrandWidth(1.2) # strand width #sdh_go.cartoon_options.SetStrandWidth(1.2) # strand width
#sdh_go.GetOptions(gfx.HSC).SetStrandThickness(0.2) # strand thickness #sdh_go.cartoon_options.SetStrandThickness(0.2) # strand thickness
Cartoon() Cartoon()
print 'Demo 5: Type Spheres(), Tube(), Trace(), or Cartoon()\n to switch render modes'
from PyQt4 import QtCore from PyQt4 import QtCore
import math import math
from ost import qa from ost import qa
# remove all objects from scene, just in case
scene.RemoveAll()
class Anim(QtCore.QTimer): class Anim(QtCore.QTimer):
def __init__(self, a, b): def __init__(self, a, b):
QtCore.QTimer.__init__(self) QtCore.QTimer.__init__(self)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment