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 ReadCheckpointDataHolder;
81 enum class StartingBehavior;
82 class StopHandlerBuilder;
83 class VirtualSitesHandler;
86 * Simulation configuation settings.
88 struct SimulatorConfig
91 //! Build from settings for this simulation.
92 SimulatorConfig(const MdrunOptions& mdrunOptions,
93 StartingBehavior startingBehavior,
94 MdrunScheduleWorkload* runScheduleWork) :
95 mdrunOptions_(mdrunOptions),
96 startingBehavior_(startingBehavior),
97 runScheduleWork_(runScheduleWork)
100 // TODO: Specify copy and move semantics.
102 //! Handle to user options.
103 const MdrunOptions& mdrunOptions_;
104 //! How are we starting the simulation.
105 StartingBehavior startingBehavior_;
106 //! How are we scheduling the tasks for this simulation.
107 MdrunScheduleWorkload* runScheduleWork_;
112 * Data for a specific simulation state.
114 * \todo Think of a better name and annoy people that forget
115 * to add documentation for their code.
117 struct SimulatorStateData
119 //! Build collection of current state data.
120 SimulatorStateData(t_state* globalState,
121 ObservablesHistory* observablesHistory,
122 gmx_enerdata_t* enerdata,
123 gmx_ekindata_t* ekindata) :
124 globalState_p(globalState),
125 observablesHistory_p(observablesHistory),
126 enerdata_p(enerdata),
131 //! Can perform copy of current state.
132 SimulatorStateData(const SimulatorStateData& simulatorStateData) = default;
134 //! Handle to global state of the simulation.
135 t_state* globalState_p;
136 //! Handle to current simulation history.
137 ObservablesHistory* observablesHistory_p;
138 //! Handle to collected data for energy groups.
139 gmx_enerdata_t* enerdata_p;
140 //! Handle to collected data for kinectic energy.
141 gmx_ekindata_t* ekindata_p;
145 * Collection of environmental information for a simulation.
147 * \todo Fix doxygen checks.
152 //! Build from current simulation environment.
153 SimulatorEnv(FILE* fplog,
155 gmx_multisim_t* multisimCommRec,
156 const MDLogger& logger,
157 gmx_output_env_t* outputEnv) :
160 multisimCommRec_{ multisimCommRec },
162 outputEnv_{ outputEnv }
166 //! Handle to log file.
168 //! Handle to communication record.
170 //! Handle to multisim communication record.
171 const gmx_multisim_t* multisimCommRec_;
172 //! Handle to propper logging framework.
173 const MDLogger& logger_;
174 //! Handle to file output handling.
175 const gmx_output_env_t* outputEnv_;
179 * Collection of profiling information.
184 //! Build profiling information collection.
185 Profiling(t_nrnb* nrnb, gmx_walltime_accounting* walltimeAccounting, gmx_wallcycle* wallCycle) :
187 wallCycle(wallCycle),
188 walltimeAccounting(walltimeAccounting)
192 //! Handle to datastructure.
194 //! Handle to wallcycle stuff.
195 gmx_wallcycle* wallCycle;
196 //! Handle to wallcycle time accounting stuff.
197 gmx_walltime_accounting* walltimeAccounting;
201 * Collection of constraint parameters.
203 class ConstraintsParam
206 //! Build collection with handle to actual objects.
207 ConstraintsParam(Constraints* constraints, gmx_enfrot* enforcedRotation, VirtualSitesHandler* vSite) :
209 enforcedRotation(enforcedRotation),
214 //! Handle to constraint object.
216 //! Handle to information about using enforced rotation.
217 gmx_enfrot* enforcedRotation;
218 //! Handle to vsite stuff.
219 VirtualSitesHandler* vsite;
223 * Collection of legacy input information.
228 //! Build collection from legacy input data.
229 LegacyInput(int filenamesSize, const t_filenm* filenamesData, t_inputrec* inputRec, t_forcerec* forceRec) :
230 numFile(filenamesSize),
231 filenames(filenamesData),
237 //! Number of input files.
240 const t_filenm* filenames;
241 //! Handle to simulation input record.
242 t_inputrec* inputrec;
243 //! Handle to simulation force record.
244 t_forcerec* forceRec;
247 /*! \brief SimulatorBuilder parameter type for InteractiveMD.
249 * Conveys a non-owning pointer to implementation details.
251 * \todo If adding doxygen stubs actual add the full stub.
256 //! Create handle to IMD information.
257 explicit InteractiveMD(ImdSession* imdSession) : imdSession(imdSession) {}
259 //! Internal handle to IMD info.
260 ImdSession* imdSession;
263 class SimulatorModules
266 SimulatorModules(IMDOutputProvider* mdOutputProvider, const MDModulesNotifiers& notifiers) :
267 outputProvider(mdOutputProvider),
268 mdModulesNotifiers(notifiers)
272 IMDOutputProvider* outputProvider;
273 const MDModulesNotifiers& mdModulesNotifiers;
276 class CenterOfMassPulling
279 explicit CenterOfMassPulling(pull_t* pullWork) : pull_work(pullWork) {}
285 * Parameter type for IonSwapping SimulatorBuilder component.
287 * Conveys a non-owning pointer to implementation details.
289 * \todo Add full information.
295 IonSwapping(t_swap* ionSwap) : ionSwap(ionSwap) {}
297 //! Internal storage for handle.
302 * Collection of handles to topology information.
307 //! Build collection from simulation data.
308 TopologyData(const gmx_mtop_t& globalTopology, MDAtoms* mdAtoms) :
309 top_global(globalTopology),
314 //! Handle to global simulation topology.
315 const gmx_mtop_t& top_global;
316 //! Handle to information about MDAtoms.
321 * Handle to information about the box.
323 * Design note: The client may own the BoxDeformation via std::unique_ptr, but we are not
324 * transferring ownership at this time. (May be the subject of future changes.)
326 class BoxDeformationHandle
329 //! Build handle to box stuff.
330 BoxDeformationHandle(BoxDeformation* boxDeformation) : deform(boxDeformation) {}
332 //! Internal storage for handle.
333 BoxDeformation* deform;
337 * \brief Class preparing the creation of Simulator objects
339 * Objects of this class build Simulator objects, which in turn are used to
340 * run molecular simulations.
342 class SimulatorBuilder
345 void add(MembedHolder&& membedHolder);
347 void add(std::unique_ptr<StopHandlerBuilder> stopHandlerBuilder)
349 stopHandlerBuilder_ = std::move(stopHandlerBuilder);
352 void add(SimulatorStateData&& simulatorStateData)
354 simulatorStateData_ = std::make_unique<SimulatorStateData>(simulatorStateData);
357 void add(SimulatorConfig&& simulatorConfig)
359 // Note: SimulatorConfig appears to the compiler to be trivially copyable,
360 // but this may not be safe and may change in the future.
361 simulatorConfig_ = std::make_unique<SimulatorConfig>(simulatorConfig);
364 void add(SimulatorEnv&& simulatorEnv)
366 simulatorEnv_ = std::make_unique<SimulatorEnv>(simulatorEnv);
369 void add(Profiling&& profiling) { profiling_ = std::make_unique<Profiling>(profiling); }
371 void add(ConstraintsParam&& constraintsParam)
373 constraintsParam_ = std::make_unique<ConstraintsParam>(constraintsParam);
376 void add(LegacyInput&& legacyInput)
378 legacyInput_ = std::make_unique<LegacyInput>(legacyInput);
381 void add(ReplicaExchangeParameters&& replicaExchangeParameters);
383 void add(InteractiveMD&& interactiveMd)
385 interactiveMD_ = std::make_unique<InteractiveMD>(interactiveMd);
388 void add(SimulatorModules&& simulatorModules)
390 simulatorModules_ = std::make_unique<SimulatorModules>(simulatorModules);
393 void add(CenterOfMassPulling&& centerOfMassPulling)
395 centerOfMassPulling_ = std::make_unique<CenterOfMassPulling>(centerOfMassPulling);
398 void add(IonSwapping&& ionSwapping)
400 ionSwapping_ = std::make_unique<IonSwapping>(ionSwapping);
403 void add(TopologyData&& topologyData)
405 topologyData_ = std::make_unique<TopologyData>(topologyData);
408 void add(BoxDeformationHandle&& boxDeformation)
410 boxDeformation_ = std::make_unique<BoxDeformationHandle>(boxDeformation);
414 * \brief Pass the read checkpoint data for modular simulator
416 * Note that this is currently the point at which the ReadCheckpointDataHolder
417 * is fully filled. Consequently it stops being an object at which read
418 * operations from file are targeted, and becomes a read-only object from
419 * which elements read their data to recreate an earlier internal state.
421 * Currently, this behavior change is not enforced. Once input reading and
422 * simulator builder have matured, these restrictions could be imposed.
426 void add(std::unique_ptr<ReadCheckpointDataHolder> modularSimulatorCheckpointData);
428 /*! \brief Build a Simulator object based on input data
430 * Return a pointer to a simulation object. The use of a parameter
431 * pack insulates the builder from changes to the arguments of the
434 * \throws gmx::APIError if expected set-up methods have not been called before build()
436 * \return Unique pointer to a Simulator object
438 std::unique_ptr<ISimulator> build(bool useModularSimulator);
441 // Note: we use std::unique_ptr instead of std::optional because we want to
442 // allow for opaque types at the discretion of the module developer.
443 /*! \brief Collection of handles to individual information. */
445 std::unique_ptr<SimulatorConfig> simulatorConfig_;
446 std::unique_ptr<MembedHolder> membedHolder_;
447 std::unique_ptr<StopHandlerBuilder> stopHandlerBuilder_;
448 std::unique_ptr<SimulatorStateData> simulatorStateData_;
449 std::unique_ptr<SimulatorEnv> simulatorEnv_;
450 std::unique_ptr<Profiling> profiling_;
451 std::unique_ptr<ConstraintsParam> constraintsParam_;
452 std::unique_ptr<LegacyInput> legacyInput_;
453 std::unique_ptr<ReplicaExchangeParameters> replicaExchangeParameters_;
454 std::unique_ptr<InteractiveMD> interactiveMD_;
455 std::unique_ptr<SimulatorModules> simulatorModules_;
456 std::unique_ptr<CenterOfMassPulling> centerOfMassPulling_;
457 std::unique_ptr<IonSwapping> ionSwapping_;
458 std::unique_ptr<TopologyData> topologyData_;
459 std::unique_ptr<BoxDeformationHandle> boxDeformation_;
460 //! Contains checkpointing data for the modular simulator
461 std::unique_ptr<ReadCheckpointDataHolder> modularSimulatorCheckpointData_;
467 #endif // GMX_MDRUN_SIMULATORBUILDER_SIMULATORBUILDER_H