Update instructions in containers.rst
[gromacs.git] / src / programs / mdrun / tests / mimic.cpp
blob244a98a25fda8d971c963ded4751d292630e1351
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 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.
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(
76 "integrator = mimic\n"
77 "QMMM-grps = QMatoms");
79 //! Prepare an mdrun caller
80 CommandLine setupRerun()
82 CommandLine rerunCaller;
83 rerunCaller.append("mdrun");
84 rerunCaller.addOption("-rerun", runner_.groFileName_);
85 runner_.edrFileName_ = fileManager_.getTemporaryFilePath(".edr");
86 return rerunCaller;
88 //! Check the output of mdrun
89 void checkRerun()
91 EnergyTermsToCompare energyTermsToCompare{ {
92 { interaction_function[F_EPOT].longname, relativeToleranceAsFloatingPoint(-20.1, 1e-4) },
93 } };
95 TestReferenceData refData;
96 auto checker = refData.rootChecker();
97 checkEnergiesAgainstReferenceData(runner_.edrFileName_, energyTermsToCompare, &checker);
101 // This test checks if the energies produced with one quantum molecule are reasonable
102 TEST_F(MimicTest, OneQuantumMol)
104 setupGrompp("1quantum.ndx", "4water.top", "4water.gro");
105 ASSERT_EQ(0, runner_.callGrompp());
107 test::CommandLine rerunCaller = setupRerun();
109 ASSERT_EQ(0, runner_.callMdrun(rerunCaller));
110 if (gmx_node_rank() == 0)
112 checkRerun();
116 // This test checks if the energies produced with all quantum molecules are reasonable (0)
117 TEST_F(MimicTest, AllQuantumMol)
119 setupGrompp("allquantum.ndx", "4water.top", "4water.gro");
120 ASSERT_EQ(0, runner_.callGrompp());
122 test::CommandLine rerunCaller = setupRerun();
123 ASSERT_EQ(0, runner_.callMdrun(rerunCaller));
124 if (gmx_node_rank() == 0)
126 checkRerun();
130 // This test checks if the energies produced with two quantum molecules are reasonable
131 // Needed to check the LJ intermolecular exclusions
132 TEST_F(MimicTest, TwoQuantumMol)
134 setupGrompp("2quantum.ndx", "4water.top", "4water.gro");
135 ASSERT_EQ(0, runner_.callGrompp());
137 test::CommandLine rerunCaller = setupRerun();
138 ASSERT_EQ(0, runner_.callMdrun(rerunCaller));
139 if (gmx_node_rank() == 0)
141 checkRerun();
145 // This test checks if the energies produced with QM/MM boundary cutting the bond are ok
146 TEST_F(MimicTest, BondCuts)
148 setupGrompp("ala.ndx", "ala.top", "ala.gro");
149 ASSERT_EQ(0, runner_.callGrompp());
151 test::CommandLine rerunCaller = setupRerun();
152 ASSERT_EQ(0, runner_.callMdrun(rerunCaller));
153 if (gmx_node_rank() == 0)
155 checkRerun();
159 } // namespace test
161 } // namespace gmx