IMP logo
IMP Reference Guide  2.20.2
The Integrative Modeling Platform
core/BallMover.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/BallMover.h
3  * \brief A modifier which variables within a ball.
4  *
5  * Copyright 2007-2023 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPCORE_BALL_MOVER_H
10 #define IMPCORE_BALL_MOVER_H
11 
12 #include <IMP/core/core_config.h>
13 #include <IMP/base_types.h>
14 #include <IMP/exception.h>
15 #include "MonteCarloMover.h"
16 #include <cereal/access.hpp>
17 #include <cereal/types/base_class.hpp>
18 #include <cereal/types/polymorphic.hpp>
19 
20 IMPCORE_BEGIN_NAMESPACE
21 
22 //! Move continuous particle variables by perturbing them within a ball.
23 /** The variables are perturbed within a ball of the given radius.
24  \see MonteCarlo
25  */
26 class IMPCOREEXPORT BallMover : public MonteCarloMover {
27  ParticleIndexes pis_;
28  FloatKeys keys_;
29  double radius_;
30  algebra::VectorKDs originals_;
31 
32  friend class cereal::access;
33 
34  template<class Archive> void serialize(Archive &ar) {
35  ar(cereal::base_class<MonteCarloMover>(this),
36  pis_, keys_, radius_, originals_);
37  }
39 
40  void initialize(ParticleIndexes pis, FloatKeys keys, double radius);
41 
42  public:
43  //! Move specified variables of particle pi within a ball of specified radius
44  /** Construct a mover that in each move, perturbs the specified
45  variables (attributes) of particle pi in model m, within a ball
46  of specified radius, whose dimensionality is the total number of
47  attributes.
48  */
49  BallMover(Model *m, ParticleIndex pi, const FloatKeys &vars,
50  double radius);
51 
52  //! Move the x,y,z coordinates of pi within a ball of specified radius
53  BallMover(Model *m, ParticleIndex pi, double radius);
54 
55  //! Move specified variables of particles within a ball of specified radius
56  /** \param[in] pis The set of particles to perturb.
57  \param[in] vars The variables to use (normally the keys for x,y,z)
58  \param[in] radius The radius deviation to use.
59  */
60  BallMover(Model *m, const ParticleIndexes &pis, const FloatKeys &vars,
61  Float radius);
62 
63  //! Move the x,y,z coordinates of pis within a ball of specified radius
64  /** The x,y,z coordinates of each particle are perturbed within a ball.
65  \param[in] pis The set of particles to perturb.
66  \param[in] radius The radius deviation to use.
67  */
68  BallMover(Model *m, const ParticleIndexes &pis, Float radius);
69 
70  BallMover() {}
71 
72  void set_radius(Float radius) {
73  IMP_ALWAYS_CHECK(radius > 0, "The radius must be positive",
75  radius_ = radius;
76  }
77 
78  Float get_radius() const { return radius_; }
79 
80  protected:
81  virtual ModelObjectsTemp do_get_inputs() const override;
82 
83  //! Move particle attributes within a ball, as specified in constructor
84  virtual MonteCarloMoverResult do_propose() override;
85 
86  //! Restore original attributes from before do_propose()
87  virtual void do_reject() override;
89 };
90 
91 IMPCORE_END_NAMESPACE
92 
93 #endif /* IMPCORE_BALL_MOVER_H */
Basic types used by IMP.
#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.
Move continuous particle variables by perturbing them within a ball.
Exception definitions and assertions.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
A base class for classes which perturb particles.
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
virtual MonteCarloMoverResult do_propose()=0
Implement propose_move()
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:19
#define IMP_ALWAYS_CHECK(condition, message, exception_name)
Throw an exception if a check fails.
Definition: check_macros.h:61
An exception for an invalid value being passed to IMP.
Definition: exception.h:136
virtual ModelObjectsTemp do_get_inputs() const =0