diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d2c040aa..243b52c5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,3 @@ -exclude: ^(tests) - repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. diff --git a/tests/conftest.py b/tests/conftest.py index 330def5a..743a599b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -131,9 +131,7 @@ def v_N_GaN(test_dir): @pytest.fixture(scope="session") -def basic_fed( - data_Mg_Ga, defect_entries_and_plot_data_Mg_Ga, stable_entries_Mg_Ga_N -): +def basic_fed(data_Mg_Ga, defect_entries_and_plot_data_Mg_Ga, stable_entries_Mg_Ga_N): bulk_vasprun = data_Mg_Ga["bulk_sc"]["vasprun"] bulk_bs = bulk_vasprun.get_band_structure() vbm = bulk_bs.get_vbm()["energy"] diff --git a/tests/plotting/test_thermo.py b/tests/plotting/test_thermo.py index 19e5b54d..7fbfbe9d 100644 --- a/tests/plotting/test_thermo.py +++ b/tests/plotting/test_thermo.py @@ -1,13 +1,14 @@ -import pytest -from pymatgen.analysis.defects.plotting.thermo import plot_formation_energy_diagrams, plot_chempot_2d +from pymatgen.analysis.defects.plotting.thermo import ( + plot_chempot_2d, + plot_formation_energy_diagrams, +) from pymatgen.core import Element -def test_fed_plot(basic_fed): - fig = plot_formation_energy_diagrams([basic_fed]) - assert {d_.name for d_ in fig.data} == {'Mg_Ga', 'Mg_Ga:slope'} - -def test_chempot_plot(basic_fed): - plot_chempot_2d(basic_fed, x_element=Element("Mg"), y_element=Element("Ga")) +def test_fed_plot(basic_fed) -> None: + fig = plot_formation_energy_diagrams([basic_fed]) + assert {d_.name for d_ in fig.data} == {"Mg_Ga", "Mg_Ga:slope"} +def test_chempot_plot(basic_fed) -> None: + plot_chempot_2d(basic_fed, x_element=Element("Mg"), y_element=Element("Ga")) diff --git a/tests/pyproject.toml b/tests/pyproject.toml new file mode 100644 index 00000000..9dda97cf --- /dev/null +++ b/tests/pyproject.toml @@ -0,0 +1,12 @@ +[tool.ruff.format] +# Like Black, use double quotes for strings. +quote-style = "double" + +# Like Black, indent with spaces, rather than tabs. +indent-style = "space" + +# Like Black, respect magic trailing commas. +skip-magic-trailing-comma = false + +# Like Black, automatically detect the appropriate line ending. +line-ending = "auto" \ No newline at end of file diff --git a/tests/test_ccd.py b/tests/test_ccd.py index 8bf2cd82..115d3007 100644 --- a/tests/test_ccd.py +++ b/tests/test_ccd.py @@ -44,7 +44,8 @@ def hd1(v_ga): assert pytest.approx(hd1.omega_eV) == 0.03341323356861477 return hd1 -def test_defect_band_raises(v_ga): + +def test_defect_band_raises(v_ga) -> None: vaspruns = v_ga[(0, -1)]["vaspruns"] procar = v_ga[(0, -1)]["procar"] hd0 = HarmonicDefect.from_vaspruns( @@ -55,15 +56,16 @@ def test_defect_band_raises(v_ga): ) # mis-matched defect band hd0.defect_band = [(138, 0, 1), (139, 1, 1)] - with pytest.raises(ValueError) as e: + with pytest.raises(ValueError): assert hd0.defect_band_index - + # mis-matched defect spin hd0.defect_band = [(138, 0, 1), (138, 1, 0)] - with pytest.raises(ValueError) as e: + with pytest.raises(ValueError): assert hd0.spin_index == 1 -def test_HarmonicDefect(hd0, v_ga, test_dir): + +def test_HarmonicDefect(hd0, v_ga, test_dir) -> None: # test other basic reading functions for HarmonicDefect vaspruns = v_ga[(0, -1)]["vaspruns"] procar = v_ga[(0, -1)]["procar"] @@ -100,7 +102,7 @@ def test_HarmonicDefect(hd0, v_ga, test_dir): assert "Spin index" in str(e.value) -def test_wswq(hd0, test_dir): +def test_wswq(hd0, test_dir) -> None: wswq_dir = test_dir / "v_Ga" / "ccd_0_-1" / "wswqs" # check for ValueError when you have mis-matched distortions and wswqs @@ -119,7 +121,7 @@ def test_wswq(hd0, test_dir): assert np.linalg.norm(elph_me[..., 139]) > 0 -def test_wswq_slope(): +def test_wswq_slope() -> None: # Make sure the the slope is automatically defined as the sign of the distoration changes. mats = [np.ones((3, 5)), np.zeros((3, 5)), np.ones((3, 5))] FakeWSWQ = namedtuple("FakeWSWQ", ["data"]) @@ -132,7 +134,7 @@ def test_wswq_slope(): assert np.allclose(res, np.ones((3, 5)) * 1) -def test_SRHCapture(hd0, hd1, test_dir): +def test_SRHCapture(hd0, hd1, test_dir) -> None: from pymatgen.analysis.defects.ccd import get_SRH_coefficient hd0.read_wswqs(test_dir / "v_Ga" / "ccd_0_-1" / "wswqs") @@ -159,7 +161,7 @@ def test_SRHCapture(hd0, hd1, test_dir): assert "WSWQ" in str(e.value) -def test_dielectric_func(test_dir): +def test_dielectric_func(test_dir) -> None: dir0_opt = test_dir / "v_Ga" / "ccd_0_-1" / "optics" hd0 = HarmonicDefect.from_directories( directories=[dir0_opt], @@ -187,5 +189,5 @@ def test_dielectric_func(test_dir): assert df.iloc[5]["jb"] == 100 -def test_plot_pes(hd0): +def test_plot_pes(hd0) -> None: plot_pes(hd0) diff --git a/tests/test_core.py b/tests/test_core.py index 6de72cb1..811418ba 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -13,7 +13,7 @@ from pymatgen.core.periodic_table import Element, Specie -def test_vacancy(gan_struct): +def test_vacancy(gan_struct) -> None: s = gan_struct.copy() vac = Vacancy(s, s.sites[0]) vac2 = Vacancy(s, s.sites[1]) @@ -29,7 +29,7 @@ def test_vacancy(gan_struct): assert vac.latex_name == r"v$_{\rm Ga}$" -def test_substitution(gan_struct): +def test_substitution(gan_struct) -> None: s = gan_struct.copy() n_site = s.sites[3] assert n_site.specie.symbol == "N" @@ -114,7 +114,7 @@ def test_substitution(gan_struct): assert n_ga.get_charge_states() == [-100, 102] -def test_interstitial(gan_struct): +def test_interstitial(gan_struct) -> None: s = gan_struct.copy() inter_fpos = [0, 0, 0.75] n_site = PeriodicSite(Specie("N"), inter_fpos, s.lattice) @@ -143,7 +143,7 @@ def test_interstitial(gan_struct): assert inter2.get_charge_states() == [-100, 102] -def test_adsorbate(gan_struct): +def test_adsorbate(gan_struct) -> None: s = gan_struct.copy() ads_fpos = [0, 0, 0.75] n_site = PeriodicSite(Specie("N"), ads_fpos, s.lattice) @@ -152,7 +152,7 @@ def test_adsorbate(gan_struct): assert str(ads) == "N adsorbate site at [0.00,0.00,0.75]" -def test_complex(gan_struct): +def test_complex(gan_struct) -> None: s = gan_struct.copy() o_site = PeriodicSite(Specie("O"), s[3].frac_coords, s.lattice) sub = Substitution(s, o_site) # O substituted on N site @@ -177,7 +177,7 @@ def test_complex(gan_struct): assert dc2 != dc -def test_parsing_and_grouping_NamedDefects(test_dir): +def test_parsing_and_grouping_NamedDefects(test_dir) -> None: bulk_dir = test_dir / "Mg_Ga" / "bulk_sc" defect_dir = test_dir / "Mg_Ga" / "q=0" bulk_struct = Structure.from_file(bulk_dir / "CONTCAR.gz") diff --git a/tests/test_corrections.py b/tests/test_corrections.py index e50afcea..649ab441 100644 --- a/tests/test_corrections.py +++ b/tests/test_corrections.py @@ -5,7 +5,7 @@ ) -def test_freysoldt(data_Mg_Ga): +def test_freysoldt(data_Mg_Ga) -> None: """Older basic test for Freysoldt correction.""" bulk_locpot = data_Mg_Ga["bulk_sc"]["locpot"] defect_locpot = data_Mg_Ga["q=0"]["locpot"] @@ -44,7 +44,7 @@ def test_freysoldt(data_Mg_Ga): ) -def test_freysoldt_sxdefect_compare(v_N_GaN): +def test_freysoldt_sxdefect_compare(v_N_GaN) -> None: """More detailed test for Freysoldt correction. Compare against results from the sxdefectalign tool from SPHInX. diff --git a/tests/test_finder.py b/tests/test_finder.py index 0a1cbc16..62500c0e 100644 --- a/tests/test_finder.py +++ b/tests/test_finder.py @@ -1,4 +1,4 @@ -def test_defect_finder(test_dir): +def test_defect_finder(test_dir) -> None: from pymatgen.analysis.defects.finder import DefectSiteFinder from pymatgen.core import IStructure diff --git a/tests/test_generators.py b/tests/test_generators.py index 34aadb82..565dc02a 100644 --- a/tests/test_generators.py +++ b/tests/test_generators.py @@ -11,7 +11,7 @@ ) -def test_vacancy_generators(gan_struct): +def test_vacancy_generators(gan_struct) -> None: vacancy_generator = VacancyGenerator().get_defects(gan_struct) for defect in vacancy_generator: assert isinstance(defect, Vacancy) @@ -29,7 +29,7 @@ def test_vacancy_generators(gan_struct): ) -def test_substitution_generators(gan_struct): +def test_substitution_generators(gan_struct) -> None: sub_generator = SubstitutionGenerator().get_defects( gan_struct, {"Ga": ["Mg", "Ca"]} ) @@ -49,13 +49,13 @@ def test_substitution_generators(gan_struct): } -def test_antisite_generator(gan_struct): +def test_antisite_generator(gan_struct) -> None: anti_gen = AntiSiteGenerator().get_defects(gan_struct) def_names = [defect.name for defect in anti_gen] assert sorted(def_names) == ["Ga_N", "N_Ga"] -def test_interstitial_generator(gan_struct): +def test_interstitial_generator(gan_struct) -> None: gen = InterstitialGenerator().get_defects( gan_struct, insertions={"Mg": [[0, 0, 0]]} ) @@ -71,7 +71,7 @@ def test_interstitial_generator(gan_struct): assert len(l_gen) == 1 -def test_charge_interstitial_generator(chgcar_fe3o4): +def test_charge_interstitial_generator(chgcar_fe3o4) -> None: gen = ChargeInterstitialGenerator().get_defects(chgcar_fe3o4, {"Ga"}) cnt = 0 for defect in gen: @@ -81,7 +81,7 @@ def test_charge_interstitial_generator(chgcar_fe3o4): assert cnt == 2 -def test_voronoi_interstitial_generator(chgcar_fe3o4): +def test_voronoi_interstitial_generator(chgcar_fe3o4) -> None: gen = VoronoiInterstitialGenerator().get_defects(chgcar_fe3o4.structure, {"Li"}) cnt = 0 for defect in gen: @@ -91,7 +91,7 @@ def test_voronoi_interstitial_generator(chgcar_fe3o4): assert cnt == 4 -def test_generate_all_native_defects(chgcar_fe3o4): +def test_generate_all_native_defects(chgcar_fe3o4) -> None: gen = generate_all_native_defects(chgcar_fe3o4) assert len(list(gen)) == 14 diff --git a/tests/test_recombination.py b/tests/test_recombination.py index 01adf23d..bf3b252b 100644 --- a/tests/test_recombination.py +++ b/tests/test_recombination.py @@ -12,7 +12,7 @@ ) -def test_boltzmann(): +def test_boltzmann() -> None: ref_results = [ 0.9791034813819097, 0.020459854127734073, @@ -27,7 +27,7 @@ def test_boltzmann(): assert np.allclose(results2[:, 1], ref_results, rtol=1e-3) -def test_get_vibronic_matrix_elements(): +def test_get_vibronic_matrix_elements() -> None: # precompute values of the overlap dQ, omega_i, omega_f = 0, 0.2, 0.2 Ni, Nf = 5, 5 @@ -42,7 +42,7 @@ def test_get_vibronic_matrix_elements(): assert np.allclose(matel, ref_result) -def test_pchip_eval(): +def test_pchip_eval() -> None: x_c = np.linspace(0, 2, 5) y_c = np.sin(x_c) + 1 xx = np.linspace(-3, 3, 1000) @@ -52,7 +52,7 @@ def test_pchip_eval(): assert int_val == pytest.approx(int_ref, rel=1e-3) -def test_get_SRH_coef(): +def test_get_SRH_coef() -> None: ref_res = [4.64530153e-14, 4.64752885e-14, 4.75265302e-14] res = get_SRH_coef( T=[100, 200, 300], @@ -67,8 +67,8 @@ def test_get_SRH_coef(): assert np.allclose(res, ref_res) -def test_get_Rad_coef(): - res = get_Rad_coef( +def test_get_Rad_coef() -> None: + get_Rad_coef( T=[100, 200, 300], dQ=1.0, dE=1.0, diff --git a/tests/test_supercells.py b/tests/test_supercells.py index 1ef169a7..8973edce 100644 --- a/tests/test_supercells.py +++ b/tests/test_supercells.py @@ -1,16 +1,16 @@ import numpy as np +import pytest from monty.serialization import loadfn from pymatgen.analysis.defects.generators import VacancyGenerator from pymatgen.analysis.defects.supercells import ( _ase_cubic, + get_closest_sc_mat, get_matched_structure_mapping, get_sc_fromstruct, - get_closest_sc_mat ) -import pytest -def test_supercells(gan_struct): +def test_supercells(gan_struct) -> None: uc = gan_struct.copy() sc_mat = get_sc_fromstruct(uc) sc = uc * sc_mat @@ -24,7 +24,7 @@ def test_supercells(gan_struct): ) # the sc_mat can be reconstructed from the sc -def test_ase_supercells(gan_struct): +def test_ase_supercells(gan_struct) -> None: sc_mat = _ase_cubic(gan_struct, min_atoms=4, max_atoms=8, min_length=1.0) sc = gan_struct * sc_mat assert 4 <= sc.num_sites <= 8 @@ -34,27 +34,28 @@ def test_ase_supercells(gan_struct): _ase_cubic(gan_struct, min_atoms=4, max_atoms=8, min_length=10) -def test_closest_sc_mat(test_dir): +def test_closest_sc_mat(test_dir) -> None: si_o_structs = loadfn(test_dir / "Si-O_structs.json") - ref_sc_mat = [[2,1,2], [2,0,3], [2,1,1]] - + ref_sc_mat = [[2, 1, 2], [2, 0, 3], [2, 1, 1]] + vg = VacancyGenerator() + def get_vac(s, sc_mat): vac = next(vg.generate(s, rm_species=["O"])) return vac.get_supercell_structure(sc_mat=sc_mat) - - def check_uc(uc_struct, sc_mat): + + def check_uc(uc_struct, sc_mat) -> None: vac_sc = get_vac(uc_struct, sc_mat) sorted_results = get_closest_sc_mat(uc_struct, vac_sc, debug=True) min_dist = sorted_results[0][0] - close_mats = [r[2] for r in sorted_results if r[0] < min_dist*1.1] + close_mats = [r[2] for r in sorted_results if r[0] < min_dist * 1.1] is_matched = [np.allclose(ref_sc_mat, x) for x in close_mats] assert any(is_matched) - + for s in si_o_structs: check_uc(s, ref_sc_mat) uc_struct = si_o_structs[0] vac_struct = get_vac(uc_struct, ref_sc_mat) res = get_closest_sc_mat(uc_struct=uc_struct, sc_struct=vac_struct, debug=False) - assert np.allclose(res, ref_sc_mat) \ No newline at end of file + assert np.allclose(res, ref_sc_mat) diff --git a/tests/test_thermo.py b/tests/test_thermo.py index 47091fe4..2d974615 100644 --- a/tests/test_thermo.py +++ b/tests/test_thermo.py @@ -72,7 +72,7 @@ def formation_energy_diagram( return fed -def test_lower_envelope(): +def test_lower_envelope() -> None: # Test the lower envelope and transition code with a simple example lines = [[4, 12], [-1, 3], [-5, 4], [-2, 1], [3, 8], [-4, 14], [2, 12], [3, 8]] lower_envelope_ref = [ @@ -84,12 +84,14 @@ def test_lower_envelope(): transitions_ref = [(-4, -4), (-1.4, 3.8), (1, -1)] lower_envelope = get_lower_envelope(lines) assert lower_envelope == lower_envelope_ref - assert get_transitions(lower_envelope, -5, 2) == [(-5, -8)] + transitions_ref + [ - (2, -6) + assert get_transitions(lower_envelope, -5, 2) == [ + (-5, -8), + *transitions_ref, + (2, -6), ] -def test_defect_entry(defect_entries_and_plot_data_Mg_Ga, data_Mg_Ga): +def test_defect_entry(defect_entries_and_plot_data_Mg_Ga, data_Mg_Ga) -> None: defect_entries, plot_data = defect_entries_and_plot_data_Mg_Ga def_entry = defect_entries[0] @@ -117,7 +119,7 @@ def test_defect_entry(defect_entries_and_plot_data_Mg_Ga, data_Mg_Ga): assert def_entry.get_ediff() == pytest.approx(ediff, abs=1e-4) -def test_formation_energy_diagram_using_bulk_entry(formation_energy_diagram): +def test_formation_energy_diagram_using_bulk_entry(formation_energy_diagram) -> None: fed = copy.deepcopy(formation_energy_diagram) def_ents_w_bulk = copy.deepcopy(fed.defect_entries) @@ -154,7 +156,7 @@ def test_formation_energy_diagram_using_bulk_entry(formation_energy_diagram): assert fed.bulk_formula == "GaN" -def test_formation_energy_diagram_shape_fixed(formation_energy_diagram): +def test_formation_energy_diagram_shape_fixed(formation_energy_diagram) -> None: fed = copy.deepcopy(formation_energy_diagram) # check that the shape of the formation energy diagram does not change @@ -173,7 +175,9 @@ def test_formation_energy_diagram_shape_fixed(formation_energy_diagram): assert np.allclose(y, y_ref) -def test_formation_energy_diagram_using_atomic_entries(formation_energy_diagram): +def test_formation_energy_diagram_using_atomic_entries( + formation_energy_diagram, +) -> None: # test the constructor with materials project phase diagram fed = copy.deepcopy(formation_energy_diagram) atomic_entries = list( @@ -191,7 +195,7 @@ def test_formation_energy_diagram_using_atomic_entries(formation_energy_diagram) assert len(fed.chempot_limits) == 3 -def test_formation_energy_diagram_numerical(formation_energy_diagram): +def test_formation_energy_diagram_numerical(formation_energy_diagram) -> None: # Create a fake defect entry independent of the test data fed = copy.deepcopy(formation_energy_diagram) fake_defect_entry = fed.defect_entries[0] @@ -220,7 +224,7 @@ def test_formation_energy_diagram_numerical(formation_energy_diagram): ) == pytest.approx(2 * 1.5875937551666035e-17) -def test_competing_phases(formation_energy_diagram): +def test_competing_phases(formation_energy_diagram) -> None: fed = copy.deepcopy(formation_energy_diagram) cp_at_point = dict() for chempot_, competing_phases_ in zip(fed.chempot_limits, fed.competing_phases): @@ -236,7 +240,9 @@ def test_competing_phases(formation_energy_diagram): assert cp_at_point == ref_dict -def test_multi(data_Mg_Ga, defect_entries_and_plot_data_Mg_Ga, stable_entries_Mg_Ga_N): +def test_multi( + data_Mg_Ga, defect_entries_and_plot_data_Mg_Ga, stable_entries_Mg_Ga_N +) -> None: bulk_vasprun = data_Mg_Ga["bulk_sc"]["vasprun"] bulk_dos = bulk_vasprun.complete_dos _, vbm = bulk_dos.get_cbm_vbm() @@ -259,7 +265,7 @@ def test_multi(data_Mg_Ga, defect_entries_and_plot_data_Mg_Ga, stable_entries_Mg ) FormationEnergyDiagram( bulk_entry=bulk_entry, - defect_entries=def_ent_list + [fake_defect_entry], + defect_entries=[*def_ent_list, fake_defect_entry], vbm=vbm, pd_entries=stable_entries_Mg_Ga_N, inc_inf_values=False, @@ -292,7 +298,9 @@ def test_multi(data_Mg_Ga, defect_entries_and_plot_data_Mg_Ga, stable_entries_Mg assert len(mfed.formation_energy_diagrams) == 1 -def test_formation_from_directory(test_dir, stable_entries_Mg_Ga_N, defect_Mg_Ga): +def test_formation_from_directory( + test_dir, stable_entries_Mg_Ga_N, defect_Mg_Ga +) -> None: sc_dir = test_dir / "Mg_Ga" qq = [] for q in [-1, 0, 1]: @@ -310,7 +318,7 @@ def test_formation_from_directory(test_dir, stable_entries_Mg_Ga_N, defect_Mg_Ga assert len(trans) == 1 + len(qq) -def test_ensure_stable_bulk(stable_entries_Mg_Ga_N): +def test_ensure_stable_bulk(stable_entries_Mg_Ga_N) -> None: entries = stable_entries_Mg_Ga_N pd = PhaseDiagram(stable_entries_Mg_Ga_N) bulk_comp = Composition("GaN") @@ -319,7 +327,7 @@ def test_ensure_stable_bulk(stable_entries_Mg_Ga_N): entries = list( filter(lambda x: x.composition.reduced_formula != "GaN", stable_entries_Mg_Ga_N) ) - pd1 = PhaseDiagram(entries + [fake_bulk_ent]) + pd1 = PhaseDiagram([*entries, fake_bulk_ent]) assert "GaN" not in [e.composition.reduced_formula for e in pd1.stable_entries] pd2 = ensure_stable_bulk(pd, fake_bulk_ent) assert "GaN" in [e.composition.reduced_formula for e in pd2.stable_entries] @@ -327,7 +335,7 @@ def test_ensure_stable_bulk(stable_entries_Mg_Ga_N): def test_plotter( data_Mg_Ga, defect_entries_and_plot_data_Mg_Ga, stable_entries_Mg_Ga_N, plot_fn -): +) -> None: bulk_vasprun = data_Mg_Ga["bulk_sc"]["vasprun"] bulk_dos = bulk_vasprun.complete_dos _, vbm = bulk_dos.get_cbm_vbm() @@ -374,7 +382,7 @@ def test_plotter( plot_fn(fed, fed.chempot_limits[0]) -@pytest.fixture(scope="function") +@pytest.fixture() def plot_fn(): def _plot(*args): plot_formation_energy_diagrams(*args, save=True, show=True) @@ -385,7 +393,7 @@ def _plot(*args): return _plot -def test_defect_entry_grouping(defect_entries_and_plot_data_Mg_Ga): +def test_defect_entry_grouping(defect_entries_and_plot_data_Mg_Ga) -> None: defect_entries_dict, _ = defect_entries_and_plot_data_Mg_Ga defect_entries = list(defect_entries_dict.values()) for g_name, g in group_defect_entries(defect_entries=defect_entries): diff --git a/tests/test_utils.py b/tests/test_utils.py index 729a8c83..063dde62 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -16,7 +16,7 @@ from pymatgen.io.vasp.outputs import Chgcar -def test_get_local_extrema(gan_struct): +def test_get_local_extrema(gan_struct) -> None: data = np.ones((48, 48, 48)) chgcar = Chgcar(poscar=gan_struct, data={"total": data}) frac_pos = [[0, 0, 0], [0.25, 0.25, 0.25], [0.5, 0.5, 0.5], [0.75, 0.75, 0.75]] @@ -28,7 +28,7 @@ def test_get_local_extrema(gan_struct): assert np.allclose(a, b) -def test_cluster_nodes(gan_struct): +def test_cluster_nodes(gan_struct) -> None: frac_pos = [ [0, 0, 0], [0.25, 0.25, 0.25], @@ -47,7 +47,7 @@ def test_cluster_nodes(gan_struct): assert np.allclose(a, b, atol=0.001) -def test_get_avg_chg(gan_struct): +def test_get_avg_chg(gan_struct) -> None: data = np.ones((48, 48, 48)) chgcar = Chgcar(poscar=gan_struct, data={"total": data}) fpos = [0.1, 0.1, 0.1] @@ -56,7 +56,7 @@ def test_get_avg_chg(gan_struct): pytest.approx(avg_chg_sphere, avg_chg) -def test_chgcar_insertion(chgcar_fe3o4): +def test_chgcar_insertion(chgcar_fe3o4) -> None: chgcar = chgcar_fe3o4 insert_ref = [ ( @@ -76,7 +76,7 @@ def test_chgcar_insertion(chgcar_fe3o4): assert np.allclose(fpos, ref_fpos) -def test_topography_analyzer(chgcar_fe3o4): +def test_topography_analyzer(chgcar_fe3o4) -> None: struct = chgcar_fe3o4.structure ta = TopographyAnalyzer(struct, ["Fe", "O"], [], check_volume=True) node_struct = ta.get_structure_with_nodes() @@ -89,14 +89,14 @@ def test_topography_analyzer(chgcar_fe3o4): ta = TopographyAnalyzer(struct, ["O"], ["Fe"], check_volume=True) -def test_get_localized_states(v_ga): +def test_get_localized_states(v_ga) -> None: vaspruns = v_ga[(0, -1)]["vaspruns"] procar = v_ga[(0, -1)]["procar"] vr = vaspruns[1] bs = vr.get_band_structure() - res = get_localized_states(bs, procar=procar) + get_localized_states(bs, procar=procar) loc_bands = set() - for iband, ikpt, ispin, val in get_localized_states(bs, procar=procar): + for iband, _ikpt, _ispin, _val in get_localized_states(bs, procar=procar): loc_bands.add(iband) assert loc_bands == { 138, @@ -108,14 +108,14 @@ def test_get_localized_states(v_ga): bs = vr.get_band_structure() loc_bands = set() - for iband, ikpt, ispin, val in get_localized_states( + for iband, _ikpt, _ispin, _val in get_localized_states( bs, procar=procar, band_window=100 ): loc_bands.add(iband) assert loc_bands == {75, 77} # 75 and 77 are more localized core states -def test_group_docs(gan_struct): +def test_group_docs(gan_struct) -> None: s = gan_struct.copy() vac1 = Vacancy(s, s.sites[0]) vac2 = Vacancy(s, s.sites[1]) @@ -160,6 +160,6 @@ def get_interstitial(fpos): assert "|".join(sorted(g_names)) == "N_i:0|N_i:1|v_Ga|v_N" -def test_plane_spacing(gan_struct): +def test_plane_spacing(gan_struct) -> None: lattice = gan_struct.lattice.matrix assert np.allclose(get_plane_spacing(lattice), [2.785, 2.785, 5.239], atol=0.001)