2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2019, 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 * Tests structure similarity measures rmsd and size-independent rho factor.
39 * \author Christian Blau <cblau@gwdg.de>
40 * \ingroup module_math
44 #include "gromacs/math/coordinatetransformation.h"
48 #include <gmock/gmock.h>
49 #include <gtest/gtest.h>
51 #include "testutils/testasserts.h"
52 #include "testutils/testmatchers.h"
60 using ::testing::Pointwise;
61 class TranslateAndScaleTest : public ::testing::Test
64 RVec identityScale_ = { 1, 1, 1 };
65 RVec identityTranslation_ = { 0, 0, 0 };
66 std::vector<RVec> testVectors_ = { { 0, 0, 0 },
73 TEST_F(TranslateAndScaleTest, identityTransformation)
75 TranslateAndScale translateAndScale(identityScale_, identityTranslation_);
76 auto toBeTransformed = testVectors_;
77 translateAndScale(toBeTransformed);
78 EXPECT_THAT(testVectors_, Pointwise(RVecEq(defaultFloatTolerance()), toBeTransformed));
81 TEST_F(TranslateAndScaleTest, translationWithIdentityScaling)
83 TranslateAndScale translateAndScale(identityScale_, { 1, -1, 2 });
84 translateAndScale(testVectors_);
85 std::vector<RVec> expected = {
86 { 1, -1, 2 }, { 2, -1, 2 }, { 1, -2, 1 }, { 1e10 + 1, 1e1 - 1, 1e-2 + 2 }, { 4, -7, 4.5 }
88 EXPECT_THAT(expected, Pointwise(RVecEq(defaultFloatTolerance()), testVectors_));
91 TEST_F(TranslateAndScaleTest, scalingWithZeroTranslation)
93 TranslateAndScale translateAndScale({ -1e10, 2, 0 }, identityTranslation_);
94 translateAndScale(testVectors_);
95 std::vector<RVec> expected = {
96 { 0, 0, 0 }, { -1e10, 0, 0 }, { 0, -2, 0 }, { -1e20, 2e1, 0 }, { -3e10, -12, 0 }
98 EXPECT_THAT(expected, Pointwise(RVecEq(defaultFloatTolerance()), testVectors_));
101 TEST_F(TranslateAndScaleTest, translationAndScalingNonTrivial)
103 TranslateAndScale translateAndScale({ -1e10, 2, 0 }, { 1, -1, 2 });
104 translateAndScale(testVectors_);
105 std::vector<RVec> expected = {
106 { -1e+10, -2, 0 }, { -2e+10, -2, 0 }, { -1e+10, -4, 0 }, { -1e+20, 18, 0 }, { -4e+10, -14, 0 }
108 EXPECT_THAT(expected, Pointwise(RVecEq(defaultFloatTolerance()), testVectors_));
111 TEST_F(TranslateAndScaleTest, scalingIdentity)
113 ScaleCoordinates scale(identityScale_);
114 auto expected = testVectors_;
116 EXPECT_THAT(expected, Pointwise(RVecEq(defaultFloatTolerance()), testVectors_));
119 TEST_F(TranslateAndScaleTest, scalingNonTrivial)
121 ScaleCoordinates scale({ -100, 0.1, 0 });
122 std::vector<RVec> expected = {
123 { 0, 0, 0 }, { -100, 0, 0 }, { 0, -0.1, 0 }, { -1e12, 1e0, 0 }, { -300, -0.6, 0 }
126 EXPECT_THAT(expected, Pointwise(RVecEq(defaultFloatTolerance()), testVectors_));
129 TEST_F(TranslateAndScaleTest, scalingInverseNoZero)
131 ScaleCoordinates scale({ -100, 0.1, 3 });
132 auto expected = testVectors_;
134 scale.inverseIgnoringZeroScale(testVectors_);
135 EXPECT_THAT(expected, Pointwise(RVecEq(defaultFloatTolerance()), testVectors_));
138 TEST_F(TranslateAndScaleTest, scalingInverseWithOneScaleDimensionZero)
140 ScaleCoordinates scale({ -100, 0.1, 0 });
141 std::vector<RVec> expected = { { 0, 0, 0 }, { 1, 0, 0 }, { 0, -1, 0 }, { 1e10, 1e1, 0 }, { 3, -6, 0 } };
143 scale.inverseIgnoringZeroScale(testVectors_);
144 EXPECT_THAT(expected, Pointwise(RVecEq(defaultFloatTolerance()), testVectors_));