1import pytest 2 3from ase.build import bulk 4 5 6def systems(): 7 yield bulk('Si') 8 atoms = bulk('Fe') 9 atoms.set_initial_magnetic_moments([1.0]) 10 yield atoms 11 12 13@pytest.mark.calculator_lite 14@pytest.mark.parametrize('atoms', systems(), 15 ids=lambda atoms: str(atoms.symbols)) 16@pytest.mark.calculator('elk', tasks=0, ngridk=(3, 3, 3)) 17def test_elk_bulk(factory, atoms): 18 calc = factory.calc() 19 atoms.calc = calc 20 spinpol = atoms.get_initial_magnetic_moments().any() 21 props = atoms.get_properties(['energy', 'forces']) 22 energy = props['energy'] 23 24 # Need more thorough tests. 25 if str(atoms.symbols) == 'Si2': 26 assert energy == pytest.approx(-15729.719246, abs=0.1) 27 assert atoms.get_potential_energy() == pytest.approx(energy) 28 29 # Since this is FileIO we tend to just load everything there is: 30 expected_props = { 31 'energy', 'free_energy', 'forces', 'ibz_kpoints', 32 'eigenvalues', 'occupations' 33 } 34 35 assert expected_props < set(props) 36 37 # TODO move to unittest based on random numbers 38 # This really belongs in a test of the calculator method mixin 39 assert calc.get_fermi_level() == props['fermi_level'] 40 assert calc.get_ibz_k_points() == pytest.approx(props['ibz_kpoints']) 41 assert calc.get_k_point_weights() == pytest.approx(props['kpoint_weights']) 42 43 I = slice(None) 44 assert calc.get_eigenvalues(I, I) == pytest.approx(props['eigenvalues']) 45 assert calc.get_occupation_numbers(I, I) == pytest.approx( 46 props['occupations']) 47 assert calc.get_spin_polarized() == spinpol 48 assert calc.get_number_of_spins() == 1 + int(spinpol) 49 assert calc.get_number_of_bands() == props['nbands'] 50