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 Defines the simulator builder for mdrun
38 * \author Pascal Merz <pascal.merz@me.com>
39 * \ingroup module_mdrun
42 #include "simulatorbuilder.h"
46 #include "gromacs/mdtypes/mdrunoptions.h"
47 #include "gromacs/mdtypes/state.h"
48 #include "gromacs/modularsimulator/modularsimulator.h"
49 #include "gromacs/topology/topology.h"
51 #include "legacysimulator.h"
52 #include "membedholder.h"
58 //! \brief Build a Simulator object
59 std::unique_ptr
<ISimulator
> SimulatorBuilder::build(bool useModularSimulator
,
60 BoxDeformation
* deform
,
63 gmx_mtop_t
* top_global
,
65 const ReplicaExchangeParameters
& replExParams
)
67 // TODO: Reduce protocol complexity.
68 // Investigate individual paramters. Identify default-constructable parameters and clarify
69 // usage requirements.
70 if (!stopHandlerBuilder_
)
72 throw APIError("You must add a StopHandlerBuilder before calling build().");
76 throw APIError("You must add a MembedHolder before calling build().");
78 if (!simulatorStateData_
)
80 throw APIError("Simulator State Data has not been added to the builder");
82 if (!simulatorConfig_
)
84 throw APIError("Simulator config should be set before building the simulator");
88 throw APIError("You must add a SimulatorEnv before calling build().");
92 throw APIError("You must add a Profiling before calling build().");
94 if (!constraintsParam_
)
96 throw APIError("You must add a ConstraintsParam before calling build().");
100 throw APIError("You must add a LegacyInput before calling build().");
102 if (!replicaExchangeParameters_
)
104 throw APIError("You must add a ReplicaExchangeParameters before calling build().");
108 throw APIError("You must add a InteractiveMD before calling build().");
110 if (!simulatorModules_
)
112 throw APIError("You must add a SimulatorModules before calling build().");
114 if (!centerOfMassPulling_
)
116 throw APIError("You must add a CenterOfMassPulling before calling build().");
120 throw APIError("You must add a IonSwapping before calling build().");
124 throw APIError("You must add a TopologyData before calling build().");
127 if (useModularSimulator
)
129 // NOLINTNEXTLINE(modernize-make-unique): make_unique does not work with private constructor
130 return std::unique_ptr
<ModularSimulator
>(new ModularSimulator(
131 simulatorEnv_
->fplog_
, simulatorEnv_
->commRec_
, simulatorEnv_
->multisimCommRec_
,
132 simulatorEnv_
->logger_
, legacyInput_
->numFile
, legacyInput_
->filenames
,
133 simulatorEnv_
->outputEnv_
, simulatorConfig_
->mdrunOptions_
,
134 simulatorConfig_
->startingBehavior_
, constraintsParam_
->vsite
, constraintsParam_
->constr
,
135 constraintsParam_
->enforcedRotation
, deform
, simulatorModules_
->outputProvider
,
136 simulatorModules_
->mdModulesNotifier
, legacyInput_
->inputrec
, interactiveMD_
->imdSession
,
137 pull_work
, swap
, top_global
, simulatorStateData_
->globalState_p
,
138 simulatorStateData_
->observablesHistory_p
, mdAtoms
, profiling_
->nrnb
,
139 profiling_
->wallCycle
, legacyInput_
->forceRec
, simulatorStateData_
->enerdata_p
,
140 simulatorStateData_
->ekindata_p
, simulatorConfig_
->runScheduleWork_
, replExParams
,
141 membedHolder_
->membed(), profiling_
->walltimeAccounting
,
142 std::move(stopHandlerBuilder_
), simulatorConfig_
->mdrunOptions_
.rerun
));
144 // NOLINTNEXTLINE(modernize-make-unique): make_unique does not work with private constructor
145 return std::unique_ptr
<LegacySimulator
>(new LegacySimulator(
146 simulatorEnv_
->fplog_
, simulatorEnv_
->commRec_
, simulatorEnv_
->multisimCommRec_
,
147 simulatorEnv_
->logger_
, legacyInput_
->numFile
, legacyInput_
->filenames
,
148 simulatorEnv_
->outputEnv_
, simulatorConfig_
->mdrunOptions_
,
149 simulatorConfig_
->startingBehavior_
, constraintsParam_
->vsite
, constraintsParam_
->constr
,
150 constraintsParam_
->enforcedRotation
, deform
, simulatorModules_
->outputProvider
,
151 simulatorModules_
->mdModulesNotifier
, legacyInput_
->inputrec
, interactiveMD_
->imdSession
, pull_work
,
152 swap
, top_global
, simulatorStateData_
->globalState_p
,
153 simulatorStateData_
->observablesHistory_p
, mdAtoms
, profiling_
->nrnb
,
154 profiling_
->wallCycle
, legacyInput_
->forceRec
, simulatorStateData_
->enerdata_p
,
155 simulatorStateData_
->ekindata_p
, simulatorConfig_
->runScheduleWork_
, replExParams
,
156 membedHolder_
->membed(), profiling_
->walltimeAccounting
,
157 std::move(stopHandlerBuilder_
), simulatorConfig_
->mdrunOptions_
.rerun
));
160 void SimulatorBuilder::add(MembedHolder
&& membedHolder
)
162 membedHolder_
= std::make_unique
<MembedHolder
>(std::move(membedHolder
));