IMP  2.4.0
The Integrative Modeling Platform
kernel/RestraintSet.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/RestraintSet.h
3  * \brief Used to hold a set of related restraints.
4  *
5  * Copyright 2007-2015 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/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(kernel::Model *m, double weight,
45  const std::string &name = "RestraintSet %1%");
46  //! Create an empty set that is registered with the model
47  RestraintSet(kernel::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 sets and non-sets.*/
66  std::pair<RestraintsTemp, RestraintSetsTemp> get_non_sets_and_sets() const;
67 
68  public:
69 #ifndef IMP_DOXYGEN
72  double weight = 1.0,
73  double max = std::numeric_limits<double>::max()) const;
74 #endif
75  double get_last_score() const;
76 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
77  protected:
81 #endif
82 };
83 
84 /** \name Gathering restraints
85  It is sometimes useful to extract all the non-RestraintSet restraints
86  from a hierarchy involving RestraintSets mixed with Restraints.
87 */
88 
89 IMPKERNELEXPORT RestraintsTemp get_restraints(const RestraintsTemp &rs);
90 
91 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
92 namespace {
93 template <class It>
94 void get_restraints_internal(It b, It e, RestraintsTemp &ret) {
95  for (It c = b; c != e; ++c) {
96  Restraint *cur = *c;
97  RestraintSet *rs = dynamic_cast<RestraintSet *>(cur);
98  if (rs) {
99  get_restraints_internal(rs->restraints_begin(), rs->restraints_end(),
100  ret);
101  } else {
102  ret.push_back(cur);
103  }
104  }
105 }
106 }
107 #endif
108 
109 template <class It>
110 inline RestraintsTemp get_restraints(It b, It e) {
111  RestraintsTemp ret;
112  get_restraints_internal(b, e, ret);
113  std::sort(ret.begin(), ret.end());
114  ret.erase(std::unique(ret.begin(), ret.end()), ret.end());
115  return ret;
116 }
117 
118 IMPKERNEL_END_NAMESPACE
119 
120 #endif /* IMPKERNEL_RESTRAINT_SET_H */
Class for adding derivatives from restraints to the model.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
IMP::base::Vector< IMP::base::WeakPointer< Restraint > > RestraintsTemp
Object used to hold a set of restraints.
virtual void do_add_score_and_derivatives(ScoreAccumulator sa) const
kernel::RestraintsTemp get_restraints(const Subset &s, const ParticleStatesTable *pst, const DependencyGraph &dg, kernel::RestraintSet *rs)
Represents a scoring function on the model.
virtual double get_last_score() const
Abstract base class for all restraints.
Class for adding up scores during ScoringFunction evaluation.
A restraint is a term in an IMP ScoringFunction.
virtual Restraints do_create_current_decomposition() const
virtual ScoringFunction * create_scoring_function(double weight=1.0, double max=NO_MAX) const
Create a scoring function with only this restraint.
virtual ModelObjectsTemp do_get_inputs() const =0
virtual Restraints do_create_decomposition() const
Macros to define containers of objects.
IMP::kernel::RestraintSet RestraintSet
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:73