Skip to content

Commit 18f1362

Browse files
improve quantum_numbers_to_angular_ket
1 parent 8f3421c commit 18f1362

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/rydstate/angular/angular_ket.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import contextlib
34
import logging
45
from abc import ABC
56
from typing import TYPE_CHECKING, Any, ClassVar, Literal, overload
@@ -773,15 +774,17 @@ def quantum_numbers_to_angular_ket(
773774
Optional, only needed for concrete angular matrix elements.
774775
775776
"""
776-
if all(qn is None for qn in [j_c, f_c, j_r]):
777+
with contextlib.suppress(InvalidQuantumNumbersError, ValueError):
777778
return AngularKetLS(
778779
s_c=s_c, l_c=l_c, s_r=s_r, l_r=l_r, s_tot=s_tot, l_tot=l_tot, j_tot=j_tot, f_tot=f_tot, m=m, species=species
779780
)
780-
if all(qn is None for qn in [s_tot, l_tot, f_c]):
781+
782+
with contextlib.suppress(InvalidQuantumNumbersError, ValueError):
781783
return AngularKetJJ(
782784
s_c=s_c, l_c=l_c, j_c=j_c, s_r=s_r, l_r=l_r, j_r=j_r, j_tot=j_tot, f_tot=f_tot, m=m, species=species
783785
)
784-
if all(qn is None for qn in [s_tot, l_tot, j_tot]):
786+
787+
with contextlib.suppress(InvalidQuantumNumbersError, ValueError):
785788
return AngularKetFJ(
786789
s_c=s_c, l_c=l_c, j_c=j_c, f_c=f_c, s_r=s_r, l_r=l_r, j_r=j_r, f_tot=f_tot, m=m, species=species
787790
)

tests/test_all_elements.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_magnetic(species_name: str) -> None:
1818
if species.number_valence_electrons == 1:
1919
state = RydbergStateSQDTAlkali(species, n=50, l=0, f=i_c + 0.5)
2020
state.radial.create_wavefunction()
21-
with pytest.raises(ValueError, match="j_tot must be set"):
21+
with pytest.raises(ValueError, match="Invalid combination of angular quantum numbers provided"):
2222
RydbergStateSQDTAlkali(species, n=50, l=1)
2323
elif species.number_valence_electrons == 2 and species._quantum_defects is not None: # noqa: SLF001
2424
for s_tot in [0, 1]:

0 commit comments

Comments
 (0)