source: sasmodels/sasmodels/models/flexible_cylinder.py @ e53b881

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since e53b881 was e53b881, checked in by smk78, 5 years ago

Clarifications to model help whilst considering #1240

  • Property mode set to 100644
File size: 6.2 KB
Line 
1r"""
2This model provides the form factor, $P(q)$, for a flexible cylinder
3where the form factor is normalized by the volume of the cylinder.
4**Inter-cylinder interactions are NOT provided for.**
5
6.. math::
7
8    P(q) = \text{scale} \left<F^2\right>/V + \text{background}
9
10where the averaging $\left<\ldots\right>$ is applied only for the 1D
11calculation
12
13The 2D scattering intensity is the same as 1D, regardless of the orientation of
14the q vector which is defined as
15
16.. math::
17
18    q = \sqrt{q_x^2 + q_y^2}
19
20Definitions
21-----------
22
23.. figure:: img/flexible_cylinder_geometry.jpg
24
25
26The chain of contour length, $L$, (the total length) can be described as a
27chain of some number of locally stiff segments of length $l_p$, the persistence
28length (the length along the cylinder over which the flexible cylinder can be
29considered a rigid rod).
30The Kuhn length $(b = 2*l_p)$ is also used to describe the stiffness of a chain.
31
32In the parameters, the sld and sld\_solvent represent the SLD of the cylinder
33and solvent respectively.
34
35Our model uses the form factor calculations in reference [1] as implemented in a
36c-library provided by the NIST Center for Neutron Research (Kline, 2006). This states:
37
38    'Method 3 With Excluded Volume' is used.
39    The model is a parametrization of simulations of a discrete representation
40    of the worm-like chain model of Kratky and Porod applied in the
41    pseudocontinuous limit.
42    See equations (13,26-27) in the original reference for the details.
43
44**This is a model with complex behaviour depending on the ratio of** $L/b$ **and the
45reader is strongly encouraged to read reference [1] before use.**
46
47References
48----------
49
50.. [#] J S Pedersen and P Schurtenberger. *Scattering functions of semiflexible polymers with and without excluded volume effects.* Macromolecules, 29 (1996) 7602-7612
51
52Correction of the formula can be found in
53
54.. [#] W R Chen, P D Butler and L J Magid, *Incorporating Intermicellar Interactions in the Fitting of SANS Data from Cationic Wormlike Micelles.* Langmuir, 22(15) 2006 6539-6548
55
56Source
57------
58
59`flexible_cylinder.py <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/flexible_cylinder.py>`_
60
61`flexible_cylinder.c <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/flexible_cylinder.c>`_
62
63Authorship and Verification
64----------------------------
65
66* **Author:**
67* **Last Modified by:**
68* **Last Reviewed by:**
69* **Source added by :** Steve King **Date:** March 25, 2019
70"""
71
72import numpy as np
73from numpy import inf
74
75name = "flexible_cylinder"
76title = "Flexible cylinder where the form factor is normalized by the volume " \
77        "of the cylinder."
78description = """Note : scale and contrast = (sld - sld_solvent) are both
79                multiplicative factors in the model and are perfectly
80                correlated. One or both of these parameters must be held fixed
81                during model fitting.
82              """
83
84category = "shape:cylinder"
85single = False  # double precision only!
86
87# pylint: disable=bad-whitespace, line-too-long
88#             ["name", "units", default, [lower, upper], "type", "description"],
89parameters = [
90    ["length",      "Ang",       1000.0, [0, inf],    "volume", "Length of the flexible cylinder"],
91    ["kuhn_length", "Ang",        100.0, [0, inf],    "volume", "Kuhn length of the flexible cylinder"],
92    ["radius",      "Ang",         20.0, [0, inf],    "volume", "Radius of the flexible cylinder"],
93    ["sld",         "1e-6/Ang^2",   1.0, [-inf, inf], "sld",    "Cylinder scattering length density"],
94    ["sld_solvent", "1e-6/Ang^2",   6.3, [-inf, inf], "sld",    "Solvent scattering length density"],
95    ]
96# pylint: enable=bad-whitespace, line-too-long
97source = ["lib/polevl.c", "lib/sas_J1.c", "lib/wrc_cyl.c", "flexible_cylinder.c"]
98
99def random():
100    """Return a random parameter set for the model."""
101    length = 10**np.random.uniform(2, 6)
102    radius = 10**np.random.uniform(1, 3)
103    kuhn_length = 10**np.random.uniform(-2, 0)*length
104    pars = dict(
105        length=length,
106        radius=radius,
107        kuhn_length=kuhn_length,
108    )
109    return pars
110
111tests = [
112    # Accuracy tests based on content in test/utest_other_models.py
113    [{'length':     1000.0,  # test T1
114      'kuhn_length': 100.0,
115      'radius':       20.0,
116      'sld':           1.0,
117      'sld_solvent':   6.3,
118      'background':    0.0001,
119     }, 0.001, 3509.2187],
120
121    # Additional tests with larger range of parameters
122    [{'length':    1000.0,  # test T2
123      'kuhn_length': 100.0,
124      'radius':       20.0,
125      'sld':           1.0,
126      'sld_solvent':   6.3,
127      'background':    0.0001,
128     }, 1.0, 0.000595345],
129    [{'length':        10.0,  # test T3
130      'kuhn_length': 800.0,
131      'radius':        2.0,
132      'sld':           6.0,
133      'sld_solvent':  12.3,
134      'background':    0.001,
135     }, 0.1, 1.55228],
136    [{'length':        100.0,  # test T4
137      'kuhn_length': 800.0,
138      'radius':       50.0,
139      'sld':           0.1,
140      'sld_solvent':   5.1,
141      'background':    0.0,
142     }, 1.0, 0.000938456]
143    ]
144
145# There are a few branches in the code that ought to have test values:
146#
147# For length > 4 * kuhn_length
148#        if length > 10 * kuhn_length then C is scaled by 3.06 (L/b)^(-0.44)
149#        q*kuhn_length <= 3.1  => Sexv_new
150#           dS/dQ < 0 has different behaviour from dS/dQ >= 0
151#  T2    q*kuhn_length > 3.1   => a_long
152#
153# For length <= 4 * kuhn_length
154#        q*kuhn_length <= max(1.9/Rg_short, 3.0)  => Sdebye((q*Rg)^2)
155#           q*Rg < 0.5 uses Pade approx, q*Rg > 1.0 uses math lib
156#  T3,T4 q*kuhn_length > max(1.9/Rg_short, 3.0)   => a_short
157#
158# Note that the transitions between branches may be abrupt.  You can see a
159# several percent change around length=10*kuhn_length and length=4*kuhn_length
160# using the following:
161#
162#    sascomp flexible_cylinder -calc=double -sets=10 length=10*kuhn_length,10.000001*kuhn_length
163#    sascomp flexible_cylinder -calc=double -sets=10 length=4*kuhn_length,4.000001*kuhn_length
164#
165# The transition between low q and high q around q*kuhn_length = 3 seems
166# to be good to 4 digits or better.  This was tested by computing the value
167# on each branches near the transition point and reporting the relative error
168# for kuhn lengths of 10, 100 and 1000 and a variety of length:kuhn_length
169# ratios.
Note: See TracBrowser for help on using the repository browser.