Restore gmxapi._gmxapi.add_mdmodule() Python functionality.
[alexxy/gromacs.git] / python_packaging / sample_restraint / src / cpp / nullpotential.cpp
1 /*! \file
2  * \brief Code to implement the potential declared in nullpotential.h
3  *
4  * This restraint is implemented in a transitional style. We are moving in the direction of
5  * callback based data flow. There is also a preference amongst the GROMACS developers for
6  * stateless objects or free functions. State can be provided by library-managed facilities
7  * rather than stored in long-lived objects.
8  *
9  * The IRestraintPotential framework is due for revision in conjunction with ongoing evolution of
10  * the gmx::MDModules interactions. Until then, we try to use a forward looking design.
11  *
12  * \author M. Eric Irrgang <ericirrgang@gmail.com>
13  */
14
15 #include "nullpotential.h"
16
17 #include <utility>
18
19 namespace plugin
20 {
21
22 null_input_param_type makeNullParams(std::vector<int>&& sites)
23 {
24     return null_input_param_type{ std::move(sites), 0 };
25 }
26
27 std::vector<int> sites(const null_input_param_type& input)
28 {
29     return input.sites_;
30 }
31
32 gmx::PotentialPointData evaluate(
33         gmx::Vector /*r1*/,
34         gmx::Vector /*r2*/,
35         double /*t*/,
36         null_input_param_type* input)
37 {
38     ++input->count_;
39     return gmx::PotentialPointData();
40 }
41
42 int count(const null_input_param_type& input)
43 {
44     return input.count_;
45 }
46
47 gmx::PotentialPointData NullRestraint::evaluate(gmx::Vector r1, gmx::Vector r2, double t)
48 {
49     return ::plugin::evaluate(r1, r2, t, &data_);
50 }
51
52 std::vector<int> NullRestraint::sites() const
53 {
54     return ::plugin::sites(data_);
55 }
56
57 NullRestraint::NullRestraint(std::vector<int>                            sites,
58                              const NullRestraint::input_param_type&      params,
59                              std::shared_ptr<Resources> /*resources*/) :
60     data_{ std::move(sites), params.count_ }
61 {
62 }
63
64 // Important: Explicitly instantiate a definition for the templated class declared in
65 // ensemblepotential.h. Failing to do this will cause a linker error.
66 template class ::plugin::RestraintModule<NullRestraint>;
67
68 } // end namespace plugin