2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
5 * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
6 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 * and including many others, as listed in the AUTHORS file in the
8 * top-level source directory and at http://www.gromacs.org.
10 * GROMACS is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1
13 * of the License, or (at your option) any later version.
15 * GROMACS is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with GROMACS; if not, see
22 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * If you want to redistribute modifications to GROMACS, please
26 * consider that scientific software is very special. Version
27 * control is crucial - bugs must be traceable. We will be happy to
28 * consider code for inclusion in the official distribution, but
29 * derived work must not be called official GROMACS. Details are found
30 * in the README & COPYING files - if they are missing, get the
31 * official version at http://www.gromacs.org.
33 * To help us fund GROMACS development, we humbly ask that you cite
34 * the research papers on the package. Check out http://www.gromacs.org.
38 * Implements classes in moduletest.h.
40 * \author Mark Abraham <mark.j.abraham@gmail.com>
41 * \ingroup module_mdrun_integration_tests
45 #include "moduletest.h"
51 #include "gromacs/gmxana/gmx_ana.h"
52 #include "gromacs/gmxpreprocess/grompp.h"
53 #include "gromacs/hardware/detecthardware.h"
54 #include "gromacs/options/basicoptions.h"
55 #include "gromacs/options/ioptionscontainer.h"
56 #include "gromacs/tools/convert_tpr.h"
57 #include "gromacs/utility/basedefinitions.h"
58 #include "gromacs/utility/basenetwork.h"
59 #include "gromacs/utility/gmxmpi.h"
60 #include "gromacs/utility/textwriter.h"
61 #include "programs/mdrun/mdrun_main.h"
63 #include "testutils/cmdlinetest.h"
64 #include "testutils/mpitest.h"
65 #include "testutils/testfilemanager.h"
66 #include "testutils/testoptions.h"
73 /********************************************************************
80 #if GMX_OPENMP || defined(DOXYGEN)
81 //! Number of OpenMP threads for child mdrun call.
82 int g_numOpenMPThreads = 1;
85 GMX_TEST_OPTIONS(MdrunTestOptions, options)
87 GMX_UNUSED_VALUE(options);
90 IntegerOption("ntomp").store(&g_numOpenMPThreads).description("Number of OpenMP threads for child mdrun calls"));
97 SimulationRunner::SimulationRunner(TestFileManager* fileManager) :
98 fullPrecisionTrajectoryFileName_(fileManager->getTemporaryFilePath(".trr")),
99 mdpOutputFileName_(fileManager->getTemporaryFilePath("output.mdp")),
100 tprFileName_(fileManager->getTemporaryFilePath(".tpr")),
101 logFileName_(fileManager->getTemporaryFilePath(".log")),
102 edrFileName_(fileManager->getTemporaryFilePath(".edr")),
103 mtxFileName_(fileManager->getTemporaryFilePath(".mtx")),
106 fileManager_(*fileManager)
109 GMX_RELEASE_ASSERT(gmx_mpi_initialized(), "MPI system not initialized for mdrun tests");
113 // TODO The combination of defaulting to Verlet cut-off scheme, NVE,
114 // and verlet-buffer-tolerance = -1 gives a grompp error. If we keep
115 // things that way, this function should be renamed. For now,
116 // we use the Verlet scheme and hard-code a tolerance.
117 // TODO There is possible outstanding unexplained behaviour of mdp
118 // input parsing e.g. Issue #2074, so this particular set of mdp
119 // contents is also tested with GetIrTest in gmxpreprocess-test.
120 void SimulationRunner::useEmptyMdpFile()
122 useStringAsMdpFile("");
125 void SimulationRunner::useStringAsMdpFile(const char* mdpString)
127 useStringAsMdpFile(std::string(mdpString));
130 void SimulationRunner::useStringAsMdpFile(const std::string& mdpString)
132 mdpInputContents_ = mdpString;
135 void SimulationRunner::useStringAsNdxFile(const char* ndxString)
137 gmx::TextWriter::writeFileFromString(ndxFileName_, ndxString);
140 void SimulationRunner::useTopG96AndNdxFromDatabase(const std::string& name)
142 topFileName_ = gmx::test::TestFileManager::getInputFilePath(name + ".top");
143 groFileName_ = gmx::test::TestFileManager::getInputFilePath(name + ".g96");
144 ndxFileName_ = gmx::test::TestFileManager::getInputFilePath(name + ".ndx");
147 void SimulationRunner::useTopGroAndNdxFromDatabase(const std::string& name)
149 topFileName_ = gmx::test::TestFileManager::getInputFilePath(name + ".top");
150 groFileName_ = gmx::test::TestFileManager::getInputFilePath(name + ".gro");
151 ndxFileName_ = gmx::test::TestFileManager::getInputFilePath(name + ".ndx");
154 void SimulationRunner::useGroFromDatabase(const char* name)
156 groFileName_ = gmx::test::TestFileManager::getInputFilePath((std::string(name) + ".gro").c_str());
159 int SimulationRunner::callGromppOnThisRank(const CommandLine& callerRef)
161 const std::string mdpInputFileName(fileManager_.getTemporaryFilePath("input.mdp"));
162 gmx::TextWriter::writeFileFromString(mdpInputFileName, mdpInputContents_);
165 caller.append("grompp");
166 caller.merge(callerRef);
167 caller.addOption("-f", mdpInputFileName);
168 if (!ndxFileName_.empty())
170 caller.addOption("-n", ndxFileName_);
172 caller.addOption("-p", topFileName_);
173 caller.addOption("-c", groFileName_);
174 caller.addOption("-r", groFileName_);
176 caller.addOption("-po", mdpOutputFileName_);
177 caller.addOption("-o", tprFileName_);
179 return gmx_grompp(caller.argc(), caller.argv());
182 int SimulationRunner::callGromppOnThisRank()
184 return callGromppOnThisRank(CommandLine());
187 int SimulationRunner::callGrompp(const CommandLine& callerRef)
191 // When compiled with external MPI, we're trying to run mdrun with
192 // MPI, but we need to make sure that we only do grompp on one
194 if (0 == gmx_node_rank())
197 returnValue = callGromppOnThisRank(callerRef);
200 // Make sure rank zero has written the .tpr file before other
201 // ranks try to read it. Thread-MPI and serial do this just fine
203 MPI_Barrier(MPI_COMM_WORLD);
208 int SimulationRunner::callGrompp()
210 return callGrompp(CommandLine());
213 int SimulationRunner::changeTprNsteps(int nsteps)
216 caller.append("convert-tpr");
217 caller.addOption("-nsteps", nsteps);
218 // Because the operation is to change the .tpr, we replace the
219 // file. TODO Do we need to delete an automatic backup?
220 caller.addOption("-s", tprFileName_);
221 caller.addOption("-o", tprFileName_);
223 return gmx_convert_tpr(caller.argc(), caller.argv());
226 int SimulationRunner::callNmeig()
228 /* Conforming to style guide by not passing a non-const reference
229 to this function. Passing a non-const reference might make it
230 easier to write code that incorrectly re-uses callerRef after
231 the call to this function. */
234 caller.append("nmeig");
235 caller.addOption("-s", tprFileName_);
236 caller.addOption("-f", mtxFileName_);
237 // Ignore the overall translation and rotation in the
238 // first six eigenvectors.
239 caller.addOption("-first", "7");
240 // No need to check more than a number of output values.
241 caller.addOption("-last", "50");
242 caller.addOption("-xvg", "none");
244 return gmx_nmeig(caller.argc(), caller.argv());
247 int SimulationRunner::callMdrun(const CommandLine& callerRef)
249 /* Conforming to style guide by not passing a non-const reference
250 to this function. Passing a non-const reference might make it
251 easier to write code that incorrectly re-uses callerRef after
252 the call to this function. */
255 caller.append("mdrun");
256 caller.merge(callerRef);
257 caller.addOption("-s", tprFileName_);
259 caller.addOption("-g", logFileName_);
260 caller.addOption("-e", edrFileName_);
261 caller.addOption("-mtx", mtxFileName_);
262 caller.addOption("-o", fullPrecisionTrajectoryFileName_);
263 caller.addOption("-x", reducedPrecisionTrajectoryFileName_);
265 caller.addOption("-deffnm", fileManager_.getTemporaryFilePath("state"));
269 caller.addOption("-nsteps", nsteps_);
273 caller.addOption("-ntmpi", getNumberOfTestMpiRanks());
277 caller.addOption("-ntomp", g_numOpenMPThreads);
280 return gmx_mdrun(caller.argc(), caller.argv());
283 int SimulationRunner::callMdrun()
285 return callMdrun(CommandLine());
290 MdrunTestFixtureBase::MdrunTestFixtureBase()
293 GMX_RELEASE_ASSERT(gmx_mpi_initialized(), "MPI system not initialized for mdrun tests");
297 MdrunTestFixtureBase::~MdrunTestFixtureBase() {}
301 MdrunTestFixture::MdrunTestFixture() : runner_(&fileManager_) {}
303 MdrunTestFixture::~MdrunTestFixture()
306 // fileManager_ should only clean up after all the ranks are done.
307 MPI_Barrier(MPI_COMM_WORLD);