1515from rydstate .units import BaseQuantities , MatrixElementOperatorRanks , ureg
1616
1717if TYPE_CHECKING :
18+ from typing_extensions import Self
19+
1820 from rydstate .angular .angular_ket import AngularKetBase , AngularKetFJ , AngularKetJJ , AngularKetLS
1921 from rydstate .units import MatrixElementOperator , PintFloat
2022
@@ -94,14 +96,19 @@ def __init__(
9496 if nu is None and n is None :
9597 raise ValueError ("Either n or nu must be given to initialize the Rydberg state." )
9698
99+ self ._set_qn_as_attributes ()
100+
101+ def _set_qn_as_attributes (self ) -> None :
102+ pass
103+
97104 @classmethod
98105 def from_angular_ket (
99- cls ,
106+ cls : type [ Self ] ,
100107 species : str | SpeciesObject ,
101108 angular_ket : AngularKetBase ,
102109 n : int | None = None ,
103110 nu : float | None = None ,
104- ) -> RydbergStateSQDT :
111+ ) -> Self :
105112 """Initialize the Rydberg state from an angular ket."""
106113 obj = cls .__new__ (cls )
107114
@@ -115,13 +122,14 @@ def from_angular_ket(
115122 raise ValueError ("Either n or nu must be given to initialize the Rydberg state." )
116123
117124 obj .angular = angular_ket
125+ obj ._set_qn_as_attributes () # noqa: SLF001
118126
119127 return obj
120128
121129 def __repr__ (self ) -> str :
122130 species , n , nu = self .species .name , self .n , self .nu
123131 n_str = f", { n = } " if n is not None else ""
124- return f"{ self .__class__ .__name__ } ({ species = } { n_str } , { nu = } , { self .angular } )"
132+ return f"{ self .__class__ .__name__ } ({ species } { n_str } , { nu = } , { self .angular } )"
125133
126134 def __str__ (self ) -> str :
127135 return self .__repr__ ()
@@ -151,13 +159,19 @@ def nu(self) -> float:
151159 """The effective principal quantum number nu (for alkali atoms also known as n*) for the Rydberg state."""
152160 if self ._nu is not None :
153161 return self ._nu
154- assert self .n is not None
155- if any (qn not in self .angular .quantum_number_names for qn in ["j_tot" , "s_tot" ]):
156- raise ValueError ("j_tot and s_tot must be defined to calculate nu from n." )
162+ assert isinstance (self .species , SpeciesObject ), "nu must be given if not sqdt"
163+ assert self .n is not None , "either nu or n must be given"
164+
165+ if "j_tot" not in self .angular .quantum_number_names or "s_tot" not in self .angular .quantum_number_names :
166+ raise RuntimeError ("j_tot and s_tot must be defined in the angular ket to calculate nu from n." )
157167 return self .species .calc_nu (
158168 self .n , self .angular .l_r , self .angular .get_qn ("j_tot" ), s_tot = self .angular .get_qn ("s_tot" )
159169 )
160170
171+ @property
172+ def nu_ref (self ) -> float :
173+ return self .nu
174+
161175 @overload
162176 def get_energy (self , unit : None = None ) -> PintFloat : ...
163177
@@ -342,15 +356,18 @@ def __init__(
342356 """
343357 super ().__init__ (species = species , n = n , nu = nu , l_r = l , j_tot = j , f_tot = f , m = m )
344358
345- self .l = l
359+ def _set_qn_as_attributes (self ) -> None :
360+ self .l = self .angular .l_r
346361 self .j = self .angular .j_tot
347362 self .f = self .angular .f_tot
348- self .m = m
363+ self .m = self . angular . m
349364
350365 def __repr__ (self ) -> str :
351- species , n , l , j , f , m = self .species , self .n , self .l , self .j , self .f , self .m
366+ species , n , nu = self .species .name , self .n , self .nu
367+ l , j , f , m = self .l , self .j , self .f , self .m
368+ n_str = f", { n = } " if n is not None else ""
352369 f_string = f", { f = } " if self .species .i_c not in (None , 0 ) else ""
353- return f"{ self .__class__ .__name__ } ({ species . name } , { n = } , { l = } , { j = } { f_string } , { m = } )"
370+ return f"{ self .__class__ .__name__ } ({ species } { n_str } , { nu = } , { l = } , { j = } { f_string } , { m = } )"
354371
355372
356373class RydbergStateSQDTAlkalineLS (RydbergStateSQDT ):
@@ -388,15 +405,18 @@ def __init__(
388405 """
389406 super ().__init__ (species = species , n = n , nu = nu , l_r = l , s_tot = s_tot , j_tot = j_tot , f_tot = f_tot , m = m )
390407
391- self .l = l
408+ def _set_qn_as_attributes (self ) -> None :
409+ self .l = self .angular .l_r
392410 self .s_tot = self .angular .s_tot
393411 self .j_tot = self .angular .j_tot
394412 self .f_tot = self .angular .f_tot
395- self .m = m
413+ self .m = self . angular . m
396414
397415 def __repr__ (self ) -> str :
398- species , n , l , s_tot , j_tot , f_tot , m = self .species , self .n , self .l , self .s_tot , self .j_tot , self .f_tot , self .m
399- return f"{ self .__class__ .__name__ } ({ species .name } , { n = } , { l = } , { s_tot = } , { j_tot = } , { f_tot = } , { m = } )"
416+ species , n , nu = self .species .name , self .n , self .nu
417+ l , s_tot , j_tot , f_tot , m = self .l , self .s_tot , self .j_tot , self .f_tot , self .m
418+ n_str = f", { n = } " if n is not None else ""
419+ return f"{ self .__class__ .__name__ } ({ species } { n_str } , { nu = } , { l = } , { s_tot = } , { j_tot = } , { f_tot = } , { m = } )"
400420
401421
402422class RydbergStateSQDTAlkalineJJ (RydbergStateSQDT ):
@@ -434,29 +454,18 @@ def __init__(
434454 """
435455 super ().__init__ (species = species , n = n , nu = nu , l_r = l , j_r = j_r , j_tot = j_tot , f_tot = f_tot , m = m )
436456
457+ def _set_qn_as_attributes (self ) -> None :
437458 self .l = self .angular .l_r
438459 self .j_r = self .angular .j_r
439460 self .j_tot = self .angular .j_tot
440461 self .f_tot = self .angular .f_tot
441462 self .m = self .angular .m
442463
443464 def __repr__ (self ) -> str :
444- species , n , l , j_r , j_tot , f_tot , m = self .species , self .n , self .l , self .j_r , self .j_tot , self .f_tot , self .m
445- return f"{ self .__class__ .__name__ } ({ species .name } , { n = } , { l = } , { j_r = } , { j_tot = } , { f_tot = } , { m = } )"
446-
447- @cached_property
448- def nu (self ) -> float :
449- if self ._nu is not None :
450- return self ._nu
451- assert self .n is not None
452- nus = [self .species .calc_nu (self .n , self .l , self .j_tot , s_tot = s_tot ) for s_tot in [0 , 1 ]]
453-
454- if any (abs (nu - nus [0 ]) > 1e-10 for nu in nus [1 :]):
455- raise ValueError (
456- "RydbergStateSQDTAlkalineJJ is intended for high-l states only, "
457- "where the quantum defects are the same for singlet and triplet states."
458- )
459- return nus [0 ]
465+ species , n , nu = self .species .name , self .n , self .nu
466+ l , j_r , j_tot , f_tot , m = self .l , self .j_r , self .j_tot , self .f_tot , self .m
467+ n_str = f", { n = } " if n is not None else ""
468+ return f"{ self .__class__ .__name__ } ({ species } { n_str } , { nu = } , { l = } , { j_r = } , { j_tot = } , { f_tot = } , { m = } )"
460469
461470
462471class RydbergStateSQDTAlkalineFJ (RydbergStateSQDT ):
@@ -494,30 +503,17 @@ def __init__(
494503 """
495504 super ().__init__ (species = species , n = n , nu = nu , l_r = l , j_r = j_r , f_c = f_c , f_tot = f_tot , m = m )
496505
506+ def _set_qn_as_attributes (self ) -> None :
497507 self .l = self .angular .l_r
498508 self .j_r = self .angular .j_r
499509 self .f_c = self .angular .f_c
500510 self .f_tot = self .angular .f_tot
501511 self .m = self .angular .m
502512
503513 def __repr__ (self ) -> str :
504- species , n , l , j_r , f_c , f_tot , m = self .species , self .n , self .l , self .j_r , self .f_c , self .f_tot , self .m
505- return f"{ self .__class__ .__name__ } ({ species .name } , { n = } , { l = } , { j_r = } , { f_c = } , { f_tot = } , { m = } )"
506-
507- @cached_property
508- def nu (self ) -> float :
509- if self ._nu is not None :
510- return self ._nu
511- assert self .n is not None
512- nus = [
513- self .species .calc_nu (self .n , self .l , float (j_tot ), s_tot = s_tot )
514- for s_tot in [0 , 1 ]
515- for j_tot in np .arange (abs (self .j_r - 1 / 2 ), self .j_r + 1 / 2 + 1 )
516- ]
517-
518- if any (abs (nu - nus [0 ]) > 1e-10 for nu in nus [1 :]):
519- raise ValueError (
520- "RydbergStateSQDTAlkalineFJ is intended for high-l states only, "
521- "where the quantum defects are the same for singlet and triplet states."
522- )
523- return nus [0 ]
514+ species , n , nu = self .species .name , self .n , self .nu
515+ l , j_r , f_c , f_tot , m = self .l , self .j_r , self .f_c , self .f_tot , self .m
516+ l_c , j_c = self .angular .l_c , self .angular .j_c
517+ core_string = f", { l_c = } , { j_c = } " if l_c != 0 else ""
518+ n_str = f", { n = } " if n is not None else ""
519+ return f"{ self .__class__ .__name__ } ({ species } { n_str } , { nu = } { core_string } , { l = } , { j_r = } , { f_c = } , { f_tot = } , { m = } )"
0 commit comments