sas.sascalc.shape2sas package

Subpackages

Submodules

sas.sascalc.shape2sas.ExperimentalScattering module

class sas.sascalc.shape2sas.ExperimentalScattering.IExperimental(q: ndarray, I0: ndarray, I: ndarray, exposure: float)

Bases: object

save_Iexperimental(Isim: ndarray, sigma: ndarray, Model: str)
simulate_data() tuple[ndarray, ndarray]

Simulate SAXS data using calculated scattering and empirical expression for sigma

input q,I : calculated scattering, normalized I0 : forward scattering #noise : relative noise (scales the simulated sigmas by a factor) exposure : exposure (in arbitrary units) - affects the noise level of data

output sigma : simulated noise Isim : simulated data

data is also written to a file

class sas.sascalc.shape2sas.ExperimentalScattering.SimulateScattering(q: ndarray, I0: ndarray, I: ndarray, exposure: float | None = <factory>)

Bases: object

Class containing parameters for simulating scattering

I: ndarray
I0: ndarray
exposure: float | None
q: ndarray
class sas.sascalc.shape2sas.ExperimentalScattering.SimulatedScattering(I_sim: ndarray, q: ndarray, I_err: ndarray)

Bases: object

Class containing parameters for simulated scattering

I_err: ndarray
I_sim: ndarray
q: ndarray
sas.sascalc.shape2sas.ExperimentalScattering.getSimulatedScattering(scalc: SimulateScattering) SimulatedScattering

Simulate scattering for a given theoretical scattering.

sas.sascalc.shape2sas.HelperFunctions module

class sas.sascalc.shape2sas.HelperFunctions.Qsampling

Bases: object

static onQsampling(qmin: float, qmax: float, Nq: int) ndarray

Returns uniform q sampling

static onUserSampledQ(q: ndarray) ndarray

Returns user sampled q

static qMethodsInput(name: str)
static qMethodsNames(name: str)
sas.sascalc.shape2sas.HelperFunctions.check_unique(A_list: list[float]) bool

if all elements in a list are unique then return True, else return False

sas.sascalc.shape2sas.HelperFunctions.euler_rotation_matrix(alpha: float, beta: float, gamma: float) ndarray

Convert Euler angles to a rotation matrix, following the intrinsic ZYX convention.

sas.sascalc.shape2sas.HelperFunctions.generate_pdb(x_list: list[ndarray], y_list: list[ndarray], z_list: list[ndarray], p_list: list[ndarray], Model_list: list[str]) None

Generates a visualisation file in PDB format with the simulated points (coordinates) and contrasts ONLY FOR VISUALIZATION! Each bead is represented as a dummy atom Carbon, C : positive contrast Hydrogen, H : zero contrast Oxygen, O : negateive contrast information of accurate contrasts not included, only sign IMPORTANT: IT WILL NOT GIVE THE CORRECT RESULTS IF SCATTERING IS CACLLUATED FROM THIS MODEL WITH E.G. CRYSOL, PEPSI-SAXS, FOXS, CAPP OR THE LIKE!

sas.sascalc.shape2sas.HelperFunctions.get_max_dimension(x_list: ndarray, y_list: ndarray, z_list: ndarray) float

find max dimensions of n models used for determining plot limits

sas.sascalc.shape2sas.HelperFunctions.plot_2D(x_list: ndarray, y_list: ndarray, z_list: ndarray, p_list: ndarray, Models: ndarray, high_res: bool) None

plot 2D-projections of generated points (shapes) using matplotlib: positive contrast in red (Model 1) or blue (Model 2) or yellow (Model 3) or green (Model 4) zero contrast in grey negative contrast in black

input (x_list,y_list,z_list) : coordinates of simulated points p_list : excess scattering length densities (contrast) of simulated points Model : Model number

output plot : points<Model>.png

sas.sascalc.shape2sas.HelperFunctions.plot_results(q: ndarray, r_list: list[ndarray], pr_list: list[ndarray], I_list: list[ndarray], Isim_list: list[ndarray], sigma_list: list[ndarray], S_list: list[ndarray], names: list[str], scales: list[float], xscale_log: bool, high_res: bool) None

plot results for all models, using matplotlib: - p(r) - calculated formfactor, P(r) on log-log or log-lin scale - simulated noisy data on log-log or log-lin scale

sas.sascalc.shape2sas.HelperFunctions.sinc(x) ndarray

function for calculating sinc = sin(x)/x numpy.sinc is defined as sinc(x) = sin(pi*x)/(pi*x)

sas.sascalc.shape2sas.Models module

class sas.sascalc.shape2sas.Models.GenerateAllPoints(Npoints: int, com: list[list[float]], subunits: list[list[float]], dimensions: list[list[float]], rotation: list[list[float]], rotation_point: list[float], p: list[float], exclude_overlap: bool)

Bases: object

getSubunitClass(key: str)
static onAppendingPoints(x_new: ndarray, y_new: ndarray, z_new: ndarray, p_new: ndarray, x_add: ndarray, y_add: ndarray, z_add: ndarray, p_add: ndarray) tuple[ndarray, ndarray, ndarray, ndarray]

append new points to vectors of point coordinates

static onCheckOverlap(x: ndarray, y: ndarray, z: ndarray, p: ndarray, rotation: list[float], rotation_point: list[float], com: list[float], subunitClass: object, dimensions: list[float])

check for overlap with previous subunits. if overlap, the point is removed

onGeneratingAllPoints() tuple[ndarray, ndarray, ndarray, ndarray, float]

Generating points for all subunits from each built model

onGeneratingAllPointsSeparately() tuple[ndarray, ndarray, ndarray]

Generating points for all subunits from each built model, but save them separately in their own list

setAvailableSubunits()

Returns the available subunits

class sas.sascalc.shape2sas.Models.GeneratePoints(com: list[float], subunitClass: object, dimensions: list[float], rotation: list[float], rotation_point: list[float], Npoints: int)

Bases: object

onGeneratingPoints() tuple[ndarray, ndarray, ndarray]

Generates the points

onTransformingPoints(x: ndarray, y: ndarray, z: ndarray) tuple[ndarray, ndarray, ndarray]

Transforms the points

class sas.sascalc.shape2sas.Models.ModelPointDistribution(x: ndarray, y: ndarray, z: ndarray, p: ndarray, volume_total: float)

Bases: object

Point distribution of a model

p: ndarray
volume_total: float
x: ndarray
y: ndarray
z: ndarray
class sas.sascalc.shape2sas.Models.ModelProfile(subunits: list[str] = <factory>, p_s: list[float] = <factory>, dimensions: list[list[float]] = <factory>, com: list[list[float]] = <factory>, rotation_points: list[list[float]] = <factory>, rotation: list[list[float]] = <factory>, exclude_overlap: bool | None = <factory>)

Bases: object

Class containing parameters for creating a particle

NOTE: Default values create a sphere with a radius of 50 Å at the origin.

com: list[list[float]]
dimensions: list[list[float]]
exclude_overlap: bool | None
p_s: list[float]
rotation: list[list[float]]
rotation_points: list[list[float]]
subunits: list[str]
class sas.sascalc.shape2sas.Models.ModelSystem(PointDistribution: ModelPointDistribution, Stype: str = <factory>, par: list[float] = <factory>, polydispersity: float = <factory>, conc: float = <factory>, sigma_r: float = <factory>)

Bases: object

Class containing parameters for the system

PointDistribution: ModelPointDistribution
Stype: str
conc: float
par: list[float]
polydispersity: float
sigma_r: float
class sas.sascalc.shape2sas.Models.Rotation(matrix: ndarray, center_mass: ndarray)

Bases: object

class sas.sascalc.shape2sas.Models.SimulationParameters(q: ndarray | None = <factory>, prpoints: int | None = <factory>, Npoints: int | None = <factory>, model_name: list[str] | None = <factory>)

Bases: object

Class containing parameters for the simulation itself

Npoints: int | None
model_name: list[str] | None
prpoints: int | None
q: ndarray | None
sas.sascalc.shape2sas.Models.getPointDistribution(prof: ModelProfile, Npoints)

Generate points for a given model profile.

sas.sascalc.shape2sas.Models.transform(coords: ~numpy.ndarray[tuple[~numpy.ndarray, ~numpy.ndarray, ~numpy.ndarray]], translate: ~numpy.ndarray = array([0, 0, 0]), rotate: ~sas.sascalc.shape2sas.Models.Rotation = <sas.sascalc.shape2sas.Models.Rotation object>)

Transform a set of coordinates by a rotation R and translation T

sas.sascalc.shape2sas.PluginGenerator module

sas.sascalc.shape2sas.PluginGenerator.format_parameter_list(par: list[list[str | float]]) str

Format a list of parameters to the model string. In this case the list is on element for each shape. For a single shape there will be only a single value. Mainly for delta Rho.

sas.sascalc.shape2sas.PluginGenerator.format_parameter_list_of_list(par: list[str | float]) str

Format a list of list containing parameters to the model string. This is used for single shape parameter lists like the center of mass of the object which will be an element of the list of such COM for each shape in a multishape model.

sas.sascalc.shape2sas.PluginGenerator.format_parameter_list_of_list_dimension(par: list[list[str | float]]) str

Format a list of lists containing dimensional parameters to the model string. Variables will be enclosed in ‘min(abs(x), 1)’ for safety.

sas.sascalc.shape2sas.PluginGenerator.generate_model(prof: ModelProfile, modelPars: list[list[str], list[str | float]], usertext: UserText, fitPar: list[str], Npoints: int, pr_points: int, model_name: str) str

Generates a theoretical model

sas.sascalc.shape2sas.PluginGenerator.generate_plugin(prof: ModelProfile, modelPars: list[list[str], list[str | float]], usertext: UserText, fitPar: list[str], Npoints: int, pr_points: int, file_name: str) tuple[str, Path]

Generates a theoretical scattering plugin model

sas.sascalc.shape2sas.PluginGenerator.get_shape_symbols(symbols: tuple[set[str], set[str]], modelPars: list[list[str], list[str | float]]) tuple[set[str], set[str]]

Get the symbols used in the model, discarding user-defined variables

sas.sascalc.shape2sas.PluginGenerator.script_insert_apply_constraints(lhs_symbols: set[str]) str

Create the code responsible for updating constraints.

sas.sascalc.shape2sas.PluginGenerator.script_insert_constrained_parameters(symbols: set[str], modelPars: list[list[str], list[str | float]]) str

Create the code defining the constrained parameters.

sas.sascalc.shape2sas.PluginGenerator.script_insert_delta_parameters(modelPars: list[list[str | float]], fitPars: list[str], symbols: tuple[set[str], set[str]]) tuple[str, str]

Create the code sections defining and updating the delta parameters. Only parameters declared in the symbol list will be included.

sas.sascalc.shape2sas.Shape2SAS module

sas.sascalc.shape2sas.StructureFactor module

class sas.sascalc.shape2sas.StructureFactor.StructureFactor(q: ndarray, x_new: ndarray, y_new: ndarray, z_new: ndarray, p_new: ndarray, Stype: str, par: list[float] | None)

Bases: object

getStructureFactorClass()

Return chosen structure factor

static getparname(name: str) list[str]

Return the name of the parameters

static save_S(q: ndarray, S_eff: ndarray, Model: str)

save S to file

setAvailableStructureFactors()

Available structure factors

sas.sascalc.shape2sas.TheoreticalScattering module

class sas.sascalc.shape2sas.TheoreticalScattering.ITheoretical(q: ndarray)

Bases: object

calc_Iq(Pq: ndarray, S_eff: ndarray, sigma_r: float) ndarray

calculates intensity

calc_Pq(r: ndarray, pr: ndarray, conc: float, volume_total: float) tuple[ndarray, ndarray]

calculate form factor, P(q), and forward scattering, I(0), using pair distribution, p(r)

calc_Pq_ausaxs(q: ndarray, x: ndarray, y: ndarray, z: ndarray, p: ndarray) ndarray

calculate form factor, P(q), using ausaxs SANS Debye method

save_I(I: ndarray, Model: str)

Save theoretical intensity to file

class sas.sascalc.shape2sas.TheoreticalScattering.TheoreticalScattering(q: ndarray, I0: ndarray, I: ndarray, S_eff: ndarray)

Bases: object

Class containing parameters for theoretical scattering

I: ndarray
I0: ndarray
S_eff: ndarray
q: ndarray
class sas.sascalc.shape2sas.TheoreticalScattering.TheoreticalScatteringCalculation(System: ModelSystem, Calculation: SimulationParameters)

Bases: object

Class containing parameters for simulating scattering for a given model system

Calculation: SimulationParameters
System: ModelSystem
class sas.sascalc.shape2sas.TheoreticalScattering.WeightedPairDistribution(x: ndarray, y: ndarray, z: ndarray, p: ndarray)

Bases: object

static calc_Rg(r: ndarray, pr: ndarray) float

calculate Rg from r and p(r)

calc_all_contrasts() ndarray

calculate all pairwise contrast products of p: all contrasts

calc_all_dist() ndarray

calculate all pairwise distances calls calc_dist() for each set of coordinates: x,y,z does a square sum of coordinates convert from matrix to

static calc_dist(x: ndarray) ndarray

calculate all distances between points in an array

calc_hr(dist: ndarray, Nbins: int, contrast: ndarray, polydispersity: float) tuple[ndarray, ndarray]

calculate h(r) h(r) is the contrast-weighted histogram of distances, including self-terms (dist = 0)

input: dist : all pairwise distances contrast : all pair-wise contrast products polydispersity: relative polydispersity, float

output: hr : pair distance distribution function

calc_pr(Nbins: int, polydispersity: float) tuple[ndarray, ndarray, ndarray]

calculate p(r) p(r) is the contrast-weighted histogram of distances, without the self-terms (dist = 0)

input: dist : all pairwise distances contrast : all pair-wise contrast products polydispersity: boolian, True or False

output: pr : pair distance distribution function

static generate_histogram(dist: ndarray, contrast: ndarray, r_max: float, Nbins: int) tuple[ndarray, ndarray]

make histogram of point pairs, h(r), binned after pair-distances, r used for calculating scattering (fast Debye)

input dist : all pairwise distances Nbins : number of bins in h(r) contrast : contrast of points r_max : max distance to include in histogram

output r : distances of bins histo : histogram, weighted by contrast

static save_pr(Nbins: int, r: ndarray, pr_norm: ndarray, Model: str)

save p(r) to textfile

sas.sascalc.shape2sas.TheoreticalScattering.getTheoreticalHistogram(model: ModelSystem, sim_pars: SimulationParameters) tuple[ndarray, ndarray, ndarray]

Get theoretical histogram for a given model system and simulation parameters. This function is used to calculate the pair distribution function (p(r)).

Parameters:
  • model – ModelSystem object containing the model parameters.

  • sim_pars – SimulationParameters object containing the simulation parameters.

Returns:

r, pr, pr_norm - pair distance distribution function.

sas.sascalc.shape2sas.TheoreticalScattering.getTheoreticalScattering(scalc: TheoreticalScatteringCalculation) TheoreticalScattering

Calculate theoretical scattering for a given model profile.

sas.sascalc.shape2sas.Typing module

sas.sascalc.shape2sas.UserText module

class sas.sascalc.shape2sas.UserText.UserText(imports: list[str], params: list[str], constraints: list[str], symbols: tuple[set[str], set[str]])

Bases: object

Module contents