Skip to content

Commit 27a4afe

Browse files
use SpeciesObjectSQDT where appropriate
1 parent 85324da commit 27a4afe

8 files changed

Lines changed: 50 additions & 45 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ This package relies on quantum defects provided by the community. Consider citin
8181

8282

8383
## Using custom quantum defects
84-
To use custom quantum defects (or quantum defects for a new species), you can simply create a subclass of `rydstate.species.species_object.SpeciesObject` (e.g. `class CustomRubidium(SpeciesObject):`) with a custom species name (e.g. `name = "Custom_Rb"`).
85-
Then, similarly to `rydstate.species.rubidium.py` you can define the quantum defects (and model potential parameters, ...) for your species.
86-
Finally, you can use the custom species by simply calling `rydstate.RydbergStateSQDTAlkali("Custom_Rb", n=50, l=0, j=1/2, m=1/2)` (the code will look for all subclasses of `SpeciesObject` until it finds one with the species name "Custom_Rb").
84+
To use custom quantum defects (or quantum defects for a new species), you can simply create a subclass of `rydstate.species.SpeciesObjectSQDT` (e.g. `class CustomRubidium(SpeciesObjectSQDT):`) with a custom species name (e.g. `name = "Custom_Rb"`).
85+
Then, similarly to `rydstate.species.sqdt.rubidium.py` you can define the quantum defects (and model potential parameters, ...) for your species.
86+
Finally, you can use the custom species by simply calling `rydstate.RydbergStateSQDTAlkali("Custom_Rb", n=50, l=0, j=1/2, m=1/2)` (the code will look for all subclasses of `SpeciesObjectSQDT` until it finds one with the species name "Custom_Rb").
8787

8888

8989
## License

docs/api_reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ All the available classes, methods and functions are documented below:
6161
.. autosummary::
6262
:toctree: _autosummary/
6363

64-
species.SpeciesObject
64+
species.SpeciesObjectSQDT
6565
species.HydrogenTextBook
6666
species.Hydrogen
6767
species.Lithium

src/rydstate/angular/angular_ket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ def __init__(
9090
"""
9191
if species is not None:
9292
if isinstance(species, str):
93-
from rydstate.species import SpeciesObject # noqa: PLC0415
93+
from rydstate.species import SpeciesObjectSQDT # noqa: PLC0415
9494

95-
species = SpeciesObject.from_name(species)
95+
species = SpeciesObjectSQDT.from_name(species)
9696
# use i_c = 0 for species without defined nuclear spin (-> ignore hyperfine)
9797
species_i_c = species.i_c if species.i_c is not None else 0
9898
if i_c is not None and i_c != species_i_c:

src/rydstate/basis/basis_sqdt.py

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

33
import logging
4-
from typing import TYPE_CHECKING
54

65
import numpy as np
76

@@ -12,16 +11,16 @@
1211
RydbergStateSQDTAlkalineJJ,
1312
RydbergStateSQDTAlkalineLS,
1413
)
15-
16-
if TYPE_CHECKING:
17-
from rydstate.species.species_object import SpeciesObject
14+
from rydstate.species import SpeciesObjectSQDT
1815

1916
logger = logging.getLogger(__name__)
2017

2118

2219
class BasisSQDTAlkali(BasisBase[RydbergStateSQDTAlkali]):
23-
def __init__(self, species: str | SpeciesObject, n_min: int = 1, n_max: int | None = None) -> None:
24-
super().__init__(species)
20+
def __init__(self, species: str | SpeciesObjectSQDT, n_min: int = 1, n_max: int | None = None) -> None:
21+
if isinstance(species, str):
22+
species = SpeciesObjectSQDT.from_name(species)
23+
self.species = species
2524

2625
if n_max is None:
2726
raise ValueError("n_max must be given")
@@ -41,8 +40,10 @@ def __init__(self, species: str | SpeciesObject, n_min: int = 1, n_max: int | No
4140

4241

4342
class BasisSQDTAlkalineLS(BasisBase[RydbergStateSQDTAlkalineLS]):
44-
def __init__(self, species: str | SpeciesObject, n_min: int = 1, n_max: int | None = None) -> None:
45-
super().__init__(species)
43+
def __init__(self, species: str | SpeciesObjectSQDT, n_min: int = 1, n_max: int | None = None) -> None:
44+
if isinstance(species, str):
45+
species = SpeciesObjectSQDT.from_name(species)
46+
self.species = species
4647

4748
if n_max is None:
4849
raise ValueError("n_max must be given")
@@ -64,8 +65,10 @@ def __init__(self, species: str | SpeciesObject, n_min: int = 1, n_max: int | No
6465

6566

6667
class BasisSQDTAlkalineJJ(BasisBase[RydbergStateSQDTAlkalineJJ]):
67-
def __init__(self, species: str | SpeciesObject, n_min: int = 0, n_max: int | None = None) -> None:
68-
super().__init__(species)
68+
def __init__(self, species: str | SpeciesObjectSQDT, n_min: int = 0, n_max: int | None = None) -> None:
69+
if isinstance(species, str):
70+
species = SpeciesObjectSQDT.from_name(species)
71+
self.species = species
6972

7073
if n_max is None:
7174
raise ValueError("n_max must be given")
@@ -94,8 +97,10 @@ def __init__(self, species: str | SpeciesObject, n_min: int = 0, n_max: int | No
9497

9598

9699
class BasisSQDTAlkalineFJ(BasisBase[RydbergStateSQDTAlkalineFJ]):
97-
def __init__(self, species: str | SpeciesObject, n_min: int = 0, n_max: int | None = None) -> None:
98-
super().__init__(species)
100+
def __init__(self, species: str | SpeciesObjectSQDT, n_min: int = 0, n_max: int | None = None) -> None:
101+
if isinstance(species, str):
102+
species = SpeciesObjectSQDT.from_name(species)
103+
self.species = species
99104

100105
if n_max is None:
101106
raise ValueError("n_max must be given")

src/rydstate/rydberg/rydberg_sqdt.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from rydstate.angular.utils import quantum_numbers_to_angular_ket
1111
from rydstate.radial import RadialKet
1212
from rydstate.rydberg.rydberg_base import RydbergStateBase
13-
from rydstate.species import SpeciesObject
13+
from rydstate.species import SpeciesObjectSQDT
1414
from rydstate.species.utils import calc_energy_from_nu
1515
from rydstate.units import BaseQuantities, MatrixElementOperatorRanks, ureg
1616

@@ -25,15 +25,15 @@
2525

2626

2727
class RydbergStateSQDT(RydbergStateBase):
28-
species: SpeciesObject
28+
species: SpeciesObjectSQDT
2929
"""The atomic species of the Rydberg state."""
3030

3131
angular: AngularKetBase
3232
"""The angular/spin part of the Rydberg electron."""
3333

3434
def __init__(
3535
self,
36-
species: str | SpeciesObject,
36+
species: str | SpeciesObjectSQDT,
3737
n: int | None = None,
3838
nu: float | None = None,
3939
s_c: float | None = None,
@@ -72,7 +72,7 @@ def __init__(
7272
7373
"""
7474
if isinstance(species, str):
75-
species = SpeciesObject.from_name(species)
75+
species = SpeciesObjectSQDT.from_name(species)
7676
self.species = species
7777

7878
self.angular = quantum_numbers_to_angular_ket(
@@ -104,7 +104,7 @@ def _set_qn_as_attributes(self) -> None:
104104
@classmethod
105105
def from_angular_ket(
106106
cls: type[Self],
107-
species: str | SpeciesObject,
107+
species: str | SpeciesObjectSQDT,
108108
angular_ket: AngularKetBase,
109109
n: int | None = None,
110110
nu: float | None = None,
@@ -113,7 +113,7 @@ def from_angular_ket(
113113
obj = cls.__new__(cls)
114114

115115
if isinstance(species, str):
116-
species = SpeciesObject.from_name(species)
116+
species = SpeciesObjectSQDT.from_name(species)
117117
obj.species = species
118118

119119
obj.n = n
@@ -145,21 +145,22 @@ def radial(self) -> RadialKet:
145145
radial_ket = RadialKet(self.species, nu=self.nu, l_r=self.angular.l_r)
146146
if self.n is not None:
147147
radial_ket.set_n_for_sanity_check(self.n)
148-
s_tot_list = [self.angular.get_qn("s_tot")] if "s_tot" in self.angular.quantum_number_names else [0, 1]
149-
for s_tot in s_tot_list:
150-
if not self.species.is_allowed_shell(self.n, self.angular.l_r, s_tot=s_tot):
151-
raise ValueError(
152-
f"The shell (n={self.n}, l_r={self.angular.l_r}, s_tot={s_tot}) "
153-
f"is not allowed for the species {self.species}."
154-
)
148+
if isinstance(self.species, SpeciesObjectSQDT):
149+
s_tot_list = [self.angular.get_qn("s_tot")] if "s_tot" in self.angular.quantum_number_names else [0, 1]
150+
for s_tot in s_tot_list:
151+
if not self.species.is_allowed_shell(self.n, self.angular.l_r, s_tot=s_tot):
152+
raise ValueError(
153+
f"The shell (n={self.n}, l_r={self.angular.l_r}, s_tot={s_tot}) "
154+
f"is not allowed for the species {self.species}."
155+
)
155156
return radial_ket
156157

157158
@cached_property
158159
def nu(self) -> float:
159160
"""The effective principal quantum number nu (for alkali atoms also known as n*) for the Rydberg state."""
160161
if self._nu is not None:
161162
return self._nu
162-
assert isinstance(self.species, SpeciesObject), "nu must be given if not sqdt"
163+
assert isinstance(self.species, SpeciesObjectSQDT), "nu must be given if not sqdt"
163164
assert self.n is not None, "either nu or n must be given"
164165
return self.species.calc_nu(self.n, self.angular)
165166

@@ -325,7 +326,7 @@ class RydbergStateSQDTAlkali(RydbergStateSQDT):
325326

326327
def __init__(
327328
self,
328-
species: str | SpeciesObject,
329+
species: str | SpeciesObjectSQDT,
329330
n: int,
330331
l: int,
331332
j: float | None = None,
@@ -372,7 +373,7 @@ class RydbergStateSQDTAlkalineLS(RydbergStateSQDT):
372373

373374
def __init__(
374375
self,
375-
species: str | SpeciesObject,
376+
species: str | SpeciesObjectSQDT,
376377
n: int,
377378
l: int,
378379
s_tot: int,
@@ -421,7 +422,7 @@ class RydbergStateSQDTAlkalineJJ(RydbergStateSQDT):
421422

422423
def __init__(
423424
self,
424-
species: str | SpeciesObject,
425+
species: str | SpeciesObjectSQDT,
425426
n: int,
426427
l: int,
427428
j_r: float,
@@ -470,7 +471,7 @@ class RydbergStateSQDTAlkalineFJ(RydbergStateSQDT):
470471

471472
def __init__(
472473
self,
473-
species: str | SpeciesObject,
474+
species: str | SpeciesObjectSQDT,
474475
n: int,
475476
l: int,
476477
j_r: float,

src/rydstate/species/species_object.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def from_name(cls: type[Self], name: str) -> Self:
7171
7272
This method searches through all subclasses of SpeciesObject until it finds one with a matching species name.
7373
This approach allows for easy extension of the library with new species.
74-
A user can even subclass SpeciesObject in his code (without modifying the rydstate library),
75-
e.g. `class CustomRubidium(SpeciesObject): name = "Custom_Rb" ...`
74+
A user can even subclass SpeciesObjectSQDT in his code (without modifying the rydstate library),
75+
e.g. `class CustomRubidium(SpeciesObjectSQDT): name = "Custom_Rb" ...`
7676
and then use the new species by calling RydbergStateSQDTAlkali("Custom_Rb", ...)
7777
7878
Args:

tests/test_all_elements.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
import pytest
44
from rydstate import RydbergStateSQDTAlkali, RydbergStateSQDTAlkalineLS
5-
from rydstate.species import SpeciesObject
5+
from rydstate.species import SpeciesObjectSQDT
66

77
if TYPE_CHECKING:
88
from rydstate import RydbergStateSQDT
99

1010

11-
@pytest.mark.parametrize("species_name", SpeciesObject.get_available_species())
12-
def test_magnetic(species_name: str) -> None:
13-
"""Test magnetic units."""
14-
species = SpeciesObject.from_name(species_name)
11+
@pytest.mark.parametrize("species_name", SpeciesObjectSQDT.get_available_species())
12+
def test_sqdt_species(species_name: str) -> None:
13+
species = SpeciesObjectSQDT.from_name(species_name)
1514
i_c = species.i_c if species.i_c is not None else 0
1615

1716
state: RydbergStateSQDT

tests/test_radial_matrix_element.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from rydstate import RydbergStateSQDTAlkali
44
from rydstate.angular import AngularKetLS
55
from rydstate.radial import RadialKet
6-
from rydstate.species import SpeciesObject
6+
from rydstate.species import SpeciesObjectSQDT
77

88

99
@pytest.mark.parametrize(
@@ -59,7 +59,7 @@ def test_circular_expectation_value(species_name: str, n: int, l: int, j_tot: fl
5959
<r>_{nl} = 1/2 (3 n^2 - l(l+1))
6060
<r^2>_{nl} = n^2/2 (5 n^2 - 3 l(l+1) + 1)
6161
"""
62-
species = SpeciesObject.from_name(species_name)
62+
species = SpeciesObjectSQDT.from_name(species_name)
6363
angular_ket = AngularKetLS(l_r=l, j_tot=j_tot, species=species)
6464
nu = species.calc_nu(n, angular_ket)
6565

0 commit comments

Comments
 (0)