Skip to content

Commit f6480b7

Browse files
authored
add AtomsState.partial_charge for atom-centered fractional charges (#335)
* add AtomsState.partial_charge * add test docstring
1 parent 02a31ab commit f6480b7

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/nomad_simulations/schema_packages/atoms_state.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,16 @@ class AtomsState(ParticleState):
11141114
""",
11151115
)
11161116

1117+
partial_charge = Quantity(
1118+
type=np.float64,
1119+
unit='elementary_charge',
1120+
description="""
1121+
Atom-centered partial charge used in force fields or population analyses
1122+
(e.g., Mulliken, Hirshfeld, CM5, NPA, RESP). This quantity is distinct from
1123+
the formal integer oxidation-like `charge`.
1124+
""",
1125+
)
1126+
11171127
spin = Quantity(
11181128
type=np.int32,
11191129
default=0,

tests/test_atoms_state.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,25 @@ def test_atomic_number_to_symbol(self, atomic_number: int, chemical_symbol: str)
487487
atom_state.normalize(EntryArchive(), logger)
488488
assert atom_state.chemical_symbol == chemical_symbol
489489

490+
def test_partial_charge_is_independent_of_formal_charge(self):
491+
"""
492+
Test that `partial_charge` is preserved independently from the formal
493+
integer `charge` after normalization.
494+
"""
495+
atom_state = AtomsState(
496+
chemical_symbol='O',
497+
charge=-1,
498+
partial_charge=-0.42 * ureg.elementary_charge,
499+
)
500+
atom_state.normalize(EntryArchive(), logger)
501+
502+
assert atom_state.charge == -1
503+
assert atom_state.partial_charge is not None
504+
assert (
505+
pytest.approx(atom_state.partial_charge.to('elementary_charge').magnitude)
506+
== -0.42
507+
)
508+
490509

491510
class TestCGBeadState:
492511
"""

0 commit comments

Comments
 (0)