2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2019-2020,2021, 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.
36 * \brief Declares the simulator builder for mdrun
38 * \author Pascal Merz <pascal.merz@me.com>
39 * \ingroup module_mdrun
41 #ifndef GMX_MDRUN_SIMULATORBUILDER_H
42 #define GMX_MDRUN_SIMULATORBUILDER_H
47 class energyhistory_t;
49 struct gmx_enerdata_t;
52 struct gmx_multisim_t;
53 struct gmx_output_env_t;
55 struct gmx_walltime_accounting;
56 struct ObservablesHistory;
58 struct ReplicaExchangeParameters;
71 class IMDOutputProvider;
74 class MdrunScheduleWorkload;
78 struct MDModulesNotifiers;
80 class ObservablesReducerBuilder;
81 class ReadCheckpointDataHolder;
82 enum class StartingBehavior;
83 class StopHandlerBuilder;
84 class VirtualSitesHandler;
87 * Simulation configuation settings.
89 struct SimulatorConfig
92 //! Build from settings for this simulation.
93 SimulatorConfig(const MdrunOptions& mdrunOptions,
94 StartingBehavior startingBehavior,
95 MdrunScheduleWorkload* runScheduleWork) :
96 mdrunOptions_(mdrunOptions), startingBehavior_(startingBehavior), runScheduleWork_(runScheduleWork)
99 // TODO: Specify copy and move semantics.
101 //! Handle to user options.
102 const MdrunOptions& mdrunOptions_;
103 //! How are we starting the simulation.
104 StartingBehavior startingBehavior_;
105 //! How are we scheduling the tasks for this simulation.
106 MdrunScheduleWorkload* runScheduleWork_;
111 * Data for a specific simulation state.
113 * \todo Think of a better name and annoy people that forget
114 * to add documentation for their code.
116 struct SimulatorStateData
118 //! Build collection of current state data.
119 SimulatorStateData(t_state* globalState,
120 ObservablesHistory* observablesHistory,
121 gmx_enerdata_t* enerdata,
122 gmx_ekindata_t* ekindata) :
123 globalState_p(globalState),
124 observablesHistory_p(observablesHistory),
125 enerdata_p(enerdata),
130 //! Can perform copy of current state.
131 SimulatorStateData(const SimulatorStateData& simulatorStateData) = default;
133 //! Handle to global state of the simulation.
134 t_state* globalState_p;
135 //! Handle to current simulation history.
136 ObservablesHistory* observablesHistory_p;
137 //! Handle to collected data for energy groups.
138 gmx_enerdata_t* enerdata_p;
139 //! Handle to collected data for kinectic energy.
140 gmx_ekindata_t* ekindata_p;
144 * Collection of environmental information for a simulation.
146 * \todo Fix doxygen checks.
151 //! Build from current simulation environment.
152 SimulatorEnv(FILE* fplog,
154 gmx_multisim_t* multisimCommRec,
155 const MDLogger& logger,
156 gmx_output_env_t* outputEnv,
157 ObservablesReducerBuilder* observablesReducerBuilder) :
158 fplog_{ fplog }, commRec_{ commRec }, multisimCommRec_{ multisimCommRec }, logger_{ logger }, outputEnv_{ outputEnv }, observablesReducerBuilder_{ observablesReducerBuilder }
162 //! Handle to log file.
164 //! Handle to communication record.
166 //! Handle to multisim communication record.
167 const gmx_multisim_t* multisimCommRec_;
168 //! Handle to propper logging framework.
169 const MDLogger& logger_;
170 //! Handle to file output handling.
171 const gmx_output_env_t* outputEnv_;
172 //! Builder for coordinator of reduction for observables
173 ObservablesReducerBuilder* observablesReducerBuilder_;
177 * Collection of profiling information.
182 //! Build profiling information collection.
183 Profiling(t_nrnb* nrnb, gmx_walltime_accounting* walltimeAccounting, gmx_wallcycle* wallCycle) :
184 nrnb(nrnb), wallCycle(wallCycle), walltimeAccounting(walltimeAccounting)
188 //! Handle to datastructure.
190 //! Handle to wallcycle stuff.
191 gmx_wallcycle* wallCycle;
192 //! Handle to wallcycle time accounting stuff.
193 gmx_walltime_accounting* walltimeAccounting;
197 * Collection of constraint parameters.
199 class ConstraintsParam
202 //! Build collection with handle to actual objects.
203 ConstraintsParam(Constraints* constraints, gmx_enfrot* enforcedRotation, VirtualSitesHandler* vSite) :
204 constr(constraints), enforcedRotation(enforcedRotation), vsite(vSite)
208 //! Handle to constraint object.
210 //! Handle to information about using enforced rotation.
211 gmx_enfrot* enforcedRotation;
212 //! Handle to vsite stuff.
213 VirtualSitesHandler* vsite;
217 * Collection of legacy input information.
222 //! Build collection from legacy input data.
223 LegacyInput(int filenamesSize, const t_filenm* filenamesData, t_inputrec* inputRec, t_forcerec* forceRec) :
224 numFile(filenamesSize), filenames(filenamesData), inputrec(inputRec), forceRec(forceRec)
228 //! Number of input files.
231 const t_filenm* filenames;
232 //! Handle to simulation input record.
233 t_inputrec* inputrec;
234 //! Handle to simulation force record.
235 t_forcerec* forceRec;
238 /*! \brief SimulatorBuilder parameter type for InteractiveMD.
240 * Conveys a non-owning pointer to implementation details.
242 * \todo If adding doxygen stubs actual add the full stub.
247 //! Create handle to IMD information.
248 explicit InteractiveMD(ImdSession* imdSession) : imdSession(imdSession) {}
250 //! Internal handle to IMD info.
251 ImdSession* imdSession;
254 class SimulatorModules
257 SimulatorModules(IMDOutputProvider* mdOutputProvider, const MDModulesNotifiers& notifiers) :
258 outputProvider(mdOutputProvider), mdModulesNotifiers(notifiers)
262 IMDOutputProvider* outputProvider;
263 const MDModulesNotifiers& mdModulesNotifiers;
266 class CenterOfMassPulling
269 explicit CenterOfMassPulling(pull_t* pullWork) : pull_work(pullWork) {}
275 * Parameter type for IonSwapping SimulatorBuilder component.
277 * Conveys a non-owning pointer to implementation details.
279 * \todo Add full information.
285 IonSwapping(t_swap* ionSwap) : ionSwap(ionSwap) {}
287 //! Internal storage for handle.
292 * Collection of handles to topology information.
297 //! Build collection from simulation data.
298 TopologyData(const gmx_mtop_t& globalTopology, MDAtoms* mdAtoms) :
299 top_global(globalTopology), mdAtoms(mdAtoms)
303 //! Handle to global simulation topology.
304 const gmx_mtop_t& top_global;
305 //! Handle to information about MDAtoms.
310 * Handle to information about the box.
312 * Design note: The client may own the BoxDeformation via std::unique_ptr, but we are not
313 * transferring ownership at this time. (May be the subject of future changes.)
315 class BoxDeformationHandle
318 //! Build handle to box stuff.
319 BoxDeformationHandle(BoxDeformation* boxDeformation) : deform(boxDeformation) {}
321 //! Internal storage for handle.
322 BoxDeformation* deform;
326 * \brief Class preparing the creation of Simulator objects
328 * Objects of this class build Simulator objects, which in turn are used to
329 * run molecular simulations.
331 class SimulatorBuilder
334 void add(MembedHolder&& membedHolder);
336 void add(std::unique_ptr<StopHandlerBuilder> stopHandlerBuilder)
338 stopHandlerBuilder_ = std::move(stopHandlerBuilder);
341 void add(SimulatorStateData&& simulatorStateData)
343 simulatorStateData_ = std::make_unique<SimulatorStateData>(simulatorStateData);
346 void add(SimulatorConfig&& simulatorConfig)
348 // Note: SimulatorConfig appears to the compiler to be trivially copyable,
349 // but this may not be safe and may change in the future.
350 simulatorConfig_ = std::make_unique<SimulatorConfig>(simulatorConfig);
353 void add(SimulatorEnv&& simulatorEnv)
355 simulatorEnv_ = std::make_unique<SimulatorEnv>(simulatorEnv);
358 void add(Profiling&& profiling) { profiling_ = std::make_unique<Profiling>(profiling); }
360 void add(ConstraintsParam&& constraintsParam)
362 constraintsParam_ = std::make_unique<ConstraintsParam>(constraintsParam);
365 void add(LegacyInput&& legacyInput)
367 legacyInput_ = std::make_unique<LegacyInput>(legacyInput);
370 void add(ReplicaExchangeParameters&& replicaExchangeParameters);
372 void add(InteractiveMD&& interactiveMd)
374 interactiveMD_ = std::make_unique<InteractiveMD>(interactiveMd);
377 void add(SimulatorModules&& simulatorModules)
379 simulatorModules_ = std::make_unique<SimulatorModules>(simulatorModules);
382 void add(CenterOfMassPulling&& centerOfMassPulling)
384 centerOfMassPulling_ = std::make_unique<CenterOfMassPulling>(centerOfMassPulling);
387 void add(IonSwapping&& ionSwapping)
389 ionSwapping_ = std::make_unique<IonSwapping>(ionSwapping);
392 void add(TopologyData&& topologyData)
394 topologyData_ = std::make_unique<TopologyData>(topologyData);
397 void add(BoxDeformationHandle&& boxDeformation)
399 boxDeformation_ = std::make_unique<BoxDeformationHandle>(boxDeformation);
403 * \brief Pass the read checkpoint data for modular simulator
405 * Note that this is currently the point at which the ReadCheckpointDataHolder
406 * is fully filled. Consequently it stops being an object at which read
407 * operations from file are targeted, and becomes a read-only object from
408 * which elements read their data to recreate an earlier internal state.
410 * Currently, this behavior change is not enforced. Once input reading and
411 * simulator builder have matured, these restrictions could be imposed.
415 void add(std::unique_ptr<ReadCheckpointDataHolder> modularSimulatorCheckpointData);
417 /*! \brief Build a Simulator object based on input data
419 * Return a pointer to a simulation object. The use of a parameter
420 * pack insulates the builder from changes to the arguments of the
423 * \throws gmx::APIError if expected set-up methods have not been called before build()
425 * \return Unique pointer to a Simulator object
427 std::unique_ptr<ISimulator> build(bool useModularSimulator);
430 // Note: we use std::unique_ptr instead of std::optional because we want to
431 // allow for opaque types at the discretion of the module developer.
432 /*! \brief Collection of handles to individual information. */
434 std::unique_ptr<SimulatorConfig> simulatorConfig_;
435 std::unique_ptr<MembedHolder> membedHolder_;
436 std::unique_ptr<StopHandlerBuilder> stopHandlerBuilder_;
437 std::unique_ptr<SimulatorStateData> simulatorStateData_;
438 std::unique_ptr<SimulatorEnv> simulatorEnv_;
439 std::unique_ptr<Profiling> profiling_;
440 std::unique_ptr<ConstraintsParam> constraintsParam_;
441 std::unique_ptr<LegacyInput> legacyInput_;
442 std::unique_ptr<ReplicaExchangeParameters> replicaExchangeParameters_;
443 std::unique_ptr<InteractiveMD> interactiveMD_;
444 std::unique_ptr<SimulatorModules> simulatorModules_;
445 std::unique_ptr<CenterOfMassPulling> centerOfMassPulling_;
446 std::unique_ptr<IonSwapping> ionSwapping_;
447 std::unique_ptr<TopologyData> topologyData_;
448 std::unique_ptr<BoxDeformationHandle> boxDeformation_;
449 //! Contains checkpointing data for the modular simulator
450 std::unique_ptr<ReadCheckpointDataHolder> modularSimulatorCheckpointData_;
456 #endif // GMX_MDRUN_SIMULATORBUILDER_SIMULATORBUILDER_H