Coverage for gamdpy/interactions/potential_functions/apply_shifted_potential_cutoff.py: 100%
7 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1import numpy as np
2import numba
3import math
4from numba import cuda
6def apply_shifted_potential_cutoff(pair_potential: callable) -> callable:
7 """ Apply shifted potential cutoff to a pair-potential function
9 If the input pair potential is :math:`u(r)`,
10 then the shifted potential is :math:`u(r) - u(r_{c})`, where :math:`r_c` is the cutoff distance.
12 Note: calls original potential function twice, avoiding changes to params.
14 Parameters
15 ----------
17 pair_potential : callable
18 A function that calculates a pair-potential:
19 u, s, umm = pair_potential(dist, params)
21 Returns
22 -------
24 pair_potential : callable
25 A function where shifted_potential_cutoff is applied to original function
27 Example
28 -------
30 The following example demonstrates how to use this function to set up the Lenard-Jones 12-6 potential
31 truncated and shifted to zero at the cutoff distance of 2.5:
33 >>> import gamdpy as gp
34 >>> pair_func = gp.apply_shifted_force_cutoff(gp.LJ_12_6)
35 >>> A12, A6, cut = 1.0, 1.0, 2.5
36 >>> pair_pot = gp.PairPotential(pair_func, params=[A12, A6, cut], max_num_nbs=1000)
38 """
39 pair_pot = numba.njit(pair_potential)
41 @numba.njit
42 def potential(dist, params): # pragma: no cover
43 cut = params[-1]
44 u, s, umm = pair_pot(dist, params)
45 u_cut, s_cut, umm_cut = pair_pot(cut, params)
46 u -= u_cut
47 return u, s, umm
49 return potential