IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
randomize_rigid_body.py
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
5import IMP.core
6import IMP.algebra
7import IMP
8import sys
9
10IMP.setup_from_argv(sys.argv, "randomize rigid body")
11
12m = IMP.Model()
13p = 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
20transformation = IMP.algebra.Transformation3D(rotation, translation)
21# Option 1:
22# note, this overwrites the existing position
23rbd.set_reference_frame(IMP.algebra.ReferenceFrame3D(transformation))
24# Option 2:
25# perturb the existing transformation
26composed_tr = IMP.algebra.compose(
27 rbd.get_reference_frame().get_transformation_to(), transformation)
28rbd.set_reference_frame(IMP.algebra.ReferenceFrame3D(composed_tr))
29# Alternative to Option 2:
30IMP.core.transform(rbd, transformation)
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Class to handle individual particles of a Model object.
Definition Particle.h:45
A reference frame in 3D.
Simple 3D transformation class.
static RigidBody setup_particle(Model *m, ParticleIndex pi, ParticleIndexesAdaptor ps)
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
Rotation3D get_random_rotation_3d()
Pick a rotation at random from all possible rotations.
Rotation2D compose(const Rotation2D &a, const Rotation2D &b)
Compose two rotations a and b.
Definition Rotation2D.h:121
VectorD< D > get_random_vector_in(const BoundingBoxD< D > &bb)
Generate a random vector in a box with uniform density.
Basic functionality that is expected to be used by a wide variety of IMP users.
void transform(RigidBody a, const algebra::Transformation3D &tr)
Transform a rigid body.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.