IMP  2.2.1
The Integrative Modeling Platform
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
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
23 
24 # add the current configuration to the file as frame 0
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
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