Coverage for gpaw/test/elph/conftest.py: 100%

27 statements  

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

1import pytest 

2 

3from ase.build import bulk 

4 

5from gpaw import GPAW 

6 

7from gpaw.elph import DisplacementRunner 

8from gpaw.elph import Supercell 

9 

10SUPERCELL = (2, 1, 1) 

11 

12 

13def get_calc(txt, parallel={}): 

14 return GPAW(mode='lcao', 

15 basis='sz(dzp)', 

16 kpts={'size': (1, 2, 2), 'gamma': False}, 

17 symmetry={'point_group': False}, 

18 convergence={'forces': 1.e-4}, 

19 parallel=parallel, 

20 txt=txt) 

21 

22 

23# NOTE: This fixture might need a proper scope assigned 

24@pytest.fixture(scope='module') 

25def elph_cache(module_tmp_path): 

26 """Minimum elph cache for Li 

27 

28 Uses 1x2x2 k-points and 2x1x1 SC to allow for parallelisaiton 

29 test. 

30 Takes 6s on 4 cores. 

31 """ 

32 atoms = bulk('Li', crystalstructure='bcc', a=3.51, cubic=True) 

33 calc = get_calc(txt='elph_li.txt') 

34 atoms.calc = calc 

35 elph = DisplacementRunner(atoms, calc, 

36 supercell=SUPERCELL, name='elph', 

37 calculate_forces=True) 

38 elph.run() 

39 return elph 

40 

41 

42# NOTE: This fixture might need a proper scope assigned 

43@pytest.fixture(scope='module') 

44def supercell_cache(module_tmp_path, elph_cache): 

45 atoms = bulk('Li', crystalstructure='bcc', a=3.51, cubic=True) 

46 atoms_N = atoms * SUPERCELL 

47 elph_cache 

48 calc = get_calc(parallel={'domain': 1, 'band': 1}, 

49 # parallel={'sl_auto': True, 'augment_grids':True, 

50 # 'band': 2, 'kpt': 1, 'domain': 1 }, 

51 txt='gs_li.txt') 

52 atoms_N.calc = calc 

53 atoms_N.get_potential_energy() 

54 

55 # create supercell cache 

56 sc = Supercell(atoms, supercell=SUPERCELL) 

57 sc.calculate_supercell_matrix(calc) 

58 return sc