11from __future__ import annotations
22
33import logging
4+ import math
45from functools import cached_property
56from typing import TYPE_CHECKING , Any , overload
67
@@ -284,6 +285,9 @@ def calc_exp_qn(self, qn: str) -> float:
284285 if qn == "nu" :
285286 return self .nu
286287
288+ if qn .startswith ("raw_value_" ):
289+ return self .calc_matrix_element (self , qn , q = 0 , unit = "a.u." ) # type: ignore [call-overload,no-any-return]
290+
287291 if is_angular_momentum_quantum_number (qn ):
288292 if qn not in self .rydberg_kets [0 ].angular .quantum_number_names :
289293 coupling_scheme = get_coupling_scheme_for_quantum_number (qn , [self .coupling_scheme ])
@@ -297,6 +301,16 @@ def calc_std_qn(self, qn: str) -> float:
297301 if qn == "nu" :
298302 return 0
299303
304+ if qn .startswith ("raw_value_" ):
305+ exp_q = self .calc_matrix_element (self , qn , q = 0 , unit = "a.u." ) # type: ignore [call-overload]
306+ exp_q2 = self .calc_matrix_element (self , qn + "_2" , q = 0 , unit = "a.u." ) # type: ignore [call-overload]
307+ if abs (exp_q2 - exp_q ** 2 ) < 1e-10 :
308+ return 0
309+ if exp_q2 - exp_q ** 2 < 0 :
310+ logger .warning ("Got negative variance for quantum number %s: %.3e. Returning 0." , qn , exp_q2 - exp_q ** 2 )
311+ return 0
312+ return math .sqrt (exp_q2 - exp_q ** 2 )
313+
300314 if is_angular_momentum_quantum_number (qn ):
301315 if qn not in self .rydberg_kets [0 ].angular .quantum_number_names :
302316 coupling_scheme = get_coupling_scheme_for_quantum_number (qn , [self .coupling_scheme ])
0 commit comments