IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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-2026 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
16IMPEXAMPLE_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*/
26class IMPEXAMPLEEXPORT ExampleRestraint : public Restraint {
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
39
40 double get_force_constant() const { return k_; }
41 ParticleIndex get_index() const { return p_; }
42
44 override;
47
48 private:
49 // Serialization support
50 friend class cereal::access;
51 template<class Archive> void serialize(Archive &ar) {
52 // We must save/load everything in the Restraint base class
53 // (e.g. restraint name, Model pointer) plus our own variables p_ and k_
54 ar(cereal::base_class<Restraint>(this), p_, k_);
55 }
56 // ExampleRestraint is polymorphic (e.g. it is stored in
57 // IMP.core.RestraintsScoringFunction as a Restraint, not an
58 // ExampleRestraint) so tell the serialization subsystem how to handle this
60
61};
62
63IMPEXAMPLE_END_NAMESPACE
64
65#endif /* IMPEXAMPLE_EXAMPLE_RESTRAINT_H */
Abstract base class for all restraints.
Restraint(Model *m, std::string name)
Create a restraint and register it with the model.
Class for adding up scores during ScoringFunction evaluation.
Restrain a particle to be in the x,y plane.
ExampleRestraint(Model *m, ParticleIndex p, double k)
Create the restraint.
void do_add_score_and_derivatives(ScoreAccumulator sa) const override
Add the score and (if requested) derivatives to the accumulator.
ModelObjectsTemp do_get_inputs() const override
Index< ParticleIndexTag > ParticleIndex
Definition base_types.h:196
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition base_types.h:122
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.