ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
core/reaction_methods/WidomInsertion.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-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#ifndef REACTION_METHODS_WIDOM_INSERTION_HPP
20#define REACTION_METHODS_WIDOM_INSERTION_HPP
21
22#include "ReactionAlgorithm.hpp"
23
24#include <unordered_map>
25#include <utility>
26
27namespace ReactionMethods {
28
29/** Widom insertion method */
31public:
33 boost::mpi::communicator const &comm, int seed, double kT,
34 double exclusion_range,
35 const std::unordered_map<int, double> &exclusion_radius_per_type)
38
40 auto &reaction = *reactions[reaction_id];
41 if (not all_reactant_particles_exist(reaction)) {
42 throw std::runtime_error("Trying to remove some non-existing particles "
43 "from the system via the inverse Widom scheme.");
44 }
45
46 // make reaction attempt and immediately reverse it
48 auto const E_pot_old = calculate_potential_energy();
50 auto const E_pot_new = calculate_potential_energy();
52
53 return E_pot_new - E_pot_old;
54 }
55};
56
57} // namespace ReactionMethods
58#endif
double calculate_potential_energy() const
Compute the system potential energy.
void make_reaction_attempt(::ReactionMethods::SingleReaction const &reaction, ParticleChanges &bookkeeping)
Carry out a chemical reaction and save the old system state.
void setup_bookkeeping_of_empty_pids()
Cleans the list of empty pids and searches for empty pid in the system.
void restore_old_system_state()
Restore last valid system state.
bool all_reactant_particles_exist(SingleReaction const &current_reaction) const
Checks whether all particles exist for the provided reaction.
auto & make_new_system_state()
Open new handle for system state tracking.
std::vector< std::shared_ptr< SingleReaction > > reactions
WidomInsertion(boost::mpi::communicator const &comm, int seed, double kT, double exclusion_range, const std::unordered_map< int, double > &exclusion_radius_per_type)