IMP logo
IMP Reference Guide  2.20.0
The Integrative Modeling Platform
ModelObject.h
Go to the documentation of this file.
1 /**
2  * \file IMP/ModelObject.h
3  * \brief Base class for objects in a Model that depend on other objects.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPKERNEL_MODEL_OBJECT_H
9 #define IMPKERNEL_MODEL_OBJECT_H
10 
11 #include <IMP/kernel_config.h>
12 #include "base_types.h"
13 #include <IMP/ref_counted_macros.h>
14 #include <IMP/utility_macros.h>
15 #include <cereal/access.hpp>
16 #include <cereal/types/base_class.hpp>
17 
18 IMPKERNEL_BEGIN_NAMESPACE
19 
20 class Model;
21 
22 //! Base class for objects in a Model that depend on other objects.
23 /** These objects are associated with a particular Model
24  and have a callback that is called whenever the dependencies
25  in the model change. This allows them to update internal state
26  when that occurs.
27  */
28 class IMPKERNELEXPORT ModelObject : public Object {
29  friend class Model;
30  WeakPointer<Model> model_;
31 
32 #ifndef SWIG
33  friend class cereal::access;
34 
35  template<class Archive> void serialize(Archive &ar) {
36  ar(cereal::base_class<Object>(this));
37  if (std::is_base_of<cereal::detail::OutputArchiveBase, Archive>::value) {
38  uint32_t model_id = get_model_id();
39  ar(model_id);
40  } else {
41  uint32_t model_id;
42  ar(model_id);
43  set_model_from_id(model_id);
44  }
45  }
46 
47  void set_model_from_id(uint32_t model_id);
48  uint32_t get_model_id() const;
49 #endif
50 
51  // for cleanup
52  void set_model(Model *m);
53 
54  public:
55 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
56  void validate_inputs() const;
57  void validate_outputs() const;
58 #endif
59 
60  ModelObject(Model *m, std::string name);
61  ModelObject();
62  ~ModelObject();
63 
64  Model *get_model() const { return model_; }
65  /** get_has_dependencies() must be true. */
66  ModelObjectsTemp get_inputs() const;
67  /** get_has_dependencies() must be true. */
68  ModelObjectsTemp get_outputs() const;
69  //! Get the interacting sets induced by this ModelObject.
70  /** That is, the particles in each ModelObjectsTemp in the list have some
71  sort of computed relation with one another and none with
72  disjoint other sets in the list. */
73  ModelObjectsTemps get_interactions() const;
74 
75  //! Return whether this object has dependencies computed
76  bool get_has_dependencies() const;
77 
78  //! Either invalidate the dependencies or ensure they are correct.
79  void set_has_dependencies(bool tf);
80 
81  //! Compute the required score states.
82  void set_has_required_score_states(bool tf);
83 
84  //! Return whether score states are computed.
85  bool get_has_required_score_states() const;
86 
87  //! Get the score states that are ancestors of this in the dependency graph.
88  const ScoreStatesTemp &get_required_score_states() const;
89 
90  protected:
91  // virtual void do_destroy() override {set_has_dependencies(false);}
92  /** Called when set_has_required_score_states() is called.*/
94  /** Get any Particle, Container or other ModelObjects read by
95  this during evaluation. If you read everything in a container,
96  you can just return that container. */
97  virtual ModelObjectsTemp do_get_inputs() const = 0;
98  /** Get any Particle, Container or other ModelObjects changed by
99  this during evaluation. This is only useful for ScoreStates,
100  at the moment.*/
101  virtual ModelObjectsTemp do_get_outputs() const = 0;
102  /** Override if this if not all inputs interact with all outputs. This is
103  rarely something you want to do.*/
104  virtual ModelObjectsTemps do_get_interactions() const;
105 };
106 
107 IMPKERNEL_END_NAMESPACE
108 
109 #endif /* IMPKERNEL_MODEL_OBJECT_H */
Macros to help with reference counting.
Basic types used by IMP.
Smart pointer to Object-derived classes that does not refcount.
Definition: WeakPointer.h:77
A more IMP-like version of the std::vector.
Definition: Vector.h:42
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
Common base class for heavy weight IMP objects.
Definition: Object.h:111
Various general useful macros for IMP.
virtual void handle_set_has_required_score_states(bool)
Definition: ModelObject.h:93