Changeset 62cf915 in sasmodels


Ignore:
Timestamp:
Apr 14, 2016 8:32:09 AM (9 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
3a45c2c, e78edc4
Parents:
81ec7c8
Message:

lint cleanup on adsorbed_layer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/adsorbed_layer.py

    rec45c4f r62cf915  
    33#converted by Steve King, Mar 2016 
    44 
     5r""" 
     6This model describes the scattering from a layer of surfactant or polymer 
     7adsorbed on large, smooth, notionally spherical particles under the conditions 
     8that (i) the particles (cores) are contrast-matched to the dispersion medium, 
     9(ii) $S(Q) \sim 1$ (ie, the particle volume fraction is dilute), (iii) the 
     10particle radius is >> layer thickness (ie, the interface is locally flat), 
     11and (iv) scattering from excess unadsorbed adsorbate in the bulk medium is 
     12absent or has been corrected for. 
    513 
    6  
    7 r""" 
    8 This model describes the scattering from a layer of surfactant or polymer adsorbed on large, smooth, notionally spherical particles under the conditions that (i) the particles (cores) are contrast-matched to the dispersion medium, (ii) *S(Q)* ~ 1 (ie, the particle volume fraction is dilute), (iii) the particle radius is >> layer thickness (ie, the interface is locally flat), and (iv) scattering from excess unadsorbed adsorbate in the bulk medium is absent or has been corrected for. 
    9  
    10 Unlike many other core-shell models, this model does not assume any form for the density distribution of the adsorbed species normal to the interface (cf, a core-shell model normally assumes the density distribution to be a homogeneous step-function). For comparison, if the thickness of a (traditional core-shell like) step function distribution is *t*, the second moment about the mean of the density distribution (ie, the distance of the centre-of-mass of the distribution from the interface), |sigma| =  sqrt((*t* :sup:`2` )/12). 
     14Unlike many other core-shell models, this model does not assume any form 
     15for the density distribution of the adsorbed species normal to the interface 
     16(cf, a core-shell model normally assumes the density distribution to be a 
     17homogeneous step-function). For comparison, if the thickness of a (traditional 
     18core-shell like) step function distribution is $t$, the second moment about 
     19the mean of the density distribution (ie, the distance of the centre-of-mass 
     20of the distribution from the interface), $\sigma = \sqrt{t^2/12}$. 
    1121 
    1222Definition 
     
    1525.. math:: 
    1626 
    17      I(q) = \text{scale} \cdot(\rho_\text{poly}-\rho_\text{solvent})^2    \left[\frac{6\pi\phi_\text{core}}{Q^2}\frac{\Gamma^2}{\delta_\text{poly}^2R_\text{core}} \exp(-Q^2\sigma^2)\right] + \text{background} 
     27     I(q) = \text{scale} \cdot (\rho_\text{poly}-\rho_\text{solvent})^2 
     28         \left[ 
     29             \frac{6\pi\phi_\text{core}}{Q^2} 
     30             \frac{\Gamma^2}{\delta_\text{poly}^2R_\text{core}} 
     31             \exp(-Q^2\sigma^2) 
     32         \right] + \text{background} 
    1833 
    19 where *scale* is a scale factor, |rho|\ :sub:`poly` is the sld of the polymer (or surfactant) layer, |rho|\ :sub:`solv` is the sld of the solvent/medium and cores, |phi|\ :sub:`core` is the volume fraction of the core particles, |delta|\ :sub:`poly` is the bulk density of the polymer, |biggamma| is the adsorbed amount, and |sigma| is the second moment of the thickness distribution. 
     34where *scale* is a scale factor, $\rho_\text{poly}$ is the sld of the 
     35polymer (or surfactant) layer, $\rho_\text{solv}$ is the sld of the 
     36solvent/medium and cores, $\phi_\text{core}$ is the volume fraction of 
     37the core particles, $\delta_\text{poly}$ is the bulk density of the 
     38polymer, $\Gamma$ is the adsorbed amount, and $\sigma$ is the second 
     39moment of the thickness distribution. 
    2040 
    21 Note that all parameters except the |sigma| are correlated so fitting more than one of these parameters will generally fail. Also note that unlike other shape models, no volume normalization is applied to this model (the calculation is exact). 
     41Note that all parameters except $\sigma$ are correlated so fitting more 
     42than one of these parameters will generally fail. Also note that unlike 
     43other shape models, no volume normalization is applied to this model (the 
     44calculation is exact). 
    2245 
    2346References 
    2447---------- 
    2548 
    26 S King, P Griffiths, J Hone, and T Cosgrove, *SANS from Adsorbed Polymer Layers*, 
    27 *Macromol. Symp.*, 190 (2002) 33-42. 
     49S King, P Griffiths, J Hone, and T Cosgrove, 
     50*SANS from Adsorbed Polymer Layers*, *Macromol. Symp.*, 190 (2002) 33-42. 
    2851""" 
    2952 
    3053from numpy import inf, sqrt, pi, exp 
    3154 
    32 name =  "adsorbed_layer" 
    33 title =  "Scattering from an adsorbed layer on particles" 
     55name = "adsorbed_layer" 
     56title = "Scattering from an adsorbed layer on particles" 
    3457 
    35 description =  """ 
     58description = """ 
    3659    Evaluates the scattering from large particles 
    3760    with an adsorbed layer of surfactant or 
     
    3962    density distribution. 
    4063    """ 
    41 category =  "shape:sphere" 
     64category = "shape:sphere" 
    4265 
     66# pylint: disable=bad-whitespace, line-too-long 
    4367#             ["name", "units", default, [lower, upper], "type", "description"], 
    44 parameters =  [["second_moment", "Ang", 23.0, [0.0, inf], "", "Second moment of polymer distribution"], 
    45               ["adsorbed_amount", "mg/m2", 1.9, [0.0, inf], "", "Adsorbed amount of polymer"], 
    46               ["density_shell", "g/cm3", 0.7, [0.0, inf], "", "Bulk density of polymer in the shell"], 
    47               ["radius", "Ang", 500.0, [0.0, inf], "", "Core particle radius"], 
    48               ["volfraction", "None", 0.14, [0.0, inf], "", "Core particle volume fraction"], 
    49               ["sld_shell", "1e-6/Ang^2", 1.5, [-inf, inf], "sld", "Polymer shell SLD"], 
    50               ["sld_solvent", "1e-6/Ang^2", 6.3, [-inf, inf], "sld", "Solvent SLD"]] 
     68parameters = [ 
     69    ["second_moment", "Ang", 23.0, [0.0, inf], "", "Second moment of polymer distribution"], 
     70    ["adsorbed_amount", "mg/m2", 1.9, [0.0, inf], "", "Adsorbed amount of polymer"], 
     71    ["density_shell", "g/cm3", 0.7, [0.0, inf], "", "Bulk density of polymer in the shell"], 
     72    ["radius", "Ang", 500.0, [0.0, inf], "", "Core particle radius"], 
     73    ["volfraction", "None", 0.14, [0.0, inf], "", "Core particle volume fraction"], 
     74    ["sld_shell", "1e-6/Ang^2", 1.5, [-inf, inf], "sld", "Polymer shell SLD"], 
     75    ["sld_solvent", "1e-6/Ang^2", 6.3, [-inf, inf], "sld", "Solvent SLD"], 
     76] 
     77# pylint: disable=bad-whitespace, line-too-long 
    5178 
    5279# NB: Scale and Background are implicit parameters on every model 
    53 def Iq(q, second_moment, adsorbed_amount, density_shell, radius,  
    54         volfraction, sld_shell, sld_solvent): 
     80def Iq(q, second_moment, adsorbed_amount, density_shell, radius, 
     81       volfraction, sld_shell, sld_solvent): 
    5582    # pylint: disable = missing-docstring 
    56 #    deltarhosqrd =  (sld_shell - sld_solvent) * (sld_shell - sld_solvent) 
    57 #    numerator =  6.0 * pi * volfraction * (adsorbed_amount * adsorbed_amount) 
    58 #    denominator =  (q * q) * (density_shell * density_shell) * radius 
    59 #    eterm =  exp(-1.0 * (q * q) * (second_moment * second_moment)) 
    60 #    #scale by 10^-2 for units conversion to cm^-1 
    61 #    inten =  1.0e-02 * deltarhosqrd * ((numerator / denominator) * eterm) 
    62     aa =  (sld_shell - sld_solvent) * adsorbed_amount / q / density_shell  
     83    #deltarhosqrd =  (sld_shell - sld_solvent) * (sld_shell - sld_solvent) 
     84    #numerator =  6.0 * pi * volfraction * (adsorbed_amount * adsorbed_amount) 
     85    #denominator =  (q * q) * (density_shell * density_shell) * radius 
     86    #eterm =  exp(-1.0 * (q * q) * (second_moment * second_moment)) 
     87    ##scale by 10^-2 for units conversion to cm^-1 
     88    #inten =  1.0e-02 * deltarhosqrd * ((numerator / denominator) * eterm) 
     89    aa = (sld_shell - sld_solvent) * adsorbed_amount / q / density_shell 
    6390    bb = q * second_moment 
    6491    #scale by 10^-2 for units conversion to cm^-1 
    65     inten =  6.0e-02 * pi * volfraction * aa * aa * exp(-bb * bb) / radius 
     92    inten = 6.0e-02 * pi * volfraction * aa * aa * exp(-bb * bb) / radius 
    6693    return inten 
    6794Iq.vectorized =  True  # Iq accepts an array of q values 
     
    7097    # pylint: disable = missing-docstring 
    7198    return Iq(sqrt(qx ** 2 + qy ** 2), *args) 
    72 Iqxy.vectorized =  True # Iqxy accepts an array of qx, qy values 
     99Iqxy.vectorized = True # Iqxy accepts an array of qx, qy values 
    73100 
    74 demo =  dict(scale = 1.0, 
    75             second_moment = 23.0, 
    76             adsorbed_amount = 1.9, 
    77             density_shell = 0.7, 
    78             radius = 500.0, 
    79             volfraction = 0.14, 
    80             sld_shell = 1.5, 
    81             sld_solvent = 6.3, 
    82             background = 0.0) 
     101# unit test values taken from SasView 3.1.2 
     102tests =  [ 
     103    [{'scale': 1.0, 'second_moment': 23.0, 'adsorbed_amount': 1.9, 
     104      'density_shell': 0.7, 'radius': 500.0, 'volfraction': 0.14, 
     105      'sld_shell': 1.5, 'sld_solvent': 6.3, 'background': 0.0}, 
     106     [0.0106939, 0.1], [73.741, 4.51684e-3]], 
     107] 
    83108 
    84 # these unit test values taken from SasView 3.1.2 
    85 tests =  [ 
    86     [{'scale': 1.0, 'second_moment': 23.0, 'adsorbed_amount': 1.9,  
    87      'density_shell': 0.7, 'radius': 500.0, 'volfraction': 0.14,  
    88      'sld_shell': 1.5, 'sld_solvent': 6.3, 'background': 0.0}, 
    89      [0.0106939, 0.1], [73.741, 4.51684e-3]], 
    90     ] 
    91 # ADDED by: SMK  ON: 16Mar2016  convert from sasview, check vs SANDRA, 18Mar2016 RKH some edits & renaming 
     109# 2016-03-16 SMK converted from sasview, checked vs SANDRA 
     110# 2016-03-18 RKH some edits & renaming 
     111# 2016-04-14 PAK reformatting 
Note: See TracChangeset for help on using the changeset viewer.