source: sasmodels/sasmodels/models/fractal.py @ b297ba9

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since b297ba9 was b297ba9, checked in by Paul Kienzle <pkienzle@…>, 5 years ago

lint

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[12dbc90]1r"""
2Definition
3----------
4This model calculates the scattering from fractal-like aggregates of spherical
5building blocks according the following equation:
6
7.. math::
8
[785cbec]9    I(q) = \phi\ V_\text{block} (\rho_\text{block}
10          - \rho_\text{solvent})^2 P(q)S(q) + \text{background}
[12dbc90]11
12where $\phi$ is The volume fraction of the spherical "building block" particles
13of radius $R_0$, $V_{block}$ is the volume of a single building block,
14$\rho_{solvent}$ is the scattering length density of the solvent, and
15$\rho_{block}$ is the scattering length density of the building blocks, and
16P(q), S(q) are the scattering from randomly distributed spherical particles
17(the building blocks) and the interference from such building blocks organized
18in a fractal-like clusters.  P(q) and S(q) are calculated as:
19
20.. math::
21
[df89d77]22    P(q)&= F(qR_0)^2 \\
23    F(q)&= \frac{3 (\sin x - x \cos x)}{x^3} \\
24    V_\text{particle} &= \frac{4}{3}\ \pi R_0 \\
[785cbec]25    S(q) &= 1 + \frac{D_f\  \Gamma\!(D_f-1)}{[1+1/(q \xi)^2\  ]^{(D_f -1)/2}}
26    \frac{\sin[(D_f-1) \tan^{-1}(q \xi) ]}{(q R_0)^{D_f}}
[12dbc90]27
28where $\xi$ is the correlation length representing the cluster size and $D_f$
[404ebbd]29is the fractal dimension, representing the self similarity of the structure.
30Note that S(q) here goes negative if $D_f$ is too large, and the Gamma function
[df89d77]31diverges at $D_f=0$ and $D_f=1$.
[12dbc90]32
33**Polydispersity on the radius is provided for.**
34
35For 2D data: The 2D scattering intensity is calculated in the same way as
361D, where the *q* vector is defined as
37
38.. math::
39
40    q = \sqrt{q_x^2 + q_y^2}
41
42
43References
44----------
45
[4788822]46.. [#] J Teixeira, *J. Appl. Cryst.*, 21 (1988) 781-785
[12dbc90]47
[4788822]48Authorship and Verification
49----------------------------
[12dbc90]50
[4788822]51* **Author:** NIST IGOR/DANSE **Date:** pre 2010
52* **Converted to sasmodels by:** Paul Butler **Date:** March 19, 2016
53* **Last Modified by:** Paul Butler **Date:** March 12, 2017
54* **Last Reviewed by:** Paul Butler **Date:** March 12, 2017
[12dbc90]55"""
[404ebbd]56from __future__ import division
[12dbc90]57
[2d81cfe]58import numpy as np
[12dbc90]59from numpy import inf
60
61name = "fractal"
62title = "Calculates the scattering from fractal-like aggregates of spheres \
63following theTexiera reference."
64description = """
65        The scattering intensity is given by
66        I(q) = scale * V * delta^(2) * P(q) * S(q) + background, where
67        p(q)= F(q*radius)^(2)
68        F(x) = 3*[sin(x)-x cos(x)]/x**3
69        delta = sld_block -sld_solv
70        scale        =  scale * volfraction
71        radius       =  Block radius
72        sld_block    =  SDL block
73        sld_solv  =  SDL solvent
74        background   =  background
75        and S(q) is the interference term between building blocks given
76        in the full documentation and depending on the parameters
77        fractal_dim  =  Fractal dimension
78        cor_length  =  Correlation Length    """
79
80category = "shape-independent"
81
82# pylint: disable=bad-whitespace, line-too-long
83#             ["name", "units", default, [lower, upper], "type","description"],
84parameters = [["volfraction", "", 0.05, [0.0, 1], "",
85               "volume fraction of blocks"],
[4788822]86              ["radius",    "Ang",  5.0, [0.0, inf], "volume",
[12dbc90]87               "radius of particles"],
[217590b]88              ["fractal_dim",      "",  2.0, [0.0, 6.0], "",
[12dbc90]89               "fractal dimension"],
90              ["cor_length", "Ang", 100.0, [0.0, inf], "",
91               "cluster correlation length"],
[42356c8]92              ["sld_block", "1e-6/Ang^2", 2.0, [-inf, inf], "sld",
[12dbc90]93               "scattering length density of particles"],
[42356c8]94              ["sld_solvent", "1e-6/Ang^2", 6.4, [-inf, inf], "sld",
[12dbc90]95               "scattering length density of solvent"],
96             ]
97# pylint: enable=bad-whitespace, line-too-long
98
[925ad6e]99source = ["lib/sas_3j1x_x.c", "lib/sas_gamma.c", "lib/fractal_sq.c", "fractal.c"]
[12dbc90]100
[404ebbd]101def random():
[b297ba9]102    """Return a random parameter set for the model."""
[404ebbd]103    radius = 10**np.random.uniform(0.7, 4)
104    #radius = 5
105    cor_length = 10**np.random.uniform(0.7, 2)*radius
106    #cor_length = 20*radius
107    volfraction = 10**np.random.uniform(-3, -1)
108    #volfraction = 0.05
109    fractal_dim = 2*np.random.beta(3, 4) + 1
110    #fractal_dim = 2
111    pars = dict(
112        #background=0, sld_block=1, sld_solvent=0,
113        volfraction=volfraction,
114        radius=radius,
115        cor_length=cor_length,
116        fractal_dim=fractal_dim,
117    )
118    return pars
119
[dff1088]120demo = dict(volfraction=0.05,
[12dbc90]121            radius=5.0,
122            fractal_dim=2.0,
123            cor_length=100.0,
124            sld_block=2.0,
125            sld_solvent=6.4)
126
127# NOTE: test results taken from values returned by SasView 3.1.2
128tests = [
[dff1088]129    [{}, 0.0005, 40.4980069872],
130    [{}, 0.234734468938, 0.0947143166058],
131    [{}, 0.5, 0.0176878183458],
[12dbc90]132    ]
Note: See TracBrowser for help on using the repository browser.