2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2017,2018,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 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();
73 setInputFile("-s", "dhdl.tpr");
74 setInputFile("-f", "dhdl.edr");
75 setOutputFile("-odh", "dhdl.xvg", XvgMatch());
77 ASSERT_EQ(0, gmx_energy(cmdline
.argc(), cmdline
.argv()));
83 TEST_F(DhdlTest
, ExtractDhdl
)
88 class OriresTest
: public CommandLineTestBase
91 void runTest(const char* stringForStdin
)
93 auto& cmdline
= commandLine();
95 setInputFile("-s", "orires.tpr");
96 setInputFile("-f", "orires.edr");
98 test::XvgMatch
& toler
= xvg
.tolerance(gmx::test::relativeToleranceAsFloatingPoint(1, 1e-4));
100 setOutputFile("-oten", ".xvg", toler
);
101 setOutputFile("-ora", ".xvg", toler
);
102 setOutputFile("-ort", ".xvg", toler
);
103 setOutputFile("-oda", ".xvg", toler
);
104 setOutputFile("-odr", ".xvg", toler
);
106 StdioTestHelper
stdioHelper(&fileManager());
107 stdioHelper
.redirectStringToStdin(stringForStdin
);
108 ASSERT_EQ(0, gmx_nmr(cmdline
.argc(), cmdline
.argv()));
114 TEST_F(OriresTest
, ExtractOrires
)
119 class EnergyTest
: public CommandLineTestBase
122 void runTest(const char* stringForStdin
)
124 auto& cmdline
= commandLine();
126 setInputFile("-f", "ener.edr");
127 setOutputFile("-o", "energy.xvg", XvgMatch());
129 StdioTestHelper
stdioHelper(&fileManager());
130 stdioHelper
.redirectStringToStdin(stringForStdin
);
131 ASSERT_EQ(0, gmx_energy(cmdline
.argc(), cmdline
.argv()));
133 // All the .edr files used in the tests contain only
134 // single-precision values, so even from a
135 // double-precision build they should conform to
136 // tolerances suitable for single-precision values.
137 setDefaultTolerance(defaultFloatTolerance());
142 TEST_F(EnergyTest
, ExtractEnergy
)
144 runTest("Potential\nKinetic-En.\nTotal-Energy\n");
147 TEST_F(EnergyTest
, ExtractEnergyByNumber
)
152 TEST_F(EnergyTest
, ExtractEnergyMixed
)
154 runTest("Pressu\n7\nbox-z\nvol\n");
157 class ViscosityTest
: public CommandLineTestBase
162 auto& cmdline
= commandLine();
163 setInputFile("-f", "ener.edr");
164 setOutputFile("-vis", "visco.xvg", NoTextMatch());
165 setOutputFile("-o", "energy.xvg", NoTextMatch());
167 /* -vis can write a lot of non-conditional output files,
168 so we use temporary paths to clean up files that are
169 not the ones being tested in this test */
170 if (!cmdline
.contains("-evisco"))
172 setOutputFile("-evisco", "evisco.xvg", NoTextMatch());
174 if (!cmdline
.contains("-eviscoi"))
176 setOutputFile("-eviscoi", "eviscoi.xvg", NoTextMatch());
178 if (!cmdline
.contains("-corr"))
180 setOutputFile("-corr", "corr.xvg", NoTextMatch());
183 ASSERT_EQ(0, gmx_energy(cmdline
.argc(), cmdline
.argv()));
189 TEST_F(ViscosityTest
, EinsteinViscosity
)
191 auto tolerance
= relativeToleranceAsFloatingPoint(1e-4, 1e-5);
192 setOutputFile("-evisco", "evisco.xvg", XvgMatch().tolerance(tolerance
));
196 TEST_F(ViscosityTest
, EinsteinViscosityIntegral
)
198 auto tolerance
= relativeToleranceAsFloatingPoint(1e-4, 1e-5);
199 setOutputFile("-eviscoi", "eviscoi.xvg", XvgMatch().tolerance(tolerance
));