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 for mrc file header structure.
39 * \author Christian Blau <cblau@gwdg.de>
40 * \ingroup module_fileio
45 #include "gromacs/fileio/mrcdensitymapheader.h"
50 #include <gmock/gmock.h>
51 #include <gtest/gtest.h>
53 #include "testutils/testasserts.h"
54 #include "testutils/testmatchers.h"
59 TEST(MrcDensityMapHeaderTest, DataSizeIsZeroForDefaultHeader)
61 MrcDensityMapHeader header;
62 EXPECT_EQ(0, numberOfExpectedDataItems(header));
65 TEST(MrcDensityMapHeaderTest, DataSizeIsCorrect)
67 MrcDensityMapHeader header;
68 header.numColumnRowSection_ = { 1, 2, 3 };
69 EXPECT_EQ(6, numberOfExpectedDataItems(header));
72 TEST(MrcDensityMapHeaderTest, DataSizeThrowsWhenInvalid)
74 MrcDensityMapHeader header;
75 header.numColumnRowSection_ = { -1, 2, 3 };
76 EXPECT_THROW(numberOfExpectedDataItems(header), InternalError);
78 TEST(MrcDensityMapHeaderTest, GetsCorrectCoordinateTransformNoOriginGiven)
80 MrcDensityMapHeader header;
82 header.extent_ = { 100, 200, 300 };
83 header.columnRowSectionStart_ = { 50, 200, 0 };
84 header.cellLength_ = { 10, 20, 15 };
86 std::array<RVec, 2> testVectors = { RVec{ 0., 0., 0. }, RVec{ 1., 1., 1. } };
87 getCoordinateTransformationToLattice(header)(testVectors);
89 std::vector<RVec> expectedVectors = { { -50, -200, 0 }, { 50, -100, 200 } };
90 EXPECT_THAT(expectedVectors,
91 testing::Pointwise(test::RVecEq(test::defaultFloatTolerance()), testVectors));
94 TEST(MrcDensityMapHeaderTest, GetsCorrectCoordinateTransformWithOriginDefined)
96 MrcDensityMapHeader header;
97 header.userDefinedFloat_[12] = 1.;
98 header.userDefinedFloat_[13] = 2.;
99 header.userDefinedFloat_[14] = 3.;
100 header.extent_ = { 100, 200, 300 };
101 // setting the columnRowSectionStart values that are to be ignored if userDefinedFloat_ is not zero
102 header.columnRowSectionStart_ = { 50, 200, 0 };
103 header.cellLength_ = { 10, 20, 15 };
105 std::array<RVec, 2> testVectors = { RVec{ 0., 0., 0. }, RVec{ 1., 1., 1. } };
106 getCoordinateTransformationToLattice(header)(testVectors);
108 std::vector<RVec> expectedVectors = { { -10, -20, -60 }, { 90, 80, 140 } };
109 EXPECT_THAT(expectedVectors,
110 testing::Pointwise(test::RVecEq(test::defaultFloatTolerance()), testVectors));
113 TEST(MrcDensityMapHeaderTest, GetsCorrectCoordinateTransformWithStartValues)
115 MrcDensityMapHeader header;
116 header.userDefinedFloat_[12] = 0;
117 header.userDefinedFloat_[13] = 0;
118 header.userDefinedFloat_[14] = 0;
119 header.extent_ = { 100, 200, 300 };
120 header.columnRowSectionStart_ = { 50, 200, 0 };
121 header.cellLength_ = { 10, 20, 15 };
123 std::array<RVec, 2> testVectors = { RVec{ 0., 0., 0. }, RVec{ 1., 1., 1. } };
124 getCoordinateTransformationToLattice(header)(testVectors);
126 std::vector<RVec> expectedVectors = { { -50, -200, 0 }, { 50, -100, 200 } };
127 EXPECT_THAT(expectedVectors,
128 testing::Pointwise(test::RVecEq(test::defaultFloatTolerance()), testVectors));
131 TEST(MrcDensityMapHeaderTest, GetsCorrectExtents)
133 MrcDensityMapHeader header;
134 header.numColumnRowSection_ = { 100, 200, 300 };
136 const auto extents = getDynamicExtents3D(header);
137 std::array<std::ptrdiff_t, DIM> expectedExtents = { 300, 200, 100 };
138 EXPECT_EQ(expectedExtents[XX], extents.extent(XX));
139 EXPECT_EQ(expectedExtents[YY], extents.extent(YY));
140 EXPECT_EQ(expectedExtents[ZZ], extents.extent(ZZ));