2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2019,2020, 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 density fitting module.
39 * \author Christian Blau <blau@kth.se>
40 * \ingroup module_applied_forces
44 #include "gromacs/applied_forces/densityfitting/densityfitting.h"
46 #include <gtest/gtest.h>
48 #include "gromacs/gmxlib/network.h"
49 #include "gromacs/math/paddedvector.h"
50 #include "gromacs/math/vec.h"
51 #include "gromacs/mdtypes/enerdata.h"
52 #include "gromacs/mdtypes/forceoutput.h"
53 #include "gromacs/mdtypes/iforceprovider.h"
54 #include "gromacs/mdtypes/imdmodule.h"
55 #include "gromacs/mdtypes/imdpoptionprovider.h"
56 #include "gromacs/mdtypes/mdatom.h"
57 #include "gromacs/options/options.h"
58 #include "gromacs/options/treesupport.h"
59 #include "gromacs/utility/keyvaluetreebuilder.h"
60 #include "gromacs/utility/keyvaluetreetransform.h"
61 #include "gromacs/utility/mdmodulenotification.h"
62 #include "gromacs/utility/real.h"
63 #include "gromacs/utility/smalloc.h"
64 #include "gromacs/utility/stringcompare.h"
66 #include "testutils/testasserts.h"
67 #include "testutils/testfilemanager.h"
68 #include "testutils/testmatchers.h"
76 class DensityFittingTest : public ::testing::Test
79 void addMdpOptionDensityFittingActive()
81 mdpValueBuilder_.rootObject().addValue("density-guided-simulation-active", std::string("yes"));
84 void addMdpOptionReferenceDensity()
86 mdpValueBuilder_.rootObject().addValue(
87 "density-guided-simulation-reference-density-filename",
88 std::string(test::TestFileManager::getInputFilePath("ellipsoid-density.mrc")));
91 //! build an mdp options tree that sets the options for the density fitting module
92 void makeDensityFittingModuleWithSetOptions()
94 KeyValueTreeObject mdpOptionsTree = mdpValueBuilder_.build();
96 densityFittingModule_ = DensityFittingModuleInfo::create();
99 Options densityFittingModuleOptions;
100 densityFittingModule_->mdpOptionProvider()->initMdpOptions(&densityFittingModuleOptions);
102 // Add rules to transform mdp inputs to densityFittingModule data
103 KeyValueTreeTransformer transform;
104 transform.rules()->addRule().keyMatchType("/", StringCompareType::CaseAndDashInsensitive);
105 densityFittingModule_->mdpOptionProvider()->initMdpTransform(transform.rules());
107 // Execute the transform on the mdpValues
108 auto transformedMdpValues = transform.transform(mdpOptionsTree, nullptr);
109 assignOptionsFromKeyValueTree(&densityFittingModuleOptions, transformedMdpValues.object(), nullptr);
112 void intializeForceProviders()
114 densityFittingModule_->initForceProviders(&densityFittingForces_);
118 KeyValueTreeBuilder mdpValueBuilder_;
119 ForceProviders densityFittingForces_;
120 std::unique_ptr<IMDModule> densityFittingModule_;
123 TEST_F(DensityFittingTest, ForceProviderLackingInputThrows)
125 // Prepare MDP inputs
126 addMdpOptionDensityFittingActive();
128 makeDensityFittingModuleWithSetOptions();
130 // Build the force provider, once all input data is gathered
131 EXPECT_ANY_THROW(intializeForceProviders());
134 TEST_F(DensityFittingTest, SingleAtom)
136 // Prepare MDP inputs
137 addMdpOptionDensityFittingActive();
138 addMdpOptionReferenceDensity();
140 makeDensityFittingModuleWithSetOptions();
142 EXPECT_ANY_THROW(intializeForceProviders());