Coverage for gpaw/test/generic/test_8Si.py: 100%

29 statements  

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

1from ase import Atoms 

2from gpaw.test import calculate_numerical_forces 

3from gpaw import GPAW, FermiDirac, PoissonSolver 

4import pytest 

5from gpaw.xc.tools import vxc 

6 

7 

8def test_generic_8Si(): 

9 a = 5.404 

10 bulk = Atoms(symbols='Si8', 

11 positions=[(0, 0, 0.1 / a), 

12 (0, 0.5, 0.5), 

13 (0.5, 0, 0.5), 

14 (0.5, 0.5, 0), 

15 (0.25, 0.25, 0.25), 

16 (0.25, 0.75, 0.75), 

17 (0.75, 0.25, 0.75), 

18 (0.75, 0.75, 0.25)], 

19 pbc=True) 

20 bulk.set_cell((a, a, a), scale_atoms=True) 

21 n = 20 

22 calc = GPAW(mode='fd', 

23 gpts=(n, n, n), 

24 nbands='150%', 

25 occupations=FermiDirac(width=0.01), 

26 poissonsolver=PoissonSolver('fd', nn='M', relax='J'), 

27 kpts=(2, 2, 2), 

28 convergence={'energy': 1e-8} 

29 ) 

30 bulk.calc = calc 

31 f1 = bulk.get_forces()[0, 2] 

32 e1 = bulk.get_potential_energy() 

33 v_xc = vxc(calc.gs_adapter()) 

34 print(v_xc) 

35 niter1 = calc.get_number_of_iterations() 

36 

37 f2 = calculate_numerical_forces(bulk, 0.001, [0], [2])[0, 0] 

38 print((f1, f2, f1 - f2)) 

39 assert f1 == pytest.approx(f2, abs=0.005) 

40 

41 # Volume per atom: 

42 vol = a**3 / 8 

43 de = calc.get_electrostatic_corrections() / vol 

44 print(de) 

45 assert abs(de[0] - -2.190) < 0.001 

46 

47 print((e1, f1, niter1)) 

48 energy_tolerance = 0.0025 

49 force_tolerance = 0.01 

50 assert e1 == pytest.approx(-46.6628, abs=energy_tolerance) 

51 assert f1 == pytest.approx(-1.38242356123, abs=force_tolerance)