Apply re-formatting to C++ in src/ tree.
[alexxy/gromacs.git] / src / gromacs / trajectoryanalysis / tests / rdf.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2014,2015,2019,2020, 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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*! \internal \file
36  * \brief
37  * Tests for functionality of the "rdf" trajectory analysis module.
38  *
39  * These tests are essentially regression tests for the actual RDF calculation
40  * from very small configurations.  Exclusions are not tested (since the input
41  * does not contain any), nor is the effect of -cut of -rmax.
42  * At the moment, they do not test the final normalization, but only the pair
43  * counts calculated for each frame.  Tests for the final normalization should
44  * be added once related TODOs in the implementation/framework have been
45  * resolved (currently, the test framework does not see the final output data).
46  *
47  * \author Teemu Murtola <teemu.murtola@gmail.com>
48  * \ingroup module_trajectoryanalysis
49  */
50 #include "gmxpre.h"
51
52 #include "gromacs/trajectoryanalysis/modules/rdf.h"
53
54 #include <gtest/gtest.h>
55
56 #include "testutils/cmdlinetest.h"
57 #include "testutils/testasserts.h"
58 #include "testutils/textblockmatchers.h"
59
60 #include "moduletest.h"
61
62 namespace
63 {
64
65 using gmx::test::CommandLine;
66 using gmx::test::NoTextMatch;
67
68 /********************************************************************
69  * Tests for gmx::analysismodules::Rdf.
70  */
71
72 //! Test fixture for the `rdf` analysis module.
73 typedef gmx::test::TrajectoryAnalysisModuleTestFixture<gmx::analysismodules::RdfInfo> RdfModuleTest;
74
75 TEST_F(RdfModuleTest, BasicTest)
76 {
77     const char* const cmdline[] = { "rdf",     "-bin", "0.05",    "-ref",
78                                     "name OW", "-sel", "name OW", "not name OW" };
79     setTopology("spc216.gro");
80     setOutputFile("-o", ".xvg", NoTextMatch());
81     excludeDataset("pairdist");
82     runTest(CommandLine(cmdline));
83 }
84
85 TEST_F(RdfModuleTest, SelectionsSolelyFromIndexFileWork)
86 {
87     const char* const cmdline[] = { "rdf",
88                                     "-bin",
89                                     "0.05",
90                                     // Use selection that names a group in the index file
91                                     "-ref",
92                                     "name_OW",
93                                     // Use selections that name groups in the index file
94                                     "-sel",
95                                     "name_OW",
96                                     "not_name_OW" };
97     // Note not supplying a topology file to -s
98     setTrajectory("spc216.gro");
99     setInputFile("-n", "index.ndx");
100     setOutputFile("-o", ".xvg", NoTextMatch());
101     excludeDataset("pairdist");
102     runTest(CommandLine(cmdline));
103 }
104
105 TEST_F(RdfModuleTest, SelectionsFromBothTopologyFileAndIndexFileWork)
106 {
107     const char* const cmdline[] = { "rdf",
108                                     "-bin",
109                                     "0.05",
110                                     // Use selection whose parsing requires topology file
111                                     "-ref",
112                                     "name OW",
113                                     // Use selections that name groups in the index file
114                                     "-sel",
115                                     "name_OW",
116                                     "not_name_OW" };
117     // Note supplying a topology file to -s
118     setTopology("spc216.gro");
119     setInputFile("-n", "index.ndx");
120     setOutputFile("-o", ".xvg", NoTextMatch());
121     excludeDataset("pairdist");
122     runTest(CommandLine(cmdline));
123 }
124
125 TEST_F(RdfModuleTest, CalculatesSurf)
126 {
127     const char* const cmdline[] = { "rdf",
128                                     "-bin",
129                                     "0.05",
130                                     "-surf",
131                                     "res",
132                                     "-ref",
133                                     "within 0.5 of (resnr 1 and name OW)",
134                                     "-sel",
135                                     "name OW",
136                                     "not name OW" };
137     setTopology("spc216.gro");
138     setOutputFile("-o", ".xvg", NoTextMatch());
139     excludeDataset("pairdist");
140     runTest(CommandLine(cmdline));
141 }
142
143 TEST_F(RdfModuleTest, CalculatesXY)
144 {
145     const char* const cmdline[] = { "rdf",     "-bin", "0.05",    "-xy",        "-ref",
146                                     "name OW", "-sel", "name OW", "not name OW" };
147     setTopology("spc216.gro");
148     setOutputFile("-o", ".xvg", NoTextMatch());
149     excludeDataset("pairdist");
150     // TODO: Consider if it is possible to get a more reproducible result
151     // and/or a stricter tolerance (e.g., by checking that the sum of
152     // neighboring values still stays constant).
153     setDatasetTolerance("paircount", gmx::test::absoluteTolerance(2.5));
154     runTest(CommandLine(cmdline));
155 }
156
157 } // namespace