ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ReactionMethods::ReactionAlgorithm Class Reference

Base class for reaction ensemble methods. More...

#include <ReactionAlgorithm.hpp>

+ Inheritance diagram for ReactionMethods::ReactionAlgorithm:
+ Collaboration diagram for ReactionMethods::ReactionAlgorithm:

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 &current_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< ParticleChangesm_system_changes
 

Detailed Description

Base class for reaction ensemble methods.

Definition at line 48 of file core/reaction_methods/ReactionAlgorithm.hpp.

Constructor & Destructor Documentation

◆ ReactionAlgorithm()

ReactionMethods::ReactionAlgorithm::ReactionAlgorithm ( boost::mpi::communicator const &  comm,
int  seed,
double  kT,
double  exclusion_range,
std::unordered_map< int, double > const &  exclusion_radius_per_type 
)
inline

Definition at line 53 of file core/reaction_methods/ReactionAlgorithm.hpp.

◆ ~ReactionAlgorithm()

virtual ReactionMethods::ReactionAlgorithm::~ReactionAlgorithm ( )
virtualdefault

Member Function Documentation

◆ add_reaction()

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.

◆ all_reactant_particles_exist()

bool ReactionMethods::ReactionAlgorithm::all_reactant_particles_exist ( SingleReaction const &  current_reaction) const
protected

◆ calculate_potential_energy()

double ReactionMethods::ReactionAlgorithm::calculate_potential_energy ( ) const

◆ clear_old_system_state()

void ReactionMethods::ReactionAlgorithm::clear_old_system_state ( )
inlineprotected

◆ create_new_trial_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.

Returns
Potential energy of the system after the move.

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.

◆ delete_particle()

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().

◆ delete_reaction()

void ReactionMethods::ReactionAlgorithm::delete_reaction ( int  reaction_id)
inline

Definition at line 134 of file core/reaction_methods/ReactionAlgorithm.hpp.

References reactions.

◆ displacement_mc_move()

void ReactionMethods::ReactionAlgorithm::displacement_mc_move ( int  type,
int  n_particles 
)
protected

Carry out displacement MC moves for particles of a given type.

Particles are selected without replacement.

Parameters
typeType of particles to move.
n_particlesNumber 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().

◆ get_acceptance_rate_configurational_moves()

double ReactionMethods::ReactionAlgorithm::get_acceptance_rate_configurational_moves ( ) const
inline

◆ get_exclusion_range()

auto ReactionMethods::ReactionAlgorithm::get_exclusion_range ( ) const
inline

Definition at line 94 of file core/reaction_methods/ReactionAlgorithm.hpp.

References exclusion_range.

◆ get_kT()

auto ReactionMethods::ReactionAlgorithm::get_kT ( ) const
inline

Definition at line 93 of file core/reaction_methods/ReactionAlgorithm.hpp.

References kT.

◆ get_old_system_state()

auto const & ReactionMethods::ReactionAlgorithm::get_old_system_state ( ) const
inline

◆ get_random_position_in_box()

Utils::Vector3d ReactionMethods::ReactionAlgorithm::get_random_position_in_box ( )
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().

◆ get_slab_constraint_parameters()

Utils::Vector2d ReactionMethods::ReactionAlgorithm::get_slab_constraint_parameters ( ) const
inline

Definition at line 124 of file core/reaction_methods/ReactionAlgorithm.hpp.

◆ get_volume()

auto ReactionMethods::ReactionAlgorithm::get_volume ( ) const
inline

Definition at line 95 of file core/reaction_methods/ReactionAlgorithm.hpp.

References volume.

◆ i_random()

int ReactionMethods::ReactionAlgorithm::i_random ( int  maxint)
inline

draws a random integer from the uniform distribution in the range [0,maxint-1]

Parameters
maxintrange.

Definition at line 228 of file core/reaction_methods/ReactionAlgorithm.hpp.

Referenced by displacement_mc_move(), and make_reaction_attempt().

◆ is_reaction_under_way()

bool ReactionMethods::ReactionAlgorithm::is_reaction_under_way ( ) const
inline

◆ make_displacement_mc_move_attempt()

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.

Parameters
typeType of particles to move.
n_particlesNumber of particles of that type to move.
Returns
true if all moves were accepted.

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().

◆ make_new_system_state()

auto & ReactionMethods::ReactionAlgorithm::make_new_system_state ( )
inlineprotected

◆ make_reaction_attempt()

◆ make_reaction_mc_move_attempt()

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.

Returns
Potential energy of the system after the move was accepted or rejected.

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().

◆ remove_constraint()

void ReactionMethods::ReactionAlgorithm::remove_constraint ( )
inline

Definition at line 121 of file core/reaction_methods/ReactionAlgorithm.hpp.

◆ restore_old_system_state()

void ReactionMethods::ReactionAlgorithm::restore_old_system_state ( )
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().

◆ set_cyl_constraint()

void ReactionMethods::ReactionAlgorithm::set_cyl_constraint ( double  center_x,
double  center_y,
double  radius 
)

◆ set_exclusion_radius_per_type()

void ReactionMethods::ReactionAlgorithm::set_exclusion_radius_per_type ( std::unordered_map< int, double > const &  map)
inline

◆ set_slab_constraint()

void ReactionMethods::ReactionAlgorithm::set_slab_constraint ( double  slab_start_z,
double  slab_end_z 
)

◆ set_volume()

void ReactionMethods::ReactionAlgorithm::set_volume ( double  new_volume)
inline

Definition at line 96 of file core/reaction_methods/ReactionAlgorithm.hpp.

References volume.

◆ setup_bookkeeping_of_empty_pids()

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().

◆ update_volume()

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.

Member Data Documentation

◆ charges_of_types

std::unordered_map<int, double> ReactionMethods::ReactionAlgorithm::charges_of_types

◆ exclusion_radius_per_type

std::unordered_map<int, double> ReactionMethods::ReactionAlgorithm::exclusion_radius_per_type

◆ exclusion_range

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().

◆ kT

double ReactionMethods::ReactionAlgorithm::kT

◆ m_accepted_configurational_MC_moves

int ReactionMethods::ReactionAlgorithm::m_accepted_configurational_MC_moves = 0

◆ m_empty_p_ids_smaller_than_max_seen_particle

std::vector<int> ReactionMethods::ReactionAlgorithm::m_empty_p_ids_smaller_than_max_seen_particle
protected

◆ m_system_changes

std::shared_ptr<ParticleChanges> ReactionMethods::ReactionAlgorithm::m_system_changes
protected

◆ m_tried_configurational_MC_moves

int ReactionMethods::ReactionAlgorithm::m_tried_configurational_MC_moves = 0

◆ neighbor_search_order_n

bool ReactionMethods::ReactionAlgorithm::neighbor_search_order_n = true

Definition at line 139 of file core/reaction_methods/ReactionAlgorithm.hpp.

◆ non_interacting_type

int ReactionMethods::ReactionAlgorithm::non_interacting_type = 100

Definition at line 84 of file core/reaction_methods/ReactionAlgorithm.hpp.

Referenced by add_reaction().

◆ particle_inside_exclusion_range_touched

bool ReactionMethods::ReactionAlgorithm::particle_inside_exclusion_range_touched = false

◆ reactions

◆ volume

double ReactionMethods::ReactionAlgorithm::volume

The documentation for this class was generated from the following files: