Skip to content

Commit

Permalink
Avoid new spglib deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
kavanase committed Jun 10, 2024
1 parent a69c2b2 commit 6e1e35d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
7 changes: 3 additions & 4 deletions doped/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,16 @@ def _ignore_pmg_warnings():
warnings.filterwarnings("ignore", message="Use get_magnetic_symmetry()")
warnings.filterwarnings("ignore", message="Use of properties is now deprecated")

warnings.filterwarnings("ignore", message="get_vasp_input") # deprecation warning introduced
# in pymatgen>2024.1.6, fixed in our PR: https://github.com/materialsproject/pymatgen/pull/3601
# (now merged) -- delete later if pymatgen requirement is updated beyond this

# avoid warning about selective_dynamics properties (can happen if user explicitly set "T T T" (or
# otherwise) for the bulk):
warnings.filterwarnings("ignore", message="Not all sites have property")

# ignore warning about structure charge that appears when getting Vasprun.as_dict():
warnings.filterwarnings("ignore", message="Structure charge")

# SpglibDataset warning introduced in v2.4.1
warnings.filterwarnings("ignore", message="dict interface")


_ignore_pmg_warnings()

Expand Down
9 changes: 8 additions & 1 deletion doped/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

from easyunfold.procar import Procar as EasyunfoldProcar

# SpglibDataset warning introduced in v2.4.1, can be ignored for now
warnings.filterwarnings("ignore", message="dict interface")


_orientational_degeneracy_warning = (
"The defect supercell has been detected to possibly have a non-scalar matrix expansion, "
"which could be breaking the cell periodicity and possibly preventing the correct _relaxed_ "
Expand Down Expand Up @@ -1364,7 +1368,10 @@ def _guess_and_set_struct_oxi_states(structure):
if oxidation states could not be guessed.
"""
bv_analyzer = BVAnalyzer()
with contextlib.suppress(ValueError): # ValueError raised if oxi states can't be assigned
with contextlib.suppress(ValueError), warnings.catch_warnings():
# ValueError raised if oxi states can't be assigned, and SpglibDataset warning introduced in
# v2.4.1, can be ignored for now:
warnings.filterwarnings("ignore", message="dict interface")
oxi_dec_structure = bv_analyzer.get_oxi_state_decorated_structure(structure)
if all(
np.isclose(int(specie.oxi_state), specie.oxi_state) for specie in oxi_dec_structure.species
Expand Down
2 changes: 2 additions & 0 deletions doped/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,8 @@ class (such as ``clustering_tol``, ``stol``, ``min_dist`` etc), or to
``DefectsGenerator`` input parameters are also set as attributes.
"""
# SpglibDataset warning introduced in v2.4.1, can later remove when pymatgen updated to avoid this:
warnings.filterwarnings("ignore", message="dict interface")
self.defects: dict[str, list[Defect]] = {} # {defect_type: [Defect, ...]}
self.defect_entries: dict[str, DefectEntry] = {} # {defect_species: DefectEntry}
self.structure = structure
Expand Down
22 changes: 10 additions & 12 deletions doped/utils/symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ def get_wyckoff(frac_coords, struct, symm_ops: Optional[list] = None, equiv_site
symm_dataset, unique_sites = _get_symm_dataset_of_struc_with_all_equiv_sites(
frac_coords, struct, symm_ops, symprec=symprec
)
conv_cell_factor = len(symm_dataset["std_positions"]) / len(symm_dataset["wyckoffs"])
conv_cell_factor = len(symm_dataset.std_positions) / len(symm_dataset.wyckoffs)
multiplicity = int(conv_cell_factor * len(unique_sites))
wyckoff_label = f"{multiplicity}{symm_dataset['wyckoffs'][-1]}"
wyckoff_label = f"{multiplicity}{symm_dataset.wyckoffs[-1]}"

return (wyckoff_label, unique_sites) if equiv_sites else wyckoff_label

Expand Down Expand Up @@ -1086,7 +1086,7 @@ def point_symmetry_from_defect(defect, symm_ops=None, symprec=0.01):
symm_dataset, _unique_sites = _get_symm_dataset_of_struc_with_all_equiv_sites(
defect.site.frac_coords, defect.structure, symm_ops=symm_ops, symprec=symprec
)
spglib_point_group_symbol = schoenflies_from_hermann(symm_dataset["site_symmetry_symbols"][-1])
spglib_point_group_symbol = schoenflies_from_hermann(symm_dataset.site_symmetry_symbols[-1])
if spglib_point_group_symbol is not None:
return spglib_point_group_symbol

Expand Down Expand Up @@ -1200,7 +1200,7 @@ def point_symmetry_from_defect_entry(
# then easy, can just be taken from symmetry dataset of defect structure
symm_dataset = _get_sga(defect_entry.defect.structure, symprec=symprec).get_symmetry_dataset()
return schoenflies_from_hermann(
symm_dataset["site_symmetry_symbols"][defect_entry.defect.defect_site_index]
symm_dataset.site_symmetry_symbols[defect_entry.defect.defect_site_index]
)

supercell = _get_defect_supercell(defect_entry) if relaxed else _get_bulk_supercell(defect_entry)
Expand Down Expand Up @@ -1304,15 +1304,15 @@ def point_symmetry_from_defect_entry(
# This issue is avoided for relaxed defect supercells as we take the symm_ops of our reduced
# symmetry cell rather than that of the bulk (so no chance of spurious symmetry upgrade from
# equivalent sites), and hence the max point symmetry is the point symmetry of the defect
spglib_point_group_symbol = schoenflies_from_hermann(symm_dataset["site_symmetry_symbols"][-1])
spglib_point_group_symbol = schoenflies_from_hermann(symm_dataset.site_symmetry_symbols[-1])

# Note that, if the supercell is non-periodicity-breaking, then the site symmetry can be simply
# determined using the point group of the unrelaxed defect structure:
# unrelaxed_defect_supercell = defect_entry.calculation_metadata.get(
# "unrelaxed_defect_structure", defect_supercell
# )
# return schoenflies_from_hermann(
# _get_sga(unrelaxed_defect_supercell, symprec).get_symmetry_dataset()["pointgroup"],
# _get_sga(unrelaxed_defect_supercell, symprec).get_symmetry_dataset().pointgroup,
# )
# But current approach works for all cases with unrelaxed defect structures

Expand All @@ -1321,15 +1321,15 @@ def point_symmetry_from_defect_entry(
# the defect (e.g. for split-interstitials, split-vacancies, swapped vacancies etc),
# so use 'pointgroup' output (in this case the reduced symmetry avoids the symmetry-upgrade
# possibility with the equivalent sites, as when relaxed=False)
spglib_point_group_symbol = schoenflies_from_hermann(symm_dataset["pointgroup"])
spglib_point_group_symbol = schoenflies_from_hermann(symm_dataset.pointgroup)

# This also works (at least for non-periodicity-breaking supercells) for relaxed defects in
# most cases, but is slightly less robust (more sensitive to ``symprec`` choice) than the
# approach above:
# schoenflies_from_hermann(
# _get_sga(
# defect_supercell, symprec=symprec
# ).get_symmetry_dataset()["pointgroup"]
# ).get_symmetry_dataset().pointgroup
# )

if spglib_point_group_symbol is not None:
Expand Down Expand Up @@ -1376,7 +1376,7 @@ def _check_relaxed_defect_symmetry_determination(

if unrelaxed_defect_structure is not None:
unrelaxed_spglib_point_group_symbol = schoenflies_from_hermann(
_get_sga(unrelaxed_defect_structure, symprec=symprec).get_symmetry_dataset()["pointgroup"],
_get_sga(unrelaxed_defect_structure, symprec=symprec).get_symmetry_dataset().pointgroup,
)

bulk_supercell = _get_bulk_supercell(defect_entry)
Expand All @@ -1388,9 +1388,7 @@ def _check_relaxed_defect_symmetry_determination(
symprec=symprec,
dist_tol=symprec,
)
bulk_spglib_point_group_symbol = schoenflies_from_hermann(
symm_dataset["site_symmetry_symbols"][-1]
)
bulk_spglib_point_group_symbol = schoenflies_from_hermann(symm_dataset.site_symmetry_symbols[-1])

if bulk_spglib_point_group_symbol != unrelaxed_spglib_point_group_symbol:
if verbose:
Expand Down

0 comments on commit 6e1e35d

Please sign in to comment.