IMP logo
IMP Reference Guide  develop.1a86c4215a,2024/04/24
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"
13 #include <IMP/core/rigid_bodies.h>
14 #include <IMP/core/XYZ.h>
16 
17 IMPNPCTRANSPORT_BEGIN_NAMESPACE
18 
19 template <class RigidBody, class BoundingVolume>
20 void randomize_rigid_body(RigidBody rbi, const BoundingVolume &bv) {
21  core::RigidBody rb(rbi);
22  algebra::Rotation3D rot = algebra::get_random_rotation_3d();
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 */
34 template <class ParticlesList, class BoundingVolume>
35 void randomize_particles(const ParticlesList &ps, const BoundingVolume &bv) {
36  for (unsigned int i = 0; i < ps.size(); ++i) {
37  core::XYZ d(ps[i]);
39  if (core::RigidBody::get_is_setup(ps[i])) {
40  randomize_rigid_body(ps[i], bv);
41  } else {
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 
56 IMPNPCTRANSPORT_END_NAMESPACE
57 
58 #endif /* IMPNPCTRANSPORT_RANDOMIZING_H */
void randomize_particles(const ParticlesList &ps, const BoundingVolume &bv)
bool get_coordinates_are_optimized() const
Get whether the coordinates are optimized.
Definition: XYZ.h:89
Simple XYZ decorator.
Rotation3D get_random_rotation_3d()
Pick a rotation at random from all possible rotations.
void set_coordinates(const algebra::Vector3D &v)
set all coordinates from a vector
Definition: XYZ.h:62
functionality for defining rigid bodies
Functions to generate vectors.
VectorD< D > get_random_vector_in(const BoundingBoxD< D > &bb)
Generate a random vector in a box with uniform density.
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
bool get_coordinates_are_optimized() const
VectorD< 3 > Vector3D
Definition: VectorD.h:408
A decorator for a rigid body.
Definition: rigid_bodies.h:82