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 /*! \libinternal \file
36 * \brief Provides the modular simulator.
38 * Defines the ModularSimulator class. Provides checkUseModularSimulator() utility function
39 * to determine whether the ModularSimulator should be used.
41 * \author Pascal Merz <pascal.merz@me.com>
42 * \ingroup module_modularsimulator
44 * This header is currently the only part of the modular simulator module which is exposed.
45 * Mdrunner creates an object of type ModularSimulator (via SimulatorBuilder), and calls its
46 * run() method. Mdrunner also calls checkUseModularSimulator(...), which in turns calls a
47 * static method of ModularSimulator. This could easily become a free function if this requires
48 * more exposure than otherwise necessary.
50 #ifndef GROMACS_MODULARSIMULATOR_MODULARSIMULATOR_H
51 #define GROMACS_MODULARSIMULATOR_MODULARSIMULATOR_H
53 #include "gromacs/mdrun/isimulator.h"
55 struct CheckpointHeaderContents;
61 class ModularSimulatorAlgorithmBuilder;
62 class ReadCheckpointDataHolder;
65 * \ingroup module_modularsimulator
66 * \brief The modular simulator
68 * Based on the input given, this simulator builds independent elements and
69 * signallers and stores them in a respective vector. The run function
70 * runs the simulation by, in turn, building a task list from the elements
71 * for a predefined number of steps, then running the task list, and repeating
72 * until the stop criterion is fulfilled.
74 class ModularSimulator final : public ISimulator
80 //! Check for disabled functionality
81 static bool isInputCompatible(bool exitOnFailure,
82 const t_inputrec* inputrec,
84 const gmx_mtop_t& globalTopology,
85 const gmx_multisim_t* ms,
86 const ReplicaExchangeParameters& replExParams,
88 bool doEssentialDynamics,
91 //! Read everything that can be stored in t_trxframe from a checkpoint file
92 static void readCheckpointToTrxFrame(t_trxframe* fr,
93 ReadCheckpointDataHolder* readCheckpointDataHolder,
94 const CheckpointHeaderContents& checkpointHeaderContents);
96 // Only builder can construct
97 friend class SimulatorBuilder;
101 ModularSimulator(std::unique_ptr<LegacySimulatorData> legacySimulatorData,
102 std::unique_ptr<ReadCheckpointDataHolder> checkpointDataHolder);
104 //! Populate algorithm builder with elements
105 void addIntegrationElements(ModularSimulatorAlgorithmBuilder* builder);
107 //! Check for disabled functionality (during construction time)
108 void checkInputForDisabledFunctionality();
110 //! Pointer to legacy simulator data (TODO: Can we avoid using unique_ptr? #3628)
111 std::unique_ptr<LegacySimulatorData> legacySimulatorData_;
112 //! Input checkpoint data
113 std::unique_ptr<ReadCheckpointDataHolder> checkpointDataHolder_;
117 * \brief Whether or not to use the ModularSimulator
119 * GMX_DISABLE_MODULAR_SIMULATOR environment variable allows to disable modular simulator for
122 * See ModularSimulator::isInputCompatible() for function signature.
124 * \ingroup module_modularsimulator
126 template<typename... Ts>
127 auto checkUseModularSimulator(Ts&&... args)
128 -> decltype(ModularSimulator::isInputCompatible(std::forward<Ts>(args)...))
130 return ModularSimulator::isInputCompatible(std::forward<Ts>(args)...)
131 && getenv("GMX_DISABLE_MODULAR_SIMULATOR") == nullptr;
136 #endif // GROMACS_MODULARSIMULATOR_MODULARSIMULATOR_H