From 504aa5921612261078809c150c65b1b7a76bcb0c Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Thu, 22 Aug 2024 19:21:19 +0900 Subject: [PATCH] Avoid using __contains__ for spglib dataset --- phonopy/interface/phonopy_yaml.py | 7 ++++--- phonopy/utils.py | 6 +----- test/conftest.py | 1 + 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/phonopy/interface/phonopy_yaml.py b/phonopy/interface/phonopy_yaml.py index 08819b865..04def8f2b 100644 --- a/phonopy/interface/phonopy_yaml.py +++ b/phonopy/interface/phonopy_yaml.py @@ -458,12 +458,13 @@ def _symmetry_yaml_lines(self): dataset = self._data.symmetry.dataset if dataset is not None: - if "uni_number" in dataset: + try: + uni_number = dataset.uni_number lines.append("magnetic_space_group:") - lines.append(f" uni_number: {dataset.uni_number}") + lines.append(f" uni_number: {uni_number}") lines.append(f" msg_type: {dataset.msg_type}") lines.append("") - else: + except AttributeError: lines.append("space_group:") spg_type = dataset.international lines.append(f' type: "{spg_type}"') diff --git a/phonopy/utils.py b/phonopy/utils.py index cd2b9560a..ab2537863 100644 --- a/phonopy/utils.py +++ b/phonopy/utils.py @@ -57,8 +57,4 @@ def get_dot_access_dataset(dataset): else: from types import SimpleNamespace - class MySimpleNamespace(SimpleNamespace): - def __contains__(self, key): - return key in self.__dict__ - - return MySimpleNamespace(**dataset) + return SimpleNamespace(**dataset) diff --git a/test/conftest.py b/test/conftest.py index 3091aee73..e529145a1 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -161,6 +161,7 @@ def ph_nacl_rd_symfc() -> Phonopy: """ pytest.importorskip("symfc") + pytest.importorskip("spglib", minversion="2.5") yaml_filename = cwd / "phonopy_params_NaCl-rd.yaml.xz" return phonopy.load(