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("");
126 SimulationRunner::useStringAsMdpFile(const char *mdpString
)
128 useStringAsMdpFile(std::string(mdpString
));
132 SimulationRunner::useStringAsMdpFile(const std::string
&mdpString
)
134 mdpInputContents_
= mdpString
;
138 SimulationRunner::useStringAsNdxFile(const char *ndxString
)
140 gmx::TextWriter::writeFileFromString(ndxFileName_
, ndxString
);
144 SimulationRunner::useTopG96AndNdxFromDatabase(const std::string
&name
)
146 topFileName_
= gmx::test::TestFileManager::getInputFilePath(name
+ ".top");
147 groFileName_
= gmx::test::TestFileManager::getInputFilePath(name
+ ".g96");
148 ndxFileName_
= gmx::test::TestFileManager::getInputFilePath(name
+ ".ndx");
152 SimulationRunner::useTopGroAndNdxFromDatabase(const std::string
&name
)
154 topFileName_
= gmx::test::TestFileManager::getInputFilePath(name
+ ".top");
155 groFileName_
= gmx::test::TestFileManager::getInputFilePath(name
+ ".gro");
156 ndxFileName_
= gmx::test::TestFileManager::getInputFilePath(name
+ ".ndx");
160 SimulationRunner::useGroFromDatabase(const char *name
)
162 groFileName_
= gmx::test::TestFileManager::getInputFilePath((std::string(name
) + ".gro").c_str());
166 SimulationRunner::callGromppOnThisRank(const CommandLine
&callerRef
)
168 const std::string
mdpInputFileName(fileManager_
.getTemporaryFilePath("input.mdp"));
169 gmx::TextWriter::writeFileFromString(mdpInputFileName
, mdpInputContents_
);
172 caller
.append("grompp");
173 caller
.merge(callerRef
);
174 caller
.addOption("-f", mdpInputFileName
);
175 if (!ndxFileName_
.empty())
177 caller
.addOption("-n", ndxFileName_
);
179 caller
.addOption("-p", topFileName_
);
180 caller
.addOption("-c", groFileName_
);
181 caller
.addOption("-r", groFileName_
);
183 caller
.addOption("-po", mdpOutputFileName_
);
184 caller
.addOption("-o", tprFileName_
);
186 return gmx_grompp(caller
.argc(), caller
.argv());
190 SimulationRunner::callGromppOnThisRank()
192 return callGromppOnThisRank(CommandLine());
196 SimulationRunner::callGrompp(const CommandLine
&callerRef
)
200 // When compiled with external MPI, we're trying to run mdrun with
201 // MPI, but we need to make sure that we only do grompp on one
203 if (0 == gmx_node_rank())
206 returnValue
= callGromppOnThisRank(callerRef
);
209 // Make sure rank zero has written the .tpr file before other
210 // ranks try to read it. Thread-MPI and serial do this just fine
212 MPI_Barrier(MPI_COMM_WORLD
);
218 SimulationRunner::callGrompp()
220 return callGrompp(CommandLine());
224 SimulationRunner::changeTprNsteps(int nsteps
)
227 caller
.append("convert-tpr");
228 caller
.addOption("-nsteps", nsteps
);
229 // Because the operation is to change the .tpr, we replace the
230 // file. TODO Do we need to delete an automatic backup?
231 caller
.addOption("-s", tprFileName_
);
232 caller
.addOption("-o", tprFileName_
);
234 return gmx_convert_tpr(caller
.argc(), caller
.argv());
238 SimulationRunner::callNmeig()
240 /* Conforming to style guide by not passing a non-const reference
241 to this function. Passing a non-const reference might make it
242 easier to write code that incorrectly re-uses callerRef after
243 the call to this function. */
246 caller
.append("nmeig");
247 caller
.addOption("-s", tprFileName_
);
248 caller
.addOption("-f", mtxFileName_
);
249 // Ignore the overall translation and rotation in the
250 // first six eigenvectors.
251 caller
.addOption("-first", "7");
252 // No need to check more than a number of output values.
253 caller
.addOption("-last", "50");
254 caller
.addOption("-xvg", "none");
256 return gmx_nmeig(caller
.argc(), caller
.argv());
260 SimulationRunner::callMdrun(const CommandLine
&callerRef
)
262 /* Conforming to style guide by not passing a non-const reference
263 to this function. Passing a non-const reference might make it
264 easier to write code that incorrectly re-uses callerRef after
265 the call to this function. */
268 caller
.append("mdrun");
269 caller
.merge(callerRef
);
270 caller
.addOption("-s", tprFileName_
);
272 caller
.addOption("-g", logFileName_
);
273 caller
.addOption("-e", edrFileName_
);
274 caller
.addOption("-mtx", mtxFileName_
);
275 caller
.addOption("-o", fullPrecisionTrajectoryFileName_
);
276 caller
.addOption("-x", reducedPrecisionTrajectoryFileName_
);
278 caller
.addOption("-deffnm", fileManager_
.getTemporaryFilePath("state"));
282 caller
.addOption("-nsteps", nsteps_
);
286 caller
.addOption("-ntmpi", getNumberOfTestMpiRanks());
290 caller
.addOption("-ntomp", g_numOpenMPThreads
);
293 return gmx_mdrun(caller
.argc(), caller
.argv());
297 SimulationRunner::callMdrun()
299 return callMdrun(CommandLine());
304 MdrunTestFixtureBase::MdrunTestFixtureBase()
307 GMX_RELEASE_ASSERT(gmx_mpi_initialized(), "MPI system not initialized for mdrun tests");
311 MdrunTestFixtureBase::~MdrunTestFixtureBase()
317 MdrunTestFixture::MdrunTestFixture() : runner_(&fileManager_
)
321 MdrunTestFixture::~MdrunTestFixture()
324 // fileManager_ should only clean up after all the ranks are done.
325 MPI_Barrier(MPI_COMM_WORLD
);