Introduce SimulatorBuilder
[gromacs.git] / src / gromacs / mdrun / isimulator.h
blob2a8110b1da7d4db680351d968de248b642a69f04
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 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.
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.
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.
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.
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.
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.
35 /*! \internal
36 * \brief Declares the general simulator interface
38 * \author Pascal Merz <pascal.merz@me.com>
39 * \ingroup module_mdrun
41 #ifndef GMX_MDRUN_ISIMULATOR_H
42 #define GMX_MDRUN_ISIMULATOR_H
44 #include "gromacs/mdlib/stophandler.h"
46 class energyhistory_t;
47 struct gmx_enerdata_t;
48 struct gmx_enfrot;
49 struct gmx_mtop_t;
50 struct gmx_membed_t;
51 struct gmx_multisim_t;
52 struct gmx_output_env_t;
53 struct gmx_vsite_t;
54 struct gmx_wallcycle;
55 struct gmx_walltime_accounting;
56 struct ObservablesHistory;
57 struct pull_t;
58 struct ReplicaExchangeParameters;
59 struct t_commrec;
60 struct t_fcdata;
61 struct t_forcerec;
62 struct t_filenm;
63 struct t_inputrec;
64 struct t_nrnb;
65 struct t_swap;
66 class t_state;
68 namespace gmx
70 enum class StartingBehavior;
71 class BoxDeformation;
72 class Constraints;
73 class PpForceWorkload;
74 class IMDOutputProvider;
75 class ImdSession;
76 class MDLogger;
77 class MDAtoms;
78 class StopHandlerBuilder;
79 struct MdrunOptions;
81 /*! \internal
82 * \brief The Simulator interface
84 * This is the general interface for any type of simulation type
85 * ran with GROMACS. This allows having a builder return different
86 * Simulator objects based on user input.
88 class ISimulator
90 public:
91 /*! \brief The simulation run
93 * This will be called by the owner of the simulator object. To be redefined
94 * by the child classes. This function is expected to run the simulation.
96 virtual void run() = 0;
97 //! Standard destructor
98 virtual ~ISimulator() = default;
99 //! The constructor
100 ISimulator(
101 FILE *fplog,
102 t_commrec *cr,
103 const gmx_multisim_t *ms,
104 const MDLogger &mdlog,
105 int nfile,
106 const t_filenm *fnm,
107 const gmx_output_env_t *oenv,
108 const MdrunOptions &mdrunOptions,
109 StartingBehavior startingBehavior,
110 gmx_vsite_t *vsite,
111 Constraints *constr,
112 gmx_enfrot *enforcedRotation,
113 BoxDeformation *deform,
114 IMDOutputProvider *outputProvider,
115 t_inputrec *inputrec,
116 ImdSession *imdSession,
117 pull_t *pull_work,
118 t_swap *swap,
119 gmx_mtop_t *top_global,
120 t_fcdata *fcd,
121 t_state *state_global,
122 ObservablesHistory *observablesHistory,
123 MDAtoms *mdAtoms,
124 t_nrnb *nrnb,
125 gmx_wallcycle *wcycle,
126 t_forcerec *fr,
127 gmx_enerdata_t *enerd,
128 PpForceWorkload *ppForceWorkload,
129 const ReplicaExchangeParameters &replExParams,
130 gmx_membed_t *membed,
131 gmx_walltime_accounting *walltime_accounting,
132 std::unique_ptr<StopHandlerBuilder> stopHandlerBuilder,
133 bool doRerun) :
134 fplog(fplog),
135 cr(cr),
136 ms(ms),
137 mdlog(mdlog),
138 nfile(nfile),
139 fnm(fnm),
140 oenv(oenv),
141 mdrunOptions(mdrunOptions),
142 startingBehavior(startingBehavior),
143 vsite(vsite),
144 constr(constr),
145 enforcedRotation(enforcedRotation),
146 deform(deform),
147 outputProvider(outputProvider),
148 inputrec(inputrec),
149 imdSession(imdSession),
150 pull_work(pull_work),
151 swap(swap),
152 top_global(top_global),
153 fcd(fcd),
154 state_global(state_global),
155 observablesHistory(observablesHistory),
156 mdAtoms(mdAtoms),
157 nrnb(nrnb),
158 wcycle(wcycle),
159 fr(fr),
160 enerd(enerd),
161 ppForceWorkload(ppForceWorkload),
162 replExParams(replExParams),
163 membed(membed),
164 walltime_accounting(walltime_accounting),
165 stopHandlerBuilder(std::move(stopHandlerBuilder)),
166 doRerun(doRerun)
169 protected:
170 //! Handles logging.
171 FILE *fplog;
172 //! Handles communication.
173 t_commrec *cr;
174 //! Coordinates multi-simulations.
175 const gmx_multisim_t *ms;
176 //! Handles logging.
177 const MDLogger &mdlog;
178 //! Count of input file options.
179 int nfile;
180 //! Content of input file options.
181 const t_filenm *fnm;
182 //! Handles writing text output.
183 const gmx_output_env_t *oenv;
184 //! Contains command-line options to mdrun.
185 const MdrunOptions &mdrunOptions;
186 //! Whether the simulation will start afresh, or restart with/without appending.
187 StartingBehavior startingBehavior;
188 //! Handles virtual sites.
189 gmx_vsite_t *vsite;
190 //! Handles constraints.
191 Constraints *constr;
192 //! Handles enforced rotation.
193 gmx_enfrot *enforcedRotation;
194 //! Handles box deformation.
195 BoxDeformation *deform;
196 //! Handles writing output files.
197 IMDOutputProvider *outputProvider;
198 //! Contains user input mdp options.
199 t_inputrec *inputrec;
200 //! The Interactive Molecular Dynamics session.
201 ImdSession *imdSession;
202 //! The pull work object.
203 pull_t *pull_work;
204 //! The coordinate-swapping session.
205 t_swap *swap;
206 //! Full system topology.
207 gmx_mtop_t *top_global;
208 //! Helper struct for force calculations.
209 t_fcdata *fcd;
210 //! Full simulation state (only non-nullptr on master rank).
211 t_state *state_global;
212 //! History of simulation observables.
213 ObservablesHistory *observablesHistory;
214 //! Atom parameters for this domain.
215 MDAtoms *mdAtoms;
216 //! Manages flop accounting.
217 t_nrnb *nrnb;
218 //! Manages wall cycle accounting.
219 gmx_wallcycle *wcycle;
220 //! Parameters for force calculations.
221 t_forcerec *fr;
222 //! Data for energy output.
223 gmx_enerdata_t *enerd;
224 //! Schedule of force-calculation work each step for this task.
225 PpForceWorkload *ppForceWorkload;
226 //! Parameters for replica exchange algorihtms.
227 const ReplicaExchangeParameters &replExParams;
228 //! Parameters for membrane embedding.
229 gmx_membed_t *membed;
230 //! Manages wall time accounting.
231 gmx_walltime_accounting *walltime_accounting;
232 //! Registers stop conditions
233 std::unique_ptr<StopHandlerBuilder> stopHandlerBuilder;
234 //! Whether we're doing a rerun.
235 bool doRerun;
239 } // namespace gmx
241 #endif //GMX_MDRUN_ISIMULATOR_H