/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2020, by the GROMACS development team, led by
+ * Copyright (c) 2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
legacyMatrix_[dimZ][dimZ] = z;
}
+bool operator==(const Box& rhs, const Box& lhs)
+{
+ using real_ptr = const real*;
+ return std::equal(real_ptr(rhs.legacyMatrix()),
+ real_ptr(rhs.legacyMatrix()) + dimSize * dimSize,
+ real_ptr(lhs.legacyMatrix()));
+}
+
} // namespace nblib
[[nodiscard]] LegacyMatrix const& legacyMatrix() const { return legacyMatrix_; }
private:
+ //! \brief check two boxes for equality
+ friend bool operator==(const Box& rhs, const Box& lhs);
+
+ //! Stores data in the GROMACS legacy data type
LegacyMatrix legacyMatrix_;
};
auto bonds = pickType<HarmonicBondType>(interactions).parameters;
computeForces(indices, bonds, x, &forces, *pbc);
- Vector3DTest vector3DTest(1e-3);
- vector3DTest.testVectors(forces, "Bond forces");
+ RefDataChecker vector3DTest(1e-3);
+ vector3DTest.testArrays<Vec3>(forces, "Bond forces");
}
TEST_F(ListedExampleData, ComputeHarmonicBondEnergies)
auto bonds = pickType<HarmonicBondType>(interactions).parameters;
real energy = computeForces(indices, bonds, x, &forces, *pbc);
- Vector3DTest vector3DTest(1e-4);
+ RefDataChecker vector3DTest(1e-4);
vector3DTest.testReal(energy, "Bond energy");
}
auto angles = pickType<HarmonicAngleType>(interactions).parameters;
computeForces(indices, angles, x, &forces, *pbc);
- Vector3DTest vector3DTest(1e-4);
- vector3DTest.testVectors(forces, "Angle forces");
+ RefDataChecker vector3DTest(1e-4);
+ vector3DTest.testArrays<Vec3>(forces, "Angle forces");
}
TEST_F(ListedExampleData, CanReduceForces)
{
reduceListedForces(interactions, x, &forces, *pbc);
- Vector3DTest vector3DTest(1e-2);
- vector3DTest.testVectors(forces, "Reduced forces");
+ RefDataChecker vector3DTest(1e-2);
+ vector3DTest.testArrays<Vec3>(forces, "Reduced forces");
}
TEST_F(ListedExampleData, CanReduceEnergies)
auto energies = reduceListedForces(interactions, x, &forces, *pbc);
real totalEnergy = std::accumulate(begin(energies), end(energies), 0.0);
- Vector3DTest vector3DTest(1e-4);
+ RefDataChecker vector3DTest(1e-4);
vector3DTest.testReal(totalEnergy, "Reduced energy");
}
#
# To help us fund GROMACS development, we humbly ask that you cite
# the research papers on the package. Check out http://www.gromacs.org.
-#
+
# \author Victor Holanda <victor.holanda@cscs.ch>
# \author Joe Jordan <ejjordan@kth.se>
# \author Prashanth Kanduri <kanduri@cscs.ch>
# Make a static library for test infrastructure code that we re-use
# in multiple test executables across the repository.
gmx_add_unit_test_library(nblib_test_infrastructure
- testhelpers.cpp
testsystems.cpp
)
target_include_directories(nblib_test_infrastructure PRIVATE ${PROJECT_SOURCE_DIR}/api)
target_include_directories(nblib_test_infrastructure SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/src/external)
-target_link_libraries(nblib_test_infrastructure PRIVATE legacy_api)
-# TODO: Explicitly link specific modules: math,
-target_link_libraries(nblib_test_infrastructure PRIVATE legacy_modules)
+target_link_libraries(nblib_test_infrastructure PUBLIC legacy_api)
set(testname "NbLibSetupTests")
set(exename "nblib-setup-test")
molecules.cpp
topology.cpp
)
+target_link_libraries(${exename} PRIVATE mdrun_test_infrastructure)
target_link_libraries(${exename} PRIVATE nblib_test_infrastructure nblib)
target_include_directories(${exename} PRIVATE ${PROJECT_SOURCE_DIR}/api)
gmx_register_gtest_test(${testname} ${exename} INTEGRATION_TEST)
# files with code for tests
gmxcalculator.cpp
nbkernelsystem.cpp
- nbnxnsetup.cpp
simstate.cpp
)
target_link_libraries(${exename} PRIVATE nblib_test_infrastructure nblib)
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2020, by the GROMACS development team, led by
+ * Copyright (c) 2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
}
}
+TEST(NBlibTest, BoxEqual)
+{
+ {
+ Box a(0), b(0);
+ EXPECT_TRUE(a == b);
+ }
+ {
+ Box a(1), b(1);
+ EXPECT_TRUE(a == b);
+ }
+ {
+ Box a(1, 2, 3), b(1, 2, 3);
+ EXPECT_TRUE(a == b);
+ }
+ {
+ Box a(0, 2, 3), b(1, 2, 3);
+ EXPECT_FALSE(a == b);
+ }
+}
+
} // namespace nblib
{
TEST(NBlibTest, GmxForceCalculatorCanCompute)
{
- ArgonSimulationStateBuilder argonSystemBuilder;
+ ArgonSimulationStateBuilder argonSystemBuilder(fftypes::GROMOS43A1);
SimulationState simState = argonSystemBuilder.setupSimulationState();
NBKernelOptions options = NBKernelOptions();
options.nbnxmSimd = SimdKernels::SimdNo;
* \author Sebastian Keller <keller@cscs.ch>
* \author Artem Zhmurov <zhmurov@gmail.com>
*/
-#include "nblib/integrator.h"
#include "gromacs/pbcutil/pbc.h"
#include "gromacs/utility/arrayref.h"
+#include "nblib/integrator.h"
#include "nblib/molecules.h"
#include "nblib/particletype.h"
#include "nblib/simulationstate.h"
#include "nblib/topology.h"
+#include "nblib/vector.h"
#include "testutils/testasserts.h"
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2020, by the GROMACS development team, led by
+ * Copyright (c) 2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
molecule.addParticle(ParticleName("H1"), H);
molecule.addParticle(ParticleName("H2"), H);
- HarmonicBondType hb(1, 2);
- CubicBondType cub(1, 2, 3);
- HarmonicAngleType ang(Degrees(1), 1);
+ HarmonicBondType hb(1, 2);
+ CubicBondType cub(1, 2, 3);
+ HarmonicAngleType ang(Degrees(1), 1);
molecule.addInteraction(ParticleName("O"), ParticleName("H1"), hb);
molecule.addInteraction(ParticleName("O"), ParticleName("H2"), hb);
gmx::ArrayRef<Vec3> forces(simState.forces());
ASSERT_NO_THROW(forceCalculator.compute(simState.coordinates(), forces));
- Vector3DTest forcesOutputTest(5e-5);
- forcesOutputTest.testVectors(forces, "SPC-methanol forces");
+ RefDataChecker forcesOutputTest(5e-5);
+ forcesOutputTest.testArrays<Vec3>(forces, "SPC-methanol forces");
}
TEST(NBlibTest, ExpectedNumberOfForces)
}
}
-TEST(NBlibTest, ArgonForcesAreCorrect)
+TEST(NBlibTest, ArgonOplsaForcesAreCorrect)
{
auto options = NBKernelOptions();
options.nbnxmSimd = SimdKernels::SimdNo;
options.coulombType = CoulombType::Cutoff;
- ArgonSimulationStateBuilder argonSystemBuilder;
+ ArgonSimulationStateBuilder argonSystemBuilder(fftypes::OPLSA);
auto simState = argonSystemBuilder.setupSimulationState();
auto forceCalculator = ForceCalculator(simState, options);
gmx::ArrayRef<Vec3> testForces(simState.forces());
forceCalculator.compute(simState.coordinates(), simState.forces());
- Vector3DTest forcesOutputTest;
- forcesOutputTest.testVectors(testForces, "Argon forces");
+ RefDataChecker forcesOutputTest(1e-7);
+ forcesOutputTest.testArrays<Vec3>(testForces, "Argon forces");
+}
+
+TEST(NBlibTest, ArgonGromos43A1ForcesAreCorrect)
+{
+ auto options = NBKernelOptions();
+ options.nbnxmSimd = SimdKernels::SimdNo;
+ options.coulombType = CoulombType::Cutoff;
+
+ ArgonSimulationStateBuilder argonSystemBuilder(fftypes::GROMOS43A1);
+
+ auto simState = argonSystemBuilder.setupSimulationState();
+ auto forceCalculator = ForceCalculator(simState, options);
+
+ gmx::ArrayRef<Vec3> testForces(simState.forces());
+ forceCalculator.compute(simState.coordinates(), simState.forces());
+
+ RefDataChecker forcesOutputTest(1e-7);
+ forcesOutputTest.testArrays<Vec3>(testForces, "Argon forces");
}
} // namespace
--- /dev/null
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+ <Sequence Name="Argon forces">
+ <Int Name="Length">12</Int>
+ <Vector>
+ <Real Name="X">-0.41298821868424429</Real>
+ <Real Name="Y">-1.0982427445010643</Real>
+ <Real Name="Z">-0.11318936363938557</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0.41298821868424429</Real>
+ <Real Name="Y">1.0982427445010643</Real>
+ <Real Name="Z">0.11318936363938557</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ </Sequence>
+</ReferenceData>
--- /dev/null
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+ <Sequence Name="Argon forces">
+ <Int Name="Length">12</Int>
+ <Vector>
+ <Real Name="X">-1.4060510037205805</Real>
+ <Real Name="Y">-3.7390541506347286</Real>
+ <Real Name="Z">-0.38536212694564093</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">1.4060510037205805</Real>
+ <Real Name="Y">3.7390541506347286</Real>
+ <Real Name="Z">0.38536212694564093</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ </Sequence>
+</ReferenceData>
--- /dev/null
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+ <Sequence Name="SPC-methanol energies">
+ <Int Name="Length">5</Int>
+ <Real>-7.1674767</Real>
+ <Real>-0.11698186</Real>
+ <Real>0</Real>
+ <Real>0</Real>
+ <Real>0</Real>
+ </Sequence>
+</ReferenceData>
--- /dev/null
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+ <Sequence Name="SPC-methanol forces on GPU">
+ <Int Name="Length">6</Int>
+ <Vector>
+ <Real Name="X">-0.38183594</Real>
+ <Real Name="Y">0.87922907</Real>
+ <Real Name="Z">-6.1406441</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">8.3033295</Real>
+ <Real Name="Y">-7.338829</Real>
+ <Real Name="Z">27.783722</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">-9.4221649</Real>
+ <Real Name="Y">6.2920837</Real>
+ <Real Name="Z">-33.986099</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">27.494339</Real>
+ <Real Name="Y">8.3915062</Real>
+ <Real Name="Z">39.693787</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">-19.009857</Real>
+ <Real Name="Y">-5.3975139</Real>
+ <Real Name="Z">-15.545643</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">-6.9838257</Real>
+ <Real Name="Y">-2.8264766</Real>
+ <Real Name="Z">-11.805126</Real>
+ </Vector>
+ </Sequence>
+</ReferenceData>
--- /dev/null
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+ <Sequence Name="coordinates">
+ <Int Name="Length">12</Int>
+ <Vector>
+ <Real Name="X">0.794</Real>
+ <Real Name="Y">1.439</Real>
+ <Real Name="Z">0.61</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">1.397</Real>
+ <Real Name="Y">0.673</Real>
+ <Real Name="Z">1.916</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0.659</Real>
+ <Real Name="Y">1.08</Real>
+ <Real Name="Z">0.573</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">1.105</Real>
+ <Real Name="Y">0.09</Real>
+ <Real Name="Z">3.431</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">1.741</Real>
+ <Real Name="Y">1.291</Real>
+ <Real Name="Z">3.432</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">1.936</Real>
+ <Real Name="Y">1.441</Real>
+ <Real Name="Z">5.873</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0.96</Real>
+ <Real Name="Y">2.246</Real>
+ <Real Name="Z">1.659</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0.382</Real>
+ <Real Name="Y">3.023</Real>
+ <Real Name="Z">2.793</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0.053</Real>
+ <Real Name="Y">4.857</Real>
+ <Real Name="Z">4.242</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">2.655</Real>
+ <Real Name="Y">5.057</Real>
+ <Real Name="Z">2.211</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">4.114</Real>
+ <Real Name="Y">0.737</Real>
+ <Real Name="Z">0.614</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">5.977</Real>
+ <Real Name="Y">5.104</Real>
+ <Real Name="Z">5.217</Real>
+ </Vector>
+ </Sequence>
+
+ <Sequence Name="velocities">
+ <Int Name="Length">12</Int>
+ <Vector>
+ <Real Name="X">0.0055</Real>
+ <Real Name="Y">-0.14</Real>
+ <Real Name="Z">0.2127</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0.093</Real>
+ <Real Name="Y">-0.016</Real>
+ <Real Name="Z">-0.0086</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0.1678</Real>
+ <Real Name="Y">0.2476</Real>
+ <Real Name="Z">-0.066</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0.1591</Real>
+ <Real Name="Y">-0.0934</Real>
+ <Real Name="Z">-0.0835</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">-0.0317</Real>
+ <Real Name="Y">0.0573</Real>
+ <Real Name="Z">0.1453</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0.0597</Real>
+ <Real Name="Y">0.0013</Real>
+ <Real Name="Z">-0.0462</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0.0484</Real>
+ <Real Name="Y">-0.0357</Real>
+ <Real Name="Z">0.0168</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0.053</Real>
+ <Real Name="Y">0.0295</Real>
+ <Real Name="Z">-0.2694</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">-0.055</Real>
+ <Real Name="Y">-0.0896</Real>
+ <Real Name="Z">0.0494</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">-0.0799</Real>
+ <Real Name="Y">-0.2534</Real>
+ <Real Name="Z">-0.0079</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0.0436</Real>
+ <Real Name="Y">-0.1557</Real>
+ <Real Name="Z">0.1849</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">-0.0214</Real>
+ <Real Name="Y">0.0446</Real>
+ <Real Name="Z">0.0758</Real>
+ </Vector>
+ </Sequence>
+
+ <Sequence Name="nbparams">
+ <Int Name="Length">2</Int>
+ <Real>0.0351364166</Real>
+ <Real>9.8438366e-05</Real>
+ </Sequence>
+
+ <Sequence Name="exclusion elements">
+ <Int Name="Length">12</Int>
+ <Int>0</Int>
+ <Int>1</Int>
+ <Int>2</Int>
+ <Int>3</Int>
+ <Int>4</Int>
+ <Int>5</Int>
+ <Int>6</Int>
+ <Int>7</Int>
+ <Int>8</Int>
+ <Int>9</Int>
+ <Int>10</Int>
+ <Int>11</Int>
+ </Sequence>
+
+ <Sequence Name="exclusion ranges">
+ <Int Name="Length">13</Int>
+ <Int>0</Int>
+ <Int>1</Int>
+ <Int>2</Int>
+ <Int>3</Int>
+ <Int>4</Int>
+ <Int>5</Int>
+ <Int>6</Int>
+ <Int>7</Int>
+ <Int>8</Int>
+ <Int>9</Int>
+ <Int>10</Int>
+ <Int>11</Int>
+ <Int>12</Int>
+ </Sequence>
+</ReferenceData>
--- /dev/null
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+ <Sequence Name="Argon forces">
+ <Int Name="Length">12</Int>
+ <Vector>
+ <Real Name="X">-1.4060510037205805</Real>
+ <Real Name="Y">-3.7390541506347286</Real>
+ <Real Name="Z">-0.38536212694564093</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">1.4060510037205805</Real>
+ <Real Name="Y">3.7390541506347286</Real>
+ <Real Name="Z">0.38536212694564093</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ <Vector>
+ <Real Name="X">0</Real>
+ <Real Name="Y">0</Real>
+ <Real Name="Z">0</Real>
+ </Vector>
+ </Sequence>
+</ReferenceData>
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2020, by the GROMACS development team, led by
+ * Copyright (c) 2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
TEST(NBlibTest, CanConstructSimulationState)
{
- ArgonSimulationStateBuilder argonSimulationStateBuilder;
+ ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
EXPECT_NO_THROW(argonSimulationStateBuilder.setupSimulationState());
}
TEST(NBlibTest, SimulationStateThrowsCoordinateNAN)
{
- ArgonSimulationStateBuilder argonSimulationStateBuilder;
+ ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
argonSimulationStateBuilder.setCoordinate(2, 0, NAN);
EXPECT_THROW(argonSimulationStateBuilder.setupSimulationState(), InputException);
}
TEST(NBlibTest, SimulationStateThrowsCoordinateINF)
{
- ArgonSimulationStateBuilder argonSimulationStateBuilder;
+ ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
argonSimulationStateBuilder.setCoordinate(2, 0, INFINITY);
EXPECT_THROW(argonSimulationStateBuilder.setupSimulationState(), InputException);
}
TEST(NBlibTest, SimulationStateThrowsVelocityNAN)
{
- ArgonSimulationStateBuilder argonSimulationStateBuilder;
+ ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
argonSimulationStateBuilder.setVelocity(2, 0, NAN);
EXPECT_THROW(argonSimulationStateBuilder.setupSimulationState(), InputException);
}
TEST(NBlibTest, SimulationStateThrowsVelocityINF)
{
- ArgonSimulationStateBuilder argonSimulationStateBuilder;
+ ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
argonSimulationStateBuilder.setVelocity(2, 0, INFINITY);
EXPECT_THROW(argonSimulationStateBuilder.setupSimulationState(), InputException);
}
TEST(NBlibTest, SimulationStateCanMove)
{
- ArgonSimulationStateBuilder argonSimulationStateBuilder;
+ ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
SimulationState simState = argonSimulationStateBuilder.setupSimulationState();
EXPECT_NO_THROW(SimulationState movedSimState = std::move(simState));
}
TEST(NBlibTest, SimulationStateCanAssign)
{
- ArgonSimulationStateBuilder argonSimulationStateBuilder;
+ ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
SimulationState simState = argonSimulationStateBuilder.setupSimulationState();
EXPECT_NO_THROW(const SimulationState& gmx_unused AssignedSimState = simState);
}
TEST(NBlibTest, SimulationStateHasBox)
{
- ArgonSimulationStateBuilder argonSimulationStateBuilder;
+ ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
SimulationState simState = argonSimulationStateBuilder.setupSimulationState();
const Box& testBox = simState.box();
const Box& refBox = argonSimulationStateBuilder.box();
TEST(NBlibTest, SimulationStateHasCorrectCoordinates)
{
- ArgonSimulationStateBuilder argonSimulationStateBuilder;
+ ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
SimulationState simState = argonSimulationStateBuilder.setupSimulationState();
std::vector<Vec3> test = simState.coordinates();
std::vector<Vec3> ref = argonSimulationStateBuilder.coordinates();
TEST(NBlibTest, SimulationStateHasCorrectVelocities)
{
- ArgonSimulationStateBuilder argonSimulationStateBuilder;
+ ArgonSimulationStateBuilder argonSimulationStateBuilder(fftypes::GROMOS43A1);
SimulationState simState = argonSimulationStateBuilder.setupSimulationState();
std::vector<Vec3> test = simState.velocities();
std::vector<Vec3> ref = argonSimulationStateBuilder.velocities();
#include "gromacs/math/vectypes.h"
#include "gromacs/utility/arrayref.h"
+
#include "nblib/box.h"
#include "nblib/vector.h"
+#include "testutils/conftest.h"
#include "testutils/refdata.h"
-#include "testutils/testasserts.h"
namespace nblib
{
namespace test
{
-//! Compare between two instances of the Box object
-bool operator==(const Box& a, const Box& b);
-
/*! \internal \brief
* Simple test harness for checking 3D vectors like coordinates, velocities,
* forces against reference data
*
*/
-class Vector3DTest
+class RefDataChecker
{
public:
- Vector3DTest() : checker_(refData_.rootChecker())
+ RefDataChecker() : checker_(refData_.rootChecker())
{
gmx::test::FloatingPointTolerance tolerance(
gmx::test::FloatingPointTolerance(1e-8, 1.0e-12, 1e-8, 1.0e-12, 200, 100, true));
checker_.setDefaultTolerance(tolerance);
}
- Vector3DTest(real relativeFloatingPointTolerance) : checker_(refData_.rootChecker())
+ RefDataChecker(real relativeFloatingPointTolerance) : checker_(refData_.rootChecker())
{
gmx::test::FloatingPointTolerance tolerance(gmx::test::FloatingPointTolerance(
- 1e-8, 1.0e-12, relativeFloatingPointTolerance, 1.0e-12, 200, 100, true));
+ 1e-6, 1.0e-9, relativeFloatingPointTolerance, relativeFloatingPointTolerance, 200, 100, true));
checker_.setDefaultTolerance(tolerance);
}
- //! Compare a given input vector of cartesians with the reference data
- void testVectors(gmx::ArrayRef<Vec3> forces, const std::string& testName)
+ //! Compare a given input array of cartesians, reals, integers, etc with the reference data
+ template<class T>
+ void testArrays(gmx::ArrayRef<T> tArray, const std::string& testString)
{
- checker_.checkSequence(forces.begin(), forces.end(), testName.c_str());
+ checker_.checkSequence(tArray.begin(), tArray.end(), testString.c_str());
}
void testReal(real value, const std::string& testName)
ParticleType H(ParticleTypeName("H"), Mass(1.008));
ParticleType OMet(ParticleTypeName("OMet"), Mass(15.999));
ParticleType CMet(ParticleTypeName("CMet"), Mass(15.035));
- ParticleType Ar(ParticleTypeName("Ar"), Mass(39.94800));
+ ParticleType Ar_gromos(ParticleTypeName("Ar_gromos"), Mass(39.94800));
+ ParticleType Ar_opls(ParticleTypeName("Ar_opls"), Mass(39.94800));
particles_.insert(std::make_pair(Ow.name(), Ow));
particles_.insert(std::make_pair(H.name(), H));
particles_.insert(std::make_pair(OMet.name(), OMet));
particles_.insert(std::make_pair(CMet.name(), CMet));
- particles_.insert(std::make_pair(Ar.name(), Ar));
-
- c6_[Ow.name()] = 0.0026173456;
- c6_[H.name()] = 0;
- c6_[OMet.name()] = 0.0022619536;
- c6_[CMet.name()] = 0.0088755241;
- c6_[Ar.name()] = 0.0062647225;
-
- c12_[Ow.name()] = 2.634129e-06;
- c12_[H.name()] = 0;
- c12_[OMet.name()] = 1.505529e-06;
- c12_[CMet.name()] = 2.0852922e-05;
- c12_[Ar.name()] = 9.847044e-06;
+ particles_.insert(std::make_pair(Ar_gromos.name(), Ar_gromos));
+ particles_.insert(std::make_pair(Ar_opls.name(), Ar_opls));
+
+ c6_[Ow.name()] = 0.0026173456;
+ c6_[H.name()] = 0;
+ c6_[OMet.name()] = 0.0022619536;
+ c6_[CMet.name()] = 0.0088755241;
+ c6_[Ar_gromos.name()] = 0.0062647225;
+ c6_[Ar_opls.name()] = 0.0058560692;
+
+ c12_[Ow.name()] = 2.634129e-06;
+ c12_[H.name()] = 0;
+ c12_[OMet.name()] = 1.505529e-06;
+ c12_[CMet.name()] = 2.0852922e-05;
+ c12_[Ar_gromos.name()] = 9.847044e-06;
+ c12_[Ar_opls.name()] = 8.203193e-06;
}
//! Get particle type using the string identifier
return waterMolecule_.waterMolecule();
}
-ArgonTopologyBuilder::ArgonTopologyBuilder(const int& numParticles)
+ArgonTopologyBuilder::ArgonTopologyBuilder(const int& numParticles, const fftypes forceField)
{
ParticleLibrary library;
ParticleTypesInteractions nbinteractions;
- nbinteractions.add(
- ParticleTypeName("Ar"), library.c6(ParticleName("Ar")), library.c12(ParticleName("Ar")));
Molecule argonMolecule(MoleculeName("AR"));
- argonMolecule.addParticle(ParticleName("AR"), library.type("Ar"));
+
+ std::string particleName;
+
+ if (forceField == fftypes::GROMOS43A1)
+ {
+ particleName = "Ar_gromos";
+ }
+ else if (forceField == fftypes::OPLSA)
+ {
+ particleName = "Ar_opls";
+ }
+
+ nbinteractions.add(ParticleTypeName(particleName),
+ library.c6(ParticleName(particleName)),
+ library.c12(ParticleName(particleName)));
+ argonMolecule.addParticle(ParticleName("AR"), library.type(particleName));
topologyBuilder_.addMolecule(argonMolecule, numParticles);
topologyBuilder_.addParticleTypesInteractions((nbinteractions));
return topologyBuilder_.buildTopology();
}
-ArgonSimulationStateBuilder::ArgonSimulationStateBuilder() :
- box_(6.05449), topology_(ArgonTopologyBuilder(12).argonTopology())
+ArgonSimulationStateBuilder::ArgonSimulationStateBuilder(const fftypes forceField) :
+ box_(6.05449), topology_(ArgonTopologyBuilder(12, forceField).argonTopology())
{
coordinates_ = {
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2020, by the GROMACS development team, led by
+ * Copyright (c) 2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
namespace nblib
{
+//! \internal \brief Force field types to select parameter sets
+enum class fftypes : int
+{
+ GROMOS43A1,
+ OPLSA
+};
+
//! \internal \brief Parameters from gromos43A1
struct ArAtom
{
{
public:
//! Build a topology with specified argon molecules
- ArgonTopologyBuilder(const int& numParticles);
+ ArgonTopologyBuilder(const int& numParticles, const fftypes forceField);
//! Get the topology with specified argon molecules
Topology argonTopology();
class ArgonSimulationStateBuilder
{
public:
- ArgonSimulationStateBuilder();
+ ArgonSimulationStateBuilder(const fftypes forceField);
//! Set coordinates of particles in the defined system
void setCoordinate(int particleNum, int dimension, real value);
Molecule water = WaterMoleculeBuilder{}.waterMolecule();
Molecule methanol = MethanolMoleculeBuilder{}.methanolMolecule();
- CubicBondType testBond(1., 1., 1.);
+ CubicBondType testBond(1., 1., 1.);
HarmonicAngleType testAngle(Degrees(1), 1);
water.addInteraction(ParticleName("H1"), ParticleName("H2"), testBond);
std::vector<Vec3> velocities;
velocities = generateVelocity(300.0, 1, masses);
- Vector3DTest velocitiesTest;
- velocitiesTest.testVectors(velocities, "generated-velocities");
+ RefDataChecker velocitiesTest;
+ velocitiesTest.testArrays<Vec3>(velocities, "generated-velocities");
}
TEST(NBlibTest, generateVelocitySize)
{