Changeset 284bdd4 in sasmodels


Ignore:
Timestamp:
Sep 25, 2018 9:11:42 PM (3 months ago)
Author:
butler
Branches:
master, beta_approx, cuda-test, py3, ticket-1015-gpu-mem-error, ticket-1015-quick-fix, ticket-1157, ticket-608-user-defined-weights, ticket_1156
Children:
2effdf6
Parents:
dd16e07
Message:

Fix docs and code for be_polyelectrolyte.py

Docs were fixed as explained in ticket #1155 as was the code. A
validation note was added to docs to indicate change and the fact that
full validation has not really been done. Also all unit tests that had
non-zero salt concentration values have been commented out till we
decide how to handle the change in terms of validating unit tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/be_polyelectrolyte.py

    ref07e95 r284bdd4  
    1111 
    1212    I(q) = K\frac{q^2+k^2}{4\pi L_b\alpha ^2} 
    13     \frac{1}{1+r_{0}^2(q^2+k^2)(q^2-12hC_a/b^2)} + background 
     13    \frac{1}{1+r_{0}^4(q^2+k^2)(q^2-12hC_a/b^2)} + background 
    1414 
    1515    k^2 = 4\pi L_b(2C_s + \alpha C_a) 
    1616 
    17     r_{0}^2 = \frac{1}{\alpha \sqrt{C_a} \left( b/\sqrt{48\pi L_b}\right)} 
     17    r_{0}^2 = \frac{b}{\alpha \sqrt{C_a 48\pi L_b}} 
    1818 
    1919where 
     
    3737kept constant for a given solvent and temperature! 
    3838 
    39 $h$ is the virial parameter (|Ang^3|/mol) - **Note:** See [#Borue]_ for the 
     39$h$ is the virial parameter (|Ang^3|) - **Note:** See [#Borue]_ for the 
    4040correct interpretation of this parameter.  It incorporates second and third 
    4141virial coefficients and can be Negative. 
    4242 
    4343$b$ is the monomer length(|Ang|), $C_s$ is the concentration of monovalent 
    44 salt(mol/L), $\alpha$ is the ionization degree (ionization degree : ratio of 
    45 charged monomers  to total number of monomers), $C_a$ is the polymer molar 
    46 concentration(mol/L), and $background$ is the incoherent background. 
     44salt(1/|Ang|- converted from mol/L), $\alpha$ is the ionization degree 
     45(ionization degree : ratio of charged monomers  to total number of monomers), 
     46$C_a$ is the polymer molar concentration(1/|Ang|- converted from mol/L), 
     47and $background$ is the incoherent background. 
    4748 
    4849For 2D data the scattering intensity is calculated in the same way as 1D, 
     
    5253 
    5354    q = \sqrt{q_x^2 + q_y^2} 
     55 
     56Validation 
     57---------- 
     58 
     59As of the last revision, this code is believed to be correct.  However it 
     60needs further validation and should be used with caution at this time.  The 
     61history of this code goes back to a 1998 implementation. It was recently noted 
     62that in that implementation, while both the polymer concentration and salt 
     63concentration were converted to units of 1/|Ang|, only the converted polymer 
     64concentraion was used in the calculation while the unconverted salt 
     65concentration was used.  This was carried through to sasmodles today (except 
     66that the conversion equation for the salt concentration was dropped somewhere 
     67along the line). Simple dimensional analysis of the calculation shows that the 
     68converted salt concentration must be used and the original code suggests that 
     69was the intention.  We therefore believe this is now correct.  Once better 
     70validation has been performed this note will be removed. 
    5471 
    5572References 
     
    6683 
    6784* **Author:** NIST IGOR/DANSE **Date:** pre 2010 
    68 * **Last Modified by:** Paul Kienzle **Date:** July 24, 2016 
    69 * **Last Reviewed by:** Paul Butler and Richard Heenan **Date:** October 07, 2016 
     85* **Last Modified by:** Paul Butler **Date:** September 25, 2018 
     86* **Last Reviewed by:** Paul Butler **Date:** September 25, 2018 
    7087""" 
    7188 
     
    92109    ["contrast_factor",       "barns",   10.0,  [-inf, inf], "", "Contrast factor of the polymer"], 
    93110    ["bjerrum_length",        "Ang",      7.1,  [0, inf],    "", "Bjerrum length"], 
    94     ["virial_param",          "Ang^3/mol", 12.0,  [-inf, inf], "", "Virial parameter"], 
     111    ["virial_param",          "Ang^3", 12.0,  [-inf, inf], "", "Virial parameter"], 
    95112    ["monomer_length",        "Ang",     10.0,  [0, inf],    "", "Monomer length"], 
    96113    ["salt_concentration",    "mol/L",    0.0,  [-inf, inf], "", "Concentration of monovalent salt"], 
     
    121138    """ 
    122139 
    123     concentration = polymer_concentration * 6.022136e-4 
    124  
    125     k_square = 4.0 * pi * bjerrum_length * (2*salt_concentration + 
    126                                             ionization_degree * concentration) 
    127  
    128     r0_square = 1.0/ionization_degree/sqrt(concentration) * \ 
     140    concentration_pol = polymer_concentration * 6.022136e-4 
     141    concentration_salt = salt_concentration * 6.022136e-4 
     142 
     143    k_square = 4.0 * pi * bjerrum_length * (2*concentration_salt + 
     144                                            ionization_degree * concentration_pol) 
     145 
     146    r0_square = 1.0/ionization_degree/sqrt(concentration_pol) * \ 
    129147                (monomer_length/sqrt((48.0*pi*bjerrum_length))) 
    130148 
     
    133151 
    134152    term2 = 1.0 + r0_square**2 * (q**2 + k_square) * \ 
    135         (q**2 - (12.0 * virial_param * concentration/(monomer_length**2))) 
     153        (q**2 - (12.0 * virial_param * concentration_pol/(monomer_length**2))) 
    136154 
    137155    return term1/term2 
     
    184202     }, 0.001, 0.0948379], 
    185203 
    186     # Additional tests with larger range of parameters 
    187     [{'contrast_factor':       10.0, 
    188       'bjerrum_length':       100.0, 
    189       'virial_param':           3.0, 
    190       'monomer_length':         1.0, 
    191       'salt_concentration':    10.0, 
    192       'ionization_degree':      2.0, 
    193       'polymer_concentration': 10.0, 
    194       'background':             0.0, 
    195      }, 0.1, -3.75693800588], 
    196  
    197     [{'contrast_factor':       10.0, 
    198       'bjerrum_length':       100.0, 
    199       'virial_param':           3.0, 
    200       'monomer_length':         1.0, 
    201       'salt_concentration':    10.0, 
    202       'ionization_degree':      2.0, 
    203       'polymer_concentration': 10.0, 
    204       'background':           100.0 
    205      }, 5.0, 100.029142149], 
    206  
    207     [{'contrast_factor':     100.0, 
    208       'bjerrum_length':       10.0, 
    209       'virial_param':        180.0, 
    210       'monomer_length':        1.0, 
    211       'salt_concentration':    0.1, 
    212       'ionization_degree':     0.5, 
    213       'polymer_concentration': 0.1, 
    214       'background':             0.0, 
    215      }, 200., 1.80664667511e-06], 
     204    #Comment out rest of tests as they use non zero salt concentrations. With 
     205    #the new code the results will change. We can just take the answer the code 
     206    #gives and call it correct but not sure that is appropriate.  May however 
     207    #be the best we can do? How were these generated in the first place? 
     208    #In the meantime comment them out.  
     209    #Additional tests with larger range of parameters 
     210#    [{'contrast_factor':       10.0, 
     211#      'bjerrum_length':       100.0, 
     212#      'virial_param':           3.0, 
     213#      'monomer_length':         1.0, 
     214#      'salt_concentration':    10.0, 
     215#      'ionization_degree':      2.0, 
     216#      'polymer_concentration': 10.0, 
     217#      'background':             0.0, 
     218#     }, 0.1, -3.75693800588], 
     219 
     220#    [{'contrast_factor':       10.0, 
     221#      'bjerrum_length':       100.0, 
     222#      'virial_param':           3.0, 
     223#      'monomer_length':         1.0, 
     224#      'salt_concentration':    10.0, 
     225#      'ionization_degree':      2.0, 
     226#      'polymer_concentration': 10.0, 
     227#      'background':           100.0 
     228#     }, 5.0, 100.029142149], 
     229# 
     230#    [{'contrast_factor':     100.0, 
     231#      'bjerrum_length':       10.0, 
     232#      'virial_param':        180.0, 
     233#      'monomer_length':        1.0, 
     234#      'salt_concentration':    0.1, 
     235#      'ionization_degree':     0.5, 
     236#      'polymer_concentration': 0.1, 
     237#      'background':             0.0, 
     238#     }, 200., 1.80664667511e-06], 
    216239    ] 
Note: See TracChangeset for help on using the changeset viewer.