IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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-2025 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
20IMPCORE_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 */
26class 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] m The model containing the particles.
57 \param[in] pis The set of particles to perturb.
58 \param[in] vars The variables to use (normally the keys for x,y,z)
59 \param[in] radius The radius deviation to use.
60 */
61 BallMover(Model *m, const ParticleIndexes &pis, const FloatKeys &vars,
62 Float radius);
63
64 //! Move the x,y,z coordinates of pis within a ball of specified radius
65 /** The x,y,z coordinates of each particle are perturbed within a ball.
66 \param[in] m The model containing the particles.
67 \param[in] pis The set of particles to perturb.
68 \param[in] radius The radius deviation to use.
69 */
70 BallMover(Model *m, const ParticleIndexes &pis, Float radius);
71
72 BallMover() {}
73
74 void set_radius(Float radius) {
75 IMP_ALWAYS_CHECK(radius > 0, "The radius must be positive",
77 radius_ = radius;
78 }
79
80 Float get_radius() const { return radius_; }
81
82 ParticleIndexes get_indexes() const { return pis_; }
83 FloatKeys get_keys() const { return keys_; }
84
85 protected:
86 virtual ModelObjectsTemp do_get_inputs() const override;
87
88 //! Move particle attributes within a ball, as specified in constructor
90
91 //! Restore original attributes from before do_propose()
92 virtual void do_reject() override;
94};
95
96IMPCORE_END_NAMESPACE
97
98#endif /* IMPCORE_BALL_MOVER_H */
The base class for movers for Monte Carlo optimization.
Basic types used by IMP.
#define IMP_ALWAYS_CHECK(condition, message, exception_name)
Throw an exception if a check fails.
An exception for an invalid value being passed to IMP.
Definition exception.h:136
BallMover(Model *m, ParticleIndex pi, double radius)
Move the x,y,z coordinates of pi within a ball of specified radius.
BallMover(Model *m, const ParticleIndexes &pis, const FloatKeys &vars, Float radius)
Move specified variables of particles within a ball of specified radius.
BallMover(Model *m, const ParticleIndexes &pis, Float radius)
Move the x,y,z coordinates of pis within a ball of specified radius.
virtual ModelObjectsTemp do_get_inputs() const override
virtual void do_reject() override
Restore original attributes from before do_propose().
BallMover(Model *m, ParticleIndex pi, const FloatKeys &vars, double radius)
Move specified variables of particle pi within a ball of specified radius.
virtual MonteCarloMoverResult do_propose() override
Move particle attributes within a ball, as specified in constructor.
Exception definitions and assertions.
Index< ParticleIndexTag > ParticleIndex
Definition base_types.h:196
Vector< VectorD<-1 > > VectorKDs
Definition VectorD.h:425
double Float
Basic floating-point value (could be float, double...).
Definition types.h:19
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Definition base_types.h:199
IMP::Vector< FloatKey > FloatKeys
Definition base_types.h:33
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition base_types.h:122
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Return value of the MonteCarloMover::propose() function.