Skip to content

Commit

Permalink
add occu_cutoff
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Feb 2, 2025
1 parent 598fea9 commit 3804849
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/pymatgen/io/vasp/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand All @@ -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."""
Expand Down
11 changes: 11 additions & 0 deletions tests/io/vasp/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3804849

Please sign in to comment.