IMP logo
IMP Reference Guide  2.9.0
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-2018 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 //! Object used to hold a set of restraints
19 /** RestraintSets allow one to define a tree of restraints
20  and to weight various restraints. Upon evaluation,
21  all of the restraints in RestraintSets that have been
22  added to the model are evaluated
23  using the provided weight (weights are multiplicative
24  when RestraintSets are nested).
25 
26  If the weight is 0, the restraints are not evaluated.
27 
28  \note Restraints can belong to multiple RestraintSets.
29  The total effect is simply one of adding up the weights.
30 
31  \headerfile RestraintSet.h "IMP/RestraintSet.h"
32  \advanceddoc
33 
34  Talk to Daniel if you want to inherit from RestraintSet.
35 */
36 class IMPKERNELEXPORT RestraintSet : public Restraint {
37  void on_add(Restraint *r);
38  void on_change();
39  static void on_remove(RestraintSet *container, Restraint *r);
40  void show_it(std::ostream &out) const;
41 
42  public:
43  //! Create an empty set that is registered with the model
44  RestraintSet(Model *m, double weight,
45  const std::string &name = "RestraintSet %1%");
46  //! Create an empty set that is registered with the model
47  RestraintSet(Model *m, const std::string &name = "RestraintSet %1%");
48  //! Create a set that is registered with the model
49  RestraintSet(const RestraintsTemp &rs, double weight,
50  const std::string &name = "RestraintSet %1%");
51 
52  double unprotected_evaluate(DerivativeAccumulator *da) const;
54  /** @name Methods to control the nested Restraint objects
55 
56  This container manages a set of Restraint objects. To
57  manipulate the stored set use the methods below.
58  */
59  /**@{*/
60  IMP_LIST_ACTION(public, Restraint, Restraints, restraint, restraints,
61  Restraint *, Restraints, on_add(obj), on_change(),
62  if (container) on_remove(container, obj));
63  /**@}*/
64 
65  //! Divide the list of contained restraints into non-sets and sets.
66  /** \return a list of all contained Restraints that are not also
67  RestraintSets, and another list of contained RestraintSets.
68  */
69  std::pair<RestraintsTemp, RestraintSetsTemp> get_non_sets_and_sets() const;
70 
71  public:
72 #ifndef IMP_DOXYGEN
75  double weight = 1.0,
76  double max = std::numeric_limits<double>::max()) const;
77 #endif
78  double get_last_score() const;
79 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
80  protected:
84 #endif
85 };
86 
87 /** \name Gathering restraints
88  It is sometimes useful to extract all the non-RestraintSet restraints
89  from a hierarchy involving RestraintSets mixed with Restraints.
90 */
91 
92 IMPKERNELEXPORT RestraintsTemp get_restraints(const RestraintsTemp &rs);
93 
94 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
95 namespace {
96 template <class It>
97 void get_restraints_internal(It b, It e, RestraintsTemp &ret) {
98  for (It c = b; c != e; ++c) {
99  Restraint *cur = *c;
100  RestraintSet *rs = dynamic_cast<RestraintSet *>(cur);
101  if (rs) {
102  get_restraints_internal(rs->restraints_begin(), rs->restraints_end(),
103  ret);
104  } else {
105  ret.push_back(cur);
106  }
107  }
108 }
109 }
110 #endif
111 
112 template <class It>
113 inline RestraintsTemp get_restraints(It b, It e) {
114  RestraintsTemp ret;
115  get_restraints_internal(b, e, ret);
116  std::sort(ret.begin(), ret.end());
117  ret.erase(std::unique(ret.begin(), ret.end()), ret.end());
118  return ret;
119 }
120 
121 IMPKERNEL_END_NAMESPACE
122 
123 #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:80
Macros to define containers of objects.
Object used to hold a set of restraints.
Definition: RestraintSet.h:36
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