IMP
2.3.1
The Integrative Modeling Platform
IMP Mainpage
Modules
Applications
Related Pages
Groups
Classes
Files
Examples
Indexes
rmf/pdb.py
Write a PDB to an hdf5 file.
1
## \example rmf/pdb.py
2
# Write a PDB to an hdf5 file.
3
#
4
5
import
IMP.atom
6
import
IMP.rmf
7
import
RMF
8
m =
IMP.kernel.Model
()
9
10
# Create a new IMP.atom.Hierarchy from the contents of the pdb file
11
h =
IMP.atom.read_pdb
(
IMP.rmf.get_example_path
(
"simple.pdb"
), m)
12
13
# find the name for a temporary file to use to for writing the hdf5 file
14
tfn = IMP.create_temporary_file_name(
"pdb"
,
".rmf"
)
15
16
print
"File name is"
, tfn
17
18
# open the temporary file, clearing any existing contents
19
rh = RMF.create_rmf_file(tfn)
20
21
# add the hierarchy to the file
22
IMP.rmf.add_hierarchies
(rh, [h])
23
24
# add the current configuration to the file as frame 0
25
IMP.rmf.save_frame
(rh)
26
27
# change a coordinate
28
IMP.core.XYZ
(
IMP.atom.get_leaves
(h)[0]).set_x(0)
29
30
# add the new configuration to the file as frame 1
31
IMP.rmf.save_frame
(rh)
32
33
# close the file
34
del rh
35
36
# reopen it, don't clear the file when opening it
37
rh = RMF.open_rmf_file_read_only(tfn)
38
39
# hps is a list with one element which is a copy of h
40
hps =
IMP.rmf.create_hierarchies
(rh, m)
41
42
IMP.atom.show_molecular_hierarchy
(hps[0])
43
44
# load the second configuration into hps
45
IMP.rmf.load_frame
(rh, RMF.FrameID(0))
46
47
print
"Try running hdf5_display or hdf5_show on"
, tfn