Moved generic simulationdatabase code to testutils.
[gromacs.git] / src / programs / mdrun / tests / mimic.cpp
blob98adef1b21bfdba3e277d5ecb58b5e08836c56b2
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 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.
36 /*! \internal \file
37 * \brief
38 * Tests for MiMiC forces computation
40 * \author Viacheslav Bolnykh <v.bolnykh@hpc-leap.eu>
41 * \ingroup module_mdrun_integration_tests
43 #include "gmxpre.h"
45 #include <gtest/gtest.h>
47 #include "gromacs/topology/ifunc.h"
48 #include "gromacs/trajectory/energyframe.h"
49 #include "gromacs/utility/basenetwork.h"
50 #include "gromacs/utility/stringutil.h"
52 #include "testutils/cmdlinetest.h"
53 #include "testutils/refdata.h"
54 #include "testutils/simulationdatabase.h"
56 #include "energycomparison.h"
57 #include "energyreader.h"
58 #include "moduletest.h"
60 namespace gmx
62 namespace test
65 //! Test fixture for bonded interactions
66 class MimicTest : public gmx::test::MdrunTestFixture
68 public:
69 //! Execute the trajectory writing test
70 void setupGrompp(const char *index_file, const char *top_file, const char *gro_file)
72 runner_.topFileName_ = TestFileManager::getInputFilePath(top_file);
73 runner_.groFileName_ = TestFileManager::getInputFilePath(gro_file);
74 runner_.ndxFileName_ = TestFileManager::getInputFilePath(index_file);
75 runner_.useStringAsMdpFile("integrator = mimic\n"
76 "QMMM-grps = QMatoms");
78 //! Prepare an mdrun caller
79 CommandLine setupMdrun()
81 CommandLine rerunCaller;
82 rerunCaller.append("mdrun");
83 rerunCaller.addOption("-rerun", runner_.groFileName_);
84 runner_.edrFileName_ = fileManager_.getTemporaryFilePath(".edr");
85 return rerunCaller;
87 //! Check the output of mdrun
88 void checkMdrun()
90 EnergyTolerances energiesToMatch
93 interaction_function[F_EPOT].longname, relativeToleranceAsFloatingPoint(-20.1, 1e-4)
95 }};
97 TestReferenceData refData;
98 auto checker = refData.rootChecker();
99 checkEnergiesAgainstReferenceData(runner_.edrFileName_,
100 energiesToMatch,
101 &checker);
105 // This test checks if the energies produced with one quantum molecule are reasonable
106 TEST_F(MimicTest, OneQuantumMol)
108 setupGrompp("1quantum.ndx", "4water.top", "4water.gro");
109 if (gmx_node_rank() == 0)
111 EXPECT_EQ(0, runner_.callGromppOnThisRank());
114 test::CommandLine rerunCaller = setupMdrun();
116 int dummy = 0;
117 if (gmx_mpi_initialized())
119 gmx_broadcast_world(sizeof(int), &dummy);
121 ASSERT_EQ(0, runner_.callMdrun(rerunCaller));
122 if (gmx_node_rank() == 0)
124 checkMdrun();
126 // Stupid way of synchronizining ranks but simplest API does not allow us to have any other
127 if (gmx_mpi_initialized())
129 gmx_broadcast_world(sizeof(int), &dummy);
133 // This test checks if the energies produced with all quantum molecules are reasonable (0)
134 TEST_F(MimicTest, AllQuantumMol)
136 setupGrompp("allquantum.ndx", "4water.top", "4water.gro");
137 if (gmx_node_rank() == 0)
139 EXPECT_EQ(0, runner_.callGromppOnThisRank());
142 test::CommandLine rerunCaller = setupMdrun();
143 int dummy = 0;
144 if (gmx_mpi_initialized())
146 gmx_broadcast_world(sizeof(int), &dummy);
148 ASSERT_EQ(0, runner_.callMdrun(rerunCaller));
149 if (gmx_node_rank() == 0)
151 checkMdrun();
153 if (gmx_mpi_initialized())
155 gmx_broadcast_world(sizeof(int), &dummy);
159 // This test checks if the energies produced with two quantum molecules are reasonable
160 // Needed to check the LJ intermolecular exclusions
161 TEST_F(MimicTest, TwoQuantumMol)
163 setupGrompp("2quantum.ndx", "4water.top", "4water.gro");
164 if (gmx_node_rank() == 0)
166 EXPECT_EQ(0, runner_.callGromppOnThisRank());
169 test::CommandLine rerunCaller = setupMdrun();
170 int dummy = 0;
171 if (gmx_mpi_initialized())
173 gmx_broadcast_world(sizeof(int), &dummy);
175 ASSERT_EQ(0, runner_.callMdrun(rerunCaller));
176 if (gmx_node_rank() == 0)
178 checkMdrun();
180 if (gmx_mpi_initialized())
182 gmx_broadcast_world(sizeof(int), &dummy);
186 // This test checks if the energies produced with QM/MM boundary cutting the bond are ok
187 TEST_F(MimicTest, BondCuts)
189 setupGrompp("ala.ndx", "ala.top", "ala.gro");
190 if (gmx_node_rank() == 0)
192 EXPECT_EQ(0, runner_.callGromppOnThisRank());
195 test::CommandLine rerunCaller = setupMdrun();
196 int dummy = 0;
197 if (gmx_mpi_initialized())
199 gmx_broadcast_world(sizeof(int), &dummy);
201 ASSERT_EQ(0, runner_.callMdrun(rerunCaller));
202 if (gmx_node_rank() == 0)
204 checkMdrun();
206 if (gmx_mpi_initialized())
208 gmx_broadcast_world(sizeof(int), &dummy);
212 } // namespace test
214 } // namespace gmx