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

1import numpy as np 

2import numba 

3import math 

4from numba import cuda 

5 

6def apply_shifted_potential_cutoff(pair_potential: callable) -> callable: 

7 """ Apply shifted potential cutoff to a pair-potential function 

8 

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. 

11 

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

13 

14 Parameters 

15 ---------- 

16 

17 pair_potential : callable 

18 A function that calculates a pair-potential: 

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

20 

21 Returns 

22 ------- 

23 

24 pair_potential : callable 

25 A function where shifted_potential_cutoff is applied to original function 

26 

27 Example 

28 ------- 

29 

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: 

32 

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) 

37 

38 """ 

39 pair_pot = numba.njit(pair_potential) 

40 

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 

48 

49 return potential 

50