2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2019-2020, 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
46 #include "gromacs/mdlib/vsite.h"
47 #include "gromacs/utility/gmxassert.h"
48 #include "gromacs/utility/mdmodulenotification.h"
50 #include "replicaexchange.h"
52 class energyhistory_t
;
53 struct gmx_ekindata_t
;
54 struct gmx_enerdata_t
;
57 struct gmx_multisim_t
;
58 struct gmx_output_env_t
;
60 struct gmx_walltime_accounting
;
61 struct ObservablesHistory
;
73 enum class StartingBehavior
;
76 class MdrunScheduleWorkload
;
78 class IMDOutputProvider
;
83 class StopHandlerBuilder
;
86 struct SimulatorConfig
89 SimulatorConfig(const MdrunOptions
& mdrunOptions
,
90 StartingBehavior startingBehavior
,
91 MdrunScheduleWorkload
* runScheduleWork
) :
92 mdrunOptions_(mdrunOptions
),
93 startingBehavior_(startingBehavior
),
94 runScheduleWork_(runScheduleWork
)
97 // TODO: Specify copy and move semantics.
99 const MdrunOptions
& mdrunOptions_
;
100 StartingBehavior startingBehavior_
;
101 MdrunScheduleWorkload
* runScheduleWork_
;
105 // TODO: Reconsider the name.
106 struct SimulatorStateData
108 t_state
* globalState_p
;
109 ObservablesHistory
* observablesHistory_p
;
110 gmx_enerdata_t
* enerdata_p
;
111 gmx_ekindata_t
* ekindata_p
;
113 SimulatorStateData(t_state
* globalState
,
114 ObservablesHistory
* observablesHistory
,
115 gmx_enerdata_t
* enerdata
,
116 gmx_ekindata_t
* ekindata
) :
117 globalState_p(globalState
),
118 observablesHistory_p(observablesHistory
),
119 enerdata_p(enerdata
),
124 SimulatorStateData(const SimulatorStateData
& simulatorStateData
) = default;
130 SimulatorEnv(FILE* fplog
,
132 gmx_multisim_t
* multisimCommRec
,
133 const MDLogger
& logger
,
134 gmx_output_env_t
* outputEnv
) :
137 multisimCommRec_
{ multisimCommRec
},
139 outputEnv_
{ outputEnv
}
145 const gmx_multisim_t
* multisimCommRec_
;
146 const MDLogger
& logger_
;
147 const gmx_output_env_t
* outputEnv_
;
153 Profiling(t_nrnb
* nrnb
, gmx_walltime_accounting
* walltimeAccounting
, gmx_wallcycle
* wallCycle
) :
155 wallCycle(wallCycle
),
156 walltimeAccounting(walltimeAccounting
)
161 gmx_wallcycle
* wallCycle
;
162 gmx_walltime_accounting
* walltimeAccounting
;
165 class ConstraintsParam
168 ConstraintsParam(Constraints
* constraints
, gmx_enfrot
* enforcedRotation
, VirtualSitesHandler
* vSite
) :
170 enforcedRotation(enforcedRotation
),
176 gmx_enfrot
* enforcedRotation
;
177 VirtualSitesHandler
* vsite
;
183 LegacyInput(int filenamesSize
,
184 const t_filenm
* filenamesData
,
185 t_inputrec
* inputRec
,
186 t_forcerec
* forceRec
) :
187 numFile(filenamesSize
),
188 filenames(filenamesData
),
194 const t_filenm
* filenames
;
195 t_inputrec
* inputrec
;
196 t_forcerec
* forceRec
;
199 /*! \brief SimulatorBuilder parameter type for InteractiveMD.
201 * Conveys a non-owning pointer to implementation details.
206 explicit InteractiveMD(ImdSession
* imdSession
) : imdSession(imdSession
) {}
208 ImdSession
* imdSession
;
211 class SimulatorModules
214 SimulatorModules(IMDOutputProvider
* mdOutputProvider
, const MdModulesNotifier
& notifier
) :
215 outputProvider(mdOutputProvider
),
216 mdModulesNotifier(notifier
)
220 IMDOutputProvider
* outputProvider
;
221 const MdModulesNotifier
& mdModulesNotifier
;
224 class CenterOfMassPulling
227 explicit CenterOfMassPulling(pull_t gmx_unused
* pPull
) {}
233 IonSwapping(t_swap gmx_unused
* pSwap
) {}
239 TopologyData(gmx_mtop_t gmx_unused
* pMtop
, MDAtoms gmx_unused
* pAtoms
) {}
243 * \brief Class preparing the creation of Simulator objects
245 * Objects of this class build Simulator objects, which in turn are used to
246 * run molecular simulations.
248 class SimulatorBuilder
251 void add(MembedHolder
&& membedHolder
);
253 void add(std::unique_ptr
<StopHandlerBuilder
> stopHandlerBuilder
)
255 stopHandlerBuilder_
= std::move(stopHandlerBuilder
);
258 void add(SimulatorStateData
&& simulatorStateData
)
260 simulatorStateData_
= std::make_unique
<SimulatorStateData
>(simulatorStateData
);
263 void add(SimulatorConfig
&& simulatorConfig
)
265 // Note: SimulatorConfig appears to the compiler to be trivially copyable,
266 // but this may not be safe and may change in the future.
267 simulatorConfig_
= std::make_unique
<SimulatorConfig
>(simulatorConfig
);
270 void add(SimulatorEnv
&& simulatorEnv
)
272 simulatorEnv_
= std::make_unique
<SimulatorEnv
>(simulatorEnv
);
275 void add(Profiling
&& profiling
) { profiling_
= std::make_unique
<Profiling
>(profiling
); }
277 void add(ConstraintsParam
&& constraintsParam
)
279 constraintsParam_
= std::make_unique
<ConstraintsParam
>(constraintsParam
);
282 void add(LegacyInput
&& legacyInput
)
284 legacyInput_
= std::make_unique
<LegacyInput
>(legacyInput
);
287 void add(ReplicaExchangeParameters
&& replicaExchangeParameters
)
289 replicaExchangeParameters_
=
290 std::make_unique
<ReplicaExchangeParameters
>(replicaExchangeParameters
);
293 void add(InteractiveMD
&& interactiveMd
)
295 interactiveMD_
= std::make_unique
<InteractiveMD
>(interactiveMd
);
298 void add(SimulatorModules
&& simulatorModules
)
300 simulatorModules_
= std::make_unique
<SimulatorModules
>(simulatorModules
);
303 void add(CenterOfMassPulling
&& centerOfMassPulling
)
305 centerOfMassPulling_
= std::make_unique
<CenterOfMassPulling
>(centerOfMassPulling
);
308 void add(IonSwapping
&& ionSwapping
)
310 ionSwapping_
= std::make_unique
<IonSwapping
>(ionSwapping
);
313 void add(TopologyData
&& topologyData
)
315 topologyData_
= std::make_unique
<TopologyData
>(topologyData
);
318 /*! \brief Build a Simulator object based on input data
320 * Return a pointer to a simulation object. The use of a parameter
321 * pack insulates the builder from changes to the arguments of the
324 * \throws gmx::APIError if expected set-up methods have not been called before build()
326 * \return Unique pointer to a Simulator object
328 std::unique_ptr
<ISimulator
> build(bool useModularSimulator
,
329 BoxDeformation
* deform
,
332 gmx_mtop_t
* top_global
,
334 const ReplicaExchangeParameters
& replExParams
);
337 // Note: we use std::unique_ptr instead of std::optional because we want to
338 // allow for opaque types at the discretion of the module developer.
339 std::unique_ptr
<SimulatorConfig
> simulatorConfig_
;
340 std::unique_ptr
<MembedHolder
> membedHolder_
;
341 std::unique_ptr
<StopHandlerBuilder
> stopHandlerBuilder_
;
342 std::unique_ptr
<SimulatorStateData
> simulatorStateData_
;
343 std::unique_ptr
<SimulatorEnv
> simulatorEnv_
;
344 std::unique_ptr
<Profiling
> profiling_
;
345 std::unique_ptr
<ConstraintsParam
> constraintsParam_
;
346 std::unique_ptr
<LegacyInput
> legacyInput_
;
347 std::unique_ptr
<ReplicaExchangeParameters
> replicaExchangeParameters_
;
348 std::unique_ptr
<InteractiveMD
> interactiveMD_
;
349 std::unique_ptr
<SimulatorModules
> simulatorModules_
;
350 std::unique_ptr
<CenterOfMassPulling
> centerOfMassPulling_
;
351 std::unique_ptr
<IonSwapping
> ionSwapping_
;
352 std::unique_ptr
<TopologyData
> topologyData_
;
357 #endif // GMX_MDRUN_SIMULATORBUILDER_SIMULATORBUILDER_H