File: correlation_length.py

package info (click to toggle)
mccode 3.5.19%2Bds5-2
  • links: PTS, VCS
  • area: main
  • in suites: 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 (75 lines) | stat: -rw-r--r-- 2,903 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
#correlation length model
# Note: model title and parameter table are inserted automatically
r"""
Definition
----------

The scattering intensity I(q) is calculated as

.. math::
    I(Q) = \frac{A}{Q^n} + \frac{C}{1 + (Q\xi)^m} + \text{background}

The first term describes Porod scattering from clusters (exponent = $n$) and
the second term is a Lorentzian function describing scattering from
polymer chains (exponent = $m$). This second term characterizes the
polymer/solvent interactions and therefore the thermodynamics. The two
multiplicative factors $A$ and $C$, and the two exponents $n$ and $m$ are
used as fitting parameters. (Respectively *porod_scale*, *lorentz_scale*,
*porod_exp* and *lorentz_exp* in the parameter list.) The remaining
parameter $\xi$ (*cor_length* in the parameter list) is a correlation
length for the polymer chains. Note that when $m=2$ this functional form
becomes the familiar Lorentzian function. Some interpretation of the
values of $A$ and $C$ may be possible depending on the values of $m$ and $n$.

For 2D data: The 2D scattering intensity is calculated in the same way as 1D,
where the q vector is defined as

.. math::  q = \sqrt{q_x^2 + q_y^2}

References
----------

#. B Hammouda, D L Ho and S R Kline, Insight into Clustering in
   Poly(ethylene oxide) Solutions, Macromolecules, 37 (2004) 6932-6937

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

* **Author:** NIST IGOR/DANSE **Date:** pre 2010
* **Last Modified by:** Steve King **Date:** September 24, 2019
* **Last Reviewed by:**
"""

from numpy import inf, errstate

name = "correlation_length"
title = """Calculates an empirical functional form for SAS data characterized
by a low-Q signal and a high-Q signal."""
description = """
"""
category = "shape-independent"
# pylint: disable=bad-continuation, line-too-long
#             ["name", "units", default, [lower, upper], "type","description"],
parameters = [
              ["lorentz_scale", "", 10.0, [0, inf], "", "Lorentzian Scaling Factor"],
              ["porod_scale", "", 1e-06, [0, inf], "", "Porod Scaling Factor"],
              ["cor_length", "Ang", 50.0, [0, inf], "", "Correlation length, xi, in Lorentzian"],
              ["porod_exp", "", 3.0, [0, inf], "", "Porod Exponent, n, in q^-n"],
              ["lorentz_exp", "", 2.0, [0, inf], "", "Lorentzian Exponent, m, in 1/( 1 + (q.xi)^m)"],
             ]
# pylint: enable=bad-continuation, line-too-long

def Iq(q, lorentz_scale, porod_scale, cor_length, porod_exp, lorentz_exp):
    """
    1D calculation of the Correlation length model
    """
    with errstate(divide='ignore'):
        porod = porod_scale / q**porod_exp
        lorentz = lorentz_scale / (1.0 + (q * cor_length)**lorentz_exp)
    inten = porod + lorentz
    return inten
Iq.vectorized = True

tests = [[{}, 0.001, 1009.98],
         [{}, 0.150141, 0.175645],
         [{}, 0.442528, 0.0213957]]