Skip to content

Commit 3147987

Browse files
various small improvements
1 parent d4d0f27 commit 3147987

File tree

5 files changed

+30
-29
lines changed

5 files changed

+30
-29
lines changed

src/rydstate/angular/angular_ket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def __str__(self) -> str:
159159

160160
def __eq__(self, other: object) -> bool:
161161
if not isinstance(other, AngularKetBase):
162-
raise NotImplementedError(f"Cannot compare {self!r} with {other!r}.")
162+
return NotImplemented
163163
if type(self) is not type(other):
164164
return False
165165
if self.m != other.m:

src/rydstate/basis/basis_sqdt.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,14 @@ def __init__(
9797
_s_r = 0.5
9898
for _n in range(n[0], n[1] + 1):
9999
for _l_r in range(_n):
100-
if self.species.is_allowed_shell(_n, _l_r, 0) != self.species.is_allowed_shell(_n, _l_r, 1):
101-
logger.warning(
102-
"For l=%d, n=%d one of the singlet/triplet states is not allowed. "
103-
"In JJ coupling the state does not exist, thus skipping this shell",
104-
*(_l_r, _n),
105-
)
106-
if not all(self.species.is_allowed_shell(_n, _l_r, s_tot) for s_tot in [0, 1]):
100+
allowed = [self.species.is_allowed_shell(_n, _l_r, s) for s in [0, 1]]
101+
if not all(allowed):
102+
if any(allowed):
103+
logger.warning(
104+
"For l=%d, n=%d one of the singlet/triplet states is not allowed. "
105+
"In JJ coupling the state does not exist, thus skipping this shell",
106+
*(_l_r, _n),
107+
)
107108
continue
108109
for _j_r in np.arange(abs(_l_r - _s_r), _l_r + _s_r + 1):
109110
for _j_tot in range(int(abs(_j_r - _j_c)), int(_j_r + _j_c + 1)):
@@ -130,13 +131,14 @@ def __init__(
130131
_s_r = 0.5
131132
for _n in range(n[0], n[1] + 1):
132133
for _l_r in range(_n):
133-
if self.species.is_allowed_shell(_n, _l_r, 0) != self.species.is_allowed_shell(_n, _l_r, 1):
134-
logger.warning(
135-
"For l=%d, n=%d one of the singlet/triplet states is not allowed. "
136-
"In FJ coupling the state does not exist, thus skipping this shell",
137-
*(_l_r, _n),
138-
)
139-
if not all(self.species.is_allowed_shell(_n, _l_r, s_tot) for s_tot in [0, 1]):
134+
allowed = [self.species.is_allowed_shell(_n, _l_r, s) for s in [0, 1]]
135+
if not all(allowed):
136+
if any(allowed):
137+
logger.warning(
138+
"For l=%d, n=%d one of the singlet/triplet states is not allowed. "
139+
"In FJ coupling the state does not exist, thus skipping this shell",
140+
*(_l_r, _n),
141+
)
140142
continue
141143
for _j_r in np.arange(abs(_l_r - _s_r), _l_r + _s_r + 1):
142144
for _f_c in np.arange(abs(_j_c - i_c), _j_c + i_c + 1):

src/rydstate/rydberg/rydberg_sqdt.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ def _get_transition_rates_au(
413413
\Gamma^{spontaneous}_{self \to other} = \frac{4}{3} \frac{\alpha}{c^2} \omega^3
414414
|\langle self || r^k_radial \hat{O}_{k_angular} || other \rangle|^2
415415
416+
where :math:`\alpha = 1/c` in atomic units.
417+
416418
and
417419
418420
.. math::
@@ -443,27 +445,25 @@ def _get_transition_rates_au(
443445
)
444446
electric_dipole_moments_au = np.zeros(len(relevant_states))
445447
for q in [-1, 0, 1]:
446-
# the different entries are only at most once nonzero -> we can just add the arrays
447448
el_di_m = np.array(
448449
[s.calc_matrix_element(self, "electric_dipole", q, unit="a.u.") for s in relevant_states]
449450
)
450-
electric_dipole_moments_au += el_di_m
451+
electric_dipole_moments_au += np.abs(el_di_m) ** 2
451452

452453
transition_rates_au = (
453-
(4 / 3)
454-
* np.abs(electric_dipole_moments_au) ** 2
455-
* energy_differences_au**2
456-
/ ureg.Quantity(1, "speed_of_light").to_base_units().magnitude ** 3
454+
(4 / 3) * electric_dipole_moments_au / ureg.Quantity(1, "speed_of_light").to_base_units().magnitude ** 3
457455
)
458456

459457
if only_spontaneous:
460-
transition_rates_au *= energy_differences_au
458+
transition_rates_au *= energy_differences_au**3
461459
else:
462460
assert temperature_au is not None, "Temperature must be given for black body transitions."
463461
if temperature_au == 0:
464462
transition_rates_au *= 0
465463
else: # for numerical stability we use 1 / exprel(x) = x / (exp(x) - 1)
466-
transition_rates_au *= temperature_au / exprel(energy_differences_au / temperature_au)
464+
transition_rates_au *= (
465+
energy_differences_au**2 * temperature_au / exprel(energy_differences_au / temperature_au)
466+
)
467467

468468
mask = transition_rates_au != 0
469469
relevant_states_masked = [ket for ket, is_relevant in zip(relevant_states, mask, strict=True) if is_relevant]

src/rydstate/species/sqdt/species_object_sqdt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ def get_ionization_energy(self, unit: None = None) -> PintFloat: ...
164164
@overload
165165
def get_ionization_energy(self, unit: str) -> float: ...
166166

167-
def get_ionization_energy(self, unit: str | None = "hartree") -> PintFloat | float:
167+
def get_ionization_energy(self, unit: str | None = None) -> PintFloat | float:
168168
"""Return the ionization energy in the desired unit.
169169
170170
Args:
171-
unit: Desired unit for the ionization energy. Default is atomic units "hartree".
171+
unit: Desired unit for the ionization energy. Default is None (returns a Pint quantity).
172172
173173
Returns:
174174
Ionization energy in the desired unit.

tests/test_lifetimes.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import numpy as np
22
import pytest
3-
from rydstate import RydbergStateSQDTAlkali
4-
from rydstate.angular.angular_ket import AngularKetLS
5-
from rydstate.rydberg.rydberg_sqdt import RydbergStateSQDT
6-
from rydstate.species.sqdt.species_object_sqdt import SpeciesObjectSQDT
3+
from rydstate import RydbergStateSQDT, RydbergStateSQDTAlkali
4+
from rydstate.angular import AngularKetLS
5+
from rydstate.species import SpeciesObjectSQDT
76

87

98
# Reference values from NIST Atomic Spectra Database (ASD), Einstein A coefficients:

0 commit comments

Comments
 (0)