IMP logo
IMP Reference Guide  2.13.0
The Integrative Modeling Platform
core/randomize_rigid_body.py

This fragment shows how to either perturb or set the orientation of a rigid body randomly.

1 ## \example core/randomize_rigid_body.py
2 # This fragment shows how to either perturb or set the orientation of a rigid
3 # body randomly.
4 
5 import IMP.core
6 import IMP.algebra
7 import IMP
8 import sys
9 
10 IMP.setup_from_argv(sys.argv, "randomize rigid body")
11 
12 m = IMP.Model()
13 p = IMP.Particle(m)
16  IMP.algebra.get_unit_bounding_box_3d())
17 
18 # we don't yet have python code to generate a nearby rotation
20 transformation = IMP.algebra.Transformation3D(rotation, translation)
21 # Option 1:
22 # note, this overwrites the existing position
23 rbd.set_reference_frame(IMP.algebra.ReferenceFrame3D(transformation))
24 # Option 2:
25 # perturb the existing transformation
26 composed_tr = IMP.algebra.compose \
27  (rbd.get_reference_frame().get_transformation_to(),
28  transformation)
29 rbd.set_reference_frame(IMP.algebra.ReferenceFrame3D(composed_tr))
30 # Alternative to Option 2:
31 IMP.core.transform(rbd, transformation)