This example shows writting one piece of geometry to an hdf5 and then reading it back.
import IMP.display
import IMP.rmf
import RMF
# create a temporary file
tfn= IMP.create_temporary_file_name("rmf_geometry", "rmf")
# open the hdf5, clearing any existing contents
f= RMF.create_rmf_file(tfn)
# creating a box geometry
bb= IMP.algebra.BoundingBox3D(IMP.algebra.Vector3D(0,0,0),
IMP.algebra.Vector3D(10, 10, 10))
# add the geometry to the file
IMP.rmf.add_geometry(f, g)
bb= IMP.algebra.BoundingBox3D(IMP.algebra.Vector3D(1,1,1),
IMP.algebra.Vector3D(10, 10, 10))
g.set_geometry(bb)
# save a second frame with the bounding box
IMP.rmf.save_frame(f, 1)
del f
f= RMF.open_rmf_file_read_only(tfn)
# recreate the geometries from the file. The geometry will be the same
# but it will not be a IMP.display.BoundingBoxGeometry, it will be
# a set of cylinders instead.
gs= IMP.rmf.create_geometries(f)
print gs[0].get_name()
print "Try running rmf_display on", tfn
# load another frame
IMP.rmf.load_frame(f, 1)
# cast it to a BoundingBoxGeometry and print out the geometry
print IMP.display.BoundingBoxGeometry.get_from(gs[0]).get_geometry()
|
|
In this example a pdb is converted into a multiresolution model, somewhat painfully.
import IMP.atom
import RMF
import IMP.rmf
pdbname= IMP.rmf.get_example_path("big.pdb")
m= IMP.Model()
h= IMP.atom.read_pdb(pdbname, m)
chains= IMP.atom.get_by_type(h, IMP.atom.CHAIN_TYPE)
def recursive_approximation(res):
lr=len(res)
if lr<=1:
return res
if lr > 4:
me= recursive_approximation(res[0:lr/4])\
+recursive_approximation(res[lr/4: lr/2])\
+recursive_approximation(res[lr/2: 3*lr/4])\
+recursive_approximation(res[3*lr/4: lr])
else:
me= res
p= IMP.Particle(m)
IMP.atom.setup_as_approximation(p, res)
+ str(IMP.atom.Residue(res[-1]).get_index())
p.set_name(nm)
for mm in me:
hc.add_child(mm)
return [hc]
for c in chains:
res= IMP.atom.get_by_type(h, IMP.atom.RESIDUE_TYPE)
for r in res:
c.remove_child(r)
lvs= IMP.atom.get_leaves(r)
IMP.atom.setup_as_approximation(r, lvs)
lr=len(res)
me= recursive_approximation(res[0:lr/4])\
+recursive_approximation(res[lr/4: lr/2])\
+recursive_approximation(res[lr/2: 3*lr/4])\
+recursive_approximation(res[3*lr/4: lr])
for mm in me:
c.add_child(mm)
rmf= RMF.create_rmf_file(fn)
IMP.rmf.add_hierarchies(rmf, chains)
print "see file", fn
|
Write a PDB to an hdf5 file.
import IMP.atom
import IMP.rmf
import RMF
m= IMP.Model()
# Create a new IMP.atom.Hierarchy from the contents of the pdb file
h= IMP.atom.read_pdb(IMP.rmf.get_example_path("simple.pdb"), m)
# find the name for a temporary file to use to for writing the hdf5 file
tfn=IMP.create_temporary_file_name("pdb", ".rmf")
print "File name is", tfn
# open the temporary file, clearing any existing contents
rh = RMF.create_rmf_file(tfn)
# add the hierarchy to the file
IMP.rmf.add_hierarchies(rh, [h])
# change a coordinate
IMP.core.XYZ(IMP.atom.get_leaves(h)[0]).set_x(0)
# add the new configuration to the file as frame 1
IMP.rmf.save_frame(rh, 1)
# close the file
del rh
# reopen it, don't clear the file when opening it
rh= RMF.open_rmf_file(tfn)
# hps is a list with one element which is a copy of h
hps= IMP.rmf.create_hierarchies(rh, m)
# load the second configuration into hps
IMP.rmf.load_frame(rh, 1)
print "Try running hdf5_display or hdf5_show on", tfn
|
|
This example shows writing a brownian dynamics simulation to a rmf file. It includes a bounding box, restraints and a hierarchy of particles.