2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2020,2021, 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 * This implements SimulationState tests
39 * \author Victor Holanda <victor.holanda@cscs.ch>
40 * \author Joe Jordan <ejjordan@kth.se>
41 * \author Prashanth Kanduri <kanduri@cscs.ch>
42 * \author Sebastian Keller <keller@cscs.ch>
46 #include "nblib/box.h"
47 #include "nblib/exception.h"
48 #include "nblib/simulationstate.h"
49 #include "nblib/simulationstateimpl.h"
50 #include "nblib/tests/testhelpers.h"
51 #include "nblib/tests/testsystems.h"
52 #include "nblib/topology.h"
54 #include "testutils/testasserts.h"
63 //! Utility function to compare 2 std::vectors of gmx::RVec used to compare cartesians
64 void compareValues(const std::vector<Vec3>& ref, const std::vector<Vec3>& test)
66 for (size_t i = 0; i < ref.size(); i++)
68 for (int j = 0; j < dimSize; j++)
70 EXPECT_EQ(ref[i][j], test.at(i)[j]);
75 TEST(NBlibTest, CanConstructSimulationState)
77 ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
78 EXPECT_NO_THROW(argonSimulationStateBuilder.setupSimulationState());
81 TEST(NBlibTest, SimulationStateThrowsCoordinateNAN)
83 ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
84 argonSimulationStateBuilder.setCoordinate(2, 0, NAN);
85 EXPECT_THROW(argonSimulationStateBuilder.setupSimulationState(), InputException);
88 TEST(NBlibTest, SimulationStateThrowsCoordinateINF)
90 ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
91 argonSimulationStateBuilder.setCoordinate(2, 0, INFINITY);
92 EXPECT_THROW(argonSimulationStateBuilder.setupSimulationState(), InputException);
95 TEST(NBlibTest, SimulationStateThrowsVelocityNAN)
97 ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
98 argonSimulationStateBuilder.setVelocity(2, 0, NAN);
99 EXPECT_THROW(argonSimulationStateBuilder.setupSimulationState(), InputException);
102 TEST(NBlibTest, SimulationStateThrowsVelocityINF)
104 ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
105 argonSimulationStateBuilder.setVelocity(2, 0, INFINITY);
106 EXPECT_THROW(argonSimulationStateBuilder.setupSimulationState(), InputException);
109 TEST(NBlibTest, SimulationStateCanMove)
111 ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
112 SimulationState simState = argonSimulationStateBuilder.setupSimulationState();
113 EXPECT_NO_THROW(SimulationState movedSimState = std::move(simState));
116 TEST(NBlibTest, SimulationStateCanAssign)
118 ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
119 SimulationState simState = argonSimulationStateBuilder.setupSimulationState();
120 EXPECT_NO_THROW(const SimulationState& gmx_unused AssignedSimState = simState);
123 TEST(NBlibTest, SimulationStateHasBox)
125 ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
126 SimulationState simState = argonSimulationStateBuilder.setupSimulationState();
127 const Box& testBox = simState.box();
128 const Box& refBox = argonSimulationStateBuilder.box();
129 // GTEST does not like the comparison operator in a different namespace
130 const bool compare = (refBox == testBox);
131 EXPECT_TRUE(compare);
134 TEST(NBlibTest, SimulationStateHasCorrectCoordinates)
136 ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
137 SimulationState simState = argonSimulationStateBuilder.setupSimulationState();
138 std::vector<Vec3> test = simState.coordinates();
139 std::vector<Vec3> ref = argonSimulationStateBuilder.coordinates();
140 compareValues(ref, test);
143 TEST(NBlibTest, SimulationStateHasCorrectVelocities)
145 ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
146 SimulationState simState = argonSimulationStateBuilder.setupSimulationState();
147 std::vector<Vec3> test = simState.velocities();
148 std::vector<Vec3> ref = argonSimulationStateBuilder.velocities();
149 compareValues(ref, test);