Coverage for gpaw/test/new/test_tb_mode.py: 100%
17 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-20 00:19 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-20 00:19 +0000
1import pytest
2from ase import Atoms
3from ase.optimize import BFGS
4from gpaw.new.ase_interface import GPAW
5from gpaw.test.xc.test_qna_stress import numeric_stress
8@pytest.mark.serial
9def test_tb_mode_molecule():
10 atoms = Atoms('LiH',
11 [[0, 0.1, 0.2],
12 [0, 0, 1.4]])
13 atoms.calc = GPAW(
14 mode='tb',
15 symmetry='off', # ??? should not be needed
16 txt='-') # None)
17 atoms.get_potential_energy()
18 # f1 = atoms.get_forces()
19 # f2 = calculate_numerical_forces(atoms)
20 # assert abs(f1 - f2).max() < 0.0005
23@pytest.mark.serial
24def test_tb_mode_bulk():
25 a = 2.0
26 atoms = Atoms('Li',
27 cell=[a, a, a],
28 pbc=True)
29 atoms.calc = GPAW(
30 mode='tb',
31 kpts=(2, 2, 2))
32 atoms.get_potential_energy()
33 return
34 from ase.filters import ExpCellFilter
35 f = atoms.get_forces()
36 assert abs(f).max() < 0.0001
37 e = atoms.get_potential_energy()
38 s = atoms.get_stress()
39 print(a, e, s)
40 s2 = [numeric_stress(atoms, 1e-6, component)
41 for component in [(0, 0), (1, 1), (2, 2), (1, 2), (0, 2), (0, 1)]]
42 print(s2)
43 assert abs(s - s2).max() < 0.0001
44 BFGS(ExpCellFilter(atoms)).run(fmax=0.002)
45 s = atoms.get_stress()
46 print(s)
47 assert abs(s).max() < 0.0001
48 assert atoms.cell[0, 0] == pytest.approx(2.044, abs=0.0005)