2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2016,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.
37 * Implements test of bonded force routines
39 * \author David van der Spoel <david.vanderspoel@icm.uu.se>
40 * \ingroup module_listed-forces
44 #include "gromacs/listed-forces/bonded.h"
50 #include <gtest/gtest.h>
52 #include "gromacs/math/units.h"
53 #include "gromacs/pbcutil/ishift.h"
54 #include "gromacs/pbcutil/pbc.h"
56 #include "testutils/refdata.h"
57 #include "testutils/testasserts.h"
58 #include "testutils/testfilemanager.h"
65 //! Number of atoms used in these tests.
68 class BondedTest : public ::testing::Test
73 test::TestReferenceData refData_;
74 test::TestReferenceChecker checker_;
76 checker_(refData_.rootChecker())
78 test::FloatingPointTolerance tolerance(test::relativeToleranceAsFloatingPoint(1.0, 1e-6));
79 checker_.setDefaultTolerance(tolerance);
80 clear_rvecs(NATOMS, x);
82 x[2][1] = x[2][2] = 1;
83 x[3][0] = x[3][1] = x[3][2] = 1;
86 box[0][0] = box[1][1] = box[2][2] = 1.5;
89 void testBondAngle(int epbc)
92 real cosine_angle, angle;
96 set_pbc(&pbc, epbc, box);
97 angle = bond_angle(x[0], x[1], x[2], &pbc,
98 r_ij, r_kj, &cosine_angle,
100 checker_.checkReal(angle, "angle");
101 checker_.checkReal(cosine_angle, "cosine_angle");
102 checker_.checkInteger(t1, "t1");
103 checker_.checkInteger(t2, "t2");
106 void testDihedralAngle(int epbc)
108 rvec r_ij, r_kj, r_kl, m, n;
113 set_pbc(&pbc, epbc, box);
114 angle = dih_angle(x[0], x[1], x[2], x[3], &pbc,
115 r_ij, r_kj, r_kl, m, n,
118 checker_.checkReal(angle, "angle");
119 checker_.checkInteger(t1, "t1");
120 checker_.checkInteger(t2, "t2");
121 checker_.checkInteger(t3, "t3");
124 void testIfunc(int ftype,
125 const std::vector<t_iatom> &iatoms,
126 const t_iparams iparams[],
132 for (int i = 0; i < NATOMS; i++)
134 for (int j = 0; j < 4; j++)
140 clear_rvecs(N_IVEC, fshift);
142 set_pbc(&pbc, epbc, box);
144 real energy = interaction_function[ftype].ifunc(iatoms.size(),
149 /* const struct t_graph *g */ nullptr,
151 /* const struct t_mdatoms *md */ nullptr,
152 /* struct t_fcdata *fcd */ nullptr,
154 checker_.checkReal(energy, interaction_function[ftype].longname);
159 TEST_F (BondedTest, BondAnglePbcNone)
161 testBondAngle(epbcNONE);
164 TEST_F (BondedTest, BondAnglePbcXy)
166 testBondAngle(epbcXY);
169 TEST_F (BondedTest, BondAnglePbcXyz)
171 testBondAngle(epbcXYZ);
174 TEST_F (BondedTest, DihedralAnglePbcNone)
176 testDihedralAngle(epbcNONE);
179 TEST_F (BondedTest, DihedralAnglePbcXy)
181 testDihedralAngle(epbcXY);
184 TEST_F (BondedTest, DihedralAnglePbcXyz)
186 testDihedralAngle(epbcXYZ);
189 TEST_F (BondedTest, IfuncBondsPbcNo)
191 std::vector<t_iatom> iatoms = { 0, 0, 1, 0, 1, 2, 0, 2, 3 };
193 iparams.harmonic.rA = iparams.harmonic.rB = 0.8;
194 iparams.harmonic.krA = iparams.harmonic.krB = 50;
195 testIfunc(F_BONDS, iatoms, &iparams, epbcNONE);
198 TEST_F (BondedTest, IfuncBondsPbcXy)
200 std::vector<t_iatom> iatoms = { 0, 0, 1, 0, 1, 2, 0, 2, 3 };
202 iparams.harmonic.rA = iparams.harmonic.rB = 0.8;
203 iparams.harmonic.krA = iparams.harmonic.krB = 50;
204 testIfunc(F_BONDS, iatoms, &iparams, epbcXY);
207 TEST_F (BondedTest, IfuncBondsPbcXyz)
209 std::vector<t_iatom> iatoms = { 0, 0, 1, 0, 1, 2, 0, 2, 3 };
211 iparams.harmonic.rA = iparams.harmonic.rB = 0.8;
212 iparams.harmonic.krA = iparams.harmonic.krB = 50;
213 testIfunc(F_BONDS, iatoms, &iparams, epbcXYZ);
216 TEST_F (BondedTest, IfuncAnglesPbcNo)
218 std::vector<t_iatom> iatoms = { 0, 0, 1, 2, 0, 1, 2, 3 };
221 iparams.harmonic.rA = iparams.harmonic.rB = 100;
222 iparams.harmonic.krA = iparams.harmonic.krB = k;
223 testIfunc(F_ANGLES, iatoms, &iparams, epbcNONE);
226 TEST_F (BondedTest, IfuncAnglesPbcXy)
228 std::vector<t_iatom> iatoms = { 0, 0, 1, 2, 0, 1, 2, 3 };
231 iparams.harmonic.rA = iparams.harmonic.rB = 100;
232 iparams.harmonic.krA = iparams.harmonic.krB = k;
233 testIfunc(F_ANGLES, iatoms, &iparams, epbcXY);
236 TEST_F (BondedTest, IfuncAnglesPbcXYZ)
238 std::vector<t_iatom> iatoms = { 0, 0, 1, 2, 0, 1, 2, 3 };
241 iparams.harmonic.rA = iparams.harmonic.rB = 100;
242 iparams.harmonic.krA = iparams.harmonic.krB = k;
243 testIfunc(F_ANGLES, iatoms, &iparams, epbcXYZ);
246 TEST_F (BondedTest, IfuncProperDihedralsPbcNo)
248 std::vector<t_iatom> iatoms = { 0, 0, 1, 2, 3 };
250 iparams.pdihs.phiA = iparams.pdihs.phiB = -100;
251 iparams.pdihs.cpA = iparams.pdihs.cpB = 10;
252 iparams.pdihs.mult = 1;
253 testIfunc(F_PDIHS, iatoms, &iparams, epbcNONE);
256 TEST_F (BondedTest, IfuncProperDihedralsPbcXy)
258 std::vector<t_iatom> iatoms = { 0, 0, 1, 2, 3 };
260 iparams.pdihs.phiA = iparams.pdihs.phiB = -100;
261 iparams.pdihs.cpA = iparams.pdihs.cpB = 10;
262 iparams.pdihs.mult = 1;
263 testIfunc(F_PDIHS, iatoms, &iparams, epbcXY);
266 TEST_F (BondedTest, IfuncProperDihedralsPbcXyz)
268 std::vector<t_iatom> iatoms = { 0, 0, 1, 2, 3 };
270 iparams.pdihs.phiA = iparams.pdihs.phiB = -100;
271 iparams.pdihs.cpA = iparams.pdihs.cpB = 10;
272 iparams.pdihs.mult = 1;
273 testIfunc(F_PDIHS, iatoms, &iparams, epbcXYZ);