[8ad9619] | 1 | r""" |
---|
[af0e70c] | 2 | This model calculates an empirical functional form for SAS data using |
---|
| 3 | SpericalSLD profile |
---|
| 4 | |
---|
| 5 | Similarly to the OnionExpShellModel, this model provides the form factor, |
---|
| 6 | P(q), for a multi-shell sphere, where the interface between the each neighboring |
---|
| 7 | shells can be described by one of a number of functions including error, |
---|
| 8 | power-law, and exponential functions. |
---|
| 9 | This model is to calculate the scattering intensity by building a continuous |
---|
| 10 | custom SLD profile against the radius of the particle. |
---|
| 11 | The SLD profile is composed of a flat core, a flat solvent, a number (up to 9 ) |
---|
| 12 | flat shells, and the interfacial layers between the adjacent flat shells |
---|
| 13 | (or core, and solvent) (see below). |
---|
[8ad9619] | 14 | |
---|
| 15 | .. figure:: img/spherical_sld_profile.gif |
---|
| 16 | |
---|
| 17 | Exemplary SLD profile |
---|
| 18 | |
---|
[af0e70c] | 19 | Unlike the <onion> model (using an analytical integration), the interfacial |
---|
| 20 | layers here are sub-divided and numerically integrated assuming each of the |
---|
| 21 | sub-layers are described by a line function. |
---|
| 22 | The number of the sub-layer can be given by users by setting the integer values |
---|
| 23 | of npts_inter. The form factor is normalized by the total volume of the sphere. |
---|
[8ad9619] | 24 | |
---|
| 25 | Definition |
---|
| 26 | ---------- |
---|
| 27 | |
---|
| 28 | The form factor $P(q)$ in 1D is calculated by: |
---|
| 29 | |
---|
| 30 | .. math:: |
---|
| 31 | |
---|
| 32 | P(q) = \frac{f^2}{V_\text{particle}} \text{ where } |
---|
| 33 | f = f_\text{core} + \sum_{\text{inter}_i=0}^N f_{\text{inter}_i} + |
---|
| 34 | \sum_{\text{flat}_i=0}^N f_{\text{flat}_i} +f_\text{solvent} |
---|
| 35 | |
---|
[af0e70c] | 36 | For a spherically symmetric particle with a particle density $\rho_x(r)$ |
---|
| 37 | the sld function can be defined as: |
---|
[8ad9619] | 38 | |
---|
| 39 | .. math:: |
---|
| 40 | |
---|
| 41 | f_x = 4 \pi \int_{0}^{\infty} \rho_x(r) \frac{\sin(qr)} {qr^2} r^2 dr |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | so that individual terms can be calcualted as follows: |
---|
| 45 | |
---|
| 46 | .. math:: |
---|
[af0e70c] | 47 | f_\text{core} = 4 \pi \int_{0}^{r_\text{core}} \rho_\text{core} |
---|
| 48 | \frac{\sin(qr)} {qr} r^2 dr = |
---|
[8ad9619] | 49 | 3 \rho_\text{core} V(r_\text{core}) |
---|
[af0e70c] | 50 | \Big[ \frac{\sin(qr_\text{core}) - qr_\text{core} \cos(qr_\text{core})} |
---|
| 51 | {qr_\text{core}^3} \Big] |
---|
| 52 | |
---|
| 53 | f_{\text{inter}_i} = 4 \pi \int_{\Delta t_{ \text{inter}_i } } |
---|
| 54 | \rho_{ \text{inter}_i } \frac{\sin(qr)} {qr} r^2 dr |
---|
| 55 | |
---|
| 56 | f_{\text{shell}_i} = 4 \pi \int_{\Delta t_{ \text{inter}_i } } |
---|
| 57 | \rho_{ \text{flat}_i } \frac{\sin(qr)} {qr} r^2 dr = |
---|
| 58 | 3 \rho_{ \text{flat}_i } V ( r_{ \text{inter}_i } + |
---|
| 59 | \Delta t_{ \text{inter}_i } ) |
---|
| 60 | \Big[ \frac{\sin(qr_{\text{inter}_i} + \Delta t_{ \text{inter}_i } ) |
---|
| 61 | - q (r_{\text{inter}_i} + \Delta t_{ \text{inter}_i }) |
---|
| 62 | \cos(q( r_{\text{inter}_i} + \Delta t_{ \text{inter}_i } ) ) } |
---|
[8ad9619] | 63 | {q ( r_{\text{inter}_i} + \Delta t_{ \text{inter}_i } )^3 } \Big] |
---|
| 64 | -3 \rho_{ \text{flat}_i } V(r_{ \text{inter}_i }) |
---|
[af0e70c] | 65 | \Big[ \frac{\sin(qr_{\text{inter}_i}) - qr_{\text{flat}_i} |
---|
| 66 | \cos(qr_{\text{inter}_i}) } {qr_{\text{inter}_i}^3} \Big] |
---|
[8ad9619] | 67 | |
---|
[af0e70c] | 68 | f_\text{solvent} = 4 \pi \int_{r_N}^{\infty} \rho_\text{solvent} |
---|
| 69 | \frac{\sin(qr)} {qr} r^2 dr = |
---|
[8ad9619] | 70 | 3 \rho_\text{solvent} V(r_N) |
---|
| 71 | \Big[ \frac{\sin(qr_N) - qr_N \cos(qr_N)} {qr_N^3} \Big] |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | Here we assumed that the SLDs of the core and solvent are constant against $r$. |
---|
| 75 | The SLD at the interface between shells, $\rho_{\text {inter}_i}$ |
---|
| 76 | is calculated with a function chosen by an user, where the functions are |
---|
| 77 | |
---|
| 78 | Exp: |
---|
| 79 | |
---|
| 80 | .. math:: |
---|
| 81 | \rho_{{inter}_i} (r) = \begin{cases} |
---|
[af0e70c] | 82 | B \exp\Big( \frac {\pm A(r - r_{\text{flat}_i})} |
---|
| 83 | {\Delta t_{ \text{inter}_i }} \Big) +C & \text{for} A \neq 0 \\ |
---|
| 84 | B \Big( \frac {(r - r_{\text{flat}_i})} |
---|
| 85 | {\Delta t_{ \text{inter}_i }} \Big) +C & \text{for} A = 0 \\ |
---|
[8ad9619] | 86 | \end{cases} |
---|
| 87 | |
---|
| 88 | Power-Law |
---|
| 89 | |
---|
| 90 | .. math:: |
---|
| 91 | \rho_{{inter}_i} (r) = \begin{cases} |
---|
[af0e70c] | 92 | \pm B \Big( \frac {(r - r_{\text{flat}_i} )} {\Delta t_{ \text{inter}_i }} |
---|
| 93 | \Big) ^A +C & \text{for} A \neq 0 \\ |
---|
[8ad9619] | 94 | \rho_{\text{flat}_{i+1}} & \text{for} A = 0 \\ |
---|
| 95 | \end{cases} |
---|
| 96 | |
---|
| 97 | Erf: |
---|
| 98 | |
---|
| 99 | .. math:: |
---|
| 100 | \rho_{{inter}_i} (r) = \begin{cases} |
---|
[af0e70c] | 101 | B \text{erf} \Big( \frac { A(r - r_{\text{flat}_i})} |
---|
| 102 | {\sqrt{2} \Delta t_{ \text{inter}_i }} \Big) +C & \text{for} A \neq 0 \\ |
---|
| 103 | B \Big( \frac {(r - r_{\text{flat}_i} )} {\Delta t_{ \text{inter}_i }} |
---|
| 104 | \Big) +C & \text{for} A = 0 \\ |
---|
[8ad9619] | 105 | \end{cases} |
---|
| 106 | |
---|
[af0e70c] | 107 | The functions are normalized so that they vary between 0 and 1, and they are |
---|
| 108 | constrained such that the SLD is continuous at the boundaries of the interface |
---|
| 109 | as well as each sub-layers. Thus B and C are determined. |
---|
[8ad9619] | 110 | |
---|
[af0e70c] | 111 | Once $\rho_{\text{inter}_i}$ is found at the boundary of the sub-layer of the |
---|
| 112 | interface, we can find its contribution to the form factor $P(q)$ |
---|
[8ad9619] | 113 | |
---|
| 114 | .. math:: |
---|
[af0e70c] | 115 | f_{\text{inter}_i} = 4 \pi \int_{\Delta t_{ \text{inter}_i } } |
---|
| 116 | \rho_{ \text{inter}_i } \frac{\sin(qr)} {qr} r^2 dr = |
---|
[8ad9619] | 117 | 4 \pi \sum_{j=0}^{npts_{\text{inter}_i} -1 } |
---|
[af0e70c] | 118 | \int_{r_j}^{r_{j+1}} \rho_{ \text{inter}_i } (r_j) |
---|
| 119 | \frac{\sin(qr)} {qr} r^2 dr \approx |
---|
[8ad9619] | 120 | |
---|
| 121 | 4 \pi \sum_{j=0}^{npts_{\text{inter}_i} -1 } \Big[ |
---|
[af0e70c] | 122 | 3 ( \rho_{ \text{inter}_i } ( r_{j+1} ) - \rho_{ \text{inter}_i } |
---|
| 123 | ( r_{j} ) V ( r_{ \text{sublayer}_j } ) |
---|
| 124 | \Big[ \frac {r_j^2 \beta_\text{out}^2 \sin(\beta_\text{out}) |
---|
| 125 | - (\beta_\text{out}^2-2) \cos(\beta_\text{out}) } |
---|
[8ad9619] | 126 | {\beta_\text{out}^4 } \Big] |
---|
| 127 | |
---|
[af0e70c] | 128 | - 3 ( \rho_{ \text{inter}_i } ( r_{j+1} ) - \rho_{ \text{inter}_i } |
---|
| 129 | ( r_{j} ) V ( r_{ \text{sublayer}_j-1 } ) |
---|
| 130 | \Big[ \frac {r_{j-1}^2 \sin(\beta_\text{in}) |
---|
| 131 | - (\beta_\text{in}^2-2) \cos(\beta_\text{in}) } |
---|
[8ad9619] | 132 | {\beta_\text{in}^4 } \Big] |
---|
| 133 | |
---|
| 134 | + 3 \rho_{ \text{inter}_i } ( r_{j+1} ) V ( r_j ) |
---|
| 135 | \Big[ \frac {\sin(\beta_\text{out}) - \cos(\beta_\text{out}) } |
---|
| 136 | {\beta_\text{out}^4 } \Big] |
---|
| 137 | |
---|
| 138 | - 3 \rho_{ \text{inter}_i } ( r_{j} ) V ( r_j ) |
---|
| 139 | \Big[ \frac {\sin(\beta_\text{in}) - \cos(\beta_\text{in}) } |
---|
| 140 | {\beta_\text{in}^4 } \Big] |
---|
| 141 | \Big] |
---|
| 142 | |
---|
| 143 | where |
---|
| 144 | |
---|
| 145 | .. math:: |
---|
| 146 | V(a) = \frac {4\pi}{3}a^3 |
---|
| 147 | |
---|
[af0e70c] | 148 | a_\text{in} ~ \frac{r_j}{r_{j+1} -r_j} \text{, } a_\text{out} |
---|
| 149 | ~ \frac{r_{j+1}}{r_{j+1} -r_j} |
---|
[8ad9619] | 150 | |
---|
| 151 | \beta_\text{in} = qr_j \text{, } \beta_\text{out} = qr_{j+1} |
---|
| 152 | |
---|
| 153 | |
---|
[af0e70c] | 154 | We assume the $\rho_{\text{inter}_i} (r)$ can be approximately linear |
---|
| 155 | within a sub-layer $j$ |
---|
[8ad9619] | 156 | |
---|
| 157 | Finally form factor can be calculated by |
---|
| 158 | |
---|
| 159 | .. math:: |
---|
| 160 | |
---|
[af0e70c] | 161 | P(q) = \frac{[f]^2} {V_\text{particle}} \text{where} V_\text{particle} |
---|
| 162 | = V(r_{\text{shell}_N}) |
---|
[8ad9619] | 163 | |
---|
| 164 | For 2D data the scattering intensity is calculated in the same way as 1D, |
---|
| 165 | where the $q$ vector is defined as |
---|
| 166 | |
---|
| 167 | .. math:: |
---|
| 168 | |
---|
| 169 | q = \sqrt{q_x^2 + q_y^2} |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | .. figure:: img/spherical_sld_1d.jpg |
---|
| 173 | |
---|
| 174 | 1D plot using the default values (w/400 data point). |
---|
| 175 | |
---|
| 176 | .. figure:: img/spherical_sld_default_profile.jpg |
---|
| 177 | |
---|
| 178 | SLD profile from the default values. |
---|
| 179 | |
---|
| 180 | .. note:: |
---|
[af0e70c] | 181 | The outer most radius is used as the effective radius for S(Q) |
---|
| 182 | when $P(Q) * S(Q)$ is applied. |
---|
[8ad9619] | 183 | |
---|
| 184 | References |
---|
| 185 | ---------- |
---|
[af0e70c] | 186 | L A Feigin and D I Svergun, Structure Analysis by Small-Angle X-Ray |
---|
| 187 | and Neutron Scattering, Plenum Press, New York, (1987) |
---|
[8ad9619] | 188 | |
---|
| 189 | """ |
---|
| 190 | |
---|
[24d5b30] | 191 | import numpy as np |
---|
[8ad9619] | 192 | from numpy import inf |
---|
| 193 | |
---|
| 194 | name = "spherical_sld" |
---|
| 195 | title = "Sperical SLD intensity calculation" |
---|
| 196 | description = """ |
---|
| 197 | I(q) = |
---|
| 198 | background = Incoherent background [1/cm] |
---|
| 199 | """ |
---|
| 200 | category = "sphere-based" |
---|
| 201 | |
---|
| 202 | # pylint: disable=bad-whitespace, line-too-long |
---|
| 203 | # ["name", "units", default, [lower, upper], "type", "description"], |
---|
[af0e70c] | 204 | parameters = [["n_shells", "", 1, [0, 9], "volume", "number of shells"], |
---|
| 205 | ["npts_inter", "", 35, [0, inf], "", "number of points in each sublayer Must be odd number"], |
---|
| 206 | ["radius_core", "Ang", 50.0, [0, inf], "volume", "intern layer thickness"], |
---|
| 207 | ["sld_core", "1e-6/Ang^2", 2.07, [-inf, inf], "", "sld function flat"], |
---|
| 208 | ["sld_solvent", "1e-6/Ang^2", 1.0, [-inf, inf], "", "sld function solvent"], |
---|
| 209 | ["func_inter0", "", 0, [0, 4], "", "Erf:0, RPower:1, LPower:2, RExp:3, LExp:4"], |
---|
| 210 | ["thick_inter0", "Ang", 50.0, [0, inf], "volume", "intern layer thickness for core layer"], |
---|
| 211 | ["nu_inter0", "", 2.5, [-inf, inf], "", "steepness parameter for core layer"], |
---|
[4605bf10] | 212 | ["sld_flat[n_shells]", "1e-6/Ang^2", 4.06, [-inf, inf], "", "sld function flat"], |
---|
[af0e70c] | 213 | ["thick_flat[n_shells]", "Ang", 100.0, [0, inf], "volume", "flat layer_thickness"], |
---|
[4605bf10] | 214 | ["func_inter[n_shells]", "", 0, [0, 4], "", "Erf:0, RPower:1, LPower:2, RExp:3, LExp:4"], |
---|
[af0e70c] | 215 | ["thick_inter[n_shells]", "Ang", 50.0, [0, inf], "volume", "intern layer thickness"], |
---|
[4605bf10] | 216 | ["nu_inter[n_shells]", "", 2.5, [-inf, inf], "", "steepness parameter"], |
---|
[8ad9619] | 217 | ] |
---|
| 218 | # pylint: enable=bad-whitespace, line-too-long |
---|
[eb97b11] | 219 | source = ["lib/librefl.c", "lib/sph_j1c.c", "spherical_sld.c"] |
---|
| 220 | |
---|
[af0e70c] | 221 | profile_axes = ['Radius (A)', 'SLD (1e-6/A^2)'] |
---|
[eb97b11] | 222 | def profile(n_shells, radius_core, sld_core, sld_solvent, sld_flat, |
---|
| 223 | thick_flat, func_inter, thick_inter, nu_inter, npts_inter): |
---|
| 224 | """ |
---|
| 225 | Returns shape profile with x=radius, y=SLD. |
---|
| 226 | """ |
---|
| 227 | |
---|
| 228 | z = [] |
---|
| 229 | beta = [] |
---|
| 230 | z0 = 0 |
---|
| 231 | # two sld points for core |
---|
| 232 | z.append(0) |
---|
| 233 | beta.append(sld_core) |
---|
| 234 | z.append(radius_core) |
---|
| 235 | beta.append(sld_core) |
---|
| 236 | z0 += radius_core |
---|
| 237 | |
---|
| 238 | for i in range(1, n_shells+2): |
---|
| 239 | dz = thick_inter[i-1]/npts_inter |
---|
| 240 | # j=0 for interface, j=1 for flat layer |
---|
| 241 | for j in range(0, 2): |
---|
| 242 | # interation for sub-layers |
---|
| 243 | for n_s in range(0, npts_inter+1): |
---|
| 244 | if j == 1: |
---|
| 245 | if i == n_shells+1: |
---|
| 246 | break |
---|
| 247 | # shift half sub thickness for the first point |
---|
| 248 | z0 -= dz#/2.0 |
---|
[4605bf10] | 249 | z.append(z0) |
---|
| 250 | #z0 -= dz/2.0 |
---|
| 251 | z0 += thick_flat[i] |
---|
| 252 | sld_i = sld_flat[i] |
---|
| 253 | beta.append(sld_flat[i]) |
---|
| 254 | dz = 0 |
---|
| 255 | else: |
---|
| 256 | nu = nu_inter[i-1] |
---|
| 257 | # decide which sld is which, sld_r or sld_l |
---|
| 258 | if i == 1: |
---|
| 259 | sld_l = sld_core |
---|
[eb97b11] | 260 | else: |
---|
[4605bf10] | 261 | sld_l = sld_flat[i-1] |
---|
| 262 | if i == n_shells+1: |
---|
| 263 | sld_r = sld_solvent |
---|
| 264 | else: |
---|
| 265 | sld_r = sld_flat[i] |
---|
| 266 | # get function type |
---|
| 267 | func_idx = func_inter[i-1] |
---|
| 268 | # calculate the sld |
---|
| 269 | sld_i = intersldfunc(func_idx, npts_inter, n_s, nu, |
---|
[eb97b11] | 270 | sld_l, sld_r) |
---|
[4605bf10] | 271 | # append to the list |
---|
| 272 | z.append(z0) |
---|
| 273 | beta.append(sld_i) |
---|
| 274 | z0 += dz |
---|
| 275 | if j == 1: |
---|
| 276 | break |
---|
[eb97b11] | 277 | z.append(z0) |
---|
| 278 | beta.append(sld_solvent) |
---|
| 279 | z_ext = z0/5.0 |
---|
| 280 | z.append(z0+z_ext) |
---|
| 281 | beta.append(sld_solvent) |
---|
| 282 | # return sld profile (r, beta) |
---|
| 283 | return np.asarray(z), np.asarray(beta)*1e-6 |
---|
| 284 | |
---|
[dd71228] | 285 | def ER(n_shells, radius_core, thick_inter0, thick_inter, thick_flat): |
---|
| 286 | total_thickness = thick_inter0 |
---|
| 287 | total_thickness += np.sum(thick_inter[:n_shells], axis=0) |
---|
| 288 | total_thickness += np.sum(thick_flat[:n_shells], axis=0) |
---|
| 289 | return total_thickness + radius_core |
---|
[669bf21] | 290 | |
---|
[8ad9619] | 291 | |
---|
[1bf66d9] | 292 | demo = { |
---|
[af0e70c] | 293 | "n_shells": 4, |
---|
| 294 | "npts_inter": 35.0, |
---|
| 295 | "radius_core": 50.0, |
---|
| 296 | "sld_core": 2.07, |
---|
[1bf66d9] | 297 | "sld_solvent": 1.0, |
---|
[af0e70c] | 298 | "thick_inter0": 50.0, |
---|
| 299 | "func_inter0": 0, |
---|
| 300 | "nu_inter0": 2.5, |
---|
| 301 | "sld_flat":[4.0,3.5,4.0,3.5], |
---|
| 302 | "thick_flat":[100.0,100.0,100.0,100.0], |
---|
| 303 | "func_inter":[0,0,0,0], |
---|
| 304 | "thick_inter":[50.0,50.0,50.0,50.0], |
---|
| 305 | "nu_inter":[2.5,2.5,2.5,2.5], |
---|
[1bf66d9] | 306 | } |
---|
[8ad9619] | 307 | |
---|
| 308 | #TODO: Not working yet |
---|
| 309 | tests = [ |
---|
| 310 | # Accuracy tests based on content in test/utest_extra_models.py |
---|
[af0e70c] | 311 | [{"n_shells":4, |
---|
| 312 | 'npts_inter':35, |
---|
| 313 | "radius_core":50.0, |
---|
| 314 | "sld_core":2.07, |
---|
| 315 | "sld_solvent": 1.0, |
---|
| 316 | "sld_flat":[4.0,3.5,4.0,3.5], |
---|
| 317 | "thick_flat":[100.0,100.0,100.0,100.0], |
---|
| 318 | "func_inter":[0,0,0,0], |
---|
| 319 | "thick_inter":[50.0,50.0,50.0,50.0], |
---|
| 320 | "nu_inter":[2.5,2.5,2.5,2.5] |
---|
[6f0e04f] | 321 | }, 0.001, 0.001], |
---|
[8ad9619] | 322 | ] |
---|