Coverage for gpaw/test/test_kpt.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.7.1, created at 2025-07-09 00:21 +0000

1import numpy as np 

2from ase.dft.kpoints import monkhorst_pack 

3from gpaw.kpt_descriptor import KPointDescriptor, to1bz 

4 

5 

6def test_kpt(): 

7 k = 70 

8 k_kc = monkhorst_pack((k, k, 1)) 

9 kd = KPointDescriptor(k_kc + (0.5 / k, 0.5 / k, 0)) 

10 assert (kd.N_c == (k, k, 1)).all() 

11 assert abs(kd.offset_c - (0.5 / k, 0.5 / k, 0)).sum() < 1e-9 

12 

13 bzk_kc = np.array([[0.5, 0.5, 0], 

14 [0.50000000001, 0.5, 0], 

15 [0.49999999999, 0.5, 0], 

16 [0.55, -0.275, 0]]) 

17 cell_cv = np.array([[1, 0, 0], 

18 [-0.5, 3**0.5 / 2, 0], 

19 [0, 0, 5]]) 

20 bz1k_kc = to1bz(bzk_kc, cell_cv) 

21 error_kc = bz1k_kc - np.array([[0.5, -0.5, 0], 

22 [0.50000000001, -0.5, 0], 

23 [0.49999999999, -0.5, 0], 

24 [0.55, -0.275, 0]]) 

25 assert abs(error_kc).max() == 0.0 

26 assert not KPointDescriptor(np.zeros((1, 3)) + 1e-14).gamma