IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
randomizing.h
Go to the documentation of this file.
1/**
2 * \file IMP/example/randomizing.h
3 * \brief A simple unary function.
4 *
5 * Copyright 2007-2022 IMP Inventors. All rights reserved.
6 *
7 */
8
9#ifndef IMPEXAMPLE_RANDOMIZING_H
10#define IMPEXAMPLE_RANDOMIZING_H
11
12#include <IMP/example/example_config.h>
15
16IMPEXAMPLE_BEGIN_NAMESPACE
17
18template <class RigidBody, class BoundingVolume>
19void randomize_rigid_body(RigidBody rbi, const BoundingVolume &bv) {
20 core::RigidBody rb(rbi);
21 algebra::Rotation3D rot = algebra::get_random_rotation_3d();
22 algebra::Vector3D trans = algebra::get_random_vector_in(bv);
23 algebra::Transformation3D tr(rot, trans);
24 algebra::ReferenceFrame3D rf(tr);
25 rb.set_reference_frame(rf);
26}
27
28/** Randomize the positions of a set of particles within a bounding
29 volume. Rigid bodies have their orientation randomized too.
30*/
31template <class ParticlesList, class BoundingVolume>
32void randomize_particles(const ParticlesList &ps, const BoundingVolume &bv) {
33 for (unsigned int i = 0; i < ps.size(); ++i) {
34 core::XYZ d(ps[i]);
35 if (d.get_coordinates_are_optimized()) {
36 if (core::RigidBody::get_is_setup(ps[i])) {
37 randomize_rigid_body(ps[i], bv);
38 } else {
39 d.set_coordinates(algebra::get_random_vector_in(bv));
40 }
41 } else if (core::RigidMember::get_is_setup(ps[i])) {
42 /* since this is unlikely to be speed critical, don't bother
43 to check if we have randomized it already.*/
44 randomize_rigid_body(core::RigidMember(ps[i]).get_rigid_body(), bv);
45 }
46 }
47}
48
49IMPEXAMPLE_END_NAMESPACE
50
51#endif /* IMPEXAMPLE_RANDOMIZING_H */
A decorator for a particle with x,y,z coordinates.
Definition XYZ.h:30
VectorD< D > get_random_vector_in(const BoundingBoxD< D > &bb)
Generate a random vector in a box with uniform density.
void randomize_particles(const ParticlesList &ps, const BoundingVolume &bv)
Definition randomizing.h:32
functionality for defining rigid bodies
Functions to generate vectors.