IMP
2.3.0
The Integrative Modeling Platform
IMP Mainpage
Modules
Applications
Related Pages
Groups
Classes
Files
Examples
Indexes
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
9
m =
IMP.kernel.Model
()
10
p =
IMP.kernel.Particle
(m)
11
rbd =
IMP.core.RigidBody.setup_particle
(p,
IMP.algebra.ReferenceFrame3D
())
12
translation =
IMP.algebra.get_random_vector_in
(
13
IMP.algebra.get_unit_bounding_box_3d())
14
15
# we don't yet have python code to generate a nearby rotation
16
rotation =
IMP.algebra.get_random_rotation_3d
()
17
transformation =
IMP.algebra.Transformation3D
(rotation, translation)
18
# Option 1:
19
# note, this overwrites the existing position
20
rbd.set_reference_frame(
IMP.algebra.ReferenceFrame3D
(transformation))
21
# Option 2:
22
# perturb the existing transformation
23
composed_tr = IMP.algebra.compose \
24
(rbd.get_reference_frame().get_transformation_to(),
25
transformation)
26
rbd.set_reference_frame(
IMP.algebra.ReferenceFrame3D
(composed_tr))
27
# Alternative to Option 2:
28
IMP.core.transform
(rbd, transformation)