IMP logo
IMP Reference Guide  2.22.0
The Integrative Modeling Platform
ExampleRestraint.h
Go to the documentation of this file.
1 /**
2  * \file IMP/example/ExampleRestraint.h
3  * \brief A restraint on a list of particle pairs.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPEXAMPLE_EXAMPLE_RESTRAINT_H
10 #define IMPEXAMPLE_EXAMPLE_RESTRAINT_H
11 
12 #include <IMP/example/example_config.h>
13 #include <IMP/Restraint.h>
14 #include <cereal/access.hpp>
15 
16 IMPEXAMPLE_BEGIN_NAMESPACE
17 
18 //! Restrain a particle to be in the x,y plane
19 /** \note Be sure to check out the swig wrapper file and how it
20  wraps this class.
21 
22  The source code is as follows:
23  \include ExampleRestraint.h
24  \include ExampleRestraint.cpp
25 */
26 class IMPEXAMPLEEXPORT ExampleRestraint : public Restraint {
27  ParticleIndex p_;
28  double k_;
29 
30  public:
31  //! Create the restraint.
32  /** Restraints should store the particles they are to act on,
33  preferably in a Singleton or PairContainer as appropriate.
34  */
35  ExampleRestraint(Model *m, ParticleIndex p, double k);
36 
37  // Default constructor, needed for serialization or Python pickle support
38  ExampleRestraint() {}
39 
40  void do_add_score_and_derivatives(ScoreAccumulator sa) const
41  override;
42  ModelObjectsTemp do_get_inputs() const override;
44 
45  private:
46  // Serialization support
47  friend class cereal::access;
48  template<class Archive> void serialize(Archive &ar) {
49  // We must save/load everything in the Restraint base class
50  // (e.g. restraint name, Model pointer) plus our own variables p_ and k_
51  ar(cereal::base_class<Restraint>(this), p_, k_);
52  }
53  // ExampleRestraint is polymorphic (e.g. it is stored in
54  // IMP.core.RestraintsScoringFunction as a Restraint, not an
55  // ExampleRestraint) so tell the serialization subsystem how to handle this
57 
58 };
59 
60 IMPEXAMPLE_END_NAMESPACE
61 
62 #endif /* IMPEXAMPLE_EXAMPLE_RESTRAINT_H */
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
A more IMP-like version of the std::vector.
Definition: Vector.h:50
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
Definition: object_macros.h:95
Class for adding up scores during ScoringFunction evaluation.
Restrain a particle to be in the x,y plane.
Abstract base class for all restraints.
virtual ModelObjectsTemp do_get_inputs() const =0
A restraint is a term in an IMP ScoringFunction.
Definition: Restraint.h:56