ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
|
Base class for reaction ensemble methods. More...
#include <ReactionAlgorithm.hpp>
Classes | |
struct | ParticleChanges |
Public Member Functions | |
ReactionAlgorithm (boost::mpi::communicator const &comm, int seed, double kT, double exclusion_range, std::unordered_map< int, double > const &exclusion_radius_per_type) | |
virtual | ~ReactionAlgorithm ()=default |
double | get_acceptance_rate_configurational_moves () const |
auto | get_kT () const |
auto | get_exclusion_range () const |
auto | get_volume () const |
void | set_volume (double new_volume) |
void | update_volume () |
Automatically sets the volume which is used by the reaction ensemble to the volume of a cuboid box. | |
void | set_exclusion_radius_per_type (std::unordered_map< int, double > const &map) |
void | remove_constraint () |
void | set_cyl_constraint (double center_x, double center_y, double radius) |
void | set_slab_constraint (double slab_start_z, double slab_end_z) |
Utils::Vector2d | get_slab_constraint_parameters () const |
void | setup_bookkeeping_of_empty_pids () |
Cleans the list of empty pids and searches for empty pid in the system. | |
void | delete_particle (int p_id) |
Deletes the particle with the given p_id and stores the id if the deletion created a hole in the particle id range. | |
void | add_reaction (std::shared_ptr< SingleReaction > const &new_reaction) |
Adds a reaction to the reaction system. | |
void | delete_reaction (int reaction_id) |
bool | is_reaction_under_way () const |
auto const & | get_old_system_state () const |
std::optional< double > | create_new_trial_state (int reaction_id) |
Carry out a reaction MC move and calculate the new potential energy. | |
double | make_reaction_mc_move_attempt (int reaction_id, double bf, double E_pot_old, double E_pot_new) |
Accept or reject a reaction MC move made by create_new_trial_state based on a probability acceptance bf . | |
bool | make_displacement_mc_move_attempt (int type, int n_particles) |
Attempt displacement MC moves for particles of a given type. | |
double | calculate_potential_energy () const |
Compute the system potential energy. | |
int | i_random (int maxint) |
draws a random integer from the uniform distribution in the range [0,maxint-1] | |
Public Attributes | |
std::vector< std::shared_ptr< SingleReaction > > | reactions |
std::unordered_map< int, double > | charges_of_types |
double | kT |
double | exclusion_range |
Hard sphere radius. | |
std::unordered_map< int, double > | exclusion_radius_per_type |
double | volume |
int | non_interacting_type = 100 |
int | m_accepted_configurational_MC_moves = 0 |
int | m_tried_configurational_MC_moves = 0 |
bool | particle_inside_exclusion_range_touched = false |
bool | neighbor_search_order_n = true |
Protected Member Functions | |
void | restore_old_system_state () |
Restore last valid system state. | |
void | clear_old_system_state () |
Clear last valid system state. | |
auto & | make_new_system_state () |
Open new handle for system state tracking. | |
void | displacement_mc_move (int type, int n_particles) |
Carry out displacement MC moves for particles of a given type. | |
void | make_reaction_attempt (::ReactionMethods::SingleReaction const &reaction, ParticleChanges &bookkeeping) |
Carry out a chemical reaction and save the old system state. | |
bool | all_reactant_particles_exist (SingleReaction const ¤t_reaction) const |
Checks whether all particles exist for the provided reaction. | |
Utils::Vector3d | get_random_position_in_box () |
Writes a random position inside the central box into the provided array. | |
Protected Attributes | |
std::vector< int > | m_empty_p_ids_smaller_than_max_seen_particle |
std::shared_ptr< ParticleChanges > | m_system_changes |
Base class for reaction ensemble methods.
Definition at line 48 of file core/reaction_methods/ReactionAlgorithm.hpp.
|
inline |
Definition at line 53 of file core/reaction_methods/ReactionAlgorithm.hpp.
|
virtualdefault |
void ReactionMethods::ReactionAlgorithm::add_reaction | ( | std::shared_ptr< SingleReaction > const & | new_reaction | ) |
Adds a reaction to the reaction system.
Definition at line 65 of file core/reaction_methods/ReactionAlgorithm.cpp.
References init_type_map(), non_interacting_type, and reactions.
|
protected |
Checks whether all particles exist for the provided reaction.
Definition at line 137 of file core/reaction_methods/ReactionAlgorithm.cpp.
References number_of_particles_with_type(), ReactionMethods::SingleReaction::reactant_coefficients, and ReactionMethods::SingleReaction::reactant_types.
Referenced by ReactionMethods::WidomInsertion::calculate_particle_insertion_potential_energy(), and create_new_trial_state().
double ReactionMethods::ReactionAlgorithm::calculate_potential_energy | ( | ) | const |
Compute the system potential energy.
Definition at line 626 of file core/reaction_methods/ReactionAlgorithm.cpp.
References System::get_system().
Referenced by ReactionMethods::WidomInsertion::calculate_particle_insertion_potential_energy(), create_new_trial_state(), and make_displacement_mc_move_attempt().
|
inlineprotected |
Clear last valid system state.
Definition at line 166 of file core/reaction_methods/ReactionAlgorithm.hpp.
References is_reaction_under_way(), and m_system_changes.
Referenced by make_displacement_mc_move_attempt(), make_reaction_mc_move_attempt(), and restore_old_system_state().
std::optional< double > ReactionMethods::ReactionAlgorithm::create_new_trial_state | ( | int | reaction_id | ) |
Carry out a reaction MC move and calculate the new potential energy.
Particles are selected without replacement. The previous state of the system is cached.
Definition at line 253 of file core/reaction_methods/ReactionAlgorithm.cpp.
References all_reactant_particles_exist(), calculate_potential_energy(), make_new_system_state(), make_reaction_attempt(), particle_inside_exclusion_range_touched, and reactions.
void ReactionMethods::ReactionAlgorithm::delete_particle | ( | int | p_id | ) |
Deletes the particle with the given p_id and stores the id if the deletion created a hole in the particle id range.
This method is intended to only delete unbonded particles since bonds are coupled to ids. This is used to avoid the id range becoming excessively huge.
Definition at line 398 of file core/reaction_methods/ReactionAlgorithm.cpp.
References get_maximal_particle_id(), m_empty_p_ids_smaller_than_max_seen_particle, and remove_particle().
Referenced by make_reaction_mc_move_attempt(), and restore_old_system_state().
|
inline |
Definition at line 134 of file core/reaction_methods/ReactionAlgorithm.hpp.
References reactions.
|
protected |
Carry out displacement MC moves for particles of a given type.
Particles are selected without replacement.
type | Type of particles to move. |
n_particles | Number of particles of that type to move. |
Definition at line 516 of file core/reaction_methods/ReactionAlgorithm.cpp.
References Utils::contains(), get_random_p_id(), get_random_position_in_box(), i_random(), kT, make_new_system_state(), ReactionMethods::ReactionAlgorithm::ParticleChanges::moved, number_of_particles_with_type(), particle_inside_exclusion_range_touched, and set_particle_pos().
Referenced by make_displacement_mc_move_attempt().
|
inline |
Definition at line 88 of file core/reaction_methods/ReactionAlgorithm.hpp.
References m_accepted_configurational_MC_moves, and m_tried_configurational_MC_moves.
|
inline |
Definition at line 94 of file core/reaction_methods/ReactionAlgorithm.hpp.
References exclusion_range.
|
inline |
Definition at line 93 of file core/reaction_methods/ReactionAlgorithm.hpp.
References kT.
|
inline |
Definition at line 155 of file core/reaction_methods/ReactionAlgorithm.hpp.
References is_reaction_under_way(), and m_system_changes.
Referenced by make_reaction_mc_move_attempt(), and restore_old_system_state().
|
protected |
Writes a random position inside the central box into the provided array.
Definition at line 457 of file core/reaction_methods/ReactionAlgorithm.cpp.
References System::System::box_geo, and System::get_system().
Referenced by displacement_mc_move().
|
inline |
Definition at line 124 of file core/reaction_methods/ReactionAlgorithm.hpp.
|
inline |
Definition at line 95 of file core/reaction_methods/ReactionAlgorithm.hpp.
References volume.
|
inline |
draws a random integer from the uniform distribution in the range [0,maxint-1]
maxint | range. |
Definition at line 228 of file core/reaction_methods/ReactionAlgorithm.hpp.
Referenced by displacement_mc_move(), and make_reaction_attempt().
|
inline |
Definition at line 154 of file core/reaction_methods/ReactionAlgorithm.hpp.
References m_system_changes.
Referenced by clear_old_system_state(), get_old_system_state(), and make_new_system_state().
bool ReactionMethods::ReactionAlgorithm::make_displacement_mc_move_attempt | ( | int | type, |
int | n_particles | ||
) |
Attempt displacement MC moves for particles of a given type.
Particles are selected without replacement.
type | Type of particles to move. |
n_particles | Number of particles of that type to move. |
Definition at line 552 of file core/reaction_methods/ReactionAlgorithm.cpp.
References calculate_potential_energy(), clear_old_system_state(), displacement_mc_move(), kT, m_accepted_configurational_MC_moves, m_tried_configurational_MC_moves, number_of_particles_with_type(), particle_inside_exclusion_range_touched, and restore_old_system_state().
|
inlineprotected |
Open new handle for system state tracking.
Definition at line 171 of file core/reaction_methods/ReactionAlgorithm.hpp.
References is_reaction_under_way(), and m_system_changes.
Referenced by ReactionMethods::WidomInsertion::calculate_particle_insertion_potential_energy(), create_new_trial_state(), and displacement_mc_move().
|
protected |
Carry out a chemical reaction and save the old system state.
Definition at line 151 of file core/reaction_methods/ReactionAlgorithm.cpp.
References ReactionMethods::ReactionAlgorithm::ParticleChanges::changed, charges_of_types, ReactionMethods::ReactionAlgorithm::ParticleChanges::created, get_random_p_id(), System::get_system(), ReactionMethods::ReactionAlgorithm::ParticleChanges::hidden, i_random(), number_of_particles_with_type(), System::System::on_particle_change(), System::System::on_particle_local_change(), on_particle_type_change(), ReactionMethods::SingleReaction::product_coefficients, ReactionMethods::SingleReaction::product_types, ReactionMethods::SingleReaction::reactant_coefficients, and ReactionMethods::SingleReaction::reactant_types.
Referenced by ReactionMethods::WidomInsertion::calculate_particle_insertion_potential_energy(), and create_new_trial_state().
double ReactionMethods::ReactionAlgorithm::make_reaction_mc_move_attempt | ( | int | reaction_id, |
double | bf, | ||
double | E_pot_old, | ||
double | E_pot_new | ||
) |
Accept or reject a reaction MC move made by create_new_trial_state based on a probability acceptance bf
.
The previous state of the system is either restored from the cache if the move is rejected, or cleared from the cache if the move is accepted.
Definition at line 273 of file core/reaction_methods/ReactionAlgorithm.cpp.
References clear_old_system_state(), delete_particle(), get_old_system_state(), kT, reactions, and restore_old_system_state().
|
inline |
Definition at line 121 of file core/reaction_methods/ReactionAlgorithm.hpp.
|
protected |
Restore last valid system state.
This method tries to keep the cell system overhead to a minimum. Event callbacks are only called once after all particles are updated, except for particle deletion (the cell structure is still reinitialized after each deletion).
Definition at line 85 of file core/reaction_methods/ReactionAlgorithm.cpp.
References type_tracking::any_type, charges_of_types, clear_old_system_state(), delete_particle(), get_old_system_state(), System::get_system(), on_particle_type_change(), and Cells::RESORT_GLOBAL.
Referenced by ReactionMethods::WidomInsertion::calculate_particle_insertion_potential_energy(), make_displacement_mc_move_attempt(), and make_reaction_mc_move_attempt().
void ReactionMethods::ReactionAlgorithm::set_cyl_constraint | ( | double | center_x, |
double | center_y, | ||
double | radius | ||
) |
Definition at line 425 of file core/reaction_methods/ReactionAlgorithm.cpp.
References System::System::box_geo, and System::get_system().
|
inline |
Definition at line 104 of file core/reaction_methods/ReactionAlgorithm.hpp.
References exclusion_radius_per_type, and exclusion_range.
void ReactionMethods::ReactionAlgorithm::set_slab_constraint | ( | double | slab_start_z, |
double | slab_end_z | ||
) |
Definition at line 440 of file core/reaction_methods/ReactionAlgorithm.cpp.
References System::System::box_geo, and System::get_system().
|
inline |
Definition at line 96 of file core/reaction_methods/ReactionAlgorithm.hpp.
References volume.
void ReactionMethods::ReactionAlgorithm::setup_bookkeeping_of_empty_pids | ( | ) |
Cleans the list of empty pids and searches for empty pid in the system.
Definition at line 611 of file core/reaction_methods/ReactionAlgorithm.cpp.
References get_particle_ids_parallel(), and m_empty_p_ids_smaller_than_max_seen_particle.
Referenced by ReactionMethods::WidomInsertion::calculate_particle_insertion_potential_energy().
void ReactionMethods::ReactionAlgorithm::update_volume | ( | ) |
Automatically sets the volume which is used by the reaction ensemble to the volume of a cuboid box.
Definition at line 129 of file core/reaction_methods/ReactionAlgorithm.cpp.
References System::System::box_geo, System::get_system(), and volume.
std::unordered_map<int, double> ReactionMethods::ReactionAlgorithm::charges_of_types |
Definition at line 73 of file core/reaction_methods/ReactionAlgorithm.hpp.
Referenced by make_reaction_attempt(), and restore_old_system_state().
std::unordered_map<int, double> ReactionMethods::ReactionAlgorithm::exclusion_radius_per_type |
Definition at line 82 of file core/reaction_methods/ReactionAlgorithm.hpp.
Referenced by set_exclusion_radius_per_type().
double ReactionMethods::ReactionAlgorithm::exclusion_range |
Hard sphere radius.
If particles are closer than this value, it is assumed that their interaction energy gets approximately infinite, therefore these configurations do not contribute to the partition function and ensemble averages.
Definition at line 81 of file core/reaction_methods/ReactionAlgorithm.hpp.
Referenced by get_exclusion_range(), and set_exclusion_radius_per_type().
double ReactionMethods::ReactionAlgorithm::kT |
Definition at line 74 of file core/reaction_methods/ReactionAlgorithm.hpp.
Referenced by displacement_mc_move(), get_kT(), make_displacement_mc_move_attempt(), and make_reaction_mc_move_attempt().
int ReactionMethods::ReactionAlgorithm::m_accepted_configurational_MC_moves = 0 |
Definition at line 86 of file core/reaction_methods/ReactionAlgorithm.hpp.
Referenced by get_acceptance_rate_configurational_moves(), and make_displacement_mc_move_attempt().
|
protected |
Definition at line 142 of file core/reaction_methods/ReactionAlgorithm.hpp.
Referenced by delete_particle(), and setup_bookkeeping_of_empty_pids().
|
protected |
Definition at line 176 of file core/reaction_methods/ReactionAlgorithm.hpp.
Referenced by clear_old_system_state(), get_old_system_state(), is_reaction_under_way(), and make_new_system_state().
int ReactionMethods::ReactionAlgorithm::m_tried_configurational_MC_moves = 0 |
Definition at line 87 of file core/reaction_methods/ReactionAlgorithm.hpp.
Referenced by get_acceptance_rate_configurational_moves(), and make_displacement_mc_move_attempt().
bool ReactionMethods::ReactionAlgorithm::neighbor_search_order_n = true |
Definition at line 139 of file core/reaction_methods/ReactionAlgorithm.hpp.
int ReactionMethods::ReactionAlgorithm::non_interacting_type = 100 |
Definition at line 84 of file core/reaction_methods/ReactionAlgorithm.hpp.
Referenced by add_reaction().
bool ReactionMethods::ReactionAlgorithm::particle_inside_exclusion_range_touched = false |
Definition at line 138 of file core/reaction_methods/ReactionAlgorithm.hpp.
Referenced by create_new_trial_state(), displacement_mc_move(), and make_displacement_mc_move_attempt().
std::vector<std::shared_ptr<SingleReaction> > ReactionMethods::ReactionAlgorithm::reactions |
Definition at line 72 of file core/reaction_methods/ReactionAlgorithm.hpp.
Referenced by add_reaction(), ReactionMethods::WidomInsertion::calculate_particle_insertion_potential_energy(), create_new_trial_state(), delete_reaction(), and make_reaction_mc_move_attempt().
double ReactionMethods::ReactionAlgorithm::volume |
Definition at line 83 of file core/reaction_methods/ReactionAlgorithm.hpp.
Referenced by get_volume(), set_volume(), and update_volume().