File: surface_fractal.py

package info (click to toggle)
mccode 3.5.19%2Bds5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,113,256 kB
  • sloc: ansic: 40,697; python: 25,137; yacc: 8,438; sh: 5,405; javascript: 4,596; lex: 1,632; cpp: 742; perl: 296; lisp: 273; makefile: 226; fortran: 132
file content (127 lines) | stat: -rw-r--r-- 4,051 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
r"""
This model calculates the scattering from fractal-like aggregates based
on the Mildner reference.

Definition
----------

The scattering intensity $I(q)$ is calculated as

.. math::
    :nowrap:

    \begin{align*}
    I(q) &= \text{scale} \times P(q)S(q) + \text{background} \\
    P(q) &= F(qR)^2 \\
    F(x) &= \frac{3\left[\sin(x)-x\cos(x)\right]}{x^3} \\
    S(q) &= \Gamma(5-D_S)\xi^{\,5-D_S}\left[1+(q\xi)^2 \right]^{-(5-D_S)/2}
            \sin\left[-(5-D_S) \tan^{-1}(q\xi) \right] q^{-1} \\
    \text{scale} &= \text{scale factor}\,
        N V^1(\rho_\text{particle} - \rho_\text{solvent})^2 \\
    V &= \frac{4}{3}\pi R^3
    \end{align*}

where $R$ is the radius of the building block, $D_S$ is the **surface** fractal
dimension, $\xi$ is the cut-off length, $\rho_\text{solvent}$ is the scattering
length density of the solvent and $\rho_\text{particle}$ is the scattering
length density of particles.

.. note::

    The surface fractal dimension is only valid if $1<D_S<3$. The result is only
    valid over a limited $q$ range, $\tfrac{5}{3-D_S}\xi^{\,-1} < q < R^{-1}$.
    See the reference for details.


References
----------

#.  D Mildner and P Hall, *J. Phys. D: Appl. Phys.*, 19 (1986) 1535-1545

Authorship and Verification
----------------------------

* **Author:**
* **Last Modified by:**
* **Last Reviewed by:**
"""

import numpy as np
from numpy import inf

name = "surface_fractal"
title = "Fractal-like aggregates based on the Mildner reference"
description = """\
    [The scattering intensity  I(x) = scale*P(x)*S(x) + background, where
        scale = scale_factor  * V * delta^(2)
        p(x) = F(x*radius)^(2)
        F(x) = 3*[sin(x)-x cos(x)]/x**3
        S(x) = [(gamma(5-Ds)*colength^(5-Ds)*[1+(x^2*colength^2)]^((Ds-5)/2)
             * sin[(Ds-5)*arctan(x*colength)])/x]
        where
        delta        =  sldParticle -sldSolv.
        radius       =  Particle radius
        fractal_dim_surf  =  Surface fractal dimension (Ds)
        co_length    =  Cut-off length
        background   =  background

        Ref.   :Mildner, Hall,J Phys D Appl Phys(1986), 19, 1535-1545
        Note I : This model is valid for 1<fractal_dim_surf<3 with limited q range.
        Note II: This model is not in absolute scale.
"""
category = "shape-independent"

# pylint: disable=bad-whitespace, line-too-long
#             ["name", "units", default, [lower, upper], "type","description"],
parameters = [["radius",        "Ang", 10.0, [0, inf],   "",
               "Particle radius"],
              ["fractal_dim_surf",   "",    2.0,  [1, 3],   "",
               "Surface fractal dimension"],
              ["cutoff_length", "Ang", 500., [0.0, inf], "",
               "Cut-off Length"],
             ]
# pylint: enable=bad-whitespace, line-too-long

source = ["lib/sas_3j1x_x.c", "lib/sas_gamma.c", "surface_fractal.c"]
# Don't need validity test since fractal_dim_surf is not polydisperse
#valid = "fractal_dim_surf > 1.0 && fractal_dim_surf < 3.0"

def random():
    """Return a random parameter set for the model."""
    radius = 10**np.random.uniform(1, 4)
    fractal_dim_surf = np.random.uniform(1, 3-1e-6)
    cutoff_length = 1e6  # Sets the low q limit; keep it big for sim
    pars = dict(
        #background=0,
        scale=1,
        radius=radius,
        fractal_dim_surf=fractal_dim_surf,
        cutoff_length=cutoff_length,
    )
    return pars

tests = [
    # Accuracy tests based on content in test/utest_other_models.py
    [{'radius': 10.0,
      'fractal_dim_surf': 2.0,
      'cutoff_length': 500.0,
     }, 0.05, 301428.66016],

    # Additional tests with larger range of parameters
    [{'radius': 1.0,
      'fractal_dim_surf': 1.0,
      'cutoff_length': 10.0,
     }, 0.332070182643, 1125.00421004],

    [{'radius': 3.5,
      'fractal_dim_surf': 0.1,
      'cutoff_length': 30.0,
      'background': 0.01,
     }, 5.0, 0.00999998891322],

    [{'radius': 3.0,
      'fractal_dim_surf': 1.0,
      'cutoff_length': 33.0,
      'scale': 0.1,
     }, 0.51, 2.50120147004],
    ]