Changeset 108e70e in sasmodels for doc


Ignore:
Timestamp:
Dec 14, 2017 3:08:45 PM (6 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
ef85a09
Parents:
df69efa
Message:

use Iqac/Iqabc? for the new orientation interface but Iqxy for the old

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/guide/plugin.rst

    rd0dc9a3 r108e70e  
    292292**Note: The order of the parameters in the definition will be the order of the 
    293293parameters in the user interface and the order of the parameters in Iq(), 
    294 Iqxy() and form_volume(). And** *scale* **and** *background* **parameters are 
    295 implicit to all models, so they do not need to be included in the parameter table.** 
     294Iqac(), Iqabc() and form_volume(). And** *scale* **and** *background* 
     295**parameters are implicit to all models, so they do not need to be included 
     296in the parameter table.** 
    296297 
    297298- **"name"** is the name of the parameter shown on the FitPage. 
     
    362363    scattered intensity. 
    363364 
    364   - "volume" parameters are passed to Iq(), Iqxy(), and form_volume(), and 
    365     have polydispersity loops generated automatically. 
    366  
    367   - "orientation" parameters are only passed to Iqxy(), and have angular 
    368     dispersion. 
     365  - "volume" parameters are passed to Iq(), Iqac(), Iqabc() and form_volume(), 
     366    and have polydispersity loops generated automatically. 
     367 
     368  - "orientation" parameters are not passed, but instead are combined with 
     369    orientation dispersity to translate *qx* and *qy* to *qa*, *qb* and *qc*. 
     370    These parameters should appear at the end of the table with the specific 
     371    names *theta*, *phi* and for asymmetric shapes *psi*, in that order. 
    369372 
    370373Some models will have integer parameters, such as number of pearls in the 
     
    419422That is, the individual models do not need to include polydispersity 
    420423calculations, but instead rely on numerical integration to compute the 
    421 appropriately smeared pattern.   Angular dispersion values over polar angle 
    422 $\theta$ requires an additional $\cos \theta$ weighting due to decreased 
    423 arc length for the equatorial angle $\phi$ with increasing latitude. 
     424appropriately smeared pattern. 
    424425 
    425426Python Models 
     
    468469barbell).  If I(q; pars) is NaN for any $q$, then those parameters will be 
    469470ignored, and not included in the calculation of the weighted polydispersity. 
    470  
    471 Similar to *Iq*, you can define *Iqxy(qx, qy, par1, par2, ...)* where the 
    472 parameter list includes any orientation parameters.  If *Iqxy* is not defined, 
    473 then it will default to *Iqxy = Iq(sqrt(qx**2+qy**2), par1, par2, ...)*. 
    474471 
    475472Models should define *form_volume(par1, par2, ...)* where the parameter 
     
    497494    } 
    498495 
    499 *Iqxy* is similar to *Iq*, except it uses parameters *qx, qy* instead of *q*, 
    500 and it includes orientation parameters. 
    501  
    502496*form_volume* defines the volume of the shape. As in python models, it 
    503497includes only the volume parameters. 
    504498 
    505 *Iqxy* will default to *Iq(sqrt(qx**2 + qy**2), par1, ...)* and 
    506 *form_volume* will default to 1.0. 
    507  
    508499**source=['fn.c', ...]** includes the listed C source files in the 
    509 program before *Iq* and *Iqxy* are defined. This allows you to extend the 
    510 library of C functions available to your model. 
     500program before *Iq* and *form_volume* are defined. This allows you to 
     501extend the library of C functions available to your model.  Note that 
     502you can put the full function definition for *Iq* and *form_volume* 
     503(include function declaration) into an external C file and add it to the list 
     504of sources instead of defining it within the python model file. 
    511505 
    512506Models are defined using double precision declarations for the 
     
    532526 
    533527    #define INVALID(v) (v.bell_radius < v.radius) 
     528 
     529Oriented Shapes 
     530............... 
     531 
     532If the scattering is dependent on the orientation of the shape, then you 
     533will need to include *orientation* parameters *theta*, *phi* and *psi* 
     534at the end of the parameter table.  Shape orientation uses *a*, *b* and *c* 
     535axes, corresponding to the *x*, *y* and *z* axes in the laboratory coordinate 
     536system, with *z* along the beam and *x*-*y* in the detector plane, with *x* 
     537horizontal and *y* vertical.  The *psi* parameter rotates the shape 
     538about its *c* axis, the *theta* parameter then rotates the *c* axis toward 
     539the *x* axis of the detector, then *phi* rotates the shape in the detector 
     540plane.  (Prior to these rotations, orientation dispersity will be applied 
     541as roll-pitch-yaw, rotating *c*, then *b* then *a* in the shape coordinate 
     542system.)  A particular *qx*, *qy* point on the detector, then corresponds 
     543to *qa*, *qb*, *qc* with respect to the shape. 
     544 
     545The oriented C model is called as *Iqabc(qa, qb, qc, par1, par2, ...)* where 
     546*par1*, etc. are the parameters to the model.  If the shape is rotationally 
     547symmetric about *c* then *psi* is not needed, and the model is called 
     548as *Iqac(qab, qc, par1, par2, ...)*.  In either case, the orientation 
     549parameters are not included in the function call. 
     550 
     551For 1D oriented shapes, an integral over all angles is usually needed for 
     552the *Iq* function. Using symmetry and the substitution $u = \cos(\alpha)$, 
     553$du = -\sin(\alpha)\,d\alpha$ this becomes 
     554 
     555.. math:: 
     556 
     557    I(q) &= \int_{-\pi/2}^{pi/2} \int_{-pi}^{pi} 
     558           F(q_a = q \sin(\alpha)\sin(\beta), 
     559             q_b = q \sin(\alpha)\cos(\beta), 
     560             q_c = q \cos(\alpha))^2 \sin(\alpha)\,d\beta\,d\alpha/(4\pi) \\ 
     561        &= 8/(4\pi) \int_{0}^{pi/2} \int_{0}^{\pi/2} F^2 \sin(\alpha)\,d\beta\,d\alpha \\ 
     562        &= 8/(4\pi) \int_0^1 \int_{0}^{\pi/2} F^2 \,d\beta\,du 
     563 
     564Using the $z, w$ values for Gauss-Legendre integration in "lib/gauss76.c", the 
     565numerical integration is then:: 
     566 
     567    double outer_sum = 0.0; 
     568    for (int i = 0; i < GAUSS_N; i++) { 
     569        const double cos_alpha = 0.5*GAUSS_Z[i] + 0.5; 
     570        const double sin_alpha = sqrt(1.0 - cos_alpha*cos_alpha); 
     571        const double qc = cos_alpha * q; 
     572        double inner_sum = 0.0; 
     573        for (int j = 0; j < GAUSS_N; j++) { 
     574            const double beta = M_PI_4 * GAUSS_Z[j] + M_PI_4; 
     575            double sin_beta, cos_beta; 
     576            SINCOS(beta, sin_beta, cos_beta); 
     577            const double qb = sin_alpha * cos_beta * q; 
     578            const double qa = sin_alpha * sin_beta * q; 
     579            const double Fq = F(qa, qb, qc, ...); 
     580            inner_sum += GAUSS_W[j] * Fq*Fq; 
     581        } 
     582        outer_sum += GAUSS_W[i] * inner_sum; 
     583    } 
     584    outer_sum *= 0.25; // = 8/(4 pi) * outer_sum * (pi/2) / 4 
     585 
     586The *z* values for the Gauss-Legendre integration extends from -1 to 1, so 
     587the double sum of *w[i]w[j]* explains the factor of 4.  Correcting for the 
     588average *dz[i]dz[j]* gives $(1-0) \cdot (\pi/2-0) = \pi/2$.  The $8/(4 \pi)$ 
     589factor comes from the integral over the quadrant.  With less symmetry (eg., 
     590in the bcc and fcc paracrystal models), then an integral over the entire 
     591sphere may be necessary. 
     592 
     593For simpler models which are rotationally symmetric a single integral 
     594suffices: 
     595 
     596.. math:: 
     597 
     598    I(q) &= \int_{-\pi/2}^{\pi/2} F(q_{ab} = q \sin(\alpha), 
     599            q_c = q \cos(\alpha))^2 \sin(\alpha)\,d\alpha/\pi \\ 
     600         &= (2/\pi) \int_0^1 F^2\,du 
     601 
     602with integration loop:: 
     603 
     604    double sum = 0.0; 
     605    for (int i = 0; i < GAUSS_N; i++) { 
     606        const double cos_alpha = 0.5*GAUSS_Z[i] + 0.5; 
     607        const double sin_alpha = sqrt(1.0 - cos_alpha*cos_alpha); 
     608        const double qc = cos_alpha * q; 
     609        const double qab = sin_alpha * q; 
     610        const double Fq = F(qab, qc, ...); 
     611        sum += GAUSS_W[j] * Fq*Fq; 
     612    } 
     613    sum *= 0.5; // = 2/pi * sum * (pi/2) / 2 
     614 
     615Magnetism 
     616......... 
     617 
     618Magnetism is supported automatically for all shapes by modifying the 
     619effective SLD of particle according to the Halpern-Johnson vector 
     620describing the interation between neutron spin and magnetic field.  All 
     621parameters marked as type *sld* in the parameter table are treated as 
     622possibly magnetic particles with magnitude *M0* and direction 
     623*mtheta* and *mphi*.  Polarization parameters are also provided 
     624automatically for magnetic models to set the spin state of the measurement. 
     625 
     626For more complicated systems where magnetism is not uniform throughout 
     627the individual particles, you will need to write your own models. 
     628You should not mark the nuclear sld as type *sld*, but instead leave 
     629them unmarked and provide your own magnetism and polarization parameters. 
     630For 2D measurements you will need $(q_x, q_y)$ values for the measurement 
     631to compute the proper magnetism and orientation, which you can implement 
     632using *Iqxy(qx, qy, par1, par2, ...)*. 
    534633 
    535634Special Functions 
     
    796895show a 50x improvement or more over the equivalent pure python model. 
    797896 
    798 External C Models 
    799 ................. 
    800  
    801 External C models are very much like embedded C models, except that 
    802 *Iq*, *Iqxy* and *form_volume* are defined in an external source file 
    803 loaded using the *source=[...]* statement. You need to supply the function 
    804 declarations for each of these that you need instead of building them 
    805 automatically from the parameter table. 
    806  
    807897 
    808898.. _Form_Factors: 
     
    10061096variable name *Rg* for example because $R_g$ is the right name for the model 
    10071097parameter then ignore the lint errors.  Also, ignore *missing-docstring* 
    1008 for standard model functions *Iq*, *Iqxy*, etc. 
     1098for standard model functions *Iq*, *Iqac*, etc. 
    10091099 
    10101100We will have delinting sessions at the SasView Code Camps, where we can 
Note: See TracChangeset for help on using the changeset viewer.