9 #ifndef IMPKERNEL_MODEL_H
10 #define IMPKERNEL_MODEL_H
12 #include <IMP/kernel_config.h>
22 #include "internal/AttributeTable.h"
23 #include "internal/attribute_tables.h"
24 #include "internal/moved_particles_cache.h"
27 #include <boost/unordered_map.hpp>
28 #include <boost/unordered_set.hpp>
30 #include <boost/iterator/transform_iterator.hpp>
31 #include <boost/iterator/filter_iterator.hpp>
35 IMPKERNEL_BEGIN_NAMESPACE
41 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
48 COMPUTING_DEPENDENCIES
74 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
76 public internal::Masks,
79 public internal::FloatAttributeTable,
80 public internal::StringAttributeTable,
81 public internal::IntAttributeTable,
82 public internal::ObjectAttributeTable,
83 public internal::WeakObjectAttributeTable,
84 public internal::IntsAttributeTable,
85 public internal::FloatsAttributeTable,
86 public internal::ObjectsAttributeTable,
87 public internal::ParticleAttributeTable,
88 public internal::ParticlesAttributeTable
96 typedef boost::unordered_map<const ModelObject *, NodeInfo>
DependencyGraph;
97 DependencyGraph dependency_graph_;
98 boost::unordered_set<const ModelObject *> no_dependencies_;
99 boost::unordered_map<const ModelObject *, ScoreStatesTemp>
100 required_score_states_;
103 boost::unordered_map<FloatKey, FloatRange> ranges_;
112 void do_clear_required_score_states(
ModelObject *mo);
113 void do_check_required_score_states(
const ModelObject *mo)
const;
114 void do_check_update_order(
const ScoreState *ss)
const;
115 void do_check_inputs_and_outputs(
const ModelObject *mo)
const;
116 void do_check_readers_and_writers(
const ModelObject *mo)
const;
117 void do_check_not_in_readers_and_writers(
const ModelObject *mo)
const;
121 unsigned age_counter_;
125 unsigned dependencies_age_;
128 internal::MovedParticlesRestraintCache moved_particles_restraint_cache_;
130 internal::MovedParticlesParticleCache moved_particles_particle_cache_;
132 unsigned moved_particles_cache_age_;
135 void increase_age() {
137 if (age_counter_ == 0) {
142 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
149 internal::Stage cur_stage_;
152 const std::set<Restraint *> &get_dependent_restraints(
ParticleIndex pi) {
153 return moved_particles_restraint_cache_.get_dependent_restraints(pi);
157 const std::set<ParticleIndex> &get_dependent_particles(
ParticleIndex pi) {
158 return moved_particles_particle_cache_.get_dependent_particles(pi);
163 bool do_get_has_dependencies(
const ModelObject *mo)
const {
164 return no_dependencies_.find(mo) == no_dependencies_.end();
166 void do_set_has_dependencies(
const ModelObject *mo,
bool tf);
167 void do_set_has_all_dependencies(
bool tf);
169 void validate_computed_derivatives()
const {}
170 void set_has_all_dependencies(
bool tf);
171 bool get_has_all_dependencies()
const;
172 void check_dependency_invariants()
const;
173 void check_dependency_invariants(
const ModelObject *mo)
const;
180 internal::Stage get_stage()
const {
return cur_stage_; }
182 static void do_remove_score_state(
ScoreState *obj);
185 bool do_get_has_required_score_states(
const ModelObject *mo)
const;
186 void do_set_has_required_score_states(
ModelObject *mo,
bool tf);
190 "Doesn't have score states");
191 return required_score_states_.find(mo)->second;
198 Model(std::string name =
"Model %1%");
201 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
202 IMP_MODEL_IMPORT(internal::FloatAttributeTable);
203 IMP_MODEL_IMPORT(internal::StringAttributeTable);
204 IMP_MODEL_IMPORT(internal::IntAttributeTable);
205 IMP_MODEL_IMPORT(internal::ObjectAttributeTable);
206 IMP_MODEL_IMPORT(internal::WeakObjectAttributeTable);
207 IMP_MODEL_IMPORT(internal::IntsAttributeTable);
208 IMP_MODEL_IMPORT(internal::FloatsAttributeTable);
209 IMP_MODEL_IMPORT(internal::ObjectsAttributeTable);
210 IMP_MODEL_IMPORT(internal::ParticleAttributeTable);
211 IMP_MODEL_IMPORT(internal::ParticlesAttributeTable);
239 do_remove_score_state(obj));
264 void add_attribute(TypeKey attribute_key,
ParticleIndex particle, Type value);
268 void remove_attribute(TypeKey attribute_key,
ParticleIndex particle);
271 bool get_has_attribute(TypeKey attribute_key,
ParticleIndex particle)
const;
275 void set_attribute(TypeKey attribute_key,
ParticleIndex particle, Type value);
279 Type get_attribute(TypeKey attribute_key,
ParticleIndex particle);
292 void add_cache_attribute(TypeKey attribute_key,
ParticleIndex particle,
297 void set_is_optimized(TypeKey attribute_key,
ParticleIndex particle,
303 #define IMP_MODEL_ATTRIBUTE_METHODS(Type, Value) \
304 void add_attribute(Type##Key attribute_key, ParticleIndex particle, \
306 void remove_attribute(Type##Key attribute_key, ParticleIndex particle); \
307 bool get_has_attribute(Type##Key attribute_key, \
308 ParticleIndex particle) const; \
309 void set_attribute(Type##Key attribute_key, ParticleIndex particle, \
311 Value get_attribute(Type##Key attribute_key, ParticleIndex particle); \
312 void add_cache_attribute(Type##Key attribute_key, ParticleIndex particle, \
316 IMP_MODEL_ATTRIBUTE_METHODS(
Int,
Int);
318 IMP_MODEL_ATTRIBUTE_METHODS(
Ints,
Ints);
323 IMP_MODEL_ATTRIBUTE_METHODS(WeakObject,
Object *);
332 return particle_index_[p];
337 if (particle_index_.size() <= get_as_unsigned_int(p))
return false;
338 return particle_index_[p];
365 bool get_has_data(
ModelKey mk)
const;
403 if (trigger_age_.size() > tk.get_index()) {
404 return trigger_age_[tk.get_index()];
412 if (tk.get_index() >= trigger_age_.size()) {
413 trigger_age_.resize(tk.get_index() + 1, 0);
415 trigger_age_[tk.get_index()] = age_counter_;
428 #if !defined(IMP_DOXYGEN)
433 IMPKERNEL_END_NAMESPACE
Particle * get_particle(ParticleIndex p) const
Get the particle from an index.
Used to hold a set of related restraints.
boost::graph DependencyGraph
Directed graph on the interactions between the various objects in the model.
The base class for undecorators.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
void add_particle(RMF::FileHandle fh, Particle *hs)
Macros to help in defining tuple classes.
virtual void clear_caches()
unsigned get_dependencies_updated()
Get the model age when ModelObject dependencies were last changed, or 0.
unsigned get_age()
Get the current 'model time'.
bool get_has_particle(ParticleIndex p) const
Check whether a given particle index exists.
Macros to define containers of objects.
unsigned get_trigger_last_updated(TriggerKey tk)
Get the time when the given trigger was last updated, or 0.
Class for storing model, its restraints, constraints, and particles.
Base class for objects in a Model that depend on other objects.
virtual void do_destroy()
Common base class for heavy weight IMP objects.
ParticleIndexes get_particle_indexes(ParticlesTemp const &particles)
ScoreStates maintain invariants in the Model.
Implements a vector tied to a particular index of type Index<Tag>.
Base class for objects in a Model that depend on other objects.
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
A nullptr-initialized pointer to an IMP Object.
A shared base class to help in debugging and things.
Represents a scoring function on the model.
double Float
Basic floating-point value (could be float, double...)
Class to handle individual particles of a Model object.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Abstract base class for all restraints.
int Int
Basic integer value.
void set_trigger_updated(TriggerKey tk)
Update the given trigger.
std::string String
Basic string value.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Class for adding derivatives from restraints to the model.