IMP  2.1.0
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 class IMPKERNELEXPORT Constraint : public ScoreState {
49  public:
50 #ifndef IMP_DOXYGEN
51  Constraint(std::string name = "Constraint %1%");
52 #endif
53  Constraint(kernel::Model *m, std::string name = "Constraint %1%");
54  virtual void do_update_attributes() = 0;
55  virtual void do_update_derivatives(DerivativeAccumulator *da) = 0;
56 
57  virtual void do_before_evaluate() IMP_OVERRIDE { do_update_attributes(); }
58  virtual void do_after_evaluate(DerivativeAccumulator *da) IMP_OVERRIDE {
59  if (da) do_update_derivatives(da);
60  }
62 };
63 
65 
66 IMPKERNEL_END_NAMESPACE
67 
68 #endif /* IMPKERNEL_CONSTRAINT_H */
Class for adding derivatives from restraints to the model.
IMP::kernel::Constraint Constraint
#define IMP_REF_COUNTED_DESTRUCTOR(Name)
Ref counted objects should have private destructors.
ScoreStates maintian invariants in the Model.
Shared score state.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing sets of objects.
Implement a constraint on the Model.
Class for storing model, its restraints, constraints, and particles.