# sas.sascalc.shape2sas package

## Submodules

## sas.sascalc.shape2sas.Shape2SAS module

class sas.sascalc.shape2sas.Shape2SAS.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.Shape2SAS.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.Shape2SAS.ModelSystem(PointDistribution: ~sas.sascalc.shape2sas.Shape2SAS.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.Shape2SAS.SimulateScattering(q: ~numpy.ndarray, I0: ~numpy.ndarray, I: ~numpy.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.Shape2SAS.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

class sas.sascalc.shape2sas.Shape2SAS.SimulationParameters(q: ~numpy.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

class sas.sascalc.shape2sas.Shape2SAS.TheoreticalScattering(q: ndarray, I0: ndarray, I: ndarray, S_eff: ndarray, r: ndarray, pr: ndarray, pr_norm: ndarray)

  Bases: `object`

  Class containing parameters for theoretical scattering

  I: ndarray
  I0: ndarray
  S_eff: ndarray
  pr: ndarray
  pr_norm: ndarray
  q: ndarray
  r: ndarray

class sas.sascalc.shape2sas.Shape2SAS.TheoreticalScatteringCalculation(System: ModelSystem, Calculation: SimulationParameters)

  Bases: `object`

  Class containing parameters for simulating scattering for a given model system

  Calculation: SimulationParameters
  System: ModelSystem

sas.sascalc.shape2sas.Shape2SAS.getPointDistribution(prof: ModelProfile, Npoints)

  Generate points for a given model profile.

sas.sascalc.shape2sas.Shape2SAS.getSimulatedScattering(scalc: SimulateScattering) → SimulatedScattering

  Simulate scattering for a given theoretical scattering.

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

  Calculate theoretical scattering for a given model profile.

## sas.sascalc.shape2sas.helpfunctions module

class sas.sascalc.shape2sas.helpfunctions.Aggregation(q: ndarray, x_new: ndarray, y_new: ndarray, z_new: ndarray, p_new: ndarray, par: list[float])

  Bases: `StructureDecouplingApprox`

  calc_S_aggr() → ndarray

    calculates fractal aggregate structure factor with dimensionality 2

    S_{2,D=2} in Larsen et al 2020, https://doi.org/10.1107/S1600576720006500

    input q : Naggr : number of particles per aggregate Reff : effective radius of one particle

    output S_aggr :

  structure_eff(Pq: ndarray) → ndarray

    Return effective structure factor for aggregation

class sas.sascalc.shape2sas.helpfunctions.Cube(dimensions: list[float])

  Bases: `object`

  checkOverlap(x_eff: ndarray, y_eff: ndarray, z_eff: ndarray) → ndarray

    Check for points within a cube

  getPointDistribution(Npoints: int) → tuple[ndarray, ndarray, ndarray]

    Returns the point distribution of a cube

  getVolume() → float

    Returns the volume of a cube

class sas.sascalc.shape2sas.helpfunctions.Cuboid(dimensions: list[float])

  Bases: `object`

  checkOverlap(x_eff: ndarray, y_eff: ndarray, z_eff: ndarray) → ndarray

    Check for points within a Cuboid

  getPointDistribution(Npoints: int) → tuple[ndarray, ndarray, ndarray]

    Returns the point distribution of a cuboid

  getVolume() → float

    Returns the volume of a cuboid

class sas.sascalc.shape2sas.helpfunctions.Cylinder(dimensions: list[float])

  Bases: `object`

  checkOverlap(x_eff: ndarray, y_eff: ndarray, z_eff: ndarray) → ndarray

    Check for points within a cylinder

  getPointDistribution(Npoints: int) → tuple[ndarray, ndarray, ndarray]

    Returns the point distribution of a cylinder

  getVolume() → float

    Returns the volume of a cylinder

class sas.sascalc.shape2sas.helpfunctions.CylinderRing(dimensions: list[float])

  Bases: `object`

  checkOverlap(x_eff: ndarray, y_eff: ndarray, z_eff: ndarray) → ndarray

    Check for points within a cylinder ring

  getPointDistribution(Npoints: int) → tuple[ndarray, ndarray, ndarray]

    Returns the point distribution of a cylinder ring

  getVolume() → float

    Returns the volume of a cylinder ring

class sas.sascalc.shape2sas.helpfunctions.Disc(dimensions: list[float])

  Bases: `EllipticalCylinder`

class sas.sascalc.shape2sas.helpfunctions.DiscRing(dimensions: list[float])

  Bases: `CylinderRing`

class sas.sascalc.shape2sas.helpfunctions.Ellipsoid(dimensions: list[float])

  Bases: `object`

  checkOverlap(x_eff: ndarray, y_eff: ndarray, z_eff: ndarray) → ndarray

    check for points within a ellipsoid

  getPointDistribution(Npoints: int) → tuple[ndarray, ndarray, ndarray]

    Returns the point distribution of an ellipsoid

  getVolume() → float

    Returns the volume of an ellipsoid

class sas.sascalc.shape2sas.helpfunctions.EllipticalCylinder(dimensions: list[float])

  Bases: `object`

  checkOverlap(x_eff: ndarray, y_eff: ndarray, z_eff: ndarray) → ndarray

    Check for points within a Elliptical cylinder

  getPointDistribution(Npoints: int) → tuple[ndarray, ndarray, ndarray]

    Returns the point distribution of an elliptical cylinder

  getVolume() → float

    Returns the volume of an elliptical cylinder

class sas.sascalc.shape2sas.helpfunctions.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.helpfunctions.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.helpfunctions.HardSphereStructure(q: ndarray, x_new: ndarray, y_new: ndarray, z_new: ndarray, p_new: ndarray, par: list[float])

  Bases: `StructureDecouplingApprox`

  static calc_G(A: ndarray, eta: float) → ndarray

    calculate G in the hard-sphere potential

    input A : 2*R*q q : momentum transfer R : hard-sphere radius eta: volume fraction

    output: G

  calc_S_HS() → ndarray

    calculate the hard-sphere structure factor calls function calc_G()

    input q : momentum transfer eta : volume fraction R : estimation of the hard-sphere radius

    output S_HS : hard-sphere structure factor

  structure_eff(Pq: ndarray) → ndarray

class sas.sascalc.shape2sas.helpfunctions.HollowCube(dimensions: list[float])

  Bases: `object`

  checkOverlap(x_eff: ndarray, y_eff: ndarray, z_eff: ndarray) → ndarray

    Check for points within a hollow cube

  getPointDistribution(Npoints: int) → tuple[ndarray, ndarray, ndarray]

    Returns the point distribution of a hollow cube

  getVolume() → float

    Returns the volume of a hollow cube

class sas.sascalc.shape2sas.helpfunctions.HollowSphere(dimensions: list[float])

  Bases: `object`

  checkOverlap(x_eff: ndarray, y_eff: ndarray, z_eff: ndarray) → ndarray

    Check for points within a hollow sphere

  getPointDistribution(Npoints: int) → tuple[ndarray, ndarray, ndarray]

    Returns the point distribution of a hollow sphere

  getVolume() → float

    Returns the volume of a hollow sphere

class sas.sascalc.shape2sas.helpfunctions.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.helpfunctions.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)

  save_I(I: ndarray, Model: str)

    Save theoretical intensity to file

class sas.sascalc.shape2sas.helpfunctions.NoStructure(q: ndarray, x_new: ndarray, y_new: ndarray, z_new: ndarray, p_new: ndarray, par: Any)

  Bases: `StructureDecouplingApprox`

  structure_eff(Pq: Any) → ndarray

    Return effective structure factor for no structure

class sas.sascalc.shape2sas.helpfunctions.Qsampling

  Bases: `object`

  onQsampling(qmax: float, Nq: int) → ndarray

    Returns uniform q sampling

  onUserSampledQ() → ndarray

    Returns user sampled q

  qMethodsInput()
  qMethodsNames()

class sas.sascalc.shape2sas.helpfunctions.Rotation(x_add: ndarray, y_add: ndarray, z_add: ndarray, alpha: float, beta: float, gam: float, rotp_x: float, rotp_y: float, rotp_z: float)

  Bases: `object`

  onRotatingPoints() → tuple[ndarray, ndarray, ndarray]

    Simple Euler rotation

class sas.sascalc.shape2sas.helpfunctions.Sphere(dimensions: list[float])

  Bases: `object`

  checkOverlap(x_eff: ndarray, y_eff: ndarray, z_eff: ndarray) → ndarray

    Check for points within a sphere

  getPointDistribution(Npoints: int) → tuple[ndarray, ndarray, ndarray]

    Returns the point distribution of a sphere

  getVolume() → float

    Returns the volume of a sphere

class sas.sascalc.shape2sas.helpfunctions.StructureDecouplingApprox(q: ndarray, x_new: ndarray, y_new: ndarray, z_new: ndarray, p_new: ndarray)

  Bases: `object`

  calc_A00() → ndarray

    calc zeroth order sph harm, for decoupling approximation

  calc_com_dist() → ndarray

    calc contrast-weighted com distance

  decoupling_approx(Pq: ndarray, S: ndarray) → ndarray

    modify structure factor with the decoupling approximation for combining structure factors with non-spherical (or polydisperse) particles

    see, for example, Larsen et al 2020: https://doi.org/10.1107/S1600576720006500 and refs therein

    input q x,y,z,p : coordinates and contrasts Pq : form factor S : structure factor

    output S_eff : effective structure factor, after applying decoupl. approx

class sas.sascalc.shape2sas.helpfunctions.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

class sas.sascalc.shape2sas.helpfunctions.Superellipsoid(dimensions: list[float])

  Bases: `object`

  static beta(a, b) → float

    beta function

  checkOverlap(x_eff: ndarray, y_eff: ndarray, z_eff: ndarray) → ndarray

    Check for points within a superellipsoid

  getPointDistribution(Npoints: int) → tuple[ndarray, ndarray, ndarray]

    Returns the point distribution of a superellipsoid

  getVolume() → float

    Returns the volume of a superellipsoid

class sas.sascalc.shape2sas.helpfunctions.Translation(x_add: ndarray, y_add: ndarray, z_add: ndarray, com_x: float, com_y: float, com_z: float)

  Bases: `object`

  onTranslatingPoints() → tuple[ndarray, ndarray, ndarray]

    Translates points

class sas.sascalc.shape2sas.helpfunctions.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.helpfunctions.check_unique(A_list: list[float]) → bool

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

sas.sascalc.shape2sas.helpfunctions.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.helpfunctions.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.helpfunctions.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.helpfunctions.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.helpfunctions.sinc(x) → ndarray

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

## Module contents