From 3804849d11e6fbdb7d39500a72d3a8a29e0df936 Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Sun, 2 Feb 2025 10:01:04 +0100 Subject: [PATCH] add occu_cutoff --- src/pymatgen/io/vasp/inputs.py | 27 +++++++++++++++++++++++---- tests/io/vasp/test_inputs.py | 11 +++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/pymatgen/io/vasp/inputs.py b/src/pymatgen/io/vasp/inputs.py index e4f07494364..a4981661c67 100644 --- a/src/pymatgen/io/vasp/inputs.py +++ b/src/pymatgen/io/vasp/inputs.py @@ -2126,11 +2126,17 @@ def __repr__(self) -> str: TITEL, VRHFIN, n_valence_elec = (self.keywords.get(key) for key in ("TITEL", "VRHFIN", "ZVAL")) return f"{cls_name}({symbol=}, {functional=}, {TITEL=}, {VRHFIN=}, {n_valence_elec=:.0f})" - @property - def electron_configuration(self) -> list[tuple[int, str, float]]: + def get_electron_configuration( + self, + occu_cutoff: float = 0.01, + ) -> list[tuple[int, str, float]]: """Valence electronic configuration corresponding to the ZVAL, read from the "Atomic configuration" section of POTCAR. + Args: + occu_cutoff (float): Occupancy cutoff below which an orbital + would be considered empty. + Returns: list[tuple[int, str, float]]: A list of tuples containing: - n (int): Principal quantum number. @@ -2157,11 +2163,11 @@ def electron_configuration(self) -> list[tuple[int, str, float]]: total_electrons = 0.0 valence_config: list[tuple[int, str, float]] = [] - for line in lines[start_idx + 3 + num_entries - 1 : start_idx + 2 : -1]: + for line in lines[start_idx + 2 + num_entries : start_idx + 2 : -1]: parts = line.split() n, ang_moment, _j, _E, occ = int(parts[0]), int(parts[1]), float(parts[2]), float(parts[3]), float(parts[4]) - if occ >= 0.01: # TODO: hard-coded occupancy cutoff + if occ >= occu_cutoff: valence_config.append((n, l_map[ang_moment], occ)) total_electrons += occ @@ -2170,6 +2176,19 @@ def electron_configuration(self) -> list[tuple[int, str, float]]: return list(reversed(valence_config)) + @property + def electron_configuration(self) -> list[tuple[int, str, float]]: + """Valence electronic configuration corresponding to the ZVAL, + read from the "Atomic configuration" section of POTCAR. + + Returns: + list[tuple[int, str, float]]: A list of tuples containing: + - n (int): Principal quantum number. + - subshell (str): Subshell notation (s, p, d, f). + - occ (float): Occupation number, limited to ZVAL. + """ + return self.get_electron_configuration() + @property def element(self) -> str: """Attempt to return the atomic symbol based on the VRHFIN keyword.""" diff --git a/tests/io/vasp/test_inputs.py b/tests/io/vasp/test_inputs.py index edcfbda33e7..3d2ebb0587c 100644 --- a/tests/io/vasp/test_inputs.py +++ b/tests/io/vasp/test_inputs.py @@ -1462,6 +1462,17 @@ def assert_config_equal(actual_config, expected_config) -> None: ], ) + # Test occupancy cut-off (Be: 2s1.99 2p0.01) + assert_config_equal( + PotcarSingle.from_file(f"{FAKE_POTCAR_DIR}/POT_GGA_PAW_PBE_54/POTCAR.Be.gz").get_electron_configuration( + occu_cutoff=0.1 + ), + [ + (1, "s", 2.0), + (2, "s", 1.99), + ], + ) + def test_attributes(self): for key, val in self.Mn_pv_attrs.items(): assert getattr(self.psingle_Mn_pv, key) == val