IMP  2.2.0
The Integrative Modeling Platform
rmf/geometry.py

This example shows writting one piece of geometry to an hdf5 and then reading it back.

1 ## \example rmf/geometry.py
2 # This example shows writting one piece of geometry to an hdf5 and then
3 # reading it back.
4 
5 import IMP.display
6 import IMP.rmf
7 import RMF
8 
9 # create a temporary file
10 tfn = IMP.create_temporary_file_name("rmf_geometry", ".rmf")
11 
12 # open the hdf5, clearing any existing contents
13 f = RMF.create_rmf_file(tfn)
14 
15 # creating a box geometry
17  IMP.algebra.Vector3D(10, 10, 10))
19 
20 # add the geometry to the file
21 IMP.rmf.add_geometry(f, g)
22 IMP.rmf.save_frame(f, "zero")
23 
25  IMP.algebra.Vector3D(10, 10, 10))
26 g.set_geometry(bb)
27 # save a second frame with the bounding box
28 IMP.rmf.save_frame(f, "one")
29 
30 
31 del f
32 f = RMF.open_rmf_file_read_only(tfn)
33 # recreate the geometries from the file. The geometry will be the same
34 # but it will not be a IMP.display.BoundingBoxGeometry, it will be
35 # a set of cylinders instead.
37 IMP.rmf.load_frame(f, RMF.FrameID(0))
38 print gs[0].get_name()
39 print "Try running rmf_display on", tfn
40 
41 # load another frame
42 IMP.rmf.load_frame(f, RMF.FrameID(1))
43 # cast it to a BoundingBoxGeometry and print out the geometry
44 print IMP.display.BoundingBoxGeometry.get_from(gs[0]).get_geometry()