ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/reaction_methods/SingleReaction.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef SCRIPT_INTERFACE_REACTION_METHODS_SINGLE_REACTION_HPP
21#define SCRIPT_INTERFACE_REACTION_METHODS_SINGLE_REACTION_HPP
22
24
26
27#include <memory>
28#include <string>
29#include <vector>
30
31namespace ScriptInterface {
32namespace ReactionMethods {
33
34class SingleReaction : public AutoParameters<SingleReaction> {
35public:
38 {"nu_bar", AutoParameter::read_only, [this]() { return m_sr->nu_bar; }},
39 {"gamma", AutoParameter::read_only, [this]() { return m_sr->gamma; }},
40 {"reactant_types", AutoParameter::read_only,
41 [this]() { return m_sr->reactant_types; }},
42 {"reactant_coefficients", AutoParameter::read_only,
43 [this]() { return m_sr->reactant_coefficients; }},
44 {"product_types", AutoParameter::read_only,
45 [this]() { return m_sr->product_types; }},
46 {"product_coefficients", AutoParameter::read_only,
47 [this]() { return m_sr->product_coefficients; }},
48 });
49 }
50
51 void do_construct(VariantMap const &params) override {
53 m_sr = std::make_shared<::ReactionMethods::SingleReaction>(
54 get_value<double>(params, "gamma"),
55 get_value<std::vector<int>>(params, "reactant_types"),
56 get_value<std::vector<int>>(params, "reactant_coefficients"),
57 get_value<std::vector<int>>(params, "product_types"),
58 get_value<std::vector<int>>(params, "product_coefficients"));
59 });
60 }
61
62 std::shared_ptr<::ReactionMethods::SingleReaction> get_reaction() {
63 return m_sr;
64 }
65
66 Variant do_call_method(std::string const &name, VariantMap const &) override {
67 if (name == "get_acceptance_rate") {
68 return m_sr->get_acceptance_rate();
69 }
70 return {};
71 }
72
73private:
74 std::shared_ptr<::ReactionMethods::SingleReaction> m_sr;
75};
76
77} /* namespace ReactionMethods */
78} /* namespace ScriptInterface */
79
80#endif
Bind parameters in the script interface.
void add_parameters(std::vector< AutoParameter > &&params)
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
boost::string_ref name() const
Context * context() const
Responsible context.
Variant do_call_method(std::string const &name, VariantMap const &) override
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:82
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
Definition Variant.hpp:80
static SteepestDescentParameters params
Currently active steepest descent instance.
static constexpr const ReadOnly read_only