2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2016,2018,2019, 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 runner_
.useEmptyMdpFile();
105 //! Prepare an mdrun caller
106 CommandLine
setupMdrun()
108 CommandLine rerunCaller
;
109 rerunCaller
.append("mdrun");
110 rerunCaller
.addOption("-rerun", runner_
.groFileName_
);
113 //! Check the output of mdrun
116 // TODO verifying some energies and forces would be good,
117 // once other code in gerrit is reviewed
121 // This test ensures that a normal non-tabulated bond interaction works
122 TEST_F(BondedInteractionsTest
, NormalBondWorks
)
124 setupGrompp("[ bonds ]\n\
125 ; ai aj funct c0 c1\n\
126 1 2 1 1.530000e-01 3.347000e+05");
127 EXPECT_EQ(0, runner_
.callGrompp());
129 test::CommandLine rerunCaller
= setupMdrun();
130 ASSERT_EQ(0, runner_
.callMdrun(rerunCaller
));
134 // This test ensures that a normal abulated bond interaction works
135 TEST_F(BondedInteractionsTest
, TabulatedBondWorks
)
137 setupGrompp("[ bonds ]\n\
140 EXPECT_EQ(0, runner_
.callGrompp());
142 test::CommandLine rerunCaller
= setupMdrun();
143 std::string tableFileName
= gmx::test::TestFileManager::getInputFilePath("butane_b0.xvg");
144 rerunCaller
.addOption("-tableb", tableFileName
);
145 ASSERT_EQ(0, runner_
.callMdrun(rerunCaller
));
149 // This test ensures that a normal non-tabulated angle interaction works
150 TEST_F(BondedInteractionsTest
, NormalAngleWorks
)
152 setupGrompp("[ angles ]\n\
153 ; ai aj ak funct c0 c1\n\
154 1 2 3 1 1.110000e+02 4.602000e+02");
155 EXPECT_EQ(0, runner_
.callGrompp());
157 test::CommandLine rerunCaller
= setupMdrun();
158 ASSERT_EQ(0, runner_
.callMdrun(rerunCaller
));
162 // This test ensures that a tabulated angle interaction works
163 TEST_F(BondedInteractionsTest
, TabulatedAngleWorks
)
165 setupGrompp("[ angles ]\n\
166 ; ai aj ak funct n k\n\
168 EXPECT_EQ(0, runner_
.callGrompp());
170 test::CommandLine rerunCaller
= setupMdrun();
171 std::string tableFileName
= gmx::test::TestFileManager::getInputFilePath("butane_a0.xvg");
172 rerunCaller
.addOption("-tableb", tableFileName
);
173 ASSERT_EQ(0, runner_
.callMdrun(rerunCaller
));
177 // This test ensures that a normal non-tabulated dihedral interaction works
178 TEST_F(BondedInteractionsTest
, NormalDihedralWorks
)
180 setupGrompp("[ dihedrals ]\n \
181 ; ai aj ak al funct c0 c1 c2 c3 c4 c5\n\
182 1 2 3 4 3 9.2789 12.156 -13.12 -3.0597 26.24 -31.495");
183 EXPECT_EQ(0, runner_
.callGrompp());
185 test::CommandLine rerunCaller
= setupMdrun();
186 ASSERT_EQ(0, runner_
.callMdrun(rerunCaller
));
190 // This test ensures that a tabulated dihedral interaction works
191 TEST_F(BondedInteractionsTest
, TabulatedDihedralWorks
)
193 setupGrompp("[ dihedrals ]\n\
194 ; ai aj ak al funct n k\n\
196 EXPECT_EQ(0, runner_
.callGrompp());
198 test::CommandLine rerunCaller
= setupMdrun();
199 std::string tableFileName
= gmx::test::TestFileManager::getInputFilePath("butane_d0.xvg");
200 rerunCaller
.addOption("-tableb", tableFileName
);
201 ASSERT_EQ(0, runner_
.callMdrun(rerunCaller
));