2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2017,2018, 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 gmx energy
39 * \todo These will be superseded by tests of the energyanalysis
42 * \author Mark Abraham <mark.j.abraham@gmail.com>
51 #include "gromacs/gmxana/gmx_ana.h"
53 #include "testutils/cmdlinetest.h"
54 #include "testutils/stdiohelper.h"
55 #include "testutils/testasserts.h"
56 #include "testutils/textblockmatchers.h"
57 #include "testutils/xvgtest.h"
66 class DhdlTest : public CommandLineTestBase
71 auto &cmdline = commandLine();
72 cmdline.append("energy");
74 setInputFile("-s", "dhdl.tpr");
75 setInputFile("-f", "dhdl.edr");
76 setOutputFile("-odh", "dhdl.xvg", XvgMatch());
78 ASSERT_EQ(0, gmx_energy(cmdline.argc(), cmdline.argv()));
84 TEST_F(DhdlTest, ExtractDhdl)
89 class OriresTest : public CommandLineTestBase
92 void runTest(const char *stringForStdin)
94 auto &cmdline = commandLine();
95 cmdline.append("energy");
97 setInputFile("-s", "orires.tpr");
98 setInputFile("-f", "orires.edr");
100 test::XvgMatch &toler = xvg.tolerance(gmx::test::relativeToleranceAsFloatingPoint(1, 1e-4));
102 setOutputFile("-oten", ".xvg", toler);
103 setOutputFile("-ora", ".xvg", toler);
104 setOutputFile("-ort", ".xvg", toler);
105 setOutputFile("-oda", ".xvg", toler);
106 setOutputFile("-odr", ".xvg", toler);
108 StdioTestHelper stdioHelper(&fileManager());
109 stdioHelper.redirectStringToStdin(stringForStdin);
110 ASSERT_EQ(0, gmx_nmr(cmdline.argc(), cmdline.argv()));
116 TEST_F(OriresTest, ExtractOrires)
121 class EnergyTest : public CommandLineTestBase
124 void runTest(const char *stringForStdin)
126 auto &cmdline = commandLine();
127 cmdline.append("energy");
129 setInputFile("-f", "ener.edr");
130 setOutputFile("-o", "energy.xvg", XvgMatch());
132 StdioTestHelper stdioHelper(&fileManager());
133 stdioHelper.redirectStringToStdin(stringForStdin);
134 ASSERT_EQ(0, gmx_energy(cmdline.argc(), cmdline.argv()));
136 // All the .edr files used in the tests contain only
137 // single-precision values, so even from a
138 // double-precision build they should conform to
139 // tolerances suitable for single-precision values.
140 setDefaultTolerance(defaultFloatTolerance());
145 TEST_F(EnergyTest, ExtractEnergy)
147 runTest("Potential\nKinetic-En.\nTotal-Energy\n");
150 TEST_F(EnergyTest, ExtractEnergyByNumber)
155 TEST_F(EnergyTest, ExtractEnergyMixed)
157 runTest("Pressu\n7\nbox-z\nvol\n");
160 class ViscosityTest : public CommandLineTestBase
165 auto &cmdline = commandLine();
166 setInputFile("-f", "ener.edr");
167 setOutputFile("-vis", "visco.xvg", NoTextMatch());
168 setOutputFile("-o", "energy.xvg", NoTextMatch());
170 /* -vis can write a lot of non-conditional output files,
171 so we use temporary paths to clean up files that are
172 not the ones being tested in this test */
173 if (!cmdline.contains("-evisco"))
175 setOutputFile("-evisco", "evisco.xvg", NoTextMatch());
177 if (!cmdline.contains("-eviscoi"))
179 setOutputFile("-eviscoi", "eviscoi.xvg", NoTextMatch());
181 if (!cmdline.contains("-corr"))
183 setOutputFile("-corr", "corr.xvg", NoTextMatch());
186 ASSERT_EQ(0, gmx_energy(cmdline.argc(), cmdline.argv()));
192 TEST_F(ViscosityTest, EinsteinViscosity)
194 auto tolerance = relativeToleranceAsFloatingPoint(1e-4, 1e-5);
195 setOutputFile("-evisco", "evisco.xvg", XvgMatch().tolerance(tolerance));
199 TEST_F(ViscosityTest, EinsteinViscosityIntegral)
201 auto tolerance = relativeToleranceAsFloatingPoint(1e-4, 1e-5);
202 setOutputFile("-eviscoi", "eviscoi.xvg", XvgMatch().tolerance(tolerance));