Split lines with many copyright years
[alexxy/gromacs.git] / src / programs / mdrun / tests / trajectory_writing.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2013,2014,2015,2016,2018 by the GROMACS development team.
5  * Copyright (c) 2019,2020, by the GROMACS development team, led by
6  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7  * and including many others, as listed in the AUTHORS file in the
8  * top-level source directory and at http://www.gromacs.org.
9  *
10  * GROMACS is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public License
12  * as published by the Free Software Foundation; either version 2.1
13  * of the License, or (at your option) any later version.
14  *
15  * GROMACS is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with GROMACS; if not, see
22  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
24  *
25  * If you want to redistribute modifications to GROMACS, please
26  * consider that scientific software is very special. Version
27  * control is crucial - bugs must be traceable. We will be happy to
28  * consider code for inclusion in the official distribution, but
29  * derived work must not be called official GROMACS. Details are found
30  * in the README & COPYING files - if they are missing, get the
31  * official version at http://www.gromacs.org.
32  *
33  * To help us fund GROMACS development, we humbly ask that you cite
34  * the research papers on the package. Check out http://www.gromacs.org.
35  */
36
37 /*! \internal \file
38  * \brief
39  * Tests for the .mdp nst*out functionality
40  *
41  * \author Mark Abraham <mark.j.abraham@gmail.com>
42  * \ingroup module_mdrun_integration_tests
43  */
44 #include "gmxpre.h"
45
46 #include "config.h"
47
48 #include <gtest/gtest.h>
49
50 #include "gromacs/options/filenameoption.h"
51 #include "gromacs/utility/stringutil.h"
52
53 #include "moduletest.h"
54
55 namespace
56 {
57
58 // TODO configure these tests so they test all formats for mdrun trajectory writing
59 #if GMX_USE_TNG
60
61 //! Test fixture for mdrun trajectory writing
62 class TrajectoryWritingTest :
63     public gmx::test::MdrunTestFixture,
64     public ::testing::WithParamInterface<const char*>
65 {
66 public:
67     //! The file name of the MDP file
68     std::string theMdpFile;
69
70     //! Execute the trajectory writing test
71     void runTest()
72     {
73         runner_.useStringAsMdpFile(theMdpFile);
74         runner_.useTopGroAndNdxFromDatabase("spc-and-methanol");
75         EXPECT_EQ(0, runner_.callGrompp());
76
77         runner_.fullPrecisionTrajectoryFileName_ =
78                 fileManager_.getTemporaryFilePath("spc-and-methanol.tng");
79         runner_.reducedPrecisionTrajectoryFileName_ =
80                 fileManager_.getTemporaryFilePath("spc-and-methanol-reduced.tng");
81         ASSERT_EQ(0, runner_.callMdrun());
82         // TODO When there is a way to sense something like the
83         // output of gmx check, compare the result with that from
84         // writing .trr and .xtc and assert the behaviour is
85         // correct. Note that TNG will always write the box, even
86         // when constant - this will be a source of
87         // trajectory-file differences.
88     }
89 };
90
91 //! Helper typedef for naming test cases like sentences
92 typedef TrajectoryWritingTest Trajectories;
93
94 /* This test ensures mdrun can write various quantities at various
95    frequencies */
96 TEST_P(Trajectories, ThatDifferInNstxout)
97 {
98     theMdpFile = gmx::formatString(
99             "integrator = md\n"
100             "nsteps = 6\n"
101             "nstxout = %s\n"
102             "nstvout = 2\n"
103             "nstfout = 4\n"
104             "nstxout-compressed = 5\n"
105             "tcoupl = v-rescale\n"
106             "tc-grps = System\n"
107             "tau-t = 1\n"
108             "ref-t = 298\n"
109             "compressed-x-grps = Sol\n",
110             GetParam());
111     runTest();
112 }
113
114 //! Helper typedef for naming test cases like sentences
115 typedef TrajectoryWritingTest NptTrajectories;
116
117 /* This test ensures mdrun can write trajectories in TNG format from NPT ensembles. */
118 TEST_P(NptTrajectories, WithDifferentPcoupl)
119 {
120     theMdpFile = gmx::formatString(
121             "integrator = md\n"
122             "nsteps = 2\n"
123             "nstxout = 2\n"
124             "nstvout = 1\n"
125             "pcoupl = %s\n"
126             "tau-p = 1\n"
127             "ref-p = 1\n"
128             "compressibility = 4.5e-5\n"
129             "tcoupl = v-rescale\n"
130             "tc-grps = System\n"
131             "tau-t = 1\n"
132             "ref-t = 298\n",
133             GetParam());
134     runTest();
135 }
136
137 // TODO Consider spamming more of the parameter space when we don't
138 // have to write .mdp and .tpr files to do it.
139 INSTANTIATE_TEST_CASE_P(MdrunCanWrite, Trajectories, ::testing::Values("1", "2", "3"));
140
141 INSTANTIATE_TEST_CASE_P(MdrunCanWrite,
142                         NptTrajectories,
143                         ::testing::Values("no", "Berendsen", "Parrinello-Rahman"));
144
145 #endif
146
147 } // namespace