clang-tidy: google tests applicable
[gromacs.git] / src / programs / mdrun / tests / tabulated_bonded_interactions.cpp
blob3bd8ec8e75d2c4aba6cd44113d345d919d67c1ad
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2016,2018, 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.
36 /*! \internal \file
37 * \brief
38 * Tests for tabulated bonded interactions
40 * \author Mark Abraham <mark.j.abraham@gmail.com>
41 * \ingroup module_mdrun_integration_tests
43 #include "gmxpre.h"
45 #include <gtest/gtest.h>
47 #include "gromacs/utility/stringutil.h"
48 #include "gromacs/utility/textwriter.h"
50 #include "testutils/cmdlinetest.h"
52 #include "moduletest.h"
54 namespace gmx
56 namespace test
59 //! Format string for building a configurable .top file
60 static const char *g_butaneTopFileFormatString = "\
61 [ defaults ]\n\
62 ; nbfunc comb-rule gen-pairs fudgeLJ fudgeQQ\n\
63 1 1 no 1.0 1.0\n\
64 \n\
65 [ atomtypes ]\n\
66 ;name mass charge ptype c6 c12\n\
67 CH2 14.02700 0.000 A 0.90975E-02 0.35333E-04\n\
68 CH3 15.03500 0.000 A 0.88765E-02 0.26150E-04\n\
69 \n\
70 [ moleculetype ]\n\
71 ; name nrexcl\n\
72 butane 3\n\
73 \n\
74 [ atoms ]\n\
75 ; nr type resnr residu atom cgnr\n\
76 1 CH3 1 BUT C1 1\n\
77 2 CH2 1 BUT C2 2\n\
78 3 CH2 1 BUT C3 3\n\
79 4 CH3 1 BUT C4 4\n\
80 \n\
81 %s\n\
82 \n\
83 [ system ]\n\
84 ; The name of the system to be simulated\n\
85 A single butane\n\
86 \n\
87 [ molecules ]\n\
88 ; Molname Number\n\
89 Butane 1\n\
92 //! Test fixture for bonded interactions
93 class BondedInteractionsTest : public gmx::test::MdrunTestFixture
95 public:
96 //! Execute the trajectory writing test
97 void setupGrompp(const char *interaction)
99 runner_.topFileName_ = fileManager_.getTemporaryFilePath("butane1.top");
100 TextWriter::writeFileFromString(runner_.topFileName_, formatString(g_butaneTopFileFormatString, interaction));
101 runner_.groFileName_ = gmx::test::TestFileManager::getInputFilePath("butane1.gro");
102 runner_.ndxFileName_ = gmx::test::TestFileManager::getInputFilePath("butane1.ndx");
103 /* TODO Now that Verlet is the default, change the implementation
104 of useEmptyMdpFile() to do that. */
105 runner_.useStringAsMdpFile("");
107 //! Prepare an mdrun caller
108 CommandLine setupMdrun()
110 CommandLine rerunCaller;
111 rerunCaller.append("mdrun");
112 rerunCaller.addOption("-rerun", runner_.groFileName_);
113 return rerunCaller;
115 //! Check the output of mdrun
116 void checkMdrun()
118 // TODO verifying some energies and forces would be good,
119 // once other code in gerrit is reviewed
123 // This test ensures that a normal non-tabulated bond interaction works
124 TEST_F(BondedInteractionsTest, NormalBondWorks)
126 setupGrompp("[ bonds ]\n\
127 ; ai aj funct c0 c1\n\
128 1 2 1 1.530000e-01 3.347000e+05");
129 EXPECT_EQ(0, runner_.callGrompp());
131 test::CommandLine rerunCaller = setupMdrun();
132 ASSERT_EQ(0, runner_.callMdrun(rerunCaller));
133 checkMdrun();
136 // This test ensures that a normal abulated bond interaction works
137 TEST_F(BondedInteractionsTest, TabulatedBondWorks)
139 setupGrompp("[ bonds ]\n\
140 ; ai aj funct n k\n\
141 1 2 8 0 1000");
142 EXPECT_EQ(0, runner_.callGrompp());
144 test::CommandLine rerunCaller = setupMdrun();
145 std::string tableFileName = gmx::test::TestFileManager::getInputFilePath("butane_b0.xvg");
146 rerunCaller.addOption("-tableb", tableFileName);
147 ASSERT_EQ(0, runner_.callMdrun(rerunCaller));
148 checkMdrun();
151 // This test ensures that a normal non-tabulated angle interaction works
152 TEST_F(BondedInteractionsTest, NormalAngleWorks)
154 setupGrompp("[ angles ]\n\
155 ; ai aj ak funct c0 c1\n\
156 1 2 3 1 1.110000e+02 4.602000e+02");
157 EXPECT_EQ(0, runner_.callGrompp());
159 test::CommandLine rerunCaller = setupMdrun();
160 ASSERT_EQ(0, runner_.callMdrun(rerunCaller));
161 checkMdrun();
164 // This test ensures that a tabulated angle interaction works
165 TEST_F(BondedInteractionsTest, TabulatedAngleWorks)
167 setupGrompp("[ angles ]\n\
168 ; ai aj ak funct n k\n\
169 1 2 3 8 0 1000");
170 EXPECT_EQ(0, runner_.callGrompp());
172 test::CommandLine rerunCaller = setupMdrun();
173 std::string tableFileName = gmx::test::TestFileManager::getInputFilePath("butane_a0.xvg");
174 rerunCaller.addOption("-tableb", tableFileName);
175 ASSERT_EQ(0, runner_.callMdrun(rerunCaller));
176 checkMdrun();
179 // This test ensures that a normal non-tabulated dihedral interaction works
180 TEST_F(BondedInteractionsTest, NormalDihedralWorks)
182 setupGrompp("[ dihedrals ]\n \
183 ; ai aj ak al funct c0 c1 c2 c3 c4 c5\n\
184 1 2 3 4 3 9.2789 12.156 -13.12 -3.0597 26.24 -31.495");
185 EXPECT_EQ(0, runner_.callGrompp());
187 test::CommandLine rerunCaller = setupMdrun();
188 ASSERT_EQ(0, runner_.callMdrun(rerunCaller));
189 checkMdrun();
192 // This test ensures that a tabulated dihedral interaction works
193 TEST_F(BondedInteractionsTest, TabulatedDihedralWorks)
195 setupGrompp("[ dihedrals ]\n\
196 ; ai aj ak al funct n k\n\
197 1 2 3 4 8 0 1000");
198 EXPECT_EQ(0, runner_.callGrompp());
200 test::CommandLine rerunCaller = setupMdrun();
201 std::string tableFileName = gmx::test::TestFileManager::getInputFilePath("butane_d0.xvg");
202 rerunCaller.addOption("-tableb", tableFileName);
203 ASSERT_EQ(0, runner_.callMdrun(rerunCaller));
204 checkMdrun();
207 } // namespace test
209 } // namespace gmx