Add AWH biasing module + tests
[gromacs.git] / src / gromacs / gmxpreprocess / tests / readir.cpp
blobf266dc156dd25a426cfa51e2fab4878bf454e66c
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2017, 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.
35 /*! \internal \file
36 * \brief
37 * Test routines that parse mdp fields from grompp input and writes
38 * mdp back out.
40 * In particular these will provide test coverage as we refactor to
41 * use a new Options-based key-value-style mdp implementation to
42 * support a more modular mdrun.
44 * \author Mark Abraham <mark.j.abraham@gmail.com>
46 #include "gmxpre.h"
48 #include "gromacs/gmxpreprocess/readir.h"
50 #include <string>
52 #include <gtest/gtest.h>
54 #include "gromacs/fileio/warninp.h"
55 #include "gromacs/mdrunutility/mdmodules.h"
56 #include "gromacs/mdtypes/inputrec.h"
57 #include "gromacs/utility/cstringutil.h"
58 #include "gromacs/utility/stringutil.h"
59 #include "gromacs/utility/textreader.h"
60 #include "gromacs/utility/textwriter.h"
61 #include "gromacs/utility/unique_cptr.h"
63 #include "testutils/refdata.h"
64 #include "testutils/testfilemanager.h"
66 namespace gmx
68 namespace test
71 class GetIrTest : public ::testing::Test
73 public:
74 GetIrTest() : fileManager_(), data_(), checker_(data_.rootChecker()),
75 ir_(), mdModules_(), opts_(),
76 wi_(init_warning(FALSE, 0)), wiGuard_(wi_)
79 snew(opts_.include, STRLEN);
80 snew(opts_.define, STRLEN);
82 ~GetIrTest()
84 done_inputrec_strings();
85 sfree(opts_.include);
86 sfree(opts_.define);
88 /*! \brief Test mdp reading and writing
90 * \todo Modernize read_inp and write_inp to use streams,
91 * which will make these tests run faster, because they don't
92 * use disk files. */
93 void runTest(const std::string &inputMdpFileContents)
95 auto inputMdpFilename = fileManager_.getTemporaryFilePath("input.mdp");
96 auto outputMdpFilename = fileManager_.getTemporaryFilePath("output.mdp");
98 TextWriter::writeFileFromString(inputMdpFilename, inputMdpFileContents);
100 get_ir(inputMdpFilename.c_str(), outputMdpFilename.c_str(),
101 &mdModules_, &ir_, &opts_, WriteMdpHeader::no, wi_);
102 bool failure = warning_errors_exist(wi_);
103 checker_.checkBoolean(failure, "Error parsing mdp file");
104 warning_reset(wi_);
106 auto outputMdpContents = TextReader::readFileToString(outputMdpFilename);
107 checker_.checkString(outputMdpContents, "OutputMdpFile");
110 TestFileManager fileManager_;
111 TestReferenceData data_;
112 TestReferenceChecker checker_;
113 t_inputrec ir_;
114 MDModules mdModules_;
115 t_gromppopts opts_;
116 warninp_t wi_;
117 unique_cptr<warninp, free_warning> wiGuard_;
120 TEST_F(GetIrTest, HandlesDifferentKindsOfMdpLines)
122 const char *inputMdpFile[] = {
123 "; File to run my simulation",
124 "title = simulation",
125 ";",
126 "xtc_grps = System ; was Protein",
127 "include = -I/home/me/stuff",
129 "tau-t = 0.1 0.3",
130 "tinit = 0.3",
131 "init_step = 0",
132 "nstcomm = 100",
133 "integrator = steep"
135 runTest(joinStrings(inputMdpFile, "\n"));
138 // This case is used often by SimulationRunner::useEmptyMdpFile (see
139 // comments there for explanation). When we remove the group scheme,
140 // that usage will have to disappear, and so can this test.
141 TEST_F(GetIrTest, HandlesOnlyCutoffScheme)
143 const char *inputMdpFile = "cutoff-scheme = Group\n";
144 runTest(inputMdpFile);
147 // TODO Stop accepting any of these
148 TEST_F(GetIrTest, UserErrorsSilentlyTolerated)
150 const char *inputMdpFile[] = {
151 "title simulation",
152 "xtc_grps = ",
153 "= -I/home/me/stuff",
156 runTest(joinStrings(inputMdpFile, "\n"));
159 TEST_F(GetIrTest, EmptyInputWorks)
161 const char *inputMdpFile = "";
162 runTest(inputMdpFile);
165 // These tests observe how the electric-field keys behave, since they
166 // are currently the only ones using the new Options-style handling.
167 TEST_F(GetIrTest, ProducesOutputFromElectricField)
169 const char *inputMdpFile = "electric-field-x = 1.2 0 0 0";
170 runTest(inputMdpFile);
173 TEST_F(GetIrTest, ProducesOutputFromElectricFieldPulsed)
175 const char *inputMdpFile = "electric-field-y = 3.7 2.0 6.5 1.0";
176 runTest(inputMdpFile);
179 TEST_F(GetIrTest, ProducesOutputFromElectricFieldOscillating)
181 const char *inputMdpFile = "electric-field-z = 3.7 7.5 0 0";
182 runTest(inputMdpFile);
185 } // namespace
186 } // namespace