10 #ifndef IMPKERNEL_DECLARE_MODEL_H
11 #define IMPKERNEL_DECLARE_MODEL_H
13 #include <IMP/kernel/kernel_config.h>
23 #include "internal/AttributeTable.h"
24 #include "internal/attribute_tables.h"
31 #include <boost/iterator/transform_iterator.hpp>
32 #include <boost/iterator/filter_iterator.hpp>
38 IMPKERNEL_BEGIN_NAMESPACE
43 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
45 enum Stage {NOT_EVALUATING, BEFORE_EVALUATING, EVALUATING, AFTER_EVALUATING,
46 COMPUTING_DEPENDENCIES};
54 double, minimum_score,
55 double, maximum_score,
56 double, average_score,
58 double, average_time,);
86 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
88 public internal::Masks,
90 public internal::FloatAttributeTable,
91 public internal::StringAttributeTable,
92 public internal::IntAttributeTable,
93 public internal::ObjectAttributeTable,
94 public internal::WeakObjectAttributeTable,
95 public internal::IntsAttributeTable,
96 public internal::ObjectsAttributeTable,
97 public internal::ParticleAttributeTable,
98 public internal::ParticlesAttributeTable
102 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
103 IMP_MODEL_IMPORT(internal::FloatAttributeTable);
104 IMP_MODEL_IMPORT(internal::StringAttributeTable);
105 IMP_MODEL_IMPORT(internal::IntAttributeTable);
106 IMP_MODEL_IMPORT(internal::ObjectAttributeTable);
107 IMP_MODEL_IMPORT(internal::WeakObjectAttributeTable);
108 IMP_MODEL_IMPORT(internal::IntsAttributeTable);
109 IMP_MODEL_IMPORT(internal::ObjectsAttributeTable);
110 IMP_MODEL_IMPORT(internal::ParticleAttributeTable);
111 IMP_MODEL_IMPORT(internal::ParticlesAttributeTable);
115 internal::FloatAttributeTable::clear_caches(pi);
116 internal::StringAttributeTable::clear_caches(pi);
117 internal::IntAttributeTable::clear_caches(pi);
118 internal::ObjectAttributeTable::clear_caches(pi);
119 internal::WeakObjectAttributeTable::clear_caches(pi);
120 internal::IntsAttributeTable::clear_caches(pi);
121 internal::ObjectsAttributeTable::clear_caches(pi);
122 internal::ParticleAttributeTable::clear_caches(pi);
123 internal::ParticlesAttributeTable::clear_caches(pi);
129 double total_time_after_;
135 Statistics(): total_time_(0), total_time_after_(0),
136 calls_(0), total_value_(0),
137 min_value_(std::numeric_limits<double>::max()),
138 max_value_(-std::numeric_limits<double>::max()),
142 mutable base::map<base::Object*, Statistics> stats_data_;
145 base::map<FloatKey, FloatRange> ranges_;
146 ParticleIndexes free_particles_;
147 unsigned int next_particle_;
148 base::IndexVector<ParticleIndexTag, base::Pointer<Particle> > particle_index_;
149 base::IndexVector<ParticleIndexTag, Undecorators > undecorators_index_;
150 base::Vector<base::OwnerPointer<base::Object> > model_data_;
151 bool dependencies_dirty_;
153 DependencyGraphVertexIndex dependency_graph_index_;
154 base::map<ModelObject*, ScoreStatesTemp> required_score_states_;
155 void compute_required_score_states();
156 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
160 void validate_computed_derivatives()
const{}
161 void compute_dependencies();
162 internal::Stage cur_stage_;
163 unsigned int eval_count_;
164 bool has_good_score_;
165 void before_evaluate(
const ScoreStatesTemp &states);
166 void after_evaluate(
const ScoreStatesTemp &states,
bool calc_derivs);
168 bool gather_statistics_;
170 void add_to_restraint_evaluate(
Restraint *r,
double t,
double score)
const;
172 internal::Stage get_stage()
const {
175 unsigned int get_evaluation()
const {
177 "Can only call get_evaluation() during evaluation");
180 void add_particle_internal(
Particle *p,
bool set_name);
185 void show_it(std::ostream &out)
const;
187 void add_to_update_before_time(
ScoreState *s,
double t)
const;
188 void add_to_update_after_time(
ScoreState *s,
double t)
const;
192 RestraintsTemp scoring_restraints_;
193 ScoreStatesTemp ordered_score_states_;
197 Model(std::string name=
"Model %1%");
204 const DependencyGraphVertexIndex& get_dependency_graph_vertex_index();
228 "The set of score states cannot be changed during"
230 obj->set_model(
this);
231 obj->set_was_used(
true);
235 base::set<ScoreState*> in(score_states_begin(),
238 "Score state already in model "
242 {obj->set_model(
nullptr);});
247 #if !defined(IMP_DOXYGEN)
248 ModelObjectsTemp get_optimized_particles()
const;
252 bool get_has_dependencies()
const;
253 double get_maximum_score(
Restraint *r)
const;
254 void set_maximum_score(
Restraint *r,
double s);
255 void set_maximum_score(
double s);
256 double get_maximum_score()
const;
262 double evaluate(
bool tf,
bool warn=
true);
306 =
NO_MAX) const IMP_OVERRIDE;
323 void clear_all_statistics();
324 void set_gather_statistics(
bool tf);
325 bool get_gather_statistics()
const {
return gather_statistics_;}
326 void show_all_statistics(std::ostream &out=std::cout)
const;
327 void show_restraint_time_statistics(std::ostream &out=std::cout)
const;
328 void show_restraint_score_statistics(std::ostream &out=std::cout)
const;
330 void show_score_state_time_statistics(std::ostream &out=std::cout)
const;
341 void add_attribute(TypeKey attribute_key,
ParticleIndex particle, Type value);
344 void remove_attribute(TypeKey attribute_key,
ParticleIndex particle);
346 bool get_has_attribute(TypeKey attribute_key,
ParticleIndex particle)
const;
349 void set_attribute(TypeKey attribute_key,
ParticleIndex particle, Type value);
352 Type get_attribute(TypeKey attribute_key,
ParticleIndex particle);
365 void add_cache_attribute(TypeKey attribute_key,
ParticleIndex particle,
371 void set_is_optimized(TypeKey attribute_key,
ParticleIndex particle,
378 #define IMP_MODEL_ATTRIBUTE_METHODS(Type, Value) \
379 void add_attribute(Type##Key attribute_key, \
380 ParticleIndex particle, Value value); \
381 void remove_attribute(Type##Key attribute_key, \
382 ParticleIndex particle); \
383 bool get_has_attribute(Type##Key attribute_key, \
384 ParticleIndex particle) const; \
385 void set_attribute(Type##Key attribute_key, \
386 ParticleIndex particle, Value value); \
387 Value get_attribute(Type##Key attribute_key, \
388 ParticleIndex particle); \
389 void add_cache_attribute(Type##Key attribute_key, \
390 ParticleIndex particle, \
394 IMP_MODEL_ATTRIBUTE_METHODS(
Int,
Int);
395 IMP_MODEL_ATTRIBUTE_METHODS(
Ints,
Ints);
397 IMP_MODEL_ATTRIBUTE_METHODS(ParticleIndexes, ParticleIndexes);
399 IMP_MODEL_ATTRIBUTE_METHODS(Object, Object*);
400 IMP_MODEL_ATTRIBUTE_METHODS(WeakObject, Object*);
408 void add_data(
ModelKey mk, base::Object *o);
409 base::Object *get_data(
ModelKey mk)
const;
411 bool get_has_data(
ModelKey mk)
const;
423 unsigned int get_number_of_particles()
const;
428 class ParticleIterator;
431 bool operator()(
const base::Pointer<Particle>& p) {
435 typedef boost::filter_iterator<NotNull,
436 base::Vector<base::Pointer<Particle> >
437 ::const_iterator> ParticleIterator;
440 ParticleIterator particles_begin()
const;
441 ParticleIterator particles_end()
const;
446 ModelObjectsTemp get_model_objects()
const;
449 IMPKERNEL_END_NAMESPACE