2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 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.
37 * Implements force provider for density fitting
39 * \author Christian Blau <blau@kth.se>
40 * \ingroup module_applied_forces
44 #include "densityfittingoptions.h"
46 #include "gromacs/applied_forces/densityfitting.h"
47 #include "gromacs/options/basicoptions.h"
48 #include "gromacs/options/optionsection.h"
49 #include "gromacs/utility/keyvaluetreebuilder.h"
50 #include "gromacs/utility/keyvaluetreetransform.h"
51 #include "gromacs/utility/strconvert.h"
59 /*! \brief Helper to declare mdp transform rules.
61 * Enforces uniform mdp options that are always prepended with the correct
62 * string for the densityfitting mdp options.
64 * \tparam ToType type to be transformed to
65 * \tparam TransformWithFunctionType type of transformation function to be used
67 * \param[in] rules KVT transformation rules
68 * \param[in] transformationFunction the function to transform the flat kvt tree
69 * \param[in] optionTag string tag that describes the mdp option, appended to the
70 * default string for the density guided simulation
72 template <class ToType, class TransformWithFunctionType>
73 void densityfittingMdpTransformFromString(IKeyValueTreeTransformRules * rules,
74 TransformWithFunctionType transformationFunction,
75 const std::string &optionTag)
78 .from<std::string>("/" + DensityFittingModuleInfo::name_ + "-" + optionTag)
79 .to<ToType>("/" + DensityFittingModuleInfo::name_ +"/" + optionTag)
80 .transformWith(transformationFunction);
82 /*! \brief Helper to declare mdp output.
84 * Enforces uniform mdp options output sting that are always prepended with the
85 * correct string for the densityfitting mdp options and is consistent with the
86 * options name and transformation.
88 * \tparam OptionType the type of the mdp option
89 * \param[in] builder the KVT builder to generate the output
90 * \param[in] option the mdp option
91 * \param[in] optionTag string tag that describes the mdp option, appended to the
92 * default string for the density guided simulation
94 template <class OptionType>
95 void addDensityFittingMdpOutputValue(KeyValueTreeObjectBuilder *builder,
96 const OptionType &option,
97 const std::string &optionTag)
99 builder->addValue<OptionType>(DensityFittingModuleInfo::name_ + "-" + optionTag,
105 void DensityFittingOptions::initMdpTransform(IKeyValueTreeTransformRules * rules)
107 densityfittingMdpTransformFromString<bool>(rules, &fromStdString<bool>, c_activeTag_);
110 void DensityFittingOptions::buildMdpOutput(KeyValueTreeObjectBuilder *builder) const
112 addDensityFittingMdpOutputValue(builder, parameters_.active_, c_activeTag_);
115 void DensityFittingOptions::initMdpOptions(IOptionsContainerWithSections *options)
117 auto section = options->addSection(OptionSection(DensityFittingModuleInfo::name_.c_str()));
119 section.addOption(BooleanOption(c_activeTag_.c_str()).store(¶meters_.active_));
122 bool DensityFittingOptions::active() const
124 return parameters_.active_;
127 const DensityFittingParameters &DensityFittingOptions::buildParameters()