IMP  2.4.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 from __future__ import print_function
6 import IMP.display
7 import IMP.rmf
8 import RMF
9 
10 # create a temporary file
11 tfn = IMP.create_temporary_file_name("rmf_geometry", ".rmf")
12 
13 # open the hdf5, clearing any existing contents
14 f = RMF.create_rmf_file(tfn)
15 
16 # creating a box geometry
18  IMP.algebra.Vector3D(10, 10, 10))
20 
21 # add the geometry to the file
22 IMP.rmf.add_geometry(f, g)
23 IMP.rmf.save_frame(f, "zero")
24 
26  IMP.algebra.Vector3D(10, 10, 10))
27 g.set_geometry(bb)
28 # save a second frame with the bounding box
29 IMP.rmf.save_frame(f, "one")
30 
31 
32 del f
33 f = RMF.open_rmf_file_read_only(tfn)
34 # recreate the geometries from the file. The geometry will be the same
35 # but it will not be a IMP.display.BoundingBoxGeometry, it will be
36 # a set of cylinders instead.
38 IMP.rmf.load_frame(f, RMF.FrameID(0))
39 print(gs[0].get_name())
40 print("Try running rmf_display on", tfn)
41 
42 # load another frame
43 IMP.rmf.load_frame(f, RMF.FrameID(1))
44 # cast it to a BoundingBoxGeometry and print out the geometry
45 print(IMP.display.BoundingBoxGeometry.get_from(gs[0]).get_geometry())