ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/reaction_methods/WidomInsertion.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_WIDOM_INSERTION_HPP
21#define SCRIPT_INTERFACE_REACTION_METHODS_WIDOM_INSERTION_HPP
22
23#include "ReactionAlgorithm.hpp"
24
26
29
30#include <memory>
31#include <stdexcept>
32#include <string>
33
34namespace ScriptInterface {
35namespace ReactionMethods {
36
38public:
39 std::shared_ptr<::ReactionMethods::ReactionAlgorithm> RE() override {
40 return m_re;
41 }
42 std::shared_ptr<::ReactionMethods::ReactionAlgorithm> const
43 RE() const override {
44 return m_re;
45 }
46
48 add_parameters({{"search_algorithm",
49 [this](Variant const &) {
50 if (context()->is_head_node()) {
51 throw std::runtime_error(
52 "No search algorithm for WidomInsertion");
53 }
54 },
55 []() { return none; }}});
56 }
57
58 void do_construct(VariantMap const &params) override {
60 m_re = std::make_shared<::ReactionMethods::WidomInsertion>(
61 context()->get_comm(), get_value<int>(params, "seed"),
62 get_value<double>(params, "kT"), 0.,
63 std::unordered_map<int, double>{});
64 });
65 }
66
67 Variant do_call_method(std::string const &name,
68 VariantMap const &params) override {
69 if (name == "calculate_particle_insertion_potential_energy") {
70 Variant result;
72 auto const reaction_id = get_value<int>(params, "reaction_id");
73 auto const index = get_reaction_index(reaction_id);
74 result = m_re->calculate_particle_insertion_potential_energy(index);
75 });
76 return result;
77 }
79 }
80
81private:
82 std::shared_ptr<::ReactionMethods::WidomInsertion> m_re;
83};
84
85} /* namespace ReactionMethods */
86} /* namespace ScriptInterface */
87
88#endif
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 &params) override
int get_reaction_index(int reaction_id) const
Check reaction id is within the reaction container bounds.
std::shared_ptr<::ReactionMethods::ReactionAlgorithm > const RE() const override
std::shared_ptr<::ReactionMethods::ReactionAlgorithm > RE() override
Variant do_call_method(std::string const &name, VariantMap const &params) 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:69
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:67
constexpr const None none
None-"literal".
Definition Variant.hpp:50
static SteepestDescentParameters params
Currently active steepest descent instance.