AutoRg

This module provides a routine to compute the radius of gyration.

class auto_rg.AutoRg(data, qmin=0.005, qmax=0.25, min_n=4, qRg_limits=(0.1, 1.3), model=None, fit_kws=None)

Computes a radius of gyration for the provided data.

The methods consists in fitting a radius of gyration (Rg) and an intensity at the limit of \(\rm q = 0~ \mathring{A}^{-1}\) (I0). This is done by considering several block sizes that will slide along the q range. For each block position, a fit is performed. Subsequently, the distribution of Rg and I0 are computed and the mean values for these two parameters is obtained from the distribution.

The class can treat both 1D and 2D datasets.

Note

By default, the class uses a linear model to fit the Rg, such that the user should provide the logarithm of the data if no user-defined model is provided.

Parameters
  • data (sample.Sample) – An instance of sample.Sample containing the data to fit. No transformation is performed on the data except slicing. Hence, if the model requires to use the log of the data, it is up to the user to apply the operator before passing the data the the class.

  • qmin (float, optional) – Minimum value for the range of q values to be used. (default 0.005)

  • qmax (float, optional) – Maximum value for the range of q values to be used. (default 0.2)

  • min_n (int, optional) – Minimum number of points to use for the fit. (default 10)

  • qRg_limits (2-tuple of floats, optional) – Minimum and maximum limit of q*Rg value to consider the fit valid. (default (0.0005, 1.3))

  • model (model.Model) – An instance of Model class to be used to fit the data. If none, a built-in model from SAXS_routines will be used.

  • fit_kws (dict, optional) – Additional keywords to pass the fit function (default None)

fitResult

A list of fitted models, each being an instance of the model.Model class.

Type

list of model.Model

prob

A list of arrays giving the posterior probability that the Rg and I0 values are correct given the data as a function of Rg and I0. There is one array per 1D scattering curve in the dataset.

Type

list of np.array

rg

The values of Rg determined by the routine for each 1D scattering curve in the dataset.

Type

list of float

rg_std

The errors for Rg determined by the routine for each 1D scattering curve in the dataset.

Type

list of float

I0

The values of I0 determined by the routine for each 1D scattering curve in the dataset.

Type

list of float

I0_std

The errors for I0 determined by the routine for each 1D scattering curve in the dataset.

Type

list of float

Examples

The class can be initialized from a 2D dataset using:

>>> import numpy as np
>>> from saxs_routines.data_parsers.esrf_bm29 import read_HPLC
>>> from saxs_routines.data_analysis.auto_rg import AutoRg
>>>
>>> data = read_HPLC('myFile', name='myProtein')
>>> # buffer subtraction
>>> sub = data[480:520] - data[:50].mean(0)
>>>
>>> # AutoRg part
>>> autorg = AutoRg(np.log(sub))
>>> autorg.run()
>>> autorg.rg
[6.625, 6.232, 6.457, ..., 6.890, 7.011]

The result can be plotted as well as other attributes:

>>> autorg.plot()
plot(plot_errors=True, new_fig=False)

Plot the fitted parameters, Rg and I0.

Initially intended to be used with 2D dataset with time as first axis.

Parameters
  • plot_errors (bool, optional) – Whether to plot the errors on the parameters or not. (default False)

  • new_fig (bool, optional) – If True, a new figure will be created. Otherwise, use the existing one if any. (default False)

plot_I0_posterior_prob(idx=0)

Plot the computed posterior probability for the I0 value.

The posterior probability is computed from the Bayes rule for each fit at a given index. The plot gives the probability as a function of fitted I0.

Parameters

idx (int) – Index of the data to be plotted for 2D dataset of time series.

plot_fit(idx=0, best=False, new_fig=True)

Plot the fitted model against experimental data.

Parameters
  • idx (int) – Index of the data to be plotted for 2D dataset of time series.

  • best (bool, optional) – If True, plot only the best estimate of the Rg and I0. If False, plot all fitted models. (default, False)

plot_rg_posterior_prob(idx=0)

Plot the computed posterior probability for the Rg value.

The posterior probability is computed from the Bayes rule for each fit at a given index. The plot gives the probability as a function of fitted radius of gyration.

Parameters

idx (int) – Index of the data to be plotted for 2D dataset of time series.

run()

Run the algorithm to extract the radius of gyration.

The result is stored in the fitResult, prob, rg, I0, rg_std and I0_std attributes.