Coverage for gpaw/test/wannier/wannierk_lcao.py: 24%

34 statements  

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

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

2 

3import pytest 

4from ase.build import bulk 

5from ase.dft.wannier import Wannier 

6 

7from gpaw import GPAW 

8from gpaw.mpi import world, serial_comm 

9 

10 

11@pytest.mark.wannier 

12@pytest.mark.skip(reason='TODO') 

13def test_wannierk_lcao(): 

14 si = bulk('Si', 'diamond', a=5.43) 

15 

16 k = 2 

17 if 1: 

18 si.calc = GPAW(kpts=(k, k, k), mode='lcao', txt='Si-ibz.txt') 

19 _ = si.get_potential_energy() 

20 si.calc.write('Si-ibz', mode='all') 

21 

22 def wan(calc): 

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

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

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

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

27 w = Wannier(4, calc, 

28 nbands=4, 

29 verbose=False, 

30 initialwannier=centers) 

31 w.localize() 

32 x = w.get_functional_value() 

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

34 c = (centers - 0.125) * 2 

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

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

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

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

39 if 0: 

40 from ase.visualize import view 

41 from ase import Atoms 

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

43 scaled_positions=centers, 

44 cell=calc.atoms.cell) 

45 view(watoms) 

46 return x 

47 

48 calc1 = GPAW('Si-bz.gpw', txt=None, communicator=serial_comm) 

49 # do full lcao initialization 

50 # print('Re-Init LCAO calc') 

51 _s = calc1.get_atoms() 

52 calc1.set_positions(_s) 

53 calc1.wfs.eigensolver.iterate(calc1.hamiltonian, calc1.wfs) 

54 x1 = wan(calc1) 

55 

56 # print x1 

57 x2 = 5.76962685681 # from FD mode 

58 assert abs(x1 - x2) < 0.001 

59 # assert abs(x1 - 9.71) < 0.01 

60 

61 world.barrier()