Coverage for gpaw/test/wannier/test_wannierk.py: 97%

29 statements  

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

1import pytest 

2from ase.dft.wannier import Wannier 

3 

4from gpaw import GPAW 

5 

6 

7@pytest.mark.serial 

8@pytest.mark.wannier 

9def test_ase_features_wannierk(in_tmp_dir, gpw_files, gpaw_new): 

10 'Test ase.dft.wannier module with k-points.' 

11 k = 3 

12 

13 def wan(calc): 

14 centers = [([0.125, 0.125, 0.125], 0, 1.5), 

15 ([0.125, 0.625, 0.125], 0, 1.5), 

16 ([0.125, 0.125, 0.625], 0, 1.5), 

17 ([0.625, 0.125, 0.125], 0, 1.5)] 

18 w = Wannier(4, calc, 

19 nbands=4, 

20 # log=print, 

21 initialwannier=centers) 

22 w.localize() 

23 x = w.get_functional_value() 

24 centers = (w.get_centers(1) * k) % 1 

25 c = (centers - 0.125) * 2 

26 print(w.get_radii()) # broken! XXX 

27 assert abs(c.round() - c).max() < 0.03 

28 c = sorted(c.round().astype(int).tolist()) 

29 assert c == [[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0]] 

30 if 0: 

31 from ase import Atoms 

32 from ase.visualize import view 

33 watoms = calc.atoms + Atoms(symbols='X4', 

34 scaled_positions=centers, 

35 cell=calc.atoms.cell) 

36 view(watoms) 

37 return x 

38 

39 calc1 = GPAW(gpw_files['si_fd_bz']) 

40 x1 = wan(calc1) 

41 assert abs(x1 - 8.817) < 0.01 

42 if gpaw_new: 

43 return 

44 

45 calc2 = GPAW(gpw_files['si_fd_ibz']) 

46 calc2.wfs.ibz2bz(calc2.atoms) 

47 x2 = wan(calc2) 

48 assert abs(x1 - x2) < 0.001