Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Commit f1db04e

Browse files
RadialState improve sanity checks
1 parent 0e0654d commit f1db04e

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

src/ryd_numerov/radial/radial_state.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import math
55
from typing import TYPE_CHECKING, Literal, overload
66

7-
import numpy as np
8-
97
from ryd_numerov.radial.grid import Grid
108
from ryd_numerov.radial.model import Model
119
from ryd_numerov.radial.radial_matrix_element import calc_radial_matrix_element_from_w_z
@@ -46,12 +44,12 @@ def __init__(
4644
self.species = species
4745

4846
self.n: int | None = None
49-
self.nu = nu
50-
self.l_r = l_r
51-
52-
# sanity checks
5347
if not nu > 0:
5448
raise ValueError(f"nu must be larger than 0, but is {nu=}")
49+
self.nu = nu
50+
if not (l_r.is_integer() and l_r >= 0):
51+
raise ValueError(f"l_r must be an integer, and larger or equal 0, but {l_r=}")
52+
self.l_r = int(l_r)
5553

5654
def set_n_for_sanity_check(self, n: int) -> None:
5755
"""Provide n for additional sanity checks of the radial wavefunction.
@@ -62,18 +60,14 @@ def set_n_for_sanity_check(self, n: int) -> None:
6260
n: Principal quantum number of the rydberg electron.
6361
6462
"""
65-
self.n = n
66-
67-
if self.nu > n and abs(self.nu - n) < 1e-10:
68-
self.nu = n # avoid numerical issues
63+
if not (n.is_integer() and n >= 1):
64+
raise ValueError(f"n must be an integer, and larger or equal 1, but {n=}")
6965

70-
if n is not None and not (isinstance(n, (int, np.integer)) and n >= 1 and n >= self.nu):
71-
raise ValueError(
72-
f"n must be an integer larger than 0 and larger (or equal) than nu, but is {n=}, {self.nu=}"
73-
)
74-
75-
if not (isinstance(self.l_r, (int, np.integer)) and self.l_r >= 0 and (n is None or self.l_r <= n - 1)):
76-
raise ValueError(f"l_r must be an integer, and between 0 and n - 1, but is {self.l_r=}, {n=}")
66+
if n < (self.nu - 1e-2): # avoid issues due to numerical precision and due to NIST data
67+
raise ValueError(f"n must be larger or equal to nu, but {n=}, nu={self.nu} for {self}")
68+
if n <= self.l_r:
69+
raise ValueError(f"n must be larger than l_r, but {n=}, l_r={self.l_r} for {self}")
70+
self.n = n
7771

7872
def __repr__(self) -> str:
7973
species, nu, l_r, n = self.species, self.nu, self.l_r, self.n

0 commit comments

Comments
 (0)