IMP logo
IMP Reference Guide  develop.29b24c6ad6,2021/05/15
The Integrative Modeling Platform
RestraintSet.h
Go to the documentation of this file.
1 /**
2  * \file IMP/RestraintSet.h
3  * \brief Used to hold a set of related restraints.
4  *
5  * Copyright 2007-2021 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_RESTRAINT_SET_H
10 #define IMPKERNEL_RESTRAINT_SET_H
11 
12 #include <IMP/kernel_config.h>
13 #include "Restraint.h"
14 #include "container_macros.h"
15 #include <string>
16 
17 IMPKERNEL_BEGIN_NAMESPACE
18 
19 //! Object used to hold a set of restraints
20 /** RestraintSets allow one to define a tree of restraints
21  and to weight various restraints. Upon evaluation,
22  all of the restraints in RestraintSets that have been
23  added to the model are evaluated
24  using the provided weight (weights are multiplicative
25  when RestraintSets are nested).
26 
27  If the weight is 0, the restraints are not evaluated.
28 
29  \note Restraints can belong to multiple RestraintSets.
30  The total effect is simply one of adding up the weights.
31 
32  \headerfile RestraintSet.h "IMP/RestraintSet.h"
33  \advanceddoc
34 
35  Talk to Daniel if you want to inherit from RestraintSet.
36 */
37 class IMPKERNELEXPORT RestraintSet : public Restraint {
38  void on_add(Restraint *r);
39  void on_change();
40  static void on_remove(RestraintSet *container, Restraint *r);
41  void show_it(std::ostream &out) const;
42 
43  public:
44  //! Create an empty set that is registered with the model
45  RestraintSet(Model *m, double weight,
46  const std::string &name = "RestraintSet %1%");
47  //! Create an empty set that is registered with the model
48  RestraintSet(Model *m, const std::string &name = "RestraintSet %1%");
49  //! Create a set that is registered with the model
50  RestraintSet(const RestraintsTemp &rs, double weight,
51  const std::string &name = "RestraintSet %1%");
52 
53  double unprotected_evaluate(DerivativeAccumulator *da) const;
55  /** @name Methods to control the nested Restraint objects
56 
57  This container manages a set of Restraint objects. To
58  manipulate the stored set use the methods below.
59  */
60  /**@{*/
61  IMP_LIST_ACTION(public, Restraint, Restraints, restraint, restraints,
62  Restraint *, Restraints, on_add(obj), on_change(),
63  if (container) on_remove(container, obj));
64  /**@}*/
65 
66  //! Divide the list of contained restraints into non-sets and sets.
67  /** \return a list of all contained Restraints that are not also
68  RestraintSets, and another list of contained RestraintSets.
69  */
70  std::pair<RestraintsTemp, RestraintSetsTemp> get_non_sets_and_sets() const;
71 
72  public:
73 #ifndef IMP_DOXYGEN
76  double weight = 1.0,
77  double max = std::numeric_limits<double>::max()) const;
78 #endif
79  double get_last_score() const;
80 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
81  protected:
85 #endif
86 };
87 
88 /** \name Gathering restraints
89  It is sometimes useful to extract all the non-RestraintSet restraints
90  from a hierarchy involving RestraintSets mixed with Restraints.
91 */
92 
93 IMPKERNELEXPORT RestraintsTemp get_restraints(const RestraintsTemp &rs);
94 
95 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
96 namespace {
97 template <class It>
98 void get_restraints_internal(It b, It e, RestraintsTemp &ret) {
99  for (It c = b; c != e; ++c) {
100  Restraint *cur = *c;
101  RestraintSet *rs = dynamic_cast<RestraintSet *>(cur);
102  if (rs) {
103  get_restraints_internal(rs->restraints_begin(), rs->restraints_end(),
104  ret);
105  } else {
106  ret.push_back(cur);
107  }
108  }
109 }
110 }
111 #endif
112 
113 template <class It>
114 inline RestraintsTemp get_restraints(It b, It e) {
115  RestraintsTemp ret;
116  get_restraints_internal(b, e, ret);
117  std::sort(ret.begin(), ret.end());
118  ret.erase(std::unique(ret.begin(), ret.end()), ret.end());
119  return ret;
120 }
121 
122 IMPKERNEL_END_NAMESPACE
123 
124 #endif /* IMPKERNEL_RESTRAINT_SET_H */
RestraintsTemp get_restraints(const Subset &s, const ParticleStatesTable *pst, const DependencyGraph &dg, RestraintSet *rs)
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
virtual void do_add_score_and_derivatives(ScoreAccumulator sa) const
A restraint should override this to compute the score and derivatives.
virtual ScoringFunction * create_scoring_function(double weight=1.0, double max=NO_MAX) const
Create a scoring function with only this restraint.
virtual Restraints do_create_decomposition() const
Definition: Restraint.h:225
IMP::Vector< IMP::WeakPointer< Restraint > > RestraintsTemp
Definition: base_types.h:84
Macros to define containers of objects.
Object used to hold a set of restraints.
Definition: RestraintSet.h:37
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
virtual Restraints do_create_current_decomposition() const
Definition: Restraint.h:235
Class for adding up scores during ScoringFunction evaluation.
virtual double get_last_score() const
Definition: Restraint.h:212
Represents a scoring function on the model.
Abstract base class for all restraints.
virtual ModelObjectsTemp do_get_inputs() const =0
Class for adding derivatives from restraints to the model.
A restraint is a term in an IMP ScoringFunction.
Definition: Restraint.h:54