IMP logo
IMP Reference Guide  2.14.0
The Integrative Modeling Platform
RigidBodyTunneler.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/RigidBodyTunneler.h
3  * \brief A mover that transform a rigid body
4  *
5  * Copyright 2007-2020 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPCORE_RIGID_BODY_TUNNELER_H
10 #define IMPCORE_RIGID_BODY_TUNNELER_H
11 
12 #include <IMP/core/core_config.h>
13 #include "MonteCarlo.h"
14 #include "MonteCarloMover.h"
15 #include <IMP/core/rigid_bodies.h>
16 #include <IMP/core/XYZ.h>
17 #include <IMP/core/internal/tunneler_helpers.h>
18 #include <Eigen/Dense>
19 #include <Eigen/Geometry>
20 #include <iostream>
21 #include <boost/ptr_container/ptr_vector.hpp>
22 
23 IMPCORE_BEGIN_NAMESPACE
24 
25 //! Modify the transformation of a rigid body
26 /** Provided a number of entry points, this mover will propose random
27  * translations of the rigid body from the closest entry point to a randomly
28  * chosen other one. Moves that do not end up in the target exit area will be
29  * dropped. This way of moving thus satisfies detailed balance. Entry points are
30  * relative to the center of the provided reference rigid body.
31  *
32  * The procedure is as follows. Suppose we are at x.
33  * pick closest entry point to x: k
34  * do
35  * pick random other entry point if one is still available: l
36  * compute new position y by applying to x the transform that maps k to l
37  * while (closest entry point to y is not l)
38  * if (closest entry point to y is l)
39  * propose y as move
40  * else
41  * do nothing
42  *
43  * \see RigidBodyMover
44  * \see MonteCarlo
45  */
46 class IMPCOREEXPORT RigidBodyTunneler : public MonteCarloMover {
47 
48  public:
49  /** Constructor
50  * \param m the model
51  * \param pis the rigid bodies to move, in order
52  * \param ref the RigidBody reference
53  * \param k the weight when calculating distances
54  * The squared distance between two coordinates is
55  * \f$d^2_\text{eucl}(COM1,COM2) + k*d^2_\text{quat}(Q1,Q2)\f$
56  * If you want to weight rotation differences at the same level as
57  * translational ones, pick \f$k \simeq d_\text{max}/\pi\f$ where
58  * \f$d_\text{max}\f$ is the largest translational difference to be expected.
59  * \param move_probability the prior probability to actually
60  * move somewhere else
61  */
63  ParticleIndex ref, double k,
64  double move_probability = 1.);
65 
66  //! add entry point
67  /** each entry point is a list of coordinates that matches the number of rigid
68  * bodies in pis (see constructor)
69  * If there are N rigid bodies in pis, then an entry point is
70  * - 3N floats, representing the x,y,z coordinates of the
71  * centroid of each of the N rigid bodies
72  * - 4N floats, corresponding to the N rotational quaternions of the rbs
73  * Coordinates are all relative to the reference, i.e. for which the centroid
74  * is at the origin and the rotation is identity.
75  * TODO: If an entry point should be indifferent of one rigid body, one
76  * centroid or one quaternion, the corresponding floats should be set to zero.
77  */
78  void add_entry_point(Floats fl);
79 
80  /// Statistics
81  void reset_stats();
82  unsigned get_number_of_rejected_moves() const { return num_rejected_; }
83  unsigned get_number_of_proposed_moves() const { return num_proposed_; }
84  unsigned get_number_of_impossible_moves() const { return num_impossible_; }
85  unsigned get_number_of_calls() const { return num_calls_; }
86 
87  //! returns center of mass and quaternion of rotation wrt ref
88  static Floats get_reduced_coordinates(Model* m,
89  ParticleIndex target,
90  ParticleIndex ref);
91 
92  //! returns center of mass and quaternion of rotation of pi
93  static Floats get_reduced_coordinates(Model* m,
94  ParticleIndex pi);
95 
96  /// sets rigid body coordinates in the reference frame of ref
97  static void set_reduced_coordinates(Model* m,
98  ParticleIndex target,
99  ParticleIndex ref,
100  Floats coords);
101 
102  protected:
105  virtual void do_reject() IMP_OVERRIDE;
107 
108  private:
109  unsigned get_closest_entry_point(const internal::Coord& x) const;
110 
111  private:
112  ParticleIndexes pis_;
113  ParticleIndex ref_;
114  double k_, move_probability_;
115  unsigned num_calls_, num_proposed_, num_rejected_, num_impossible_;
116  boost::ptr_vector<internal::Transformer> last_transformations_;
117  std::vector<internal::Coord> entries_;
118 };
119 
120 IMPCORE_END_NAMESPACE
121 
122 #endif /* IMPCORE_RIGID_BODY_TUNNELER_H */
Simple Monte Carlo optimizer.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
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:72
A base class for classes which perturb particles.
functionality for defining rigid bodies
The base class for movers for Monte Carlo optimization.
virtual MonteCarloMoverResult do_propose()=0
Implement propose_move()
Modify the transformation of a rigid body.
virtual ModelObjectsTemp do_get_inputs() const =0
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.