<commit_before>r"""
Polydispersity in the bilayer thickness can be applied from the GUI.

Definition
----------

The scattering intensity $I(q)$ is

.. math::

    I(q) = \frac{2\pi P(q)}{\delta q^2}


The form factor is

.. math::

    P(q) = \frac{2\Delta\rho^2}{q^2}(1-cos(q\delta))


where $\delta$ is the bilayer thickness.

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
----------

<NAME>, <NAME>, and <NAME>, J. Phys. II France, 3, (1993) 487-502

also in J. Phys. Chem. B, 105, (2001) 11081-11088


"""

from numpy import inf

name = "lamellar"
title = "Lyotropic lamellar phase with uniform SLD and random distribution"
description = """\
    [Dilute Lamellar Form Factor](from a lyotropic lamellar phase)
        I(q)= 2*pi*P(q)/(delta *q^(2)), where
        P(q)=2*(contrast/q)^(2)*(1-cos(q*delta))^(2))
        thickness = layer thickness
        sld = layer scattering length density
        sld_solvent = solvent scattering length density
        background = incoherent background
        scale = scale factor
"""
category = "shape:lamellae"

#             ["name", "units", default, [lower, upper], "type","description"],
parameters = [["sld", "1e-6/Ang^2", 1, [-inf, inf], "",
               "Layer scattering length density" ],
              ["solvent_sld", "1e-6/Ang^2", 6, [-inf, inf], "",
               "Solvent scattering length density" ],
              ["thickness", "Ang", 50, [0, inf], "volume","Bilayer thickness" ],
             ]


# No volume normalization despite having a volume parameter
# This should perhaps be volume normalized?
form_volume = """
    return 1.0;
    """

Iq = """
    const double sub = sld - solvent_sld;
    const double qsq = q*q;
    // Original expression
    //return 4.0e-4*M_PI*sub*sub/qsq * (1.0-cos(q*thickness)) / (thickness*qsq);
    // const double alpha = fmod(q*thickness+0.1, 2.0*M_PI)-0.1;
    // Use small angle fix 1-cos(theta) = 2 sin^2(theta/2)
    const double sinq2 = sin(0.5*q*thickness);
    return 4.0e-4*M_PI*sub*sub/qsq * 2.0*sinq2*sinq2 / (thickness*qsq);
    """

Iqxy = """
    return Iq(sqrt(qx*qx+qy*qy), IQ_PARAMETERS);
    """

# ER defaults to 0.0
# VR defaults to 1.0

demo = dict(scale=1, background=0,
            sld=6, solvent_sld=1,
            thickness=40,
            thickness_pd=0.2, thickness_pd_n=40)
oldname = 'LamellarModel'
oldpars = dict(sld='sld_bi', solvent_sld='sld_sol', thickness='bi_thick')
tests = [
        [ {'scale': 1.0, 'background' : 0.0, 'thickness' : 50.0, 'sld' : 1.0,'solvent_sld' : 6.3, 'thickness_pd' : 0.0, 
           }, [0.001], [882289.54309]]
        ]
# ADDED by: converted by PAK? (or RKH?)     ON: 16Mar2016 - RKH adding unit tests from sasview to early 2015 conversion
#  [(qx1, qy1), (qx2, qy2), ...], [I(qx1,qy1), I(qx2,qy2), ...]],<commit_msg>checked lamellar, reordered params, improved docs<commit_after>r"""
Polydispersity in the bilayer thickness can be applied from the GUI.

Definition
----------

The scattering intensity $I(q)$ for dilute, randomly oriented, "infinitely large" sheets or lamellae is

.. math::

    I(q) = scale*\frac{2\pi P(q)}{q^2\delta }


The form factor is

.. math::

   P(q) = \frac{2\Delta\rho^2}{q^2}(1-cos(q\delta)) = \frac{4\Delta\rho^2}{q^2}sin^2(\frac{q\delta}{2})

where $\delta$ is the total layer thickness and $\Delta\rho$ is the scattering length density difference.

This is the limiting form for a spherical shell of infinitely large radius. Note that the division by $\delta$
means that $scale$ in sasview is the volume fraction of sheet, $\phi = S\delta$ where $S$ is the area of 
sheet per unit volume. $S$ is half the Porod surface area per unit volume of a thicker layer (as that would 
include both faces of the sheet).

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
----------

<NAME>, <NAME>, and <NAME>, J. Phys. II France, 3, (1993) 487-502

also in J. Phys. Chem. B, 105, (2001) 11081-11088


"""

from numpy import inf

name = "lamellar"
title = "Lyotropic lamellar phase with uniform SLD and random distribution"
description = """\
    [Dilute Lamellar Form Factor](from a lyotropic lamellar phase)
        I(q)= 2*pi*P(q)/(delta *q^(2)), where
        P(q)=2*(contrast/q)^(2)*(1-cos(q*delta))^(2))
        thickness = layer thickness
        sld = layer scattering length density
        sld_solvent = solvent scattering length density
        background = incoherent background
        scale = scale factor
"""
category = "shape:lamellae"

#             ["name", "units", default, [lower, upper], "type","description"],
parameters = [ ["thickness", "Ang", 50, [0, inf], "volume","total layer thickness" ],
               ["sld", "1e-6/Ang^2", 1, [-inf, inf], "","Layer scattering length density" ],
               ["sld_solvent", "1e-6/Ang^2", 6, [-inf, inf], "","Solvent scattering length density" ],
             ]

# No volume normalization despite having a volume parameter
# This should perhaps be volume normalized? - it is!
form_volume = """
    return 1.0;
    """

Iq = """
    const double sub = sld - sld_solvent;
    const double qsq = q*q;
    // Original expression
    //return 4.0e-4*M_PI*sub*sub/qsq * (1.0-cos(q*thickness)) / (thickness*qsq);
    // const double alpha = fmod(q*thickness+0.1, 2.0*M_PI)-0.1;
    // Use small angle fix 1-cos(theta) = 2 sin^2(theta/2)
    const double sinq2 = sin(0.5*q*thickness);
    return 4.0e-4*M_PI*sub*sub/qsq * 2.0*sinq2*sinq2 / (thickness*qsq);
    """

Iqxy = """
    return Iq(sqrt(qx*qx+qy*qy), IQ_PARAMETERS);
    """

# ER defaults to 0.0
# VR defaults to 1.0

demo = dict(scale=1, background=0,
            sld=6, sld_solvent=1,
            thickness=40,
            thickness_pd=0.2, thickness_pd_n=40)
oldname = 'LamellarModel'
oldpars = dict(sld='sld_bi', sld_solvent='sld_sol', thickness='bi_thick')
tests = [
        [ {'scale': 1.0, 'background' : 0.0, 'thickness' : 50.0, 'sld' : 1.0,'sld_solvent' : 6.3, 'thickness_pd' : 0.0, 
           }, [0.001], [882289.54309]]
        ]
# ADDED by: converted by PAK? (or RKH?)     ON: 16Mar2016 - RKH adding unit tests from sasview to early 2015 conversion
#  [(qx1, qy1), (qx2, qy2), ...], [I(qx1,qy1), I(qx2,qy2), ...]],
{'fraction_non_alphanumeric': 0.1647763074984247, 'fraction_numerical': 0.045526149968494016, 'mean_word_length': 2.975579211020664, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3193874', 'n_tokens_mistral': 2480, 'n_tokens_neox': 2253, 'n_words': 653}