ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
nonbonded_interaction_data.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24/** \file
25 * Various procedures concerning interactions between particles.
26 */
27
28#include <config/config.hpp>
29
31#include "system/Leaf.hpp"
32
33#include <utils/index.hpp>
35
36#include <algorithm>
37#include <cassert>
38#include <cmath>
39#include <memory>
40#include <vector>
41
42/** Lennard-Jones with shift */
44 double eps = 0.0;
45 double sig = 0.0;
47 double shift = 0.0;
48 double offset = 0.0;
49 double min = 0.0;
50 LJ_Parameters() = default;
51 LJ_Parameters(double epsilon, double sigma, double cutoff, double offset,
52 double min, double shift);
53 double get_auto_shift() const {
54 auto auto_shift = 0.;
55 if (cut != 0.) {
56 auto_shift = Utils::int_pow<6>(sig / cut) - Utils::int_pow<12>(sig / cut);
57 }
58 return auto_shift;
59 }
60 double max_cutoff() const { return cut + offset; }
61 double min_cutoff() const { return min + offset; }
62};
63
64/** WCA potential */
66 double eps = 0.0;
67 double sig = 0.0;
69 WCA_Parameters() = default;
70 WCA_Parameters(double epsilon, double sigma);
71 double max_cutoff() const { return cut; }
72};
73
74/** Generic Lennard-Jones with shift */
76 double eps = 0.0;
77 double sig = 0.0;
79 double shift = 0.0;
80 double offset = 0.0;
81 double lambda = 1.0;
82 double softrad = 0.0;
83 double a1 = 0.0;
84 double a2 = 0.0;
85 double b1 = 0.0;
86 double b2 = 0.0;
87 LJGen_Parameters() = default;
88 LJGen_Parameters(double epsilon, double sigma, double cutoff, double shift,
89 double offset,
90#ifdef ESPRESSO_LJGEN_SOFTCORE
91 double lam, double delta,
92#endif
93 double e1, double e2, double b1, double b2);
94 double get_auto_shift() const {
95 auto auto_shift = 0.;
96 if (cut != 0.) {
97 auto_shift = b2 * std::pow(sig / cut, a2) - b1 * std::pow(sig / cut, a1);
98 }
99 return auto_shift;
100 }
101 double max_cutoff() const { return cut + offset; }
102};
103
104/** smooth step potential */
106 double eps = 0.0;
107 double sig = 0.0;
109 double d = 0.0;
110 int n = 0;
111 double k0 = 0.0;
113 SmoothStep_Parameters(double eps, double sig, double cutoff, double d, int n,
114 double k0);
115 double max_cutoff() const { return cut; }
116};
117
118/** Hertzian potential */
120 double eps = 0.0;
123 Hertzian_Parameters(double eps, double sig);
124 double max_cutoff() const { return sig; }
125};
126
127/** Gaussian potential */
129 double eps = 0.0;
130 double sig = 1.0;
133 Gaussian_Parameters(double eps, double sig, double cutoff);
134 double max_cutoff() const { return cut; }
135};
136
137/** BMHTF NaCl potential */
139 double A = 0.0;
140 double B = 0.0;
141 double C = 0.0;
142 double D = 0.0;
143 double sig = 0.0;
145 double computed_shift = 0.0;
146 BMHTF_Parameters() = default;
147 BMHTF_Parameters(double A, double B, double C, double D, double sig,
148 double cut);
149 double max_cutoff() const { return cut; }
150};
151
152/** Morse potential */
154 double eps = 0.;
159 Morse_Parameters() = default;
160 Morse_Parameters(double eps, double alpha, double rmin, double cutoff);
161 double max_cutoff() const { return cut; }
162};
163
164/** Buckingham potential */
166 double A = 0.0;
167 double B = 0.0;
168 double C = 0.0;
169 double D = 0.0;
171 double discont = 0.0;
172 double shift = 0.0;
173 double F1 = 0.0;
174 double F2 = 0.0;
176 Buckingham_Parameters(double a, double b, double c, double d, double cutoff,
177 double discont, double shift);
178 double max_cutoff() const { return cut; }
179};
180
181/** soft-sphere potential */
183 double a = 0.0;
184 double n = 0.0;
186 double offset = 0.0;
188 SoftSphere_Parameters(double a, double n, double cutoff, double offset);
189 double max_cutoff() const { return cut + offset; }
190};
191
192/** hat potential */
194 double Fmax = 0.0;
196 Hat_Parameters() = default;
197 Hat_Parameters(double F_max, double cutoff);
198 double max_cutoff() const { return r; }
199};
200
201/** Lennard-Jones+Cos potential */
203 double eps = 0.0;
204 double sig = 0.0;
206 double offset = 0.0;
207 double alfa = 0.0;
208 double beta = 0.0;
209 double rmin = 0.0;
210 LJcos_Parameters() = default;
211 LJcos_Parameters(double epsilon, double sigma, double cutoff, double offset);
212 double max_cutoff() const { return cut + offset; }
213};
214
215/** Lennard-Jones with a different Cos potential */
217 double eps = 0.0;
218 double sig = 0.0;
220 double offset = 0.0;
221 double w = 0.0;
222 double rchange = 0.0;
223 LJcos2_Parameters() = default;
224 LJcos2_Parameters(double epsilon, double sigma, double offset, double width);
225 double max_cutoff() const { return cut + offset; }
226};
227
228/** Gay-Berne potential */
230 double eps = 0.0;
231 double sig = 0.0;
233 double k1 = 0.0;
234 double k2 = 0.0;
235 double mu = 0.0;
236 double nu = 0.0;
237 double chi1 = 0.0;
238 double chi2 = 0.0;
240 GayBerne_Parameters(double eps, double sig, double cut, double k1, double k2,
241 double mu, double nu);
242 double max_cutoff() const { return cut; }
243};
244
245/** Thole potential */
247 double scaling_coeff = 0.; // inactive cutoff is 0
248 double q1q2 = 0.;
249 Thole_Parameters() = default;
252};
253
254/** DPD potential */
256 double gamma = 0.;
257 double k = 1.;
259 int wf = 0;
260 double pref = 0.0;
261};
262
266 DPD_Parameters() = default;
267 DPD_Parameters(double gamma, double k, double r_c, int wf, double tgamma,
268 double tr_c, int twf) {
269 radial = DPDParameters{gamma, k, r_c, wf, -1.};
270 trans = DPDParameters{tgamma, k, tr_c, twf, -1.};
271 }
272 double max_cutoff() const { return std::max(radial.cutoff, trans.cutoff); }
273};
274
275/** @brief Parameters for non-bonded interactions. */
277 /** maximal cutoff for this pair of particle types. This contains
278 * contributions from the short-ranged interactions, plus any
279 * cutoffs from global interactions like electrostatics.
280 */
282
283#ifdef ESPRESSO_LENNARD_JONES
285#endif
286
287#ifdef ESPRESSO_WCA
289#endif
290
291#ifdef ESPRESSO_LENNARD_JONES_GENERIC
293#endif
294
295#ifdef ESPRESSO_SMOOTH_STEP
297#endif
298
299#ifdef ESPRESSO_HERTZIAN
301#endif
302
303#ifdef ESPRESSO_GAUSSIAN
305#endif
306
307#ifdef ESPRESSO_BMHTF_NACL
309#endif
310
311#ifdef ESPRESSO_MORSE
313#endif
314
315#ifdef ESPRESSO_BUCKINGHAM
317#endif
318
319#ifdef ESPRESSO_SOFT_SPHERE
321#endif
322
323#ifdef ESPRESSO_HAT
325#endif
326
327#ifdef ESPRESSO_LJCOS
329#endif
330
331#ifdef ESPRESSO_LJCOS2
333#endif
334
335#ifdef ESPRESSO_GAY_BERNE
337#endif
338
339#ifdef ESPRESSO_TABULATED
341#endif
342
343#ifdef ESPRESSO_DPD
345#endif
346
347#ifdef ESPRESSO_THOLE
349#endif
350};
351
352class InteractionsNonBonded : public System::Leaf<InteractionsNonBonded> {
353 /** @brief List of pairwise interactions. */
354 std::vector<std::shared_ptr<IA_parameters>> m_nonbonded_ia_params{};
355 /** @brief Maximal particle type seen so far. */
356 int max_seen_particle_type = -1;
357
358 void realloc_ia_params(int type) {
359 assert(type >= 0);
360 auto const old_size = m_nonbonded_ia_params.size();
361 m_nonbonded_ia_params.resize(Utils::lower_triangular(type, type) + 1);
362 auto const new_size = m_nonbonded_ia_params.size();
363 if (new_size > old_size) {
364 for (auto &data : m_nonbonded_ia_params) {
365 if (data == nullptr) {
366 data = std::make_shared<IA_parameters>();
367 }
368 }
369 }
370 }
371
372public:
374 /* make sure interaction 0<->0 always exists */
376 }
377
378 /**
379 * @brief Make sure the interaction parameter list is large enough to cover
380 * interactions for this particle type.
381 * New interactions are initialized with values such that no physical
382 * interaction occurs.
383 */
385 assert(type >= 0);
386 if (type > max_seen_particle_type) {
387 realloc_ia_params(type);
388 max_seen_particle_type = type;
389 }
390 }
391
392 auto get_ia_param_key(int i, int j) const {
393 assert(i >= 0 and i <= max_seen_particle_type);
394 assert(j >= 0 and j <= max_seen_particle_type);
395 auto const key = static_cast<unsigned int>(
396 Utils::lower_triangular(std::max(i, j), std::min(i, j)));
397 assert(key < m_nonbonded_ia_params.size());
398 return key;
399 }
400
401 /**
402 * @brief Get interaction parameters between particle types i and j
403 *
404 * This is symmetric, e.g. it holds that `get_ia_param(i, j)` and
405 * `get_ia_param(j, i)` point to the same data.
406 *
407 * @param i First type, must exist
408 * @param j Second type, must exist
409 *
410 * @return Reference to interaction parameters for the type pair.
411 */
412 auto &get_ia_param(int i, int j) {
413 return *m_nonbonded_ia_params[get_ia_param_key(i, j)];
414 }
415
416 auto const &get_ia_param(int i, int j) const {
417 return *m_nonbonded_ia_params[get_ia_param_key(i, j)];
418 }
419
420 auto get_ia_param_ref_counted(int i, int j) const {
421 return m_nonbonded_ia_params[get_ia_param_key(i, j)];
422 }
423
424 void set_ia_param(int i, int j, std::shared_ptr<IA_parameters> const &ia) {
425 m_nonbonded_ia_params[get_ia_param_key(i, j)] = ia;
426 }
427
428 auto get_max_seen_particle_type() const { return max_seen_particle_type; }
429
430 /** @brief Recalculate cutoff of each interaction struct. */
432
433 /** @brief Get maximal cutoff. */
434 double maximal_cutoff() const;
435
436 /** @brief Notify system that non-bonded interactions changed. */
437 void on_non_bonded_ia_change() const;
438};
auto get_ia_param_ref_counted(int i, int j) const
auto get_ia_param_key(int i, int j) const
void set_ia_param(int i, int j, std::shared_ptr< IA_parameters > const &ia)
auto const & get_ia_param(int i, int j) const
void recalc_maximal_cutoffs()
Recalculate cutoff of each interaction struct.
void on_non_bonded_ia_change() const
Notify system that non-bonded interactions changed.
double maximal_cutoff() const
Get maximal cutoff.
auto & get_ia_param(int i, int j)
Get interaction parameters between particle types i and j.
void make_particle_type_exist(int type)
Make sure the interaction parameter list is large enough to cover interactions for this particle type...
Abstract class that represents a component of the system.
constexpr double inactive_cutoff
Special cutoff value for an inactive interaction.
Definition config.hpp:44
T lower_triangular(T i, T j)
Linear index into a lower triangular matrix.
Definition index.hpp:83
BMHTF_Parameters()=default
Buckingham_Parameters()=default
DPD_Parameters()=default
DPD_Parameters(double gamma, double k, double r_c, int wf, double tgamma, double tr_c, int twf)
Gaussian_Parameters()=default
GayBerne_Parameters()=default
Hat_Parameters()=default
Hertzian_Parameters()=default
Parameters for non-bonded interactions.
Gaussian_Parameters gaussian
double max_cut
maximal cutoff for this pair of particle types.
GayBerne_Parameters gay_berne
SoftSphere_Parameters soft_sphere
SmoothStep_Parameters smooth_step
Hertzian_Parameters hertzian
Buckingham_Parameters buckingham
Generic Lennard-Jones with shift.
LJGen_Parameters()=default
Lennard-Jones with shift.
LJ_Parameters()=default
Lennard-Jones with a different Cos potential.
LJcos2_Parameters()=default
Lennard-Jones+Cos potential.
LJcos_Parameters()=default
Morse_Parameters()=default
SmoothStep_Parameters()=default
SoftSphere_Parameters()=default
Evaluate forces and energies using a custom potential profile.
Thole_Parameters()=default
Thole_Parameters(double scaling_coeff, double q1q2)
WCA_Parameters()=default