SimulatorBuilder.add() for StopHandlerBuilder.
[gromacs.git] / src / gromacs / mdrun / simulatorbuilder.cpp
blob7f52cc13295e6eca99ab90299861e43713036a31
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/state.h"
47 #include "gromacs/modularsimulator/modularsimulator.h"
48 #include "gromacs/topology/topology.h"
50 #include "legacysimulator.h"
53 namespace gmx
56 // The build function will use members in a future change, and so should not be static.
57 //! Build a Simulator object
58 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
59 std::unique_ptr<ISimulator> SimulatorBuilder::build(bool useModularSimulator,
60 FILE* fplog,
61 t_commrec* cr,
62 const gmx_multisim_t* ms,
63 const MDLogger& mdlog,
64 int nfile,
65 const t_filenm* fnm,
66 const gmx_output_env_t* oenv,
67 const MdrunOptions& mdrunOptions,
68 StartingBehavior startingBehavior,
69 VirtualSitesHandler* vsite,
70 Constraints* constr,
71 gmx_enfrot* enforcedRotation,
72 BoxDeformation* deform,
73 IMDOutputProvider* outputProvider,
74 const MdModulesNotifier& mdModulesNotifier,
75 t_inputrec* inputrec,
76 ImdSession* imdSession,
77 pull_t* pull_work,
78 t_swap* swap,
79 gmx_mtop_t* top_global,
80 t_state* state_global,
81 ObservablesHistory* observablesHistory,
82 MDAtoms* mdAtoms,
83 t_nrnb* nrnb,
84 gmx_wallcycle* wcycle,
85 t_forcerec* fr,
86 gmx_enerdata_t* enerd,
87 gmx_ekindata_t* ekind,
88 MdrunScheduleWorkload* runScheduleWork,
89 const ReplicaExchangeParameters& replExParams,
90 gmx_membed_t* membed,
91 gmx_walltime_accounting* walltime_accounting,
92 bool doRerun)
94 if (!stopHandlerBuilder_)
96 throw APIError("You must add a StopHandlerBuilder before calling build().");
99 if (useModularSimulator)
101 // NOLINTNEXTLINE(modernize-make-unique): make_unique does not work with private constructor
102 return std::unique_ptr<ModularSimulator>(new ModularSimulator(
103 fplog, cr, ms, mdlog, nfile, fnm, oenv, mdrunOptions, startingBehavior, vsite,
104 constr, enforcedRotation, deform, outputProvider, mdModulesNotifier, inputrec,
105 imdSession, pull_work, swap, top_global, state_global, observablesHistory, mdAtoms,
106 nrnb, wcycle, fr, enerd, ekind, runScheduleWork, replExParams, membed,
107 walltime_accounting, std::move(stopHandlerBuilder_), doRerun));
109 // NOLINTNEXTLINE(modernize-make-unique): make_unique does not work with private constructor
110 return std::unique_ptr<LegacySimulator>(new LegacySimulator(
111 fplog, cr, ms, mdlog, nfile, fnm, oenv, mdrunOptions, startingBehavior, vsite, constr,
112 enforcedRotation, deform, outputProvider, mdModulesNotifier, inputrec, imdSession,
113 pull_work, swap, top_global, state_global, observablesHistory, mdAtoms, nrnb, wcycle,
114 fr, enerd, ekind, runScheduleWork, replExParams, membed, walltime_accounting,
115 std::move(stopHandlerBuilder_), doRerun));
118 } // namespace gmx