Coverage for gamdpy/interactions/potential_functions/apply_shifted_force_cutoff.py: 100%
4 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 numba
3def apply_shifted_force_cutoff(pair_potential):
4 # Cut-off by computing potential twice, avoiding changes to params
5 """ Apply shifted force cutoff to a pair-potential function
7 If the input pair potential is :math:`u(r)`, then the shifted force potential is
8 :math:`u(r) - u(r_{c}) + s(r_{c})(r - r_{c})`, where :math:`r_c` is the cutoff distance,
9 and :math:`s(r) = -u'(r)/r`.
12 Note: calls original potential function twice, avoiding changes to params
14 Parameters
15 ----------
16 pair_potential: callable
17 a function that calculates a pair-potential:
18 u, s, umm = pair_potential(dist, params)
20 Returns
21 -------
23 potential: callable
24 a function where shifted force cutoff is applied to original function
26 """
27 pair_pot = numba.njit(pair_potential)
29 @numba.njit
30 def potential(dist, params): # pragma: no cover
31 cut = params[-1]
32 u, s, umm = pair_pot(dist, params)
33 u_cut, s_cut, umm_cut = pair_pot(cut, params)
34 u -= u_cut - s_cut * cut * (dist - cut)
35 #u -= u_cut - s_cut*dist*(dist-cut)
36 s -= s_cut
37 return u, s, umm
39 return potential