IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
randomize_particles.h
Go to the documentation of this file.
1/**
2 * \file IMP/npctransport/randomize_particles.h
3 * \brief Randomizing particles in a bounding volume
4 *
5 * Copyright 2007-2022 IMP Inventors. All rights reserved.
6 *
7 */
8
9#ifndef IMPNPCTRANSPORT_RANDOMIZING_H
10#define IMPNPCTRANSPORT_RANDOMIZING_H
11
12#include "npctransport_config.h"
14#include <IMP/core/XYZ.h>
16
17IMPNPCTRANSPORT_BEGIN_NAMESPACE
18
19template <class RigidBody, class BoundingVolume>
20void randomize_rigid_body(RigidBody rbi, const BoundingVolume &bv) {
21 core::RigidBody rb(rbi);
22 algebra::Rotation3D rot = algebra::get_random_rotation_3d();
23 algebra::Vector3D trans = algebra::get_random_vector_in(bv);
24 algebra::Transformation3D tr(rot, trans);
25 algebra::ReferenceFrame3D rf(tr);
26 rb.set_reference_frame(rf);
27}
28
29/** Randomize the positions of a set of particles within a bounding
30 volume. Rigid bodies have their orientation randomized too.
31 @note Particles are randomized only if their coordinates are optimizable,
32 that is, get_coordinates_are_optimized() == true)
33*/
34template <class ParticlesList, class BoundingVolume>
35void randomize_particles(const ParticlesList &ps, const BoundingVolume &bv) {
36 for (unsigned int i = 0; i < ps.size(); ++i) {
37 core::XYZ d(ps[i]);
38 if (d.get_coordinates_are_optimized()) {
39 if (core::RigidBody::get_is_setup(ps[i])) {
40 randomize_rigid_body(ps[i], bv);
41 } else {
42 d.set_coordinates(algebra::get_random_vector_in(bv));
43 }
44 } else if (core::RigidMember::get_is_setup(ps[i])) {
45 /* since this is unlikely to be speed critical, don't bother
46 to check if we have randomized it already.*/
47 core::RigidMember rm(ps[i]);
48 core::RigidBody parent_rb = rm.get_rigid_body();
49 if (parent_rb.get_coordinates_are_optimized()) {
50 randomize_rigid_body(parent_rb, bv);
51 }
52 }
53 }
54}
55
56IMPNPCTRANSPORT_END_NAMESPACE
57
58#endif /* IMPNPCTRANSPORT_RANDOMIZING_H */
Simple XYZ decorator.
A decorator for a rigid body.
bool get_coordinates_are_optimized() const
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)
functionality for defining rigid bodies
Functions to generate vectors.