Changeset b52e00f in sasmodels


Ignore:
Timestamp:
Jun 16, 2017 8:01:31 AM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
c26897a
Parents:
a03fad8 (diff), c1114bf (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 doc_update

Files:
15 added
10 deleted
25 edited
9 moved

Legend:

Unmodified
Added
Removed
  • doc/guide/gpu/gpu_computations.rst

    r8ae8532 rb52e00f  
    3131from available OpenCL platforms. 
    3232 
     33OpenCL devices can be set from OpenCL options dialog in Fitting menu or as 
     34enviromental variables. 
     35 
     36**If you don't want to use OpenCL, you can select "No OpenCL" option from** 
     37**GUI dialog or set *SAS_OPENCL=None* in your environment settings** 
     38**This will only use normal programs.** 
     39 
    3340SasView prefers AMD or NVIDIA drivers for GPU, and prefers Intel or 
    3441Apple drivers for CPU. Both GPU and CPU are included on the assumption that CPU 
     
    3946chose to run the model. 
    4047 
    41 **If you don't want to use OpenCL, you can set** *SAS_OPENCL=None* 
    42 **in your environment settings, and it will only use normal programs.** 
    43  
    44 If you want to use one of the other devices, you can run the following 
    45 from the python console in SasView:: 
     48If you want to use one of the other devices, you can select it from OpenCL 
     49options dialog (accessible from Fitting menu) or run the following from 
     50the python console in SasView:: 
    4651 
    4752    import pyopencl as cl 
  • sasmodels/generate.py

    rc4e3215 rbb4b509  
    492492 
    493493def test_tag_float(): 
    494  
    495     cases=""" 
     494    """check that floating point constants are properly identified and tagged with 'f'""" 
     495 
     496    cases = """ 
    496497ZP  : 0. 
    497498ZPF : 0.0,0.01,0.1 
     
    519520""" 
    520521 
    521     output=""" 
     522    output = """ 
    522523ZP  : 0.f 
    523524ZPF : 0.0f,0.01f,0.1f 
     
    611612    # type: (str, List[Parameter]) -> List[str] 
    612613    """ 
    613     Return a list of *prefix.parameter* from parameter items. 
     614    Return a list of *prefix+parameter* from parameter items. 
     615 
     616    *prefix* should be "v." if v is a struct. 
    614617    """ 
    615618    return [p.as_call_reference(prefix) for p in pars] 
     
    733736        call_iqxy = "#define CALL_IQ(_q,_i,_v) Iq(%s)" % (",".join(pars_sqrt)) 
    734737 
    735     magpars = [k-2 for k,p in enumerate(partable.call_parameters) 
     738    magpars = [k-2 for k, p in enumerate(partable.call_parameters) 
    736739               if p.type == 'sld'] 
    737740 
     
    742745    source.append("#define NUM_MAGNETIC %d" % partable.nmagnetic) 
    743746    source.append("#define MAGNETIC_PARS %s"%",".join(str(k) for k in magpars)) 
    744     for k,v in enumerate(magpars[:3]): 
     747    for k, v in enumerate(magpars[:3]): 
    745748        source.append("#define MAGNETIC_PAR%d %d"%(k+1, v)) 
    746749 
     
    779782        "#undef CALL_IQ", 
    780783        "#undef KERNEL_NAME", 
    781          ] 
     784    ] 
    782785 
    783786    imagnetic = [ 
     
    872875 
    873876# TODO: need a single source for rst_prolog; it is also in doc/rst_prolog 
    874 RST_PROLOG = """\ 
     877RST_PROLOG = r"""\ 
    875878.. |Ang| unicode:: U+212B 
    876879.. |Ang^-1| replace:: |Ang|\ :sup:`-1` 
  • sasmodels/kernel_header.c

    rb00a646 rbb4b509  
    1414#    define SINCOS(angle,svar,cvar) do {const double _t_=angle; svar=sin(_t_);cvar=cos(_t_);} while (0) 
    1515#  endif 
    16    // Intel CPU on Mac gives strange values for erf(); also on the tested 
     16   // Intel CPU on Mac gives strange values for erf(); on the verified 
    1717   // platforms (intel, nvidia, amd), the cephes erf() is significantly 
    1818   // faster than that available in the native OpenCL. 
     
    5757         typedef int int32_t; 
    5858         #include <math.h> 
    59          // TODO: test isnan 
     59         // TODO: check isnan is correct 
    6060         inline double _isnan(double x) { return x != x; } // hope this doesn't optimize away! 
    6161         #undef isnan 
  • sasmodels/kernelcl.py

    rd2b939c rc1114bf  
    578578        # Free buffers 
    579579        for v in (details_b, values_b): 
    580             if v is not None: v.release() 
     580            if v is not None: 
     581                v.release() 
    581582 
    582583        pd_norm = self.result[self.q_input.nq] 
    583         scale = values[0]/(pd_norm if pd_norm!=0.0 else 1.0) 
     584        scale = values[0]/(pd_norm if pd_norm != 0.0 else 1.0) 
    584585        background = values[1] 
    585586        #print("scale",scale,values[0],self.result[self.q_input.nq],background) 
  • sasmodels/model_test.py

    r3330bb4 rbb4b509  
    8585        skip = [] 
    8686    for model_name in models: 
    87         if model_name in skip: continue 
     87        if model_name in skip: 
     88            continue 
    8889        model_info = load_model_info(model_name) 
    8990 
     
    239240            multiple = [test for test in self.info.tests 
    240241                        if isinstance(test[2], list) 
    241                             and not all(result is None for result in test[2])] 
     242                        and not all(result is None for result in test[2])] 
    242243            tests_has_1D_multiple = any(isinstance(test[1][0], float) 
    243244                                        for test in multiple) 
     
    262263            user_pars, x, y = test 
    263264            pars = expand_pars(self.info.parameters, user_pars) 
     265            invalid = invalid_pars(self.info.parameters, pars) 
     266            if invalid: 
     267                raise ValueError("Unknown parameters in test: " + ", ".join(invalid)) 
    264268 
    265269            if not isinstance(y, list): 
     
    305309 
    306310    return ModelTestCase 
     311 
     312def invalid_pars(partable, pars): 
     313    # type: (ParameterTable, Dict[str, float]) 
     314    """ 
     315    Return a list of parameter names that are not part of the model. 
     316    """ 
     317    names = set(p.id for p in partable.call_parameters) 
     318    invalid = [] 
     319    for par in sorted(pars.keys()): 
     320        parts = par.split('_pd') 
     321        if len(parts) > 1 and parts[1] not in ("", "_n", "nsigma", "type"): 
     322            invalid.append(par) 
     323            continue 
     324        if parts[0] not in names: 
     325            invalid.append(par) 
     326    return invalid 
     327 
    307328 
    308329def is_near(target, actual, digits=5): 
  • sasmodels/modelinfo.py

    r9c44b7b rbb4b509  
    101101                limits = (float(low), float(high)) 
    102102            except Exception: 
    103                 raise ValueError("invalid limits for %s: %r"%(name,user_limits)) 
     103                raise ValueError("invalid limits for %s: %r"%(name, user_limits)) 
    104104            if low >= high: 
    105105                raise ValueError("require lower limit < upper limit") 
     
    342342    def as_call_reference(self, prefix=""): 
    343343        # type: (str) -> str 
     344        """ 
     345        Return *prefix* + parameter name.  For struct references, use "v." 
     346        as the prefix. 
     347        """ 
    344348        # Note: if the parameter is a struct type, then we will need to use 
    345349        # &prefix+id.  For scalars and vectors we can just use prefix+id. 
     
    420424        self.npars = sum(p.length for p in self.kernel_parameters) 
    421425        self.nmagnetic = sum(p.length for p in self.kernel_parameters 
    422                              if p.type=='sld') 
     426                             if p.type == 'sld') 
    423427        self.nvalues = 2 + self.npars 
    424428        if self.nmagnetic: 
     
    457461        self.has_2d = any(p.type in ('orientation', 'magnetic') 
    458462                          for p in self.kernel_parameters) 
    459         self.magnetism_index = [k for k,p in enumerate(self.call_parameters) 
     463        self.magnetism_index = [k for k, p in enumerate(self.call_parameters) 
    460464                                if p.id.startswith('M0:')] 
    461465 
     
    544548                              'magnetic', 'magnetic amplitude for '+p.description), 
    545549                    Parameter('mtheta:'+p.id, 'degrees', 0., [-90., 90.], 
    546                                'magnetic', 'magnetic latitude for '+p.description), 
     550                              'magnetic', 'magnetic latitude for '+p.description), 
    547551                    Parameter('mphi:'+p.id, 'degrees', 0., [-180., 180.], 
    548                                'magnetic', 'magnetic longitude for '+p.description), 
     552                              'magnetic', 'magnetic longitude for '+p.description), 
    549553                ]) 
    550554        #print("call parameters", full_list) 
     
    683687 
    684688    if (model_info.Iq is None 
    685         and model_info.Iqxy is None 
    686         and model_info.Imagnetic is None 
    687         and model_info.form_volume is None): 
     689            and model_info.Iqxy is None 
     690            and model_info.Imagnetic is None 
     691            and model_info.form_volume is None): 
    688692        return 
    689693 
     
    843847    #: it to False because they require double precision calculations. 
    844848    single = None           # type: bool 
     849    #: True if the model can be run as an opencl model.  If for some reason 
     850    #: the model cannot be run in opencl (e.g., because the model passes 
     851    #: functions by reference), then set this to false. 
     852    opencl = None           # type: bool 
    845853    #: True if the model is a structure factor used to model the interaction 
    846854    #: between form factor models.  This will default to False if it is not 
  • sasmodels/models/hollow_cylinder.py

    r9b79f29 rf102a96  
    8080    ["thickness",   "Ang",     10.0, [0, inf],    "volume",      "Cylinder wall thickness"], 
    8181    ["length",      "Ang",    400.0, [0, inf],    "volume",      "Cylinder total length"], 
    82     ["sld",         "1/Ang^2",  6.3, [-inf, inf], "sld",         "Cylinder sld"], 
    83     ["sld_solvent", "1/Ang^2",  1,   [-inf, inf], "sld",         "Solvent sld"], 
     82    ["sld",         "1e-6/Ang^2",  6.3, [-inf, inf], "sld",         "Cylinder sld"], 
     83    ["sld_solvent", "1e-6/Ang^2",  1,   [-inf, inf], "sld",         "Solvent sld"], 
    8484    ["theta",       "degrees", 90,   [-360, 360], "orientation", "Cylinder axis to beam angle"], 
    8585    ["phi",         "degrees",  0,   [-360, 360], "orientation", "Rotation about beam"], 
  • sasmodels/models/lib/sas_3j1x_x.c

    r473a9f1 reb2946f  
    4646double sas_3j1x_x(double q) 
    4747{ 
    48     if (q < SPH_J1C_CUTOFF) { 
     48    // 2017-05-18 PAK - support negative q 
     49    if (fabs(q) < SPH_J1C_CUTOFF) { 
    4950        const double q2 = q*q; 
    5051        return (1.0 + q2*(-3./30. + q2*(3./840. + q2*(-3./45360.))));// + q2*(3./3991680.))))); 
  • sasmodels/models/lib/sas_J0.c

    rc8902ac reb2946f  
    236236        xx = x; 
    237237 
    238     if( x <= 2.0 ) { 
     238    // 2017-05-18 PAK - support negative x 
     239    if( xx <= 2.0 ) { 
    239240        z = xx * xx; 
    240         if( x < 1.0e-3 ) 
     241        if( xx < 1.0e-3 ) 
    241242            return( 1.0 - 0.25*z ); 
    242243 
     
    245246    } 
    246247 
    247     q = 1.0/x; 
     248    q = 1.0/xx; 
    248249    w = sqrt(q); 
    249250 
  • sasmodels/models/lib/sas_J1.c

    r473a9f1 r5181ccc  
    109109{ 
    110110 
    111     double w, z, p, q, xn; 
     111    double w, z, p, q, abs_x, sign_x; 
    112112 
    113113    const double Z1 = 1.46819706421238932572E1; 
    114114    const double Z2 = 4.92184563216946036703E1; 
    115     const double THPIO4 =  2.35619449019234492885; 
    116     const double SQ2OPI = 0.79788456080286535588; 
    117  
    118     w = x; 
    119     if( x < 0 ) 
    120         w = -x; 
    121  
    122     if( w <= 5.0 ) { 
    123         z = x * x; 
     115 
     116    // 2017-05-18 PAK - mathematica and mpmath use J1(-x) = -J1(x) 
     117    if (x < 0) { 
     118        abs_x = -x; 
     119        sign_x = -1.0; 
     120    } else { 
     121        abs_x = x; 
     122        sign_x = 1.0; 
     123    } 
     124 
     125    if( abs_x <= 5.0 ) { 
     126        z = abs_x * abs_x; 
    124127        w = polevl( z, RPJ1, 3 ) / p1evl( z, RQJ1, 8 ); 
    125         w = w * x * (z - Z1) * (z - Z2); 
    126         return( w ); 
     128        w = w * abs_x * (z - Z1) * (z - Z2); 
     129        return( sign_x * w ); 
    127130    } 
    128131 
    129     w = 5.0/x; 
     132    w = 5.0/abs_x; 
    130133    z = w * w; 
    131  
    132134    p = polevl( z, PPJ1, 6)/polevl( z, PQJ1, 6 ); 
    133135    q = polevl( z, QPJ1, 7)/p1evl( z, QQJ1, 7 ); 
    134136 
    135     xn = x - THPIO4; 
    136  
    137     double sn, cn; 
    138     SINCOS(xn, sn, cn); 
    139     p = p * cn - w * q * sn; 
    140  
    141     return( p * SQ2OPI / sqrt(x) ); 
     137    // 2017-05-19 PAK improve accuracy using trig identies 
     138    // original: 
     139    //    const double THPIO4 =  2.35619449019234492885; 
     140    //    const double SQ2OPI = 0.79788456080286535588; 
     141    //    double sin_xn, cos_xn; 
     142    //    SINCOS(abs_x - THPIO4, sin_xn, cos_xn); 
     143    //    p = p * cos_xn - w * q * sin_xn; 
     144    //    return( sign_x * p * SQ2OPI / sqrt(abs_x) ); 
     145    // expanding p*cos(a - 3 pi/4) - wq sin(a - 3 pi/4) 
     146    //    [ p(sin(a) - cos(a)) + wq(sin(a) + cos(a)) / sqrt(2) 
     147    // note that sqrt(1/2) * sqrt(2/pi) = sqrt(1/pi) 
     148    const double SQRT1_PI = 0.56418958354775628; 
     149    double sin_x, cos_x; 
     150    SINCOS(abs_x, sin_x, cos_x); 
     151    p = p*(sin_x - cos_x) + w*q*(sin_x + cos_x); 
     152    return( sign_x * p * SQRT1_PI / sqrt(abs_x) ); 
    142153} 
    143154 
     
    179190    }; 
    180191 
    181 float cephes_j1f(float x) 
     192float cephes_j1f(float xx) 
    182193{ 
    183194 
    184     float xx, w, z, p, q, xn; 
     195    float x, w, z, p, q, xn; 
    185196 
    186197    const float Z1 = 1.46819706421238932572E1; 
    187     const float THPIO4F =  2.35619449019234492885;    /* 3*pi/4 */ 
    188  
    189  
    190     xx = x; 
    191     if( xx < 0 ) 
    192         xx = -x; 
    193  
    194     if( xx <= 2.0 ) { 
    195         z = xx * xx; 
    196         p = (z-Z1) * xx * polevl( z, JPJ1, 4 ); 
    197         return( p ); 
     198 
     199 
     200    // 2017-05-18 PAK - mathematica and mpmath use J1(-x) = -J1(x) 
     201    x = xx; 
     202    if( x < 0 ) 
     203        x = -xx; 
     204 
     205    if( x <= 2.0 ) { 
     206        z = x * x; 
     207        p = (z-Z1) * x * polevl( z, JPJ1, 4 ); 
     208        return( xx < 0. ? -p : p ); 
    198209    } 
    199210 
     
    203214    p = w * polevl( q, MO1J1, 7); 
    204215    w = q*q; 
    205     xn = q * polevl( w, PH1J1, 7) - THPIO4F; 
    206     p = p * cos(xn + xx); 
    207  
    208     return(p); 
     216    // 2017-05-19 PAK improve accuracy using trig identies 
     217    // original: 
     218    //    const float THPIO4F =  2.35619449019234492885;    /* 3*pi/4 */ 
     219    //    xn = q * polevl( w, PH1J1, 7) - THPIO4F; 
     220    //    p = p * cos(xn + x); 
     221    //    return( xx < 0. ? -p : p ); 
     222    // expanding cos(a + b - 3 pi/4) is 
     223    //    [sin(a)sin(b) + sin(a)cos(b) + cos(a)sin(b)-cos(a)cos(b)] / sqrt(2) 
     224    xn = q * polevl( w, PH1J1, 7); 
     225    float cos_xn, sin_xn; 
     226    float cos_x, sin_x; 
     227    SINCOS(xn, sin_xn, cos_xn);  // about xn and 1 
     228    SINCOS(x, sin_x, cos_x); 
     229    p *= M_SQRT1_2*(sin_xn*(sin_x+cos_x) + cos_xn*(sin_x-cos_x)); 
     230 
     231    return( xx < 0. ? -p : p ); 
    209232} 
    210233#endif 
  • sasmodels/models/lib/sas_erf.c

    rb3796fa reb2946f  
    165165        // the erf function instead and z < 1.0. 
    166166        //return (1.0 - cephes_erf(a)); 
    167         z = x * x; 
    168         y = x * polevl(z, TD, 4) / p1evl(z, UD, 5); 
    169  
    170         return y; 
     167        // 2017-05-18 PAK - use erf(a) rather than erf(|a|) 
     168        z = a * a; 
     169        y = a * polevl(z, TD, 4) / p1evl(z, UD, 5); 
     170 
     171        return 1.0 - y; 
    171172    } 
    172173 
     
    279280        //is explicit here for the case < 1.0 
    280281        //return (1.0 - sas_erf(a)); 
    281         z = x * x; 
    282         y = x * polevl( z, TF, 6 ); 
    283  
    284         return y; 
     282        // 2017-05-18 PAK - use erf(a) rather than erf(|a|) 
     283        z = a * a; 
     284        y = a * polevl( z, TF, 6 ); 
     285 
     286        return 1.0 - y; 
    285287    } 
    286288 
  • sasmodels/models/stacked_disks.py

    r9802ab3 r9d50a1e  
    156156qx = q*cos(pi/6.0) 
    157157qy = q*sin(pi/6.0) 
    158 tests = [ 
    159158# Accuracy tests based on content in test/utest_extra_models.py. 
    160159# Added 2 tests with n_stacked = 5 using SasView 3.1.2 - PDB; 
    161160# for which alas q=0.001 values seem closer to n_stacked=1 not 5, 
    162161# changed assuming my 4.1 code OK, RKH 
    163     [{'thick_core': 10.0, 
    164       'thick_layer': 15.0, 
    165       'radius': 3000.0, 
    166       'n_stacking': 1.0, 
    167       'sigma_d': 0.0, 
    168       'sld_core': 4.0, 
    169       'sld_layer': -0.4, 
    170       'solvent_sd': 5.0, 
     162tests = [ 
     163    [{'thick_core': 10.0, 
     164      'thick_layer': 15.0, 
     165      'radius': 3000.0, 
     166      'n_stacking': 1.0, 
     167      'sigma_d': 0.0, 
     168      'sld_core': 4.0, 
     169      'sld_layer': -0.4, 
     170      'sld_solvent': 5.0, 
    171171      'theta': 90.0, 
    172172      'phi': 0.0, 
     
    181181      'sld_core': 4.0, 
    182182      'sld_layer': -0.4, 
    183       'solvent_sd': 5.0, 
     183      'sld_solvent': 5.0, 
    184184      'theta': 90.0, 
    185185      'phi': 0.0, 
     
    196196      'sld_core': 4.0, 
    197197      'sld_layer': -0.4, 
    198       'solvent_sd': 5.0, 
     198      'sld_solvent': 5.0, 
    199199      'theta': 90.0, 
    200200      'phi': 20.0, 
    201201      'scale': 0.01, 
    202       'background': 0.001}, 
    203       (qx, qy), 0.0491167089952  ], 
     202      'background': 0.001, 
     203     }, (qx, qy), 0.0491167089952], 
    204204    [{'thick_core': 10.0, 
    205205      'thick_layer': 15.0, 
     
    209209      'sld_core': 4.0, 
    210210      'sld_layer': -0.4, 
    211       'solvent_sd': 5.0, 
     211      'sld_solvent': 5.0, 
    212212      'theta': 90.0, 
    213213      'phi': 0.0, 
     
    225225      'sld_core': 4.0, 
    226226      'sld_layer': -0.4, 
    227       'solvent_sd': 5.0, 
     227      'sld_solvent': 5.0, 
    228228      'theta': 90.0, 
    229229      'phi': 0.0, 
     
    240240      'sld_core': 4.0, 
    241241      'sld_layer': -0.4, 
    242       'solvent_sd': 5.0, 
     242      'sld_solvent': 5.0, 
    243243      'theta': 90.0, 
    244244      'phi': 0.0, 
     
    246246      'background': 0.001, 
    247247     }, ([0.4, 0.5]), [0.00105074, 0.00121761]], 
    248     [{'thick_core': 10.0, 
    249       'thick_layer': 15.0, 
    250       'radius': 3000.0, 
    251       'n_stacking': 1.0, 
    252       'sigma_d': 0.0, 
    253       'sld_core': 4.0, 
    254       'sld_layer': -0.4, 
    255       'solvent_sd': 5.0, 
    256       'theta': 90.0, 
    257       'phi': 20.0, 
    258       'scale': 0.01, 
    259       'background': 0.001, 
    260      }, (qx, qy), 0.0341738733124 ], 
    261  
    262     [{'thick_core': 10.0, 
    263       'thick_layer': 15.0, 
    264       'radius': 3000.0, 
    265       'n_stacking': 1.0, 
    266       'sigma_d': 0.0, 
    267       'sld_core': 4.0, 
    268       'sld_layer': -0.4, 
    269      'solvent_sd': 5.0, 
     248#    [{'thick_core': 10.0, 
     249#      'thick_layer': 15.0, 
     250#      'radius': 3000.0, 
     251#      'n_stacking': 1.0, 
     252#      'sigma_d': 0.0, 
     253#      'sld_core': 4.0, 
     254#      'sld_layer': -0.4, 
     255#      'sld_solvent': 5.0, 
     256#      'theta': 90.0, 
     257#      'phi': 20.0, 
     258#      'scale': 0.01, 
     259#      'background': 0.001, 
     260# 2017-05-18 PAK temporarily suppress output of qx,qy test; j1 is not accurate for large qr 
     261#     }, (qx, qy), 0.0341738733124], 
     262#     }, (qx, qy), None], 
     263 
     264    [{'thick_core': 10.0, 
     265      'thick_layer': 15.0, 
     266      'radius': 3000.0, 
     267      'n_stacking': 1.0, 
     268      'sigma_d': 0.0, 
     269      'sld_core': 4.0, 
     270      'sld_layer': -0.4, 
     271      'sld_solvent': 5.0, 
    270272      'theta': 90.0, 
    271273      'phi': 0.0, 
     
    274276     }, ([1.3, 1.57]), [0.0010039, 0.0010038]], 
    275277    ] 
    276 # 11Jan2017   RKH checking unit test agai, note they are all 1D, no 2D 
    277  
     278# 11Jan2017   RKH checking unit test again, note they are all 1D, no 2D 
  • sasmodels/models/two_power_law.py

    r40a87fa rbb4b509  
    120120     }, 0.150141, 0.125945], 
    121121 
    122     [{'coeffcent_1':    1.0, 
     122    [{'coefficent_1':    1.0, 
    123123      'crossover':  0.04, 
    124124      'power_1':    1.0, 
     
    127127     }, 0.442528, 0.00166884], 
    128128 
    129     [{'coeffcent_1':    1.0, 
     129    [{'coefficent_1':    1.0, 
    130130      'crossover':  0.04, 
    131131      'power_1':    1.0, 
  • .gitignore

    r2a55a6f r8ae8532  
    1111/doc/api/ 
    1212/doc/model/ 
    13 /doc/ref/models 
     13/doc/guide/models 
    1414.mplconfig 
    1515/pylint_violations.txt 
  • doc/conf.py

    r39674a0 r8ae8532  
    4242             ] 
    4343 
     44# Redirect mathjax to a different CDN 
     45mathjax_path = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML" 
     46 
    4447# Add any paths that contain templates here, relative to this directory. 
    4548templates_path = ['_templates'] 
  • doc/developer/calculator.rst

    re822c97 r2e66ef5  
    77model calculator which implements the polydispersity and magnetic SLD 
    88calculations.  There are three separate implementations of this layer, 
    9 *kernelcl.py* for OpenCL, which operates on a single Q value at a time, 
    10 *kerneldll.c* for the DLL, which loops over a vector of Q values, and 
    11 *kernelpy.py* for python models which operates on vector Q values. 
     9:mod:`kernelcl` for OpenCL, which operates on a single Q value at a time, 
     10:mod:`kerneldll` for the DLL, which loops over a vector of Q values, and 
     11:mod:`kernelpy` for python models which operates on vector Q values. 
    1212 
    1313Each implementation provides three different calls *Iq*, *Iqxy* and *Imagnetic* 
  • doc/developer/index.rst

    rb85be2d r2e66ef5  
    77   :maxdepth: 4 
    88 
     9   overview.rst 
    910   calculator.rst 
  • doc/genapi.py

    ra5b8477 r2e66ef5  
    22import os.path 
    33 
    4 MODULE_TEMPLATE=""".. Autogenerated by genmods.py 
     4MODULE_TEMPLATE = """.. Autogenerated by genmods.py 
    55 
    66****************************************************************************** 
     
    1919""" 
    2020 
    21 INDEX_TEMPLATE=""".. Autogenerated by genmods.py 
     21INDEX_TEMPLATE = """.. Autogenerated by genmods.py 
    2222 
    2323.. _api-index: 
     
    4646        os.makedirs(dir) 
    4747 
    48     for module,name in modules: 
    49         with open(os.path.join(dir,module+'.rst'), 'w') as f: 
     48    for module, name in modules: 
     49        with open(os.path.join(dir, module+'.rst'), 'w') as f: 
    5050            f.write(MODULE_TEMPLATE%locals()) 
    5151 
    52     rsts = "\n   ".join(module+'.rst' for module,name in modules) 
    53     with open(os.path.join(dir,'index.rst'),'w') as f: 
     52    rsts = "\n   ".join(module+'.rst' for module, name in modules) 
     53    with open(os.path.join(dir, 'index.rst'), 'w') as f: 
    5454        f.write(INDEX_TEMPLATE%locals()) 
    5555 
    5656 
    57 modules=[ 
    58     #('__init__', 'Top level namespace'), 
     57modules = [ 
     58    ('__init__', 'Sasmodels package'), 
    5959    #('alignment', 'GPU data alignment [unused]'), 
    6060    ('bumps_model', 'Bumps interface'), 
     61    ('compare_many', 'Batch compare models on different compute engines'), 
    6162    ('compare', 'Compare models on different compute engines'), 
    6263    ('convert', 'Sasview to sasmodel converter'), 
     
    6667    ('direct_model', 'Simple interface'), 
    6768    ('exception', 'Annotate exceptions'), 
    68     #('frozendict', 'Freeze a dictionary to make it immutable'), 
    6969    ('generate', 'Model parser'), 
    7070    ('kernel', 'Evaluator type definitions'), 
     
    7979    ('resolution', '1-D resolution functions'), 
    8080    ('resolution2d', '2-D resolution functions'), 
     81    ('rst2html', 'Convert doc strings the web pages'), 
    8182    ('sasview_model', 'Sasview interface'), 
    8283    ('sesans', 'SESANS calculation routines'), 
    83     #('transition', 'Model stepper for automatic model selection'), 
    8484    ('weights', 'Distribution functions'), 
    8585] 
    86 package='sasmodels' 
    87 package_name='Reference' 
     86package = 'sasmodels' 
     87package_name = 'Reference' 
    8888genfiles(package, package_name, modules) 
  • doc/gentoc.py

    r40a87fa r990d8df  
    1616    from sasmodels.modelinfo import ModelInfo 
    1717 
    18 TEMPLATE="""\ 
     18TEMPLATE = """\ 
    1919.. 
    2020    Generated from doc/gentoc.py -- DO NOT EDIT -- 
     
    3030""" 
    3131 
    32 MODEL_TOC_PATH = "ref/models" 
     32MODEL_TOC_PATH = "guide/models" 
    3333 
    3434def _make_category(category_name, label, title, parent=None): 
     
    6565        # assume model is in sasmodels/models/name.py, and ignore the full path 
    6666        model_name = basename(item)[:-3] 
    67         if model_name.startswith('_'): continue 
     67        if model_name.startswith('_'): 
     68            continue 
    6869        model_info = load_model_info(model_name) 
    6970        if model_info.category is None: 
    7071            print("Missing category for", item, file=sys.stderr) 
    7172        else: 
    72             category.setdefault(model_info.category,[]).append(model_name) 
     73            category.setdefault(model_info.category, []).append(model_name) 
    7374 
    7475    # Check category names 
    75     for k,v in category.items(): 
     76    for k, v in category.items(): 
    7677        if len(v) == 1: 
    77             print("Category %s contains only %s"%(k,v[0]), file=sys.stderr) 
     78            print("Category %s contains only %s"%(k, v[0]), file=sys.stderr) 
    7879 
    7980    # Generate category files for the table of contents. 
     
    8687    # alphabetical order before them. 
    8788 
    88     if not exists(MODEL_TOC_PATH): mkdir(MODEL_TOC_PATH) 
     89    if not exists(MODEL_TOC_PATH): 
     90        mkdir(MODEL_TOC_PATH) 
    8991    model_toc = _make_category( 
    90         'index',  'Models', 'Model Functions') 
     92        'index', 'Models', 'Model Functions') 
    9193    #shape_toc = _make_category( 
    9294    #    'shape',  'Shapes', 'Shape Functions', model_toc) 
    9395    free_toc = _make_category( 
    94         'shape-independent',  'Shape-independent', 
     96        'shape-independent', 'Shape-independent', 
    9597        'Shape-Independent Functions') 
    9698    struct_toc = _make_category( 
    97         'structure-factor',  'Structure-factor', 'Structure Factors') 
    98     custom_toc = _make_category( 
    99         'custom-models', 'Custom-models', 'Custom Models') 
     99        'structure-factor', 'Structure-factor', 'Structure Factors') 
     100    #custom_toc = _make_category( 
     101    #    'custom-models', 'Custom-models', 'Custom Models') 
    100102 
    101103    # remember to top level categories 
     
    105107        'shape-independent':free_toc, 
    106108        'structure-factor': struct_toc, 
    107         'custom': custom_toc, 
     109        #'custom': custom_toc, 
    108110        } 
    109111 
    110112    # Process the model lists 
    111     for k,v in sorted(category.items()): 
     113    for k, v in sorted(category.items()): 
    112114        if ':' in k: 
    113             cat,subcat = k.split(':') 
     115            cat, subcat = k.split(':') 
    114116            _maybe_make_category(cat, v, cat_files, model_toc) 
    115117            cat_file = cat_files[cat] 
    116             label = "-".join((cat,subcat)) 
     118            label = "-".join((cat, subcat)) 
    117119            filename = label 
    118             title = subcat.capitalize()+" Functions" 
     120            title = subcat.capitalize() + " Functions" 
    119121            sub_toc = _make_category(filename, label, title, cat_file) 
    120122            for model in sorted(v): 
     
    130132    _add_subcategory('shape-independent', model_toc) 
    131133    _add_subcategory('structure-factor', model_toc) 
    132     _add_subcategory('custom-models', model_toc) 
     134    #_add_subcategory('custom-models', model_toc) 
    133135 
    134136    # Close the top-level category files 
    135137    #model_toc.close() 
    136     for f in cat_files.values(): f.close() 
     138    for f in cat_files.values(): 
     139        f.close() 
    137140 
    138141 
  • doc/guide/gpu/opencl_installation.rst

    rec8b9a3 r990d8df  
    44OpenCL Installation 
    55******************* 
    6 *Warning! GPU devices do not in general offer the same level of memory protection as CPU devices. If your code attempts to write outside allocated memory buffers unpredicatable behaviour may result (eg, your video display may freeze, or your system may crash, etc). Do not install OpenCL drivers without first checking for known issues (eg, some computer manufacturers install modified graphics drivers so replacing these may not be a good idea!). If in doubt, seek advice from an IT professional before proceeding further.* 
     6*Warning! GPU devices do not in general offer the same level of memory 
     7protection as CPU devices. If your code attempts to write outside allocated 
     8memory buffers unpredicatable behaviour may result (eg, your video display 
     9may freeze, or your system may crash, etc). Do not install OpenCL drivers 
     10ithout first checking for known issues (eg, some computer manufacturers 
     11install modified graphics drivers so replacing these may not be a good 
     12idea!). If in doubt, seek advice from an IT professional before proceeding 
     13further.* 
    714 
    8151. Check if you have OpenCL already installed 
     
    2532Mac OSX 
    2633....... 
    27     For OS X operating systems higher than 10.6 OpenCL is shipped along with the system. 
     34    For OS X operating systems higher than 10.6 OpenCL is shipped along with 
     35    the system. 
    2836 
    29     However, OpenCL has had a rocky history on Macs. Apple provide a useful compatibility table at https://support.apple.com/en-us/HT202823 
     37    However, OpenCL has had a rocky history on Macs. Apple provide a useful 
     38    compatibility table at https://support.apple.com/en-us/HT202823 
    3039 
    3140 
     
    4453....... 
    4554    N/A 
    46          
    47         You cannot download OpenCL driver updates for your Mac. They are packaged with the normal quarterly OS X updates from Apple.  
     55 
     56 You cannot download OpenCL driver updates for your Mac. They are packaged 
     57 with the normal quarterly OS X updates from Apple. 
    4858 
    4959 
    5060.. note:: 
    51     Intel provides OpenCL drivers for Intel processors at     https://software.intel.com/en-us/articles/opencl-drivers  
     61    Intel provides OpenCL drivers for Intel processors at 
     62    https://software.intel.com/en-us/articles/opencl-drivers 
    5263    These can sometimes make use of special vector instructions across multiple 
    5364    processors, so it is worth installing if the GPU does not support double 
     
    5566    or AMD. 
    5667 
    57          
     68 
    5869.. note:: 
    5970    This help document was last changed by Steve King, 08Oct2016 
  • doc/guide/index.rst

    rbb6f0f3 r2e66ef5  
    1 ********** 
    2 SAS Models 
    3 ********** 
     1**************** 
     2SAS Models Guide 
     3**************** 
    44 
    5 Small angle X-ray and Neutron (SAXS and SANS) scattering examines the 
    6 scattering patterns produced by a beam travelling through the sample 
    7 and scattering at low angles.  The scattering is computed as a function 
    8 of $q_x$ and $q_y$, which for a given beam wavelength corresponds to 
    9 particular scattering angles. Each pixel on the detector corresponds to 
    10 a different scattering angle. If the sample is unoriented, the scattering 
    11 pattern will appear as rings on the detector.  In this case, a circular 
    12 average can be taken with 1-dimension data at $q = \surd (q_x^2 + q_y^2)$ 
    13 compared to the orientationally averaged SAS scattering pattern. 
     5.. toctree:: 
     6   :numbered: 4 
     7   :maxdepth: 4 
    148 
    15 Models have certain features in common. 
    16  
    17 Every model has a *scale* and a *background*. 
    18  
    19 Talk about orientation, with diagrams for orientation so that we don't need 
    20 a link on every model page? 
    21  
    22 .. _orientation: 
    23  
    24 .. figure: img/orientation1.jpg 
    25  
    26     Orientation in 3D 
    27  
    28 .. figure: img/orientation2.jpg 
    29  
    30     Orientation cross sections 
    31  
    32 Talk about polydispersity. 
    33  
    34 Talk about magnetism, converting the magnetism help file to inline text here, 
    35 with links so that models can point back to it. 
    36  
    37 Need to talk about structure factors even though we don't have any 
    38 implemented yet. 
     9   intro.rst 
     10   install.rst 
     11   pd/polydispersity.rst 
     12   resolution.rst 
     13   magnetism/magnetism.rst 
     14   sesans/sans_to_sesans.rst 
     15   sesans/sesans_fitting.rst 
     16   plugin.rst 
     17   scripting.rst 
     18   refs.rst 
  • doc/guide/magnetism/magnetism.rst

    rdeb854f r990d8df  
    22 
    33Polarisation/Magnetic Scattering 
    4 ======================================================= 
     4================================ 
    55 
    6 In earlier versions of SasView magnetic scattering was implemented in just five  
    7 (2D) models 
    8  
    9 *  :ref:`sphere` 
    10 *  :ref:`core-shell-sphere` 
    11 *  :ref:`core-multi-shell` 
    12 *  :ref:`cylinder` 
    13 *  :ref:`parallelepiped` 
    14  
    15 From SasView 4.x it is implemented on most models in the 'shape' category. 
    16  
    17 In general, the scattering length density (SLD = $\beta$) in each region where the 
    18 SLD is uniform, is a combination of the nuclear and magnetic SLDs and, for polarised 
    19 neutrons, also depends on the spin states of the neutrons. 
     6Models which define a scattering length density parameter can be evaluated 
     7 as magnetic models. In general, the scattering length density (SLD = 
     8 $\beta$) in each region where the SLD is uniform, is a combination of the 
     9 nuclear and magnetic SLDs and, for polarised neutrons, also depends on the 
     10 spin states of the neutrons. 
    2011 
    2112For magnetic scattering, only the magnetization component $\mathbf{M_\perp}$ 
     
    9889.. note:: 
    9990    This help document was last changed by Steve King, 02May2015 
     91 
     92* Document History * 
     93 
     94| 2017-05-08 Paul Kienzle 
  • doc/guide/sesans/sesans_fitting.rst

    r3330bb4 r8ae8532  
    77=================== 
    88 
    9 .. note:: A proper installation of the developers setup of SasView (http://trac.sasview.org/wiki/AnacondaSetup) is a prerequisite for using these instructions. 
     9.. note:: 
     10 
     11    A proper installation of the developers setup of SasView 
     12    (http://trac.sasview.org/wiki/AnacondaSetup) is a prerequisite for 
     13    using these instructions. 
    1014 
    1115It is possible to fit SESANS measurements from the command line in Python. 
     
    1317Simple Fits 
    1418........... 
    15 In the folder sasmodels/example the file sesans_sphere_2micron.py gives an example of how to fit a shape to a measurement. 
     19In the folder sasmodels/example the file sesans_sphere_2micron.py gives 
     20an example of how to fit a shape to a measurement. 
    1621 
    1722The command:: 
     
    2328.. image:: sesans_img/SphereLineFitSasView.png 
    2429 
    25 All the parameters and names in sesans_sphere_2micron.py (shown below) can be adjusted to fit your own problem:: 
     30All the parameters and names in sesans_sphere_2micron.py (shown below) can 
     31be adjusted to fit your own problem:: 
    2632 
    2733  """ 
     
    6470  # Constraints 
    6571  # model.param_name = f(other params) 
    66   # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius and scale are model functions and phi is 
    67   # a custom parameter 
     72  # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius 
     73  # and scale are model functions and phi is a custom parameter 
    6874  model.scale = phi*(1-phi) 
    6975 
     
    7480Incorporating a Structure Factor 
    7581................................ 
    76 An example of how to also include a structure factor can be seen in the following example taken from Washington et al.,  
    77 *Soft Matter*\, (2014), 10, 3016 (dx.doi.org/10.1039/C3SM53027B). These are time-of-flight measurements, which is the  
    78 reason that not the polarisation is plotted, but the :math:`\frac{log(P/P_0)}{\lambda^2}` . The sample is a dispersion  
    79 of core-shell colloids at a high volume fraction with hard sphere interactions. 
     82An example of how to also include a structure factor can be seen in the 
     83following example taken from Washington et al., *Soft Matter*\, (2014), 10, 3016 
     84(dx.doi.org/10.1039/C3SM53027B). These are time-of-flight measurements, which 
     85is the reason that not the polarisation is plotted, but the 
     86:math:`\frac{log(P/P_0)}{\lambda^2}` . The sample is a dispersion of 
     87core-shell colloids at a high volume fraction with hard sphere interactions. 
    8088 
    8189The fit can be started by:: 
     
    8795.. image:: sesans_img/HardSphereLineFitSasView.png 
    8896 
    89 The code sesans_parameters_css-hs.py can then be used as a template for a fitting problem with a structure factor:: 
     97The code sesans_parameters_css-hs.py can then be used as a template for a 
     98fitting problem with a structure factor:: 
    9099 
    91100 """ 
     
    131140 # Constraints 
    132141 # model.param_name = f(other params) 
    133  # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius and scale are model functions and phi is 
    134  # a custom parameter 
     142 # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius 
     143 # and scale are model functions and phi is a custom parameter 
    135144 model.scale = phi*(1-phi) 
    136145 model.volfraction = phi 
  • doc/index.rst

    r7bb290c r8ae8532  
    1 Introduction 
    2 ============ 
     1sasmodels 
     2========= 
     3Small angle X-ray and Neutron scattering (SAXS and SANS) examines the 
     4scattering patterns produced by a beam travelling through the sample 
     5and scattering at low angles.  The scattering is computed as a function 
     6of reciprocal space $q$, which arises from a combination of beam wavelength 
     7and scattering angles. Each pixel on the detector corresponds to 
     8a different scattering angle, and has a distinct $q_x$ and $q_y$. If the 
     9sample is unoriented, the scattering pattern will appear as rings on the 
     10detector.  In this case, a circular average can be taken with 1-dimension 
     11data at $q = \surd (q_x^2 + q_y^2)$ compared to the orientationally 
     12averaged SAS scattering pattern. 
     13 
    314The sasmodels package provides theory functions for small angle scattering 
    4 calculations. 
     15calculations for different shapes, including the effects of resolution, 
     16polydispersity and orientational dispersion. 
    517 
    618.. htmlonly:: 
     
    1527 
    1628   guide/index.rst 
     29   guide/models/index.rst 
    1730   developer/index.rst 
    18    ref/index.rst 
    19    ref/models/index.rst 
    2031   api/index.rst 
    2132 
     
    2839.. htmlonly:: 
    2940  * :ref:`search` 
    30  
    31  
    32  
    33  
    34    
    35  
  • example/model.py

    r1182da5 r2e66ef5  
    1717model = Model(kernel, 
    1818    scale=0.08, 
    19     r_polar=15, r_equatorial=800, 
     19    radius_polar=15, radius_equatorial=800, 
    2020    sld=.291, sld_solvent=7.105, 
    2121    background=0, 
    2222    theta=90, phi=0, 
    2323    theta_pd=15, theta_pd_n=40, theta_pd_nsigma=3, 
    24     r_polar_pd=0.222296, r_polar_pd_n=1, r_polar_pd_nsigma=0, 
    25     r_equatorial_pd=.000128, r_equatorial_pd_n=1, r_equatorial_pd_nsigma=0, 
     24    radius_polar_pd=0.222296, radius_polar_pd_n=1, radius_polar_pd_nsigma=0, 
     25    radius_equatorial_pd=.000128, radius_equatorial_pd_n=1, radius_equatorial_pd_nsigma=0, 
    2626    phi_pd=0, phi_pd_n=20, phi_pd_nsigma=3, 
    2727    ) 
    2828 
    2929# SET THE FITTING PARAMETERS 
    30 model.r_polar.range(15, 1000) 
    31 model.r_equatorial.range(15, 1000) 
     30model.radius_polar.range(15, 1000) 
     31model.radius_equatorial.range(15, 1000) 
    3232model.theta_pd.range(0, 360) 
    3333model.background.range(0,1000) 
  • sasmodels/core.py

    r650c6d2 r2e66ef5  
    117117    Load model info and build model. 
    118118 
    119     *model_name* is the name of the model as used by :func:`load_model_info`. 
    120     Additional keyword arguments are passed directly to :func:`build_model`. 
     119    *model_name* is the name of the model, or perhaps a model expression 
     120    such as sphere*hardsphere or sphere+cylinder. 
     121 
     122    *dtype* and *platform* are given by :func:`build_model`. 
    121123    """ 
    122124    return build_model(load_model_info(model_name), 
     
    128130    """ 
    129131    Load a model definition given the model name. 
     132 
     133    *model_name* is the name of the model, or perhaps a model expression 
     134    such as sphere*hardsphere or sphere+cylinder. 
    130135 
    131136    This returns a handle to the module defining the model.  This can be 
     
    227232 
    228233    Possible types include 'half', 'single', 'double' and 'quad'.  If the 
    229     type is 'fast', then this is equivalent to dtype 'single' with the 
    230     fast flag set to True. 
     234    type is 'fast', then this is equivalent to dtype 'single' but using 
     235    fast native functions rather than those with the precision level guaranteed 
     236    by the OpenCL standard. 
     237 
     238    Platform preference can be specfied ("ocl" vs "dll"), with the default 
     239    being OpenCL if it is availabe.  If the dtype name ends with '!' then 
     240    platform is forced to be DLL rather than OpenCL. 
     241 
     242    This routine ignores the preferences within the model definition.  This 
     243    is by design.  It allows us to test models in single precision even when 
     244    we have flagged them as requiring double precision so we can easily check 
     245    the performance on different platforms without having to change the model 
     246    definition. 
    231247    """ 
    232248    # Assign default platform, overriding ocl with dll if OpenCL is unavailable 
  • sasmodels/resolution.py

    rb32caab r990d8df  
    437437    .. math:: 
    438438 
    439          \log \Delta q = (\log q_n - log q_1) / (n - 1) 
     439         \log \Delta q = (\log q_n - \log q_1) / (n - 1) 
    440440 
    441441    From this we can compute the number of steps required to extend $q$ 
     
    451451 
    452452         n_\text{extend} = (n-1) (\log q_\text{max} - \log q_n) 
    453             / (\log q_n - log q_1) 
     453            / (\log q_n - \log q_1) 
    454454    """ 
    455455    q = np.sort(q) 
     
    459459        log_delta_q = log(10.) / points_per_decade 
    460460    if q_min < q[0]: 
    461         if q_min < 0: q_min = q[0]*MINIMUM_ABSOLUTE_Q 
     461        if q_min < 0: 
     462            q_min = q[0]*MINIMUM_ABSOLUTE_Q 
    462463        n_low = log_delta_q * (log(q[0])-log(q_min)) 
    463464        q_low = np.logspace(log10(q_min), log10(q[0]), np.ceil(n_low)+1)[:-1] 
  • sasmodels/rst2html.py

    rf2f5413 r990d8df  
    3838    - mathml 
    3939    - mathjax 
    40     See `http://docutils.sourceforge.net/docs/user/config.html#math-output`_ 
     40    See `<http://docutils.sourceforge.net/docs/user/config.html#math-output>`_ 
    4141    for details. 
    4242 
     
    211211    sys.exit(app.exec_()) 
    212212 
     213def can_use_qt(): 
     214    """ 
     215    Return True if QWebView exists. 
     216 
     217    Checks first in PyQt5 then in PyQt4 
     218    """ 
     219    try: 
     220        from PyQt5.QtWebKitWidgets import QWebView 
     221        return True 
     222    except ImportError: 
     223        try: 
     224            from PyQt4.QtWebkit import QWebView 
     225            return True 
     226        except ImportError: 
     227            return False 
     228 
    213229def view_help(filename, qt=False): 
    214230    import os 
    215     url="file:///"+os.path.abspath(filename).replace("\\","/") 
     231 
     232    if qt: 
     233        qt = can_use_qt() 
     234 
     235    url = "file:///"+os.path.abspath(filename).replace("\\", "/") 
    216236    if filename.endswith('.rst'): 
    217237        html = load_rst_as_html(filename) 
Note: See TracChangeset for help on using the changeset viewer.