Follow up to "Separate StatePropagatorData element" (!363)
[alexxy/gromacs.git] / src / gromacs / modularsimulator / modularsimulator.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*! \internal \file
36  * \brief Defines the modular simulator
37  *
38  * \author Pascal Merz <pascal.merz@me.com>
39  * \ingroup module_modularsimulator
40  */
41
42 #include "gmxpre.h"
43
44 #include "modularsimulator.h"
45
46 #include "gromacs/commandline/filenm.h"
47 #include "gromacs/domdec/domdec.h"
48 #include "gromacs/ewald/pme.h"
49 #include "gromacs/ewald/pme_load_balancing.h"
50 #include "gromacs/ewald/pme_pp.h"
51 #include "gromacs/gmxlib/network.h"
52 #include "gromacs/gmxlib/nrnb.h"
53 #include "gromacs/listed_forces/listed_forces.h"
54 #include "gromacs/mdlib/checkpointhandler.h"
55 #include "gromacs/mdlib/constr.h"
56 #include "gromacs/mdlib/coupling.h"
57 #include "gromacs/mdlib/energyoutput.h"
58 #include "gromacs/mdlib/mdatoms.h"
59 #include "gromacs/mdlib/resethandler.h"
60 #include "gromacs/mdlib/update.h"
61 #include "gromacs/mdrun/replicaexchange.h"
62 #include "gromacs/mdrun/shellfc.h"
63 #include "gromacs/mdrunutility/handlerestart.h"
64 #include "gromacs/mdrunutility/printtime.h"
65 #include "gromacs/mdtypes/commrec.h"
66 #include "gromacs/mdtypes/fcdata.h"
67 #include "gromacs/mdtypes/forcerec.h"
68 #include "gromacs/mdtypes/inputrec.h"
69 #include "gromacs/mdtypes/mdatom.h"
70 #include "gromacs/mdtypes/mdrunoptions.h"
71 #include "gromacs/mdtypes/observableshistory.h"
72 #include "gromacs/nbnxm/nbnxm.h"
73 #include "gromacs/topology/mtop_util.h"
74 #include "gromacs/topology/topology.h"
75 #include "gromacs/utility/fatalerror.h"
76
77 #include "compositesimulatorelement.h"
78 #include "computeglobalselement.h"
79 #include "constraintelement.h"
80 #include "energydata.h"
81 #include "forceelement.h"
82 #include "freeenergyperturbationdata.h"
83 #include "parrinellorahmanbarostat.h"
84 #include "propagator.h"
85 #include "signallers.h"
86 #include "simulatoralgorithm.h"
87 #include "statepropagatordata.h"
88 #include "trajectoryelement.h"
89 #include "vrescalethermostat.h"
90
91 namespace gmx
92 {
93 void ModularSimulator::run()
94 {
95     GMX_LOG(mdlog.info).asParagraph().appendText("Using the modular simulator.");
96
97     ModularSimulatorAlgorithmBuilder algorithmBuilder(compat::make_not_null(this));
98     auto                             algorithm = algorithmBuilder.build();
99
100     while (const auto* task = algorithm.getNextTask())
101     {
102         // execute task
103         (*task)();
104     }
105 }
106
107 std::unique_ptr<ISimulatorElement> ModularSimulatorAlgorithmBuilder::buildForces(
108         SignallerBuilder<NeighborSearchSignaller>* neighborSearchSignallerBuilder,
109         SignallerBuilder<EnergySignaller>*         energySignallerBuilder,
110         StatePropagatorData*                       statePropagatorDataPtr,
111         EnergyData*                                energyDataPtr,
112         FreeEnergyPerturbationData*                freeEnergyPerturbationDataPtr,
113         TopologyHolder*                            topologyHolder)
114 {
115     const bool isVerbose    = mdrunOptions.verbose;
116     const bool isDynamicBox = inputrecDynamicBox(inputrec);
117
118     auto forceElement = std::make_unique<ForceElement>(
119             statePropagatorDataPtr, energyDataPtr, freeEnergyPerturbationDataPtr, isVerbose,
120             isDynamicBox, fplog, cr, inputrec, mdAtoms, nrnb, fr, wcycle, runScheduleWork, vsite,
121             imdSession, pull_work, constr, top_global, enforcedRotation);
122     topologyHolder->registerClient(forceElement.get());
123     neighborSearchSignallerBuilder->registerSignallerClient(compat::make_not_null(forceElement.get()));
124     energySignallerBuilder->registerSignallerClient(compat::make_not_null(forceElement.get()));
125
126     // std::move *should* not be needed with c++-14, but clang-3.6 still requires it
127     return std::move(forceElement);
128 }
129
130 std::unique_ptr<ISimulatorElement> ModularSimulatorAlgorithmBuilder::buildIntegrator(
131         SignallerBuilder<NeighborSearchSignaller>* neighborSearchSignallerBuilder,
132         SignallerBuilder<LastStepSignaller>*       lastStepSignallerBuilder,
133         SignallerBuilder<EnergySignaller>*         energySignallerBuilder,
134         SignallerBuilder<LoggingSignaller>*        loggingSignallerBuilder,
135         SignallerBuilder<TrajectorySignaller>*     trajectorySignallerBuilder,
136         TrajectoryElementBuilder*                  trajectoryElementBuilder,
137         std::vector<ICheckpointHelperClient*>*     checkpointClients,
138         CheckBondedInteractionsCallbackPtr*        checkBondedInteractionsCallback,
139         compat::not_null<StatePropagatorData*>     statePropagatorDataPtr,
140         compat::not_null<EnergyData*>              energyDataPtr,
141         FreeEnergyPerturbationData*                freeEnergyPerturbationDataPtr,
142         bool                                       hasReadEkinState,
143         TopologyHolder*                            topologyHolder,
144         SimulationSignals*                         signals)
145 {
146     auto forceElement = buildForces(neighborSearchSignallerBuilder, energySignallerBuilder,
147                                     statePropagatorDataPtr, energyDataPtr,
148                                     freeEnergyPerturbationDataPtr, topologyHolder);
149
150     // list of elements owned by the simulator composite object
151     std::vector<std::unique_ptr<ISimulatorElement>> elementsOwnershipList;
152     // call list of the simulator composite object
153     std::vector<compat::not_null<ISimulatorElement*>> elementCallList;
154
155     std::function<void()> needToCheckNumberOfBondedInteractions;
156     if (inputrec->eI == eiMD)
157     {
158         auto computeGlobalsElement =
159                 std::make_unique<ComputeGlobalsElement<ComputeGlobalsAlgorithm::LeapFrog>>(
160                         statePropagatorDataPtr, energyDataPtr, freeEnergyPerturbationDataPtr,
161                         signals, nstglobalcomm_, fplog, mdlog, cr, inputrec, mdAtoms, nrnb, wcycle,
162                         fr, top_global, constr, hasReadEkinState);
163         topologyHolder->registerClient(computeGlobalsElement.get());
164         energySignallerBuilder->registerSignallerClient(compat::make_not_null(computeGlobalsElement.get()));
165         trajectorySignallerBuilder->registerSignallerClient(
166                 compat::make_not_null(computeGlobalsElement.get()));
167
168         *checkBondedInteractionsCallback =
169                 computeGlobalsElement->getCheckNumberOfBondedInteractionsCallback();
170
171         auto propagator = std::make_unique<Propagator<IntegrationStep::LeapFrog>>(
172                 inputrec->delta_t, statePropagatorDataPtr, mdAtoms, wcycle);
173
174         addToCallListAndMove(std::move(forceElement), elementCallList, elementsOwnershipList);
175         auto stateElement = compat::make_not_null(statePropagatorDataPtr->element());
176         trajectoryElementBuilder->registerWriterClient(stateElement);
177         trajectorySignallerBuilder->registerSignallerClient(stateElement);
178         lastStepSignallerBuilder->registerSignallerClient(stateElement);
179         checkpointClients->emplace_back(stateElement);
180         // we have a full microstate at time t here!
181         addToCallList(stateElement, elementCallList);
182         if (inputrec->etc == etcVRESCALE)
183         {
184             // TODO: With increased complexity of the propagator, this will need further development,
185             //       e.g. using propagators templated for velocity propagation policies and a builder
186             propagator->setNumVelocityScalingVariables(inputrec->opts.ngtc);
187             auto thermostat = std::make_unique<VRescaleThermostat>(
188                     inputrec->nsttcouple, -1, false, inputrec->ld_seed, inputrec->opts.ngtc,
189                     inputrec->delta_t * inputrec->nsttcouple, inputrec->opts.ref_t, inputrec->opts.tau_t,
190                     inputrec->opts.nrdf, energyDataPtr, propagator->viewOnVelocityScaling(),
191                     propagator->velocityScalingCallback(), state_global, cr, inputrec->bContinuation);
192             checkpointClients->emplace_back(thermostat.get());
193             energyDataPtr->setVRescaleThermostat(thermostat.get());
194             addToCallListAndMove(std::move(thermostat), elementCallList, elementsOwnershipList);
195         }
196
197         std::unique_ptr<ParrinelloRahmanBarostat> prBarostat = nullptr;
198         if (inputrec->epc == epcPARRINELLORAHMAN)
199         {
200             // Building the PR barostat here since it needs access to the propagator
201             // and we want to be able to move the propagator object
202             prBarostat = std::make_unique<ParrinelloRahmanBarostat>(
203                     inputrec->nstpcouple, -1, inputrec->delta_t * inputrec->nstpcouple,
204                     inputrec->init_step, propagator->viewOnPRScalingMatrix(),
205                     propagator->prScalingCallback(), statePropagatorDataPtr, energyDataPtr, fplog,
206                     inputrec, mdAtoms, state_global, cr, inputrec->bContinuation);
207             energyDataPtr->setParrinelloRahamnBarostat(prBarostat.get());
208             checkpointClients->emplace_back(prBarostat.get());
209         }
210         addToCallListAndMove(std::move(propagator), elementCallList, elementsOwnershipList);
211         if (constr)
212         {
213             auto constraintElement = std::make_unique<ConstraintsElement<ConstraintVariable::Positions>>(
214                     constr, statePropagatorDataPtr, energyDataPtr, freeEnergyPerturbationDataPtr,
215                     MASTER(cr), fplog, inputrec, mdAtoms->mdatoms());
216             auto constraintElementPtr = compat::make_not_null(constraintElement.get());
217             energySignallerBuilder->registerSignallerClient(constraintElementPtr);
218             trajectorySignallerBuilder->registerSignallerClient(constraintElementPtr);
219             loggingSignallerBuilder->registerSignallerClient(constraintElementPtr);
220
221             addToCallListAndMove(std::move(constraintElement), elementCallList, elementsOwnershipList);
222         }
223
224         addToCallListAndMove(std::move(computeGlobalsElement), elementCallList, elementsOwnershipList);
225         auto energyElement = compat::make_not_null(energyDataPtr->element());
226         trajectoryElementBuilder->registerWriterClient(energyElement);
227         trajectorySignallerBuilder->registerSignallerClient(energyElement);
228         energySignallerBuilder->registerSignallerClient(energyElement);
229         checkpointClients->emplace_back(energyElement);
230         // we have the energies at time t here!
231         addToCallList(energyElement, elementCallList);
232         if (prBarostat)
233         {
234             addToCallListAndMove(std::move(prBarostat), elementCallList, elementsOwnershipList);
235         }
236     }
237     else if (inputrec->eI == eiVV)
238     {
239         auto computeGlobalsElement =
240                 std::make_unique<ComputeGlobalsElement<ComputeGlobalsAlgorithm::VelocityVerlet>>(
241                         statePropagatorDataPtr, energyDataPtr, freeEnergyPerturbationDataPtr,
242                         signals, nstglobalcomm_, fplog, mdlog, cr, inputrec, mdAtoms, nrnb, wcycle,
243                         fr, &topologyHolder->globalTopology(), constr, hasReadEkinState);
244         topologyHolder->registerClient(computeGlobalsElement.get());
245         energySignallerBuilder->registerSignallerClient(compat::make_not_null(computeGlobalsElement.get()));
246         trajectorySignallerBuilder->registerSignallerClient(
247                 compat::make_not_null(computeGlobalsElement.get()));
248
249         *checkBondedInteractionsCallback =
250                 computeGlobalsElement->getCheckNumberOfBondedInteractionsCallback();
251
252         auto propagatorVelocities = std::make_unique<Propagator<IntegrationStep::VelocitiesOnly>>(
253                 inputrec->delta_t * 0.5, statePropagatorDataPtr, mdAtoms, wcycle);
254         auto propagatorVelocitiesAndPositions =
255                 std::make_unique<Propagator<IntegrationStep::VelocityVerletPositionsAndVelocities>>(
256                         inputrec->delta_t, statePropagatorDataPtr, mdAtoms, wcycle);
257
258         addToCallListAndMove(std::move(forceElement), elementCallList, elementsOwnershipList);
259
260         std::unique_ptr<ParrinelloRahmanBarostat> prBarostat = nullptr;
261         if (inputrec->epc == epcPARRINELLORAHMAN)
262         {
263             // Building the PR barostat here since it needs access to the propagator
264             // and we want to be able to move the propagator object
265             prBarostat = std::make_unique<ParrinelloRahmanBarostat>(
266                     inputrec->nstpcouple, -1, inputrec->delta_t * inputrec->nstpcouple,
267                     inputrec->init_step, propagatorVelocities->viewOnPRScalingMatrix(),
268                     propagatorVelocities->prScalingCallback(), statePropagatorDataPtr, energyDataPtr,
269                     fplog, inputrec, mdAtoms, state_global, cr, inputrec->bContinuation);
270             energyDataPtr->setParrinelloRahamnBarostat(prBarostat.get());
271             checkpointClients->emplace_back(prBarostat.get());
272         }
273         addToCallListAndMove(std::move(propagatorVelocities), elementCallList, elementsOwnershipList);
274         if (constr)
275         {
276             auto constraintElement = std::make_unique<ConstraintsElement<ConstraintVariable::Velocities>>(
277                     constr, statePropagatorDataPtr, energyDataPtr, freeEnergyPerturbationDataPtr,
278                     MASTER(cr), fplog, inputrec, mdAtoms->mdatoms());
279             energySignallerBuilder->registerSignallerClient(compat::make_not_null(constraintElement.get()));
280             trajectorySignallerBuilder->registerSignallerClient(
281                     compat::make_not_null(constraintElement.get()));
282             loggingSignallerBuilder->registerSignallerClient(
283                     compat::make_not_null(constraintElement.get()));
284
285             addToCallListAndMove(std::move(constraintElement), elementCallList, elementsOwnershipList);
286         }
287         addToCallList(compat::make_not_null(computeGlobalsElement.get()), elementCallList);
288         auto stateElement = compat::make_not_null(statePropagatorDataPtr->element());
289         trajectoryElementBuilder->registerWriterClient(stateElement);
290         trajectorySignallerBuilder->registerSignallerClient(stateElement);
291         lastStepSignallerBuilder->registerSignallerClient(stateElement);
292         checkpointClients->emplace_back(stateElement);
293         // we have a full microstate at time t here!
294         addToCallList(stateElement, elementCallList);
295         if (inputrec->etc == etcVRESCALE)
296         {
297             // TODO: With increased complexity of the propagator, this will need further development,
298             //       e.g. using propagators templated for velocity propagation policies and a builder
299             propagatorVelocitiesAndPositions->setNumVelocityScalingVariables(inputrec->opts.ngtc);
300             auto thermostat = std::make_unique<VRescaleThermostat>(
301                     inputrec->nsttcouple, 0, true, inputrec->ld_seed, inputrec->opts.ngtc,
302                     inputrec->delta_t * inputrec->nsttcouple, inputrec->opts.ref_t,
303                     inputrec->opts.tau_t, inputrec->opts.nrdf, energyDataPtr,
304                     propagatorVelocitiesAndPositions->viewOnVelocityScaling(),
305                     propagatorVelocitiesAndPositions->velocityScalingCallback(), state_global, cr,
306                     inputrec->bContinuation);
307             checkpointClients->emplace_back(thermostat.get());
308             energyDataPtr->setVRescaleThermostat(thermostat.get());
309             addToCallListAndMove(std::move(thermostat), elementCallList, elementsOwnershipList);
310         }
311         addToCallListAndMove(std::move(propagatorVelocitiesAndPositions), elementCallList,
312                              elementsOwnershipList);
313         if (constr)
314         {
315             auto constraintElement = std::make_unique<ConstraintsElement<ConstraintVariable::Positions>>(
316                     constr, statePropagatorDataPtr, energyDataPtr, freeEnergyPerturbationDataPtr,
317                     MASTER(cr), fplog, inputrec, mdAtoms->mdatoms());
318             energySignallerBuilder->registerSignallerClient(compat::make_not_null(constraintElement.get()));
319             trajectorySignallerBuilder->registerSignallerClient(
320                     compat::make_not_null(constraintElement.get()));
321             loggingSignallerBuilder->registerSignallerClient(
322                     compat::make_not_null(constraintElement.get()));
323
324             addToCallListAndMove(std::move(constraintElement), elementCallList, elementsOwnershipList);
325         }
326         addToCallListAndMove(std::move(computeGlobalsElement), elementCallList, elementsOwnershipList);
327         auto energyElement = compat::make_not_null(energyDataPtr->element());
328         trajectoryElementBuilder->registerWriterClient(energyElement);
329         trajectorySignallerBuilder->registerSignallerClient(energyElement);
330         energySignallerBuilder->registerSignallerClient(energyElement);
331         checkpointClients->emplace_back(energyElement);
332         // we have the energies at time t here!
333         addToCallList(energyElement, elementCallList);
334         if (prBarostat)
335         {
336             addToCallListAndMove(std::move(prBarostat), elementCallList, elementsOwnershipList);
337         }
338     }
339     else
340     {
341         gmx_fatal(FARGS, "Integrator not implemented for the modular simulator.");
342     }
343
344     auto integrator = std::make_unique<CompositeSimulatorElement>(std::move(elementCallList),
345                                                                   std::move(elementsOwnershipList));
346     // std::move *should* not be needed with c++-14, but clang-3.6 still requires it
347     return std::move(integrator);
348 }
349
350 bool ModularSimulator::isInputCompatible(bool                             exitOnFailure,
351                                          const t_inputrec*                inputrec,
352                                          bool                             doRerun,
353                                          const gmx_mtop_t&                globalTopology,
354                                          const gmx_multisim_t*            ms,
355                                          const ReplicaExchangeParameters& replExParams,
356                                          const t_fcdata*                  fcd,
357                                          bool                             doEssentialDynamics,
358                                          bool                             doMembed)
359 {
360     auto conditionalAssert = [exitOnFailure](bool condition, const char* message) {
361         if (exitOnFailure)
362         {
363             GMX_RELEASE_ASSERT(condition, message);
364         }
365         return condition;
366     };
367
368     bool isInputCompatible = true;
369
370     // GMX_USE_MODULAR_SIMULATOR allows to use modular simulator also for non-standard uses,
371     // such as the leap-frog integrator
372     const auto modularSimulatorExplicitlyTurnedOn = (getenv("GMX_USE_MODULAR_SIMULATOR") != nullptr);
373     // GMX_USE_MODULAR_SIMULATOR allows to use disable modular simulator for all uses,
374     // including the velocity-verlet integrator used by default
375     const auto modularSimulatorExplicitlyTurnedOff = (getenv("GMX_DISABLE_MODULAR_SIMULATOR") != nullptr);
376
377     GMX_RELEASE_ASSERT(
378             !(modularSimulatorExplicitlyTurnedOn && modularSimulatorExplicitlyTurnedOff),
379             "Cannot have both GMX_USE_MODULAR_SIMULATOR=ON and GMX_DISABLE_MODULAR_SIMULATOR=ON. "
380             "Unset one of the two environment variables to explicitly chose which simulator to "
381             "use, "
382             "or unset both to recover default behavior.");
383
384     GMX_RELEASE_ASSERT(
385             !(modularSimulatorExplicitlyTurnedOff && inputrec->eI == eiVV
386               && inputrec->epc == epcPARRINELLORAHMAN),
387             "Cannot use a Parrinello-Rahman barostat with md-vv and "
388             "GMX_DISABLE_MODULAR_SIMULATOR=ON, "
389             "as the Parrinello-Rahman barostat is not implemented in the legacy simulator. Unset "
390             "GMX_DISABLE_MODULAR_SIMULATOR or use a different pressure control algorithm.");
391
392     isInputCompatible =
393             isInputCompatible
394             && conditionalAssert(
395                        inputrec->eI == eiMD || inputrec->eI == eiVV,
396                        "Only integrators md and md-vv are supported by the modular simulator.");
397     isInputCompatible = isInputCompatible
398                         && conditionalAssert(inputrec->eI != eiMD || modularSimulatorExplicitlyTurnedOn,
399                                              "Set GMX_USE_MODULAR_SIMULATOR=ON to use the modular "
400                                              "simulator with integrator md.");
401     isInputCompatible =
402             isInputCompatible
403             && conditionalAssert(!doRerun, "Rerun is not supported by the modular simulator.");
404     isInputCompatible =
405             isInputCompatible
406             && conditionalAssert(
407                        inputrec->etc == etcNO || inputrec->etc == etcVRESCALE,
408                        "Only v-rescale thermostat is supported by the modular simulator.");
409     isInputCompatible =
410             isInputCompatible
411             && conditionalAssert(
412                        inputrec->epc == epcNO || inputrec->epc == epcPARRINELLORAHMAN,
413                        "Only Parrinello-Rahman barostat is supported by the modular simulator.");
414     isInputCompatible =
415             isInputCompatible
416             && conditionalAssert(
417                        !(inputrecNptTrotter(inputrec) || inputrecNphTrotter(inputrec)
418                          || inputrecNvtTrotter(inputrec)),
419                        "Legacy Trotter decomposition is not supported by the modular simulator.");
420     isInputCompatible = isInputCompatible
421                         && conditionalAssert(inputrec->efep == efepNO || inputrec->efep == efepYES
422                                                      || inputrec->efep == efepSLOWGROWTH,
423                                              "Expanded ensemble free energy calculation is not "
424                                              "supported by the modular simulator.");
425     isInputCompatible = isInputCompatible
426                         && conditionalAssert(!inputrec->bPull,
427                                              "Pulling is not supported by the modular simulator.");
428     isInputCompatible =
429             isInputCompatible
430             && conditionalAssert(inputrec->opts.ngacc == 1 && inputrec->opts.acc[0][XX] == 0.0
431                                          && inputrec->opts.acc[0][YY] == 0.0
432                                          && inputrec->opts.acc[0][ZZ] == 0.0 && inputrec->cos_accel == 0.0,
433                                  "Acceleration is not supported by the modular simulator.");
434     isInputCompatible =
435             isInputCompatible
436             && conditionalAssert(inputrec->opts.ngfrz == 1 && inputrec->opts.nFreeze[0][XX] == 0
437                                          && inputrec->opts.nFreeze[0][YY] == 0
438                                          && inputrec->opts.nFreeze[0][ZZ] == 0,
439                                  "Freeze groups are not supported by the modular simulator.");
440     isInputCompatible =
441             isInputCompatible
442             && conditionalAssert(
443                        inputrec->deform[XX][XX] == 0.0 && inputrec->deform[XX][YY] == 0.0
444                                && inputrec->deform[XX][ZZ] == 0.0 && inputrec->deform[YY][XX] == 0.0
445                                && inputrec->deform[YY][YY] == 0.0 && inputrec->deform[YY][ZZ] == 0.0
446                                && inputrec->deform[ZZ][XX] == 0.0 && inputrec->deform[ZZ][YY] == 0.0
447                                && inputrec->deform[ZZ][ZZ] == 0.0,
448                        "Deformation is not supported by the modular simulator.");
449     isInputCompatible =
450             isInputCompatible
451             && conditionalAssert(gmx_mtop_interaction_count(globalTopology, IF_VSITE) == 0,
452                                  "Virtual sites are not supported by the modular simulator.");
453     isInputCompatible = isInputCompatible
454                         && conditionalAssert(!inputrec->bDoAwh,
455                                              "AWH is not supported by the modular simulator.");
456     isInputCompatible =
457             isInputCompatible
458             && conditionalAssert(gmx_mtop_ftype_count(globalTopology, F_DISRES) == 0,
459                                  "Distance restraints are not supported by the modular simulator.");
460     isInputCompatible =
461             isInputCompatible
462             && conditionalAssert(
463                        gmx_mtop_ftype_count(globalTopology, F_ORIRES) == 0,
464                        "Orientation restraints are not supported by the modular simulator.");
465     isInputCompatible =
466             isInputCompatible
467             && conditionalAssert(ms == nullptr,
468                                  "Multi-sim are not supported by the modular simulator.");
469     isInputCompatible =
470             isInputCompatible
471             && conditionalAssert(replExParams.exchangeInterval == 0,
472                                  "Replica exchange is not supported by the modular simulator.");
473
474     int numEnsembleRestraintSystems;
475     if (fcd)
476     {
477         numEnsembleRestraintSystems = fcd->disres->nsystems;
478     }
479     else
480     {
481         auto distantRestraintEnsembleEnvVar = getenv("GMX_DISRE_ENSEMBLE_SIZE");
482         numEnsembleRestraintSystems =
483                 (ms != nullptr && distantRestraintEnsembleEnvVar != nullptr)
484                         ? static_cast<int>(strtol(distantRestraintEnsembleEnvVar, nullptr, 10))
485                         : 0;
486     }
487     isInputCompatible =
488             isInputCompatible
489             && conditionalAssert(numEnsembleRestraintSystems <= 1,
490                                  "Ensemble restraints are not supported by the modular simulator.");
491     isInputCompatible =
492             isInputCompatible
493             && conditionalAssert(!doSimulatedAnnealing(inputrec),
494                                  "Simulated annealing is not supported by the modular simulator.");
495     isInputCompatible =
496             isInputCompatible
497             && conditionalAssert(!inputrec->bSimTemp,
498                                  "Simulated tempering is not supported by the modular simulator.");
499     isInputCompatible = isInputCompatible
500                         && conditionalAssert(!inputrec->bExpanded,
501                                              "Expanded ensemble simulations are not supported by "
502                                              "the modular simulator.");
503     isInputCompatible =
504             isInputCompatible
505             && conditionalAssert(!doEssentialDynamics,
506                                  "Essential dynamics is not supported by the modular simulator.");
507     isInputCompatible = isInputCompatible
508                         && conditionalAssert(inputrec->eSwapCoords == eswapNO,
509                                              "Ion / water position swapping is not supported by "
510                                              "the modular simulator.");
511     isInputCompatible =
512             isInputCompatible
513             && conditionalAssert(!inputrec->bIMD,
514                                  "Interactive MD is not supported by the modular simulator.");
515     isInputCompatible =
516             isInputCompatible
517             && conditionalAssert(!doMembed,
518                                  "Membrane embedding is not supported by the modular simulator.");
519     // TODO: Change this to the boolean passed when we merge the user interface change for the GPU update.
520     isInputCompatible =
521             isInputCompatible
522             && conditionalAssert(
523                        getenv("GMX_FORCE_UPDATE_DEFAULT_GPU") == nullptr,
524                        "Integration on the GPU is not supported by the modular simulator.");
525     // Modular simulator is centered around NS updates
526     // TODO: think how to handle nstlist == 0
527     isInputCompatible = isInputCompatible
528                         && conditionalAssert(inputrec->nstlist != 0,
529                                              "Simulations without neighbor list update are not "
530                                              "supported by the modular simulator.");
531     isInputCompatible = isInputCompatible
532                         && conditionalAssert(!GMX_FAHCORE,
533                                              "GMX_FAHCORE not supported by the modular simulator.");
534
535     return isInputCompatible;
536 }
537
538 void ModularSimulator::checkInputForDisabledFunctionality()
539 {
540     isInputCompatible(true, inputrec, mdrunOptions.rerun, *top_global, ms, replExParams,
541                       &fr->listedForces->fcdata(), opt2bSet("-ei", nfile, fnm), membed != nullptr);
542     if (observablesHistory->edsamHistory)
543     {
544         gmx_fatal(FARGS,
545                   "The checkpoint is from a run with essential dynamics sampling, "
546                   "but the current run did not specify the -ei option. "
547                   "Either specify the -ei option to mdrun, or do not use this checkpoint file.");
548     }
549 }
550
551 } // namespace gmx