Changes in doc/guide/plugin.rst [94bfa42:81751c2] in sasmodels


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/guide/plugin.rst

    r94bfa42 r81751c2  
    273273`Form_Factors`_ for more details. 
    274274 
    275 **model_info = ...** lets you define a model directly, for example, by 
    276 loading and modifying existing models.  This is done implicitly by 
    277 :func:`sasmodels.core.load_model_info`, which can create a mixture model 
    278 from a pair of existing models.  For example:: 
    279  
    280     from sasmodels.core import load_model_info 
    281     model_info = load_model_info('sphere+cylinder') 
    282  
    283 See :class:`sasmodels.modelinfo.ModelInfo` for details about the model 
    284 attributes that are defined. 
    285  
    286275Model Parameters 
    287276................ 
     
    302291 
    303292**Note: The order of the parameters in the definition will be the order of the 
    304 parameters in the user interface and the order of the parameters in Iq(), 
    305 Iqac(), Iqabc() and form_volume(). And** *scale* **and** *background* 
    306 **parameters are implicit to all models, so they do not need to be included 
    307 in the parameter table.** 
     293parameters in the user interface and the order of the parameters in Fq(), Iq(), 
     294Iqac(), Iqabc(), form_volume() and shell_volume(). 
     295And** *scale* **and** *background* **parameters are implicit to all models, 
     296so they do not need to be included in the parameter table.** 
    308297 
    309298- **"name"** is the name of the parameter shown on the FitPage. 
     
    374363    scattered intensity. 
    375364 
    376   - "volume" parameters are passed to Iq(), Iqac(), Iqabc() and form_volume(), 
    377     and have polydispersity loops generated automatically. 
     365  - "volume" parameters are passed to Fq(), Iq(), Iqac(), Iqabc(), form_volume() 
     366    and shell_volume(), and have polydispersity loops generated automatically. 
    378367 
    379368  - "orientation" parameters are not passed, but instead are combined with 
     
    503492used. 
    504493 
     494Hollow shapes, where the volume fraction of particle corresponds to the 
     495material in the shell rather than the volume enclosed by the shape, must 
     496also define a *shell_volume(par1, par2, ...)* function.  The parameters 
     497are the same as for *form_volume*.  The *I(q)* calculation should use 
     498*shell_volume* squared as its scale factor for the volume normalization. 
     499The structure factor calculation needs *form_volume* in order to properly 
     500scale the volume fraction parameter, so both functions are required for 
     501hollow shapes. 
     502 
     503Note: Pure python models do not yet support direct computation of the 
     504average of $F(q)$ and $F^2(q)$. 
     505 
    505506Embedded C Models 
    506507................. 
     
    514515This expands into the equivalent C code:: 
    515516 
    516     #include <math.h> 
    517517    double Iq(double q, double par1, double par2, ...); 
    518518    double Iq(double q, double par1, double par2, ...) 
     
    523523*form_volume* defines the volume of the shape. As in python models, it 
    524524includes only the volume parameters. 
     525 
     526*form_volume* defines the volume of the shell for hollow shapes. As in 
     527python models, it includes only the volume parameters. 
    525528 
    526529**source=['fn.c', ...]** includes the listed C source files in the 
     
    559562The INVALID define can go into *Iq*, or *c_code*, or an external C file 
    560563listed in *source*. 
     564 
     565Structure Factors 
     566................. 
     567 
     568Structure factor calculations may need the underlying $<F(q)>$ and $<F^2(q)>$ 
     569rather than $I(q)$.  This is used to compute $\beta = <F(q)>^2/<F^2(q)>$ in 
     570the decoupling approximation to the structure factor. 
     571 
     572Instead of defining the *Iq* function, models can define *Fq* as 
     573something like:: 
     574 
     575    double Fq(double q, double *F1, double *F2, double par1, double par2, ...); 
     576    double Fq(double q, double *F1, double *F2, double par1, double par2, ...) 
     577    { 
     578        // Polar integration loop over all orientations. 
     579        ... 
     580        *F1 = 1e-2 * total_F1 * contrast * volume; 
     581        *F2 = 1e-4 * total_F2 * square(contrast * volume); 
     582        return I(q, par1, par2, ...); 
     583    } 
     584 
     585If the volume fraction scale factor is built into the model (as occurs for 
     586the vesicle model, for example), then scale *F1* by $\surd V_f$ so that 
     587$\beta$ is computed correctly. 
     588 
     589Structure factor calculations are not yet supported for oriented shapes. 
     590 
     591Note: only available as a separate C file listed in *source*, or within 
     592a *c_code* block within the python model definition file. 
    561593 
    562594Oriented Shapes 
     
    712744    erf, erfc, tgamma, lgamma:  **do not use** 
    713745        Special functions that should be part of the standard, but are missing 
    714         or inaccurate on some platforms. Use sas_erf, sas_erfc, sas_gamma 
    715         and sas_lgamma instead (see below). 
     746        or inaccurate on some platforms. Use sas_erf, sas_erfc and sas_gamma 
     747        instead (see below). Note: lgamma(x) has not yet been tested. 
    716748 
    717749Some non-standard constants and functions are also provided: 
     
    780812        Gamma function sas_gamma\ $(x) = \Gamma(x)$. 
    781813 
    782         The standard math function, tgamma(x), is unstable for $x < 1$ 
     814        The standard math function, tgamma(x) is unstable for $x < 1$ 
    783815        on some platforms. 
    784816 
    785817        :code:`source = ["lib/sas_gamma.c", ...]` 
    786818        (`sas_gamma.c <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/sas_gamma.c>`_) 
    787  
    788     sas_gammaln(x): 
    789         log gamma function sas_gammaln\ $(x) = \log \Gamma(|x|)$. 
    790  
    791         The standard math function, lgamma(x), is incorrect for single 
    792         precision on some platforms. 
    793  
    794         :code:`source = ["lib/sas_gammainc.c", ...]` 
    795         (`sas_gammainc.c <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/sas_gammainc.c>`_) 
    796  
    797     sas_gammainc(a, x), sas_gammaincc(a, x): 
    798         Incomplete gamma function 
    799         sas_gammainc\ $(a, x) = \int_0^x t^{a-1}e^{-t}\,dt / \Gamma(a)$ 
    800         and complementary incomplete gamma function 
    801         sas_gammaincc\ $(a, x) = \int_x^\infty t^{a-1}e^{-t}\,dt / \Gamma(a)$ 
    802  
    803         :code:`source = ["lib/sas_gammainc.c", ...]` 
    804         (`sas_gammainc.c <https://github.com/SasView/sasmodels/tree/master/sasmodels/models/lib/sas_gammainc.c>`_) 
    805819 
    806820    sas_erf(x), sas_erfc(x): 
     
    840854        If $n$ = 0 or 1, it uses sas_J0($x$) or sas_J1($x$), respectively. 
    841855 
    842         Warning: JN(n,x) can be very inaccurate (0.1%) for x not in [0.1, 100]. 
    843  
    844856        The standard math function jn(n, x) is not available on all platforms. 
    845857 
     
    850862        Sine integral Si\ $(x) = \int_0^x \tfrac{\sin t}{t}\,dt$. 
    851863 
    852         Warning: Si(x) can be very inaccurate (0.1%) for x in [0.1, 100]. 
    853  
    854864        This function uses Taylor series for small and large arguments: 
    855865 
    856         For large arguments use the following Taylor series, 
     866        For large arguments, 
    857867 
    858868        .. math:: 
     
    10231033          "radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, 
    10241034         0.2, 0.228843], 
    1025         [{"radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, "ER", 120.], 
    1026         [{"radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, "VR", 1.], 
     1035        [{"radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, 
     1036         0.1, None, None, 120., None, 1.],  # q, F, F^2, R_eff, V, form:shell 
     1037        [{"@S": "hardsphere"}, 0.1, None], 
    10271038    ] 
    10281039 
    10291040 
    1030 **tests=[[{parameters}, q, result], ...]** is a list of lists. 
     1041**tests=[[{parameters}, q, Iq], ...]** is a list of lists. 
    10311042Each list is one test and contains, in order: 
    10321043 
     
    10401051- input and output values can themselves be lists if you have several 
    10411052  $q$ values to test for the same model parameters. 
    1042 - for testing *ER* and *VR*, give the inputs as "ER" and "VR" respectively; 
    1043   the output for *VR* should be the sphere/shell ratio, not the individual 
    1044   sphere and shell values. 
     1053- for testing effective radius, volume and form:shell volume ratio, use the 
     1054  extended form of the tests results, with *None, None, R_eff, V, V_r* 
     1055  instead of *Iq*.  This calls the kernel *Fq* function instead of *Iq*. 
     1056- for testing F and F^2 (used for beta approximation) do the same as the 
     1057  effective radius test, but include values for the first two elements, 
     1058  $<F(q)>$ and $<F^2(q)>$. 
     1059- for testing interaction between form factor and structure factor, specify 
     1060  the structure factor name in the parameters as *{"@S": "name", ...}* with 
     1061  the remaining list of parameters defined by the *P@S* product model. 
    10451062 
    10461063.. _Test_Your_New_Model: 
Note: See TracChangeset for help on using the changeset viewer.