IMP logo
IMP Reference Guide  2.20.2
The Integrative Modeling Platform
ExampleConstraint.h
Go to the documentation of this file.
1 /**
2  * \file IMP/example/ExampleConstraint.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_CONSTRAINT_H
10 #define IMPEXAMPLE_EXAMPLE_CONSTRAINT_H
11 
12 #include <IMP/example/example_config.h>
13 #include <IMP/SingletonScore.h>
14 #include <IMP/Constraint.h>
15 #include <IMP/PairContainer.h>
16 #include <IMP/PairScore.h>
17 #include <cereal/access.hpp>
18 
19 IMPEXAMPLE_BEGIN_NAMESPACE
20 
21 //! A trivial constraint that just increments a counter
22 /**
23 */
24 class IMPEXAMPLEEXPORT ExampleConstraint : public Constraint {
25  ParticleIndex p_;
26  IntKey k_;
27 
28  public:
31 
32  virtual void do_update_attributes() override;
33  virtual void do_update_derivatives(DerivativeAccumulator *da) override;
34  virtual ModelObjectsTemp do_get_inputs() const override;
35  virtual ModelObjectsTemp do_get_outputs() const override;
36 
37  static IntKey get_key();
39 
40  private:
41  // Serialization support
42  friend class cereal::access;
43  template<class Archive> void serialize(Archive &ar) {
44  ar(cereal::base_class<Constraint>(this), p_);
45  // There is no need to serialize the IntKey - just recreate it on load:
46  if (std::is_base_of<cereal::detail::InputArchiveBase, Archive>::value) {
47  k_ = get_key();
48  }
49  }
50  IMP_OBJECT_SERIALIZE_DECL(ExampleConstraint);
51 };
52 
53 IMPEXAMPLE_END_NAMESPACE
54 
55 #endif /* IMPEXAMPLE_EXAMPLE_CONSTRAINT_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:42
Implement a constraint on the Model.
Definition: Constraint.h:49
A container for Pairs.
Define PairScore.
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
Definition: object_macros.h:95
A base class for constraints.
Define SingletonScore.
virtual ModelObjectsTemp do_get_outputs() const =0
Class to handle individual particles of a Model object.
Definition: Particle.h:43
A trivial constraint that just increments a counter.
virtual ModelObjectsTemp do_get_inputs() const =0
Class for adding derivatives from restraints to the model.