Guinier.SimpleFallback#

Guinier.SimpleFallback.py

compute_rg(qw2, lnI, weights)#

Compute radius of gyration (Rg) using weighted linear regression.

compute_r_squared(qw2, lnI, weights)#

Compute R² (coefficient of determination) for weighted linear regression.

Parameters:
  • qw2 (ndarray) – q² values

  • lnI (ndarray) – Natural log of intensity

  • weights (ndarray) – Weights for each point

Returns:

R² value (closer to 1.0 means better linearity)

Return type:

float

estimate_rg_simply(data, rg_range=None, min_num_points=5, q_rg_limit=1.3, initial_q_max=0.025)#

A simple fallback function for Guinier analysis.

This function uses a multi-step approach: 1. Sliding window to find the most linear region and exclude problematic initial points 2. Initial conservative fit with the best window to estimate Rg 3. Range refinement based on q*Rg < q_rg_limit criterion 4. Final fit with the refined range

Parameters:
  • data (ndarray) – SAXS data with columns [q, I, error]

  • rg_range (tuple, optional) – Expected range of Rg values (min_rg, max_rg) in Angstroms. Default is (MIN_RG, MAX_RG) = (10.0, 80.0)

  • min_num_points (int, optional) – Minimum number of points required in the Guinier region (default: 5)

  • q_rg_limit (float, optional) – Guinier criterion limit for q*Rg (default: 1.3)

  • initial_q_max (float, optional) – Initial conservative q maximum for searching the best starting window (default: 0.025 Å⁻¹)

Returns:

Dictionary containing: - ‘Rg’: Radius of gyration in Angstroms - ‘I0’: Forward scattering intensity - ‘q_start’: Starting index of the fitted range - ‘q_end’: Ending index of the fitted range - ‘q_min’: Minimum q value used in fit (Å⁻¹) - ‘q_max’: Maximum q value used in fit (Å⁻¹) - ‘n_points’: Number of points used in fit - ‘q_rg_max’: Maximum q*Rg value in the fitted range - ‘r_squared’: R² value indicating quality of linear fit

Return type:

dict

Raises:

ValueError – If there are not enough valid data points for analysis

class SimpleFallback(data, rg_range=None, q_rg_limit=1.3)#

Bases: object

A simple fallback class for Guinier analysis.

data#

SAXS data with columns [q, I, error]

Type:

ndarray

rg_range#

Expected range of Rg values (min_rg, max_rg) in Angstroms

Type:

tuple

result#

Results from Guinier analysis

Type:

dict

Initialize SimpleFallback with SAXS data.

Parameters:
  • data (ndarray) – SAXS data with columns [q, I, error]

  • rg_range (tuple, optional) – Expected range of Rg values (min_rg, max_rg) in Angstroms

  • q_rg_limit (float, optional) – Guinier criterion limit (default: 1.3)

estimate()#

Perform Guinier analysis and return results.

Returns:

Dictionary with keys: ‘Rg’, ‘I0’, ‘q_min’, ‘q_max’, ‘n_points’, ‘r_squared’

Return type:

dict

plot(ax=None, show=True)#

Plot Guinier plot with the fitted range.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – Axes to plot on. If None, creates new figure.

  • show (bool, optional) – Whether to display the plot (default: True)

Returns:

The axes with the plot

Return type:

matplotlib.axes.Axes