home
about
news
download
doc
source
systems
tests
bugs
contact
IMP Reference Guide
2.22.0
The Integrative Modeling Platform
IMP Manual
Reference Guide
Tutorial Index
Modules
Classes
Examples
version 2.22.0
rmf/geometry.py
This example shows writing one piece of geometry to an RMF file and then reading it back.
1
## \example rmf/geometry.py
2
# This example shows writing one piece of geometry to an RMF file and then
3
# reading it back.
4
5
import
IMP.display
6
import
IMP.rmf
7
import
RMF
8
import
sys
9
10
IMP.setup_from_argv
(sys.argv,
"geometry"
)
11
12
tfn =
"rmf_geometry.rmf"
13
14
# open the RMF, clearing any existing contents
15
f = RMF.create_rmf_file(tfn)
16
17
# creating a box geometry
18
bb =
IMP.algebra.BoundingBox3D
(
IMP.algebra.Vector3D
(0, 0, 0),
19
IMP.algebra.Vector3D
(10, 10, 10))
20
g =
IMP.display.BoundingBoxGeometry
(bb)
21
22
# add the geometry to the file
23
IMP.rmf.add_geometry
(f, g)
24
IMP.rmf.save_frame
(f,
"zero"
)
25
26
bb =
IMP.algebra.BoundingBox3D
(
IMP.algebra.Vector3D
(1, 1, 1),
27
IMP.algebra.Vector3D
(10, 10, 10))
28
g.set_geometry(bb)
29
# save a second frame with the bounding box
30
IMP.rmf.save_frame
(f,
"one"
)
31
32
33
del f
34
f = RMF.open_rmf_file_read_only(tfn)
35
# recreate the geometries from the file. The geometry will be the same
36
# but it will not be a IMP.display.BoundingBoxGeometry; it will be
37
# a set of cylinders instead.
38
gs =
IMP.rmf.create_geometries
(f)
39
IMP.rmf.load_frame
(f, RMF.FrameID(0))
40
print(gs[0].get_name())
41
print(
"Try running rmf_display on"
, tfn)
42
43
# load another frame
44
IMP.rmf.load_frame
(f, RMF.FrameID(1))
45
# cast it to a BoundingBoxGeometry and print out the geometry
46
print(IMP.display.BoundingBoxGeometry.get_from(gs[0]).get_geometry())