IMP logo
IMP Reference Guide  2.20.1
The Integrative Modeling Platform
Constraint.h
Go to the documentation of this file.
1 /**
2  * \file IMP/Constraint.h \brief A base class for constraints.
3  *
4  * Copyright 2007-2022 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 modified directly (not through e.g., an
43  Optimizer), until Model::update() or Model::evaluate()
44  have been called. For example, if you change a
45  particle's coordinates, a IMP::core::Centroid of a set of particles that
46  contains the particle, will not be the correct centroid until the
47  Model is updated.
48  */
49 class IMPKERNELEXPORT Constraint : public ScoreState {
50  public:
51  Constraint(Model *m, std::string name = "Constraint %1%");
52  Constraint() {}
53  virtual void do_update_attributes() = 0;
54  virtual void do_update_derivatives(DerivativeAccumulator *da) = 0;
55 
56  virtual void do_before_evaluate() override { do_update_attributes(); }
57  virtual void do_after_evaluate(DerivativeAccumulator *da) override {
58  if (da) do_update_derivatives(da);
59  }
61 };
62 
64 
65 IMPKERNEL_END_NAMESPACE
66 
67 #endif /* IMPKERNEL_CONSTRAINT_H */
#define IMP_REF_COUNTED_DESTRUCTOR(Name)
Set up destructor for a ref counted object.
A more IMP-like version of the std::vector.
Definition: Vector.h:42
Implement a constraint on the Model.
Definition: Constraint.h:49
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
ScoreStates maintain invariants in the Model.
Definition: ScoreState.h:56
virtual void do_after_evaluate(DerivativeAccumulator *da) override
Do any necessary updates after the model score is calculated.
Definition: Constraint.h:57
Shared score state.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Definition: object_macros.h:44
virtual void do_before_evaluate() override
Update the state given the current state of the model.
Definition: Constraint.h:56
Class for adding derivatives from restraints to the model.