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

1import numba 

2 

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 

6 

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`. 

10 

11 

12 Note: calls original potential function twice, avoiding changes to params 

13 

14 Parameters 

15 ---------- 

16 pair_potential: callable 

17 a function that calculates a pair-potential: 

18 u, s, umm = pair_potential(dist, params) 

19 

20 Returns 

21 ------- 

22 

23 potential: callable 

24 a function where shifted force cutoff is applied to original function 

25 

26 """ 

27 pair_pot = numba.njit(pair_potential) 

28 

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 

38 

39 return potential 

40