Skip to content

Commit 8f3421c

Browse files
RydbergStateSQDT add from_angular_ket
1 parent 630917c commit 8f3421c

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

src/rydstate/rydberg/rydberg_base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414

1515
class RydbergStateBase(ABC):
16-
@property
17-
@abstractmethod
18-
def angular(self) -> AngularState[Any] | AngularKetBase: ...
16+
angular: AngularState[Any] | AngularKetBase
1917

2018
@abstractmethod
2119
def calc_reduced_overlap(self, other: RydbergStateBase) -> float: ...

src/rydstate/rydberg/rydberg_sqdt.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
class RydbergStateSQDT(RydbergStateBase):
2626
species: SpeciesObject
27+
"""The atomic species of the Rydberg state."""
28+
29+
angular: AngularKetBase
30+
"""The angular/spin part of the Rydberg electron."""
2731

2832
def __init__(
2933
self,
@@ -69,7 +73,8 @@ def __init__(
6973
species = SpeciesObject.from_name(species)
7074
self.species = species
7175

72-
self._qns = dict( # noqa: C408
76+
self.angular = quantum_numbers_to_angular_ket(
77+
species=self.species,
7378
s_c=s_c,
7479
l_c=l_c,
7580
j_c=j_c,
@@ -89,6 +94,30 @@ def __init__(
8994
if nu is None and n is None:
9095
raise ValueError("Either n or nu must be given to initialize the Rydberg state.")
9196

97+
@classmethod
98+
def from_angular_ket(
99+
cls,
100+
species: str | SpeciesObject,
101+
angular_ket: AngularKetBase,
102+
n: int | None = None,
103+
nu: float | None = None,
104+
) -> RydbergStateSQDT:
105+
"""Initialize the Rydberg state from an angular ket."""
106+
obj = cls.__new__(cls)
107+
108+
if isinstance(species, str):
109+
species = SpeciesObject.from_name(species)
110+
obj.species = species
111+
112+
obj.n = n
113+
obj._nu = nu # noqa: SLF001
114+
if nu is None and n is None:
115+
raise ValueError("Either n or nu must be given to initialize the Rydberg state.")
116+
117+
obj.angular = angular_ket
118+
119+
return obj
120+
92121
def __repr__(self) -> str:
93122
species, n, nu = self.species.name, self.n, self.nu
94123
n_str = f", {n=}" if n is not None else ""
@@ -100,6 +129,11 @@ def __str__(self) -> str:
100129
@cached_property
101130
def radial(self) -> RadialKet:
102131
"""The radial part of the Rydberg electron."""
132+
if "l_r" not in self.angular.quantum_number_names:
133+
raise ValueError(
134+
f"l_r must be defined in the angular ket to access the radial ket, but angular={self.angular}."
135+
)
136+
103137
radial_ket = RadialKet(self.species, nu=self.nu, l_r=self.angular.l_r)
104138
if self.n is not None:
105139
radial_ket.set_n_for_sanity_check(self.n)
@@ -112,11 +146,6 @@ def radial(self) -> RadialKet:
112146
)
113147
return radial_ket
114148

115-
@cached_property
116-
def angular(self) -> AngularKetBase:
117-
"""The angular/spin part of the Rydberg electron."""
118-
return quantum_numbers_to_angular_ket(species=self.species, **self._qns) # type: ignore [arg-type]
119-
120149
@cached_property
121150
def nu(self) -> float:
122151
"""The effective principal quantum number nu (for alkali atoms also known as n*) for the Rydberg state."""

0 commit comments

Comments
 (0)