Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kavanase committed Jul 1, 2024
1 parent d23ed98 commit eb0cb3f
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 38 deletions.
Binary file modified examples/CdTe/CdTe_example_defect_dict.json.gz
Binary file not shown.
Binary file modified examples/CdTe/CdTe_example_thermo.json.gz
Binary file not shown.
Binary file modified examples/Sb2Si2Te6/Sb2Si2Te6_example_defect_dict.json.gz
Binary file not shown.
Binary file modified examples/Sb2Si2Te6/Sb2Si2Te6_example_thermo.json.gz
Binary file not shown.
Binary file modified examples/YTOS/YTOS_example_defect_dict.json.gz
Binary file not shown.
Binary file modified examples/YTOS/YTOS_example_thermo.json.gz
Binary file not shown.
Binary file modified tests/data/Sb2Se3/Sb2Se3_O_example_thermo.json.gz
Binary file not shown.
Binary file modified tests/data/Sb2Se3/defect/Sb2Se3_O_example_defect_dict.json.gz
Binary file not shown.
Binary file modified tests/data/V2O5/V2O5_example_defect_dict.json.gz
Binary file not shown.
Binary file modified tests/data/V2O5/V2O5_example_thermo.json.gz
Binary file not shown.
Binary file modified tests/data/ZnS/ZnS_thermo.json.gz
Binary file not shown.
64 changes: 37 additions & 27 deletions tests/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def _check_parsed_CdTe_defect_energies(self, dp):
7.661,
atol=3e-3,
) # uncorrected energy
assert np.isclose(dp.defect_dict["v_Cd_-2"].get_ediff(), 8.398, atol=1e-3)
# slightly higher atol here, due to LOCPOT sub-sampling for file compression on repo:
assert np.isclose(dp.defect_dict["v_Cd_-2"].get_ediff(), 8.398, atol=2e-3)
assert np.isclose(dp.defect_dict["Int_Te_3_2"].get_ediff(), -6.2009, atol=1e-3)

def _check_default_CdTe_DefectsParser_outputs(
Expand Down Expand Up @@ -346,7 +347,7 @@ def test_DefectsParser_CdTe(self):
@custom_mpl_image_compare(filename="CdTe_example_defects_plot.png")
def test_DefectsParser_CdTe_without_multiprocessing(self):
shutil.move( # avoid overwriting
os.path.join(self.CdTe_EXAMPLE_DIR, "CdTe_example_thermo.json.gz.gz"),
os.path.join(self.CdTe_EXAMPLE_DIR, "CdTe_example_thermo.json.gz"),
os.path.join(self.CdTe_EXAMPLE_DIR, "orig_CdTe_example_thermo.json.gz"),
)
# test same behaviour without multiprocessing:
Expand Down Expand Up @@ -615,8 +616,10 @@ def test_DefectsParser_corrections_errors_warning(self):
"Estimated error in the Kumagai (eFNV) ",
"charge correction for certain defects is greater than the `error_tolerance` (= "
"1.00e-03 eV):",
"v_Cd_-2: 1.13e-02 eV",
"v_Cd_-1: 7.91e-03 eV",
"v_Cd_-2: 1.",
"e-02 eV",
"v_Cd_-1:",
"e-03 eV",
"Int_Te_3_1: 3.10e-03 eV",
"Te_Cd_+1: 2.02e-03 eV",
"Int_Te_3_Unperturbed_1: 4.91e-03 eV",
Expand Down Expand Up @@ -1340,8 +1343,6 @@ def tearDown(self):
f"{self.CdTe_EXAMPLE_DIR}/v_Cd_-2/vasp_ncl/LOCPOT.gz",
)

if_present_rm(f"{self.CdTe_EXAMPLE_DIR}/Int_Te_3_2/vasp_ncl/LOCPOT.gz")

def test_auto_charge_determination(self):
"""
Test that the defect charge is correctly auto-determined.
Expand All @@ -1363,8 +1364,8 @@ def test_auto_charge_determination(self):
"with specified charge_state, but beware!" in str(w[-1].message)
)
assert np.isclose(
parsed_v_cd_m1.corrections["freysoldt_charge_correction"], 0.26066457692529815
)
parsed_v_cd_m1.corrections["freysoldt_charge_correction"], 0.261, atol=1e-3
) # slightly higher atol, due to LOCPOT sub-sampling for file compression on repo

# test YTOS, has trickier POTCAR symbols with Y_sv, Ti, S, O
ytos_F_O_1 = defect_entry_from_paths( # with corrections this time
Expand Down Expand Up @@ -1578,8 +1579,9 @@ def blockwise_average_ND(a, factors):
atol=3e-3,
) # uncorrected energy
assert np.isclose(
parsed_int_Te_2_fake_aniso.get_ediff(), -4.7620, atol=1e-3
) # -4.734 with old voronoi frac coords
parsed_int_Te_2_fake_aniso.get_ediff(), -4.7620, atol=2e-2
) # -4.734 with old voronoi frac coords, expanded atol now to account for LOCPOT sub-sampling
# compression

if_present_rm(f"{self.CdTe_EXAMPLE_DIR}/Int_Te_3_2/vasp_ncl/LOCPOT.gz")

Expand Down Expand Up @@ -1786,7 +1788,7 @@ def test_dielectric_initialisation(self):
assert np.isclose(
parsed_v_cd_m2.corrections[correction_name],
correction_energy,
atol=1e-3,
atol=2e-3, # slightly higher atol due to LOCPOT sub-sampling for file compression
)

# test float
Expand All @@ -1800,7 +1802,7 @@ def test_dielectric_initialisation(self):
assert np.isclose(
new_parsed_v_cd_m2.corrections[correction_name],
correction_energy,
atol=1e-3,
atol=2e-3, # slightly higher atol due to LOCPOT sub-sampling for file compression
)

# test int
Expand Down Expand Up @@ -1829,7 +1831,7 @@ def test_dielectric_initialisation(self):
assert np.isclose(
new_parsed_v_cd_m2.corrections[correction_name],
correction_energy,
atol=1e-3,
atol=2e-3, # slightly higher atol due to LOCPOT sub-sampling for file compression
)

# test 3x1 list
Expand All @@ -1844,7 +1846,7 @@ def test_dielectric_initialisation(self):
assert np.isclose(
new_parsed_v_cd_m2.corrections[correction_name],
correction_energy,
atol=1e-3,
atol=2e-3, # slightly higher atol due to LOCPOT sub-sampling for file compression
)

# test 3x3 array
Expand All @@ -1858,7 +1860,7 @@ def test_dielectric_initialisation(self):
assert np.isclose(
new_parsed_v_cd_m2.corrections[correction_name],
correction_energy,
atol=1e-3,
atol=2e-3, # slightly higher atol due to LOCPOT sub-sampling for file compression
)

# test 3x3 list
Expand All @@ -1873,7 +1875,7 @@ def test_dielectric_initialisation(self):
assert np.isclose(
new_parsed_v_cd_m2.corrections[correction_name],
correction_energy,
atol=1e-3,
atol=2e-3, # slightly higher atol due to LOCPOT sub-sampling for file compression
)

def test_vacancy_parsing_and_freysoldt(self):
Expand Down Expand Up @@ -1918,12 +1920,12 @@ def test_vacancy_parsing_and_freysoldt(self):
},
),
]:
assert np.isclose(parsed_vac_Cd_dict[name].get_ediff(), energy, atol=1e-3)
assert np.isclose(parsed_vac_Cd_dict[name].get_ediff(), energy, atol=2e-3)
for correction_name, correction_energy in correction_dict.items():
assert np.isclose(
parsed_vac_Cd_dict[name].corrections[correction_name],
correction_energy,
atol=1e-3,
atol=2e-3, # slightly higher atol due to LOCPOT sub-sampling for file compression
)

# assert auto-determined vacancy site is correct
Expand Down Expand Up @@ -2209,16 +2211,20 @@ def test_extrinsic_substitution_parsing_and_freysoldt_and_kumagai(self):
parse_projected_eigen=False,
) # check no correction error warning with default tolerance:
print([str(warn.message) for warn in w])
assert any( # break up warning message to allow slightly difference numbers after 3.XXe-04 eV:
f"Estimated error in the Freysoldt (FNV) charge correction for defect {F_O_1_ent.name} is 3"
in str(warning.message)
for warning in w
)
assert any(
f"Estimated error in the Freysoldt (FNV) charge correction for defect {F_O_1_ent.name} is "
f"3.54e-04 eV (i.e. which is greater than the `error_tolerance`: 1.00e-05 eV). You may want "
f"to check the accuracy of the correction by plotting the site potential differences (using "
f"`defect_entry.get_freysoldt_correction()` with `plot=True`). Large errors are often due "
f"to unstable or shallow defect charge states (which can't be accurately modelled with "
f"the supercell approach; see "
f"https://doped.readthedocs.io/en/latest/Tips.html#perturbed-host-states). "
f"If this error is not acceptable, you may need to use a larger supercell for more "
f"accurate energies." in str(warning.message)
"e-04 eV (i.e. which is greater than the `error_tolerance`: 1.00e-05 eV). You may want "
"to check the accuracy of the correction by plotting the site potential differences (using "
"`defect_entry.get_freysoldt_correction()` with `plot=True`). Large errors are often due "
"to unstable or shallow defect charge states (which can't be accurately modelled with "
"the supercell approach; see "
"https://doped.readthedocs.io/en/latest/Tips.html#perturbed-host-states). "
"If this error is not acceptable, you may need to use a larger supercell for more "
"accurate energies." in str(warning.message)
for warning in w
)

Expand Down Expand Up @@ -2483,6 +2489,9 @@ def tearDown(self):
f"{self.Cu2SiSe3_EXAMPLE_DIR}/{dir}/vasp_std/vasprun.xml.gz",
)

if_present_rm(os.path.join(self.Cu2SiSe3_EXAMPLE_DIR, "Cu2SiSe3_defect_dict.json.gz"))
if_present_rm(os.path.join(self.Cu2SiSe3_EXAMPLE_DIR, "bulk/vasp_std/voronoi_nodes.json"))

def test_defect_name_from_structures(self):
# by proxy also tests defect_from_structures
for defect_gen_name in [
Expand Down Expand Up @@ -3181,6 +3190,7 @@ def _compare_band_edge_states_dicts(d1, d2, orb_diff_tol: float = 0.1):
reloaded_defect_dict = loadfn("test.json")
bes, fig = reloaded_defect_dict["v_Cu_0"].get_eigenvalue_analysis()
_compare_band_edge_states_dicts(bes, v_Cu_0_bes_path, orb_diff_tol=0.001)
os.remove("test.json")

return fig

Expand Down
22 changes: 11 additions & 11 deletions tests/test_thermodynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,16 +555,16 @@ def test_transition_levels_CdTe(self):
Test outputs of transition level functions for CdTe.
"""
assert self.CdTe_defect_thermo.transition_level_map == {
"v_Cd": {0.46988348089141413: [0, -2]},
"v_Cd": {0.47047144459596113: [0, -2]},
"Te_Cd": {},
"Int_Te_3": {0.03497090517885537: [2, 1]},
}

tl_info = ["Defect: v_Cd", "Defect: Te_Cd"]
tl_info_not_all = ["Transition level ε(0/-2) at 0.470 eV above the VBM"]
tl_info_all = [
"Transition level ε(-1*/-2) at 0.397 eV above the VBM",
"Transition level ε(0/-1*) at 0.543 eV above the VBM",
"Transition level ε(-1*/-2) at 0.399 eV above the VBM",
"Transition level ε(0/-1*) at 0.542 eV above the VBM",
"*",
]

Expand Down Expand Up @@ -707,8 +707,8 @@ def test_get_transition_levels_CdTe(self):

tl_df = self.CdTe_defect_thermo.get_transition_levels(all=True)
assert tl_df.shape == (5, 5)
assert list(tl_df.iloc[0]) == ["v_Cd", "ε(-1*/-2)", 0.397, True, 1]
assert list(tl_df.iloc[1]) == ["v_Cd", "ε(0/-1*)", 0.543, True, 1]
assert list(tl_df.iloc[0]) == ["v_Cd", "ε(-1*/-2)", 0.399, True, 1]
assert list(tl_df.iloc[1]) == ["v_Cd", "ε(0/-1*)", 0.542, True, 1]
assert list(tl_df.iloc[2]) == ["Te_Cd", "None", np.inf, False, 0]
assert list(tl_df.iloc[3]) == ["Int_Te_3", "ε(+2/+1)", 0.035, True, 0]
assert list(tl_df.iloc[4]) == ["Int_Te_3", "ε(+2/+1*)", 0.09, True, 1]
Expand Down Expand Up @@ -943,8 +943,8 @@ def test_formation_energies_CdTe(self):
-1.499,
"N/A",
0,
0.738,
3.607,
0.739,
3.608,
f"{self.CdTe_EXAMPLE_DIR}/v_Cd_-2/vasp_ncl",
],
[
Expand Down Expand Up @@ -1279,8 +1279,8 @@ def _check_formation_energy_methods(form_en_df_row, thermo_obj, fermi_level):
-1.499,
-1.016,
-1.251,
0.738,
1.34,
0.739,
1.341,
f"{self.CdTe_EXAMPLE_DIR}/v_Cd_-2/vasp_ncl",
],
[
Expand Down Expand Up @@ -1394,8 +1394,8 @@ def _check_formation_energy_methods(form_en_df_row, thermo_obj, fermi_level):
-6,
-12,
-1,
0.738,
-13.895,
0.739,
-13.893,
]
assert list(manual_form_en_df.iloc[4])[:-1] == [
"Int_Te_3",
Expand Down

0 comments on commit eb0cb3f

Please sign in to comment.