Coverage for gpaw/test/nlopt/test_linear.py: 100%
19 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-12 00:18 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-12 00:18 +0000
1import pytest
2import numpy as np
4from gpaw.mpi import world
5from gpaw.nlopt.basic import NLOData
6from gpaw.nlopt.linear import get_chi_tensor
9def test_chi_spinpol(mme_files, in_tmp_dir):
10 chi_values = np.array([7.97619464 + 0.06564128j,
11 7.98936984 + 0.06620975j,
12 8.00265916 + 0.06678416j,
13 8.01606379 + 0.06736459j,
14 8.02958494 + 0.06795116j,
15 8.04322385 + 0.06854397j,
16 8.05698176 + 0.06914314j,
17 8.07085997 + 0.06974877j,
18 8.08485976 + 0.07036098j,
19 8.09898247 + 0.07097988j,
20 8.11322944 + 0.07160561j])
22 freqs = np.linspace(2.3, 2.4, 11)
23 chi_xx = {}
24 for spinpol in ['spinpaired', 'spinpol']:
25 tag = '_spinpol' if spinpol == 'spinpol' else ''
27 # Get pre-calculated nlodata from SiC fixtures
28 nlodata = NLOData.load(mme_files[f'sic_pw{tag}'], comm=world)
30 # Calculate tensor elements of susceptibility spectra
31 get_chi_tensor(nlodata, freqs=freqs,
32 eta=0.05, out_name=f'chi{tag}.npy')
33 world.barrier()
35 # Load the calculated susceptibility
36 chi_xx[spinpol] = np.load(f'chi{tag}.npy')[1]
38 assert chi_xx[spinpol] == pytest.approx(chi_values, abs=5e-2)
40 # Assert that the difference between spectra from spinpaired and
41 # spinpolarised calculations is small
43 # Absolute error
44 assert chi_xx['spinpol'].real == pytest.approx(
45 chi_xx['spinpaired'].real, abs=2e-2)
47 # Relative error
48 assert chi_xx['spinpol'].real == pytest.approx(
49 chi_xx['spinpaired'].real, rel=1e-3)
50 assert chi_xx['spinpol'].imag == pytest.approx(
51 chi_xx['spinpaired'].imag, abs=1e-4)