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.
38 * Tests for tabulated bonded interactions
40 * \author Mark Abraham <mark.j.abraham@gmail.com>
41 * \ingroup module_mdrun_integration_tests
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"
59 //! Format string for building a configurable .top file
60 static const char *g_butaneTopFileFormatString
= "\
62 ; nbfunc comb-rule gen-pairs fudgeLJ fudgeQQ\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\
75 ; nr type resnr residu atom cgnr\n\
84 ; The name of the system to be simulated\n\
92 //! Test fixture for bonded interactions
93 class BondedInteractionsTest
: public gmx::test::MdrunTestFixture
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_
);
115 //! Check the output of mdrun
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
));
136 // This test ensures that a normal abulated bond interaction works
137 TEST_F(BondedInteractionsTest
, TabulatedBondWorks
)
139 setupGrompp("[ bonds ]\n\
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
));
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
));
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\
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
));
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
));
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\
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
));