IMP logo
rmf examples

geometry

This example shows writting one piece of geometry to an hdf5 and then reading it back.

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
# 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
del f
# 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.
print gs[0].get_name()
print "Try running rmf_display on", tfn
# load another frame
# cast it to a BoundingBoxGeometry and print out the geometry
print IMP.display.BoundingBoxGeometry.get_from(gs[0]).get_geometry()

multiresolution

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")
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
nm= str(IMP.atom.Residue(res[0]).get_index())+"-"\
+ 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)
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)
fn= IMP.base.create_temporary_file_name("multires", ".rmf")
print "see file", fn

pdb

Write a PDB to an hdf5 file.

import IMP.atom
import IMP.rmf
import RMF
# 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
# add the hierarchy to the file
# change a coordinate
# add the new configuration to the file as frame 1
# close the file
del rh
# reopen it, don't clear the file when opening it
# hps is a list with one element which is a copy of h
# load the second configuration into hps
print "Try running hdf5_display or hdf5_show on", tfn

simulation

This example shows writing a brownian dynamics simulation to a rmf file. It includes a bounding box, restraints and a hierarchy of particles.

import IMP.atom
import IMP.rmf
import RMF
k=10.0
np=10
if IMP.build=="debug":
frames=100
else:
frames=1000
bb= IMP.algebra.BoundingBox3D(IMP.algebra.Vector3D(0,0,0),
ps= [IMP.core.XYZR.setup_particle(IMP.Particle(m)) for i in range(0,np)]
for p in ps:
p.set_radius(1)
p.set_coordinates_are_optimized(True)
p.set_coordinates(IMP.algebra.get_random_vector_in(bb))
rs=[]
pl=[]
for i in range(0, len(ps)/2):
pp=(ps[2*i], ps[2*i+1])
pl.append(pp)
# create OK staring position
pp[1].set_coordinates(IMP.algebra.get_random_vector_on(pp[0].get_sphere()))
hr= IMP.atom.Hierarchy.setup_particle(IMP.Particle(m, "molecule "+str(i)))
hr.add_child(IMP.atom.Hierarchy.setup_particle(pp[0]))
hr.add_child(IMP.atom.Hierarchy.setup_particle(pp[1]))
h.add_child(hr)
r= IMP.container.PairsRestraint(link, pl, "Bonds")
rs.append(r)
rs.append(ev)
rs.append(bbr)
bd.set_scoring_function(sf)
bd.set_maximum_time_step(10)
name= IMP.base.create_temporary_file_name("brownian", ".rmf")
os.set_log_level(IMP.SILENT)
IMP.rmf.add_geometry(rmf, IMP.display.BoundingBoxGeometry(bb))
bd.add_optimizer_state(os)
bd.optimize(frames)
print "file is", rmf.get_name()


Generated on Tue May 22 2012 23:33:21 for IMP by doxygen 1.8.1