Mass Tolerances
Helpers for ppm errors, Da <-> ppm conversion and tolerance windows. Every function is
also importable from tacular. Units are the lowercase strings "da" and "ppm";
anything else raises TacularError. A ppm tolerance is relative to
the absolute value of the reference mass, so windows around negative masses are symmetric.
Mass tolerance helpers: ppm errors, Da <-> ppm conversion, and tolerance windows.
Units are the lowercase strings "da" and "ppm". Anything else raises
TacularError. A ppm tolerance is relative to abs(mass), so
windows around negative masses (for example, loss deltas) are well formed and symmetric.
>>> from tacular import ppm_error, tolerance_window, within_tolerance
>>> ppm_error(1000.01, 1000.0)
9.999999999990905
>>> tolerance_window(1000.0, 10, tolerance_unit="ppm")
(999.99, 1000.01)
>>> within_tolerance(1000.005, 1000.0, 10, tolerance_unit="ppm")
True
- tacular.tolerance.ToleranceUnit
"da"(daltons, absolute) or"ppm"(parts per million, relative).- Type:
A tolerance unit
alias of
Literal[‘da’, ‘ppm’]
- tacular.tolerance.da_to_ppm(delta, mz)[source]
Convert a mass difference
deltain Da to ppm ofmz:delta / abs(mz) * 1e6.tacular divides by
abs(mz), so the sign of the result is the sign ofdeltaeven for a negativemz(spxtacular’sda_to_ppmdivides by the signedmz).- Raises:
TacularError – if
mzis 0.- Return type:
float- Parameters:
delta (float)
mz (float)
- tacular.tolerance.ppm_error(observed, theoretical)[source]
The signed error of
observedin ppm oftheoretical:(observed - theoretical) / abs(theoretical) * 1e6.- Raises:
TacularError – if
theoreticalis 0.- Return type:
float- Parameters:
observed (float)
theoretical (float)
- tacular.tolerance.ppm_to_da(delta_ppm, mz)[source]
Convert a mass difference
delta_ppmin ppm ofmzto Da:delta_ppm * abs(mz) / 1e6.As in
da_to_ppm(), a negativemzdoes not flip the sign.- Return type:
float- Parameters:
delta_ppm (float)
mz (float)
- tacular.tolerance.tolerance_window(mass, tolerance, *, tolerance_unit='da')[source]
The
(lo, hi)bounds of atolerancewindow centred onmass.tolerance_unit="da"readstolerancein Da;tolerance_unit="ppm"in ppm ofabs(mass). A negative tolerance gives an empty window (lo > hi).- Raises:
TacularError – if
tolerance_unitis not"da"or"ppm", ormassortoleranceis NaN or infinite.- Return type:
tuple[float,float]- Parameters:
mass (float)
tolerance (float)
tolerance_unit (Literal['da', 'ppm'])
- tacular.tolerance.within_tolerance(observed, theoretical, tolerance, *, tolerance_unit='da')[source]
Whether
observedlies intolerance_window(theoretical, tolerance, tolerance_unit=tolerance_unit), bounds included:lo <= observed <= hi.tolerance_unit="ppm"readstolerancein ppm ofabs(theoretical). Testing against the window’s bounds (notabs(observed - theoretical) <= width) keeps the two functions consistent under float rounding: a value exactly atloorhiis within.- Raises:
TacularError – if
tolerance_unitis not"da"or"ppm", or any number is NaN or infinite.- Return type:
bool- Parameters:
observed (float)
theoretical (float)
tolerance (float)
tolerance_unit (Literal['da', 'ppm'])