Make ImdSession into a Pimpl-ed class with factory function
[alexxy/gromacs.git] / src / gromacs / mdrun / integrator.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2015,2016,2017,2018,2019, 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 /*! \internal
36  * \brief Declares the integrator interface for mdrun
37  *
38  * \author David van der Spoel <david.vanderspoel@icm.uu.se>
39  * \author Mark Abraham <mark.j.abraham@gmail.com>
40  * \ingroup module_mdrun
41  */
42 #ifndef GMX_MDRUN_INTEGRATOR_H
43 #define GMX_MDRUN_INTEGRATOR_H
44
45 #include <cstdio>
46
47 #include <memory>
48
49 #include "gromacs/utility/basedefinitions.h"
50 #include "gromacs/utility/real.h"
51
52 class energyhistory_t;
53 struct gmx_enerdata_t;
54 struct gmx_enfrot;
55 struct gmx_mtop_t;
56 struct gmx_membed_t;
57 struct gmx_multisim_t;
58 struct gmx_output_env_t;
59 struct gmx_vsite_t;
60 struct gmx_wallcycle;
61 struct gmx_walltime_accounting;
62 struct ObservablesHistory;
63 struct ReplicaExchangeParameters;
64 struct t_commrec;
65 struct t_fcdata;
66 struct t_forcerec;
67 struct t_filenm;
68 struct t_inputrec;
69 struct t_nrnb;
70 class t_state;
71
72 namespace gmx
73 {
74
75 class BoxDeformation;
76 class Constraints;
77 class PpForceWorkload;
78 class IMDOutputProvider;
79 class ImdSession;
80 class MDLogger;
81 class MDAtoms;
82 class StopHandlerBuilder;
83 struct MdrunOptions;
84
85 //! Function type for integrator code.
86 using IntegratorFunctionType = void();
87
88 /*! \internal
89  * \brief Struct to handle setting up and running the different "integrators".
90  *
91  * This struct is a mere aggregate of parameters to pass to evaluate an
92  * energy, so that future changes to names and types of them consume
93  * less time when refactoring other code.
94  *
95  * Aggregate initialization is used, for which the chief risk is that
96  * if a member is added at the end and not all initializer lists are
97  * updated, then the member will be value initialized, which will
98  * typically mean initialization to zero.
99  *
100  * Having multiple integrators as member functions isn't a good
101  * design, and we definitely only intend one to be called, but the
102  * goal is to make it easy to change the names and types of members
103  * without having to make identical changes in several places in the
104  * code. Once many of them have become modules, we should change this
105  * approach.
106  *
107  * Note that the presence of const reference members means that the
108  * default constructor would be implicitly deleted. But we only want
109  * to make one of these when we know how to initialize these members,
110  * so that is perfect. To ensure this remains true even if we would
111  * remove those members, we explicitly delete this constructor.
112  * Other constructors, copies and moves are OK. */
113 struct Integrator
114 {
115     //! Handles logging.
116     FILE                               *fplog;
117     //! Handles communication.
118     t_commrec                          *cr;
119     //! Coordinates multi-simulations.
120     const gmx_multisim_t               *ms;
121     //! Handles logging.
122     const MDLogger                     &mdlog;
123     //! Count of input file options.
124     int                                 nfile;
125     //! Content of input file options.
126     const t_filenm                     *fnm;
127     //! Handles writing text output.
128     const gmx_output_env_t             *oenv;
129     //! Contains command-line options to mdrun.
130     const MdrunOptions                 &mdrunOptions;
131     //! Handles virtual sites.
132     gmx_vsite_t                        *vsite;
133     //! Handles constraints.
134     Constraints                        *constr;
135     //! Handles enforced rotation.
136     gmx_enfrot                         *enforcedRotation;
137     //! Handles box deformation.
138     BoxDeformation                     *deform;
139     //! Handles writing output files.
140     IMDOutputProvider                  *outputProvider;
141     //! Contains user input mdp options.
142     t_inputrec                         *inputrec;
143     //! The Interactive Molecular Dynamics session.
144     ImdSession                         *imdSession;
145     //! Full system topology.
146     gmx_mtop_t                         *top_global;
147     //! Helper struct for force calculations.
148     t_fcdata                           *fcd;
149     //! Full simulation state (only non-nullptr on master rank).
150     t_state                            *state_global;
151     //! History of simulation observables.
152     ObservablesHistory                 *observablesHistory;
153     //! Atom parameters for this domain.
154     MDAtoms                            *mdAtoms;
155     //! Manages flop accounting.
156     t_nrnb                             *nrnb;
157     //! Manages wall cycle accounting.
158     gmx_wallcycle                      *wcycle;
159     //! Parameters for force calculations.
160     t_forcerec                         *fr;
161     //! Data for energy output.
162     gmx_enerdata_t                     *enerd;
163     //! Schedule of force-calculation work each step for this task.
164     PpForceWorkload                    *ppForceWorkload;
165     //! Parameters for replica exchange algorihtms.
166     const ReplicaExchangeParameters    &replExParams;
167     //! Parameters for membrane embedding.
168     gmx_membed_t                       *membed;
169     //! Manages wall time accounting.
170     gmx_walltime_accounting            *walltime_accounting;
171     //! Registers stop conditions
172     std::unique_ptr<StopHandlerBuilder> stopHandlerBuilder;
173     //! Implements the normal MD integrators.
174     IntegratorFunctionType              do_md;
175     //! Implements the rerun functionality.
176     IntegratorFunctionType              do_rerun;
177     //! Implements steepest descent EM.
178     IntegratorFunctionType              do_steep;
179     //! Implements conjugate gradient energy minimization
180     IntegratorFunctionType              do_cg;
181     //! Implements onjugate gradient energy minimization using the L-BFGS algorithm
182     IntegratorFunctionType              do_lbfgs;
183     //! Implements normal mode analysis
184     IntegratorFunctionType              do_nm;
185     //! Implements test particle insertion
186     IntegratorFunctionType              do_tpi;
187     //! Implements MiMiC QM/MM workflow
188     IntegratorFunctionType              do_mimic;
189     /*! \brief Function to run the correct IntegratorFunctionType,
190      * based on the .mdp integrator field. */
191     void run(unsigned int ei, bool doRerun);
192     //! We only intend to construct such objects with an initializer list.
193     Integrator() = delete;
194 };
195
196 }      // namespace gmx
197
198 #endif // GMX_MDRUN_INTEGRATOR_H