Skip to content

Commit 13c2e22

Browse files
committed
- Deactivate automated kappa and j derivations, as it may give the wrong impressions.
-- Retain conversion capabilities -- Add TODO for future integration - Update tests to stop using quantum symbols Changes to be committed: modified: src/nomad_simulations/schema_packages/atoms_state.py modified: tests/test_model_method.py
1 parent bdbee91 commit 13c2e22

File tree

2 files changed

+47
-40
lines changed

2 files changed

+47
-40
lines changed

src/nomad_simulations/schema_packages/atoms_state.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ def compute_l_from_kappa(self, kappa: int) -> int:
240240
if kappa == 0:
241241
raise ValueError('κ = 0 is unphysical')
242242
if kappa < 0:
243-
return abs(kappa) - 1 # l = |κ| - 1 for κ < 0
243+
return abs(kappa) - 1
244244
else:
245-
return kappa # l = κ for κ > 0
245+
return kappa
246246

247247
def validate_kappa_j_relationship(self, logger: 'BoundLogger') -> bool:
248248
"""
@@ -253,10 +253,8 @@ def validate_kappa_j_relationship(self, logger: 'BoundLogger') -> bool:
253253
"""
254254
if self.kappa_quantum_number is not None and self.j_quantum_number is not None:
255255
try:
256-
# Use factored computation for validation
257256
expected_j = self.compute_j_from_kappa(self.kappa_quantum_number)
258257

259-
# Check if j value matches expected
260258
if abs(self.j_quantum_number - expected_j) >= 1e-10:
261259
logger.error(
262260
f'Inconsistent κ={self.kappa_quantum_number} and j={self.j_quantum_number}. '
@@ -268,20 +266,6 @@ def validate_kappa_j_relationship(self, logger: 'BoundLogger') -> bool:
268266
return False
269267
return True
270268

271-
def normalize_kappa_j_consistency(self):
272-
"""
273-
Ensure κ and j are consistent during normalization using factored computation.
274-
Populates missing values when possible.
275-
"""
276-
if self.kappa_quantum_number is not None and self.j_quantum_number is None:
277-
# Compute j from κ
278-
self.j_quantum_number = self.compute_j_from_kappa(self.kappa_quantum_number)
279-
280-
elif self.j_quantum_number is not None and self.kappa_quantum_number is None:
281-
# Cannot uniquely determine κ from j alone (need l as well)
282-
# This would need orbital information
283-
pass
284-
285269
@log
286270
def validate_quantum_numbers(self) -> bool:
287271
"""
@@ -458,14 +442,37 @@ def _jj_coupling(self, electron_data: list[dict]) -> list[float]:
458442
# Remove duplicates and sort
459443
return sorted(list(set(all_j_combinations)))
460444

445+
@log
446+
def normalize_kappa_j_consistency(self) -> None:
447+
"""
448+
Populate j and l quantum numbers from κ (kappa) when κ is defined but j/l are not.
449+
450+
This method is NOT called during normalization to avoid baking in physics assumptions
451+
about relativistic coupling and the underlying Hamiltonian. It is retained for
452+
higher-level search/matching operations where users can explicitly request conversion
453+
between relativistic (κ) and non-relativistic (j, l) quantum number representations.
454+
"""
455+
#TODO: Implement search/matching functionality at GUI or query level that allows users
456+
# to explicitly convert between κ and (j, l) representations when searching for or
457+
# comparing quantum states. This should be a user-driven operation, not an automatic
458+
# schema-level conversion.
459+
460+
if self.kappa_quantum_number is not None:
461+
if self.j_quantum_number is None:
462+
self.j_quantum_number = self.compute_j_from_kappa(
463+
self.kappa_quantum_number
464+
)
465+
if self.l_quantum_number is None:
466+
self.l_quantum_number = self.compute_l_from_kappa(
467+
self.kappa_quantum_number
468+
)
469+
461470
def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
462471
super().normalize(archive, logger)
463472

464473
if not self.validate_kappa_j_relationship(logger):
465474
return None
466475

467-
self.normalize_kappa_j_consistency()
468-
469476
if not self.validate_quantum_numbers(logger=logger):
470477
return None
471478

tests/test_model_method.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -322,19 +322,19 @@ class TestSlaterKosterBond:
322322
"""
323323

324324
@pytest.mark.parametrize(
325-
'orb1_symbol, orb2_symbol, bravais_vector, expected_name',
325+
'orb1_l_number, orb2_l_number, bravais_vector, expected_name',
326326
[
327327
(None, None, None, None),
328-
('s', None, None, None),
329-
(None, 'p', None, None),
330-
('s', 's', (0, 0, 0), 'sss'),
331-
('s', 'p', (0, 0, 0), 'sps'),
328+
(0, None, None, None),
329+
(None, 1, None, None),
330+
(0, 0, (0, 0, 0), 'sss'),
331+
(0, 1, (0, 0, 0), 'sps'),
332332
],
333333
)
334334
def test_resolve_bond_name_from_references(
335335
self,
336-
orb1_symbol: str | None,
337-
orb2_symbol: str | None,
336+
orb1_l_number: int | None,
337+
orb2_l_number: int | None,
338338
bravais_vector: tuple | None,
339339
expected_name: str | None,
340340
):
@@ -344,13 +344,13 @@ def test_resolve_bond_name_from_references(
344344
sk_bond = SlaterKosterBond()
345345
# If there's an orbit1 or orbit2, build them
346346
orbit1 = None
347-
if orb1_symbol:
348-
spherical_state = SphericalSymmetryState(l_quantum_symbol=orb1_symbol)
347+
if orb1_l_number is not None:
348+
spherical_state = SphericalSymmetryState(l_quantum_number=orb1_l_number)
349349
orbit1 = ElectronicState(spin_orbit_state=spherical_state)
350350

351351
orbit2 = None
352-
if orb2_symbol:
353-
spherical_state = SphericalSymmetryState(l_quantum_symbol=orb2_symbol)
352+
if orb2_l_number is not None:
353+
spherical_state = SphericalSymmetryState(l_quantum_number=orb2_l_number)
354354
orbit2 = ElectronicState(spin_orbit_state=spherical_state)
355355

356356
name = sk_bond.resolve_bond_name_from_references(
@@ -362,17 +362,17 @@ def test_resolve_bond_name_from_references(
362362
assert name == expected_name
363363

364364
@pytest.mark.parametrize(
365-
'orb1_symbol, orb2_symbol, bravais_vector, expected',
365+
'orb1_l_number, orb2_l_number, bravais_vector, expected',
366366
[
367367
(None, None, None, None),
368-
('s', None, None, None),
369-
('s', 'p', (0, 0, 0), 'sps'),
368+
(0, None, None, None),
369+
(0, 1, (0, 0, 0), 'sps'),
370370
],
371371
)
372372
def test_normalize(
373373
self,
374-
orb1_symbol: str | None,
375-
orb2_symbol: str | None,
374+
orb1_l_number: int | None,
375+
orb2_l_number: int | None,
376376
bravais_vector: tuple | None,
377377
expected: str | None,
378378
):
@@ -382,13 +382,13 @@ def test_normalize(
382382
# Prepare a model scenario
383383
bond = SlaterKosterBond()
384384
orbitals = []
385-
if orb1_symbol:
386-
spherical_state = SphericalSymmetryState(l_quantum_symbol=orb1_symbol)
385+
if orb1_l_number is not None:
386+
spherical_state = SphericalSymmetryState(l_quantum_number=orb1_l_number)
387387
electronic_state = ElectronicState(spin_orbit_state=spherical_state)
388388
orbitals.append(electronic_state)
389389
bond.orbital_1 = orbitals[-1]
390-
if orb2_symbol:
391-
spherical_state = SphericalSymmetryState(l_quantum_symbol=orb2_symbol)
390+
if orb2_l_number is not None:
391+
spherical_state = SphericalSymmetryState(l_quantum_number=orb2_l_number)
392392
electronic_state = ElectronicState(spin_orbit_state=spherical_state)
393393
orbitals.append(electronic_state)
394394
bond.orbital_2 = orbitals[-1]

0 commit comments

Comments
 (0)