The first just fixes some minor errors in the LIST macros.
The second cleans up on the MoverBase, making it use the LIST macros. In
addition, the order of the arguments on the movers has been changed to
make particles last as in the restraints.
Index: kernel/include/IMP/macros.h
===================================================================
--- kernel/include/IMP/macros.h (revision 569)
+++ kernel/include/IMP/macros.h (working copy)
@@ -240,7 +240,7 @@
/** \short Add several objects.
\param[in] obj a vector of pointers
*/ \
- void add_##lcname##s(const std::vector<Ucname*>& obj); \
+ void add_##lcname##s(const std::vector<Data>& obj); \
/** \short Clear the contents of the container */ \
void clear_##lcname##s(); \
/** \short return the number of objects*/ \
@@ -277,7 +277,7 @@
IndexType index= lcname##_vector_.push_back(obj); \
Init_obj; \
Onchanged; \
- if (false) std::cout << index; \
+ if (false) {index=index; obj=obj;}; \
return index; \
} \
void Class::add_##lcname##s(const std::vector<Data> &objs) { \
@@ -288,7 +288,7 @@
Data obj= lcname##_vector_[osz+i]; \
IndexType index(osz+i); \
Init_obj; \
- if (false) std::cout << *obj << index; \
+ if (false) {obj=obj; index=index;} \
} \
Onchanged; \
} \
Index: kernel/include/IMP/optimizers/MoverBase.h
===================================================================
--- kernel/include/IMP/optimizers/MoverBase.h (revision 569)
+++ kernel/include/IMP/optimizers/MoverBase.h (working copy)
@@ -10,6 +10,7 @@
#include "Mover.h"
#include "../Particle.h"
+#include "../macros.h"
#include <vector>
@@ -28,9 +29,6 @@
{
std::vector<Floats> floats_;
std::vector<Ints> ints_;
- FloatKeys fkeys_;
- IntKeys ikeys_;
- Particles ps_;
public:
virtual void accept_move(){}
virtual void reject_move();
@@ -39,59 +37,24 @@
*/
virtual void propose_move(float f);
+ IMP_LIST(public, Particle, particle, Particle*);
+ IMP_LIST(public, FloatKey, float_key, FloatKey);
+ IMP_LIST(public, IntKey, int_key, IntKey);
+
protected:
//! implement this method to propose a move
/** See NormalMover for a simple example.
*/
virtual void generate_move(float f)=0;
- //! Add to the set of particles being controlled
- void add_particles(const Particles &ps) {
- ps_.insert(ps_.end(), ps.begin(), ps.end());
- }
- //! Clear the set of particles being controlled
- void clear_particles() {
- ps_.clear();
- }
-
- //! Get the number of particles
- unsigned int number_of_particles() const {
- return ps_.size();
- }
- Particle *get_particle(unsigned int i) const {
- IMP_check(i< ps_.size(), "Bad index in MoverBase::get_particle",
- IndexException("Particle index out of range in mover base"));
- return ps_[i];
- }
-
- //! Add an attribute
- unsigned int add_key(FloatKey k) {
- fkeys_.push_back(k);
- return fkeys_.size()-1;
- }
- //! Add an attribute
- unsigned int add_key(IntKey k) {
- ikeys_.push_back(k);
- return ikeys_.size()-1;
- }
-
- unsigned int number_of_float_keys() const {return fkeys_.size();}
- unsigned int number_of_int_keys() const {return ikeys_.size();}
-
-
-
//! Get the value of a controlled attribute
/** \param [in] i The index of the particle.
\param [in] j The index of the attribute.
*/
Float get_float(unsigned int i, unsigned int j) const {
- IMP_assert(i < ps_.size(),
- "Out of range controlled attribute in guard");
- IMP_assert(j < fkeys_.size(),
- "Out of range controlled attribute in guard");
- IMP_assert(ps_.size() == floats_.size(),
+ IMP_assert(number_of_particles() == floats_.size(),
"Only call get_float from within generate_proposal");
- return get_particle(i)->get_value(fkeys_[j]);
+ return get_particle(i)->get_value(get_float_key(j));
}
//! Get an int attribute value
@@ -99,23 +62,19 @@
\param [in] j The index of the attribute.
*/
Int get_int(unsigned int i, unsigned int j) const {
- IMP_assert(i < ps_.size(),
- "Out of range controlled attribute in guard");
- IMP_assert(j < ikeys_.size(),
- "Out of range controlled attribute in guard");
- IMP_assert(ps_.size() == ints_.size(),
- "Only call get_float from within generate_proposal");
-
- return get_particle(i)->get_value(ikeys_[j]);
+ IMP_assert(number_of_particles() == ints_.size(),
+ "Only call get_int from within generate_proposal");
+ return get_particle(i)->get_value(get_int_key(j));
}
+
//! Propose a value
/** \param[in] i The index of the particle.
\param[in] j The index of the key
\param[in] t The value to propose
*/
void propose_value(unsigned int i, unsigned int j, Float t) {
- if (get_particle(i)->get_is_optimized(fkeys_[j])) {
- get_particle(i)->set_value(fkeys_[j], t);
+ if (get_particle(i)->get_is_optimized(get_float_key(j))) {
+ get_particle(i)->set_value(get_float_key(j), t);
}
}
//! Propose a value
@@ -124,7 +83,7 @@
\param[in] t The value to propose
*/
void propose_value(unsigned int i, unsigned int j, Int t) {
- get_particle(i)->set_value(ikeys_[j], t);
+ get_particle(i)->set_value(get_int_key(j), t);
}
MoverBase(){}
Index: kernel/include/IMP/optimizers/movers/NormalMover.h
===================================================================
--- kernel/include/IMP/optimizers/movers/NormalMover.h (revision 569)
+++ kernel/include/IMP/optimizers/movers/NormalMover.h (working copy)
@@ -21,16 +21,13 @@
class IMPDLLEXPORT NormalMover :public MoverBase
{
public:
- /** \param[in] ps The particles to perturb.
- \param[in] vars The variables to use (normally the keys for x,y,z)
+ /** \param[in] vars The variables to use (normally the keys for x,y,z)
\param[in] sigma The standard deviation to use.
+ \param[in] ps The particles to perturb.
*/
- NormalMover(const Particles &ps, const FloatKeys &vars,
- Float sigma);
- void set_particles(const Particles &ps) {
- MoverBase::clear_particles();
- MoverBase::add_particles(ps);
- }
+ NormalMover(const FloatKeys &vars,
+ Float sigma, const Particles &ps=Particles());
+
void set_sigma(Float sigma) {
IMP_check(sigma > 0, "Sigma must be positive",
ValueException("Negative sigma"));
Index: kernel/include/IMP/optimizers/movers/BallMover.h
===================================================================
--- kernel/include/IMP/optimizers/movers/BallMover.h (revision 569)
+++ kernel/include/IMP/optimizers/movers/BallMover.h (working copy)
@@ -26,12 +26,12 @@
public:
/** The attributes are perturbed within a pall whose dimensionality is
given by the number of attributes and radius by the given value.
- \param[in] ps The particles to perturb.
\param[in] vars The variables to use (normally the keys for x,y,z)
\param[in] radius The radius deviation to use.
+ \param[in] ps The particles to perturb.
*/
- BallMover(const Particles &ps, const FloatKeys &vars,
- Float radius);
+ BallMover(const FloatKeys &vars,
+ Float radius, const Particles &ps);
//!
void set_radius(Float radius) {
IMP_check(radius > 0, "The radius must be positive",
Index: kernel/src/optimizers/MoverBase.cpp
===================================================================
--- kernel/src/optimizers/MoverBase.cpp (revision 569)
+++ kernel/src/optimizers/MoverBase.cpp (working copy)
@@ -10,21 +10,25 @@
namespace IMP
{
+IMP_LIST_IMPL(MoverBase, Particle, particle, Particle*,,);
+IMP_LIST_IMPL(MoverBase, FloatKey, float_key, FloatKey,,);
+IMP_LIST_IMPL(MoverBase, IntKey, int_key, IntKey,,);
+
void MoverBase::propose_move(float f)
{
- if (!fkeys_.empty()) {
- floats_.resize(number_of_particles(), Floats(fkeys_.size(), 0));
+ if (number_of_float_keys() != 0) {
+ floats_.resize(number_of_particles(), Floats(number_of_float_keys(), 0));
}
- if (!ikeys_.empty()) {
- ints_.resize(number_of_particles(), Ints(ikeys_.size(), 0));
+ if (number_of_int_keys() != 0) {
+ ints_.resize(number_of_particles(), Ints(number_of_int_keys(), 0));
}
for (unsigned int i=0; i< number_of_particles(); ++i) {
Particle *p = get_particle(i);
- for (unsigned int j=0; j< fkeys_.size(); ++j) {
- floats_[i][j]= p->get_value(fkeys_[j]);
+ for (unsigned int j=0; j< number_of_float_keys(); ++j) {
+ floats_[i][j]= p->get_value(get_float_key(j));
}
- for (unsigned int j=0; j< ikeys_.size(); ++j) {
- ints_[i][j]= p->get_value(ikeys_[j]);
+ for (unsigned int j=0; j< number_of_int_keys(); ++j) {
+ ints_[i][j]= p->get_value(get_int_key(j));
}
}
generate_move(f);
@@ -34,11 +38,11 @@
{
for (unsigned int i=0; i< number_of_particles(); ++i) {
Particle *p = get_particle(i);
- for (unsigned int j=0; j< fkeys_.size(); ++j) {
- p->set_value(fkeys_[j], floats_[i][j]);
+ for (unsigned int j=0; j< number_of_float_keys(); ++j) {
+ p->set_value(get_float_key(j), floats_[i][j]);
}
- for (unsigned int j=0; j< ikeys_.size(); ++j) {
- p->set_value(fkeys_[j], floats_[i][j]);
+ for (unsigned int j=0; j< number_of_int_keys(); ++j) {
+ p->set_value(get_int_key(j), ints_[i][j]);
}
}
}
Index: kernel/src/optimizers/movers/NormalMover.cpp
===================================================================
--- kernel/src/optimizers/movers/NormalMover.cpp (revision 569)
+++ kernel/src/optimizers/movers/NormalMover.cpp (working copy)
@@ -13,14 +13,12 @@
namespace IMP
{
-NormalMover::NormalMover(const Particles &pis,
- const FloatKeys &vars,
- Float max)
+NormalMover::NormalMover(const FloatKeys &vars,
+ Float max,
+ const Particles &pis)
{
add_particles(pis);
- for (unsigned int i = 0; i < vars.size(); ++i) {
- add_key(vars[i]);
- }
+ add_float_keys(vars);
set_sigma(max);
}
Index: kernel/src/optimizers/movers/BallMover.cpp
===================================================================
--- kernel/src/optimizers/movers/BallMover.cpp (revision 569)
+++ kernel/src/optimizers/movers/BallMover.cpp (working copy)
@@ -46,14 +46,12 @@
-BallMover::BallMover(const Particles &pis,
- const FloatKeys &vars,
- Float max)
+BallMover::BallMover(const FloatKeys &vars,
+ Float max,
+ const Particles &pis)
{
add_particles(pis);
- for (unsigned int i = 0; i < vars.size(); ++i) {
- add_key(vars[i]);
- }
+ add_float_keys(vars);
set_radius(max);
}