OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
primitives.py

Shows how to create grapical objects to render lines and rectangles in 3D space.

See Also
Bounding Box Example, Random Lines
1 sdh=io.LoadPDB('sdh.pdb')
2 helix=sdh.Select('rnum=75:78 and cname=A and aname=CA,C,N,O')
3 res_a=helix.residues[0]
4 res_b=helix.residues[-1]
5 
6 def MakePlane(name, pt1, pt2, pt3):
7  p1=[pt1, pt2, pt3, pt2+(pt1-pt2)+(pt3-pt2)]
8  c1=sum(p1)/4.0
9  p1=[c1+(p-c1)*1.5 for p in p1]
10  plane=gfx.Quad(name, *p1)
11  plane.SetLineWidth(1.0)
12  plane.SetFillColor(gfx.Color(0.3, 0.7, 0.3, 0.5))
13  scene.Add(plane)
14 
15 r1_n=res_a.FindAtom("N").pos
16 r1_ca=res_a.FindAtom("CA").pos
17 r1_c=res_a.FindAtom("C").pos
18 MakePlane("Plane1", r1_n, r1_ca, r1_c)
19 r2_ca=res_b.FindAtom("CA").pos
20 r2_c=res_b.FindAtom("C").pos
21 r2_o=res_b.FindAtom("O").pos
22 MakePlane("Plane2", r2_ca, r2_c, r2_o)
23 
24 ca_dist=gfx.PrimList("Calpha dist")
25 ca_dist.AddLine(r1_ca, r2_ca, gfx.GREEN)
26 scene.Add(ca_dist)
27 go=gfx.Entity('helix2', gfx.SIMPLE, helix)
28 scene.Add(go)
29 scene.SetBackground(gfx.WHITE)
30 go.SetRenderMode(gfx.CUSTOM)
31 scene.center=go.center