From 6c3cdb08865124fa37dfac4b6424d4afac8597ab Mon Sep 17 00:00:00 2001 From: Joe Jordan Date: Mon, 29 Mar 2021 13:03:56 +0000 Subject: [PATCH] Add tests for calcvir --- src/gromacs/mdlib/tests/CMakeLists.txt | 1 + src/gromacs/mdlib/tests/calcvir.cpp | 153 ++++++++++++++++++ ...irTest_CanCalculateVirialAllAtomsInBox.xml | 19 +++ ...t_CanCalculateVirialAllAtomsInBoxScrew.xml | 19 +++ ..._CanCalculateVirialAtomsOutOfBoxScrewX.xml | 19 +++ ...anCalculateVirialAtomsOutOfBoxScrewXYZ.xml | 19 +++ ..._CanCalculateVirialAtomsOutOfBoxScrewY.xml | 19 +++ ..._CanCalculateVirialAtomsOutOfBoxScrewZ.xml | 19 +++ 8 files changed, 268 insertions(+) create mode 100644 src/gromacs/mdlib/tests/calcvir.cpp create mode 100644 src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAllAtomsInBox.xml create mode 100644 src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAllAtomsInBoxScrew.xml create mode 100644 src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAtomsOutOfBoxScrewX.xml create mode 100644 src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAtomsOutOfBoxScrewXYZ.xml create mode 100644 src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAtomsOutOfBoxScrewY.xml create mode 100644 src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAtomsOutOfBoxScrewZ.xml diff --git a/src/gromacs/mdlib/tests/CMakeLists.txt b/src/gromacs/mdlib/tests/CMakeLists.txt index 96e4760622..e50f85ab4f 100644 --- a/src/gromacs/mdlib/tests/CMakeLists.txt +++ b/src/gromacs/mdlib/tests/CMakeLists.txt @@ -35,6 +35,7 @@ gmx_add_unit_test(MdlibUnitTest mdlib-test HARDWARE_DETECTION CPP_SOURCE_FILES calc_verletbuf.cpp + calcvir.cpp constr.cpp constrtestdata.cpp constrtestrunners.cpp diff --git a/src/gromacs/mdlib/tests/calcvir.cpp b/src/gromacs/mdlib/tests/calcvir.cpp new file mode 100644 index 0000000000..55043968c4 --- /dev/null +++ b/src/gromacs/mdlib/tests/calcvir.cpp @@ -0,0 +1,153 @@ +/* + * This file is part of the GROMACS molecular simulation package. + * + * 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. + * + * GROMACS is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * GROMACS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with GROMACS; if not, see + * http://www.gnu.org/licenses, or write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * If you want to redistribute modifications to GROMACS, please + * consider that scientific software is very special. Version + * control is crucial - bugs must be traceable. We will be happy to + * consider code for inclusion in the official distribution, but + * derived work must not be called official GROMACS. Details are found + * in the README & COPYING files - if they are missing, get the + * official version at http://www.gromacs.org. + * + * To help us fund GROMACS development, we humbly ask that you cite + * the research papers on the package. Check out http://www.gromacs.org. + */ +/*! \internal \file + * \brief Tests for virial calculation. + * + * \author Joe Jordan + */ +#include "gmxpre.h" + +#include "gromacs/mdlib/calcvir.h" + +#include + +#include "testutils/refdata.h" +#include "testutils/testasserts.h" + +namespace gmx +{ +namespace test +{ +namespace +{ + + +class CalcvirTest : public ::testing::Test +{ +public: + TestReferenceData refData_; + TestReferenceChecker checker_; + std::vector coordinates_; + std::vector forces_; + int numVirialAtoms_; + tensor virial_{ { 0 } }; + FloatingPointTolerance tolerances = + FloatingPointTolerance(1e-16, 1.0e-16, 1e-16, 1.0e-7, 1000, 100, false); + + CalcvirTest() : + checker_(refData_.rootChecker()), + coordinates_{ { 1, 2, 3 }, + { + 4, + 5, + 6, + }, + { 7, 8, 9 } }, + forces_{ { 0.9, 0.1, 0.3 }, { 0.4, 0.7, 0.2 }, { 0.5, 1, 0.6 } }, + numVirialAtoms_(coordinates_.size()) + { + checker_.setDefaultTolerance(tolerances); + } + +private: +}; + +TEST_F(CalcvirTest, CanCalculateVirialAllAtomsInBox) +{ + calc_vir(numVirialAtoms_, as_rvec_array(coordinates_.data()), as_rvec_array(forces_.data()), virial_, false, nullptr); + + checker_.checkVector(virial_[0], "Virial x"); + checker_.checkVector(virial_[1], "Virial y"); + checker_.checkVector(virial_[2], "Virial z"); +} + +TEST_F(CalcvirTest, CanCalculateVirialAllAtomsInBoxScrew) +{ + + const matrix box = { { 10, 0, 0 }, { 0, 12, 0 }, { 0, 0, 14 } }; + calc_vir(numVirialAtoms_, as_rvec_array(coordinates_.data()), as_rvec_array(forces_.data()), virial_, true, box); + + checker_.checkVector(virial_[0], "Virial x"); + checker_.checkVector(virial_[1], "Virial y"); + checker_.checkVector(virial_[2], "Virial z"); +} + +TEST_F(CalcvirTest, CanCalculateVirialAtomsOutOfBoxScrewX) +{ + + const matrix box = { { 5, 0, 0 }, { 0, 10, 0 }, { 0, 0, 12 } }; + calc_vir(numVirialAtoms_, as_rvec_array(coordinates_.data()), as_rvec_array(forces_.data()), virial_, true, box); + + checker_.checkVector(virial_[0], "Virial x"); + checker_.checkVector(virial_[1], "Virial y"); + checker_.checkVector(virial_[2], "Virial z"); +} + +TEST_F(CalcvirTest, CanCalculateVirialAtomsOutOfBoxScrewY) +{ + + const matrix box = { { 10, 0, 0 }, { 0, 5, 0 }, { 0, 0, 12 } }; + calc_vir(numVirialAtoms_, as_rvec_array(coordinates_.data()), as_rvec_array(forces_.data()), virial_, true, box); + + checker_.checkVector(virial_[0], "Virial x"); + checker_.checkVector(virial_[1], "Virial y"); + checker_.checkVector(virial_[2], "Virial z"); +} + +TEST_F(CalcvirTest, CanCalculateVirialAtomsOutOfBoxScrewZ) +{ + + const matrix box = { { 10, 0, 0 }, { 0, 12, 0 }, { 0, 0, 5 } }; + calc_vir(numVirialAtoms_, as_rvec_array(coordinates_.data()), as_rvec_array(forces_.data()), virial_, true, box); + + checker_.checkVector(virial_[0], "Virial x"); + checker_.checkVector(virial_[1], "Virial y"); + checker_.checkVector(virial_[2], "Virial z"); +} + +TEST_F(CalcvirTest, CanCalculateVirialAtomsOutOfBoxScrewXYZ) +{ + + const matrix box = { { 4, 0, 0 }, { 0, 5, 0 }, { 0, 0, 6 } }; + calc_vir(numVirialAtoms_, as_rvec_array(coordinates_.data()), as_rvec_array(forces_.data()), virial_, true, box); + + checker_.checkVector(virial_[0], "Virial x"); + checker_.checkVector(virial_[1], "Virial y"); + checker_.checkVector(virial_[2], "Virial z"); +} + +} // namespace +} // namespace test +} // namespace gmx diff --git a/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAllAtomsInBox.xml b/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAllAtomsInBox.xml new file mode 100644 index 0000000000..68e13d9d89 --- /dev/null +++ b/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAllAtomsInBox.xml @@ -0,0 +1,19 @@ + + + + + -3 + -4.9500000000000002 + -2.6499999999999999 + + + -3.9000000000000004 + -5.8499999999999996 + -3.2000000000000002 + + + -4.8000000000000007 + -6.75 + -3.75 + + diff --git a/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAllAtomsInBoxScrew.xml b/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAllAtomsInBoxScrew.xml new file mode 100644 index 0000000000..bf2f13361b --- /dev/null +++ b/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAllAtomsInBoxScrew.xml @@ -0,0 +1,19 @@ + + + + + -5 + -8.4499999999999993 + -3.6499999999999999 + + + -6.3000000000000007 + -10.050000000000001 + -4.4000000000000004 + + + -7.6000000000000005 + -11.649999999999999 + -5.1500000000000004 + + diff --git a/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAtomsOutOfBoxScrewX.xml b/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAtomsOutOfBoxScrewX.xml new file mode 100644 index 0000000000..b95987f915 --- /dev/null +++ b/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAtomsOutOfBoxScrewX.xml @@ -0,0 +1,19 @@ + + + + + -4 + -6.6999999999999993 + -3.1499999999999999 + + + -5.9000000000000004 + -9.3499999999999996 + -4.2000000000000002 + + + -7.2000000000000002 + -10.949999999999999 + -4.9500000000000002 + + diff --git a/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAtomsOutOfBoxScrewXYZ.xml b/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAtomsOutOfBoxScrewXYZ.xml new file mode 100644 index 0000000000..42b61b501b --- /dev/null +++ b/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAtomsOutOfBoxScrewXYZ.xml @@ -0,0 +1,19 @@ + + + + + -3.7999999999999998 + -6.3499999999999996 + -3.0499999999999998 + + + -4.9000000000000004 + -7.5999999999999996 + -3.7000000000000002 + + + -6 + -8.8499999999999996 + -4.3499999999999996 + + diff --git a/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAtomsOutOfBoxScrewY.xml b/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAtomsOutOfBoxScrewY.xml new file mode 100644 index 0000000000..e7b0dc78d7 --- /dev/null +++ b/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAtomsOutOfBoxScrewY.xml @@ -0,0 +1,19 @@ + + + + + -5 + -8.4499999999999993 + -3.6499999999999999 + + + -4.9000000000000004 + -7.5999999999999996 + -3.7000000000000002 + + + -7.2000000000000002 + -10.949999999999999 + -4.9500000000000002 + + diff --git a/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAtomsOutOfBoxScrewZ.xml b/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAtomsOutOfBoxScrewZ.xml new file mode 100644 index 0000000000..b619e9441e --- /dev/null +++ b/src/gromacs/mdlib/tests/refdata/CalcvirTest_CanCalculateVirialAtomsOutOfBoxScrewZ.xml @@ -0,0 +1,19 @@ + + + + + -5 + -8.4499999999999993 + -3.6499999999999999 + + + -6.3000000000000007 + -10.050000000000001 + -4.4000000000000004 + + + -5.8000000000000007 + -8.5 + -4.25 + + -- 2.22.0