2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 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 * Tests for functionality of the QMMM module.
39 * \author Dmitry Morozov <dmitry.morozov@jyu.fi>
40 * \author Christian Blau <blau@kth.se>
41 * \ingroup module_applied_forces
45 #include "gromacs/applied_forces/qmmm/qmmm.h"
47 #include <gtest/gtest.h>
49 #include "gromacs/gmxlib/network.h"
50 #include "gromacs/math/paddedvector.h"
51 #include "gromacs/math/vec.h"
52 #include "gromacs/mdtypes/enerdata.h"
53 #include "gromacs/mdtypes/forceoutput.h"
54 #include "gromacs/mdtypes/iforceprovider.h"
55 #include "gromacs/mdtypes/imdmodule.h"
56 #include "gromacs/mdtypes/imdpoptionprovider.h"
57 #include "gromacs/mdtypes/mdatom.h"
58 #include "gromacs/options/options.h"
59 #include "gromacs/options/treesupport.h"
60 #include "gromacs/utility/keyvaluetreebuilder.h"
61 #include "gromacs/utility/keyvaluetreetransform.h"
62 #include "gromacs/utility/mdmodulesnotifiers.h"
63 #include "gromacs/utility/real.h"
64 #include "gromacs/utility/smalloc.h"
65 #include "gromacs/utility/stringcompare.h"
67 #include "testutils/testasserts.h"
68 #include "testutils/testfilemanager.h"
69 #include "testutils/testmatchers.h"
77 class QMMMTest : public ::testing::Test
80 void addMdpOptionQMMMActive()
82 mdpValueBuilder_.rootObject().addValue("qmmm-cp2k-active", std::string("yes"));
85 //! build an mdp options tree that sets the options for the qmmm module
86 void makeQMMMModuleWithSetOptions()
88 KeyValueTreeObject mdpOptionsTree = mdpValueBuilder_.build();
90 QMMMModule_ = QMMMModuleInfo::create();
93 Options QMMMModuleOptions;
94 QMMMModule_->mdpOptionProvider()->initMdpOptions(&QMMMModuleOptions);
96 // Add rules to transform mdp inputs to QMMMModule data
97 KeyValueTreeTransformer transform;
98 transform.rules()->addRule().keyMatchType("/", StringCompareType::CaseAndDashInsensitive);
99 QMMMModule_->mdpOptionProvider()->initMdpTransform(transform.rules());
101 // Execute the transform on the mdpValues
102 auto transformedMdpValues = transform.transform(mdpOptionsTree, nullptr);
103 assignOptionsFromKeyValueTree(&QMMMModuleOptions, transformedMdpValues.object(), nullptr);
106 void intializeForceProviders() { QMMMModule_->initForceProviders(&QMMMForces_); }
109 KeyValueTreeBuilder mdpValueBuilder_;
110 ForceProviders QMMMForces_;
111 std::unique_ptr<IMDModule> QMMMModule_;
114 TEST_F(QMMMTest, ForceProviderLackingInputThrows)
116 // Prepare MDP inputs
117 addMdpOptionQMMMActive();
119 // Initialize with default options
120 makeQMMMModuleWithSetOptions();
122 // Build the force provider, once all input data is gathered
123 EXPECT_ANY_THROW(intializeForceProviders());