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