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.
37 * Implements test of some pulling routines
39 * \author David van der Spoel <david.vanderspoel@icm.uu.se>
40 * \ingroup module_pulling
44 #include "gromacs/pulling/pull.h"
50 #include <gtest/gtest.h>
52 #include "gromacs/math/vec.h"
53 #include "gromacs/pbcutil/pbc.h"
54 #include "gromacs/pulling/pull_internal.h"
55 #include "gromacs/utility/smalloc.h"
57 #include "testutils/refdata.h"
58 #include "testutils/testasserts.h"
59 #include "testutils/testfilemanager.h"
66 using gmx::test::defaultRealTolerance;
68 class PullTest : public ::testing::Test
73 void test(int epbc, matrix box)
78 set_pbc(&pbc, epbc, box);
80 GMX_ASSERT(pbc.ndim_ePBC >= 1, "Tests only support PBC along at least x");
83 if (pbc.ndim_ePBC > ZZ)
85 boxSizeZSquared = gmx::square(box[ZZ][ZZ]);
89 boxSizeZSquared = GMX_REAL_MAX;
93 // Distance pulling in all 3 dimensions
95 params.eGeom = epullgDIST;
99 pull_coord_work_t pcrd(params);
100 clear_dvec(pcrd.spatialData.vec);
102 real minBoxSize2 = GMX_REAL_MAX;
103 for (int d = 0; d < pbc.ndim_ePBC; d++)
105 minBoxSize2 = std::min(minBoxSize2, norm2(box[d]));
107 EXPECT_REAL_EQ_TOL(0.25*minBoxSize2,
108 max_pull_distance2(&pcrd, &pbc),
109 defaultRealTolerance());
113 // Distance pulling along Z
115 params.eGeom = epullgDIST;
119 pull_coord_work_t pcrd(params);
120 clear_dvec(pcrd.spatialData.vec);
121 EXPECT_REAL_EQ_TOL(0.25*boxSizeZSquared,
122 max_pull_distance2(&pcrd, &pbc),
123 defaultRealTolerance());
127 // Directional pulling along Z
129 params.eGeom = epullgDIR;
133 pull_coord_work_t pcrd(params);
134 clear_dvec(pcrd.spatialData.vec);
135 pcrd.spatialData.vec[ZZ] = 1;
136 EXPECT_REAL_EQ_TOL(0.25*boxSizeZSquared,
137 max_pull_distance2(&pcrd, &pbc),
138 defaultRealTolerance());
142 // Directional pulling along X
144 params.eGeom = epullgDIR;
148 pull_coord_work_t pcrd(params);
149 clear_dvec(pcrd.spatialData.vec);
150 pcrd.spatialData.vec[XX] = 1;
152 real minDist2 = square(box[XX][XX]);
153 for (int d = XX + 1; d < DIM; d++)
155 minDist2 -= square(box[d][XX]);
157 EXPECT_REAL_EQ_TOL(0.25*minDist2,
158 max_pull_distance2(&pcrd, &pbc),
159 defaultRealTolerance());
164 TEST_F (PullTest, MaxPullDistanceXyzScrewBox)
166 matrix box = { { 10, 0, 0 }, { 0, 10, 0 }, { 0, 0, 10 } };
168 test(epbcSCREW, box);
171 TEST_F (PullTest, MaxPullDistanceXyzCubicBox)
173 matrix box = { { 10, 0, 0 }, { 0, 10, 0 }, { 0, 0, 10 } };
178 TEST_F (PullTest, MaxPullDistanceXyzTricBox)
180 matrix box = { { 10, 0, 0 }, { 3, 10, 0 }, { 3, 4, 10 } };
185 TEST_F (PullTest, MaxPullDistanceXyzLongBox)
187 matrix box = { { 10, 0, 0 }, { 0, 10, 0 }, { 0, 0, 30 } };
192 TEST_F (PullTest, MaxPullDistanceXySkewedBox)
194 matrix box = { { 10, 0, 0 }, { 5, 8, 0 }, { 0, 0, 0 } };