IMP  2.0.0
The Integrative Modeling Platform
core/randomize_rigid_body.py

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

1 ## \example core/randomize_rigid_body.py
2 ## This fragments 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 from IMP.algebra import ReferenceFrame3D
9 from IMP.algebra import Transformation3D
10 
11 m = IMP.Model()
12 p = IMP.Particle(m)
13 rbd = IMP.core.RigidBody.setup_particle(p, ReferenceFrame3D())
14 translation=IMP.algebra.get_random_vector_in(IMP.algebra.get_unit_bounding_box_3d())
15 
16 # we don't yet have python code to generate a nearby rotation
18 transformation= Transformation3D(rotation, translation)
19 # Option 1:
20 # note, this overwrites the existing position
21 # The True is to transform the members now rather than wait for a
22 # score state
23 rbd.set_reference_frame(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(ReferenceFrame3D(composed_tr))
30 # Alternative to Option 2:
31 IMP.core.transform(rbd, transformation)