1+ from __future__ import annotations
2+
13import inspect
24import logging
35import re
46from abc import ABC
57from fractions import Fraction
68from functools import cache , cached_property
7- from pathlib import Path
8- from typing import TYPE_CHECKING , ClassVar , Optional , Union , overload
9+ from typing import TYPE_CHECKING , ClassVar , overload
910
1011import numpy as np
1112
1213from ryd_numerov .units import rydberg_constant , ureg
1314
1415if TYPE_CHECKING :
16+ from pathlib import Path
17+
1518 from ryd_numerov .model .model import PotentialType
1619 from ryd_numerov .units import PintFloat
1720
@@ -39,21 +42,19 @@ class BaseElement(ABC):
3942
4043 _core_electron_configuration : ClassVar [str ]
4144 """Electron configuration of the core electrons, e.g. 4p6 for Rb or 5s for Sr."""
42- _ionization_energy : tuple [float , Optional [ float ] , str ]
45+ _ionization_energy : tuple [float , float | None , str ]
4346 """Ionization energy with uncertainty and unit: (value, uncertainty, unit)."""
4447
4548 # Parameters for the extended Rydberg Ritz formula, see calc_n_star
46- _quantum_defects : ClassVar [Optional [dict [tuple [int , float , float ], tuple [float , float , float , float , float ]]]] = (
47- None
48- )
49+ _quantum_defects : ClassVar [dict [tuple [int , float , float ], tuple [float , float , float , float , float ]] | None ] = None
4950 """Dictionary containing the quantum defects for each (l, j_tot, s_tot) combination, i.e.
5051 _quantum_defects[(l,j_tot,s_tot)] = (d0, d2, d4, d6, d8)
5152 """
5253
53- _corrected_rydberg_constant : tuple [float , Optional [ float ] , str ]
54+ _corrected_rydberg_constant : tuple [float , float | None , str ]
5455 r"""Corrected Rydberg constant stored as (value, uncertainty, unit)"""
5556
56- potential_type_default : Optional [ " PotentialType" ] = None
57+ potential_type_default : PotentialType | None = None
5758 """Default potential type to use for this element. If None, the potential type must be specified explicitly.
5859 In general, it looks like marinescu_1993 is better for alkali atoms, and fei_2009 is better for alkaline earth atoms
5960 """
@@ -78,7 +79,7 @@ class BaseElement(ABC):
7879 defined in: Y. Fei et al., Chin. Phys. B 18, 4349 (2009), https://iopscience.iop.org/article/10.1088/1674-1056/18/10/025
7980 """
8081
81- _nist_energy_levels_file : Optional [ Path ] = None
82+ _nist_energy_levels_file : Path | None = None
8283 """Path to the NIST energy levels file for this element.
8384 The file should be directly downloaded from https://physics.nist.gov/PhysRefData/ASD/levels_form.html
8485 in the 'Tab-delimited' format and in units of Hartree.
@@ -170,7 +171,7 @@ def _setup_nist_energy_levels(self, file: Path) -> None: # noqa: C901, PLR0912
170171
171172 @classmethod
172173 @cache
173- def from_species (cls , species : str , use_nist_data : bool = True ) -> " BaseElement" :
174+ def from_species (cls , species : str , use_nist_data : bool = True ) -> BaseElement :
174175 """Create an instance of the element class from the species string.
175176
176177 This method searches through all subclasses of BaseElement until it finds one with a matching species attribute.
@@ -196,7 +197,7 @@ def from_species(cls, species: str, use_nist_data: bool = True) -> "BaseElement"
196197 )
197198
198199 @classmethod
199- def _get_concrete_subclasses (cls ) -> list [type [" BaseElement" ]]:
200+ def _get_concrete_subclasses (cls ) -> list [type [BaseElement ]]:
200201 subclasses = []
201202 for subclass in cls .__subclasses__ ():
202203 if not inspect .isabstract (subclass ) and hasattr (subclass , "species" ):
@@ -239,12 +240,12 @@ def is_allowed_shell(self, n: int, l: int, s_tot: float) -> bool:
239240 return (n , l ) in self ._additional_allowed_shells
240241
241242 @overload
242- def get_ionization_energy (self , unit : None = None ) -> " PintFloat" : ...
243+ def get_ionization_energy (self , unit : None = None ) -> PintFloat : ...
243244
244245 @overload
245246 def get_ionization_energy (self , unit : str ) -> float : ...
246247
247- def get_ionization_energy (self , unit : Optional [ str ] = "hartree" ) -> Union [ " PintFloat" , float ] :
248+ def get_ionization_energy (self , unit : str | None = "hartree" ) -> PintFloat | float :
248249 """Return the ionization energy in the desired unit.
249250
250251 Args:
@@ -263,12 +264,12 @@ def get_ionization_energy(self, unit: Optional[str] = "hartree") -> Union["PintF
263264 return ionization_energy .to (unit , "spectroscopy" ).magnitude
264265
265266 @overload
266- def get_corrected_rydberg_constant (self , unit : None = None ) -> " PintFloat" : ...
267+ def get_corrected_rydberg_constant (self , unit : None = None ) -> PintFloat : ...
267268
268269 @overload
269270 def get_corrected_rydberg_constant (self , unit : str ) -> float : ...
270271
271- def get_corrected_rydberg_constant (self , unit : Optional [ str ] = "hartree" ) -> Union [ " PintFloat" , float ] :
272+ def get_corrected_rydberg_constant (self , unit : str | None = "hartree" ) -> PintFloat | float :
272273 r"""Return the corrected Rydberg constant in the desired unit.
273274
274275 The corrected Rydberg constant is defined as
@@ -317,14 +318,14 @@ def reduced_mass_factor(self) -> float:
317318 )
318319
319320 @overload
320- def calc_energy (self , n : int , l : int , j_tot : float , s_tot : float , unit : None = None ) -> " PintFloat" : ...
321+ def calc_energy (self , n : int , l : int , j_tot : float , s_tot : float , unit : None = None ) -> PintFloat : ...
321322
322323 @overload
323324 def calc_energy (self , n : int , l : int , j_tot : float , s_tot : float , unit : str ) -> float : ...
324325
325326 def calc_energy (
326- self , n : int , l : int , j_tot : float , s_tot : float , unit : Optional [ str ] = "hartree"
327- ) -> Union [ " PintFloat" , float ] :
327+ self , n : int , l : int , j_tot : float , s_tot : float , unit : str | None = "hartree"
328+ ) -> PintFloat | float :
328329 r"""Calculate the energy of a Rydberg state with for the given n, l, j_tot and s_tot.
329330
330331 I.e. either look up the energy for low lying states in the nist data,
@@ -355,7 +356,7 @@ def calc_energy(
355356 if j_tot % 1 != (l + s_tot ) % 1 :
356357 raise ValueError (f"Invalid quantum numbers: ({ l = } , { j_tot = } , { s_tot = } )" )
357358
358- energy_au : Optional [ float ] = None
359+ energy_au : float | None = None
359360 if n <= self ._nist_n_max and self .use_nist_data :
360361 if (n , l , j_tot , s_tot ) in self ._nist_energy_levels :
361362 energy_au = self ._nist_energy_levels [(n , l , j_tot , s_tot )]
0 commit comments