Skip to content

Commit 4a0e9d2

Browse files
enhanced unknown element treatment
1 parent 3ba0b2d commit 4a0e9d2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

dpgen/generator/lib/cp2k.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def calculate_multiplicity(atom_names, atom_types, charge=0):
255255
It does not account for systems with multiple unpaired electrons, which can have higher
256256
multiplicities (e.g., triplet, quartet, etc.). Users should be aware of this limitation
257257
and use the function accordingly.
258-
258+
259259
:param atom_names: List of element symbols.
260260
:param atom_types: List of atom type indices.
261261
:param charge: System charge (default: 0).
@@ -265,7 +265,10 @@ def calculate_multiplicity(atom_names, atom_types, charge=0):
265265
total_electrons = 0
266266
for idx in atom_types:
267267
element = atom_names[idx]
268-
total_electrons += atomic_numbers.get(element, 0)
268+
try:
269+
total_electrons += atomic_numbers[element]
270+
except KeyError:
271+
raise ValueError(f"Unknown element '{element}' encountered in atom_names.")
269272

270273
# Subtract/add electrons based on system charge
271274
# Positive charge means we remove electrons, negative charge means we add electrons

0 commit comments

Comments
 (0)