ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
bonded_interaction_data.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
20#pragma once
21
22/** @file
23 * Data structures for bonded interactions.
24 * For more information on how to add new interactions, see @ref bondedIA_new.
25 */
26
27#include "angle_common.hpp"
28#include "angle_cosine.hpp"
29#include "angle_cossquare.hpp"
30#include "angle_harmonic.hpp"
31#include "bonded_coulomb.hpp"
32#include "bonded_coulomb_sr.hpp"
33#include "bonded_tab.hpp"
34#include "dihedral.hpp"
35#include "fene.hpp"
36#include "harmonic.hpp"
42#include "quartic.hpp"
43#include "rigid_bond.hpp"
44#include "thermalized_bond.hpp"
45
47
48#include <boost/serialization/access.hpp>
49#include <boost/serialization/variant.hpp>
50#include <boost/variant.hpp>
51
52#include <algorithm>
53#include <cassert>
54#include <cmath>
55#include <stdexcept>
56#include <unordered_map>
57#include <vector>
58
59/* Special cutoff value for a disabled bond.
60 * Bonds that have this cutoff are not visited during bond evaluation.
61 */
62static constexpr double BONDED_INACTIVE_CUTOFF = -1.;
63
64/** Interaction type for unused bonded interaction slots */
65struct NoneBond {
66 static constexpr int num = 0;
67 double cutoff() const { return BONDED_INACTIVE_CUTOFF; }
68
69private:
70 friend boost::serialization::access;
71 template <typename Archive> void serialize(Archive &, long int) {}
72};
73
74/** Interaction type for virtual bonds */
76 static constexpr int num = 1;
77 double cutoff() const { return BONDED_INACTIVE_CUTOFF; }
78
79private:
80 friend boost::serialization::access;
81 template <typename Archive> void serialize(Archive &, long int) {}
82};
83
84/** Visitor to get the number of bound partners from the bond parameter
85 * variant.
86 */
87class BondNumPartners : public boost::static_visitor<int> {
88public:
89 template <typename T> int operator()(T const &) const { return T::num; }
90};
91
92/** Variant in which to store the parameters of an individual bonded
93 * interaction
94 */
102
104 using container_type =
105 std::unordered_map<int, std::shared_ptr<Bonded_IA_Parameters>>;
106
107public:
108 using key_type = typename container_type::key_type;
109 using mapped_type = typename container_type::mapped_type;
110 using value_type = typename container_type::value_type;
111 using iterator = typename container_type::iterator;
112 using const_iterator = typename container_type::const_iterator;
113
114 explicit BondedInteractionsMap() = default;
115
116 iterator begin() { return m_params.begin(); }
117 iterator end() { return m_params.end(); }
118 const_iterator begin() const { return m_params.begin(); }
119 const_iterator end() const { return m_params.end(); }
120
121 void insert(key_type const &key, mapped_type const &ptr) {
122 next_key = std::max(next_key, key + 1);
123 m_params[key] = ptr;
124 on_ia_change();
125 }
127 auto const key = next_key++;
128 m_params[key] = ptr;
129 on_ia_change();
130 return key;
131 }
132 auto erase(key_type const &key) {
133 auto &&obj = m_params.erase(key);
134 on_ia_change();
135 return obj;
136 }
137 mapped_type at(key_type const &key) const { return m_params.at(key); }
138 auto count(key_type const &key) const { return m_params.count(key); }
139 bool contains(key_type const &key) const { return m_params.count(key); }
140 bool empty() const { return m_params.empty(); }
141 auto size() const { return m_params.size(); }
142 auto get_next_key() const { return next_key; }
143 auto get_zero_based_type(int bond_id) const {
144 return contains(bond_id) ? at(bond_id)->which() : 0;
145 }
146 auto get_n_thermalized_bonds() const { return n_thermalized_bonds; }
147#ifdef BOND_CONSTRAINT
148 auto get_n_rigid_bonds() const { return n_rigid_bonds; }
149#endif
150
151private:
152 container_type m_params = {};
153 key_type next_key = static_cast<key_type>(0);
154 int n_thermalized_bonds = 0;
155#ifdef BOND_CONSTRAINT
156 int n_rigid_bonds = 0;
157#endif
158 void on_ia_change();
159};
160
161/** Field containing the parameters of the bonded ia types */
163
164/** Calculate the maximal cutoff of bonded interactions, required to
165 * determine the cell size for communication.
166 *
167 * Bond angle and dihedral potentials do not contain a cutoff intrinsically.
168 * The cutoff for these potentials depends on the bond length potentials
169 * (it is assumed that particles participating in a bond angle or dihedral
170 * potential are bound to each other by some bond length potential). For bond
171 * angle potentials nothing has to be done. For dihedral potentials the cutoff
172 * is set to twice the maximal cutoff because the particle in which the bond
173 * is stored is only bonded to the first two partners, one of which has an
174 * additional bond to the third partner.
175 */
176double maximal_cutoff_bonded();
177
178/** Return the number of bonded partners for the specified bond */
179inline int number_of_partners(Bonded_IA_Parameters const &iaparams) {
180 return boost::apply_visitor(BondNumPartners(), iaparams);
181}
Common code for functions calculating angle forces.
Routines to calculate the angle energy or/and and force for a particle triple using the potential des...
Routines to calculate the angle energy or/and and force for a particle triple using the potential des...
Routines to calculate the angle energy or/and and force for a particle triple using the potential des...
Routines to calculate the bonded Coulomb potential between particle pairs.
Routines to calculate the short-range part of the bonded Coulomb potential between particle pairs.
double maximal_cutoff_bonded()
Calculate the maximal cutoff of bonded interactions, required to determine the cell size for communic...
BondedInteractionsMap bonded_ia_params
Field containing the parameters of the bonded ia types.
static constexpr double BONDED_INACTIVE_CUTOFF
int number_of_partners(Bonded_IA_Parameters const &iaparams)
Return the number of bonded partners for the specified bond.
boost::variant< NoneBond, FeneBond, HarmonicBond, QuarticBond, BondedCoulomb, BondedCoulombSR, AngleHarmonicBond, AngleCosineBond, AngleCossquareBond, DihedralBond, TabulatedDistanceBond, TabulatedAngleBond, TabulatedDihedralBond, ThermalizedBond, RigidBond, IBMTriel, IBMVolCons, IBMTribend, OifGlobalForcesBond, OifLocalForcesBond, VirtualBond > Bonded_IA_Parameters
Variant in which to store the parameters of an individual bonded interaction.
Routines to calculate the energy and/or force for particle bonds, angles and dihedrals via interpolat...
Visitor to get the number of bound partners from the bond parameter variant.
int operator()(T const &) const
typename container_type::key_type key_type
auto count(key_type const &key) const
key_type insert(mapped_type const &ptr)
mapped_type at(key_type const &key) const
auto get_zero_based_type(int bond_id) const
bool contains(key_type const &key) const
void insert(key_type const &key, mapped_type const &ptr)
typename container_type::const_iterator const_iterator
BondedInteractionsMap()=default
typename container_type::mapped_type mapped_type
auto erase(key_type const &key)
typename container_type::iterator iterator
typename container_type::value_type value_type
Routines to calculate the dihedral energy or/and force for a particle quadruple.
Routines to calculate the FENE potential between particle pairs.
Routines to calculate the harmonic bond potential between particle pairs.
Routines to calculate the OIF local forces for a particle quadruple (two neighboring triangles with c...
Routines to calculate the quartic potential between particle pairs.
Definition of the rigid bond data type for the Rattle algorithm.
Parameters for three-body angular potential (cosine).
Parameters for three-body angular potential (cossquare).
Parameters for three-body angular potential (harmonic).
Parameters for Coulomb bond short-range Potential.
Parameters for Coulomb bond Potential.
Parameters for four-body angular potential (dihedral-angle potentials).
Definition dihedral.hpp:42
Parameters for FENE bond Potential.
Definition fene.hpp:39
Parameters for harmonic bond Potential.
Definition harmonic.hpp:37
Parameters for IBM tribend.
Parameters for IBM elastic triangle (triel)
Definition ibm_triel.hpp:34
Parameters for IBM volume conservation bond.
Interaction type for unused bonded interaction slots.
double cutoff() const
static constexpr int num
Parameters for OIF global forces.
Parameters for OIF local forces.
Parameters for quartic bond Potential.
Definition quartic.hpp:36
Parameters for the rigid_bond/SHAKE/RATTLE ALGORITHM.
Parameters for 3-body tabulated potential.
Parameters for 4-body tabulated potential.
Parameters for 2-body tabulated potential.
Parameters for Thermalized bond.
Interaction type for virtual bonds.
static constexpr int num
Routines to thermalize the center of mass and distance of a particle pair.