Update instructions in containers.rst
[gromacs.git] / src / gromacs / mdrun / simulatorbuilder.cpp
blob8a0e4edf1b6b946d841d7a388102b6950b6c51e0
1 /*
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.
35 /*! \internal \file
36 * \brief Defines the simulator builder for mdrun
38 * \author Pascal Merz <pascal.merz@me.com>
39 * \ingroup module_mdrun
42 #include "gmxpre.h"
44 #include "simulatorbuilder.h"
46 #include <memory>
48 #include "gromacs/mdlib/vsite.h"
49 #include "gromacs/mdtypes/checkpointdata.h"
50 #include "gromacs/mdtypes/mdrunoptions.h"
51 #include "gromacs/mdtypes/state.h"
52 #include "gromacs/modularsimulator/modularsimulator.h"
53 #include "gromacs/topology/topology.h"
54 #include "gromacs/utility/mdmodulenotification.h"
56 #include "legacysimulator.h"
57 #include "membedholder.h"
58 #include "replicaexchange.h"
61 namespace gmx
64 //! \brief Build a Simulator object
65 std::unique_ptr<ISimulator> SimulatorBuilder::build(bool useModularSimulator)
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().");
74 if (!membedHolder_)
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");
86 if (!simulatorEnv_)
88 throw APIError("You must add a SimulatorEnv before calling build().");
90 if (!profiling_)
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().");
98 if (!legacyInput_)
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().");
106 if (!interactiveMD_)
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().");
118 if (!ionSwapping_)
120 throw APIError("You must add a IonSwapping before calling build().");
122 if (!topologyData_)
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 std::make_unique<LegacySimulatorData>(simulatorEnv_->fplog_,
132 simulatorEnv_->commRec_,
133 simulatorEnv_->multisimCommRec_,
134 simulatorEnv_->logger_,
135 legacyInput_->numFile,
136 legacyInput_->filenames,
137 simulatorEnv_->outputEnv_,
138 simulatorConfig_->mdrunOptions_,
139 simulatorConfig_->startingBehavior_,
140 constraintsParam_->vsite,
141 constraintsParam_->constr,
142 constraintsParam_->enforcedRotation,
143 boxDeformation_->deform,
144 simulatorModules_->outputProvider,
145 simulatorModules_->mdModulesNotifier,
146 legacyInput_->inputrec,
147 interactiveMD_->imdSession,
148 centerOfMassPulling_->pull_work,
149 ionSwapping_->ionSwap,
150 topologyData_->top_global,
151 simulatorStateData_->globalState_p,
152 simulatorStateData_->observablesHistory_p,
153 topologyData_->mdAtoms,
154 profiling_->nrnb,
155 profiling_->wallCycle,
156 legacyInput_->forceRec,
157 simulatorStateData_->enerdata_p,
158 simulatorStateData_->ekindata_p,
159 simulatorConfig_->runScheduleWork_,
160 *replicaExchangeParameters_,
161 membedHolder_->membed(),
162 profiling_->walltimeAccounting,
163 std::move(stopHandlerBuilder_),
164 simulatorConfig_->mdrunOptions_.rerun),
165 std::move(modularSimulatorCheckpointData_)));
167 // NOLINTNEXTLINE(modernize-make-unique): make_unique does not work with private constructor
168 return std::unique_ptr<LegacySimulator>(new LegacySimulator(simulatorEnv_->fplog_,
169 simulatorEnv_->commRec_,
170 simulatorEnv_->multisimCommRec_,
171 simulatorEnv_->logger_,
172 legacyInput_->numFile,
173 legacyInput_->filenames,
174 simulatorEnv_->outputEnv_,
175 simulatorConfig_->mdrunOptions_,
176 simulatorConfig_->startingBehavior_,
177 constraintsParam_->vsite,
178 constraintsParam_->constr,
179 constraintsParam_->enforcedRotation,
180 boxDeformation_->deform,
181 simulatorModules_->outputProvider,
182 simulatorModules_->mdModulesNotifier,
183 legacyInput_->inputrec,
184 interactiveMD_->imdSession,
185 centerOfMassPulling_->pull_work,
186 ionSwapping_->ionSwap,
187 topologyData_->top_global,
188 simulatorStateData_->globalState_p,
189 simulatorStateData_->observablesHistory_p,
190 topologyData_->mdAtoms,
191 profiling_->nrnb,
192 profiling_->wallCycle,
193 legacyInput_->forceRec,
194 simulatorStateData_->enerdata_p,
195 simulatorStateData_->ekindata_p,
196 simulatorConfig_->runScheduleWork_,
197 *replicaExchangeParameters_,
198 membedHolder_->membed(),
199 profiling_->walltimeAccounting,
200 std::move(stopHandlerBuilder_),
201 simulatorConfig_->mdrunOptions_.rerun));
204 void SimulatorBuilder::add(MembedHolder&& membedHolder)
206 membedHolder_ = std::make_unique<MembedHolder>(std::move(membedHolder));
209 void SimulatorBuilder::add(ReplicaExchangeParameters&& replicaExchangeParameters)
211 replicaExchangeParameters_ = std::make_unique<ReplicaExchangeParameters>(replicaExchangeParameters);
214 void SimulatorBuilder::add(std::unique_ptr<ReadCheckpointDataHolder> modularSimulatorCheckpointData)
216 modularSimulatorCheckpointData_ = std::move(modularSimulatorCheckpointData);
220 } // namespace gmx