Coverage for strongcoca/calculators/utilities.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-10-26 18:44 +0000

1import numpy as np 

2 

3 

4def get_dipole_dipole_tensor(distance_vector: np.ndarray) -> np.ndarray: 

5 r"""Returns the dipole-dipole tensor. The dipole-dipole tensor is defined as 

6 

7 .. math: 

8 

9 T_{i\mu j\nu} = \nabla_\mu \nabla_\nu \frac{1}{|\vec{R_{ij}}|} 

10 = \frac{\delta_{\mu\nu}}{|\vec{R_{ij}}|^3} 

11 - 3 \frac{R_{ij,\mu} R_{ij,\nu}}{|\vec{R_{ij}}|^5} 

12 

13 Parameters 

14 ---------- 

15 distance_vector 

16 Distance vector between the two subsystems. 

17 

18 Example 

19 ------- 

20 

21 .. doctest: 

22 

23 >>> get_dipole_dipole_tensor(np.array([1, 2, 3])) 

24 array([[ 0.01499936, -0.00818147, -0.0122722 ], 

25 [-0.00818147, 0.00272716, -0.0245444 ], 

26 [-0.0122722 , -0.0245444 , -0.01772651]]) 

27 

28 """ 

29 assert distance_vector.shape == (3,), \ 

30 f'distance_vector has the wrong shape ({distance_vector})' 

31 r = np.linalg.norm(distance_vector) 

32 T = np.eye(3) / r ** 3 - 3 * np.outer(distance_vector, distance_vector) / r ** 5 

33 return T # type: ignore