IMP logo
IMP Reference Guide  develop.5d113ecbfd,2023/06/06
The Integrative Modeling Platform
Model.h
Go to the documentation of this file.
1 /**
2  * \file IMP/Model.h
3  * \brief Storage of a model, its restraints, constraints and particles.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_MODEL_H
10 #define IMPKERNEL_MODEL_H
11 
12 #include <IMP/kernel_config.h>
13 #include "ModelObject.h"
14 #include "ScoringFunction.h"
15 #include "Restraint.h"
16 #include "RestraintSet.h"
17 #include "ScoreState.h"
18 #include "container_macros.h"
19 #include "base_types.h"
20 //#include "Particle.h"
21 #include "Undecorator.h"
22 #include "internal/AttributeTable.h"
23 #include "internal/attribute_tables.h"
24 #include "internal/moved_particles_cache.h"
25 #include "internal/KeyVector.h"
26 #include <IMP/Object.h>
27 #include <IMP/Pointer.h>
28 #include <IMP/internal/IDGenerator.h>
29 #include <boost/unordered_map.hpp>
30 #include <boost/unordered_set.hpp>
31 #include <IMP/tuple_macros.h>
32 #include <boost/iterator/transform_iterator.hpp>
33 #include <boost/iterator/filter_iterator.hpp>
34 #include <cereal/access.hpp>
35 #include <cereal/types/polymorphic.hpp>
36 
37 #include <limits>
38 
39 IMPKERNEL_BEGIN_NAMESPACE
40 
41 class ModelObject;
42 class Undecorator;
43 class Particle;
44 
45 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
46 namespace internal {
47 enum Stage {
48  NOT_EVALUATING,
49  BEFORE_EVALUATING,
50  EVALUATING,
51  AFTER_EVALUATING,
52  COMPUTING_DEPENDENCIES
53 };
54 }
55 #endif
56 
57 class Model;
58 
59 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
60 // This is needed as NodeInfo (below) needs to be showable, and Edges are not
61 inline std::ostream &operator<<(
62  std::ostream &out, const std::set<ModelObject *> &) {
63  out << "(set of ModelObject)";
64  return out;
65 }
66 #endif
67 
68 //! Class for storing model, its restraints, constraints, and particles.
69 /** The Model maintains a standard \imp container for each of Particle,
70  ScoreState and Restraint object types.
71 
72  Each Float attribute has an associated range which reflects the
73  range of values that it is expected to take on during optimization.
74  The optimizer can use these ranges to make the optimization process
75  more efficient. By default, the range estimates are simply the
76  range of values for that attribute in the various particles, but
77  it can be set to another value. For example, an attribute storing
78  an angle could have the range set to (0,PI).
79 
80  The ranges are not enforced; they are just guidelines. In order to
81  enforce ranges, see, for example,
82  IMP::example::ExampleSingletonModifier.
83 
84  \headerfile Model.h "IMP/Model.h"
85  */
86 class IMPKERNELEXPORT Model : public Object
87 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
88  ,
89  public internal::Masks,
90  // The attribute tables provide fast access to
91  // e.g. particle attributes, etc.
92  public internal::FloatAttributeTable,
93  public internal::StringAttributeTable,
94  public internal::IntAttributeTable,
95  public internal::ObjectAttributeTable,
96  public internal::WeakObjectAttributeTable,
97  public internal::IntsAttributeTable,
98  public internal::FloatsAttributeTable,
99  public internal::ObjectsAttributeTable,
100  public internal::ParticleAttributeTable,
101  public internal::ParticlesAttributeTable
102 #endif
103  {
104  typedef std::set<ModelObject *> Edges;
105  // must be up top
106  // we don't want any liveness checks
107  IMP_NAMED_TUPLE_5(NodeInfo, NodeInfos, Edges, inputs, Edges, input_outputs,
108  Edges, outputs, Edges, readers, Edges, writers, );
109  typedef boost::unordered_map<const ModelObject *, NodeInfo> DependencyGraph;
110  DependencyGraph dependency_graph_;
111  boost::unordered_set<const ModelObject *> no_dependencies_;
112  boost::unordered_map<const ModelObject *, ScoreStatesTemp>
113  required_score_states_;
114 
115  // basic representation
116  boost::unordered_map<FloatKey, FloatRange> ranges_;
117 
118  ParticleIndexes free_particles_;
121 
122  internal::KeyVector<ModelKey, PointerMember<Object> > model_data_;
123 
124 #if !defined(IMP_DOXYGEN)
125  // Map unique ID to Model*
126  class ModelMap {
127  std::map<uint32_t, Model*> map_;
128  internal::IDGenerator id_gen_;
129  public:
130  ModelMap() {}
131  uint32_t add_new_model(Model *m);
132  void add_model_with_id(Model *m, uint32_t id);
133  void remove_model(Model *m);
134  Model *get(uint32_t id) const;
135  };
136 
137  static ModelMap model_map_;
138  uint32_t unique_id_;
139 #endif
140 
141  void do_add_dependencies(const ModelObject *mo);
142  void do_clear_required_score_states(ModelObject *mo);
143  void do_check_required_score_states(const ModelObject *mo) const;
144  void do_check_update_order(const ScoreState *ss) const;
145  void do_check_inputs_and_outputs(const ModelObject *mo) const;
146  void do_check_readers_and_writers(const ModelObject *mo) const;
147  void do_check_not_in_readers_and_writers(const ModelObject *mo) const;
148  void do_clear_dependencies(const ModelObject *mo);
149 
150  // used to track time when triggers are activated
151  unsigned age_counter_;
152  // all triggers
153  Vector<unsigned> trigger_age_;
154  // time when dependencies were last changed, or 0
155  unsigned dependencies_age_;
156 
157  // allow skipping updating dependencies_age_ for temporary ModelObjects
158  bool dependencies_saved_;
159  unsigned saved_dependencies_age_;
160  // We don't use ModelObjectsTemp here because these objects might get freed
161  // under us, which would cause WeakPointer to raise an exception
162  std::vector<ModelObject *> mos_added_since_save_, mos_removed_since_save_;
163 
164  // cache of restraints that are affected by each moved particle,
165  // used for evaluate_moved() and related functions
166  internal::MovedParticlesRestraintCache moved_particles_restraint_cache_;
167  // cache of particles that are affected by each moved particle
168  internal::MovedParticlesParticleCache moved_particles_particle_cache_;
169  // time when moved_particles_*_cache_ were last updated, or 0
170  unsigned moved_particles_cache_age_;
171 
172  void register_unique_id();
173 
174  friend class cereal::access;
175 
176  template<class Archive> void serialize(Archive &ar) {
177  ar(cereal::base_class<Object>(this));
178  // We need to get unique_id_ early on read, so that any ModelObjects
179  // that reference it get correctly associated with this model
180  ar(unique_id_);
181  if (std::is_base_of<cereal::detail::InputArchiveBase, Archive>::value) {
182  register_unique_id();
183  }
184  ar(cereal::base_class<internal::FloatAttributeTable>(this),
185  cereal::base_class<internal::StringAttributeTable>(this),
186  cereal::base_class<internal::IntAttributeTable>(this),
187  cereal::base_class<internal::ObjectAttributeTable>(this),
188  cereal::base_class<internal::WeakObjectAttributeTable>(this),
189  cereal::base_class<internal::IntsAttributeTable>(this),
190  cereal::base_class<internal::FloatsAttributeTable>(this),
191  cereal::base_class<internal::ObjectsAttributeTable>(this),
192  cereal::base_class<internal::ParticleAttributeTable>(this),
193  cereal::base_class<internal::ParticlesAttributeTable>(this),
194  free_particles_, model_data_, mutable_access_score_states());
195 
196  if (std::is_base_of<cereal::detail::InputArchiveBase, Archive>::value) {
197  size_t count;
198  free_particles_.clear();
199  ar(count);
200  particle_index_.clear();
201  while(count-- > 0) {
202  std::string name;
203  ar(name);
204  add_particle(name);
205  }
206  ParticleIndexes to_free;
207  ar(to_free);
208  for (auto pi : to_free) {
209  remove_particle(pi);
210  }
211  } else {
212  size_t count = particle_index_.size();
213  ar(count);
214  for (size_t i = 0; i < count; ++i) {
215  std::string name;
216  if (get_has_particle(ParticleIndex(i))) {
217  name = get_particle_name(ParticleIndex(i));
218  }
219  ar(name);
220  }
221  ar(free_particles_);
222  }
223 
224  if (std::is_base_of<cereal::detail::InputArchiveBase, Archive>::value) {
225  // clear caches
226  age_counter_ = 1;
227  trigger_age_.clear();
228  dependencies_age_ = 0;
229  saved_dependencies_age_ = 0;
230  dependencies_saved_ = false;
231  moved_particles_cache_age_ = 0;
232  }
233  }
234 
235  // update model age (can never be zero, even if it wraps)
236  void increase_age() {
237  age_counter_++;
238  if (age_counter_ == 0) {
239  age_counter_ = 1;
240  }
241  }
242 
243  template <class MOType, class MOVector>
244  void do_get_dependent(ModelObject *mo, MOVector &ret) {
245  const auto &node = dependency_graph_.find(mo);
247  "Object " << mo->get_name()
248  << " does not have dependencies.");
249  IMP_INTERNAL_CHECK(node != dependency_graph_.end(),
250  "Node not in dependency_graph.");
251  MOType *r = dynamic_cast<MOType *>(mo);
252  if (r) {
253  ret.push_back(r);
254  }
255  for (ModelObject *cur : node->second.get_outputs()) {
256  do_get_dependent<MOType, MOVector>(cur, ret);
257  }
258  for (ModelObject *cur : node->second.get_readers()) {
259  do_get_dependent<MOType, MOVector>(cur, ret);
260  }
261  }
262 
263 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
264  // things the evaluate template functions need, can't be bothered with friends
265  public:
266 #endif
267  // check more things on the first call
268  bool first_call_;
269  // the stage of evaluation
270  internal::Stage cur_stage_;
271 
272  //! Get all Restraints that depend on the given particle
273  const std::set<Restraint *> &get_dependent_restraints(ParticleIndex pi) {
274  return moved_particles_restraint_cache_.get_dependent_restraints(pi);
275  }
276 
277  //! Get all particles that depend on the given particle
278  const ParticleIndexes &get_dependent_particles(ParticleIndex pi) {
279  return moved_particles_particle_cache_.get_dependent_particles(pi);
280  }
281 
282  ModelObjectsTemp get_dependency_graph_inputs(const ModelObject *mo) const;
283  ModelObjectsTemp get_dependency_graph_outputs(const ModelObject *mo) const;
284  bool do_get_has_dependencies(const ModelObject *mo) const {
285  return no_dependencies_.find(mo) == no_dependencies_.end();
286  }
287  void do_set_has_dependencies(const ModelObject *mo, bool tf);
288  void do_set_has_all_dependencies(bool tf);
289 
290  void validate_computed_derivatives() const {}
291  void set_has_all_dependencies(bool tf);
292  bool get_has_all_dependencies() const;
293  void check_dependency_invariants() const;
294  void check_dependency_invariants(const ModelObject *mo) const;
295  ScoreStatesTemp get_ancestor_score_states(const ModelObject *mo) const;
296  ScoreStatesTemp get_descendent_score_states(const ModelObject *mo) const;
297 
298  void before_evaluate(const ScoreStatesTemp &states);
299  void after_evaluate(const ScoreStatesTemp &states, bool calc_derivs);
300 
301  internal::Stage get_stage() const { return cur_stage_; }
302  ParticleIndex add_particle_internal(Particle *p);
303  static void do_remove_score_state(ScoreState *obj);
304  void do_add_score_state(ScoreState *obj);
305  void do_remove_particle(ParticleIndex pi);
306  bool do_get_has_required_score_states(const ModelObject *mo) const;
307  void do_set_has_required_score_states(ModelObject *mo, bool tf);
308  const ScoreStatesTemp &do_get_required_score_states(const ModelObject *mo)
309  const {
310  IMP_USAGE_CHECK(do_get_has_required_score_states(mo),
311  "Doesn't have score states");
312  return required_score_states_.find(mo)->second;
313  }
314  void do_add_model_object(ModelObject *mo);
315  void do_remove_model_object(ModelObject *mo);
316 
317  public:
318  //! Construct an empty model
319  Model(std::string name = "Model %1%");
320 
321  public:
322 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
323  IMP_MODEL_IMPORT(internal::FloatAttributeTable);
324  IMP_MODEL_IMPORT(internal::StringAttributeTable);
325  IMP_MODEL_IMPORT(internal::IntAttributeTable);
326  IMP_MODEL_IMPORT(internal::ObjectAttributeTable);
327  IMP_MODEL_IMPORT(internal::WeakObjectAttributeTable);
328  IMP_MODEL_IMPORT(internal::IntsAttributeTable);
329  IMP_MODEL_IMPORT(internal::FloatsAttributeTable);
330  IMP_MODEL_IMPORT(internal::ObjectsAttributeTable);
331  IMP_MODEL_IMPORT(internal::ParticleAttributeTable);
332  IMP_MODEL_IMPORT(internal::ParticlesAttributeTable);
333 #endif
334  //! Clear all the cache attributes of a given particle.
335  void clear_particle_caches(ParticleIndex pi);
336 
337  //! Add particle to the model
338  ParticleIndex add_particle(std::string name);
339 
340  //! Get the name of a particle
341  std::string get_particle_name(ParticleIndex pi);
342 
343  //! Add the passed Undecorator to the particle.
344  void add_undecorator(ParticleIndex pi, Undecorator *d);
345 
346 #if !defined(IMP_DOXYGEN)
347  RestraintsTemp get_dependent_restraints_uncached(ParticleIndex pi);
348 
349  ParticlesTemp get_dependent_particles_uncached(ParticleIndex pi);
350 
351  ScoreStatesTemp get_dependent_score_states_uncached(ParticleIndex pi);
352 #endif
353 
354  /** @name States
355 
356  ScoreStates maintain invariants in the Model (see ScoreState
357  for more information.)
358 
359  ScoreStates do not need to be explicitly added to the Model, but they
360  can be if desired in order to keep them alive as long as the model is
361  alive.
362 
363  \advancedmethod
364  */
365  /**@{*/
366  IMP_LIST_ACTION(public, ScoreState, ScoreStates, score_state, score_states,
367  ScoreState *, ScoreStates, do_add_score_state(obj), {},
368  do_remove_score_state(obj));
369  /**@}*/
370 
371  public:
372 #ifndef SWIG
373  using Object::clear_caches;
374 #endif
375 
376  //! Sometimes it is useful to be able to make sure the model is up to date
377  /** This method updates all the state but does not necessarily compute the
378  score. Use this to make sure that your containers and rigid bodies are
379  up to date.
380  */
381  void update();
382 
383 #ifdef IMP_DOXYGEN
384  /** \name Accessing attributes
385  \anchor model_attributes
386  All the attribute data associated with each Particle are stored in the
387  Model. For each type of attribute, there are the methods detailed below
388  (where, eg, TypeKey is FloatKey or StringKey)
389  @{
390  */
391  //! add particle atribute with the specied key and initial value
392  /** \pre get_has_attribute(attribute_key, particle) is false*/
393  void add_attribute(TypeKey attribute_key, ParticleIndex particle, Type value);
394 
395  //! remove particle attribute with the specied key
396  /** \pre get_has_attribute(attribute_key, particle) is true*/
397  void remove_attribute(TypeKey attribute_key, ParticleIndex particle);
398 
399  //! return true if particle has attribute with the specified key
400  bool get_has_attribute(TypeKey attribute_key, ParticleIndex particle) const;
401 
402  //! set the value of particle attribute with the specified key
403  /** \pre get_has_attribute(attribute_key, particle) is true*/
404  void set_attribute(TypeKey attribute_key, ParticleIndex particle, Type value);
405 
406  //! get the value of the particle attribute with the specified key
407  /** \pre get_has_attribute(attribute_key, particle) is true*/
408  Type get_attribute(TypeKey attribute_key, ParticleIndex particle);
409 
410  /** Cache attributes, unlike normal attributes, can be added during
411  evaluation. They are also cleared by the clear_cache_attributes() method.
412  Cache attributes should be used when one is adding data to a particle
413  to aid scoring (eg cache the rigid body collision acceleration structure).
414 
415  When some pertinent aspect of the particle changes, the clear method
416  should
417  be called (yes, this is a bit vague). Examples where it should be cleared
418  include changing the set of members of a core::RigidBody or their
419  coordinates, changing the members of an atom::Hierarchy.
420  */
421  void add_cache_attribute(TypeKey attribute_key, ParticleIndex particle,
422  Type value);
423 
424  //! Optimized attributes are the parameters of the model that are
425  //! allowed to be modified by samplers and optimizers
426  void set_is_optimized(TypeKey attribute_key, ParticleIndex particle,
427  bool true_or_false);
428 /** @} */
429 #endif
430 
431 #ifdef SWIG
432 #define IMP_MODEL_ATTRIBUTE_METHODS(Type, Value) \
433  void add_attribute(Type##Key attribute_key, ParticleIndex particle, \
434  Value value); \
435  void remove_attribute(Type##Key attribute_key, ParticleIndex particle); \
436  bool get_has_attribute(Type##Key attribute_key, \
437  ParticleIndex particle) const; \
438  void set_attribute(Type##Key attribute_key, ParticleIndex particle, \
439  Value value); \
440  Value get_attribute(Type##Key attribute_key, ParticleIndex particle); \
441  void add_cache_attribute(Type##Key attribute_key, ParticleIndex particle, \
442  Value value)
443 
444  IMP_MODEL_ATTRIBUTE_METHODS(Float, Float);
445  IMP_MODEL_ATTRIBUTE_METHODS(Int, Int);
446  IMP_MODEL_ATTRIBUTE_METHODS(Floats, Floats);
447  IMP_MODEL_ATTRIBUTE_METHODS(Ints, Ints);
448  IMP_MODEL_ATTRIBUTE_METHODS(String, String);
449  IMP_MODEL_ATTRIBUTE_METHODS(ParticleIndexes, ParticleIndexes);
450  IMP_MODEL_ATTRIBUTE_METHODS(ParticleIndex, ParticleIndex);
451  IMP_MODEL_ATTRIBUTE_METHODS(Object, Object *);
452  IMP_MODEL_ATTRIBUTE_METHODS(WeakObject, Object *);
453  void set_is_optimized(FloatKey, ParticleIndex, bool);
454  void add_to_derivative(FloatKey k, ParticleIndex particle, double v,
455  const DerivativeAccumulator &da);
456 #endif
457 
458  //! Get the particle from an index.
460  IMP_USAGE_CHECK(get_has_particle(p), "Invalid particle requested");
461  return particle_index_[p];
462  }
463 
464  //! Check whether a given particle index exists.
466  if (particle_index_.size() <= get_as_unsigned_int(p)) return false;
467  return particle_index_[p];
468  }
469 
470  //! Get all particle indexes
472 
473  //! Get all the ModelObjects associated with this Model.
474  ModelObjectsTemp get_model_objects() const;
475 
476  //! Remove a particle from the Model.
477  /** The particle will then be inactive and cannot be used for anything
478  and all data stored in the particle is lost.
479  */
480  void remove_particle(ParticleIndex pi);
481 
482  /** \name Storing data in the model
483 
484  One can store data associated with the model. This is used, for example,
485  to keep a central ScoreState to normalize rigid body rotational variables.
486  @{ */
487  //! Store a piece of data in the model referenced by the key.
488  void add_data(ModelKey mk, Object *o);
489  //! Get back some data stored in the model.
490  Object *get_data(ModelKey mk) const;
491  //! Remove data stored in the model.
492  void remove_data(ModelKey mk);
493  //! Check if the model has a certain piece of data attached.
494  bool get_has_data(ModelKey mk) const;
495  /** @} */
496 
497  /** \name Model triggers
498 
499  Triggers can be used to track when to clear and rebuild caches
500  of derived model properties. For example, a Restraint may restrain
501  two particles as a function of the number of chemical bonds between
502  them. To speed up this restraint, the bond graph can be cached; however,
503  this graph needs to be rebuilt if bonds are created or removed. This
504  can be achieved by checking that the model time (see get_age()) of the
505  cache matches the time when the 'bond added/removed' Trigger was last
506  updated (see get_trigger_last_updated()), either when the Restraint is
507  evaluated or in an associated ScoreState.
508 
509  Triggers are intended for events that are rare during a typical
510  optimization. Triggers can be created by any IMP module in either C++
511  or Python by creating a new TriggerKey, much as model attributes
512  are handled. To avoid name collisions, it is recommended to prepend
513  the module and/or class name to the trigger, e.g. "atom.Bond.changed".
514 
515  For an example, see IMP::score_functor::OrientedSoap, which uses
516  a cache built from the molecular hierarchy, which is cleared when the
517  IMP::core::Hierarchy::get_changed_key() trigger is updated.
518 
519  @{ */
520 
521  //! Get the current 'model time'.
522  /** This is a number 1 or more that tracks the 'age' of the model;
523  it is incremented every time before_evaluate() is called.
524  It may wrap (and so should not be assumed to always increase)
525  but will never be 0. */
526  unsigned get_age() { return age_counter_; }
527 
528  //! Get the time when the given trigger was last updated, or 0.
529  /** Return the 'model time' (as given by get_age()) when the given
530  trigger was last updated on this model, or 0 if never. */
532  if (trigger_age_.size() > tk.get_index()) {
533  return trigger_age_[tk.get_index()];
534  } else {
535  return 0;
536  }
537  }
538 
539  //! Update the given trigger
541  if (tk.get_index() >= trigger_age_.size()) {
542  trigger_age_.resize(tk.get_index() + 1, 0);
543  }
544  trigger_age_[tk.get_index()] = age_counter_;
545  }
546  /** @} */
547 
548  //! Get the model age when ModelObject dependencies were last changed, or 0.
549  /** This gives the Model age (see get_age()) when Particles, Restraints,
550  or ScoreStates were last added or removed. It is typically used to
551  help maintain caches that depend on the model's dependency graph. */
552  unsigned get_dependencies_updated() { return dependencies_age_; }
553 
554  //! Mark a 'restore point' for ModelObject dependencies.
555  /** \see restore_dependencies() */
557  dependencies_saved_ = true;
558  saved_dependencies_age_ = dependencies_age_;
560  mos_added_since_save_.clear();
561  mos_removed_since_save_.clear();
562  }
563  }
564 
565  //! Restore ModelObject dependencies to previous restore point.
566  /** This method, when paired with save_dependencies(), can be used to
567  avoid triggering a model dependency update due to a temporary change
568  in the model dependency graph, for example due to adding a temporary
569  restraint, evaluating it, then removing that same restraint. It should
570  only be called in cases where it is known that the dependency graph
571  is the same as when save_dependencies() was called (this is only checked
572  in debug mode). Save/restore call pairs cannot be nested, although it
573  is OK to skip the call to restore_dependencies(), e.g. if an exception
574  occurs.
575 
576  \see get_dependencies_updated()
577  \see save_dependencies()
578  */
580  if (dependencies_saved_) {
581  dependencies_saved_ = false;
582  dependencies_age_ = saved_dependencies_age_;
584  // Need to sort pointers since we may not add/remove in the same order
585  std::sort(mos_added_since_save_.begin(), mos_added_since_save_.end());
586  std::sort(mos_removed_since_save_.begin(),
587  mos_removed_since_save_.end());
588  IMP_INTERNAL_CHECK(mos_added_since_save_ == mos_removed_since_save_,
589  "ModelObjects added do not match those removed");
590  }
591  }
592  }
593 
594  //! Get an upper bound on the number of particles in the Model.
595  /** This value is guaranteed to be at least the number of particles in
596  the model (there may be fewer particles if any have been removed)
597  and every ParticleIndex will be smaller than this value. */
598  unsigned get_particles_size() const { return particle_index_.size(); }
599 
600  //! Get the unique ID of this Model.
601  /** When multiple Models exist simultaneously, each has a different unique ID.
602  */
603  uint32_t get_unique_id() const {
604  return unique_id_;
605  }
606 
607  //! Return the Model with the given unique ID.
608  /** If no Model with this ID exists, nullptr is returned. */
609  static Model* get_by_unique_id(uint32_t id) {
610  return model_map_.get(id);
611  }
612 
614 
615  public:
616 #if !defined(IMP_DOXYGEN)
617  virtual void do_destroy() override;
618 #endif
619 };
620 
621 IMPKERNEL_END_NAMESPACE
622 
623 CEREAL_SPECIALIZE_FOR_ALL_ARCHIVES(
624  IMP::Model, cereal::specialization::member_serialize);
625 
626 // This is needed for per cpp compilations, a not even sure why
627 // (perhaps cause Model returns ParticleIterator here and there?)
628 // - Feel free to remove if you *really* know what you're doing
629 #include "IMP/Particle.h"
630 
631 #endif /* IMPKERNEL_MODEL_H */
Particle * get_particle(ParticleIndex p) const
Get the particle from an index.
Definition: Model.h:459
Basic types used by IMP.
#define IMP_IF_CHECK(level)
Execute the code block if a certain level checks are on.
Definition: check_macros.h:104
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.
Definition: object_macros.h:25
void restore_dependencies()
Restore ModelObject dependencies to previous restore point.
Definition: Model.h:579
Index< ParticleIndexTag > ParticleIndex
Definition: base_types.h:161
void add_particle(RMF::FileHandle fh, Particle *hs)
Macros to help in defining tuple classes.
virtual void clear_caches()
Definition: Object.h:270
unsigned get_dependencies_updated()
Get the model age when ModelObject dependencies were last changed, or 0.
Definition: Model.h:552
A more IMP-like version of the std::vector.
Definition: Vector.h:42
unsigned get_particles_size() const
Get an upper bound on the number of particles in the Model.
Definition: Model.h:598
unsigned get_age()
Get the current 'model time'.
Definition: Model.h:526
bool get_has_particle(ParticleIndex p) const
Check whether a given particle index exists.
Definition: Model.h:465
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.
Definition: Model.h:531
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
Definition: check_macros.h:139
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
Base class for objects in a Model that depend on other objects.
Definition: ModelObject.h:28
virtual void do_destroy()
Definition: Object.h:274
Common base class for heavy weight IMP objects.
Definition: Object.h:111
ParticleIndexes get_particle_indexes(ParticlesTemp const &particles)
ScoreStates maintain invariants in the Model.
Definition: ScoreState.h:56
static Model * get_by_unique_id(uint32_t id)
Return the Model with the given unique ID.
Definition: Model.h:609
uint32_t get_unique_id() const
Get the unique ID of this Model.
Definition: Model.h:603
Implements a vector tied to a particular index of type Index<Tag>.
Definition: Index.h:64
Shared score state.
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.
void save_dependencies()
Mark a 'restore point' for ModelObject dependencies.
Definition: Model.h:556
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...)
Definition: types.h:19
Class to handle individual particles of a Model object.
Definition: Particle.h:43
bool get_has_dependencies() const
Return whether this object has dependencies computed.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168
Abstract base class for all restraints.
int Int
Basic integer value.
Definition: types.h:34
void set_trigger_updated(TriggerKey tk)
Update the given trigger.
Definition: Model.h:540
std::string String
Basic string value.
Definition: types.h:43
Class for adding derivatives from restraints to the model.