2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2013,2014, 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
44 #include "moduletest.h"
48 #include "gromacs/gmxpreprocess/grompp.h"
49 #include "gromacs/options/basicoptions.h"
50 #include "gromacs/options/options.h"
51 #include "gromacs/utility/basedefinitions.h"
52 #include "gromacs/utility/basenetwork.h"
53 #include "gromacs/utility/file.h"
54 #include "programs/mdrun/mdrun_main.h"
56 #include "testutils/cmdlinetest.h"
57 #include "testutils/integrationtests.h"
58 #include "testutils/testoptions.h"
65 /********************************************************************
72 #if defined(GMX_THREAD_MPI) || defined(DOXYGEN)
73 //! Number of tMPI threads for child mdrun call.
76 #if defined(GMX_OPENMP) || defined(DOXYGEN)
77 //! Number of OpenMP threads for child mdrun call.
78 int g_numOpenMPThreads = 1;
81 GMX_TEST_OPTIONS(MdrunTestOptions, options)
83 GMX_UNUSED_VALUE(options);
85 options->addOption(IntegerOption("nt").store(&g_numThreads)
86 .description("Number of thread-MPI threads/ranks for child mdrun call"));
89 options->addOption(IntegerOption("nt_omp").store(&g_numOpenMPThreads)
90 .description("Number of OpenMP threads for child mdrun call"));
97 MdrunTestFixture::MdrunTestFixture() :
100 fullPrecisionTrajectoryFileName(),
102 mdpInputFileName(fileManager_.getTemporaryFilePath("input.mdp")),
103 mdpOutputFileName(fileManager_.getTemporaryFilePath("output.mdp")),
104 tprFileName(fileManager_.getTemporaryFilePath(".tpr")),
105 logFileName(fileManager_.getTemporaryFilePath(".log")),
106 edrFileName(fileManager_.getTemporaryFilePath(".edr")),
110 GMX_RELEASE_ASSERT(gmx_mpi_initialized(), "MPI system not initialized for mdrun tests");
114 MdrunTestFixture::~MdrunTestFixture()
118 // TODO The combination of defaulting to Verlet cut-off scheme, NVE,
119 // and verlet-buffer-tolerance = -1 gives a grompp error. If we keep
120 // things that way, this function should be renamed. For now,
121 // force the use of the group scheme.
123 MdrunTestFixture::useEmptyMdpFile()
125 useStringAsMdpFile("cutoff-scheme = Group\n");
129 MdrunTestFixture::useStringAsMdpFile(const char *mdpString)
131 useStringAsMdpFile(std::string(mdpString));
135 MdrunTestFixture::useStringAsMdpFile(const std::string &mdpString)
137 gmx::File::writeFileFromString(mdpInputFileName, mdpString);
141 MdrunTestFixture::useStringAsNdxFile(const char *ndxString)
143 gmx::File::writeFileFromString(ndxFileName, ndxString);
147 MdrunTestFixture::useTopGroAndNdxFromDatabase(const char *name)
149 topFileName = fileManager_.getInputFilePath((std::string(name) + ".top").c_str());
150 groFileName = fileManager_.getInputFilePath((std::string(name) + ".gro").c_str());
151 ndxFileName = fileManager_.getInputFilePath((std::string(name) + ".ndx").c_str());
155 MdrunTestFixture::callGromppOnThisRank()
158 caller.append("grompp");
159 caller.addOption("-f", mdpInputFileName);
160 caller.addOption("-n", ndxFileName);
161 caller.addOption("-p", topFileName);
162 caller.addOption("-c", groFileName);
164 caller.addOption("-po", mdpOutputFileName);
165 caller.addOption("-o", tprFileName);
167 return gmx_grompp(caller.argc(), caller.argv());
171 MdrunTestFixture::callGrompp()
174 // When compiled with external MPI, only call one instance of the
176 if (0 != gmx_node_rank())
181 return callGromppOnThisRank();
185 MdrunTestFixture::callMdrun(const CommandLine &callerRef)
187 /* Conforming to style guide by not passing a non-const reference
188 to this function. Passing a non-const reference might make it
189 easier to write code that incorrectly re-uses callerRef after
190 the call to this function. */
191 CommandLine caller(callerRef);
192 caller.addOption("-s", tprFileName);
194 caller.addOption("-g", logFileName);
195 caller.addOption("-e", edrFileName);
196 caller.addOption("-o", fullPrecisionTrajectoryFileName);
197 caller.addOption("-x", reducedPrecisionTrajectoryFileName);
199 caller.addOption("-deffnm", fileManager_.getTemporaryFilePath("state"));
203 caller.addOption("-nsteps", nsteps);
206 #ifdef GMX_THREAD_MPI
207 caller.addOption("-nt", g_numThreads);
210 caller.addOption("-ntomp", g_numOpenMPThreads);
213 return gmx_mdrun(caller.argc(), caller.argv());
217 MdrunTestFixture::callMdrun()
220 caller.append("mdrun");
221 return callMdrun(caller);