Coverage for gamdpy/interactions/potential_functions/cos_angle_function.py: 42%

12 statements  

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

1import numpy as np 

2import numba 

3import math 

4from numba import cuda 

5 

6 

7 

8 

9def cos_angle_function(angle, params): 

10 """ Cosine angle potential 

11 

12 .. math:: 

13 u(\\theta) = \\frac{k}{2} (\\cos(\\theta) - \\cos(\\theta_0))^2 

14 

15 Parameters 

16 ---------- 

17 angle: Current angle 

18 params: Parameter array - angle spring coefficient and zero force angle 

19  

20 Returns 

21 ------- 

22 u: Potential energy 

23 f: Force multiplier 

24 """ 

25 

26 kspring, angle0 = params[0], params[1] 

27 

28 # Definition the calc. angle is pi-angle0 - see Rapaport  

29 cos_angle_0 = math.cos(math.pi - angle0) 

30 cos_angle = math.cos(angle) 

31 dcos_angle = cos_angle - cos_angle_0 

32 

33 f = -kspring*dcos_angle 

34 u = numba.float32(0.5)*kspring*dcos_angle**2 

35 

36 return u, f 

37