2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
37 * Implements classes in moduletest.h.
39 * \author Mark Abraham <mark.j.abraham@gmail.com>
40 * \ingroup module_mdrun_integration_tests
44 #include "moduletest.h"
50 #include "gromacs/gmxana/gmx_ana.h"
51 #include "gromacs/gmxpreprocess/grompp.h"
52 #include "gromacs/hardware/detecthardware.h"
53 #include "gromacs/options/basicoptions.h"
54 #include "gromacs/options/ioptionscontainer.h"
55 #include "gromacs/tools/convert_tpr.h"
56 #include "gromacs/utility/basedefinitions.h"
57 #include "gromacs/utility/basenetwork.h"
58 #include "gromacs/utility/gmxmpi.h"
59 #include "gromacs/utility/textwriter.h"
60 #include "programs/mdrun/mdrun_main.h"
62 #include "testutils/cmdlinetest.h"
63 #include "testutils/mpitest.h"
64 #include "testutils/testfilemanager.h"
65 #include "testutils/testoptions.h"
72 /********************************************************************
79 #if GMX_OPENMP || defined(DOXYGEN)
80 //! Number of OpenMP threads for child mdrun call.
81 int g_numOpenMPThreads = 1;
84 GMX_TEST_OPTIONS(MdrunTestOptions, options)
86 GMX_UNUSED_VALUE(options);
88 options->addOption(IntegerOption("ntomp").store(&g_numOpenMPThreads)
89 .description("Number of OpenMP threads for child mdrun calls"));
96 SimulationRunner::SimulationRunner(TestFileManager *fileManager) :
97 fullPrecisionTrajectoryFileName_(fileManager->getTemporaryFilePath(".trr")),
98 mdpOutputFileName_(fileManager->getTemporaryFilePath("output.mdp")),
99 tprFileName_(fileManager->getTemporaryFilePath(".tpr")),
100 logFileName_(fileManager->getTemporaryFilePath(".log")),
101 edrFileName_(fileManager->getTemporaryFilePath(".edr")),
102 mtxFileName_(fileManager->getTemporaryFilePath(".mtx")),
105 fileManager_(*fileManager)
108 GMX_RELEASE_ASSERT(gmx_mpi_initialized(), "MPI system not initialized for mdrun tests");
112 // TODO The combination of defaulting to Verlet cut-off scheme, NVE,
113 // and verlet-buffer-tolerance = -1 gives a grompp error. If we keep
114 // things that way, this function should be renamed. For now,
115 // we use the Verlet scheme and hard-code a tolerance.
116 // TODO There is possible outstanding unexplained behaviour of mdp
117 // input parsing e.g. Redmine 2074, so this particular set of mdp
118 // contents is also tested with GetIrTest in gmxpreprocess-test.
120 SimulationRunner::useEmptyMdpFile()
122 useStringAsMdpFile(R"(cutoff-scheme = Verlet
123 verlet-buffer-tolerance = 0.005)");
127 SimulationRunner::useStringAsMdpFile(const char *mdpString)
129 useStringAsMdpFile(std::string(mdpString));
133 SimulationRunner::useStringAsMdpFile(const std::string &mdpString)
135 mdpInputContents_ = mdpString;
139 SimulationRunner::useStringAsNdxFile(const char *ndxString)
141 gmx::TextWriter::writeFileFromString(ndxFileName_, ndxString);
145 SimulationRunner::useTopG96AndNdxFromDatabase(const std::string &name)
147 topFileName_ = gmx::test::TestFileManager::getInputFilePath(name + ".top");
148 groFileName_ = gmx::test::TestFileManager::getInputFilePath(name + ".g96");
149 ndxFileName_ = gmx::test::TestFileManager::getInputFilePath(name + ".ndx");
153 SimulationRunner::useTopGroAndNdxFromDatabase(const std::string &name)
155 topFileName_ = gmx::test::TestFileManager::getInputFilePath(name + ".top");
156 groFileName_ = gmx::test::TestFileManager::getInputFilePath(name + ".gro");
157 ndxFileName_ = gmx::test::TestFileManager::getInputFilePath(name + ".ndx");
161 SimulationRunner::useGroFromDatabase(const char *name)
163 groFileName_ = gmx::test::TestFileManager::getInputFilePath((std::string(name) + ".gro").c_str());
167 SimulationRunner::callGromppOnThisRank(const CommandLine &callerRef)
169 const std::string mdpInputFileName(fileManager_.getTemporaryFilePath("input.mdp"));
170 gmx::TextWriter::writeFileFromString(mdpInputFileName, mdpInputContents_);
173 caller.append("grompp");
174 caller.merge(callerRef);
175 caller.addOption("-f", mdpInputFileName);
176 if (!ndxFileName_.empty())
178 caller.addOption("-n", ndxFileName_);
180 caller.addOption("-p", topFileName_);
181 caller.addOption("-c", groFileName_);
182 caller.addOption("-r", groFileName_);
184 caller.addOption("-po", mdpOutputFileName_);
185 caller.addOption("-o", tprFileName_);
187 return gmx_grompp(caller.argc(), caller.argv());
191 SimulationRunner::callGromppOnThisRank()
193 return callGromppOnThisRank(CommandLine());
197 SimulationRunner::callGrompp(const CommandLine &callerRef)
201 // When compiled with external MPI, we're trying to run mdrun with
202 // MPI, but we need to make sure that we only do grompp on one
204 if (0 == gmx_node_rank())
207 returnValue = callGromppOnThisRank(callerRef);
210 // Make sure rank zero has written the .tpr file before other
211 // ranks try to read it. Thread-MPI and serial do this just fine
213 MPI_Barrier(MPI_COMM_WORLD);
219 SimulationRunner::callGrompp()
221 return callGrompp(CommandLine());
225 SimulationRunner::changeTprNsteps(int nsteps)
228 caller.append("convert-tpr");
229 caller.addOption("-nsteps", nsteps);
230 // Because the operation is to change the .tpr, we replace the
231 // file. TODO Do we need to delete an automatic backup?
232 caller.addOption("-s", tprFileName_);
233 caller.addOption("-o", tprFileName_);
235 return gmx_convert_tpr(caller.argc(), caller.argv());
239 SimulationRunner::callNmeig()
241 /* Conforming to style guide by not passing a non-const reference
242 to this function. Passing a non-const reference might make it
243 easier to write code that incorrectly re-uses callerRef after
244 the call to this function. */
247 caller.append("nmeig");
248 caller.addOption("-s", tprFileName_);
249 caller.addOption("-f", mtxFileName_);
250 // Ignore the overall translation and rotation in the
251 // first six eigenvectors.
252 caller.addOption("-first", "7");
253 // No need to check more than a number of output values.
254 caller.addOption("-last", "50");
255 caller.addOption("-xvg", "none");
257 return gmx_nmeig(caller.argc(), caller.argv());
261 SimulationRunner::callMdrun(const CommandLine &callerRef)
263 /* Conforming to style guide by not passing a non-const reference
264 to this function. Passing a non-const reference might make it
265 easier to write code that incorrectly re-uses callerRef after
266 the call to this function. */
269 caller.append("mdrun");
270 caller.merge(callerRef);
271 caller.addOption("-s", tprFileName_);
273 caller.addOption("-g", logFileName_);
274 caller.addOption("-e", edrFileName_);
275 caller.addOption("-mtx", mtxFileName_);
276 caller.addOption("-o", fullPrecisionTrajectoryFileName_);
277 caller.addOption("-x", reducedPrecisionTrajectoryFileName_);
279 caller.addOption("-deffnm", fileManager_.getTemporaryFilePath("state"));
283 caller.addOption("-nsteps", nsteps_);
287 caller.addOption("-ntmpi", getNumberOfTestMpiRanks());
291 caller.addOption("-ntomp", g_numOpenMPThreads);
294 return gmx_mdrun(caller.argc(), caller.argv());
298 SimulationRunner::callMdrun()
300 return callMdrun(CommandLine());
305 MdrunTestFixtureBase::MdrunTestFixtureBase()
308 GMX_RELEASE_ASSERT(gmx_mpi_initialized(), "MPI system not initialized for mdrun tests");
312 MdrunTestFixtureBase::~MdrunTestFixtureBase()
318 MdrunTestFixture::MdrunTestFixture() : runner_(&fileManager_)
322 MdrunTestFixture::~MdrunTestFixture()
325 // fileManager_ should only clean up after all the ranks are done.
326 MPI_Barrier(MPI_COMM_WORLD);