98c719fe02c11b3d2210bcc4abe9ab3bb6047625
[alexxy/gromacs.git] / src / gromacs / restraint / manager.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2018, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35
36 #ifndef GROMACS_RESTRAINT_MANAGER_H
37 #define GROMACS_RESTRAINT_MANAGER_H
38
39 /*! \libinternal \file
40  * \brief Declare the Manager for restraint potentials.
41  *
42  * \author M. Eric Irrgang <ericirrgang@gmail.com>
43  *
44  * \inlibraryapi
45  * \ingroup module_restraint
46  */
47
48 #include <memory>
49 #include <mutex>
50 #include <string>
51
52 #include "gromacs/restraint/restraintpotential.h"
53 #include "gromacs/utility/basedefinitions.h"
54
55 struct t_commrec;
56 struct t_mdatoms;
57 struct pull_t;
58
59 namespace gmx
60 {
61
62 /*! \libinternal \ingroup module_restraint
63  * \brief Manage the Restraint potentials available for Molecular Dynamics.
64  *
65  * A simulation runner owns one manager resource to hold restraint objects used
66  * in the simulation. In the case of thread MPI simulations, multiple runner
67  * instances will have handles to the same underlying resource. With further
68  * factoring of the mdrun call stack, this facility can be combined with others
69  * into a simulation context object from which simulation code can retrieve
70  * support code for a user-configured simulation.
71  *
72  * Calling code provides the manager with a means to access the various required input data
73  * to be used when restraints are computed.
74  *
75  * \todo This should be generalized as work description and factory functions in Context.
76  */
77 class RestraintManager final
78 {
79     public:
80         //! Create new restraint manager resources with empty set of restraints.
81         RestraintManager();
82
83         ~RestraintManager();
84
85         /*!
86          * \brief Client code can access the shared resource by copying or moving a handle.
87          * \{
88          */
89         RestraintManager(const RestraintManager &/* unused */) = default;
90         RestraintManager               &operator=(const RestraintManager & /* unused */)     = default;
91         RestraintManager(RestraintManager &&) noexcept                                       = default;
92         RestraintManager               &operator=(RestraintManager && /* unused */) noexcept = default;
93         /*! \} */
94
95         /*!
96          * \brief Clear registered restraints and reset the manager.
97          */
98         void clear() noexcept;
99
100         /*!
101          * \brief Get the number of currently managed restraints.
102          *
103          * \return number of restraints.
104          *
105          * \internal
106          * Only considers the IRestraintPotential objects
107          */
108         unsigned long countRestraints() noexcept;
109
110         /*! \brief Obtain the ability to create a restraint MDModule
111          *
112          * Though the name is reminiscent of the evolving idea of a work specification, the
113          * Spec here is just a list of restraint modules.
114          *
115          * \param restraint shared ownership of a restraint potential interface.
116          * \param name key by which to reference the restraint.
117          */
118         void addToSpec(std::shared_ptr<gmx::IRestraintPotential> restraint,
119                        std::string                               name);
120
121         /*!
122          * \brief Get a copy of the current set of restraints to be applied.
123          *
124          * This function is to be used when launching a simulation to get the
125          * restraint handles to bind, so it is not performance sensitive. A new
126          * vector is returned with each call because it is unspecified whether
127          * the set of handles point to the same objects on all threads or between
128          * calls to getRestraints.
129          *
130          * \return a copy of the list of restraint potentials.
131          */
132         std::vector< std::shared_ptr<IRestraintPotential> > getRestraints() const;
133
134     private:
135         class Impl;
136         //! Ownership of the shared reference to the global manager.
137         std::shared_ptr<Impl> instance_;
138 };
139
140 }      // end namespace gmx
141
142 #endif //GROMACS_RESTRAINT_MANAGER_H