Use LegacyInput.
[gromacs.git] / src / gromacs / mdrun / simulatorbuilder.cpp
bloba7129095abcd43e1b8145fe195651468bf67c036
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 "simulatorbuilder.h"
44 #include <memory>
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"
55 namespace gmx
58 //! \brief Build a Simulator object
59 std::unique_ptr<ISimulator> SimulatorBuilder::build(bool useModularSimulator,
60 BoxDeformation* deform,
61 IMDOutputProvider* outputProvider,
62 const MdModulesNotifier& mdModulesNotifier,
63 ImdSession* imdSession,
64 pull_t* pull_work,
65 t_swap* swap,
66 gmx_mtop_t* top_global,
67 MDAtoms* mdAtoms,
68 const ReplicaExchangeParameters& replExParams)
70 // TODO: Reduce protocol complexity.
71 // Investigate individual paramters. Identify default-constructable parameters and clarify
72 // usage requirements.
73 if (!stopHandlerBuilder_)
75 throw APIError("You must add a StopHandlerBuilder before calling build().");
77 if (!membedHolder_)
79 throw APIError("You must add a MembedHolder before calling build().");
81 if (!simulatorStateData_)
83 throw APIError("Simulator State Data has not been added to the builder");
85 if (!simulatorConfig_)
87 throw APIError("Simulator config should be set before building the simulator");
89 if (!simulatorEnv_)
91 throw APIError("You must add a SimulatorEnv before calling build().");
93 if (!profiling_)
95 throw APIError("You must add a Profiling before calling build().");
97 if (!constraintsParam_)
99 throw APIError("You must add a ConstraintsParam before calling build().");
101 if (!legacyInput_)
103 throw APIError("You must add a LegacyInput before calling build().");
105 if (!replicaExchangeParameters_)
107 throw APIError("You must add a ReplicaExchangeParameters before calling build().");
109 if (!interactiveMD_)
111 throw APIError("You must add a InteractiveMD before calling build().");
113 if (!simulatorModules_)
115 throw APIError("You must add a SimulatorModules before calling build().");
117 if (!centerOfMassPulling_)
119 throw APIError("You must add a CenterOfMassPulling before calling build().");
121 if (!ionSwapping_)
123 throw APIError("You must add a IonSwapping before calling build().");
125 if (!topologyData_)
127 throw APIError("You must add a TopologyData before calling build().");
130 if (useModularSimulator)
132 // NOLINTNEXTLINE(modernize-make-unique): make_unique does not work with private constructor
133 return std::unique_ptr<ModularSimulator>(new ModularSimulator(
134 simulatorEnv_->fplog_, simulatorEnv_->commRec_, simulatorEnv_->multisimCommRec_,
135 simulatorEnv_->logger_, legacyInput_->numFile, legacyInput_->filenames,
136 simulatorEnv_->outputEnv_, simulatorConfig_->mdrunOptions_,
137 simulatorConfig_->startingBehavior_, constraintsParam_->vsite,
138 constraintsParam_->constr, constraintsParam_->enforcedRotation, deform,
139 outputProvider, mdModulesNotifier, legacyInput_->inputrec, imdSession, pull_work,
140 swap, top_global, simulatorStateData_->globalState_p,
141 simulatorStateData_->observablesHistory_p, mdAtoms, profiling_->nrnb,
142 profiling_->wallCycle, legacyInput_->forceRec, simulatorStateData_->enerdata_p,
143 simulatorStateData_->ekindata_p, simulatorConfig_->runScheduleWork_, replExParams,
144 membedHolder_->membed(), profiling_->walltimeAccounting,
145 std::move(stopHandlerBuilder_), simulatorConfig_->mdrunOptions_.rerun));
147 // NOLINTNEXTLINE(modernize-make-unique): make_unique does not work with private constructor
148 return std::unique_ptr<LegacySimulator>(new LegacySimulator(
149 simulatorEnv_->fplog_, simulatorEnv_->commRec_, simulatorEnv_->multisimCommRec_,
150 simulatorEnv_->logger_, legacyInput_->numFile, legacyInput_->filenames,
151 simulatorEnv_->outputEnv_, simulatorConfig_->mdrunOptions_,
152 simulatorConfig_->startingBehavior_, constraintsParam_->vsite,
153 constraintsParam_->constr, constraintsParam_->enforcedRotation, deform,
154 outputProvider, mdModulesNotifier, legacyInput_->inputrec, imdSession, pull_work,
155 swap, top_global, simulatorStateData_->globalState_p,
156 simulatorStateData_->observablesHistory_p, mdAtoms, profiling_->nrnb,
157 profiling_->wallCycle, legacyInput_->forceRec, simulatorStateData_->enerdata_p,
158 simulatorStateData_->ekindata_p, simulatorConfig_->runScheduleWork_, replExParams,
159 membedHolder_->membed(), profiling_->walltimeAccounting,
160 std::move(stopHandlerBuilder_), simulatorConfig_->mdrunOptions_.rerun));
163 void SimulatorBuilder::add(MembedHolder&& membedHolder)
165 membedHolder_ = std::make_unique<MembedHolder>(std::move(membedHolder));
169 } // namespace gmx