OpenStructure
bbox.py

Illustrates the use of BoundingBoxFromEntity().

1 # This code example shows how to calculate and display an oriented bounding box
2 # that contains all the atoms of an entity.
3 
4 # remove all objects from scene, just in case
5 scene.RemoveAll()
6 
7 # Load sdh molecule
8 sdh=io.LoadPDB('data/sdh.pdb')
9 # Select backbone atoms of residues 99-128, which form a helix.
10 helix=sdh.Select('rnum=99:128 and cname=A and aname=CA,C,N,O')
11 # create a graphical representation of the helix and render it with simple
12 # lines.
13 go=gfx.Entity('helix', gfx.SIMPLE, helix)
14 # add it to the scene
15 scene.Add(go)
16 
17 # calculate the bounding box for the helix
18 bbox=mol.BoundingBoxFromEntity(helix)
19 
20 # create a graphical representation of the bounding box and add it to the scene
21 bb=gfx.Cuboid('xxx', bbox)
22 bb.SetFillColor(gfx.Color(0.5, 0.8, 0.5, 0.2))
23 scene.Add(bb)
24 
25 # center the camera on the graphical object
26 scene.center=go.center