## 5 Layer Core Shell Disc - five_layer_core_shell_bicelle.py

    #Last update: January 24, 2021

r"""
Definition
----------

This model calculates the form factor for a core-shell circular cylinder. The core includes
three layers, two methylene and one methyl, which creates a five-layer model when combined
with the two headgroup layers. The shell on the walls and ends of the model can be of
different thicknesses and scattering length densities. Normalization of the form factor
is done using the particle volume. Cylindrical symmetry is assumed for this model.

Given the scattering length densities (sld) $\rho_{mlene}$, the methylene sld, $\rho_{myl}$,
the methyl sld, $\rho_f$, the face sld, $\rho_r$, the rim sld and $\rho_s$ the solvent sld,
the scattering length density variation along the cylinder axis is:

\begin{align}
\rho(r) =
\begin{cases}
&\rho_{mlene} \text{ for } 0 \lt r \lt R; -L_c/2 \lt z\lt L_c/2 \\[1.5ex]
&\rho_{myl} \text{ for } 0 \lt r \lt R; -L_{myl}/2 \lt z\lt L_{myl}/2 \\[1.5ex]
&\rho_f \text{ for } 0 \lt r \lt R; -(L_c+2t_f)/2 \lt z\lt -L; L \lt z\lt (L_c+2t_f)/2 \\[1.5ex]
&\rho_r\text{ for } R \lt r \lt R+t_r; -(L_c+2t_f)/2 \lt z\lt -L; L \lt z\lt (L_c+2t_f)/2
\end{cases}
\end{align}

Cylindrical coordinates are used for this model, where $\alpha$ is the angle between the
$Q$ vector and the cylinder axis, to give:

\begin{align}
I(Q,\alpha) = \frac{\text{scale}}{V_t} \cdot
F(Q,\alpha)^2.sin(\alpha) + \text{background}
\end{align}

where

.. math::

\begin{align}
F(Q,\alpha) = &\bigg[
(\rho_{myl} - \rho_{mlene}) V_{myl} \frac{2J_1(QRsin\alpha)}{QRsin\alpha}\frac{sin(Q(L_{myl})cos\alpha/2)}{Q(L_{myl}/2)cos\alpha} \\
&+(\rho_{mlene} - \rho_f) V_c \frac{2J_1(QRsin\alpha)}{QRsin\alpha}\frac{sin(QL_ccos\alpha/2)}{Q(L_c/2)cos\alpha} \\
&+(\rho_f - \rho_r) V_{c+f} \frac{2J_1(QRsin\alpha)}{QRsin\alpha}\frac{sin(Q(L_c/2+t_f)cos\alpha)}{Q(L_c/2+t_f)cos\alpha} \\
&+(\rho_r - \rho_s) V_t \frac{2J_1(Q(R+t_r)sin\alpha)}{Q(R+t_r)sin\alpha}\frac{sin(Q(L_c/2+t_f)cos\alpha)}{Q(L_c/2+t_f)cos\alpha}
\bigg]
\end{align}
\begin{align}
L_c = &\bigg[
2L_{mlene}+L_{myl}
\bigg]
\end{align}

where $V_t$ is the total volume of the bicelle, $V_c$ the volume of the core,
$V_{c+f}$ the volume of the core plus the volume of the faces, $R$ is the radius
of the core, $L_c$ the length of the core, $L_{mlene} is the length of the methylene layer,$L_{myl}$the length of the methyl layer,$t_f$the thickness of the face,$t_r$the thickness of the rim and$J_1$the usual first order bessel function. The 1D scattering intensity for randomly oriented cylinders is calculated by integrating over all possible$\theta$and$\phi\$.

The 1D output does not use the *theta* and *phi* parameters. The scattering kernel
and the 1D scattering intensity use the c-library from NIST.

References
----------

.. [#] D Singh (2009). *Small angle scattering studies of self assembly in
lipid mixtures*, John's Hopkins University Thesis (2009) 223-225. Available
from Proquest <http://search.proquest.com/docview/304915826?accountid
=26379>_
[#] C Cheu, L Yang, M P Nieh (2020). *Refining internal bilayer structure of bicelles resolved
by extended-q small angle X-ray scattering*, Chemistry and Physics of Lipids, 231
(2020) 104945.

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

* **Author:** Catherine Cheu **Date:** 2019
"""

from numpy import inf, sin, cos

name = "five_layer_core_shell_bicelle"
title = "Circular cylinder with a three-layer core-shell scattering length density profiles.."
description = """
P(q,alpha)= (scale/Vs)*f(q)^(2) + bkg,  where:
f(q)= Vt(sld_rim - sld_solvent)* sin[qLt.cos(alpha)/2]
/[qLt.cos(alpha)/2]*J1(qRout.sin(alpha))
/[qRout.sin(alpha)]+
2*(sld_methylene-sld_face)*Vl1*sin[qLccos(alpha)/2][[qLc
*cos(alpha)/2]*J1(qRc.sin(alpha))
/qRc.sin(alpha)]+
(sld_methyl-sld_methylene)*Vl2*sin[qlength2cos(alpha)/2][[qlength2
*cos(alpha)/2]*J1(qRc.sin(alpha))
/qRc.sin(alpha)]
(sld_face-sld_rim)*(Vl1+Vl2+Vf)*sin[q(Lc+2.thick_face).
cos(alpha)/2][[q(Lc+2.thick_face)*cos(alpha)/2]*
J1(qRc.sin(alpha))/qRc.sin(alpha)]

alpha:is the angle between the axis of
the cylinder and the q-vector
Vt = pi.(Rc + thick_rim)^2.Lt : total volume
Vl1 = pi.Rc^2.(2.length1 + length2) :the volume of the core
Vl2 = pi.Rc^2.length2 :the volume of the methyl group
Vf = 2.pi.Rc^2.thick_face : the volume of the face
Rc = radius: the core radius
Lc = 2.length1 + length2: the length of the core
Lt = Lc + 2.thick_face: total length
length1: thickness of methylene group
length2: thickness of methyl group
thick_face: thickness of face
thick_rim: thickness of rim
Rout = radius + thick_rim
sld_methylene, sld_methyl, sld_rim, sld_face:scattering length
densities within the particle
sld_solvent: the scattering length density
of the solvent
bkg: the background
J1: the first order Bessel function
theta: axis_theta of the cylinder
phi: the axis_phi of the cylinder...
"""
category = "shape:cylinder"

# pylint: disable=bad-whitespace, line-too-long
#             ["name", "units", default, [lower, upper], "type", "description"],
parameters = [
["radius",         "Ang",       80, [0, inf],    "volume",      "Cylinder core radius"],
["thick_rim",  "Ang",       10, [0, inf],    "volume",      "Rim shell thickness"],
["thick_face", "Ang",       10, [0, inf],    "volume",      "Cylinder face thickness"],
["methylene_length",         "Ang",      25, [0, inf],    "volume",      "Methylene length of one side"],
["methyl_length",         "Ang",      0, [0, inf],    "volume",      "Methyl core length"],
["sld_methylene",       "1e-6/Ang^2", 1, [-inf, inf], "sld",         "Methylene scattering length density"],
["sld_methyl",       "1e-6/Ang^2", 1, [-inf, inf], "sld",         "Methyl core scattering length density"],
["sld_face",       "1e-6/Ang^2", 4, [-inf, inf], "sld",         "Cylinder face scattering length density"],
["sld_rim",        "1e-6/Ang^2", 4, [-inf, inf], "sld",         "Cylinder rim scattering length density"],
["sld_solvent",    "1e-6/Ang^2", 1, [-inf, inf], "sld",         "Solvent scattering length density"],
["theta",          "degrees",   90, [-inf, inf], "orientation", "In plane angle"],
["phi",            "degrees",    0, [-inf, inf], "orientation", "Out of plane angle"],
]

# pylint: enable=bad-whitespace, line-too-long

source = ["lib/sas_Si.c", "lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c",
"five_layer_core_shell_bicelle.c"]

demo = dict(scale=1, background=0,
radius=20.0,
thick_rim=10.0,
thick_face=10.0,
methylene_length=100.0,
methyl_length = 200.0,
sld_methylene=1.0,
sld_methyl=1.0,
sld_face=4.0,
sld_rim=4.0,
sld_solvent=1.0,
theta=90,
phi=0)

#qx, qy = 0.4 * cos(pi/2.0), 0.5 * sin(0)