2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2018,2020,2021, 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 #include "testingconfiguration.h"
38 #include "gmxapi/context.h"
39 #include "gmxapi/session.h"
40 #include "gmxapi/status.h"
41 #include "gmxapi/system.h"
43 #include "gromacs/mdlib/sighandler.h"
44 #include "gromacs/mdtypes/iforceprovider.h"
56 * \brief Check that we can run a basic simulation from a simple client.
58 TEST_F(GmxApiTest, RunnerBasicMD)
61 auto system = gmxapi::fromTprFile(runner_.tprFileName_);
64 auto context = std::make_shared<gmxapi::Context>(gmxapi::createContext());
65 gmxapi::MDArgs args = makeMdArgs();
66 // TODO the command line arguments should be set through the
67 // usual command line options settings for the tests
69 context->setMDArgs(args);
70 auto session = system.launch(context);
71 EXPECT_TRUE(session != nullptr);
72 gmxapi::Status status;
73 ASSERT_NO_THROW(status = session->run());
74 EXPECT_TRUE(status.success());
75 status = session->close();
76 EXPECT_TRUE(status.success());
81 * \brief Test our ability to reinitialize the libgromacs environment between simulations.
83 TEST_F(GmxApiTest, RunnerReinitialize)
85 auto context = std::make_shared<gmxapi::Context>(gmxapi::createContext());
86 gmxapi::MDArgs args = makeMdArgs();
91 context->setMDArgs(args);
92 auto system = gmxapi::fromTprFile(runner_.tprFileName_);
93 auto session = system.launch(context);
95 // Try to simulate an interrupt signal to catch.
96 gmx_set_stop_condition(StopCondition::NextNS);
98 auto status = session->run();
99 EXPECT_FALSE(status.success());
101 // If this assertion fails, it is not an error, but it indicates expected behavior has
102 // changed and we need to consider the impact of whatever changes caused this.
103 EXPECT_NE(gmx_get_stop_condition(), StopCondition::None);
106 } // allow system and session to be destroyed.
109 context->setMDArgs(args);
110 auto system = gmxapi::fromTprFile(runner_.tprFileName_);
112 // If this assertion fails, it is not an error, but it indicates expected behavior has
113 // changed and we need to consider the impact of whatever changes caused this.
114 // We are expecting that the libgromacs state has retained the stop condition from the
115 // previously issued SIGINT
116 EXPECT_NE(gmx_get_stop_condition(), StopCondition::None);
118 auto session = system.launch(context);
120 // Launching a session should clear the stop condition.
121 EXPECT_EQ(gmx_get_stop_condition(), StopCondition::None);
123 auto status = session->run();
124 EXPECT_TRUE(status.success());
126 // Stop condition should still be clear.
127 EXPECT_EQ(gmx_get_stop_condition(), StopCondition::None);
134 * \brief Test simulation continuation.
136 * Run a simulation, then extend the target number of steps and continue the simulation.
138 TEST_F(GmxApiTest, RunnerContinuedMD)
140 // Run a simulation, then extend the target number of steps and continue the simulation
142 auto system = gmxapi::fromTprFile(runner_.tprFileName_);
145 auto context = std::make_shared<gmxapi::Context>(gmxapi::createContext());
148 EXPECT_TRUE(context != nullptr);
149 gmxapi::MDArgs args = makeMdArgs();
151 context->setMDArgs(args);
152 auto session = system.launch(context);
153 EXPECT_TRUE(session != nullptr);
154 gmxapi::Status status;
155 ASSERT_NO_THROW(status = session->run());
156 EXPECT_TRUE(status.success());
157 ASSERT_NO_THROW(status = session->close());
158 EXPECT_TRUE(status.success());
161 // Reuse the context. Add MD parameters. Run a new session extending the previous trajectory.
163 gmxapi::MDArgs args = makeMdArgs();
164 // TODO This needs to be changed to make a new tpr with convert-tpr instead.
165 args.emplace_back("-nsteps");
166 args.emplace_back("20");
168 context->setMDArgs(args);
169 auto session = system.launch(context);
170 EXPECT_TRUE(session != nullptr);
171 gmxapi::Status status;
172 ASSERT_NO_THROW(status = session->run());
173 EXPECT_TRUE(status.success());
174 ASSERT_NO_THROW(status = session->close());
175 EXPECT_TRUE(status.success());
180 } // end anonymous namespace
182 } // end namespace testing
184 } // end namespace gmxapi