IMP logo
IMP Reference Guide  2.20.1
The Integrative Modeling Platform
TransformMover.h
Go to the documentation of this file.
1 /**
2  * \file IMP/pmi/TransformMover.h
3  * \brief A mover that transforms a rigid body
4  *
5  * Copyright 2007-2023 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPPMI_TRANSFORM_MOVER_H
10 #define IMPPMI_TRANSFORM_MOVER_H
11 
12 #include <IMP/pmi/pmi_config.h>
13 #include <IMP/core/MonteCarlo.h>
15 #include <IMP/algebra/Vector3D.h>
17 #include <IMP/SingletonContainer.h>
18 #include <IMP/core/rigid_bodies.h>
19 #include <IMP/core/XYZ.h>
20 #include <cereal/access.hpp>
21 #include <cereal/types/base_class.hpp>
22 
23 IMPPMI_BEGIN_NAMESPACE
24 
25 //! Modify the transformation of a rigid body
26 /** The transformation of a rigid body is moved in a ball of given
27  size. The probability distribution is uniform over the ball.
28  \see MonteCarlo
29  */
30 class IMPPMIEXPORT TransformMover : public IMP::core::MonteCarloMover {
31  algebra::Transformation3D last_transformation_;
32  Float max_translation_;
33  Float max_angle_;
34  IMP::ParticleIndex p1i_;
35  IMP::ParticleIndex p2i_;
36  IMP::ParticleIndexes pixyzs_;
37  IMP::ParticleIndexes pirbs_;
45  unsigned int called_;
46  unsigned int not_accepted_;
47  unsigned int constr_;
48 
49  friend class cereal::access;
50  template<class Archive> void serialize(Archive &ar) {
51  ar(cereal::base_class<core::MonteCarloMover>(this),
52  last_transformation_, max_translation_, max_angle_, p1i_, p2i_,
53  pixyzs_, pirbs_, pis_, t_, c_, rbts_, xyzs_, axis_, tt_, called_,
54  not_accepted_, constr_);
55  }
57 
58  IMP::algebra::Vector3D get_center(){
59  Float x=0;
60  Float y=0;
61  Float z=0;
62  unsigned int nelements=0;
63  for (unsigned int i=0;i<pixyzs_.size();i++) {
64  core::XYZ d(get_model(), pixyzs_[i]);
66  x=x+xyz[0];
67  y=y+xyz[1];
68  z=z+xyz[2];
69  nelements++;
70  }
71 
72  for (unsigned int i=0;i<pirbs_.size();i++){
73  core::RigidBody rb(get_model(), pirbs_[i]);
74  algebra::Vector3D xyz=rb.get_coordinates();
75  unsigned int nparticles=rb.get_number_of_members();
76  x=x+xyz[0]*float(nparticles);
77  y=y+xyz[1]*float(nparticles);
78  z=z+xyz[2]*float(nparticles);
79  nelements=nelements+nparticles;
80  }
81 
82  algebra::Vector3D center;
83  center[0]=x/float(nelements);
84  center[1]=y/float(nelements);
85  center[2]=z/float(nelements);
86  return center;
87  }
88 
89  public:
90  TransformMover(Model *m, Float max_translation, Float max_rotation);
91 
93  Float max_translation, Float max_rotation);
94 
97  Float max_translation, Float max_rotation);
98 
99  TransformMover() {}
100 
101  void add_xyz_particle(IMP::ParticleIndexAdaptor pi) {
102  if (core::RigidBody::get_is_setup(get_model(), pi)) {
103  pirbs_.push_back(pi);
104  pis_.push_back(pi);
105  } else {
106  pixyzs_.push_back(pi);
107  pis_.push_back(pi);
108  }
109  }
110 
111  void add_rigid_body_particle(IMP::ParticleIndexAdaptor pi) {
112  pirbs_.push_back(pi);
113  pis_.push_back(pi);
114  }
115 
116  void set_maximum_translation(Float mt) {
117  IMP_USAGE_CHECK(mt > 0, "Max translation must be positive");
118  max_translation_ = mt;
119  }
120 
121  void set_maximum_rotation(Float mr) {
122  IMP_USAGE_CHECK(mr > 0, "Max rotation must be positive");
123  max_angle_ = mr;
124  }
125 
126  Float get_maximum_translation() const { return max_translation_; }
127 
128  Float get_maximum_rotation() const { return max_angle_; }
129 
130  IMP::algebra::Transformation3D get_last_transformation() const { return tt_; }
131 
132  protected:
133  virtual ModelObjectsTemp do_get_inputs() const override;
134  virtual core::MonteCarloMoverResult do_propose() override;
135  virtual void do_reject() override;
137 };
138 
139 IMPPMI_END_NAMESPACE
140 
141 #endif /* IMPPMI_TRANSFORM_MOVER_H */
Simple 3D transformation class.
A container for Singletons.
Simple Monte Carlo optimizer.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Take Decorator, Particle or ParticleIndex.
virtual void do_reject()=0
Implement reset_proposed_move()
Return value of the MonteCarloMover::propose() function.
Simple XYZ decorator.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
A base class for classes which perturb particles.
functionality for defining rigid bodies
The base class for movers for Monte Carlo optimization.
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
Definition: object_macros.h:95
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
virtual MonteCarloMoverResult do_propose()=0
Implement propose_move()
const algebra::Vector3D & get_coordinates() const
Convert it to a vector.
Definition: XYZ.h:109
Modify the transformation of a rigid body.
Simple 3D transformation class.
VectorD< 3 > Vector3D
Definition: VectorD.h:425
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:19
Simple 3D vector class.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168
A decorator for a rigid body.
Definition: rigid_bodies.h:82
virtual ModelObjectsTemp do_get_inputs() const =0