# Changeset 9616dfe in sasmodels

Ignore:
Timestamp:
Mar 11, 2018 2:31:50 PM (4 years ago)
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
331870d
Parents:
dbf1a60 (diff), bf94e6e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into ticket-896

Files:
7 edited
1 moved

Unmodified
Removed
• ## example/multiscatfit.py

 rbc248f8 from sasmodels.data import load_data, set_beam_stop, set_top from multiscat import MultipleScattering from sasmodels.multiscat import MultipleScattering ## Load the data #data = load_data('DEC07267.DAT') #set_beam_stop(data, 0.003, outer=0.025) data = load_data('latex_smeared.xml', index=1) data = load_data('latex_smeared.xml', index=0) ## Define the model # Mulitple scattering probability parameter # HACK: the parameter is assigned to model.theta, which is otherwise unused # since the dataset is 1D; this won't work for 2D data # HACK: the probability is stuffed in as an extra parameter to the experiment. probability = Parameter(name="probability", value=0.0) probability.range(0.0, 0.9) model.phi = probability M = Experiment(data=data, model=model) M = Experiment(data=data, model=model, extra_pars={'probability': probability}) # Stack mulitple scattering on top of the existing resolution function.
• ## sasmodels/bumps_model.py

 r2d81cfe """ _cache = None # type: Dict[str, np.ndarray] def __init__(self, data, model, cutoff=1e-5, name=None): def __init__(self, data, model, cutoff=1e-5, name=None, extra_pars=None): # type: (Data, Model, float) -> None # remember inputs so we can inspect from outside self._interpret_data(data, model.sasmodel) self._cache = {} self.extra_pars = extra_pars def update(self): Return a dictionary of parameters """ return self.model.parameters() pars = self.model.parameters() if self.extra_pars: pars.update(self.extra_pars) return pars def theory(self):
• ## sasmodels/kerneldll.py

 r2d81cfe return CC + [source, "-o", output, "-lm"] # Windows-specific solution if os.name == 'nt': # Assume the default location of module DLLs is in .sasmodels/compiled_models. DLL_PATH = os.path.join(os.path.expanduser("~"), ".sasmodels", "compiled_models") if not os.path.exists(DLL_PATH): os.makedirs(DLL_PATH) else: # Set up the default path for compiled modules. DLL_PATH = tempfile.gettempdir() # Assume the default location of module DLLs is in .sasmodels/compiled_models. DLL_PATH = os.path.join(os.path.expanduser("~"), ".sasmodels", "compiled_models") ALLOW_SINGLE_PRECISION_DLLS = True Set *sasmodels.kerneldll.DLL_PATH* to the compiled dll output path. The default is the system temporary directory. The default is in ~/.sasmodels/compiled_models. """ if dtype == F16: need_recompile = dll_time < newest_source if need_recompile: # Make sure the DLL path exists if not os.path.exists(DLL_PATH): os.makedirs(DLL_PATH) basename = splitext(os.path.basename(dll))[0] + "_" system_fd, filename = tempfile.mkstemp(suffix=".c", prefix=basename)
• ## sasmodels/multiscat.py

 rbc248f8 frame = np.fft.ifft2(F_convolved) result = scale * _inverse_shift(frame.real, dtype=self.dtype) #print("multiscat time", time.time()-t0) #print("numpy multiscat time", time.time()-t0) return result #result = scale * _inverse_shift(frame.real, dtype=self.dtype) result = scale * _inverse_shift(frame.real, dtype=self.dtype) #print("multiscat time", time.time()-t0) #print("OpenCL multiscat time", time.time()-t0) return result
• ## sasmodels/models/core_shell_parallelepiped.c

 re077231 // outer integral (with gauss points), integration limits = 0, 1 // substitute d_cos_alpha for sin_alpha d_alpha double outer_sum = 0; //initialize integral for( int i=0; i
• ## sasmodels/models/core_shell_parallelepiped.py

 r97be877 .. math:: I(q) = \text{scale}\frac{\langle f^2 \rangle}{V} + \text{background} I(q) = \frac{\text{scale}}{V} \langle P(q,\alpha,\beta) \rangle + \text{background} where $\langle \ldots \rangle$ is an average over all possible orientations of the rectangular solid. The function calculated is the form factor of the rectangular solid below. of the rectangular solid, and the usual $\Delta \rho^2 \ V^2$ term cannot be pulled out of the form factor term due to the multiple slds in the model. The core of the solid is defined by the dimensions $A$, $B$, $C$ such that $A < B < C$. .. image:: img/core_shell_parallelepiped_geometry.jpg .. figure:: img/parallelepiped_geometry.jpg Core of the core shell Parallelepiped with the corresponding definition of sides. There are rectangular "slabs" of thickness $t_A$ that add to the $A$ dimension (on the $BC$ faces). There are similar slabs on the $AC$ $(=t_B)$ and $AB$ $(=t_C)$ faces. The projection in the $AB$ plane is then .. image:: img/core_shell_parallelepiped_projection.jpg The volume of the solid is $(=t_C)$ faces. The projection in the $AB$ plane is .. figure:: img/core_shell_parallelepiped_projection.jpg AB cut through the core-shell parllelipiped showing the cross secion of four of the six shell slabs. As can be seen This model leaves **"gaps"** at the corners of the solid. The total volume of the solid is thus given as .. math:: V = ABC + 2t_ABC + 2t_BAC + 2t_CAB **meaning that there are "gaps" at the corners of the solid.** The intensity calculated follows the :ref:parallelepiped model, with the core-shell intensity being calculated as the square of the sum of the amplitudes of the core and the slabs on the edges. the scattering amplitude is computed for a particular orientation of the core-shell parallelepiped with respect to the scattering vector and then averaged over all possible orientations, where $\alpha$ is the angle between the $z$ axis and the $C$ axis of the parallelepiped, $\beta$ is the angle between projection of the particle in the $xy$ detector plane and the $y$ axis. .. math:: F(Q) amplitudes of the core and the slabs on the edges. The scattering amplitude is computed for a particular orientation of the core-shell parallelepiped with respect to the scattering vector and then averaged over all possible orientations, where $\alpha$ is the angle between the $z$ axis and the $C$ axis of the parallelepiped, and $\beta$ is the angle between the projection of the particle in the $xy$ detector plane and the $y$ axis. .. math:: P(q)=\frac {\int_{0}^{\pi/2}\int_{0}^{\pi/2}F^2(q,\alpha,\beta) \ sin\alpha \ d\alpha \ d\beta} {\int_{0}^{\pi/2} \ sin\alpha \ d\alpha \ d\beta} and .. math:: F(q,\alpha,\beta) &= (\rho_\text{core}-\rho_\text{solvent}) S(Q_A, A) S(Q_B, B) S(Q_C, C) \\ &+ (\rho_\text{A}-\rho_\text{solvent}) \left[S(Q_A, A+2t_A) - S(Q_A, Q)\right] S(Q_B, B) S(Q_C, C) \\ \left[S(Q_A, A+2t_A) - S(Q_A, A)\right] S(Q_B, B) S(Q_C, C) \\ &+ (\rho_\text{B}-\rho_\text{solvent}) S(Q_A, A) \left[S(Q_B, B+2t_B) - S(Q_B, B)\right] S(Q_C, C) \\ .. math:: S(Q, L) = L \frac{\sin \tfrac{1}{2} Q L}{\tfrac{1}{2} Q L} S(Q_X, L) = L \frac{\sin \tfrac{1}{2} Q_X L}{\tfrac{1}{2} Q_X L} and .. math:: Q_A &= \sin\alpha \sin\beta \\ Q_B &= \sin\alpha \cos\beta \\ Q_C &= \cos\alpha Q_A &= q \sin\alpha \sin\beta \\ Q_B &= q \sin\alpha \cos\beta \\ Q_C &= q \cos\alpha is the scattering length of the solvent. .. note:: the code actually implements two substitutions: $d(cos\alpha)$ is substituted for -$sin\alpha \ d\alpha$ (note that in the :ref:parallelepiped code this is explicitly implemented with $\sigma = cos\alpha$), and $\beta$ is set to $\beta = u \pi/2$ so that $du = \pi/2 \ d\beta$.  Thus both integrals go from 0 to 1 rather than 0 to $\pi/2$. FITTING NOTES ~~~~~~~~~~~~~ and length $(C+2t_C)$ values, after appropriately sorting the three dimensions to give an oblate or prolate particle, to give an effective radius, for $S(Q)$ when $P(Q) * S(Q)$ is applied. for $S(q)$ when $P(q) * S(q)$ is applied. For 2d data the orientation of the particle is required, described using $\Psi = 0$ when the *short_b* axis is parallel to the *x*-axis of the detector. For 2d, constraints must be applied during fitting to ensure that the inequality $A < B < C$ is not violated, and hence the correct definition of angles is preserved. The calculation will not report an error, but the results may be not correct. .. note:: For 2d, constraints must be applied during fitting to ensure that the inequality $A < B < C$ is not violated, and hence the correct definition of angles is preserved. The calculation will not report an error, but the results may be not correct. .. figure:: img/parallelepiped_angle_definition.png
• ## sasmodels/models/parallelepiped.c

 r108e70e inner_total += GAUSS_W[j] * square(si1 * si2); } // now complete change of inner integration variable (1-0)/(1-(-1))= 0.5 inner_total *= 0.5; outer_total += GAUSS_W[i] * inner_total * si * si; } // now complete change of outer integration variable (1-0)/(1-(-1))= 0.5 outer_total *= 0.5;
• ## sasmodels/models/parallelepiped.py

 ref07e95 This model calculates the scattering from a rectangular parallelepiped (\:numref:parallelepiped-image\). (:numref:parallelepiped-image). If you need to apply polydispersity, see also :ref:rectangular-prism. I(q) = \frac{\text{scale}}{V} (\Delta\rho \cdot V)^2 \left< P(q, \alpha) \right> + \text{background} \left< P(q, \alpha, \beta) \right> + \text{background} where the volume $V = A B C$, the contrast is defined as $\Delta\rho = \rho_\text{p} - \rho_\text{solvent}$, $P(q, \alpha)$ is the form factor corresponding to a parallelepiped oriented at an angle $\alpha$ (angle between the long axis C and $\vec q$), and the averaging $\left<\ldots\right>$ is applied over all orientations. $\Delta\rho = \rho_\text{p} - \rho_\text{solvent}$, $P(q, \alpha, \beta)$ is the form factor corresponding to a parallelepiped oriented at an angle $\alpha$ (angle between the long axis C and $\vec q$), and $\beta$ ( the angle between the projection of the particle in the $xy$ detector plane and the $y$ axis) and the averaging $\left<\ldots\right>$ is applied over all orientations. Assuming $a = A/B < 1$, $b = B /B = 1$, and $c = C/B > 1$, the form factor is given by (Mittelbach and Porod, 1961) form factor is given by (Mittelbach and Porod, 1961 [#Mittelbach]_) .. math:: \mu &= qB The scattering intensity per unit volume is returned in units of |cm^-1|. where substitution of $\sigma = cos\alpha$ and $\beta = \pi/2 \ u$ have been applied. NB: The 2nd virial coefficient of the parallelepiped is calculated based on .. math:: P(q_x, q_y) = \left[\frac{\sin(\tfrac{1}{2}qA\cos\alpha)}{(\tfrac{1}{2}qA\cos\alpha)}\right]^2 \left[\frac{\sin(\tfrac{1}{2}qB\cos\beta)}{(\tfrac{1}{2}qB\cos\beta)}\right]^2 \left[\frac{\sin(\tfrac{1}{2}qC\cos\gamma)}{(\tfrac{1}{2}qC\cos\gamma)}\right]^2 P(q_x, q_y) = \left[\frac{\sin(\tfrac{1}{2}qA\cos\alpha)}{(\tfrac{1} {2}qA\cos\alpha)}\right]^2 \left[\frac{\sin(\tfrac{1}{2}qB\cos\beta)}{(\tfrac{1} {2}qB\cos\beta)}\right]^2 \left[\frac{\sin(\tfrac{1}{2}qC\cos\gamma)}{(\tfrac{1} {2}qC\cos\gamma)}\right]^2 with ---------- P Mittelbach and G Porod, *Acta Physica Austriaca*, 14 (1961) 185-211 R Nayuk and K Huber, *Z. Phys. Chem.*, 226 (2012) 837-854 .. [#Mittelbach] P Mittelbach and G Porod, *Acta Physica Austriaca*, 14 (1961) 185-211 .. [#] R Nayuk and K Huber, *Z. Phys. Chem.*, 226 (2012) 837-854 Authorship and Verification
Note: See TracChangeset for help on using the changeset viewer.