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
42 #include "moduletest.h"
48 #include "testutils/integrationtests.h"
49 #include "testutils/testoptions.h"
50 #include "testutils/cmdlinetest.h"
51 #include "gromacs/options/options.h"
52 #include "gromacs/options/basicoptions.h"
53 #include "gromacs/utility/file.h"
54 #include "gromacs/legacyheaders/network.h"
55 #include "gromacs/legacyheaders/types/simple.h"
56 #include "programs/mdrun/mdrun_main.h"
57 #include "programs/gmx/legacycmainfunctions.h"
64 /********************************************************************
69 /*! /brief Number of tMPI threads for child mdrun call */
70 static int gmx_unused numThreads = 1;
71 /*! /brief Number of OpenMP threads for child mdrun call */
72 static int gmx_unused numOpenMPThreads = 1;
77 GMX_TEST_OPTIONS(MdrunTestOptions, options)
79 GMX_UNUSED_VALUE(options);
81 options->addOption(IntegerOption("nt").store(&numThreads)
82 .description("Number of thread-MPI threads/ranks for child mdrun call"));
85 options->addOption(IntegerOption("nt_omp").store(&numOpenMPThreads)
86 .description("Number of OpenMP threads for child mdrun call"));
92 MdrunTestFixture::MdrunTestFixture() :
97 mdpInputFileName(fileManager_.getTemporaryFilePath("input.mdp")),
98 mdpOutputFileName(fileManager_.getTemporaryFilePath("output.mdp")),
99 tprFileName(fileManager_.getTemporaryFilePath(".tpr")),
100 logFileName(fileManager_.getTemporaryFilePath(".log")),
101 edrFileName(fileManager_.getTemporaryFilePath(".edr"))
104 GMX_RELEASE_ASSERT(gmx_mpi_initialized(), "MPI system not initialized for mdrun tests");
108 MdrunTestFixture::~MdrunTestFixture()
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 // force the use of the group scheme.
117 MdrunTestFixture::useEmptyMdpFile()
119 useStringAsMdpFile("cutoff-scheme = Group\n");
123 MdrunTestFixture::useStringAsMdpFile(const char *mdpString)
125 gmx::File::writeFileFromString(mdpInputFileName, mdpString);
129 MdrunTestFixture::useStringAsNdxFile(const char *ndxString)
131 gmx::File::writeFileFromString(ndxFileName, ndxString);
135 MdrunTestFixture::useTopGroAndNdxFromDatabase(const char *name)
137 topFileName = fileManager_.getInputFilePath((std::string(name) + ".top").c_str());
138 groFileName = fileManager_.getInputFilePath((std::string(name) + ".gro").c_str());
139 ndxFileName = fileManager_.getInputFilePath((std::string(name) + ".ndx").c_str());
143 MdrunTestFixture::callGrompp()
146 // When compiled with external MPI, only call one instance of the grompp function
147 if (0 != gmx_node_rank())
154 caller.append("grompp");
155 caller.addOption("-f", mdpInputFileName);
156 caller.addOption("-n", ndxFileName);
157 caller.addOption("-p", topFileName);
158 caller.addOption("-c", groFileName);
160 caller.addOption("-po", mdpOutputFileName);
161 caller.addOption("-o", tprFileName);
163 return gmx_grompp(caller.argc(), caller.argv());
167 MdrunTestFixture::callMdrun(const CommandLine &callerRef)
169 /* Conforming to style guide by not passing a non-const reference
170 to this function. Passing a non-const reference might make it
171 easier to write code that incorrectly re-uses callerRef after
172 the call to this function. */
173 CommandLine caller(callerRef);
174 caller.addOption("-s", tprFileName);
176 caller.addOption("-g", logFileName);
177 caller.addOption("-e", edrFileName);
178 caller.addOption("-o", trrFileName);
179 caller.addOption("-x", xtcFileName);
181 #ifdef GMX_THREAD_MPI
182 caller.addOption("-nt", numThreads);
185 caller.addOption("-ntomp", numOpenMPThreads);
188 return gmx_mdrun(caller.argc(), caller.argv());
192 MdrunTestFixture::callMdrun()
195 caller.append("mdrun");
196 return callMdrun(caller);