IMP  2.0.1
The Integrative Modeling Platform
kernel/declare_RestraintSet.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/declare_RestraintSet.h
3  * \brief Used to hold a set of related restraints.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_DECLARE_RESTRAINT_SET_H
10 #define IMPKERNEL_DECLARE_RESTRAINT_SET_H
11 
12 #include <IMP/kernel/kernel_config.h>
13 #include "declare_Restraint.h"
14 #include "container_macros.h"
15 #include <IMP/base/map.h>
16 #include <string>
17 
18 IMPKERNEL_BEGIN_NAMESPACE
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 {
39  void on_add(Restraint*r);
40  void on_change();
41  static void on_remove(RestraintSet *container, Restraint *r);
42  void show_it(std::ostream &out) const;
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 a set that is registered with the model
48  RestraintSet(const RestraintsTemp &rs, double weight,
49  const std::string& name="RestraintSet %1%");
50 #ifndef IMP_DOXYGEN
51  //! Create an empty set
52  RestraintSet(double weight,
53  const std::string& name="RestraintSet %1%");
54 
55  //! Create an empty set
56  RestraintSet(const std::string& name="RestraintSet %1%");
57 
58  //! special for model
59  RestraintSet(Restraint::ModelInitTag,
60  const std::string& name="RestraintSet %1%");
61 #endif
62 
63  double unprotected_evaluate(DerivativeAccumulator *da) const;
64  IMP_OBJECT_INLINE(RestraintSet,show_it(out),
65  Restraint::set_model(nullptr));
66  /** @name Methods to control the nested Restraint objects
67 
68  This container manages a set of Restraint objects. To
69  manipulate the stored set use the methods below.
70  */
71  /**@{*/
72  IMP_LIST_ACTION(public, Restraint, Restraints, restraint, restraints,
74  on_add(obj), on_change(),
75  if (container) on_remove(container, obj));
76  /**@}*/
77 
78  /** Divide the list of contained restraints into sets and non-sets.*/
79  std::pair<RestraintsTemp, RestraintSetsTemp> get_non_sets_and_sets() const;
80  public:
81 #ifndef IMP_DOXYGEN
83  ScoringFunction* create_scoring_function(double weight=1.0,
84  double max
85  = std::numeric_limits<double>::max())
86  const;
87 #endif
88  IMP_IMPLEMENT(double get_last_score() const);
89 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
90  void set_model(Model *m);
91  IMP_PROTECTED_METHOD(Restraints, do_create_decomposition,(), const,);;
92  IMP_PROTECTED_METHOD(Restraints, do_create_current_decomposition,(), const,);
93  IMP_PROTECTED_METHOD(void, do_add_score_and_derivatives,
94  (ScoreAccumulator sa), const,);
95 
96  friend class Model;
97 #endif
98 };
99 
100 /** \name Gathering restraints
101  It is sometimes useful to extract all the non-RestraintSet restraints
102  from a hierarchy involving RestraintSets mixed with Restraints.
103 */
104 
105 IMPKERNELEXPORT RestraintsTemp get_restraints(const RestraintsTemp &rs);
106 
107 IMPKERNEL_END_NAMESPACE
108 
109 #endif /* IMPKERNEL_DECLARE_RESTRAINT_SET_H */