Skip to content

Commit 3804849

Browse files
committed
add occu_cutoff
1 parent 598fea9 commit 3804849

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/pymatgen/io/vasp/inputs.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,11 +2126,17 @@ def __repr__(self) -> str:
21262126
TITEL, VRHFIN, n_valence_elec = (self.keywords.get(key) for key in ("TITEL", "VRHFIN", "ZVAL"))
21272127
return f"{cls_name}({symbol=}, {functional=}, {TITEL=}, {VRHFIN=}, {n_valence_elec=:.0f})"
21282128

2129-
@property
2130-
def electron_configuration(self) -> list[tuple[int, str, float]]:
2129+
def get_electron_configuration(
2130+
self,
2131+
occu_cutoff: float = 0.01,
2132+
) -> list[tuple[int, str, float]]:
21312133
"""Valence electronic configuration corresponding to the ZVAL,
21322134
read from the "Atomic configuration" section of POTCAR.
21332135
2136+
Args:
2137+
occu_cutoff (float): Occupancy cutoff below which an orbital
2138+
would be considered empty.
2139+
21342140
Returns:
21352141
list[tuple[int, str, float]]: A list of tuples containing:
21362142
- n (int): Principal quantum number.
@@ -2157,11 +2163,11 @@ def electron_configuration(self) -> list[tuple[int, str, float]]:
21572163

21582164
total_electrons = 0.0
21592165
valence_config: list[tuple[int, str, float]] = []
2160-
for line in lines[start_idx + 3 + num_entries - 1 : start_idx + 2 : -1]:
2166+
for line in lines[start_idx + 2 + num_entries : start_idx + 2 : -1]:
21612167
parts = line.split()
21622168
n, ang_moment, _j, _E, occ = int(parts[0]), int(parts[1]), float(parts[2]), float(parts[3]), float(parts[4])
21632169

2164-
if occ >= 0.01: # TODO: hard-coded occupancy cutoff
2170+
if occ >= occu_cutoff:
21652171
valence_config.append((n, l_map[ang_moment], occ))
21662172
total_electrons += occ
21672173

@@ -2170,6 +2176,19 @@ def electron_configuration(self) -> list[tuple[int, str, float]]:
21702176

21712177
return list(reversed(valence_config))
21722178

2179+
@property
2180+
def electron_configuration(self) -> list[tuple[int, str, float]]:
2181+
"""Valence electronic configuration corresponding to the ZVAL,
2182+
read from the "Atomic configuration" section of POTCAR.
2183+
2184+
Returns:
2185+
list[tuple[int, str, float]]: A list of tuples containing:
2186+
- n (int): Principal quantum number.
2187+
- subshell (str): Subshell notation (s, p, d, f).
2188+
- occ (float): Occupation number, limited to ZVAL.
2189+
"""
2190+
return self.get_electron_configuration()
2191+
21732192
@property
21742193
def element(self) -> str:
21752194
"""Attempt to return the atomic symbol based on the VRHFIN keyword."""

tests/io/vasp/test_inputs.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,17 @@ def assert_config_equal(actual_config, expected_config) -> None:
14621462
],
14631463
)
14641464

1465+
# Test occupancy cut-off (Be: 2s1.99 2p0.01)
1466+
assert_config_equal(
1467+
PotcarSingle.from_file(f"{FAKE_POTCAR_DIR}/POT_GGA_PAW_PBE_54/POTCAR.Be.gz").get_electron_configuration(
1468+
occu_cutoff=0.1
1469+
),
1470+
[
1471+
(1, "s", 2.0),
1472+
(2, "s", 1.99),
1473+
],
1474+
)
1475+
14651476
def test_attributes(self):
14661477
for key, val in self.Mn_pv_attrs.items():
14671478
assert getattr(self.psingle_Mn_pv, key) == val

0 commit comments

Comments
 (0)