Skip to content

Commit

Permalink
Format mis-matching INCAR tags warning for many defects
Browse files Browse the repository at this point in the history
  • Loading branch information
kavanase committed Nov 1, 2024
1 parent 3b01655 commit 5f6e0e0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
19 changes: 16 additions & 3 deletions doped/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,19 +1230,32 @@ def _call_multiple_corrections_tolerance_warning(correction_errors, type="FNV"):
# within the charge correction functions (with self._check_if_multiple_finite_size_corrections())

mismatching_INCAR_warnings = [
(name, defect_entry.calculation_metadata.get("mismatching_INCAR_tags"))
(name, set(defect_entry.calculation_metadata.get("mismatching_INCAR_tags")))
for name, defect_entry in self.defect_dict.items()
if defect_entry.calculation_metadata.get("mismatching_INCAR_tags", True) is not True
]
if mismatching_INCAR_warnings:
# group by the mismatching tags, so we can print them together:
mismatching_tags_name_list_dict = {
tuple(sorted(mismatching_set)): [
name
for name, other_mismatching_set in mismatching_INCAR_warnings
if other_mismatching_set == mismatching_set
]
for mismatching_set in [mismatching for name, mismatching in mismatching_INCAR_warnings]
}
joined_info_string = "\n".join(
[f"{name}: {mismatching}" for name, mismatching in mismatching_INCAR_warnings]
[
f"{defect_list}:\n{list(mismatching)}"
for mismatching, defect_list in mismatching_tags_name_list_dict.items()
]
)
warnings.warn(
f"There are mismatching INCAR tags for (some of) your bulk and defect calculations which "
f"are likely to cause errors in the parsed results (energies). Found the following "
f"differences:\n"
f"(in the format: (INCAR tag, value in bulk calculation, value in defect calculation)):"
f"(in the format: 'Defects: (INCAR tag, value in bulk calculation, value in defect "
f"calculation))':"
f"\n{joined_info_string}\n"
f"In general, the same INCAR settings should be used in all final calculations for these "
f"tags which can affect energies!"
Expand Down
25 changes: 16 additions & 9 deletions doped/utils/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,21 +802,28 @@ def check_atom_mapping_far_from_defect(
)[0]
]

bulk_species_outside_near_ws_coord_dict = {}
defect_species_outside_ws_coord_dict = {}
for species in bulk_supercell.composition.elements: # divide and vectorise calc for efficiency
bulk_species_outside_near_ws_coord_dict[species.name] = get_coords_and_idx_of_species(
bulk_species_outside_near_ws_coords = get_coords_and_idx_of_species(
bulk_sites_outside_or_at_ws_radius, species.name
)[0]
defect_species_outside_ws_coord_dict[species.name] = get_coords_and_idx_of_species(
defect_species_outside_ws_coords = get_coords_and_idx_of_species(
defect_sites_outside_wigner_radius, species.name
)[0]
vecs, d_2 = pbc_shortest_vectors(
bulk_supercell.lattice,
defect_species_outside_ws_coord_dict[species.name],
bulk_species_outside_near_ws_coord_dict[species.name],
return_d2=True,
if (
min(
len(bulk_species_outside_near_ws_coords),
len(defect_species_outside_ws_coords),
)
== 0
):
continue # if no sites of this species outside the WS radius, skip

subset, superset = ( # supa-set
(defect_species_outside_ws_coords, bulk_species_outside_near_ws_coords)
if len(defect_species_outside_ws_coords) < len(bulk_species_outside_near_ws_coords)
else (bulk_species_outside_near_ws_coords, defect_species_outside_ws_coords)
)
vecs, d_2 = pbc_shortest_vectors(bulk_supercell.lattice, subset, superset, return_d2=True)
site_matches = LinearAssignment(d_2).solution # matching superset indices, of len(subset)
matching_vecs = vecs[np.arange(len(site_matches)), site_matches]
displacements = np.linalg.norm(matching_vecs, axis=1)
Expand Down
15 changes: 5 additions & 10 deletions tests/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ def _check_default_CdTe_DefectsParser_outputs(
i in str(warn.message)
for i in [
"There are mismatching INCAR tags for (some of)",
"in the format: (INCAR tag, value in bulk calculation, value in defect",
"Int_Te_3_Unperturbed_1: [('ADDGRID', True, False)]",
"in the format: 'Defects: (INCAR tag, value in bulk calculation, value in defect",
"['Int_Te_3_Unperturbed_1']:\n[('ADDGRID', True, False)]",
"In general, the same INCAR settings should be used",
]
)
Expand Down Expand Up @@ -968,9 +968,7 @@ def test_SrTiO3_diff_ISYM_bulk_defect_and_concentration_funcs(self):
i in str(w[0].message)
for i in [
"There are mismatching INCAR tags",
"vac_O_0: [('LASPH', False, True)]",
"vac_O_1: [('LASPH', False, True)]",
"vac_O_2: [('LASPH', False, True)]",
"['vac_O_1', 'vac_O_0', 'vac_O_2']:\n[('LASPH', False, True)]",
]
)

Expand Down Expand Up @@ -1149,13 +1147,10 @@ def test_ZnS_non_diagonal_NKRED_mismatch(self):
i in str(w[0].message)
for i in [
"There are mismatching INCAR tags",
"vac_1_Zn_0: [('NKRED', 2, 1)]",
"vac_1_Zn_-2: [('NKRED', 2, 1)]",
"vac_2_S_2: [('NKRED', 2, 1)]",
"inter_29_Al_3: [('NKRED', 2, 1)]",
"sub_1_Al_on_Zn_-1: [('NKRED', 2, 1)]",
":\n[('NKRED', 2, 1)]\nIn",
]
)
assert str(w[0].message).count(":\n[('NKRED', 2, 1)]\nIn") == 1 # only once

assert len(dp.defect_dict) == 17
self._check_DefectsParser(dp)
Expand Down

0 comments on commit 5f6e0e0

Please sign in to comment.