Changeset 40a87fa in sasmodels


Ignore:
Timestamp:
Aug 8, 2016 11:24:11 AM (5 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
2472141
Parents:
2d65d51
Message:

lint and latex cleanup

Files:
1 deleted
64 edited

Legend:

Unmodified
Added
Removed
  • doc/conf.py

    r785cbec r40a87fa  
    3636              #'only_directives', 
    3737              #'matplotlib.sphinxext.mathmpl', 
    38               #'matplotlib.sphinxext.only_directives', 
     38              'matplotlib.sphinxext.only_directives', 
    3939              'matplotlib.sphinxext.plot_directive', 
    4040              'dollarmath', 
  • doc/gentoc.py

    ra5b8477 r40a87fa  
    2020    Generated from doc/gentoc.py -- DO NOT EDIT -- 
    2121 
    22 .. %(label)s: 
     22.. _%(label)s: 
    2323 
    2424%(bar)s 
  • sasmodels/__init__.py

    r32e3c9b r40a87fa  
    2828    from .generate import EXTERNAL_DIR, DATA_PATH 
    2929 
    30     def expand_patterns(path, patterns): 
     30    def _expand_patterns(path, patterns): 
    3131        target_path = joinpath(EXTERNAL_DIR, *path) 
    3232        source_path = joinpath(DATA_PATH, *path) 
     
    4141    # can build model docs on the fly, including images. 
    4242    return_list = [ 
    43         expand_patterns([], ['*.c', '*.cl']), 
    44         expand_patterns(['models'], ['*.py', '*.c']), 
    45         expand_patterns(['models', 'lib'], ['*.c']), 
    46         expand_patterns(['models', 'img'], ['*.*']), 
     43        _expand_patterns([], ['*.c', '*.cl']), 
     44        _expand_patterns(['models'], ['*.py', '*.c']), 
     45        _expand_patterns(['models', 'lib'], ['*.c']), 
     46        _expand_patterns(['models', 'img'], ['*.*']), 
    4747        ] 
    4848    return return_list 
  • sasmodels/bumps_model.py

    r04dc697 r40a87fa  
    1313from __future__ import print_function 
    1414 
    15 __all__ = [ "Model", "Experiment" ] 
     15__all__ = ["Model", "Experiment"] 
    1616 
    1717import numpy as np  # type: ignore 
     
    204204        """ 
    205205        data, theory, resid = self._data, self.theory(), self.residuals() 
    206         plot_theory(data, theory, resid, view, Iq_calc = self.Iq_calc) 
     206        plot_theory(data, theory, resid, view, Iq_calc=self.Iq_calc) 
    207207 
    208208    def simulate_data(self, noise=None): 
     
    223223        if self.data_type == "sesans": 
    224224            np.savetxt(basename+".dat", np.array([self._data.x, self.theory()]).T) 
    225         pass 
    226225 
    227226    def __getstate__(self): 
  • sasmodels/compare_many.py

    rf3bd37f r40a87fa  
    152152    except Exception as exc: 
    153153        #raise 
    154         print('"Error: %s"'%str(exc).replace('"',"'")) 
    155         print('"good","%d of %d","max diff",%g'%(0, N, np.NaN)) 
     154        print('"Error: %s"'%str(exc).replace('"', "'")) 
     155        print('"good","%d of %d","max diff",%g' % (0, N, np.NaN)) 
    156156        return 
    157157    expected = max(PRECISION[base], PRECISION[comp]) 
  • sasmodels/convert.py

    r54bcd4a r40a87fa  
    6363    for new, old in mapping.items(): 
    6464        if old == new: continue 
    65         for pd, dot in PD_DOT: 
     65        for underscore, dot in PD_DOT: 
    6666            if old+dot in newpars: 
    6767                if new is not None: 
    68                     newpars[new+pd] = pars[old+dot] 
     68                    newpars[new+underscore] = pars[old+dot] 
    6969                del newpars[old+dot] 
    7070    return newpars 
     
    103103    new model definition end with sld. 
    104104    """ 
    105     return dict((id, (_unscale(v,1e-6) if _is_sld(modelinfo, id) else v)) 
     105    return dict((id, (_unscale(v, 1e-6) if _is_sld(modelinfo, id) else v)) 
    106106                for id, v in pars.items()) 
    107107 
     
    113113    """ 
    114114    # Bumps style parameter names 
    115     pd = pars.pop(key+".width", 0.0) 
    116     pd_n = pars.pop(key+".npts", 0) 
    117     if pd != 0.0 and pd_n != 0: 
     115    width = pars.pop(key+".width", 0.0) 
     116    n_points = pars.pop(key+".npts", 0) 
     117    if width != 0.0 and n_points != 0: 
    118118        warnings.warn("parameter %s not polydisperse in sasview %s"%(key, name)) 
    119119    pars.pop(key+".nsigmas", None) 
     
    128128 
    129129    for new, old in mapping.items(): 
    130         for pd, dot in PD_DOT: 
    131             if old and old+pd == new+dot: 
     130        for underscore, dot in PD_DOT: 
     131            if old and old+underscore == new+dot: 
    132132                continue 
    133             if new+pd in newpars: 
     133            if new+underscore in newpars: 
    134134                if old is not None: 
    135                     newpars[old+dot] = pars[new+pd] 
    136                 del newpars[new+pd] 
     135                    newpars[old+dot] = pars[new+underscore] 
     136                del newpars[new+underscore] 
    137137    for k in list(newpars.keys()): 
    138         for pd, dot in PD_DOT[1:]:  # skip "" => "" 
    139             if k.endswith(pd): 
    140                 newpars[k[:-len(pd)]+dot] = newpars[k] 
     138        for underscore, dot in PD_DOT[1:]:  # skip "" => "" 
     139            if k.endswith(underscore): 
     140                newpars[k[:-len(underscore)]+dot] = newpars[k] 
    141141                del newpars[k] 
    142142    return newpars 
    143143 
    144144def revert_name(model_info): 
    145     oldname, oldpars = CONVERSION_TABLE.get(model_info.id, [None, {}]) 
     145    oldname, _ = CONVERSION_TABLE.get(model_info.id, [None, {}]) 
    146146    return oldname 
    147147 
     
    180180        composition_type, parts = model_info.composition 
    181181        if composition_type == 'product': 
    182             P, S = parts 
    183182            oldpars = {'scale':'scale_factor'} 
    184             oldpars.update(_get_old_pars(P)) 
    185             oldpars.update(_get_old_pars(S)) 
     183            oldpars.update(_get_old_pars(parts[0])) 
     184            oldpars.update(_get_old_pars(parts[1])) 
    186185        else: 
    187186            raise NotImplementedError("cannot convert to sasview sum") 
     
    206205    # Remove magnetic parameters from non-magnetic sasview models 
    207206    if name not in MAGNETIC_SASVIEW_MODELS: 
    208         oldpars = dict((k,v) for k,v in oldpars.items() if ':' not in k) 
     207        oldpars = dict((k, v) for k, v in oldpars.items() if ':' not in k) 
    209208 
    210209    # If it is a product model P*S, then check the individual forms for special 
     
    253252        elif name == 'core_shell_parallelepiped': 
    254253            _remove_pd(oldpars, 'rimA', name) 
    255         elif name in ['mono_gauss_coil','poly_gauss_coil']: 
     254        elif name in ['mono_gauss_coil', 'poly_gauss_coil']: 
    256255            del oldpars['i_zero'] 
    257256        elif name == 'onion': 
  • sasmodels/core.py

    r2547694 r40a87fa  
    4040    # CRUFT: np.meshgrid requires multiple vectors 
    4141    def meshgrid(*args): 
     42        """Allow meshgrid with a single argument""" 
    4243        if len(args) > 1: 
    4344            return np.meshgrid(*args) 
     
    6364    """ 
    6465    Return the list of available models on the model path. 
     66 
     67    *kind* can be one of the following: 
     68 
     69        * all: all models 
     70        * py: python models only 
     71        * c: compiled models only 
     72        * single: models which support single precision 
     73        * double: models which require double precision 
     74        * 1d: models which are 1D only, or 2D using abs(q) 
     75        * 2d: models which can be 2D 
     76        * magnetic: models with an sld 
     77        * nommagnetic: models without an sld 
    6578    """ 
    6679    if kind and kind not in KINDS: 
     
    88101    elif kind == "2d" and any(p.type == 'orientation' for p in pars): 
    89102        return True 
    90     elif kind == "1d" and any(p.type != 'orientation' for p in pars): 
     103    elif kind == "1d" and all(p.type != 'orientation' for p in pars): 
    91104        return True 
    92105    elif kind == "magnetic" and any(p.type == 'sld' for p in pars): 
     
    252265 
    253266def list_models_main(): 
     267    # type: () -> None 
     268    """ 
     269    Run list_models as a main program.  See :func:`list_models` for the 
     270    kinds of models that can be requested on the command line. 
     271    """ 
    254272    import sys 
    255273    kind = sys.argv[1] if len(sys.argv) > 1 else "all" 
  • sasmodels/custom/__init__.py

    r56b2687 r40a87fa  
    1616    from importlib.util import spec_from_file_location, module_from_spec  # type: ignore 
    1717    def load_module_from_path(fullname, path): 
     18        """load module from *path* as *fullname*""" 
    1819        spec = spec_from_file_location(fullname, path) 
    1920        module = module_from_spec(spec) 
     
    2425    import imp 
    2526    def load_module_from_path(fullname, path): 
     27        """load module from *path* as *fullname*""" 
    2628        module = imp.load_source(fullname, path) 
    2729        #os.unlink(path+"c")  # remove the automatic pyc file 
     
    2931 
    3032def load_custom_kernel_module(path): 
     33    """load SAS kernel from *path* as *sasmodels.custom.modelname*""" 
    3134    # Pull off the last .ext if it exists; there may be others 
    3235    name = basename(splitext(path)[0]) 
  • sasmodels/data.py

    r56b2687 r40a87fa  
    155155 
    156156class SesansData(Data1D): 
     157    """ 
     158    SESANS data object. 
     159 
     160    This is just :class:`Data1D` with a wavelength parameter. 
     161 
     162    *x* is spin echo length and *y* is polarization (P/P0). 
     163    """ 
    157164    def __init__(self, **kw): 
    158165        Data1D.__init__(self, **kw) 
     
    213220        self._zaxis, self._zunit = "z", "" 
    214221        self.x_bins, self.y_bins = None, None 
     222        self.filename = None 
    215223 
    216224    def xaxis(self, label, unit): 
     
    377385 
    378386 
    379 def protect(fn): 
     387def protect(func): 
    380388    # type: (Callable) -> Callable 
    381389    """ 
     
    388396        """ 
    389397        try: 
    390             return fn(*args, **kw) 
     398            return func(*args, **kw) 
    391399        except Exception: 
    392400            traceback.print_exc() 
     
    410418    use_calc = use_theory and Iq_calc is not None 
    411419    num_plots = (use_data or use_theory) + use_calc + use_resid 
    412     non_positive_x = (data.x<=0.0).any() 
     420    non_positive_x = (data.x <= 0.0).any() 
    413421 
    414422    scale = data.x**4 if view == 'q4' else 1.0 
     
    456464        plt.subplot(1, num_plots, 2) 
    457465        qx, qy, Iqxy = Iq_calc 
    458         plt.pcolormesh(qx, qy[qy>0], np.log10(Iqxy[qy>0,:])) 
     466        plt.pcolormesh(qx, qy[qy > 0], np.log10(Iqxy[qy > 0, :])) 
    459467        plt.xlabel("$q_x$/A$^{-1}$") 
    460468        plt.xlabel("$q_y$/A$^{-1}$") 
     
    508516        plt.xlabel('spin echo length ({})'.format(data._xunit)) 
    509517        if is_tof: 
    510             plt.ylabel('(Log (P/P$_0$))/$\lambda^2$') 
     518            plt.ylabel(r'(Log (P/P$_0$))/$\lambda^2$') 
    511519        else: 
    512520            plt.ylabel('polarization (P/P0)') 
  • sasmodels/details.py

    rbaa79c2 r40a87fa  
    113113    @pd_prod.setter 
    114114    def pd_prod(self, v): 
     115        """Total size of the pd mesh""" 
    115116        self.buffer[-4] = v 
    116117 
     
    122123    @pd_sum.setter 
    123124    def pd_sum(self, v): 
     125        """Total length of all the weight vectors""" 
    124126        self.buffer[-3] = v 
    125127 
     
    131133    @num_active.setter 
    132134    def num_active(self, v): 
     135        """Number of active polydispersity loops""" 
    133136        self.buffer[-2] = v 
    134137 
     
    140143    @theta_par.setter 
    141144    def theta_par(self, v): 
     145        """Location of the theta parameter in the parameter vector""" 
    142146        self.buffer[-1] = v 
    143147 
     
    185189    pd_length = np.array([len(w) 
    186190                          for w in weights[2:2+model_info.parameters.npars]]) 
    187     num_active = np.sum(pd_length>1) 
     191    num_active = np.sum(pd_length > 1) 
    188192    max_pd = model_info.parameters.max_pd 
    189193    if num_active > max_pd: 
     
    250254    values, weights = zip(*pairs) 
    251255    scalars = [v[0] for v in values] 
    252     if all(len(w)==1 for w in weights): 
     256    if all(len(w) == 1 for w in weights): 
    253257        call_details = mono_details(kernel.info) 
    254258        # Pad value array to a 32 value boundary 
     
    276280    mag = values[parameters.nvalues-3*parameters.nmagnetic:parameters.nvalues] 
    277281    mag = mag.reshape(-1, 3) 
    278     M0 = mag[:,0] 
    279     if np.any(M0): 
    280         theta, phi = mag[:,1]*pi/180., mag[:,2]*pi/180. 
     282    scale = mag[:,0] 
     283    if np.any(scale): 
     284        theta, phi = mag[:, 1]*pi/180., mag[:, 2]*pi/180. 
    281285        cos_theta = cos(theta) 
    282         mx = M0*cos_theta*cos(phi) 
    283         my = M0*sin(theta) 
    284         mz = -M0*cos_theta*sin(phi) 
    285         mag[:,0], mag[:,1], mag[:,2] = mx, my, mz 
     286        mag[:, 0] = scale*cos_theta*cos(phi)  # mx 
     287        mag[:, 1] = scale*sin(theta)  # my 
     288        mag[:, 2] = -scale*cos_theta*sin(phi)  # mz 
    286289        return True 
    287290    else: 
  • sasmodels/direct_model.py

    r745b7bb r40a87fa  
    3030from . import resolution 
    3131from . import resolution2d 
    32 from .details import build_details 
     32from .details import build_details, dispersion_mesh 
    3333 
    3434try: 
     
    7373    #print("values:", values) 
    7474    return calculator(call_details, values, cutoff, is_magnetic) 
     75 
     76 
     77def call_ER(model_info, pars): 
     78    # type: (ModelInfo, ParameterSet) -> float 
     79    """ 
     80    Call the model ER function using *values*. 
     81 
     82    *model_info* is either *model.info* if you have a loaded model, 
     83    or *kernel.info* if you have a model kernel prepared for evaluation. 
     84    """ 
     85    if model_info.ER is None: 
     86        return 1.0 
     87    else: 
     88        value, weight = _vol_pars(model_info, pars) 
     89        individual_radii = model_info.ER(*value) 
     90        return np.sum(weight*individual_radii) / np.sum(weight) 
     91 
     92 
     93def call_VR(model_info, pars): 
     94    # type: (ModelInfo, ParameterSet) -> float 
     95    """ 
     96    Call the model VR function using *pars*. 
     97 
     98    *model_info* is either *model.info* if you have a loaded model, 
     99    or *kernel.info* if you have a model kernel prepared for evaluation. 
     100    """ 
     101    if model_info.VR is None: 
     102        return 1.0 
     103    else: 
     104        value, weight = _vol_pars(model_info, pars) 
     105        whole, part = model_info.VR(*value) 
     106        return np.sum(weight*part)/np.sum(weight*whole) 
     107 
     108 
     109def call_profile(model_info, **pars): 
     110    # type: (ModelInfo, ...) -> Tuple[np.ndarray, np.ndarray, Tuple[str, str]] 
     111    """ 
     112    Returns the profile *x, y, (xlabel, ylabel)* representing the model. 
     113    """ 
     114    args = {} 
     115    for p in model_info.parameters.kernel_parameters: 
     116        if p.length > 1: 
     117            value = np.array([pars.get(p.id+str(j), p.default) 
     118                              for j in range(1, p.length+1)]) 
     119        else: 
     120            value = pars.get(p.id, p.default) 
     121        args[p.id] = value 
     122    x, y = model_info.profile(**args) 
     123    return x, y, model_info.profile_axes 
    75124 
    76125 
     
    98147 
    99148 
    100 def call_profile(model_info, **pars): 
    101     args = {} 
    102     for p in model_info.parameters.kernel_parameters: 
    103         if p.length > 1: 
    104             value = np.array([pars.get(p.id+str(j), p.default) 
    105                               for j in range(1, p.length+1)]) 
    106         else: 
    107             value = pars.get(p.id, p.default) 
    108         args[p.id] = value 
    109     x, y = model_info.profile(**args) 
    110     return x, y, model_info.profile_axes 
     149def _vol_pars(model_info, pars): 
     150    # type: (ModelInfo, ParameterSet) -> Tuple[np.ndarray, np.ndarray] 
     151    vol_pars = [get_weights(p, pars) 
     152                for p in model_info.parameters.call_parameters 
     153                if p.type == 'volume'] 
     154    value, weight = dispersion_mesh(model_info, vol_pars) 
     155    return value, weight 
    111156 
    112157 
     
    158203                Iq, dIq = None, None 
    159204            #self._theory = np.zeros_like(q) 
    160             q_vectors = [q]             
     205            q_vectors = [q] 
    161206            q_mono = sesans.make_all_q(data) 
    162207        elif self.data_type == 'Iqxy': 
     
    213258                Iq, dIq = None, None 
    214259            if (getattr(data, 'dxl', None) is None 
    215                 or getattr(data, 'dxw', None) is None): 
     260                    or getattr(data, 'dxw', None) is None): 
    216261                raise ValueError("oriented sample with 1D data needs slit resolution") 
    217262 
     
    254299        if self._kernel is None: 
    255300            self._kernel = self._model.make_kernel(self._kernel_inputs) 
    256             self._kernel_mono = (self._model.make_kernel(self._kernel_mono_inputs) 
    257                                  if self._kernel_mono_inputs else None) 
     301            self._kernel_mono = ( 
     302                self._model.make_kernel(self._kernel_mono_inputs) 
     303                if self._kernel_mono_inputs else None) 
    258304 
    259305        Iq_calc = call_kernel(self._kernel, pars, cutoff=cutoff) 
    260         # TODO: may want to plot the raw Iq for other than oriented usans 
     306        # Storing the calculated Iq values so that they can be plotted. 
     307        # Only applies to oriented USANS data for now. 
     308        # TODO: extend plotting of calculate Iq to other measurement types 
     309        # TODO: refactor so we don't store the result in the model 
    261310        self.Iq_calc = None 
    262311        if self.data_type == 'sesans': 
     
    264313                       if self._kernel_mono_inputs else None) 
    265314            result = sesans.transform(self._data, 
    266                                    self._kernel_inputs[0], Iq_calc,  
    267                                    self._kernel_mono_inputs, Iq_mono) 
     315                                      self._kernel_inputs[0], Iq_calc, 
     316                                      self._kernel_mono_inputs, Iq_mono) 
    268317        else: 
    269318            result = self.resolution.apply(Iq_calc) 
     
    273322                    np.reshape(Iq_calc, (self.resolution.ny, self.resolution.nx)) 
    274323                ) 
    275         return result         
     324        return result 
    276325 
    277326 
     
    350399                for k, v in [pair.split('=')]) 
    351400    if call == "ER_VR": 
    352         print(calculator.ER_VR(**pars)) 
     401        ER = call_ER(model_info, pars) 
     402        VR = call_VR(model_info, pars) 
     403        print(ER, VR) 
    353404    else: 
    354405        Iq = calculator(**pars) 
  • sasmodels/kernelcl.py

    r20317b3 r40a87fa  
    6262    cl.create_some_context(interactive=False) 
    6363except Exception as exc: 
    64     warnings.warn("OpenCL startup failed with ***"+str(exc)+"***; using C compiler instead") 
     64    warnings.warn("OpenCL startup failed with ***" 
     65                  + str(exc) + "***; using C compiler instead") 
    6566    raise RuntimeError("OpenCL not available") 
    6667 
     
    9091 
    9192def fix_pyopencl_include(): 
     93    """ 
     94    Monkey patch pyopencl to allow spaces in include file path. 
     95    """ 
    9296    import pyopencl as cl 
    9397    if hasattr(cl, '_DEFAULT_INCLUDE_OPTIONS'): 
  • sasmodels/kerneldll.py

    r739aad4 r40a87fa  
    4848import sys 
    4949import os 
    50 from os.path import join as joinpath, split as splitpath, splitext 
     50from os.path import join as joinpath, splitext 
    5151import subprocess 
    5252import tempfile 
     
    100100        CC.append("-fopenmp") 
    101101    def compile_command(source, output): 
     102        """unix compiler command""" 
    102103        return CC + [source, "-o", output, "-lm"] 
    103104elif compiler == "msvc": 
     
    115116    LN = "/link /DLL /INCREMENTAL:NO /MANIFEST".split() 
    116117    def compile_command(source, output): 
     118        """MSVC compiler command""" 
    117119        return CC + ["/Tp%s"%source] + LN + ["/OUT:%s"%output] 
    118120elif compiler == "tinycc": 
     
    120122    CC = [tinycc.TCC] + "-shared -rdynamic -Wall".split() 
    121123    def compile_command(source, output): 
     124        """tinycc compiler command""" 
    122125        return CC + [source, "-o", output] 
    123126elif compiler == "mingw": 
     
    127130        CC.append("-fopenmp") 
    128131    def compile_command(source, output): 
     132        """mingw compiler command""" 
    129133        return CC + [source, "-o", output, "-lm"] 
    130134 
     
    142146 
    143147def compile(source, output): 
     148    # type: (str, str) -> None 
     149    """ 
     150    Compile *source* producing *output*. 
     151 
     152    Raises RuntimeError if the compile failed or the output wasn't produced. 
     153    """ 
    144154    command = compile_command(source=source, output=output) 
    145155    command_str = " ".join('"%s"'%p if ' ' in p else p for p in command) 
     
    219229        need_recompile = dll_time < newest_source 
    220230    if need_recompile: 
    221         basename = os.path.splitext(os.path.basename(dll))[0] + "_" 
    222         fd, filename = tempfile.mkstemp(suffix=".c", prefix=basename) 
     231        basename = splitext(os.path.basename(dll))[0] + "_" 
     232        system_fd, filename = tempfile.mkstemp(suffix=".c", prefix=basename) 
    223233        source = generate.convert_type(source, dtype) 
    224         with os.fdopen(fd, "w") as file: 
    225             file.write(source) 
     234        with os.fdopen(system_fd, "w") as file_handle: 
     235            file_handle.write(source) 
    226236        compile(source=filename, output=dll) 
    227237        # comment the following to keep the generated c file 
     
    260270    Call :meth:`release` when done with the kernel. 
    261271    """ 
    262      
    263272    def __init__(self, dllpath, model_info, dtype=generate.F32): 
    264273        # type: (str, ModelInfo, np.dtype) -> None 
     
    266275        self.dllpath = dllpath 
    267276        self._dll = None  # type: ct.CDLL 
     277        self._kernels = None # type: List[Callable, Callable] 
    268278        self.dtype = np.dtype(dtype) 
    269279 
     
    277287            raise 
    278288 
    279         fp = (c_float if self.dtype == generate.F32 
    280               else c_double if self.dtype == generate.F64 
    281               else c_longdouble) 
     289        float_type = (c_float if self.dtype == generate.F32 
     290                      else c_double if self.dtype == generate.F64 
     291                      else c_longdouble) 
    282292 
    283293        # int, int, int, int*, double*, double*, double*, double*, double 
    284         argtypes = [c_int32]*3 + [c_void_p]*4 + [fp] 
     294        argtypes = [c_int32]*3 + [c_void_p]*4 + [float_type] 
    285295        names = [generate.kernel_name(self.info, variant) 
    286296                 for variant in ("Iq", "Iqxy", "Imagnetic")] 
     
    316326            #dll = ct.cdll.LoadLibrary(self.dllpath) 
    317327            dll = ct.CDLL(self.dllpath) 
    318             libHandle = dll._handle 
    319             #libHandle = ct.c_void_p(dll._handle) 
     328            dll_handle = dll._handle 
     329            #dll_handle = ct.c_void_p(dll._handle) 
    320330            del dll, self._dll 
    321331            self._dll = None 
    322             ct.windll.kernel32.FreeLibrary(libHandle) 
    323         else:     
    324             pass  
     332            ct.windll.kernel32.FreeLibrary(dll_handle) 
     333        else: 
     334            pass 
    325335 
    326336 
  • sasmodels/kernelpy.py

    r32e3c9b r40a87fa  
    143143        if q_input.is_2d: 
    144144            form = model_info.Iqxy 
    145             qx, qy = q_input.q[:,0], q_input.q[:,1] 
     145            qx, qy = q_input.q[:, 0], q_input.q[:, 1] 
    146146            self._form = lambda: form(qx, qy, *kernel_args) 
    147147        else: 
     
    168168        self.q_input = None 
    169169 
    170 def _loops(parameters, form, form_volume, nq, details, 
    171            values, cutoff): 
     170def _loops(parameters, form, form_volume, nq, call_details, values, cutoff): 
    172171    # type: (np.ndarray, Callable[[], np.ndarray], Callable[[], float], int, details.CallDetails, np.ndarray, np.ndarray, float) -> None 
    173172    ################################################################ 
     
    180179    #                                                              # 
    181180    ################################################################ 
    182     NPARS = len(parameters) 
    183     parameters[:] = values[2:NPARS+2] 
     181    n_pars = len(parameters) 
     182    parameters[:] = values[2:n_pars+2] 
    184183    scale, background = values[0], values[1] 
    185     if details.num_active == 0: 
     184    if call_details.num_active == 0: 
    186185        norm = float(form_volume()) 
    187186        if norm > 0.0: 
     
    190189            return np.ones(nq, 'd')*background 
    191190 
    192     pd_value = values[2+NPARS:2+NPARS+details.pd_sum] 
    193     pd_weight = values[2+NPARS+details.pd_sum:] 
     191    pd_value = values[2+n_pars:2+n_pars + call_details.pd_sum] 
     192    pd_weight = values[2+n_pars + call_details.pd_sum:] 
    194193 
    195194    pd_norm = 0.0 
    196195    spherical_correction = 1.0 
    197196    partial_weight = np.NaN 
    198     weight =np.NaN 
    199  
    200     p0_par = details.pd_par[0] 
    201     p0_is_theta = (p0_par == details.theta_par) 
    202     p0_length = details.pd_length[0] 
     197    weight = np.NaN 
     198 
     199    p0_par = call_details.pd_par[0] 
     200    p0_is_theta = (p0_par == call_details.theta_par) 
     201    p0_length = call_details.pd_length[0] 
    203202    p0_index = p0_length 
    204     p0_offset = details.pd_offset[0] 
    205  
    206     pd_par = details.pd_par[:details.num_active] 
    207     pd_offset = details.pd_offset[:details.num_active] 
    208     pd_stride = details.pd_stride[:details.num_active] 
    209     pd_length = details.pd_length[:details.num_active] 
     203    p0_offset = call_details.pd_offset[0] 
     204 
     205    pd_par = call_details.pd_par[:call_details.num_active] 
     206    pd_offset = call_details.pd_offset[:call_details.num_active] 
     207    pd_stride = call_details.pd_stride[:call_details.num_active] 
     208    pd_length = call_details.pd_length[:call_details.num_active] 
    210209 
    211210    total = np.zeros(nq, 'd') 
    212     for loop_index in range(details.pd_prod): 
     211    for loop_index in range(call_details.pd_prod): 
    213212        # update polydispersity parameter values 
    214213        if p0_index == p0_length: 
     
    216215            parameters[pd_par] = pd_value[pd_offset+pd_index] 
    217216            partial_weight = np.prod(pd_weight[pd_offset+pd_index][1:]) 
    218             if details.theta_par >= 0: 
    219                 spherical_correction = max(abs(cos(pi/180 * parameters[details.theta_par])), 1e-6) 
     217            if call_details.theta_par >= 0: 
     218                cor = cos(pi / 180 * parameters[call_details.theta_par]) 
     219                spherical_correction = max(abs(cor), 1e-6) 
    220220            p0_index = loop_index%p0_length 
    221221 
     
    223223        parameters[p0_par] = pd_value[p0_offset + p0_index] 
    224224        if p0_is_theta: 
    225             spherical_correction = max(abs(cos(pi/180 * parameters[p0_par])), 1e-6) 
     225            cor = cos(pi/180 * parameters[p0_par]) 
     226            spherical_correction = max(abs(cor), 1e-6) 
    226227        p0_index += 1 
    227228        if weight > cutoff: 
     
    230231            # exclude all q for that NaN.  Even better would be to have an 
    231232            # INVALID expression like the C models, but that is too expensive. 
    232             I = form() 
    233             if np.isnan(I).any(): continue 
     233            Iq = form() 
     234            if np.isnan(Iq).any(): continue 
    234235 
    235236            # update value and norm 
    236237            weight *= spherical_correction 
    237             total += weight * I 
     238            total += weight * Iq 
    238239            pd_norm += weight * form_volume() 
    239240 
  • sasmodels/model_test.py

    r2c74c11 r40a87fa  
    5151 
    5252from .core import list_models, load_model_info, build_model, HAVE_OPENCL 
    53 from .details import dispersion_mesh 
    54 from .direct_model import call_kernel, get_weights 
     53from .direct_model import call_kernel, call_ER, call_VR 
    5554from .exception import annotate_exception 
    5655from .modelinfo import expand_pars 
     
    6362    from .modelinfo import ParameterTable, ParameterSet, TestCondition, ModelInfo 
    6463    from .kernel import KernelModel 
    65  
    66 def call_ER(model_info, pars): 
    67     # type: (ModelInfo, ParameterSet) -> float 
    68     """ 
    69     Call the model ER function using *values*. 
    70  
    71     *model_info* is either *model.info* if you have a loaded model, 
    72     or *kernel.info* if you have a model kernel prepared for evaluation. 
    73     """ 
    74     if model_info.ER is None: 
    75         return 1.0 
    76     else: 
    77         value, weight = _vol_pars(model_info, pars) 
    78         individual_radii = model_info.ER(*value) 
    79         return np.sum(weight*individual_radii) / np.sum(weight) 
    80  
    81 def call_VR(model_info, pars): 
    82     # type: (ModelInfo, ParameterSet) -> float 
    83     """ 
    84     Call the model VR function using *pars*. 
    85  
    86     *model_info* is either *model.info* if you have a loaded model, 
    87     or *kernel.info* if you have a model kernel prepared for evaluation. 
    88     """ 
    89     if model_info.VR is None: 
    90         return 1.0 
    91     else: 
    92         value, weight = _vol_pars(model_info, pars) 
    93         whole, part = model_info.VR(*value) 
    94         return np.sum(weight*part)/np.sum(weight*whole) 
    95  
    96 def _vol_pars(model_info, pars): 
    97     # type: (ModelInfo, ParameterSet) -> Tuple[np.ndarray, np.ndarray] 
    98     vol_pars = [get_weights(p, pars) 
    99                 for p in model_info.parameters.call_parameters 
    100                 if p.type == 'volume'] 
    101     value, weight = dispersion_mesh(model_info, vol_pars) 
    102     return value, weight 
    10364 
    10465 
     
    194155        def run_all(self): 
    195156            # type: () -> None 
     157            """ 
     158            Run all the tests in the test suite, including smoke tests. 
     159            """ 
    196160            smoke_tests = [ 
    197161                # test validity at reasonable values 
     
    230194        def run_one(self, model, test): 
    231195            # type: (KernelModel, TestCondition) -> None 
     196            """Run a single test case.""" 
    232197            user_pars, x, y = test 
    233198            pars = expand_pars(self.info.parameters, user_pars) 
     
    269234                    # is_near does not work for infinite values, so also test 
    270235                    # for exact values.  Note that this will not 
    271                     self.assertTrue(yi==actual_yi or is_near(yi, actual_yi, 5), 
     236                    self.assertTrue(yi == actual_yi or is_near(yi, actual_yi, 5), 
    272237                                    'f(%s); expected:%s; actual:%s' 
    273238                                    % (xi, yi, actual_yi)) 
     
    293258    try: 
    294259        from xmlrunner import XMLTestRunner as TestRunner 
    295         test_args = { 'output': 'logs' } 
     260        test_args = {'output': 'logs'} 
    296261    except ImportError: 
    297262        from unittest import TextTestRunner as TestRunner 
    298         test_args = { } 
     263        test_args = {} 
    299264 
    300265    models = sys.argv[1:] 
  • sasmodels/modelinfo.py

    r50ec515 r40a87fa  
    4646] 
    4747assert (len(COMMON_PARAMETERS) == 2 
    48         and COMMON_PARAMETERS[0][0]=="scale" 
    49         and COMMON_PARAMETERS[1][0]=="background"), "don't change common parameters" 
     48        and COMMON_PARAMETERS[0][0] == "scale" 
     49        and COMMON_PARAMETERS[1][0] == "background"), "don't change common parameters" 
    5050 
    5151 
     
    131131 
    132132    # automatically identify sld types 
    133     if ptype== '' and (pid.startswith('sld') or pid.endswith('sld')): 
     133    if ptype == '' and (pid.startswith('sld') or pid.endswith('sld')): 
    134134        ptype = 'sld' 
    135135 
     
    182182        scalars = dict((name, value) for name, value in pars.items() 
    183183                       if name not in lookup or lookup[name].length == 1) 
    184         vectors = dict((name,value) for name,value in pars.items() 
     184        vectors = dict((name, value) for name, value in pars.items() 
    185185                       if name in lookup and lookup[name].length > 1) 
    186186        #print("lookup", lookup) 
     
    199199                    # supoprt for the form 
    200200                    #    dict(thickness=[20,10,3]) 
    201                     for (k,v) in enumerate(value): 
     201                    for (k, v) in enumerate(value): 
    202202                        scalars[name+str(k+1)] = v 
    203203        result.update(scalars) 
     
    275275 
    276276    * *relative_pd* is true if that polydispersity is a portion of the 
    277     value (so a 10% length dipsersity would use a polydispersity value of 0.1) 
    278     rather than absolute dispersisity (such as an angle plus or minus 
    279     15 degrees). 
     277      value (so a 10% length dipsersity would use a polydispersity value 
     278      of 0.1) rather than absolute dispersisity (such as an angle plus or 
     279      minus 15 degrees). 
    280280 
    281281    *choices* is the option names for a drop down list of options, as for 
     
    325325    def as_function_argument(self): 
    326326        # type: () -> str 
    327         """ 
     327        r""" 
    328328        Declare the variable as a function argument. 
    329329 
    330330        For example, the parameter thickness with length 3 will 
    331         return "double *thickness", with no spaces before and 
     331        return "double \*thickness", with no spaces before and 
    332332        no comma afterward. 
    333333        """ 
     
    370370 
    371371    * *kernel_parameters* is the list of parameters in the kernel parameter 
    372     table, with vector parameter p declared as p[]. 
     372      table, with vector parameter p declared as p[]. 
    373373 
    374374    * *iq_parameters* is the list of parameters to the Iq(q, ...) function, 
    375     with vector parameter p sent as p[]. 
     375      with vector parameter p sent as p[]. 
    376376 
    377377    * *iqxy_parameters* is the list of parameters to the Iqxy(qx, qy, ...) 
    378     function, with vector parameter p sent as p[]. 
     378      function, with vector parameter p sent as p[]. 
    379379 
    380380    * *form_volume_parameters* is the list of parameters to the form_volume(...) 
    381     function, with vector parameter p sent as p[]. 
     381      function, with vector parameter p sent as p[]. 
    382382 
    383383    Problem details, which sets up the polydispersity loops, requires the 
     
    385385 
    386386    * *theta_offset* is the offset of the theta parameter in the kernel parameter 
    387     table, with vector parameters counted as n individual parameters 
    388     p1, p2, ..., or offset is -1 if there is no theta parameter. 
     387      table, with vector parameters counted as n individual parameters 
     388      p1, p2, ..., or offset is -1 if there is no theta parameter. 
    389389 
    390390    * *max_pd* is the maximum number of polydisperse parameters, with vector 
    391     parameters counted as n individual parameters p1, p2, ...  Note that 
    392     this number is limited to sasmodels.modelinfo.MAX_PD. 
     391      parameters counted as n individual parameters p1, p2, ...  Note that 
     392      this number is limited to sasmodels.modelinfo.MAX_PD. 
    393393 
    394394    * *npars* is the total number of parameters to the kernel, with vector 
    395     parameters counted as n individual parameters p1, p2, ... 
     395      parameters counted as n individual parameters p1, p2, ... 
    396396 
    397397    * *call_parameters* is the complete list of parameters to the kernel, 
    398     including scale and background, with vector parameters recorded as 
    399     individual parameters p1, p2, ... 
     398      including scale and background, with vector parameters recorded as 
     399      individual parameters p1, p2, ... 
    400400 
    401401    * *active_1d* is the set of names that may be polydisperse for 1d data 
     
    406406    the scale and background parameters that the kernel does not see.  User 
    407407    parameters don't use vector notation, and instead use p1, p2, ... 
    408  
    409408    """ 
    410409    # scale and background are implicit parameters 
     
    830829    #: form of "section" or "section:subsection".  So for example, 
    831830    #: :ref:`porod` uses *category="shape-independent"* so it is in the 
    832     #: :ref:`Shape-independent` section whereas 
    833     #: :ref:`capped_cylinder` uses: *category="shape:cylinder"*, which puts 
     831    #: :ref:`shape-independent` section whereas 
     832    #: :ref:`capped-cylinder` uses: *category="shape:cylinder"*, which puts 
    834833    #: it in the :ref:`shape-cylinder` section. 
    835834    category = None         # type: Optional[str] 
    836835    #: True if the model can be computed accurately with single precision. 
    837     #: This is True by default, but models such as :ref:`bcc_paracrystal` set 
     836    #: This is True by default, but models such as :ref:`bcc-paracrystal` set 
    838837    #: it to False because they require double precision calculations. 
    839838    single = None           # type: bool 
  • sasmodels/models/adsorbed_layer.py

    r2c74c11 r40a87fa  
    9393    inten = 6.0e-02 * pi * volfraction * aa**2 * exp(-bb**2) / radius 
    9494    return inten 
    95 Iq.vectorized =  True  # Iq accepts an array of q values 
     95Iq.vectorized = True  # Iq accepts an array of q values 
    9696 
    9797# unit test values taken from SasView 3.1.2 
    98 tests =  [ 
     98tests = [ 
    9999    [{'scale': 1.0, 'second_moment': 23.0, 'adsorbed_amount': 1.9, 
    100100      'density_shell': 0.7, 'radius': 500.0, 'volfraction': 0.14, 
  • sasmodels/models/broad_peak.py

    r2c74c11 r40a87fa  
    1515The scattering intensity $I(q)$ is calculated as 
    1616 
    17 .. math:: 
    18  
    19     I(q) = \frac{A}{q^n} + \frac{C}{1 + (|q - q_0|\xi)^m} + B 
     17.. math:: I(q) = \frac{A}{q^n} + \frac{C}{1 + (|q - q_0|\xi)^m} + B 
    2018 
    2119Here the peak position is related to the d-spacing as $q_o = 2\pi / d_o$. 
    2220 
    23 $A$ is the Porod law scale factor, $n$ the Porod exponent, $C$ is the Lorentzian  
    24 scale factor, $m$ the exponent of q, \ |xi|\  the screening length, and $B$ the flat background. 
     21$A$ is the Porod law scale factor, $n$ the Porod exponent, $C$ is the 
     22Lorentzian scale factor, $m$ the exponent of $q$, $\xi$ the screening length, 
     23and $B$ the flat background. 
    2524 
    2625For 2D data the scattering intensity is calculated in the same way as 1D, 
    2726where the $q$ vector is defined as 
    2827 
    29 .. math:: 
    30  
    31     q = \sqrt{q_x^2 + q_y^2} 
    32  
     28.. math:: q = \sqrt{q_x^2 + q_y^2} 
    3329 
    3430References 
     
    3834 
    3935*2013/09/09 - Description reviewed by King, S and Parker, P.* 
    40  
    4136""" 
    4237 
  • sasmodels/models/core_multi_shell.py

    re187b25 r40a87fa  
    44 
    55This model is a trivial extension of the CoreShell function to a larger number 
    6 of shells. The scattering length density profile for the default sld values  
     6of shells. The scattering length density profile for the default sld values 
    77(w/ 4 shells). 
    88 
     
    2525          effective radius for $S(Q)$ when $P(Q)*S(Q)$ is applied. 
    2626 
    27 For information about polarised and magnetic scattering, see  
     27For information about polarised and magnetic scattering, see 
    2828the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 
    2929 
     
    3333References 
    3434---------- 
    35 See the :ref:`core_shell_sphere <core_shell_sphere>` model documentation. 
     35See the :ref:`core-shell-sphere` model documentation. 
    3636 
    3737L A Feigin and D I Svergun, 
     
    5151 
    5252import numpy as np 
    53 from numpy import inf, nan 
    54 from math import fabs, exp, expm1 
     53from numpy import inf 
    5554 
    5655name = "core_multi_shell" 
     
    9998              ["thickness[n]", "Ang", 40., [0, inf], "volume", 
    10099               "Thickness of shell k"], 
    101               ] 
     100             ] 
    102101 
    103102source = ["lib/sph_j1c.c", "core_multi_shell.c"] 
     
    107106    Returns the SLD profile *r* (Ang), and *rho* (1e-6/Ang^2). 
    108107    """ 
    109     r = [] 
     108    z = [] 
    110109    rho = [] 
    111110 
    112111    # add in the core 
    113     r.append(0) 
     112    z.append(0) 
    114113    rho.append(sld_core) 
    115     r.append(radius) 
     114    z.append(radius) 
    116115    rho.append(sld_core) 
    117116 
     
    119118    for k in range(n): 
    120119        # Left side of each shells 
    121         r.append(r[-1]) 
     120        z.append(z[-1]) 
    122121        rho.append(sld[k]) 
    123         r.append(r[-1] + thickness[k]) 
     122        z.append(z[-1] + thickness[k]) 
    124123        rho.append(sld[k]) 
    125124    # add in the solvent 
    126     r.append(r[-1]) 
     125    z.append(z[-1]) 
    127126    rho.append(sld_solvent) 
    128     r.append(r[-1]*1.25) 
     127    z.append(z[-1]*1.25) 
    129128    rho.append(sld_solvent) 
    130129 
    131     return np.asarray(r), np.asarray(rho) 
     130    return np.asarray(z), np.asarray(rho) 
    132131 
    133132def ER(radius, n, thickness): 
     133    """Effective radius""" 
    134134    n = n[0]  # n cannot be polydisperse 
    135135    return np.sum(thickness[:n], axis=0) + radius 
    136136 
    137 def VR(radius, n, thickness): 
    138     return 1.0, 1.0 
    139  
    140 demo = dict(sld_core = 6.4, 
    141             radius = 60, 
    142             sld_solvent = 6.4, 
    143             n = 2, 
    144             sld = [2.0, 3.0], 
    145             thickness = 20, 
    146             thickness1_pd = 0.3, 
    147             thickness2_pd = 0.3, 
    148             thickness1_pd_n = 10, 
    149             thickness2_pd_n = 10, 
     137demo = dict(sld_core=6.4, 
     138            radius=60, 
     139            sld_solvent=6.4, 
     140            n=2, 
     141            sld=[2.0, 3.0], 
     142            thickness=20, 
     143            thickness1_pd=0.3, 
     144            thickness2_pd=0.3, 
     145            thickness1_pd_n=10, 
     146            thickness2_pd_n=10, 
    150147            ) 
  • sasmodels/models/core_shell_bicelle.py

    r42356c8 r40a87fa  
    33Definition 
    44---------- 
    5 This model provides the form factor for a circular cylinder with a core-shell 
    6 scattering length density profile. Thus this is a variation of a core-shell cylinder  
    7 or disc where the shell on the walls and ends may be of different thicknesses and scattering 
    8 length densities. The form factor is normalized by the particle volume. 
     5This model provides the form factor for a circular cylinder with a 
     6core-shell scattering length density profile. Thus this is a variation 
     7of a core-shell cylinder or disc where the shell on the walls and ends 
     8may be of different thicknesses and scattering length densities. The form 
     9factor is normalized by the particle volume. 
    910 
    1011.. _core-shell-bicelle-geometry: 
     
    1213.. figure:: img/core_shell_bicelle_geometry.png 
    1314 
    14     (Graphic from DOI: 10.1039/C0NP00002G, note however that the model here calculates for rectangular, not curved, rims.) 
    15  
     15    (Graphic from DOI: 10.1039/C0NP00002G, note however that the model here 
     16    calculates for rectangular, not curved, rims.) 
    1617 
    1718The output of the 1D scattering intensity function for randomly oriented 
     
    8889# pylint: enable=bad-whitespace, line-too-long 
    8990 
    90 source = ["lib/Si.c","lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "core_shell_bicelle.c"] 
     91source = ["lib/Si.c", "lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", 
     92          "core_shell_bicelle.c"] 
    9193 
    9294demo = dict(scale=1, background=0, 
  • sasmodels/models/core_shell_cylinder.py

    r42356c8 r40a87fa  
    5252 
    5353To provide easy access to the orientation of the core-shell cylinder, we 
    54 define the axis of the cylinder using two angles $\theta$ and $\phi$.  
     54define the axis of the cylinder using two angles $\theta$ and $\phi$. 
    5555(see :ref:`cylinder model <cylinder-angle-definition>`) 
    5656 
     
    130130             ] 
    131131 
    132 source = ["lib/polevl.c","lib/sas_J1.c", "lib/gauss76.c", "core_shell_cylinder.c"] 
     132source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "core_shell_cylinder.c"] 
    133133 
    134134def ER(radius, thickness, length): 
    135135    """ 
    136         Returns the effective radius used in the S*P calculation 
     136    Returns the effective radius used in the S*P calculation 
    137137    """ 
    138138    radius = radius + thickness 
     
    143143def VR(radius, thickness, length): 
    144144    """ 
    145         Returns volume ratio 
     145    Returns volume ratio 
    146146    """ 
    147147    whole = pi * (radius + thickness) ** 2 * (length + 2 * thickness) 
  • sasmodels/models/core_shell_ellipsoid.py

    r7f1ee79 r40a87fa  
    55.. math:: 
    66 
    7     P(q) = scale * \left<f^2\right>/V + background 
     7    P(q) = \text{scale} * \left<f^2\right>/V + \text{background} 
    88 
    9 where the volume $V = (4/3)\pi(R_{major\_outer}R_{minor\_outer}^2)$ and the averaging $< >$ is 
    10 applied over all orientations for 1D. 
     9where the volume $V = (4/3)\pi(r_\text{major outer} r_\text{minor outer}^2)$ 
     10and the averaging $< >$ is applied over all orientations for 1D. 
    1111 
    1212.. figure:: img/core_shell_ellipsoid_geometry.png 
    1313 
    14     The returned value is in units of $cm^{-1}$, on absolute scale. 
     14    The returned value is in units of |cm^-1|, on absolute scale. 
    1515 
    1616Definition 
     
    2121.. math:: 
    2222 
    23     P(q) = \frac{scale}{V}\int_0^1 
    24         \left|F(q,r_{minor\_core},r_{major\_core},\alpha) + F(q,r_{major\_outer},r_{major\_outer},\alpha)\right|^2d\alpha + background 
     23    P(q) &= \frac{\text{scale}}{V}\int_0^1 
     24        \left|F(q,r_\text{minor core},r_\text{major core},\alpha) 
     25        + F(q,r_\text{minor outer},r_\text{major outer},\alpha)\right|^2 
     26        d\alpha 
     27        + \text{background} 
    2528 
    26     \left|F(q,r_{minor},r_{major},\alpha)\right|=(4\pi/3)r_{major}r_{minor}^2 \Delta \rho \cdot (3j_1(u)/u) 
     29    \left|F(q,r_\text{minor},r_\text{major},\alpha)\right| 
     30        &=(4\pi/3)r_\text{major}r_\text{minor}^2 \Delta \rho \cdot (3j_1(u)/u) 
    2731 
    28     u = q\left[ r_{major}^2\alpha ^2 + r_{minor}^2(1-\alpha ^2)\right]^{1/2} 
     32    u &= q\left[ r_\text{major}^2\alpha ^2 
     33                  + r_\text{minor}^2(1-\alpha ^2)\right]^{1/2} 
    2934 
    3035where 
     
    4045The contrast is defined as SLD(core) - SLD(shell) and SLD(shell) - SLD(solvent). 
    4146 
    42 In the parameters, *equat_core* = equatorial core radius, *polar_core* = 
    43 polar core radius, *equat_shell* = $r_{min}$ (or equatorial outer radius), 
    44 and *polar_shell* = $r_{maj}$ (or polar outer radius). 
    45  
    46 Note:It is the users' responsibility to ensure that shell radii are larger than  
     47Note: It is the users' responsibility to ensure that shell radii are larger than 
    4748the core radii, especially if both are polydisperse, in which case the 
    4849core_shell_ellipsoid_xt model may be much better. 
     
    6768 
    6869S J Berr, *Phys. Chem.*, 91 (1987) 4760 
    69  
    7070""" 
    7171 
     
    100100 
    101101# pylint: disable=bad-whitespace, line-too-long 
    102 #             ["name", "units", default, [lower, upper], "type", "description"], 
     102#   ["name", "units", default, [lower, upper], "type", "description"], 
    103103parameters = [ 
    104     ["equat_core",  "Ang",      200,   [0, inf],    "volume",      "Equatorial radius of core, Rminor_core "], 
    105     ["polar_core",  "Ang",       10,   [0, inf],    "volume",      "Polar radius of core, Rmajor_core"], 
    106     ["equat_shell", "Ang",      250,   [0, inf],    "volume",      "Equatorial radius of shell, Rminor_outer "], 
    107     ["polar_shell", "Ang",       30,   [0, inf],    "volume",      "Polar radius of shell, Rmajor_outer"], 
    108     ["sld_core",    "1e-6/Ang^2", 2,   [-inf, inf], "sld",            "Core scattering length density"], 
    109     ["sld_shell",   "1e-6/Ang^2", 1,   [-inf, inf], "sld",            "Shell scattering length density"], 
    110     ["sld_solvent", "1e-6/Ang^2", 6.3, [-inf, inf], "sld",            "Solvent scattering length density"], 
     104    ["equat_core",  "Ang",      200,   [0, inf],    "volume",      "Equatorial radius of core, r minor core"], 
     105    ["polar_core",  "Ang",       10,   [0, inf],    "volume",      "Polar radius of core, r major core"], 
     106    ["equat_shell", "Ang",      250,   [0, inf],    "volume",      "Equatorial radius of shell, r minor outer"], 
     107    ["polar_shell", "Ang",       30,   [0, inf],    "volume",      "Polar radius of shell, r major outer"], 
     108    ["sld_core",    "1e-6/Ang^2", 2,   [-inf, inf], "sld",         "Core scattering length density"], 
     109    ["sld_shell",   "1e-6/Ang^2", 1,   [-inf, inf], "sld",         "Shell scattering length density"], 
     110    ["sld_solvent", "1e-6/Ang^2", 6.3, [-inf, inf], "sld",         "Solvent scattering length density"], 
    111111    ["theta",       "degrees",    0,   [-inf, inf], "orientation", "Oblate orientation wrt incoming beam"], 
    112112    ["phi",         "degrees",    0,   [-inf, inf], "orientation", "Oblate orientation in the plane of the detector"], 
     
    120120        Returns the effective radius used in the S*P calculation 
    121121    """ 
    122     import numpy as np 
    123122    from .ellipsoid import ER as ellipsoid_ER 
    124123    return ellipsoid_ER(polar_shell, equat_shell) 
  • sasmodels/models/core_shell_ellipsoid_xt.py

    r42356c8 r40a87fa  
    11r""" 
    22An alternative version of $P(q)$ for the core_shell_ellipsoid 
    3 having as parameters the core axial ratio X and a shell thickness,  
     3having as parameters the core axial ratio X and a shell thickness, 
    44which are more often what we would like to determine. 
    55 
  • sasmodels/models/core_shell_sphere.py

    r42356c8 r40a87fa  
    22.. _core_shell_sphere: 
    33 
    4 This model provides the form factor, $P(q)$, for a spherical particle with a core-shell structure. 
    5 The form factor is normalized by the particle volume. 
     4This model provides the form factor, $P(q)$, for a spherical particle with 
     5a core-shell structure. The form factor is normalized by the particle volume. 
    66 
    77Definition 
     
    1818.. math:: 
    1919 
    20     F^2(q)=\frac{3}{V_s}\left[V_c(\rho_c-\rho_s)\frac{\sin(qr_c)-qr_c\cos(qr_c)}{(qr_c)^3}+ 
    21     V_s(\rho_s-\rho_{solv})\frac{\sin(qr_s)-qr_s\cos(qr_s)}{(qr_s)^3}\right] 
     20    F^2(q) = \frac{3}{V_s}\left[ 
     21       V_c(\rho_c-\rho_s)\frac{\sin(qr_c)-qr_c\cos(qr_c)}{(qr_c)^3} + 
     22       V_s(\rho_s-\rho_\text{solv})\frac{\sin(qr_s)-qr_s\cos(qr_s)}{(qr_s)^3} 
     23       \right] 
    2224 
    23 where $V_s$ is the volume of the whole particle, $V_c$ is 
    24 the volume of the core, $r_s$ = $radius$ + $thickness$ is the radius of the particle, $r_c$ is the radius of the 
    25 core, $\rho_c$ is the scattering length density of the core, $\rho_s$ is the scattering length 
    26 density of the shell, $\rho_{solv}$ is the scattering length density of the solvent. 
     25where $V_s$ is the volume of the whole particle, $V_c$ is the volume of the 
     26core, $r_s$ = $radius$ + $thickness$ is the radius of the particle, $r_c$ 
     27is the radius of the core, $\rho_c$ is the scattering length density of the 
     28core, $\rho_s$ is the scattering length density of the shell, 
     29$\rho_\text{solv}$, is the scattering length density of the solvent. 
    2730 
    2831The 2D scattering intensity is the same as $P(q)$ above, regardless of the 
     
    3538---------- 
    3639 
    37 A Guinier and G Fournet, *Small-Angle Scattering of X-Rays*, John Wiley and Sons, New York, (1955) 
     40A Guinier and G Fournet, *Small-Angle Scattering of X-Rays*, 
     41John Wiley and Sons, New York, (1955) 
    3842 
    3943Validation 
    4044---------- 
    4145 
    42 Validation of our code was done by comparing the output of the 1D model to the output of 
    43 the software provided by NIST (Kline, 2006). Figure 1 shows a comparison of the output of 
    44 our model and the output of the NIST software. 
    45  
     46Validation of our code was done by comparing the output of the 1D model to 
     47the output of the software provided by NIST (Kline, 2006). Figure 1 shows a 
     48comparison of the output of our model and the output of the NIST software. 
    4649""" 
    4750 
     
    8891        @param thickness: shell thickness 
    8992    """ 
    90     return (1,1) 
     93    return (1, 1) 
    9194    whole = 4.0 * pi / 3.0 * pow((radius + thickness), 3) 
    9295    core = 4.0 * pi / 3.0 * radius * radius * radius 
    9396    return whole, whole - core 
    9497 
    95 tests = [[{'radius': 20.0, 'thickness': 10.0}, 'ER', 30.0], 
    96          # TODO: VR test suppressed until we sort out new product model 
    97          # and determine what to do with volume ratio. 
    98          #[{'radius': 20.0, 'thickness': 10.0}, 'VR', 0.703703704], 
     98tests = [ 
     99    [{'radius': 20.0, 'thickness': 10.0}, 'ER', 30.0], 
     100     # TODO: VR test suppressed until we sort out new product model 
     101     # and determine what to do with volume ratio. 
     102     #[{'radius': 20.0, 'thickness': 10.0}, 'VR', 0.703703704], 
    99103 
    100          # The SasView test result was 0.00169, with a background of 0.001 
    101          [{'radius': 60.0, 
    102            'thickness': 10.0, 
    103            'sld_core': 1.0, 
    104            'sld_shell':2.0, 
    105            'sld_solvent':3.0, 
    106            'background':0.0 
    107           }, 0.4, 0.000698838]] 
     104     # The SasView test result was 0.00169, with a background of 0.001 
     105     [{'radius': 60.0, 'thickness': 10.0, 'sld_core': 1.0, 'sld_shell':2.0, 
     106       'sld_solvent':3.0, 'background':0.0}, 
     107      0.4, 0.000698838], 
     108] 
  • sasmodels/models/correlation_length.py

    r2c74c11 r40a87fa  
    88 
    99.. math:: 
    10     I(Q) = \frac{A}{Q^n} + \frac{C}{1 + (Q\xi)^m} + B 
     10    I(Q) = \frac{A}{Q^n} + \frac{C}{1 + (Q\xi)^m} + \text{background} 
    1111 
    12 The first term describes Porod scattering from clusters (exponent = n) and the 
    13 second term is a Lorentzian function describing scattering from polymer chains 
    14 (exponent = m). This second term characterizes the polymer/solvent interactions 
    15 and therefore the thermodynamics. The two multiplicative factors A and C, the 
    16 incoherent background B and the two exponents n and m are used as fitting 
    17 parameters. (Respectively $porod\_scale$, $lorentz\_scale$, $background$, $exponent\_p$ and  
    18 $exponent\_l$ in the parameter list.) The remaining parameter \ |xi|\  is a correlation  
    19 length for the polymer chains. Note that when m=2 this functional form becomes the  
    20 familiar Lorentzian function. Some interpretation of the values of A and C may be  
    21 possible depending on the values of m and n. 
     12The first term describes Porod scattering from clusters (exponent = $n$) and 
     13the second term is a Lorentzian function describing scattering from 
     14polymer chains (exponent = $m$). This second term characterizes the 
     15polymer/solvent interactions and therefore the thermodynamics. The two 
     16multiplicative factors $A$ and $C$, and the two exponents $n$ and $m$ are 
     17used as fitting parameters. (Respectively *porod_scale*, *lorentz_scale*, 
     18*exponent_p* and *exponent_l* in the parameter list.) The remaining 
     19parameter $\xi$ (*cor_length* in the parameter list) is a correlation 
     20length for the polymer chains. Note that when $m=2$ this functional form 
     21becomes the familiar Lorentzian function. Some interpretation of the 
     22values of $A$ and $C$ may be possible depending on the values of $m$ and $n$. 
    2223 
    2324For 2D data: The 2D scattering intensity is calculated in the same way as 1D, 
    2425where the q vector is defined as 
    2526 
    26 .. math:: 
    27     q = \sqrt{q_x^2 + q_y^2} 
     27.. math::  q = \sqrt{q_x^2 + q_y^2} 
    2828 
    2929References 
  • sasmodels/models/cylinder.py

    r42356c8 r40a87fa  
    119119             ] 
    120120 
    121 source = ["lib/polevl.c","lib/sas_J1.c", "lib/gauss76.c", "cylinder.c"] 
     121source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "cylinder.c"] 
    122122 
    123123def ER(radius, length): 
  • sasmodels/models/elliptical_cylinder.c

    rabdd01c r40a87fa  
    1919 
    2020    arg = q*r_minor*sqrt((1.0+r_ratio*r_ratio)/2+(1.0-r_ratio*r_ratio)*cos(theta)/2); 
    21     if (arg == 0.0){ 
    22         retval = 1.0; 
    23     }else{ 
    24         //retval = 2.0*NR_BessJ1(arg)/arg; 
    25         retval = sas_J1c(arg); 
    26     } 
     21    //retval = 2.0*J1(arg)/arg; 
     22    retval = sas_J1c(arg); 
    2723    return retval*retval ; 
    2824} 
     
    6864        //now calculate the value of the inner integral 
    6965        answer = (vbj-vaj)/2.0*summj; 
    70         //divide integral by Pi 
    71         answer /= M_PI; 
    7266 
    7367        //now calculate outer integral 
    7468        arg = q*length*zi/2.0; 
    75         if (arg == 0.0){ 
    76             si = 1.0; 
    77         }else{ 
    78             si = sin(arg) * sin(arg) / arg / arg; 
    79         } 
     69        si = square(sinc(arg)); 
    8070        yyy = Gauss76Wt[i] * answer * si; 
    8171        summ += yyy; 
    8272    } 
    8373 
    84     answer = (vb-va)/2.0*summ; 
     74    //divide integral by Pi 
     75    answer = (vb-va)/2.0*summ/M_PI; 
    8576    // Multiply by contrast^2 
    8677    answer *= delrho*delrho; 
  • sasmodels/models/elliptical_cylinder.py

    r42356c8 r40a87fa  
    11# pylint: disable=line-too-long 
    22r""" 
    3 This function calculates the scattering from an elliptical cylinder. 
    4  
    53Definition for 2D (orientated system) 
    64------------------------------------- 
    75 
    8 The angles |theta| and |phi| define the orientation of the axis of the cylinder. The angle |bigpsi| is defined as the 
    9 orientation of the major axis of the ellipse with respect to the vector *Q*\ . A gaussian polydispersity can be added 
    10 to any of the orientation angles, and also for the minor radius and the ratio of the ellipse radii. 
     6The angles $\theta$ and $\phi$ define the orientation of the axis of the 
     7cylinder. The angle $\Psi$ is defined as the orientation of the major 
     8axis of the ellipse with respect to the vector $Q$. A gaussian polydispersity 
     9can be added to any of the orientation angles, and also for the minor 
     10radius and the ratio of the ellipse radii. 
    1111 
    1212.. figure:: img/elliptical_cylinder_geometry.png 
    1313 
    14    Elliptical cylinder geometry $a$ = $r_{minor}$ and \ |nu|\  = $axis\_ratio$ = $r_{major} / r_{minor}$ 
     14   Elliptical cylinder geometry $a = r_\text{minor}$ 
     15   and $\nu = r_\text{major} / r_\text{minor}$ is the *axis_ratio*. 
    1516 
    1617The function calculated is 
     
    1819.. math:: 
    1920 
    20     I(\mathbf{q})=\frac{1}{V_{cyl}}\int{d\psi}\int{d\phi}\int{p(\theta,\phi,\psi)F^2(\mathbf{q},\alpha,\psi)\sin(\theta)d\theta} 
     21    I(\vec q)=\frac{1}{V_\text{cyl}}\int{d\psi}\int{d\phi}\int{ 
     22        p(\theta,\phi,\psi)F^2(\vec q,\alpha,\psi)\sin(\theta)d\theta} 
    2123 
    2224with the functions 
     
    2426.. math:: 
    2527 
    26     F(\mathbf{q},\alpha,\psi)=2\frac{J_1(a)\sin(b)}{ab} 
    27     \\ 
    28     where  a = \mathbf{q}\sin(\alpha)\left[ r^2_{major}\sin^2(\psi)+r^2_{minor}\cos(\psi) \right]^{1/2} 
    29     \\ 
    30     b=\mathbf{q}\frac{L}{2}\cos(\alpha) 
     28    F(\vec q,\alpha,\psi) = 2\frac{J_1(a)\sin(b)}{ab} 
    3129 
    32 and the angle |bigpsi| is defined as the orientation of the major axis of the ellipse with respect to the vector $\vec q$ . 
    33 The angle $\alpha$ is the angle between the axis of the cylinder and $\vec q$. 
     30where 
     31 
     32.. math:: 
     33 
     34    a &= \vec q\sin(\alpha)\left[ 
     35        r^2_\text{major}\sin^2(\psi)+r^2_\text{minor}\cos(\psi) \right]^{1/2} 
     36 
     37    b &= \vec q\frac{L}{2}\cos(\alpha) 
     38 
     39and the angle $\Psi$ is defined as the orientation of the major axis of the 
     40ellipse with respect to the vector $\vec q$. The angle $\alpha$ is the angle 
     41between the axis of the cylinder and $\vec q$. 
    3442 
    3543 
     
    3745-------------------------------------------- 
    3846 
    39 The form factor is averaged over all possible orientation before normalized by the particle volume 
     47The form factor is averaged over all possible orientation before normalized 
     48by the particle volume 
    4049 
    4150.. math:: 
    42     P(q) = scale  <F^2> / V 
    4351 
    44 To provide easy access to the orientation of the elliptical cylinder, we define the axis of the cylinder using two 
    45 angles |theta|, |phi| and |bigpsi| (see :ref:`cylinder orientation <cylinder-angle-definition>`). 
    46 The angle |bigpsi| is the rotational angle around its own long_c axis against the *q* plane. 
    47 For example, |bigpsi| = 0 when the *r_minor* axis is parallel to the *x*\ -axis of the detector. 
     52    P(q) = \text{scale}  <F^2> / V 
    4853 
    49 All angle parameters are valid and given only for 2D calculation; ie, an oriented system. 
     54To provide easy access to the orientation of the elliptical cylinder, we 
     55define the axis of the cylinder using two angles $\theta$, $\phi$ and $\Psi$ 
     56(see :ref:`cylinder orientation <cylinder-angle-definition>`). The angle 
     57$\Psi$ is the rotational angle around its own long_c axis against the $q$ plane. 
     58For example, $\Psi = 0$ when the $r_\text{minor}$ axis is parallel to the 
     59$x$ axis of the detector. 
     60 
     61All angle parameters are valid and given only for 2D calculation; ie, an 
     62oriented system. 
    5063 
    5164.. figure:: img/elliptical_cylinder_angle_definition.jpg 
     
    5568.. figure:: img/cylinder_angle_projection.jpg 
    5669 
    57     Examples of the angles for oriented elliptical cylinders against the detector plane. 
     70    Examples of the angles for oriented elliptical cylinders against the 
     71    detector plane. 
    5872 
    59 NB: The 2nd virial coefficient of the cylinder is calculated based on the averaged radius (= sqrt(*r_minor*\ :sup:`2` \* *axis_ratio*)) 
    60 and length values, and used as the effective radius for *S(Q)* when *P(Q)* \* *S(Q)* is applied. 
     73NB: The 2nd virial coefficient of the cylinder is calculated based on the 
     74averaged radius $(=\sqrt{r_\text{minor}^2 * \text{axis ratio}})$ and length 
     75values, and used as the effective radius for $S(Q)$ when $P(Q)*S(Q)$ is applied. 
    6176 
    6277 
     
    6479---------- 
    6580 
    66 Validation of our code was done by comparing the output of the 1D calculation to the  
    67 angular average of the output of the 2D calculation over all possible angles.  
     81Validation of our code was done by comparing the output of the 1D calculation 
     82to the angular average of the output of the 2D calculation over all possible 
     83angles. 
    6884 
    69 In the 2D average, more binning in the angle |phi| is necessary to get the proper result.  
    70 The following figure shows the results of the averaging by varying the number of angular bins. 
     85In the 2D average, more binning in the angle $\phi$ is necessary to get the 
     86proper result. The following figure shows the results of the averaging by 
     87varying the number of angular bins. 
    7188 
    7289.. figure:: img/elliptical_cylinder_averaging.png 
     
    7794---------- 
    7895 
    79 L A Feigin and D I Svergun, *Structure Analysis by Small-Angle X-Ray and Neutron Scattering*, Plenum, 
    80 New York, (1987) 
     96L A Feigin and D I Svergun, *Structure Analysis by Small-Angle X-Ray and 
     97Neutron Scattering*, Plenum, New York, (1987) 
    8198""" 
    8299 
     
    104121# pylint: enable=bad-whitespace, line-too-long 
    105122 
    106 source = ["lib/polevl.c","lib/sas_J1.c", "lib/gauss76.c", "lib/gauss20.c", "elliptical_cylinder.c"] 
     123source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "lib/gauss20.c", 
     124          "elliptical_cylinder.c"] 
    107125 
    108126demo = dict(scale=1, background=0, r_minor=100, axis_ratio=1.5, length=400.0, 
    109             sld=4.0, sld_solvent=1.0, theta=10.0, phi=20, psi=30, theta_pd=10, phi_pd=2, psi_pd=3) 
     127            sld=4.0, sld_solvent=1.0, theta=10.0, phi=20, psi=30, 
     128            theta_pd=10, phi_pd=2, psi_pd=3) 
    110129 
    111130def ER(r_minor, axis_ratio, length): 
     
    117136    """ 
    118137    radius = sqrt(r_minor * r_minor * axis_ratio) 
    119     ddd = 0.75 * radius * (2 * radius * length + (length + radius) * (length + pi * radius)) 
     138    ddd = 0.75 * radius * (2 * radius * length 
     139                           + (length + radius) * (length + pi * radius)) 
    120140    return 0.5 * (ddd) ** (1. / 3.) 
    121141 
    122 tests = [[{'r_minor': 20.0, 'axis_ratio': 1.5, 'length':400.0}, 'ER', 79.89245454155024], 
    123          [{'r_minor': 20.0, 'axis_ratio': 1.2, 'length':300.0}, 'VR', 1], 
     142tests = [ 
     143    [{'r_minor': 20.0, 'axis_ratio': 1.5, 'length':400.0}, 'ER', 79.89245454155024], 
     144    [{'r_minor': 20.0, 'axis_ratio': 1.2, 'length':300.0}, 'VR', 1], 
    124145 
    125          # The SasView test result was 0.00169, with a background of 0.001 
    126          [{'r_minor': 20.0, 
    127            'axis_ratio': 1.5, 
    128            'sld': 4.0, 
    129            'length':400.0, 
    130            'sld_solvent':1.0, 
    131            'background':0.0 
    132           }, 0.001, 675.504402]] 
     146    # The SasView test result was 0.00169, with a background of 0.001 
     147    [{'r_minor': 20.0, 'axis_ratio': 1.5, 'sld': 4.0, 'length':400.0, 
     148      'sld_solvent':1.0, 'background':0.0}, 
     149     0.001, 675.504402], 
     150] 
  • sasmodels/models/flexible_cylinder_elliptical.py

    r42356c8 r40a87fa  
    109109# pylint: enable=bad-whitespace, line-too-long 
    110110 
    111 source = ["lib/polevl.c","lib/sas_J1.c", "lib/gauss76.c", "lib/wrc_cyl.c", "flexible_cylinder_elliptical.c"] 
     111source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "lib/wrc_cyl.c", 
     112          "flexible_cylinder_elliptical.c"] 
    112113 
    113114demo = dict(scale=1.0, background=0.0001, 
  • sasmodels/models/fuzzy_sphere.py

    r2c74c11 r40a87fa  
    11r""" 
    2 For information about polarised and magnetic scattering, see  
    3 the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 
     2For information about polarised and magnetic scattering, see 
     3the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` 
     4documentation. 
    45 
    56Definition 
    67---------- 
    78 
    8 The scattering intensity *I(q)* is calculated as: 
     9The scattering intensity $I(q)$ is calculated as: 
    910 
    1011.. math:: 
    11     I(q) = \frac{scale}{V}(\Delta \rho)^2 A^2(q) S(q) +\text{background} 
     12 
     13    I(q) = \frac{\text{scale}}{V}(\Delta \rho)^2 A^2(q) S(q) 
     14           + \text{background} 
    1215 
    1316 
    14 where the amplitude *A(q)* is given as the typical sphere scattering convoluted 
     17where the amplitude $A(q)$ is given as the typical sphere scattering convoluted 
    1518with a Gaussian to get a gradual drop-off in the scattering length density: 
    1619 
     
    1821 
    1922    A(q) = \frac{3\left[\sin(qR) - qR \cos(qR)\right]}{(qR)^3} 
    20            \exp\left(\frac{-(\sigma_{fuzzy}q)^2}{2}\right) 
     23           \exp\left(\frac{-(\sigma_\text{fuzzy}q)^2}{2}\right) 
    2124 
    22 Here *|A(q)|*:sup:`2`\  is the form factor, *P(q)*. The scale is equivalent to the 
    23 volume fraction of spheres, each of volume, *V*\. Contrast (|drho|) is the 
    24 difference of scattering length densities of the sphere and the surrounding 
    25 solvent. 
     25Here $A(q)^2$ is the form factor, $P(q)$. The scale is equivalent to the 
     26volume fraction of spheres, each of volume, $V$. Contrast $(\Delta \rho)$ 
     27is the difference of scattering length densities of the sphere and the 
     28surrounding solvent. 
    2629 
    27 Poly-dispersion in radius and in fuzziness is provided for, though the fuzziness 
    28 must be kept much smaller than the sphere radius for meaningful results. 
    29  
    30  
     30Poly-dispersion in radius and in fuzziness is provided for, though the 
     31fuzziness must be kept much smaller than the sphere radius for meaningful 
     32results. 
    3133 
    3234From the reference: 
    3335 
    3436  The "fuzziness" of the interface is defined by the parameter 
    35   |sigma| :sub:`fuzzy`\ . The particle radius *R* represents the radius of the 
     37  $\sigma_\text{fuzzy}$. The particle radius $R$ represents the radius of the 
    3638  particle where the scattering length density profile decreased to 1/2 of the 
    37   core density. The |sigma| :sub:`fuzzy`\ is the width of the smeared particle 
     39  core density. $\sigma_\text{fuzzy}$ is the width of the smeared particle 
    3840  surface; i.e., the standard deviation from the average height of the fuzzy 
    3941  interface. The inner regions of the microgel that display a higher density 
    4042  are described by the radial box profile extending to a radius of 
    41   approximately *Rbox* ~ *R* - 2\ |sigma|\ . The profile approaches zero as 
    42   *Rsans* ~ *R* + 2\ |sigma|\ . 
     43  approximately $R_\text{box} \sim R - 2 \sigma$. The profile approaches 
     44  zero as $R_\text{sans} \sim R + 2\sigma$. 
    4345 
    4446For 2D data: The 2D scattering intensity is calculated in the same way as 1D, 
    45 where the *q* vector is defined as 
     47where the $q$ vector is defined as 
    4648 
    47 .. math:: 
    48  
    49     q = \sqrt{{q_x}^2 + {q_y}^2} 
    50  
     49.. math:: q = \sqrt{{q_x}^2 + {q_y}^2} 
    5150 
    5251References 
  • sasmodels/models/gauss_lorentz_gel.py

    r2c74c11 r40a87fa  
    99---------- 
    1010 
    11 The scattering intensity I(q) is calculated as (Eqn. 5 from the reference) 
     11The scattering intensity $I(q)$ is calculated as (Eqn. 5 from the reference) 
    1212 
    13 .. math:: 
     13.. math:: I(q) = I_G(0) \exp(-q^2\Xi ^2/2) + I_L(0)/(1+q^2\xi^2) 
    1414 
    15     I(q) = I_G(0)exp(-q^2\Xi ^2/2) + I_L(0)/(1+q^2\xi^2) 
    16  
    17 $\Xi$ is the length scale of the static correlations in the gel, 
    18 which can be attributed to the "frozen-in" crosslinks. 
    19 \ |xi|\  is the dynamic correlation length, which can be attributed to the 
    20 fluctuating polymer chains between crosslinks. 
    21 $I_G(0)$ and $I_L(0)$ are the scaling factors for each of these structures. 
    22 Think carefully about how these map to your particular system! 
     15$\Xi$ is the length scale of the static correlations in the gel, which can 
     16be attributed to the "frozen-in" crosslinks. $\xi$ is the dynamic correlation 
     17length, which can be attributed to the fluctuating polymer chains between 
     18crosslinks. $I_G(0)$ and $I_L(0)$ are the scaling factors for each of these 
     19structures. Think carefully about how these map to your particular system! 
    2320 
    2421.. note:: 
    2522    The peaked structure at higher $q$ values (Figure 2 from the reference) 
    2623    is not reproduced by the model. Peaks can be introduced into the model 
    27     by summing this model with the PeakGaussModel function. 
     24    by summing this model with the :ref:`gaussian-peak` model. 
    2825 
    2926For 2D data the scattering intensity is calculated in the same way as 1D, 
    3027where the $q$ vector is defined as 
    3128 
    32 .. math:: 
    33  
    34     q = \sqrt{q_x^2 + q_y^2} 
    35  
     29.. math:: q = \sqrt{q_x^2 + q_y^2} 
    3630 
    3731References 
  • sasmodels/models/gel_fit.py

    rec45c4f r40a87fa  
    88and a longer distance (denoted here as $a2$ ) needed to account for the static 
    99accumulations of polymer pinned down by junction points or clusters of such 
    10 points. The latter is derived from a simple Guinier function. Compare also the  
     10points. The latter is derived from a simple Guinier function. Compare also the 
    1111gauss_lorentz_gel model. 
    1212 
  • sasmodels/models/guinier.py

    r2c74c11 r40a87fa  
    55This model fits the Guinier function 
    66 
    7 .. math:: I(q) = scale \exp{\left[ \frac{-Q^2R_g^2}{3} \right]} 
     7.. math:: 
    88 
    9 to the data directly without any need for linearisation 
    10 (*cf*. the usual plot of $\ln I(q)$ vs $q^2$\ ). Note that you may have to  
    11 restrict the data range to include small q only, where the Guinier approximation 
    12 actually applies. See also the guinier_porod model. 
     9    I(q) = \text{scale} \cdot \exp{\left[ \frac{-Q^2R_g^2}{3} \right]} 
     10            + \text{background} 
     11 
     12to the data directly without any need for linearisation (*cf*. the usual 
     13plot of $\ln I(q)$ vs $q^2$\ ). Note that you may have to restrict the data 
     14range to include small q only, where the Guinier approximation actually 
     15applies. See also the guinier_porod model. 
    1316 
    1417For 2D data the scattering intensity is calculated in the same way as 1D, 
    1518where the $q$ vector is defined as 
    1619 
    17 .. math:: q=\sqrt{q_x^2 + q_y^2} 
     20.. math:: q = \sqrt{q_x^2 + q_y^2} 
    1821 
    1922References 
  • sasmodels/models/guinier_porod.py

    r2c74c11 r40a87fa  
    1 # pylint: disable=line-too-long 
    21r""" 
    32Calculates the scattering for a generalized Guinier/power law object. 
     
    1312 
    1413.. math:: 
    15     I(q) = \frac{G}{Q^s} \ \exp{\left[ \frac{-Q^2R_g^2}{3-s} \right]} \textrm{ for } Q \leq Q_1 
    16     \\ 
    17     I(q) = D / Q^m \textrm{ for } Q \geq Q_1 
     14 
     15    I(q) = \begin{cases} 
     16    \frac{G}{Q^s}\ \exp{\left[\frac{-Q^2R_g^2}{3-s} \right]} & Q \leq Q_1 \\ 
     17    D / Q^m  & Q \geq Q_1 
     18    \end{cases} 
    1819 
    1920This is based on the generalized Guinier law for such elongated objects 
    20 (see the Glatter reference below). For 3D globular objects (such as spheres), $s = 0$ 
    21 and one recovers the standard Guinier formula. 
    22 For 2D symmetry (such as for rods) $s = 1$, 
    23 and for 1D symmetry (such as for lamellae or platelets) $s = 2$. 
    24 A dimensionality parameter ($3-s$) is thus defined, and is 3 for spherical objects, 
    25 2 for rods, and 1 for plates. 
     21(see the Glatter reference below). For 3D globular objects (such as spheres), 
     22$s = 0$ and one recovers the standard Guinier formula. For 2D symmetry 
     23(such as for rods) $s = 1$, and for 1D symmetry (such as for lamellae or 
     24platelets) $s = 2$. A dimensionality parameter ($3-s$) is thus defined, 
     25and is 3 for spherical objects, 2 for rods, and 1 for plates. 
    2626 
    27 Enforcing the continuity of the Guinier and Porod functions and their derivatives yields 
     27Enforcing the continuity of the Guinier and Porod functions and their 
     28derivatives yields 
    2829 
    2930.. math:: 
     31 
    3032    Q_1 = \frac{1}{R_g} \sqrt{(m-s)(3-s)/2} 
    3133 
     
    3335 
    3436.. math:: 
    35     D = G \ \exp{ \left[ \frac{-Q_1^2 R_g^2}{3-s} \right]} \ Q_1^{m-s} 
    36       = \frac{G}{R_g^{m-s}} \ \exp{\left[  -\frac{m-s}{2} \right]} \left( \frac{(m-s)(3-s)}{2} \right)^{\frac{m-s}{2}} 
     37 
     38    D &= G \ \exp{ \left[ \frac{-Q_1^2 R_g^2}{3-s} \right]} \ Q_1^{m-s} 
     39 
     40      &= \frac{G}{R_g^{m-s}} \ \exp \left[ -\frac{m-s}{2} \right] 
     41          \left( \frac{(m-s)(3-s)}{2} \right)^{\frac{m-s}{2}} 
    3742 
    3843 
    39 Note that the radius-of-gyration for a sphere of radius R is given by $R_g = R \sqrt(3/5)$. 
    40  
    41 For a cylinder of radius $R$ and length $L$,    $R_g^2 = \frac{L^2}{12} + \frac{R^2}{2}$ 
    42  
    43 from which the cross-sectional radius-of-gyration for a randomly oriented thin  
    44 cylinder is $R_g = R / \sqrt(2)$. 
    45  
    46 and the cross-sectional radius-of-gyration of a randomly oriented lamella 
    47 of thickness $T$ is given by $R_g = T / \sqrt(12)$. 
     44Note that the radius of gyration for a sphere of radius $R$ is given 
     45by $R_g = R \sqrt{3/5}$. For a cylinder of radius $R$ and length $L$, 
     46$R_g^2 = \frac{L^2}{12} + \frac{R^2}{2}$ from which the cross-sectional 
     47radius of gyration for a randomly oriented thin cylinder is $R_g = R/\sqrt{2}$ 
     48and the cross-sectional radius of gyration of a randomly oriented lamella 
     49of thickness $T$ is given by $R_g = T / \sqrt{12}$. 
    4850 
    4951For 2D data: The 2D scattering intensity is calculated in the same way as 1D, 
     
    5759--------- 
    5860 
    59 A Guinier, G Fournet, Small-Angle Scattering of X-Rays, John Wiley and Sons, New York, (1955) 
     61A Guinier, G Fournet, *Small-Angle Scattering of X-Rays*, 
     62John Wiley and Sons, New York, (1955) 
    6063 
    61 O Glatter, O Kratky, Small-Angle X-Ray Scattering, Academic Press (1982) 
     64O Glatter, O Kratky, *Small-Angle X-Ray Scattering*, Academic Press (1982) 
    6265Check out Chapter 4 on Data Treatment, pages 155-156. 
    6366""" 
  • sasmodels/models/hardsphere.py

    r7f1ee79 r40a87fa  
    33spherical particles interacting through hard sphere (excluded volume) 
    44interactions. 
    5 May be a reasonable approximation for other shapes of particles that  
    6 freely rotate, and for moderately polydisperse systems. Though strictly  
     5May be a reasonable approximation for other shapes of particles that 
     6freely rotate, and for moderately polydisperse systems. Though strictly 
    77the maths needs to be modified (no \Beta(Q) correction yet in sasview). 
    88 
     
    1313used in the form factor $P(q)$ that this $S(q)$ is combined with. 
    1414 
    15 For numerical stability the computation uses a Taylor series expansion  
     15For numerical stability the computation uses a Taylor series expansion 
    1616at very small $qR$, there may be a very minor glitch at the transition point 
    1717in some circumstances. 
     
    156156# VR defaults to 1.0 
    157157 
    158 demo = dict(radius_effective=200, volfraction=0.2, radius_effective_pd=0.1, radius_effective_pd_n=40) 
     158demo = dict(radius_effective=200, volfraction=0.2, 
     159            radius_effective_pd=0.1, radius_effective_pd_n=40) 
    159160# Q=0.001 is in the Taylor series, low Q part, so add Q=0.1, assuming double precision sasview is correct 
    160161tests = [ 
    161         [ {'scale': 1.0, 'background' : 0.0, 'radius_effective' : 50.0, 'volfraction' : 0.2, 
    162            'radius_effective_pd' : 0}, [0.001,0.1], [0.209128,0.930587]] 
     162        [ {'scale': 1.0, 'background' : 0.0, 'radius_effective' : 50.0, 
     163           'volfraction' : 0.2, 'radius_effective_pd' : 0}, 
     164          [0.001,0.1], [0.209128,0.930587]], 
    163165        ] 
    164 # ADDED by: RKH  ON: 16Mar2016  using equations from FISH as better than orig sasview, see notes above. Added Taylor expansions at small Q,  
     166# ADDED by: RKH  ON: 16Mar2016  using equations from FISH as better than orig sasview, see notes above. Added Taylor expansions at small Q, 
  • sasmodels/models/hayter_msa.py

    rd2bb604 r40a87fa  
    1616there is no provision for entering the ionic strength directly nor for use 
    1717of any multivalent salts, though it should be possible to simulate the effect 
    18 of this by increasing the salt concentration. The counterions are also assumed to  
    19 be monovalent. 
     18of this by increasing the salt concentration. The counterions are also 
     19assumed to be monovalent. 
    2020 
    2121In sasview the effective radius may be calculated from the parameters 
    2222used in the form factor $P(q)$ that this $S(q)$ is combined with. 
    2323 
    24 The computation uses a Taylor series expansion at very small rescaled $qR$, to  
    25 avoid some serious rounding error issues, this may result in a minor artefact  
     24The computation uses a Taylor series expansion at very small rescaled $qR$, to 
     25avoid some serious rounding error issues, this may result in a minor artefact 
    2626in the transition region under some circumstances. 
    2727 
     
    103103            radius_effective_pd_n=40) 
    104104# 
    105 # attempt to use same values as old sasview unit test at Q=.001 was 0.0712928,  
    106 # then add lots new ones assuming values from new model are OK, need some low Q values to test the small Q Taylor expansion 
     105# attempt to use same values as old sasview unit test at Q=.001 was 0.0712928, 
     106# then add lots new ones assuming values from new model are OK, need some 
     107# low Q values to test the small Q Taylor expansion 
    107108tests = [ 
    108109    [{'scale': 1.0, 
     
    115116      'dielectconst': 78.0, 
    116117      'radius_effective_pd': 0}, 
    117      [0.00001,0.0010,0.01,0.075], [0.0711646,0.0712928,0.0847006,1.07150]], 
     118     [0.00001, 0.0010, 0.01, 0.075], [0.0711646, 0.0712928, 0.0847006, 1.07150]], 
    118119    [{'scale': 1.0, 
    119120      'background': 0.0, 
     
    126127      'radius_effective_pd': 0.1, 
    127128      'radius_effective_pd_n': 40}, 
    128      [0.00001,0.0010,0.01,0.075], [0.450272,0.450420,0.465116,1.039625]] 
     129     [0.00001, 0.0010, 0.01, 0.075], [0.450272, 0.450420, 0.465116, 1.039625]] 
    129130    ] 
    130131# ADDED by:  RKH  ON: 16Mar2016 converted from sasview, new Taylor expansion at smallest rescaled Q 
  • sasmodels/models/hollow_rectangular_prism.py

    r42356c8 r40a87fa  
    115115             ] 
    116116 
    117 source = [ "lib/gauss76.c", "hollow_rectangular_prism.c"] 
     117source = ["lib/gauss76.c", "hollow_rectangular_prism.c"] 
    118118 
    119119def ER(a_side, b2a_ratio, c2a_ratio, thickness): 
    120120    """ 
    121         Return equivalent radius (ER) 
    122         thickness parameter not used 
     121    Return equivalent radius (ER) 
     122    thickness parameter not used 
    123123    """ 
    124124    b_side = a_side * b2a_ratio 
     
    133133def VR(a_side, b2a_ratio, c2a_ratio, thickness): 
    134134    """ 
    135         Return shell volume and total volume 
     135    Return shell volume and total volume 
    136136    """ 
    137137    b_side = a_side * b2a_ratio 
  • sasmodels/models/lamellar.py

    r42356c8 r40a87fa  
    55---------- 
    66 
    7 The scattering intensity $I(q)$ for dilute, randomly oriented, "infinitely large" sheets or lamellae is 
     7The scattering intensity $I(q)$ for dilute, randomly oriented, 
     8"infinitely large" sheets or lamellae is 
    89 
    910.. math:: 
     
    1920        = \frac{4\Delta\rho^2}{q^2}\sin^2\left(\frac{q\delta}{2}\right) 
    2021 
    21 where $\delta$ is the total layer thickness and $\Delta\rho$ is the scattering length density difference. 
     22where $\delta$ is the total layer thickness and $\Delta\rho$ is the 
     23scattering length density difference. 
    2224 
    23 This is the limiting form for a spherical shell of infinitely large radius. Note that the division by $\delta$ 
    24 means that $scale$ in sasview is the volume fraction of sheet, $\phi = S\delta$ where $S$ is the area of  
    25 sheet per unit volume. $S$ is half the Porod surface area per unit volume of a thicker layer (as that would  
    26 include both faces of the sheet). 
     25This is the limiting form for a spherical shell of infinitely large radius. 
     26Note that the division by $\delta$ means that $scale$ in sasview is the 
     27volume fraction of sheet, $\phi = S\delta$ where $S$ is the area of sheet 
     28per unit volume. $S$ is half the Porod surface area per unit volume of a 
     29thicker layer (as that would include both faces of the sheet). 
    2730 
    2831The 2D scattering intensity is calculated in the same way as 1D, where 
     
    6063category = "shape:lamellae" 
    6164 
    62 #             ["name", "units", default, [lower, upper], "type","description"], 
    63 parameters = [ ["thickness", "Ang", 50, [0, inf], "volume","total layer thickness" ], 
    64                ["sld", "1e-6/Ang^2", 1, [-inf, inf], "sld","Layer scattering length density" ], 
    65                ["sld_solvent", "1e-6/Ang^2", 6, [-inf, inf], "sld","Solvent scattering length density" ], 
    66              ] 
     65# pylint: disable=bad-whitespace, line-too-long 
     66#   ["name", "units", default, [lower, upper], "type","description"], 
     67parameters = [ 
     68    ["thickness",          "Ang", 50, [0, inf],    "volume", "total layer thickness" ], 
     69    ["sld",         "1e-6/Ang^2",  1, [-inf, inf], "sld",    "Layer scattering length density" ], 
     70    ["sld_solvent", "1e-6/Ang^2",  6, [-inf, inf], "sld",    "Solvent scattering length density" ], 
     71    ] 
     72# pylint: enable=bad-whitespace, line-too-long 
    6773 
    6874# No volume normalization despite having a volume parameter 
     
    9197            thickness_pd=0.2, thickness_pd_n=40) 
    9298tests = [ 
    93         [ {'scale': 1.0, 'background' : 0.0, 'thickness' : 50.0, 'sld' : 1.0,'sld_solvent' : 6.3, 'thickness_pd' : 0.0,  
    94            }, [0.001], [882289.54309]] 
     99        [ {'scale': 1.0, 'background': 0.0, 'thickness': 50.0, 
     100           'sld': 1.0, 'sld_solvent': 6.3, 'thickness_pd': 0.0}, 
     101          [0.001], [882289.54309]] 
    95102        ] 
    96103# ADDED by: converted by PAK? (or RKH?)     ON: 16Mar2016 - RKH adding unit tests from sasview to early 2015 conversion 
  • sasmodels/models/lamellar_hg.py

    r42356c8 r40a87fa  
    2929and $\Delta\rho_T$ is tail contrast (*sld* $-$ *sld_solvent*). 
    3030 
    31 The total thickness of the lamellar sheet is $\delta_H$ + $\delta_T$ + $\delta_T$ + $\delta_H$. 
    32 Note that in a non aqueous solvent the chemical "head" group may be the  
     31The total thickness of the lamellar sheet is $\delta_H + \delta_T + \delta_T + \delta_H$. 
     32Note that in a non aqueous solvent the chemical "head" group may be the 
    3333"Tail region" and vice-versa. 
    3434 
     
    3636the $q$ vector is defined as 
    3737 
    38 .. math:: 
    39  
    40     q = \sqrt{q_x^2 + q_y^2} 
    41  
     38.. math:: q = \sqrt{q_x^2 + q_y^2} 
    4239 
    4340References 
     
    111108 
    112109# 
    113 tests = [[{'scale': 1.0, 'background': 0.0, 'tail_length': 15.0, 'head_length': 10.0, 
    114            'sld': 0.4, 'sld_head': 3.0, 'sld_solvent': 6.0}, [0.001], [653143.9209]]] 
     110tests = [ 
     111    [{'scale': 1.0, 'background': 0.0, 'tail_length': 15.0, 'head_length': 10.0, 
     112      'sld': 0.4, 'sld_head': 3.0, 'sld_solvent': 6.0}, 
     113     [0.001], [653143.9209]], 
     114] 
    115115# ADDED by: RKH  ON: 18Mar2016  converted from sasview previously, now renaming everything & sorting the docs 
  • sasmodels/models/lamellar_stack_paracrystal.py

    r42356c8 r40a87fa  
    142142# 
    143143tests = [ 
    144         [ {'scale': 1.0, 'background' : 0.0, 'thickness' : 33.,'Nlayers' : 20.0, 'spacing' : 250., 'spacing_polydisp' : 0.2, 
    145             'sld' : 1.0, 'sld_solvent' : 6.34, 
    146             'thickness_pd' : 0.0, 'thickness_pd_n' : 40 }, [0.001, 0.215268], [21829.3, 0.00487686]] 
    147         ] 
     144    [{'scale': 1.0, 'background': 0.0, 'thickness': 33.,'Nlayers': 20.0, 
     145      'spacing': 250., 'spacing_polydisp': 0.2, 'sld': 1.0, 
     146      'sld_solvent': 6.34, 'thickness_pd': 0.0, 'thickness_pd_n': 40 }, 
     147     [0.001, 0.215268], [21829.3, 0.00487686]], 
     148] 
    148149# ADDED by: RKH  ON: 18Mar2016  converted from sasview previously, now renaming everything & sorting the docs 
  • sasmodels/models/linear_pearls.py

    rd2d6100 r40a87fa  
    6161    ] 
    6262# pylint: enable=bad-whitespace, line-too-long 
    63 single=False 
     63single = False 
    6464 
    6565source = ["linear_pearls.c"] 
  • sasmodels/models/mono_gauss_coil.py

    r2c74c11 r40a87fa  
    22#conversion of DebyeModel.py 
    33#converted by Steve King, Mar 2016 
     4r""" 
     5This Debye Gaussian coil model strictly describes the scattering from 
     6*monodisperse* polymer chains in theta solvents or polymer melts, conditions 
     7under which the distances between segments follow a Gaussian distribution. 
     8Provided the number of segments is large (ie, high molecular weight polymers) 
     9the single-chain form factor P(Q) is that described by Debye (1947). 
    410 
    5  
    6  
    7 r""" 
    8 This Debye Gaussian coil model strictly describes the scattering from *monodisperse* polymer chains in theta solvents or polymer melts, conditions under which the distances between segments follow a Gaussian distribution. Provided the number of segments is large (ie, high molecular weight polymers) the single-chain form factor P(Q) is that described by Debye (1947). 
    9  
    10 To describe the scattering from *polydisperse* polymer chains see the :ref:`poly_gauss_coil <poly-gauss-coil>` model. 
     11To describe the scattering from *polydisperse* polymer chains see the 
     12:ref:`poly-gauss-coil` model. 
    1113 
    1214Definition 
    1315---------- 
    1416 
    15      *I(q)* = *scale* |cdot| *I* \ :sub:`0` |cdot| *P(q)* + *background* 
     17.. math:: 
     18 
     19     I(q) = \text{scale} \cdot I_0 \cdot P(q) + \text{background} 
    1620 
    1721where 
    1822 
    19      *I*\ :sub:`0` = |phi|\ :sub:`poly` |cdot| *V* |cdot| (|rho|\ :sub:`poly` - |rho|\ :sub:`solv`)\  :sup:`2` 
     23.. math:: 
    2024 
    21      *P(q)* = 2 [exp(-Z) + Z - 1] / Z \ :sup:`2` 
     25     I_0 &= \phi_\text{poly} \cdot V 
     26            \cdot (\rho_\text{poly} - \rho_\text{solv})^2 
    2227 
    23      *Z* = (*q R* \ :sub:`g`)\ :sup:`2` 
     28     P(q) &= 2 [\exp(-Z) + Z - 1] / Z^2 
    2429 
    25 and 
     30     Z &= (q R_g)^2 
    2631 
    27      *V* = *M* / (*N*\ :sub:`A` |delta|) 
     32     V &= M / (N_A \delta) 
    2833 
    29 Here, |phi|\ :sub:`poly` is the volume fraction of polymer, *V* is the volume of a polymer coil, *M* is the molecular weight of the polymer, *N*\ :sub:`A` is Avogadro's Number, |delta| is the bulk density of the polymer, |rho|\ :sub:`poly` is the sld of the polymer, |rho|\ :sub:`solv` is the sld of the solvent, and *R*\ :sub:`g` is the radius of gyration of the polymer coil. 
     34Here, $\phi_\text{poly}$ is the volume fraction of polymer, $V$ is the 
     35volume of a polymer coil, *M* is the molecular weight of the polymer, 
     36$N_A$ is Avogadro's Number, $\delta$ is the bulk density of the polymer, 
     37$\rho_\text{poly}$ is the sld of the polymer, $\rho\text{solv}$ is the 
     38sld of the solvent, and $R_g$ is the radius of gyration of the polymer coil. 
    3039 
    31 The 2D scattering intensity is calculated in the same way as the 1D, but where the *q* vector is redefined as 
     40The 2D scattering intensity is calculated in the same way as the 1D, 
     41but where the *q* vector is redefined as 
    3242 
    3343.. math:: 
     
    4050P Debye, *J. Phys. Colloid. Chem.*, 51 (1947) 18. 
    4151 
    42 R J Roe, *Methods of X-Ray and Neutron Scattering in Polymer Science*, Oxford University Press, New York (2000). 
     52R J Roe, *Methods of X-Ray and Neutron Scattering in Polymer Science*, 
     53Oxford University Press, New York (2000). 
    4354 
    4455http://www.ncnr.nist.gov/staff/hammouda/distance_learning/chapter_28.pdf 
     
    4758from numpy import inf, exp, errstate 
    4859 
    49 name =  "mono_gauss_coil" 
    50 title =  "Scattering from monodisperse polymer coils" 
     60name = "mono_gauss_coil" 
     61title = "Scattering from monodisperse polymer coils" 
    5162 
    52 description =  """ 
     63description = """ 
    5364    Evaluates the scattering from  
    5465    monodisperse polymer chains. 
    5566    """ 
    56 category =  "shape-independent" 
     67category = "shape-independent" 
    5768 
    58 #             ["name", "units", default, [lower, upper], "type", "description"], 
    59 parameters =  [["i_zero", "1/cm", 70.0, [0.0, inf], "", "Intensity at q=0"], 
    60                ["radius_gyration", "Ang", 75.0, [0.0, inf], "", "Radius of gyration"]] 
     69# pylint: disable=bad-whitespace, line-too-long 
     70#   ["name", "units", default, [lower, upper], "type", "description"], 
     71parameters = [ 
     72    ["i_zero", "1/cm", 70.0, [0.0, inf], "", "Intensity at q=0"], 
     73    ["radius_gyration", "Ang", 75.0, [0.0, inf], "", "Radius of gyration"], 
     74    ] 
     75# pylint: enable=bad-whitespace, line-too-long 
    6176 
    6277# NB: Scale and Background are implicit parameters on every model 
     
    7186Iq.vectorized = True # Iq accepts an array of q values 
    7287 
    73 demo =  dict(scale = 1.0, 
    74             i_zero = 70.0, 
    75             radius_gyration = 75.0, 
    76             background = 0.0) 
     88demo = dict(scale=1.0, i_zero=70.0, radius_gyration=75.0, background=0.0) 
    7789 
    7890# these unit test values taken from SasView 3.1.2 
    79 tests =  [ 
     91tests = [ 
    8092    [{'scale': 1.0, 'i_zero': 70.0, 'radius_gyration': 75.0, 'background': 0.0}, 
    8193     [0.0106939, 0.469418], [57.1241, 0.112859]], 
  • sasmodels/models/multilayer_vesicle.py

    rf67f26c r40a87fa  
    1313    Geometry of the multilayer_vesicle model. 
    1414 
    15 See the core_shell_ function for more documentation. 
    16  
    17 .. _core_shell: core_shell_sphere.html 
     15See the :ref:`core-shell` model for more documentation. 
    1816 
    1917The 2D scattering intensity is the same as 1D, regardless of the orientation 
     
    2927    is used as the effective radius for *S(Q)* when $P(Q) * S(Q)$ is applied. 
    3028 
    31 For information about polarised and magnetic scattering, see  
     29For information about polarised and magnetic scattering, see 
    3230the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 
    3331 
  • sasmodels/models/onion.py

    r785cbec r40a87fa  
    300300# TODO: n is a volume parameter that is not polydisperse 
    301301 
    302 #             ["name", "units", default, [lower, upper], "type","description"], 
    303 parameters = [["sld_core", "1e-6/Ang^2", 1.0, [-inf, inf], "sld", 
    304                "Core scattering length density"], 
    305               ["radius_core", "Ang", 200., [0, inf], "volume", 
    306                "Radius of the core"], 
    307               ["sld_solvent", "1e-6/Ang^2", 6.4, [-inf, inf], "sld", 
    308                "Solvent scattering length density"], 
    309               ["n_shells", "", 1, [0, 10], "volume", 
    310                "number of shells"], 
    311               ["sld_in[n_shells]", "1e-6/Ang^2", 1.7, [-inf, inf], "sld", 
    312                "scattering length density at the inner radius of shell k"], 
    313               ["sld_out[n_shells]", "1e-6/Ang^2", 2.0, [-inf, inf], "sld", 
    314                "scattering length density at the outer radius of shell k"], 
    315               ["thickness[n_shells]", "Ang", 40., [0, inf], "volume", 
    316                "Thickness of shell k"], 
    317               ["A[n_shells]", "", 1.0, [-inf, inf], "", 
    318                "Decay rate of shell k"], 
    319               ] 
     302# pylint: disable=bad-whitespace, line-too-long 
     303#   ["name", "units", default, [lower, upper], "type","description"], 
     304parameters = [ 
     305    ["sld_core", "1e-6/Ang^2", 1.0, [-inf, inf], "sld", "Core scattering length density"], 
     306    ["radius_core", "Ang", 200., [0, inf], "volume", "Radius of the core"], 
     307    ["sld_solvent", "1e-6/Ang^2", 6.4, [-inf, inf], "sld", "Solvent scattering length density"], 
     308    ["n_shells", "", 1, [0, 10], "volume", "number of shells"], 
     309    ["sld_in[n_shells]", "1e-6/Ang^2", 1.7, [-inf, inf], "sld", "scattering length density at the inner radius of shell k"], 
     310    ["sld_out[n_shells]", "1e-6/Ang^2", 2.0, [-inf, inf], "sld", "scattering length density at the outer radius of shell k"], 
     311    ["thickness[n_shells]", "Ang", 40., [0, inf], "volume", "Thickness of shell k"], 
     312    ["A[n_shells]", "", 1.0, [-inf, inf], "", "Decay rate of shell k"], 
     313    ] 
     314# pylint: enable=bad-whitespace, line-too-long 
    320315 
    321316source = ["lib/sph_j1c.c", "onion.c"] 
     
    330325 
    331326    total_radius = 1.25*(sum(thickness[:n_shells]) + radius_core + 1) 
    332     dr = total_radius/400  # 400 points for a smooth plot 
    333  
    334     r = [] 
     327    dz = total_radius/400  # 400 points for a smooth plot 
     328 
     329    z = [] 
    335330    rho = [] 
    336331 
    337332    # add in the core 
    338     r.append(0) 
     333    z.append(0) 
    339334    rho.append(sld_core) 
    340     r.append(radius_core) 
     335    z.append(radius_core) 
    341336    rho.append(sld_core) 
    342337 
     
    344339    for k in range(n_shells): 
    345340        # Left side of each shells 
    346         r0 = r[-1] 
    347         r.append(r0) 
     341        z_current = z[-1] 
     342        z.append(z_current) 
    348343        rho.append(sld_in[k]) 
    349344 
    350345        if fabs(A[k]) < 1.0e-16: 
    351346            # flat shell 
    352             r.append(r0 + thickness[k]) 
     347            z.append(z_current + thickness[k]) 
    353348            rho.append(sld_out[k]) 
    354349        else: 
     
    356351            # num_steps must be at least 1, so use floor()+1 rather than ceil 
    357352            # to protect against a thickness0. 
    358             num_steps = np.floor(thickness[k]/dr) + 1 
     353            num_steps = np.floor(thickness[k]/dz) + 1 
    359354            slope = (sld_out[k] - sld_in[k]) / expm1(A[k]) 
    360355            const = (sld_in[k] - slope) 
    361             for rk in np.linspace(0, thickness[k], num_steps+1): 
    362                 r.append(r0+rk) 
    363                 rho.append(slope*exp(A[k]*rk/thickness[k]) + const) 
     356            for z_shell in np.linspace(0, thickness[k], num_steps+1): 
     357                z.append(z_current+z_shell) 
     358                rho.append(slope*exp(A[k]*z_shell/thickness[k]) + const) 
    364359 
    365360    # add in the solvent 
    366     r.append(r[-1]) 
     361    z.append(z[-1]) 
    367362    rho.append(sld_solvent) 
    368     r.append(total_radius) 
     363    z.append(total_radius) 
    369364    rho.append(sld_solvent) 
    370365 
    371     return np.asarray(r), np.asarray(rho) 
     366    return np.asarray(z), np.asarray(rho) 
    372367 
    373368def ER(core_radius, n, thickness): 
     369    """Effective radius""" 
    374370    return np.sum(thickness[:n[0]], axis=0) + core_radius 
    375  
    376 def VR(core_radius, n, thickness): 
    377     return 1.0, 1.0 
    378371 
    379372demo = { 
  • sasmodels/models/parallelepiped.py

    r42356c8 r40a87fa  
    77---------- 
    88 
    9 | This model calculates the scattering from a rectangular parallelepiped (:numref:`parallelepiped-image`). 
     9| This model calculates the scattering from a rectangular parallelepiped 
     10| (:numref:`parallelepiped-image`). 
    1011| If you need to apply polydispersity, see also :ref:`rectangular-prism`. 
    1112 
     
    3435.. math:: 
    3536 
    36     I(q) = \frac{\text{scale}}{V} (\Delta\rho \cdot V)^2 \left< P(q, \alpha) \right> 
    37     + \text{background} 
     37    I(q) = \frac{\text{scale}}{V} (\Delta\rho \cdot V)^2 
     38           \left< P(q, \alpha) \right> + \text{background} 
    3839 
    3940where the volume $V = A B C$, the contrast is defined as 
    40 :math:`\Delta\rho = \rho_{\textstyle p} - \rho_{\textstyle solvent}`, 
     41$\Delta\rho = \rho_\text{p} - \rho_\text{solvent}$, 
    4142$P(q, \alpha)$ is the form factor corresponding to a parallelepiped oriented 
    42 at an angle $\alpha$ (angle between the long axis C and :math:`\vec q`), 
     43at an angle $\alpha$ (angle between the long axis C and $\vec q$), 
    4344and the averaging $\left<\ldots\right>$ is applied over all orientations. 
    4445 
     
    5556.. math:: 
    5657 
    57     \phi_Q(\mu,a) = \int_0^1 
     58    \phi_Q(\mu,a) &= \int_0^1 
    5859        \left\{S\left[\frac{\mu}{2}\cos\left(\frac{\pi}{2}u\right)\right] 
    5960               S\left[\frac{\mu a}{2}\sin\left(\frac{\pi}{2}u\right)\right] 
    6061               \right\}^2 du 
    6162 
    62     S(x) = \frac{\sin x}{x} 
    63  
    64     \mu = qB 
     63    S(x) &= \frac{\sin x}{x} 
     64 
     65    \mu &= qB 
    6566 
    6667 
     
    105106.. figure:: img/parallelepiped_angle_projection.jpg 
    106107 
    107     Examples of the angles for oriented parallelepipeds against the detector plane. 
    108  
    109 For a given orientation of the parallelepiped, the 2D form factor is calculated as 
    110  
    111 .. math:: 
    112  
    113     P(q_x, q_y) = \left[\frac{sin(qA\cos\alpha/2)}{(qA\cos\alpha/2)}\right]^2 
    114                   \left[\frac{sin(qB\cos\beta/2)}{(qB\cos\beta/2)}\right]^2 
    115                   \left[\frac{sin(qC\cos\gamma/2)}{(qC\cos\gamma/2)}\right]^2 
     108    Examples of the angles for oriented parallelepipeds against the 
     109    detector plane. 
     110 
     111For a given orientation of the parallelepiped, the 2D form factor is 
     112calculated as 
     113 
     114.. math:: 
     115 
     116    P(q_x, q_y) = \left[\frac{\sin(qA\cos\alpha/2)}{(qA\cos\alpha/2)}\right]^2 
     117                  \left[\frac{\sin(qB\cos\beta/2)}{(qB\cos\beta/2)}\right]^2 
     118                  \left[\frac{\sin(qC\cos\gamma/2)}{(qC\cos\gamma/2)}\right]^2 
    116119 
    117120with 
     
    119122.. math:: 
    120123 
    121     \cos\alpha = \hat A \cdot \hat q, \; 
    122     \cos\beta  = \hat B \cdot \hat q, \; 
    123     \cos\gamma = \hat C \cdot \hat q 
     124    \cos\alpha &= \hat A \cdot \hat q, 
     125 
     126    \cos\beta  &= \hat B \cdot \hat q, 
     127 
     128    \cos\gamma &= \hat C \cdot \hat q 
    124129 
    125130and the scattering intensity as: 
     
    127132.. math:: 
    128133 
    129     I(q_x, q_y) = \frac{\text{scale}}{V} V^2 \Delta\rho^2 P(q_x, q_y) + \text{background} 
     134    I(q_x, q_y) = \frac{\text{scale}}{V} V^2 \Delta\rho^2 P(q_x, q_y) 
     135            + \text{background} 
    130136 
    131137.. Comment by Miguel Gonzalez: 
    132138   This reflects the logic of the code, as in parallelepiped.c the call 
    133    to _pkernel returns P(q_x, q_y) and then this is multiplied by V^2 * (delta rho)^2. 
    134    And finally outside parallelepiped.c it will be multiplied by scale, normalized by 
    135    V and the background added. But mathematically it makes more sense to write 
    136    I(q_x, q_y) = \text{scale} V \Delta\rho^2 P(q_x, q_y) + \text{background}, 
     139   to _pkernel returns $P(q_x, q_y)$ and then this is multiplied by 
     140   $V^2 * (\Delta \rho)^2$. And finally outside parallelepiped.c it will be 
     141   multiplied by scale, normalized by $V$ and the background added. But 
     142   mathematically it makes more sense to write 
     143   $I(q_x, q_y) = \text{scale} V \Delta\rho^2 P(q_x, q_y) + \text{background}$, 
    137144   with scale being the volume fraction. 
    138145 
     
    143150Validation of the code was done by comparing the output of the 1D calculation 
    144151to the angular average of the output of a 2D calculation over all possible 
    145 angles.  
     152angles. 
    146153 
    147154This model is based on form factor calculations implemented in a c-library 
  • sasmodels/models/poly_gauss_coil.py

    r2c74c11 r40a87fa  
    22#conversion of Poly_GaussCoil.py 
    33#converted by Steve King, Mar 2016 
     4r""" 
     5This empirical model describes the scattering from *polydisperse* polymer 
     6chains in theta solvents or polymer melts, assuming a Schulz-Zimm type 
     7molecular weight distribution. 
    48 
    5  
    6   
    7 r""" 
    8 This empirical model describes the scattering from *polydisperse* polymer chains in theta solvents or polymer melts, assuming a Schulz-Zimm type molecular weight distribution. 
    9  
    10 To describe the scattering from *monodisperse* polymer chains, see the :ref:`mono_gauss_coil <mono-gauss-coil>` model. 
     9To describe the scattering from *monodisperse* polymer chains, see the 
     10:ref:`mono-gauss-coil` model. 
    1111 
    1212Definition 
    1313---------- 
    1414 
    15      *I(q)* = *scale* |cdot| *I* \ :sub:`0` |cdot| *P(q)* + *background* 
     15.. math:: 
     16 
     17     I(q) = \text{scale} \cdot I_0 \cdot P(q) + \text{background} 
    1618 
    1719where 
    1820 
    19      *I*\ :sub:`0` = |phi|\ :sub:`poly` |cdot| *V* |cdot| (|rho|\ :sub:`poly` - |rho|\ :sub:`solv`)\ :sup:`2` 
     21.. math:: 
    2022 
    21      *P(q)* = 2 [(1 + UZ)\ :sup:`-1/U` + Z - 1] / [(1 + U) Z\ :sup:`2`] 
     23     I_0 &= \phi_\text{poly} \cdot V \cdot (\rho_\text{poly}-\rho_\text{solv})^2 
    2224 
    23      *Z* = [(*q R*\ :sub:`g`)\ :sup:`2`] / (1 + 2U) 
     25     P(q) &= 2 [(1 + UZ)^{-1/U} + Z - 1] / [(1 + U) Z^2] 
    2426 
    25      *U* = (Mw / Mn) - 1 = (*polydispersity ratio*) - 1 
     27     Z &= [(q R_g)^2] / (1 + 2U) 
    2628 
    27 and 
     29     U &= (Mw / Mn) - 1 = \text{polydispersity ratio} - 1 
    2830 
    29      *V* = *M* / (*N*\ :sub:`A` |delta|) 
     31     V &= M / (N_A \delta) 
    3032 
    31 Here, |phi|\ :sub:`poly`, is the volume fraction of polymer, *V* is the volume of a polymer coil, *M* is the molecular weight of the polymer, *N*\ :sub:`A` is Avogadro's Number, |delta| is the bulk density of the polymer, |rho|\ :sub:`poly` is the sld of the polymer, |rho|\ :sub:`solv` is the sld of the solvent, and *R*\ :sub:`g` is the radius of gyration of the polymer coil. 
     33Here, $\phi_\text{poly}$, is the volume fraction of polymer, $V$ is the 
     34volume of a polymer coil, $M$ is the molecular weight of the polymer, 
     35$N_A$ is Avogadro's Number, $\delta$ is the bulk density of the polymer, 
     36$\rho_\text{poly}$ is the sld of the polymer, $\rho_\text{solv}$ is the 
     37sld of the solvent, and $R_g$ is the radius of gyration of the polymer coil. 
    3238 
    33 The 2D scattering intensity is calculated in the same way as the 1D, but where the *q* vector is redefined as 
     39The 2D scattering intensity is calculated in the same way as the 1D, 
     40but where the $q$ vector is redefined as 
    3441 
    3542.. math:: 
     
    4047---------- 
    4148 
    42 O Glatter and O Kratky (editors), *Small Angle X-ray Scattering*, Academic Press, (1982) 
    43 Page 404. 
     49O Glatter and O Kratky (editors), *Small Angle X-ray Scattering*, 
     50Academic Press, (1982) Page 404. 
    4451 
    45 J S Higgins, H C Benoit, *Polymers and Neutron Scattering*, Oxford Science Publications, (1996). 
     52J S Higgins, H C Benoit, *Polymers and Neutron Scattering*, 
     53Oxford Science Publications, (1996). 
    4654 
    47 S M King, *Small Angle Neutron Scattering* in *Modern Techniques for Polymer Characterisation*, Wiley, (1999). 
     55S M King, *Small Angle Neutron Scattering* in *Modern Techniques for 
     56Polymer Characterisation*, Wiley, (1999). 
    4857 
    4958http://www.ncnr.nist.gov/staff/hammouda/distance_learning/chapter_28.pdf 
     
    5261from numpy import inf, exp, power 
    5362 
    54 name =  "poly_gauss_coil" 
    55 title =  "Scattering from polydisperse polymer coils" 
     63name = "poly_gauss_coil" 
     64title = "Scattering from polydisperse polymer coils" 
    5665 
    57 description =  """ 
     66description = """ 
    5867    Evaluates the scattering from  
    5968    polydisperse polymer chains. 
    6069    """ 
    61 category =  "shape-independent" 
     70category = "shape-independent" 
    6271 
    63 #             ["name", "units", default, [lower, upper], "type", "description"], 
    64 parameters =  [["i_zero", "1/cm", 70.0, [0.0, inf], "", "Intensity at q=0"], 
    65                ["radius_gyration", "Ang", 75.0, [0.0, inf], "", "Radius of gyration"], 
    66                ["polydispersity", "None", 2.0, [1.0, inf], "", "Polymer Mw/Mn"]] 
     72# pylint: disable=bad-whitespace, line-too-long 
     73#   ["name", "units", default, [lower, upper], "type", "description"], 
     74parameters = [ 
     75    ["i_zero",          "1/cm", 70.0, [0.0, inf], "", "Intensity at q=0"], 
     76    ["radius_gyration",  "Ang", 75.0, [0.0, inf], "", "Radius of gyration"], 
     77    ["polydispersity",  "None",  2.0, [1.0, inf], "", "Polymer Mw/Mn"], 
     78    ] 
     79# pylint: enable=bad-whitespace, line-too-long 
    6780 
    6881# NB: Scale and Background are implicit parameters on every model 
     
    7184    u = polydispersity - 1.0 
    7285    z = (q*radius_gyration)**2 / (1.0 + 2.0*u) 
    73     # need to trap the case of the polydispersity being 1 (ie, monodispersity!) 
     86    # need to trap the case of the polydispersity being 1 (ie, monodisperse!) 
    7487    if polydispersity == 1.0: 
    7588        inten = i_zero * 2.0 * (exp(-z) + z - 1.0) 
     
    8093    inten[index] /= z[index]**2 
    8194    return inten 
    82 Iq.vectorized =  True  # Iq accepts an array of q values 
     95Iq.vectorized = True  # Iq accepts an array of q values 
    8396 
    84 demo =  dict(scale = 1.0, 
    85             i_zero = 70.0, 
    86             radius_gyration = 75.0, 
    87             polydispersity = 2.0, 
    88             background = 0.0) 
     97demo = dict(scale=1.0, 
     98            i_zero=70.0, 
     99            radius_gyration=75.0, 
     100            polydispersity=2.0, 
     101            background=0.0) 
    89102 
    90103# these unit test values taken from SasView 3.1.2 
    91 tests =  [ 
    92     [{'scale': 1.0, 'i_zero': 70.0, 'radius_gyration': 75.0, 'polydispersity': 2.0, 'background': 0.0}, 
     104tests = [ 
     105    [{'scale': 1.0, 'i_zero': 70.0, 'radius_gyration': 75.0, 
     106      'polydispersity': 2.0, 'background': 0.0}, 
    93107     [0.0106939, 0.469418], [57.6405, 0.169016]], 
    94108    ] 
  • sasmodels/models/polymer_excl_volume.py

    r2c74c11 r40a87fa  
    106106 
    107107# pylint: disable=bad-whitespace, line-too-long 
    108 #             ["name", "units", default, [lower, upper], "type", "description"], 
    109 parameters = [["rg",        "Ang", 60.0, [0, inf],    "", "Radius of Gyration"], 
    110               ["porod_exp", "",     3.0, [-inf, inf], "", "Porod exponent"], 
    111              ] 
     108#   ["name", "units", default, [lower, upper], "type", "description"], 
     109parameters = [ 
     110    ["rg",        "Ang", 60.0, [0, inf],    "", "Radius of Gyration"], 
     111    ["porod_exp", "",     3.0, [-inf, inf], "", "Porod exponent"], 
     112] 
    112113# pylint: enable=bad-whitespace, line-too-long 
    113114 
     
    120121    :return:          Calculated intensity 
    121122    """ 
    122     u = (q*rg)**2 * (2.0/porod_exp + 1.0) * (2.0/porod_exp + 2.0)/6.0 
     123    usub = (q*rg)**2 * (2.0/porod_exp + 1.0) * (2.0/porod_exp + 2.0)/6.0 
    123124    with errstate(divide='ignore', invalid='ignore'): 
    124         upow = power(u, -0.5*porod_exp) 
    125         iq = (porod_exp*upow * 
    126               (gamma(0.5*porod_exp)*gammainc(0.5*porod_exp, u) - 
    127                upow*gamma(porod_exp)*gammainc(porod_exp, u))) 
    128     iq[q <= 0] = 1.0 
     125        upow = power(usub, -0.5*porod_exp) 
     126        result= (porod_exp*upow * 
     127                 (gamma(0.5*porod_exp)*gammainc(0.5*porod_exp, usub) - 
     128                  upow*gamma(porod_exp)*gammainc(porod_exp, usub))) 
     129    result[q <= 0] = 1.0 
    129130 
    130     return iq 
     131    return result 
    131132 
    132133Iq.vectorized = True  # Iq accepts an array of q values 
    133  
    134134 
    135135tests = [ 
  • sasmodels/models/polymer_micelle.py

    rd2d6100 r40a87fa  
    33This model provides the form factor, $P(q)$, for a micelle with a spherical 
    44core and Gaussian polymer chains attached to the surface, thus may be applied 
    5 to block copolymer micelles. To work well the Gaussian chains must be much smaller 
    6 than the core, which is often not the case.  Please study the reference carefully. 
     5to block copolymer micelles. To work well the Gaussian chains must be much 
     6smaller than the core, which is often not the case.  Please study the 
     7reference carefully. 
    78 
    89Definition 
     
    7172    [{}, 0.01, 15.3532], 
    7273    ] 
    73 # RKH 20Mar2016 - need to check whether the core & corona volumes are per monomer ??? and how aggregation number works! 
    74 # renamed from micelle_spherical_core to polymer_micelle, moved from shape-independent to spheres section. 
     74# RKH 20Mar2016 - need to check whether the core & corona volumes are per 
     75#                 monomer ??? and how aggregation number works! 
     76# renamed from micelle_spherical_core to polymer_micelle, 
     77# moved from shape-independent to spheres section. 
    7578# Ought to be able to add polydisp to core? And add ability to x by S(Q) ? 
  • sasmodels/models/porod.py

    r2c74c11 r40a87fa  
    22This model fits the Porod function 
    33 
    4 .. math:: 
    5  
    6     I(q) = C/q^4 
    7     \\ 
    8     C = 2\pi (\Delta\rho)^2 S_v 
     4.. math:: I(q) = C/q^4 
    95 
    106to the data directly without any need for linearisation (cf. Log I(q) vs Log q). 
    117 
    12 Here $C$ is the scale factor and $S_v$ is the specific surface area (ie, surface area / volume) 
    13 of the sample, and $\Delta\rho$ is the contrast factor. 
     8Here $C = 2\pi (\Delta\rho)^2 S_v$ is the scale factor where $S_v$ is 
     9the specific surface area (ie, surface area / volume) of the sample, and 
     10$\Delta\rho$ is the contrast factor. 
    1411 
    1512For 2D data: The 2D scattering intensity is calculated in the same way as 1D, 
    1613where the q vector is defined as 
    1714 
    18 .. math:: 
    19     q = \sqrt{q_x^2+q_y^2} 
     15.. math:: q = \sqrt{q_x^2+q_y^2} 
    2016 
    2117References 
     
    2319 
    2420G Porod. *Kolloid Zeit*. 124 (1951) 83. 
    25 L A Feigin, D I Svergun, G W Taylor. *Structure Analysis by Small-Angle X-ray and Neutron Scattering*. Springer. (1987) 
     21 
     22L A Feigin, D I Svergun, G W Taylor. *Structure Analysis by Small-Angle 
     23X-ray and Neutron Scattering*. Springer. (1987) 
    2624""" 
    2725 
  • sasmodels/models/power_law.py

    r2c74c11 r40a87fa  
    4646    # pylint: disable=missing-docstring 
    4747    with errstate(divide='ignore'): 
    48         iq = q**-power 
    49     return iq 
     48        result = q**-power 
     49    return result 
    5050Iq.vectorized = True  # Iq accepts an array of q values 
    5151 
    52 demo = dict(scale=1.0, 
    53             power=4.0, 
    54             background=0.0) 
     52demo = dict(scale=1.0, power=4.0, background=0.0) 
    5553 
    5654tests = [ 
  • sasmodels/models/pringle.py

    rc047acf r40a87fa  
    3131$d$ and $R$ are the "pringle" thickness and radius respectively, $\alpha$ and 
    3232$\beta$ are the two curvature parameters, and $J_n$ is the n\ :sup:`th` order 
    33 Bessel function of the first kind.  
     33Bessel function of the first kind. 
    3434 
    3535.. figure:: img/pringles_fig1.png 
     
    7979def ER(radius, thickness, alpha, beta): 
    8080    """ 
    81         Return equivalent radius (ER) 
     81    Return equivalent radius (ER) 
    8282    """ 
    8383    ddd = 0.75 * radius * (2 * radius * thickness + (thickness + radius) \ 
  • sasmodels/models/raspberry.py

    r42356c8 r40a87fa  
    2222.. math:: 
    2323 
    24     S(q) = \frac{sin(qR_1)}{qR_1}\frac{sin(qR_2)}{qR_2}\frac{sin(qr)}{qr} 
     24    S(q) = \frac{\sin(qR_1)}{qR_1}\frac{\sin(qR_2)}{qR_2}\frac{\sin(qr)}{qr} 
    2525 
    2626In this case, the large droplet and small particles are solid spheres rather 
     
    3131.. math:: 
    3232 
    33     \Psi_L = \int_0^{R_L}(4\pi R^2_L)\frac{sin(qR_L)}{qR_L}dR_L =  
    34     \frac{3[sin(qR_L)-qR_Lcos(qR_L)]}{(qR_L)^2} 
     33    \Psi_L = \int_0^{R_L}(4\pi R^2_L)\frac{\sin(qR_L)}{qR_L}dR_L = 
     34    \frac{3[\sin(qR_L)-qR_L\cos(qR_L)]}{(qR_L)^2} 
    3535 
    3636.. math:: 
    3737 
    38     \Psi_S = \int_0^{R_S}(4\pi R^2_S)\frac{sin(qR_S)}{qR_S}dR_S = 
    39     \frac{3[sin(qR_S)-qR_Lcos(qR_S)]}{(qR_S)^2} 
     38    \Psi_S = \int_0^{R_S}(4\pi R^2_S)\frac{\sin(qR_S)}{qR_S}dR_S = 
     39    \frac{3[\sin(qR_S)-qR_L\cos(qR_S)]}{(qR_S)^2} 
    4040 
    4141The cross term between the large droplet and small particles is given by: 
    4242 
    4343.. math:: 
    44     S_{LS} = \Psi_L\Psi_S\frac{sin(q(R_L+\delta R_S))}{q(R_L+\delta\ R_S)} 
     44    S_{LS} = \Psi_L\Psi_S\frac{\sin(q(R_L+\delta R_S))}{q(R_L+\delta\ R_S)} 
    4545 
    4646and the self term between small particles is given by: 
    4747 
    4848.. math:: 
    49     S_{SS} = \Psi_S^2\biggl[\frac{sin(q(R_L+\delta R_S))}{q(R_L+\delta\ R_S)} 
     49    S_{SS} = \Psi_S^2\biggl[\frac{\sin(q(R_L+\delta R_S))}{q(R_L+\delta\ R_S)} 
    5050    \biggr]^2 
    5151 
     
    5454.. math:: 
    5555 
    56     N_p = \frac{\phi_S\phi_{surface}V_L}{\phi_L V_S} 
     56    N_p = \frac{\phi_S\phi_\text{surface}V_L}{\phi_L V_S} 
    5757 
    5858where $\phi_S$ is the volume fraction of small particles in the sample, 
    59 $\phi_{surface}$ is the fraction of the small particles that are adsorbed to 
    60 the large droplets, $\phi_L$ is the volume fraction of large droplets in the 
     59$\phi_\text{surface}$ is the fraction of the small particles that are adsorbed 
     60to the large droplets, $\phi_L$ is the volume fraction of large droplets in the 
    6161sample, and $V_S$ and $V_L$ are the volumes of individual small particles and 
    6262large droplets respectively. 
     
    6464The form factor of the entire complex can now be calculated including the excess 
    6565scattering length densities of the components $\Delta\rho_L$ and $\Delta\rho_S$, 
    66 where $\Delta\rho_x = |\rho_x-\rho_{solvent}|$ : 
     66where $\Delta\rho_x = \left|\rho_x-\rho_\text{solvent}\right|$ : 
    6767 
    6868.. math:: 
     
    8383 
    8484.. math:: 
    85     I(Q) = I_{LS}(Q) + I_S(Q) = (\phi_L(\Delta\rho_L)^2V_L +  
    86             \phi_S\phi_{surface}N_p(\Delta\rho_S)^2V_S)P_{LS} 
    87             + \phi_S(1-\phi_{surface})(\Delta\rho_S)^2V_S\Psi_S^2 
     85    I(Q) = I_{LS}(Q) + I_S(Q) = (\phi_L(\Delta\rho_L)^2V_L + 
     86            \phi_S\phi_\text{surface}N_p(\Delta\rho_S)^2V_S)P_{LS} 
     87            + \phi_S(1-\phi_\text{surface})(\Delta\rho_S)^2V_S\Psi_S^2 
    8888 
    8989A useful parameter to extract is the fraction of the surface area of the large 
     
    9292 
    9393.. math:: 
    94     \chi = \frac{4\phi_L\phi_{surface}(R_L+\delta R_S)}{\phi_LR_S} 
     94    \chi = \frac{4\phi_L\phi_\text{surface}(R_L+\delta R_S)}{\phi_LR_S} 
    9595 
    9696 
     
    109109""" 
    110110 
    111 from numpy import pi, inf 
     111from numpy import inf 
    112112 
    113113name = "raspberry" 
  • sasmodels/models/rpa.py

    r51ec7e8 r40a87fa  
    111111HIDE_AB = set("N2 Phi2 v2 L2 b2 K23 K24".split()).union(HIDE_A) 
    112112def hidden(case_num): 
     113    """ 
     114    Return a list of parameters to hide depending on the multiplicity parameter. 
     115    """ 
    113116    if case_num < 2: 
    114117        return HIDE_AB 
  • sasmodels/models/sphere.py

    r2c74c11 r40a87fa  
    11r""" 
    2 For information about polarised and magnetic scattering, see  
    3 the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 
     2For information about polarised and magnetic scattering, see 
     3the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` 
     4documentation. 
    45 
    56Definition 
  • sasmodels/models/squarewell.py

    r56b2687 r40a87fa  
    11# Note: model title and parameter table are inserted automatically 
    22r""" 
    3 This calculates the interparticle structure factor for a square well fluid spherical particles. The mean spherical 
    4 approximation (MSA) closure was used for this calculation, and is not the most appropriate closure for an attractive 
    5 interparticle potential. This solution has been compared to Monte Carlo simulations for a square well fluid, showing 
    6 this calculation to be limited in applicability to well depths |epsilon| < 1.5 kT and volume fractions |phi| < 0.08. 
     3This calculates the interparticle structure factor for a square well fluid 
     4spherical particles. The mean spherical approximation (MSA) closure was 
     5used for this calculation, and is not the most appropriate closure for 
     6an attractive interparticle potential. This solution has been compared 
     7to Monte Carlo simulations for a square well fluid, showing this calculation 
     8to be limited in applicability to well depths $\epsilon < 1.5$ kT and 
     9volume fractions $\phi < 0.08$. 
    710 
    8 Positive well depths correspond to an attractive potential well. Negative well depths correspond to a potential 
    9 "shoulder", which may or may not be physically reasonable. The stickyhardsphere model may be a better choice in 
     11Positive well depths correspond to an attractive potential well. Negative 
     12well depths correspond to a potential "shoulder", which may or may not be 
     13physically reasonable. The stickyhardsphere model may be a better choice in 
    1014some circumstances. Computed values may behave badly at extremely small $qR$. 
    1115 
    12 The well width (|lambda| ) is defined as multiples of the particle diameter (2\*\ *R*\ ) 
     16The well width $(\lambda)$ is defined as multiples of the particle diameter 
     17$(2 R)$. 
    1318 
    1419The interaction potential is: 
     
    2934used in the form factor $P(q)$ that this $S(q)$ is combined with. 
    3035 
    31 For 2D data: The 2D scattering intensity is calculated in the same way as 1D, where the *q* vector is defined as 
     36For 2D data: The 2D scattering intensity is calculated in the same way as 1D, 
     37where the $q$ vector is defined as 
    3238 
    3339.. math:: 
     
    130136# 
    131137tests = [ 
    132         [ {'scale': 1.0, 'background' : 0.0, 'radius_effective' : 50.0, 'volfraction' : 0.04,'welldepth' : 1.5, 'wellwidth' : 1.2,  
    133            'radius_effective_pd' : 0}, [0.001], [0.97665742]] 
    134         ] 
     138    [{'scale': 1.0, 'background' : 0.0, 'radius_effective' : 50.0, 
     139      'volfraction' : 0.04,'welldepth' : 1.5, 'wellwidth' : 1.2, 
     140      'radius_effective_pd' : 0}, 
     141     [0.001], [0.97665742]], 
     142    ] 
    135143# ADDED by: converting from sasview RKH  ON: 16Mar2016 
    136144 
  • sasmodels/models/stacked_disks.py

    r42356c8 r40a87fa  
    1414of the q vector which is defined as 
    1515 
    16 .. math:: 
    17  
    18     q = \sqrt{q_x^2 + q_y^2} 
     16.. math:: q = \sqrt{q_x^2 + q_y^2} 
    1917 
    2018Definition 
     
    2826 
    2927    I(q) = N\int_{0}^{\pi /2}\left[ \Delta \rho_t 
    30     \left( V_tf_t(q) - V_cf_c(q)\right) + \Delta \rho_cV_cf_c(q) 
    31     \right]^2S(q)\sin{\alpha d\alpha} + background 
     28    \left( V_t f_t(q) - V_c f_c(q)\right) + \Delta \rho_c V_c f_c(q) 
     29    \right]^2 S(q)\sin{\alpha}\ d\alpha + \text{background} 
    3230 
    3331where the contrast 
     
    3533.. math:: 
    3634 
    37     \Delta \rho_i = \rho_i - \rho_{solvent} 
    38  
    39 and *N* is the number of discs per unit volume, 
    40 $\alpha$ is the angle between the axis of the disc and *q*, 
     35    \Delta \rho_i = \rho_i - \rho_\text{solvent} 
     36 
     37and $N$ is the number of discs per unit volume, 
     38$\alpha$ is the angle between the axis of the disc and $q$, 
    4139and $V_t$ and $V_c$ are the total volume and the core volume of 
    4240a single disc, respectively. 
     
    4644    \left\langle f_{t}^2(q)\right\rangle_{\alpha} = 
    4745    \int_{0}^{\pi/2}\left[ 
    48     \left(\frac{sin(q(d+h)\cos{\alpha})}{q(d+h)\cos{\alpha}}\right) 
     46    \left(\frac{\sin(q(d+h)\cos{\alpha})}{q(d+h)\cos{\alpha}}\right) 
    4947    \left(\frac{2J_1(qR\sin{\alpha})}{qR\sin{\alpha}} \right) 
    50     \right]^2 \sin{\alpha d\alpha} 
     48    \right]^2 \sin{\alpha}\ d\alpha 
    5149 
    5250    \left\langle f_{c}^2(q)\right\rangle_{\alpha} = 
    5351    \int_{0}^{\pi/2}\left[ 
    54     \left(\frac{sin(qh)\cos{\alpha})}{qh\cos{\alpha}}\right) 
    55     \left(\frac{2J_1(qR\sin{\alpha})}{qR\sin{\alpha}} \right) 
    56     \right]^2 \sin{\alpha d\alpha} 
    57  
    58 where *d* = thickness of the layer (layer_thick), 
    59 *2h* = core thickness (core_thick), and *R* = radius of the disc (radius). 
     52    \left(\frac{\sin(qh)\cos{\alpha})}{qh\cos{\alpha}}\right) 
     53    \left(\frac{2J_1(qR\sin{\alpha})}{qR\sin{\alpha}}\right) 
     54    \right]^2 \sin{\alpha}\ d\alpha 
     55 
     56where $d$ = thickness of the layer (*layer_thick*), 
     57$2h$ = core thickness (*core_thick*), and $R$ = radius of the disc (*radius*). 
    6058 
    6159.. math:: 
    6260 
    6361    S(q) = 1 + \frac{1}{2}\sum_{k=1}^n(n-k)\cos{(kDq\cos{\alpha})} 
    64     exp\left[ -k(q\cos{\alpha})^2\sigma_D/2\right] 
    65  
    66 where *n* = the total number of the disc stacked (n_stacking), 
    67 *D* = 2*(*d*+*h*)the next neighbor center-to-center distance (d-spacing), 
    68 and $\sigma_D$ = the Gaussian standard deviation of the d-spacing (sigma_d). 
     62    \exp\left[ -k(q\cos{\alpha})^2\sigma_D/2\right] 
     63 
     64where $n$ is the total number of the disc stacked (*n_stacking*), 
     65$D = 2(d+h)$ is the next neighbor center-to-center distance (d-spacing), 
     66and $\sigma_D$ = the Gaussian standard deviation of the d-spacing (*sigma_d*). 
    6967 
    7068.. note:: 
    71     Each assmebly in the stack is layer/core/layer, so the spacing of the cores 
    72     is core plus two layers. The 2nd virial coefficient of the cylinder is  
    73     calculated based on the  
    74     *radius* and *length* = *n_stacking* * (*core_thick* + 2 * *layer_thick*) 
     69    Each assmebly in the stack is layer/core/layer, so the spacing of the 
     70    cores is core plus two layers. The 2nd virial coefficient of the cylinder 
     71    is calculated based on the *radius* and *length* 
     72    = *n_stacking* * (*core_thick* + 2 * *layer_thick*) 
    7573    values, and used as the effective radius for $S(Q)$ when $P(Q) * S(Q)$ 
    7674    is applied. 
     
    9492---------- 
    9593 
    96 A Guinier and G Fournet, *Small-Angle Scattering of X-Rays*, John Wiley and Sons, New York, 1955 
     94A Guinier and G Fournet, *Small-Angle Scattering of X-Rays*, 
     95John Wiley and Sons, New York, 1955 
    9796 
    9897O Kratky and G Porod, *J. Colloid Science*, 4, (1949) 35 
    9998 
    100 J S Higgins and H C Benoit, *Polymers and Neutron Scattering*, Clarendon, Oxford, 1994 
     99J S Higgins and H C Benoit, *Polymers and Neutron Scattering*, 
     100Clarendon, Oxford, 1994 
    101101 
    102102**Author:** NIST IGOR/DANSE **on:** pre 2010 
  • sasmodels/models/star_polymer.py

    rec45c4f r40a87fa  
    11r""" 
    2 The Benoit model for a simple star polymer, with Gaussian coils arms from  
     2The Benoit model for a simple star polymer, with Gaussian coils arms from 
    33a common point. 
    44 
     
    1010.. math:: 
    1111 
    12     I(q) = \frac{2}{fv^2}\left[ v-1+exp(-v)+\frac{f-1}{2} 
    13            \left[ 1-exp(-v)\right]^2\right] 
     12    I(q) = \frac{2}{fv^2}\left[ v-1+\exp(-v)+\frac{f-1}{2} 
     13           \left[ 1-\exp(-v)\right]^2\right] 
    1414 
    1515where 
    1616 
    17 .. math:: 
    18  
    19     v=\frac{u^2f}{(3f-2)} 
     17.. math:: v=\frac{u^2f}{(3f-2)} 
    2018 
    2119and 
    2220 
    23 .. math:: 
     21.. math:: u = \left\langle R_{g}^2\right\rangle q^2 
    2422 
    25     u = \left\langle R_{g}^2\right\rangle q^2 
    26  
    27 contains the square of the ensemble average radius-of-gyration of an arm.  Note that  
    28 when there is only one arm, $f$ = 1, the Debye Gaussian coil equation is recovered. 
    29 Star polymers in solutions tend to have strong interparticle and osmotic effects, so  
    30 the Benoit equation may not work well. At small q the Guinier term and hence I(q=0) 
    31 is the same as for $f$ arms of radius of gyration $R_g$, as described for the :ref:`mono_gauss_coil <mono-gauss-coil>`. 
    32  
     23contains the square of the ensemble average radius-of-gyration of an arm. 
     24Note that when there is only one arm, $f = 1$, the Debye Gaussian coil 
     25equation is recovered. Star polymers in solutions tend to have strong 
     26interparticle and osmotic effects, so the Benoit equation may not work well. 
     27At small $q$ the Guinier term and hence $I(q=0)$ is the same as for $f$ arms 
     28of radius of gyration $R_g$, as described for the :ref:`mono-gauss-coil` model. 
    3329 
    3430References 
     
    3632 
    3733H Benoit *J. Polymer Science*, 11, 596-599 (1953) 
    38  
    39  
    4034""" 
    4135 
  • sasmodels/models/stickyhardsphere.py

    rd2bb604 r40a87fa  
    178178# 
    179179tests = [ 
    180         [ {'scale': 1.0, 'background' : 0.0, 'radius_effective' : 50.0, 'perturb' : 0.05, 'stickiness' : 0.2, 'volfraction' : 0.1, 
    181            'radius_effective_pd' : 0}, [0.001, 0.003], [1.09718, 1.087830]] 
    182         ] 
    183  
    184  
     180    [{'scale': 1.0, 'background': 0.0, 'radius_effective': 50.0, 
     181      'perturb': 0.05, 'stickiness': 0.2, 'volfraction': 0.1, 
     182      'radius_effective_pd': 0}, 
     183     [0.001, 0.003], [1.09718, 1.087830]], 
     184    ] 
  • sasmodels/models/teubner_strey.py

    r2c74c11 r40a87fa  
    4747 
    4848import numpy as np 
    49 from numpy import inf, sqrt 
     49from numpy import inf 
    5050 
    5151name = "teubner_strey" 
     
    5858category = "shape-independent" 
    5959 
    60 #             ["name", "units", default, [lower, upper], "type","description"], 
    61 parameters = [["a2", "", 0.1, [0, inf], "", 
    62                "a2"], 
    63               ["c1", "1e-6/Ang^2", -30., [-inf, 0], "", 
    64                "c1"], 
    65               ["c2", "Ang", 5000., [0, inf], "volume", 
    66                "c2"], 
    67              ] 
    68  
     60#   ["name", "units", default, [lower, upper], "type","description"], 
     61parameters = [ 
     62    ["a2", "", 0.1, [0, inf], "", "a2"], 
     63    ["c1", "1e-6/Ang^2", -30., [-inf, 0], "", "c1"], 
     64    ["c2", "Ang", 5000., [0, inf], "volume", "c2"], 
     65    ] 
    6966 
    7067def Iq(q, a2, c1, c2): 
     68    """SAS form""" 
    7169    return 1. / np.polyval([c2, c1, a2], q**2) 
    7270Iq.vectorized = True  # Iq accepts an array of q values 
  • sasmodels/models/two_power_law.py

    r2c74c11 r40a87fa  
    1414where $q_c$ = the location of the crossover from one slope to the other, 
    1515$A$ = the scaling coefficent that sets the overall intensity of the lower Q 
    16 power law region, $m1$ = power law exponent at low Q, and $m2$ = power law  
     16power law region, $m1$ = power law exponent at low Q, and $m2$ = power law 
    1717exponent at high Q.  The scaling of the second power law region (coefficent C) 
    1818is then automatically scaled to match the first by following formula: 
     
    6262category = "shape-independent" 
    6363 
    64 #            ["name", "units", default, [lower, upper], "type", "description"], 
    65 parameters = [["coefficent_1",  "",         1.0, [-inf, inf], "", 
    66                "coefficent A in low Q region"], 
    67               ["crossover",     "1/Ang",    0.04,[0, inf],    "", 
    68                "crossover location"], 
    69               ["power_1",       "",         1.0, [0, inf],    "", 
    70                "power law exponent at low Q"], 
    71               ["power_2",       "",         4.0, [0, inf],    "", 
    72                "power law exponent at high Q"], 
    73              ] 
     64# pylint: disable=bad-whitespace, line-too-long 
     65#   ["name", "units", default, [lower, upper], "type", "description"], 
     66parameters = [ 
     67    ["coefficent_1", "",       1.0, [-inf, inf], "", "coefficent A in low Q region"], 
     68    ["crossover",    "1/Ang",  0.04,[0, inf],    "", "crossover location"], 
     69    ["power_1",      "",       1.0, [0, inf],    "", "power law exponent at low Q"], 
     70    ["power_2",      "",       4.0, [0, inf],    "", "power law exponent at high Q"], 
     71    ] 
     72# pylint: enable=bad-whitespace, line-too-long 
    7473 
    7574 
     
    8988    :return:                    Calculated intensity 
    9089    """ 
    91     iq = empty(q.shape, 'd') 
    92     idx = (q <= crossover) 
     90    result= empty(q.shape, 'd') 
     91    index = (q <= crossover) 
    9392    with errstate(divide='ignore'): 
    9493        coefficent_2 = coefficent_1 * power(crossover, power_2 - power_1) 
    95         iq[idx] = coefficent_1 * power(q[idx], -power_1) 
    96         iq[~idx] = coefficent_2 * power(q[~idx], -power_2) 
    97     return iq 
     94        result[index] = coefficent_1 * power(q[index], -power_1) 
     95        result[~index] = coefficent_2 * power(q[~index], -power_2) 
     96    return result 
    9897 
    9998Iq.vectorized = True  # Iq accepts an array of q values 
  • sasmodels/models/unified_power_Rg.py

    r785cbec r40a87fa  
    3737$q_i^*$ which is ignored here. 
    3838 
    39 For example, to approximate the scattering from random coils (Debye_ equation), 
     39For example, to approximate the scattering from random coils (Debye equation), 
    4040set $R_{gi}$ as the Guinier radius, $P_i = 2$, and $B_i = 2 G_i / R_{gi}$ 
    4141 
     
    6565from scipy.special import erf 
    6666 
     67category = "shape-independent" 
     68 
     69# pylint: disable=bad-whitespace, line-too-long 
    6770parameters = [ 
    6871    ["level",     "",     1,      [0, 6], "", "Level number"], 
     
    7275    ["G[level]",  "1/cm", 400,    [0, inf], "", ""], 
    7376    ] 
    74 category = "shape-independent" 
     77# pylint: enable=bad-whitespace, line-too-long 
    7578 
    7679def Iq(q, level, rg, power, B, G): 
     
    8790            exp_next = exp(-(q*rg[i+1])**2/3.) if i < ilevel-1 else 1. 
    8891            result += G[i]*exp_now + B[i]*exp_next*pow_now 
    89     result[q==0] = np.sum(G[:ilevel]) 
     92    result[q == 0] = np.sum(G[:ilevel]) 
    9093    return result 
    9194 
  • sasmodels/resolution.py

    r7ae2b7f r40a87fa  
    154154    edges = bin_edges(q_calc) 
    155155    edges[edges < 0.0] = 0.0 # clip edges below zero 
    156     G = erf((edges[:, None] - q[None, :]) / (sqrt(2.0)*q_width)[None, :]) 
    157     weights = G[1:] - G[:-1] 
     156    cdf = erf((edges[:, None] - q[None, :]) / (sqrt(2.0)*q_width)[None, :]) 
     157    weights = cdf[1:] - cdf[:-1] 
    158158    weights /= np.sum(weights, axis=0)[None, :] 
    159159    return weights 
     
    307307            weights[i, :] = (in_x + abs_x) * np.diff(q_edges) / (2*h) 
    308308        else: 
    309             L = n_height 
    310             for k in range(-L, L+1): 
    311                 weights[i, :] += _q_perp_weights(q_edges, qi+k*h/L, w) 
    312             weights[i, :] /= 2*L + 1 
     309            for k in range(-n_height, h_height+1): 
     310                weights[i, :] += _q_perp_weights(q_edges, qi+k*h/n_height, w) 
     311            weights[i, :] /= 2*n_height + 1 
    313312 
    314313    return weights.T 
     
    523522    for i, (qi, w, h) in enumerate(zip(q, width, height)): 
    524523        if h == 0.: 
    525             r = romberg(_int_w, 0, w, args=(qi,), 
    526                         divmax=100, vec_func=True, tol=0, rtol=1e-8) 
    527             result[i] = r/w 
     524            total = romberg(_int_w, 0, w, args=(qi,), 
     525                            divmax=100, vec_func=True, tol=0, rtol=1e-8) 
     526            result[i] = total/w 
    528527        elif w == 0.: 
    529             r = romberg(_int_h, -h, h, args=(qi,), 
    530                         divmax=100, vec_func=True, tol=0, rtol=1e-8) 
    531             result[i] = r/(2*h) 
     528            total = romberg(_int_h, -h, h, args=(qi,), 
     529                            divmax=100, vec_func=True, tol=0, rtol=1e-8) 
     530            result[i] = total/(2*h) 
    532531        else: 
    533532            w_grid = np.linspace(0, w, 21)[None, :] 
    534533            h_grid = np.linspace(-h, h, 23)[:, None] 
    535             u = sqrt((qi+h_grid)**2 + w_grid**2) 
    536             Iu = np.interp(u, q_calc, Iq) 
     534            u_sub = sqrt((qi+h_grid)**2 + w_grid**2) 
     535            f_at_u = np.interp(u_sub, q_calc, Iq) 
    537536            #print(np.trapz(Iu, w_grid, axis=1)) 
    538             Is = np.trapz(np.trapz(Iu, w_grid, axis=1), h_grid[:, 0]) 
    539             result[i] = Is / (2*h*w) 
     537            total  = np.trapz(np.trapz(f_at_u, w_grid, axis=1), h_grid[:, 0]) 
     538            result[i] = total / (2*h*w) 
    540539            # from scipy.integrate import dblquad 
    541540            # r, err = dblquad(_int_wh, -h, h, lambda h: 0., lambda h: w, 
     
    564563 
    565564    _fn = lambda q, q0, dq: eval_form(q, form, pars)*gaussian(q, q0, dq) 
    566     r = [romberg(_fn, max(qi-nsigma*dqi, 1e-10*q[0]), qi+nsigma*dqi, 
    567                  args=(qi, dqi), divmax=100, vec_func=True, tol=0, rtol=1e-8) 
    568          for qi, dqi in zip(q, q_width)] 
     565    total = [romberg(_fn, max(qi-nsigma*dqi, 1e-10*q[0]), qi+nsigma*dqi, 
     566                     args=(qi, dqi), divmax=100, vec_func=True, 
     567                     tol=0, rtol=1e-8) 
     568             for qi, dqi in zip(q, q_width)] 
    569569    return np.asarray(r).flatten() 
    570570 
     
    715715 
    716716        data = np.loadtxt(data_string.split('\n')).T 
    717         q, width, answer, _ = data 
     717        q, _, answer, _ = data 
    718718        resolution = Perfect1D(q) 
    719719        output = self._eval_sphere(pars, resolution) 
     
    741741        data_string = TEST_DATA_PINHOLE_SPHERE 
    742742        pars['radius'] *= 5 
    743         radius = pars['radius'] 
    744743 
    745744        data = np.loadtxt(data_string.split('\n')).T 
     
    748747        ## Getting 0.1% requires 5 sigma and 200 points per fringe 
    749748        #q_calc = interpolate(pinhole_extend_q(q, q_width, nsigma=5), 
    750         #                     2*np.pi/radius/200) 
     749        #                     2*np.pi/pars['radius']/200) 
    751750        #tol = 0.001 
    752751        ## The default 3 sigma and no extra points gets 1% 
     
    787786        pars = TEST_PARS_SLIT_SPHERE 
    788787        data_string = TEST_DATA_SLIT_SPHERE 
    789         radius = pars['radius'] 
    790788 
    791789        data = np.loadtxt(data_string.split('\n')).T 
    792790        q, delta_qv, _, answer = data 
    793791        answer = romberg_slit_1d(q, delta_qv, 0., self.model, pars) 
    794         q_calc = slit_extend_q(interpolate(q, 2*np.pi/radius/20), 
     792        q_calc = slit_extend_q(interpolate(q, 2*np.pi/pars['radius']/20), 
    795793                               delta_qv[0], 0.) 
    796794        resolution = Slit1D(q, qx_width=delta_qv, qy_width=0, q_calc=q_calc) 
  • sasmodels/resolution2d.py

    r7ae2b7f r40a87fa  
    2424## Defaults 
    2525N_SLIT_PERP = {'xhigh':1000, 'high':500, 'med':200, 'low':50} 
    26 N_SLIT_PERP_DOC = ", ".join("%s=%d"%(name,value) for value,name in 
    27                             sorted((2*v+1,k) for k,v in N_SLIT_PERP.items())) 
     26N_SLIT_PERP_DOC = ", ".join("%s=%d"%(name, value) 
     27                            for value, name in 
     28                            sorted((2*v+1, k) for k, v in N_SLIT_PERP.items())) 
    2829 
    2930class Pinhole2D(Resolution): 
     
    225226            self.weights = resolution.pinhole_resolution(qx_calc, q, 
    226227                    np.maximum(qx_width, resolution.MINIMUM_RESOLUTION)) 
    227         elif len(qx_calc)==len(q) and np.all(qx_calc == q): 
     228        elif len(qx_calc) == len(q) and np.all(qx_calc == q): 
    228229            self.weights = None 
    229230        else: 
  • sasmodels/rst2html.py

    rb32dafd r40a87fa  
    107107    assert replace_dollar(ur"dollar \$escape\$ too") == u"dollar $escape$ too" 
    108108    assert replace_dollar(u"spaces $in the$ math") == u"spaces :math:`in the` math" 
    109     assert replace_dollar(u"emb\ $ed$\ ed") == ur"emb\ :math:`ed`\ ed" 
     109    assert replace_dollar(ur"emb\ $ed$\ ed") == ur"emb\ :math:`ed`\ ed" 
    110110    assert replace_dollar(u"$first$a") == u"$first$a" 
    111111    assert replace_dollar(u"a$last$") == u"a$last$" 
Note: See TracChangeset for help on using the changeset viewer.