source: sasmodels/sasmodels/models/hayter_msa.py @ ef07e95

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

lint

  • Property mode set to 100644
File size: 5.6 KB
Line 
1# Note: model title and parameter table are inserted automatically
2r"""
3This calculates the structure factor (the Fourier transform of the pair
4correlation function $g(r)$) for a system of charged, spheroidal objects
5in a dielectric medium. When combined with an appropriate form factor
6(such as sphere, core+shell, ellipsoid, etc), this allows for inclusion
7of the interparticle interference effects due to screened coulomb repulsion
8between charged particles.
9
10**This routine only works for charged particles**. If the charge is set to
11zero the routine may self-destruct! For non-charged particles use a hard
12sphere potential.
13
14The salt concentration is used to compute the ionic strength of the solution
15which in turn is used to compute the Debye screening length. At present
16there is no provision for entering the ionic strength directly nor for use
17of any multivalent salts, though it should be possible to simulate the effect
18of this by increasing the salt concentration. The counterions are also
19assumed to be monovalent.
20
21In sasview the effective radius may be calculated from the parameters
22used in the form factor $P(q)$ that this $S(q)$ is combined with.
23
24The computation uses a Taylor series expansion at very small rescaled $qR$, to
25avoid some serious rounding error issues, this may result in a minor artefact
26in the transition region under some circumstances.
27
28For 2D data, the scattering intensity is calculated in the same way as 1D,
29where the $q$ vector is defined as
30
31.. math::
32
33    q = \sqrt{q_x^2 + q_y^2}
34
35
36References
37----------
38
39J B Hayter and J Penfold, *Molecular Physics*, 42 (1981) 109-118
40
41J P Hansen and J B Hayter, *Molecular Physics*, 46 (1982) 651-656
42"""
43
44import numpy as np
45from numpy import inf
46
47category = "structure-factor"
48structure_factor = True
49single = False  # double precision only!
50
51#  dp[0] = 2.0*radius_effective();
52#  dp[1] = fabs(charge());
53#  dp[2] = volfraction();
54#  dp[3] = temperature();
55#  dp[4] = concentration_salt();
56#  dp[5] = dielectconst();
57
58
59
60
61name = "hayter_msa"
62title = "Hayter-Penfold rescaled MSA, charged sphere, interparticle S(Q) structure factor"
63description = """\
64    [Hayter-Penfold RMSA charged sphere interparticle S(Q) structure factor]
65        Interparticle structure factor S(Q)for a charged hard spheres.
66        Routine takes absolute value of charge, use HardSphere if charge
67        goes to zero.
68        In sasview the effective radius and volume fraction may be calculated
69        from the parameters used in P(Q).
70"""
71
72
73# pylint: disable=bad-whitespace, line-too-long
74#             [ "name", "units", default, [lower, upper], "type", "description" ],
75parameters = [
76    ["radius_effective", "Ang", 20.75,   [0, inf],    "volume", "effective radius of charged sphere"],
77    ["volfraction",   "None",     0.0192, [0, 0.74],   "", "volume fraction of spheres"],
78    ["charge",        "e",   19.0,    [0, 200],    "", "charge on sphere (in electrons)"],
79    ["temperature",   "K",  318.16,   [0, 450],    "", "temperature, in Kelvin, for Debye length calculation"],
80    ["concentration_salt",      "M",    0.0,    [0, inf], "", "conc of salt, moles/litre, 1:1 electolyte, for Debye length"],
81    ["dielectconst",  "None",    71.08,   [-inf, inf], "", "dielectric constant (relative permittivity) of solvent, default water, for Debye length"]
82    ]
83# pylint: enable=bad-whitespace, line-too-long
84
85source = ["hayter_msa.c"]
86# No volume normalization despite having a volume parameter
87# This should perhaps be volume normalized?
88form_volume = """
89    return 1.0;
90    """
91# ER defaults to 0.0
92# VR defaults to 1.0
93
94def random():
95    # TODO: too many failures for random hayter_msa parameters
96    pars = dict(
97        scale=1, background=0,
98        radius_effective=10**np.random.uniform(1, 4.7),
99        volfraction=10**np.random.uniform(-2, 0),  # high volume fraction
100        charge=min(int(10**np.random.uniform(0, 1.3)+0.5), 200),
101        temperature=10**np.random.uniform(0, np.log10(450)), # max T = 450
102        #concentration_salt=10**np.random.uniform(-3, 1),
103        dialectconst=10**np.random.uniform(0, 6),
104        #charge=10,
105        #temperature=318.16,
106        concentration_salt=0.0,
107        #dielectconst=71.08,
108    )
109    return pars
110
111# default parameter set,  use  compare.sh -midQ -linear
112# note the calculation varies in different limiting cases so a wide range of
113# parameters will be required for a thorough test!
114# odd that the default st has concentration_salt zero
115demo = dict(radius_effective=20.75,
116            charge=19.0,
117            volfraction=0.0192,
118            temperature=318.16,
119            concentration_salt=0.05,
120            dielectconst=71.08,
121            radius_effective_pd=0.1,
122            radius_effective_pd_n=40)
123#
124# attempt to use same values as old sasview unit test at Q=.001 was 0.0712928,
125# then add lots new ones assuming values from new model are OK, need some
126# low Q values to test the small Q Taylor expansion
127tests = [
128    [{'scale': 1.0,
129      'background': 0.0,
130      'radius_effective': 20.75,
131      'charge': 19.0,
132      'volfraction': 0.0192,
133      'temperature': 298.0,
134      'concentration_salt': 0,
135      'dielectconst': 78.0,
136      'radius_effective_pd': 0},
137     [0.00001, 0.0010, 0.01, 0.075], [0.0711646, 0.0712928, 0.0847006, 1.07150]],
138    [{'scale': 1.0,
139      'background': 0.0,
140      'radius_effective': 20.75,
141      'charge': 19.0,
142      'volfraction': 0.0192,
143      'temperature': 298.0,
144      'concentration_salt': 0.05,
145      'dielectconst': 78.0,
146      'radius_effective_pd': 0.1,
147      'radius_effective_pd_n': 40},
148     [0.00001, 0.0010, 0.01, 0.075], [0.450272, 0.450420, 0.465116, 1.039625]]
149    ]
150# ADDED by:  RKH  ON: 16Mar2016 converted from sasview, new Taylor expansion at smallest rescaled Q
Note: See TracBrowser for help on using the repository browser.