38#include <boost/serialization/serialization.hpp>
44#include <unordered_map>
54 std::vector<Variant>
out;
65 if (
key ==
"order_n") {
66 RE()->neighbor_search_order_n =
true;
67 }
else if (
key ==
"parallel") {
68 RE()->neighbor_search_order_n =
false;
70 throw std::invalid_argument(
"Unknown search algorithm '" +
key +
76 if (
RE()->neighbor_search_order_n) {
77 return std::string(
"order_n");
79 return std::string(
"parallel");
81 {
"particle_inside_exclusion_range_touched",
85 [
this]() {
return RE()->particle_inside_exclusion_range_touched; }},
91 [
this]() {
return RE()->get_exclusion_range(); }},
92 {
"exclusion_radius_per_type",
95 RE()->set_exclusion_radius_per_type(
96 get_value<std::unordered_map<int, double>>(v));
101 RE()->exclusion_radius_per_type);
107 if (
name ==
"calculate_factorial_expression") {
108 if (
context()->is_head_node()) {
110 auto &old_particle_numbers =
bookkeeping.old_particle_numbers;
116 if (
name ==
"get_random_reaction_index") {
117 return RE()->i_random(
static_cast<int>(
RE()->reactions.size()));
119 if (
name ==
"potential_energy") {
120 return RE()->calculate_potential_energy();
122 if (
name ==
"create_new_trial_state") {
126 auto const optional =
RE()->create_new_trial_state(reaction_id);
133 if (
name ==
"make_reaction_mc_move_attempt") {
140 result =
RE()->make_reaction_mc_move_attempt(reaction_id,
bf,
E_pot_old,
145 if (
name ==
"setup_bookkeeping_of_empty_pids") {
146 RE()->setup_bookkeeping_of_empty_pids();
147 }
else if (
name ==
"remove_constraint") {
148 RE()->remove_constraint();
149 }
else if (
name ==
"set_cylindrical_constraint_in_z_direction") {
155 }
else if (
name ==
"set_wall_constraints_in_z_direction") {
160 }
else if (
name ==
"get_wall_constraints_in_z_direction") {
162 return RE()->get_slab_constraint_parameters();
165 }
else if (
name ==
"set_volume") {
168 }
else if (
name ==
"get_volume") {
169 return RE()->get_volume();
170 }
else if (
name ==
"get_acceptance_rate_reaction") {
174 throw std::out_of_range(
"No reaction with id " + std::to_string(index));
177 return m_reactions[index]->get_reaction()->get_acceptance_rate();
178 }
else if (
name ==
"set_non_interacting_type") {
182 throw std::domain_error(
"Invalid type: " + std::to_string(type));
185 RE()->non_interacting_type = type;
187 }
else if (
name ==
"get_non_interacting_type") {
188 return RE()->non_interacting_type;
189 }
else if (
name ==
"displacement_mc_move_for_particles_of_type") {
191 auto const n_particles =
195 result =
RE()->make_displacement_mc_move_attempt(type, n_particles);
198 }
else if (
name ==
"delete_particle") {
201 }
else if (
name ==
"delete_reaction") {
205 delete_reaction(index + 1);
206 delete_reaction(index + 0);
207 }
else if (
name ==
"add_reaction") {
212 }
else if (
name ==
"change_reaction_constant") {
216 if (reaction_id % 2 == 1) {
217 throw std::invalid_argument(
"Only forward reactions can be selected");
220 throw std::domain_error(
"gamma needs to be a strictly positive value");
224 m_reactions[index + 0]->get_reaction()->gamma = gamma;
225 m_reactions[index + 1]->get_reaction()->gamma = 1. / gamma;
226 }
else if (
name ==
"set_charge_of_type") {
229 RE()->charges_of_types[type] = charge;
230 }
else if (
context()->is_head_node()) {
231 throw std::runtime_error(
"unknown method '" +
name +
"()'");
void add_parameters(std::vector< AutoParameter > &¶ms)
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
virtual bool is_head_node() const =0
boost::string_ref name() const
Context * context() const
Responsible context.
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
virtual double calculate_factorial_expression(::ReactionMethods::SingleReaction const &reaction, std::unordered_map< int, int > const &particle_numbers) const
virtual std::shared_ptr<::ReactionMethods::ReactionAlgorithm > RE()=0
int get_reaction_index(int reaction_id) const
Check reaction id is within the reaction container bounds.
std::vector< std::shared_ptr< SingleReaction > > m_reactions
Keep track of the script interface pointer of each reaction.
This file contains the defaults for ESPResSo.
This file contains the asynchronous MPI communication.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
auto make_unordered_map_of_variants(std::unordered_map< K, V > const &v)
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.
void init_type_map(int type)
Particles creation and deletion.
static SteepestDescentParameters params
Currently active steepest descent instance.
static constexpr const ReadOnly read_only