IMP  2.0.1
The Integrative Modeling Platform
kernel/Constraint.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/Constraint.h \brief A base class for constraints.
3  *
4  * Copyright 2007-2013 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPKERNEL_CONSTRAINT_H
9 #define IMPKERNEL_CONSTRAINT_H
10 
11 #include "ScoreState.h"
12 
13 IMPKERNEL_BEGIN_NAMESPACE
14 
15 //! Implement a constraint on the Model.
16 /** The solution model can be restricted two ways, either by
17  penalizing "bad" conformations (a restraint) or by forcing some
18  set of attributes to a function of other attributes (a
19  constraint). For example, rigid bodies consisting of a number of
20  particles could be implemented either way.
21 
22  - As a restraint: the particles in the rigid body are each moved
23  independently by the optimizer. The scoring function has a term
24  for how far each particle diverges from its rigid position.
25 
26  - As a constraint: the optimizer only changes the position of the
27  rigid body itself and the position of the particles in the body
28  are computed from the position of the rigid body.
29 
30  In IMP, constraints are implemented as a type of
31  ScoreState. Before evaluation, the constraint updates the
32  attributes of some of the particles to ensure that the constraint
33  is satisfied. Since this update creates implicit relationships
34  between the particles, after the derivatives are computed, the
35  constraint can move them around to make sure the derivatives of
36  the optimizer parameters are correct.
37 
38  In general, constraints are associated with Decorator objects
39  and created invisibly when needed.
40 
41  \note Constraint invariants will not necessarily hold if
42  involved particles have been called and Model::evaluate()
43  has not been called. For example, if you change a
44  particle's coordinates, a IMP::core::Centroid of a set
45  containing the particle will not be correct until the
46  Model is evaluated.
47 
48  \implementationwithoutexample{Constraint, IMP_CONSTRAINT}
49  */
50 class IMPKERNELEXPORT Constraint : public ScoreState
51 {
52 public:
53 #ifndef IMP_DOXYGEN
54  Constraint(std::string name="Constraint %1%");
55 #endif
56  Constraint(Model *m, std::string name="Constraint %1%");
57  virtual void do_update_attributes()=0;
58  virtual void do_update_derivatives(DerivativeAccumulator *da)=0;
59 
60  virtual void do_before_evaluate() IMP_OVERRIDE {
61  do_update_attributes();
62  }
63  virtual void do_after_evaluate(DerivativeAccumulator*da) IMP_OVERRIDE {
64  if (da) do_update_derivatives(da);
65  }
67 };
68 
69 
71 
72 IMPKERNEL_END_NAMESPACE
73 
74 #endif /* IMPKERNEL_CONSTRAINT_H */