Coverage for gamdpy/interactions/potential_functions/add_potential_functions.py: 50%

6 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2025-06-14 15:25 +0200

1import numba 

2import numpy as np 

3 

4def add_potential_functions(potential_1, potential_2): 

5 """ Add two potential functions into a single potential function 

6 

7 Note that the two potential functions will have the same cut-off, by convention always stored as the last entry in params. 

8 The **potential_1** cannot explicitly depend on cut-off (last entry in params). 

9 The **potential_2** should know where to *look* for its first parameter in the list of parmeters (**params**), 

10 see e.g. **first_parameter** in :func:`gamdpy.make_IPL_n`. 

11 

12 

13 Parameters 

14 ---------- 

15 potential_1: callable 

16 a function that calculates a pair-potential: 

17 u, s, umm = potential_1(dist, params) 

18 potential_2: callable 

19 a function that calculates a pair-potential: 

20 u, s, umm = potential_2(dist, params) 

21 

22 Returns 

23 ------- 

24 potential: callable 

25 a function implementing the sum of potential_1 and potential_2 

26 

27 Example 

28 ------- 

29 Below we make the 12-6 Lennard-Jones potential by adding two inverse power-law potentials. 

30 

31 >>> import gamdpy as gp 

32 >>> LJ = gp.add_potential_functions(gp.make_IPL_n(12), gp.make_IPL_n(6, first_parameter=1)) 

33 >>> params = A12, A6, cut = 4.0, -4.0, 2.5 

34 >>> dist = 2**(1/6) # Minima of LJ potential 

35 >>> LJ(dist,params)[0] # Pair energy in minima 

36 -1.0 

37 """ 

38 pair_pot1 = numba.njit(potential_1) 

39 pair_pot2 = numba.njit(potential_2) 

40 

41 #@numba.njit 

42 def potential(dist, params): # pragma: no cover 

43 u1, s1, umm1 = pair_pot1(dist, params) 

44 u2, s2, umm2 = pair_pot2(dist, params) 

45 return u1+u2, s1+s2, umm1+umm2 

46 

47 return potential 

48