Index: kernel/src/optimizers/MolecularDynamics.cpp =================================================================== --- kernel/src/optimizers/MolecularDynamics.cpp (revision 377) +++ kernel/src/optimizers/MolecularDynamics.cpp (working copy) @@ -46,14 +46,10 @@ particles_.push_back(p); } } + ModelData *md= model.get_model_data(); + unsigned nopt = std::distance(md->optimized_float_indexes_begin(), + md->optimized_float_indexes_end()); - OptFloatIndexIterator opt_value_iter; - unsigned nopt = 0; - opt_value_iter.reset(model.get_model_data()); - while (opt_value_iter.next()) { - nopt++; - } - if (particles_.size() * 3 != nopt) { throw InvalidStateException("Can only do MD on xyz particles"); } Index: kernel/src/optimizers/SteepestDescent.cpp =================================================================== --- kernel/src/optimizers/SteepestDescent.cpp (revision 377) +++ kernel/src/optimizers/SteepestDescent.cpp (working copy) @@ -38,22 +38,15 @@ { std::vector temp_vals; std::vector temp_derivs; - std::vector float_indexes; Float last_score, new_score = 0.0; - ModelData* model_data; + ModelData* model_data = get_model()->get_model_data(); - model_data = get_model()->get_model_data(); - // set up the indexes - int opt_var_cnt = 0; - OptFloatIndexIterator opt_float_iter; - opt_float_iter.reset(model_data); - while (opt_float_iter.next()) { - float_indexes.push_back(opt_float_iter.get()); - opt_var_cnt++; - } + FloatIndexes float_indexes(model_data->optimized_float_indexes_begin(), + model_data->optimized_float_indexes_end()); + int opt_var_cnt = float_indexes.size(); Float current_step_size = step_size_; Index: kernel/src/optimizers/ConjugateGradients.cpp =================================================================== --- kernel/src/optimizers/ConjugateGradients.cpp (revision 377) +++ kernel/src/optimizers/ConjugateGradients.cpp (working copy) @@ -211,20 +211,14 @@ Float ConjugateGradients::optimize(unsigned int max_steps) { - std::vector float_indices; std::vector x, dx; - int n = 0, i; + int i; ModelData* model_data = get_model()->get_model_data(); - OptFloatIndexIterator opt_value_iter; + FloatIndexes float_indices(model_data->optimized_float_indexes_begin(), + model_data->optimized_float_indexes_end()); + int n = float_indices.size(); - opt_value_iter.reset(model_data); - // determine n, the number of degrees of freedom - while (opt_value_iter.next()) { - n++; - float_indices.push_back(opt_value_iter.get()); - } - x.resize(n); dx.resize(n); // get initial state in x(n): Index: kernel/src/Particle.cpp =================================================================== --- kernel/src/Particle.cpp (revision 377) +++ kernel/src/Particle.cpp (working copy) @@ -45,9 +45,6 @@ void Particle::set_is_active(const bool is_active) { is_active_ = is_active; - - // indicate to restraints that a particle's active status may have changed - model_->get_model_data()->set_check_particles_active(true); } Index: kernel/include/IMP/Index.h =================================================================== --- kernel/include/IMP/Index.h (revision 377) +++ kernel/include/IMP/Index.h (working copy) @@ -23,11 +23,17 @@ { public: typedef Index This; - Index(int i): i_(i) { + //! Construct an index from a nonnegative int + Index(unsigned int i): i_(i) { IMP_check(i >= 0, "Index initializer must be positive. " << i << " is not.", ErrorException()); } + //! Construct a default index + /** This can be used as a sentinal value */ Index(): i_(-1) {} + + //! Return an integer for this index + /** The integer is unique within the container */ unsigned int get_index() const { IMP_check(i_ >= 0, "get_index() called on defaultly constructed Index", ErrorException()); @@ -42,7 +48,17 @@ } IMP_COMPARISONS_1(i_) -private: +#ifndef SWIG + //! This should be protected + /** + \note Really we only want this accessible from the iterators in + ModelData, but I can't get that to work. Don't use it. + */ + void operator++() { + ++i_; + } +#endif +protected: bool is_default() const { return i_==-1; } @@ -53,7 +69,6 @@ IMP_OUTPUT_OPERATOR_1(Index) - } // namespace IMP #endif /* __IMP_INDEX_H */ Index: kernel/include/IMP/ModelData.h =================================================================== --- kernel/include/IMP/ModelData.h (revision 377) +++ kernel/include/IMP/ModelData.h (working copy) @@ -8,12 +8,13 @@ #ifndef __IMP_MODEL_DATA_H #define __IMP_MODEL_DATA_H -#include -#include - #include "IMP_config.h" #include "base_types.h" +#include +#include +#include + namespace IMP { @@ -38,28 +39,26 @@ friend class DerivativeAccumulator; friend class std::auto_ptr; - // variables - class FloatData + struct FloatData { - public: Float value_; Float deriv_; int stats_index_; bool is_optimized_; }; - //! variable statistics - /** intended for keeping track of change sizes during optimization - for efficiency issues (e.g. updates of neighborhoods) - */ - class Statistics - { + struct FloatIsOptimized { + const ModelData *m_; public: - Float min_; - Float max_; - Float max_delta_; - Float min_delta_; + FloatIsOptimized(const ModelData *m): m_(m){} + bool operator()(FloatIndex f) const { + return m_->get_is_optimized(f); + } }; + + typedef boost::counting_iterator FloatIndexIterator; + public: @@ -156,7 +155,20 @@ return string_data_[idx.get_index()]; } + typedef boost::filter_iterator OptimizedFloatIndexIterator; + OptimizedFloatIndexIterator optimized_float_indexes_begin() const { + return OptimizedFloatIndexIterator(FloatIsOptimized(this), + FloatIndexIterator(0), + FloatIndexIterator(float_data_.size())); + } + OptimizedFloatIndexIterator optimized_float_indexes_end() const { + return OptimizedFloatIndexIterator(FloatIsOptimized(this), + FloatIndexIterator(float_data_.size()), + FloatIndexIterator(float_data_.size())); + } + void show(std::ostream &out=std::cout) const; protected: ModelData(); @@ -168,14 +180,6 @@ */ void add_to_deriv(const FloatIndex idx, const Float value); - //! used by model to see if restraints need to check their particles - bool check_particles_active() { - return check_particles_active_; - } - void set_check_particles_active(bool check_particles_active) { - check_particles_active_ = check_particles_active; - } - //! particle variables and attributes /** these are stored outside of particles to allow restraints to get access them directly through @@ -185,55 +189,13 @@ //! See float_data_. std::vector int_data_; + //! See float_data_. std::vector string_data_; - - //! float attribute state change statistics associated with a particular - //! name in some subset of particles - std::map stat_indexes_; - //! See stat_indexes_. - std::vector float_stats_; - - //! flag set whenever a particle is activated or deactivated - bool check_particles_active_; }; IMP_OUTPUT_OPERATOR(ModelData); -//! Optimizable variable iterator -/** Returns all optimizable Floats in the ModelData. - */ -class IMPDLLEXPORT OptFloatIndexIterator -{ -public: - OptFloatIndexIterator() {} - - //! Reset the iterator. - /** After the next call to next(), get() will return the first optimizable - Float variable. - \param[in] model_data The model data that is being referenced. - */ - void reset(ModelData* model_data); - - //! Move to the next optimizable Float variable. - /** Check if another optimizable Float variable is available, and if so, - make sure it is called by the next call to get(). - \return True if another optimizable variable is available. - */ - bool next(); - - //! Return the current available optimizable Float variable. - /** Should only be called if next() returned True. - \return the index of the Float variable. - */ - FloatIndex get() const; - -protected: - int cur_; - ModelData* model_data_; -}; - - } // namespace IMP #endif /* __IMP_MODEL_DATA_H */ Index: kernel/src/ModelData.cpp =================================================================== --- kernel/src/ModelData.cpp (revision 377) +++ kernel/src/ModelData.cpp (working copy) @@ -14,7 +14,6 @@ //! Constructor ModelData::ModelData() { - check_particles_active_ = false; } @@ -177,50 +176,4 @@ } } -//! Reset the iterator. -/** After the next call to next(), get() will return the first optimizable - Float variable. - \param[in] model_data The model data that is being referenced. - */ -void OptFloatIndexIterator::reset(ModelData* model_data) -{ - model_data_ = model_data; - cur_ = -1; -} - - -//! Move to the next optimizable Float variable. -/** Check if another optimizable Float variable is available, and if so, - make sure it is called by the next call to get(). - \return True if another optimizable variable is available. - */ -bool OptFloatIndexIterator::next() -{ - FloatIndex fi; - - do { - fi = FloatIndex(++cur_); - if (cur_ >= (int) model_data_->float_data_.size()) { - cur_--; // keep pointing at the last item - return false; - } - - } while (!model_data_->get_is_optimized(fi)); - - return true; -} - - -//! Return the current available optimizable Float variable. -/** Should only be called if next() returned True. - \return the index of the Float variable. - */ -FloatIndex OptFloatIndexIterator::get() const -{ - FloatIndex fi; - - fi = FloatIndex(cur_); - return fi; -} - } // namespace IMP