Changes in / [01dba26:55e82f0] in sasmodels
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/guide/gpu_setup.rst
r63602b1 r59485a4 139 139 the compiler. 140 140 141 On Windows, set *SAS _COMPILER=tinycc* for the tinycc compiler,142 *SAS _COMPILER=msvc* for the Microsoft Visual C compiler,143 or *SAS _COMPILER=mingw* for the MinGW compiler. If TinyCC is available141 On Windows, set *SASCOMPILER=tinycc* for the tinycc compiler, 142 *SASCOMPILER=msvc* for the Microsoft Visual C compiler, 143 or *SASCOMPILER=mingw* for the MinGW compiler. If TinyCC is available 144 144 on the python path (it is provided with SasView), that will be the 145 145 default. If you want one of the other compilers, be sure to have it -
doc/guide/pd/polydispersity.rst
rd089a00 rf41027b 8 8 .. _polydispersityhelp: 9 9 10 Polydispersity & Orientational Distributions 11 -------------------------------------------- 12 13 For some models we can calculate the average intensity for a population of 14 particles that possess size and/or orientational (ie, angular) distributions. 15 In SasView we call the former *polydispersity* but use the parameter *PD* to 16 parameterise both. In other words, the meaning of *PD* in a model depends on 17 the actual parameter it is being applied too. 18 19 The resultant intensity is then normalized by the average particle volume such 20 that 10 Polydispersity Distributions 11 ---------------------------- 12 13 With some models in sasmodels we can calculate the average intensity for a 14 population of particles that exhibit size and/or orientational 15 polydispersity. The resultant intensity is normalized by the average 16 particle volume such that 21 17 22 18 .. math:: … … 25 21 26 22 where $F$ is the scattering amplitude and $\langle\cdot\rangle$ denotes an 27 average over the distribution $f(x; \bar x, \sigma)$, giving23 average over the size distribution $f(x; \bar x, \sigma)$, giving 28 24 29 25 .. math:: … … 34 30 Each distribution is characterized by a center value $\bar x$ or 35 31 $x_\text{med}$, a width parameter $\sigma$ (note this is *not necessarily* 36 <<<<<<< HEAD37 32 the standard deviation, so read the description carefully), the number of 38 33 sigmas $N_\sigma$ to include from the tails of the distribution, and the … … 47 42 However, the distribution width applied to *orientation* (ie, angle-describing) 48 43 parameters is just $\sigma = \mathrm{PD}$. 49 =======50 the standard deviation, so read the description of the distribution carefully),51 the number of sigmas $N_\sigma$ to include from the tails of the distribution,52 and the number of points used to compute the average. The center of the53 distribution is set by the value of the model parameter.54 55 The distribution width applied to *volume* (ie, shape-describing) parameters56 is relative to the center value such that $\sigma = \mathrm{PD} \cdot \bar x$.57 However, the distribution width applied to *orientation* parameters is just58 $\sigma = \mathrm{PD}$.59 >>>>>>> master60 44 61 45 $N_\sigma$ determines how far into the tails to evaluate the distribution, … … 67 51 68 52 Users should note that the averaging computation is very intensive. Applying 69 polydispersion and/or orientational distributions to multiple parameters at 70 the same time, or increasing the number of points in the distribution, will 71 require patience! However, the calculations are generally more robust with 72 more data points or more angles. 53 polydispersion to multiple parameters at the same time or increasing the 54 number of points in the distribution will require patience! However, the 55 calculations are generally more robust with more data points or more angles. 73 56 74 57 The following distribution functions are provided: … … 86 69 87 70 88 **Beware: when the Polydispersity & Orientational Distribution panel in SasView is**89 **first opened, the default distribution for all parameters is the Gaussian Distribution.**90 **This may not be suitable. See Suggested Applications below.**91 92 71 .. note:: In 2009 IUPAC decided to introduce the new term 'dispersity' to replace 93 72 the term 'polydispersity' (see `Pure Appl. Chem., (2009), 81(2), 94 73 351-353 <http://media.iupac.org/publications/pac/2009/pdf/8102x0351.pdf>`_ 95 in order to make the terminology describing distributions of chemical 96 properties unambiguous. However, these terms are unrelated to the 97 proportional size distributions and orientational distributions used in 98 SasView models. 74 in order to make the terminology describing distributions of properties 75 unambiguous. Throughout the SasView documentation we continue to use the 76 term polydispersity because one of the consequences of the IUPAC change is 77 that orientational polydispersity would not meet their new criteria (which 78 requires dispersity to be dimensionless). 99 79 100 80 Suggested Applications 101 81 ^^^^^^^^^^^^^^^^^^^^^^ 102 82 103 If applying polydispersion to parameters describing particle sizes, consider using83 If applying polydispersion to parameters describing particle sizes, use 104 84 the Lognormal or Schulz distributions. 105 85 106 86 If applying polydispersion to parameters describing interfacial thicknesses 107 or angular orientations, consider usingthe Gaussian or Boltzmann distributions.87 or angular orientations, use the Gaussian or Boltzmann distributions. 108 88 109 89 If applying polydispersion to parameters describing angles, use the Uniform … … 442 422 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 443 423 444 Several measures of polydispersity abound in Dynamic Light Scattering (DLS) and 445 it should not be assumed that any of the following can be simply equated with 446 the polydispersity *PD* parameter used in SasView. 447 448 The dimensionless **Polydispersity Index (PI)** is a measure of the width of the 449 distribution of autocorrelation function decay rates (*not* the distribution of 450 particle sizes itself, though the two are inversely related) and is defined by 451 ISO 22412:2017 as 452 453 .. math:: 454 455 PI = \mu_{2} / \bar \Gamma^2 456 457 where $\mu_\text{2}$ is the second cumulant, and $\bar \Gamma^2$ is the 458 intensity-weighted average value, of the distribution of decay rates. 459 460 *If the distribution of decay rates is Gaussian* then 461 462 .. math:: 463 464 PI = \sigma^2 / 2\bar \Gamma^2 465 466 where $\sigma$ is the standard deviation, allowing a **Relative Polydispersity (RP)** 467 to be defined as 468 469 .. math:: 470 471 RP = \sigma / \bar \Gamma = \sqrt{2 \cdot PI} 472 473 PI values smaller than 0.05 indicate a highly monodisperse system. Values 474 greater than 0.7 indicate significant polydispersity. 475 476 The **size polydispersity P-parameter** is defined as the relative standard 477 deviation coefficient of variation 478 479 .. math:: 480 481 P = \sqrt\nu / \bar R 482 483 where $\nu$ is the variance of the distribution and $\bar R$ is the mean 484 value of $R$. Here, the product $P \bar R$ is *equal* to the standard 485 deviation of the Lognormal distribution. 486 487 P values smaller than 0.13 indicate a monodisperse system. 424 Many commercial Dynamic Light Scattering (DLS) instruments produce a size 425 polydispersity parameter, sometimes even given the symbol $p$\ ! This 426 parameter is defined as the relative standard deviation coefficient of 427 variation of the size distribution and is NOT the same as the polydispersity 428 parameters in the Lognormal and Schulz distributions above (though they all 429 related) except when the DLS polydispersity parameter is <0.13. 430 431 .. math:: 432 433 p_{DLS} = \sqrt(\nu / \bar x^2) 434 435 where $\nu$ is the variance of the distribution and $\bar x$ is the mean 436 value of $x$. 488 437 489 438 For more information see: 490 491 `ISO 22412:2017, International Standards Organisation (2017) <https://www.iso.org/standard/65410.html>`_. 492 493 `Polydispersity: What does it mean for DLS and Chromatography <http://www.materials-talks.com/blog/2014/10/23/polydispersity-what-does-it-mean-for-dls-and-chromatography/>`_. 494 495 `Dynamic Light Scattering: Common Terms Defined, Whitepaper WP111214. Malvern Instruments (2011) <http://www.biophysics.bioc.cam.ac.uk/wp-content/uploads/2011/02/DLS_Terms_defined_Malvern.pdf>`_. 496 497 S King, C Washington & R Heenan, *Phys Chem Chem Phys*, (2005), 7, 143. 498 499 T Allen, in *Particle Size Measurement*, 4th Edition, Chapman & Hall, London (1990). 439 S King, C Washington & R Heenan, *Phys Chem Chem Phys*, (2005), 7, 143 500 440 501 441 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ … … 507 447 | 2018-03-20 Steve King 508 448 | 2018-04-04 Steve King 509 | 2018-08-09 Steve King -
doc/guide/scripting.rst
rbd7630d r4aa5dce 10 10 The key functions are :func:`sasmodels.core.load_model` for loading the 11 11 model definition and compiling the kernel and 12 :func:`sasmodels.data.load_data` for calling sasview to load the data. 12 :func:`sasmodels.data.load_data` for calling sasview to load the data. Need 13 the data because that defines the resolution function and the q values to 14 evaluate. If there is no data, then use :func:`sasmodels.data.empty_data1D` 15 or :func:`sasmodels.data.empty_data2D` to create some data with a given $q$. 13 16 14 Preparing data 15 ============== 17 Using sasmodels through bumps 18 ============================= 16 19 17 Usually you will load data via the sasview loader, with the 18 :func:`sasmodels.data.load_data` function. For example:: 19 20 from sasmodels.data import load_data 21 data = load_data("sasmodels/example/093191_201.dat") 22 23 You may want to apply a data mask, such a beam stop, and trim high $q$:: 24 25 from sasmodels.data import set_beam_stop 26 set_beam_stop(data, qmin, qmax) 27 28 The :func:`sasmodels.data.set_beam_stop` method simply sets the *mask* 29 attribute for the data. 30 31 The data defines the resolution function and the q values to evaluate, so 32 even if you simulating experiments prior to making measurements, you still 33 need a data object for reference. Use :func:`sasmodels.data.empty_data1D` 34 or :func:`sasmodels.data.empty_data2D` to create a container with a 35 given $q$ and $\Delta q/q$. For example:: 36 37 import numpy as np 38 from sasmodels.data import empty_data1D 39 40 # 120 points logarithmically spaced from 0.005 to 0.2, with dq/q = 5% 41 q = np.logspace(np.log10(5e-3), np.log10(2e-1), 120) 42 data = empty_data1D(q, resolution=0.05) 43 44 To use a more realistic model of resolution, or to load data from a file 45 format not understood by SasView, you can use :class:`sasmodels.data.Data1D` 46 or :class:`sasmodels.data.Data2D` directly. The 1D data uses 47 *x*, *y*, *dx* and *dy* for $x = q$ and $y = I(q)$, and 2D data uses 48 *x*, *y*, *z*, *dx*, *dy*, *dz* for $x, y = qx, qy$ and $z = I(qx, qy)$. 49 [Note: internally, the Data2D object uses SasView conventions, 50 *qx_data*, *qy_data*, *data*, *dqx_data*, *dqy_data*, and *err_data*.] 51 52 For USANS data, use 1D data, but set *dxl* and *dxw* attributes to 53 indicate slit resolution:: 54 55 data.dxl = 0.117 56 57 See :func:`sasmodels.resolution.slit_resolution` for details. 58 59 SESANS data is more complicated; if your SESANS format is not supported by 60 SasView you need to define a number of attributes beyond *x*, *y*. For 61 example:: 62 63 SElength = np.linspace(0, 2400, 61) # [A] 64 data = np.ones_like(SElength) 65 err_data = np.ones_like(SElength)*0.03 66 67 class Source: 68 wavelength = 6 # [A] 69 wavelength_unit = "A" 70 class Sample: 71 zacceptance = 0.1 # [A^-1] 72 thickness = 0.2 # [cm] 73 74 class SESANSData1D: 75 #q_zmax = 0.23 # [A^-1] 76 lam = 0.2 # [nm] 77 x = SElength 78 y = data 79 dy = err_data 80 sample = Sample() 81 data = SESANSData1D() 82 83 x, y = ... # create or load sesans 84 data = smd.Data 85 86 The *data* module defines various data plotters as well. 87 88 Using sasmodels directly 89 ======================== 90 91 Once you have a computational kernel and a data object, you can evaluate 92 the model for various parameters using 93 :class:`sasmodels.direct_model.DirectModel`. The resulting object *f* 94 will be callable as *f(par=value, ...)*, returning the $I(q)$ for the $q$ 95 values in the data. For example:: 96 97 import numpy as np 98 from sasmodels.data import empty_data1D 99 from sasmodels.core import load_model 100 from sasmodels.direct_model import DirectModel 101 102 # 120 points logarithmically spaced from 0.005 to 0.2, with dq/q = 5% 103 q = np.logspace(np.log10(5e-3), np.log10(2e-1), 120) 104 data = empty_data1D(q, resolution=0.05) 105 kernel = load_model("ellipsoid) 106 f = DirectModel(data, kernel) 107 Iq = f(radius_polar=100) 108 109 Polydispersity information is set with special parameter names: 110 111 * *par_pd* for polydispersity width, $\Delta p/p$, 112 * *par_pd_n* for the number of points in the distribution, 113 * *par_pd_type* for the distribution type (as a string), and 114 * *par_pd_nsigmas* for the limits of the distribution. 115 116 Using sasmodels through the bumps optimizer 117 =========================================== 118 119 Like DirectModel, you can wrap data and a kernel in a *bumps* model with 20 With the data and the model, you can wrap it in a *bumps* model with 120 21 class:`sasmodels.bumps_model.Model` and create an 121 class:`sasmodels.bump s_model.Experiment` that you can fit with the *bumps*22 class:`sasmodels.bump_model.Experiment` that you can fit with the *bumps* 122 23 interface. Here is an example from the *example* directory such as 123 24 *example/model.py*:: … … 174 75 SasViewCom bumps.cli example/model.py --preview 175 76 176 Calling the computation kernel 177 ============================== 77 Using sasmodels directly 78 ======================== 79 80 Bumps has a notion of parameter boxes in which you can set and retrieve 81 values. Instead of using bumps, you can create a directly callable function 82 with :class:`sasmodels.direct_model.DirectModel`. The resulting object *f* 83 will be callable as *f(par=value, ...)*, returning the $I(q)$ for the $q$ 84 values in the data. Polydisperse parameters use the same naming conventions 85 as in the bumps model, with e.g., radius_pd being the polydispersity associated 86 with radius. 178 87 179 88 Getting a simple function that you can call on a set of q values and return -
doc/rst_prolog
r2c12061 r30b60d2 9 9 .. |Ang^-3| replace:: |Ang|\ :sup:`-3` 10 10 .. |Ang^-4| replace:: |Ang|\ :sup:`-4` 11 .. |nm^-1| replace:: nm\ :sup:`-1`12 11 .. |cm^-1| replace:: cm\ :sup:`-1` 13 12 .. |cm^2| replace:: cm\ :sup:`2` -
sasmodels/compare.py
rbd7630d rd0fdba2 1289 1289 1290 1290 if opts['datafile'] is not None: 1291 data0 = load_data(os.path.expanduser(opts['datafile'])) 1292 data = data0, data0 1291 data = load_data(os.path.expanduser(opts['datafile'])) 1293 1292 else: 1294 1293 # Hack around the fact that make_data doesn't take a pair of resolutions -
sasmodels/core.py
r2dcd6e7 r4341dd4 233 233 if not callable(model_info.Iq): 234 234 source = generate.make_source(model_info)['dll'] 235 old_path = kerneldll. SAS_DLL_PATH235 old_path = kerneldll.DLL_PATH 236 236 try: 237 kerneldll. SAS_DLL_PATH = path237 kerneldll.DLL_PATH = path 238 238 dll = kerneldll.make_dll(source, model_info, dtype=numpy_dtype) 239 239 finally: 240 kerneldll. SAS_DLL_PATH = old_path240 kerneldll.DLL_PATH = old_path 241 241 compiled_dlls.append(dll) 242 242 return compiled_dlls -
sasmodels/data.py
rbd7630d r1a8c11c 183 183 *x* is spin echo length and *y* is polarization (P/P0). 184 184 """ 185 isSesans = True186 185 def __init__(self, **kw): 187 186 Data1D.__init__(self, **kw) … … 302 301 self.wavelength_unit = "A" 303 302 304 class Sample(object):305 """306 Sample attributes.307 """308 def __init__(self):309 # type: () -> None310 pass311 303 312 304 def empty_data1D(q, resolution=0.0, L=0., dL=0.): … … 512 504 # and the data mask will be added to it. 513 505 #mtheory = masked_array(theory, data.mask.copy()) 514 theory_x = data.x[ data.mask == 0]506 theory_x = data.x[~data.mask] 515 507 mtheory = masked_array(theory) 516 508 mtheory[~np.isfinite(mtheory)] = masked … … 553 545 554 546 if use_resid: 555 theory_x = data.x[ data.mask == 0]547 theory_x = data.x[~data.mask] 556 548 mresid = masked_array(resid) 557 549 mresid[~np.isfinite(mresid)] = masked -
sasmodels/direct_model.py
r7b9e4dd r1a8c11c 31 31 from . import resolution2d 32 32 from .details import make_kernel_args, dispersion_mesh 33 from .modelinfo import DEFAULT_BACKGROUND34 33 35 34 # pylint: disable=unused-import … … 350 349 351 350 # Need to pull background out of resolution for multiple scattering 352 background = pars.get('background', DEFAULT_BACKGROUND)351 background = pars.get('background', 0.) 353 352 pars = pars.copy() 354 353 pars['background'] = 0. -
sasmodels/generate.py
r6e45516 rd86f0fc 965 965 docs = model_info.docs if model_info.docs is not None else "" 966 966 docs = convert_section_titles_to_boldface(docs) 967 if model_info.structure_factor: 968 pars = model_info.parameters.kernel_parameters 969 else: 970 pars = model_info.parameters.COMMON + model_info.parameters.kernel_parameters 971 partable = make_partable(pars) 967 pars = make_partable(model_info.parameters.COMMON 968 + model_info.parameters.kernel_parameters) 972 969 subst = dict(id=model_info.id.replace('_', '-'), 973 970 name=model_info.name, 974 971 title=model_info.title, 975 parameters=par table,972 parameters=pars, 976 973 returns=Sq_units if model_info.structure_factor else Iq_units, 977 974 docs=docs) -
sasmodels/kernel_iq.c
r70530778 r7c35fda 84 84 out_spin = clip(out_spin, 0.0, 1.0); 85 85 // Previous version of this function took the square root of the weights, 86 // under the assumption that 86 // under the assumption that 87 87 // 88 88 // w*I(q, rho1, rho2, ...) = I(q, sqrt(w)*rho1, sqrt(w)*rho2, ...) … … 188 188 QACRotation *rotation, 189 189 double qx, double qy, 190 double *qa b_out, double *qc_out)190 double *qa_out, double *qc_out) 191 191 { 192 const double dqc = rotation->R31*qx + rotation->R32*qy; 192 193 // Indirect calculation of qab, from qab^2 = |q|^2 - qc^2 193 const double dqc = rotation->R31*qx + rotation->R32*qy; 194 const double dqab_sq = -dqc*dqc + qx*qx + qy*qy; 195 //*qab_out = sqrt(fabs(dqab_sq)); 196 *qab_out = dqab_sq > 0.0 ? sqrt(dqab_sq) : 0.0; 194 const double dqa = sqrt(-dqc*dqc + qx*qx + qy*qy); 195 196 *qa_out = dqa; 197 197 *qc_out = dqc; 198 198 } -
sasmodels/model_test.py
- Property mode changed from 100755 to 100644
r012cd34 r3221de0 376 376 stream.writeln(traceback.format_exc()) 377 377 return 378 # Run the test suite 379 suite.run(result) 380 381 # Print the failures and errors 382 for _, tb in result.errors: 383 stream.writeln(tb) 384 for _, tb in result.failures: 385 stream.writeln(tb) 378 386 379 387 # Warn if there are no user defined tests. … … 385 393 # iterator since we don't have direct access to the list of tests in the 386 394 # test suite. 387 # In Qt5 suite.run() will clear all tests in the suite after running388 # with no way of retaining them for the test below, so let's check389 # for user tests before running the suite.390 395 for test in suite: 391 396 if not test.info.tests: … … 394 399 else: 395 400 stream.writeln("Note: no test suite created --- this should never happen") 396 397 # Run the test suite398 suite.run(result)399 400 # Print the failures and errors401 for _, tb in result.errors:402 stream.writeln(tb)403 for _, tb in result.failures:404 stream.writeln(tb)405 401 406 402 output = stream.getvalue() -
sasmodels/modelinfo.py
r7b9e4dd r95498a3 45 45 # Note that scale and background cannot be coordinated parameters whose value 46 46 # depends on the some polydisperse parameter with the current implementation 47 DEFAULT_BACKGROUND = 1e-348 47 COMMON_PARAMETERS = [ 49 48 ("scale", "", 1, (0.0, np.inf), "", "Source intensity"), 50 ("background", "1/cm", DEFAULT_BACKGROUND, (-np.inf, np.inf), "", "Source background"),49 ("background", "1/cm", 1e-3, (-np.inf, np.inf), "", "Source background"), 51 50 ] 52 51 assert (len(COMMON_PARAMETERS) == 2 … … 590 589 Parameter('up:frac_f', '', 0., [0., 1.], 591 590 'magnetic', 'fraction of spin up final'), 592 Parameter('up:angle', 'degre es', 0., [0., 360.],591 Parameter('up:angle', 'degress', 0., [0., 360.], 593 592 'magnetic', 'spin up angle'), 594 593 ]) -
sasmodels/models/_spherepy.py
rca4444f r108e70e 1 1 r""" 2 2 For information about polarised and magnetic scattering, see 3 the : ref:`magnetism` documentation.3 the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 4 4 5 5 Definition -
sasmodels/models/core_shell_cylinder.py
re31b19a r2d81cfe 5 5 The output of the 2D scattering intensity function for oriented core-shell 6 6 cylinders is given by (Kline, 2006 [#kline]_). The form factor is normalized 7 by the particle volume. Note that in this model the shell envelops the entire 8 core so that besides a "sleeve" around the core, the shell also provides two 9 flat end caps of thickness = shell thickness. In other words the length of the 10 total cyclinder is the length of the core cylinder plus twice the thickness of 11 the shell. If no end caps are desired one should use the 12 :ref:`core-shell-bicelle` and set the thickness of the end caps (in this case 13 the "thick_face") to zero. 7 by the particle volume. 14 8 15 9 .. math:: … … 39 33 40 34 and $\alpha$ is the angle between the axis of the cylinder and $\vec q$, 41 $V_s$ is the total volume (i.e. including both the core and the outer shell),42 $V_c$ is the volume of the core, $L$ is the length of the core,35 $V_s$ is the volume of the outer shell (i.e. the total volume, including 36 the shell), $V_c$ is the volume of the core, $L$ is the length of the core, 43 37 $R$ is the radius of the core, $T$ is the thickness of the shell, $\rho_c$ 44 38 is the scattering length density of the core, $\rho_s$ is the scattering … … 141 135 return 0.5 * (ddd) ** (1. / 3.) 142 136 137 def VR(radius, thickness, length): 138 """ 139 Returns volume ratio 140 """ 141 whole = pi * (radius + thickness) ** 2 * (length + 2 * thickness) 142 core = pi * radius ** 2 * length 143 return whole, whole - core 144 143 145 def random(): 144 146 outer_radius = 10**np.random.uniform(1, 4.7) -
sasmodels/models/core_shell_sphere.py
rda1c8d1 rdc76240 89 89 return radius + thickness 90 90 91 def VR(radius, thickness): 92 """ 93 Volume ratio 94 @param radius: core radius 95 @param thickness: shell thickness 96 """ 97 return (1, 1) 98 whole = 4.0/3.0 * pi * (radius + thickness)**3 99 core = 4.0/3.0 * pi * radius**3 100 return whole, whole - core 101 91 102 def random(): 92 103 outer_radius = 10**np.random.uniform(1.3, 4.3) … … 103 114 tests = [ 104 115 [{'radius': 20.0, 'thickness': 10.0}, 'ER', 30.0], 116 # TODO: VR test suppressed until we sort out new product model 117 # and determine what to do with volume ratio. 118 #[{'radius': 20.0, 'thickness': 10.0}, 'VR', 0.703703704], 105 119 106 120 # The SasView test result was 0.00169, with a background of 0.001 -
sasmodels/models/ellipsoid.py
r0168844 r2d81cfe 125 125 import numpy as np 126 126 from numpy import inf, sin, cos, pi 127 128 try:129 from numpy import cbrt130 except ImportError:131 def cbrt(x): return x ** (1.0/3.0)132 127 133 128 name = "ellipsoid" … … 175 170 idx = radius_polar < radius_equatorial 176 171 ee[idx] = (radius_equatorial[idx] ** 2 - radius_polar[idx] ** 2) / radius_equatorial[idx] ** 2 177 valid = (radius_polar * radius_equatorial != 0) & (radius_polar != radius_equatorial) 172 idx = radius_polar == radius_equatorial 173 ee[idx] = 2 * radius_polar[idx] 174 valid = (radius_polar * radius_equatorial != 0) 178 175 bd = 1.0 - ee[valid] 179 176 e1 = np.sqrt(ee[valid]) … … 182 179 b2 = 1.0 + bd / 2 / e1 * np.log(bL) 183 180 delta = 0.75 * b1 * b2 184 ddd = 2.0 * (delta + 1.0) * (radius_polar * radius_equatorial**2)[valid] 185 186 r = np.zeros_like(radius_polar) 187 r[valid] = 0.5 * cbrt(ddd) 188 idx = radius_polar == radius_equatorial 189 r[idx] = radius_polar[idx] 190 return r 181 182 ddd = np.zeros_like(radius_polar) 183 ddd[valid] = 2.0 * (delta + 1.0) * radius_polar * radius_equatorial ** 2 184 return 0.5 * ddd ** (1.0 / 3.0) 191 185 192 186 def random(): -
sasmodels/models/fractal_core_shell.py
reb3eb38 ref07e95 88 88 ["sld_shell", "1e-6/Ang^2", 2.0, [-inf, inf], "sld", "Sphere shell scattering length density"], 89 89 ["sld_solvent", "1e-6/Ang^2", 3.0, [-inf, inf], "sld", "Solvent scattering length density"], 90 ["volfraction", "", 0.05, [0.0, inf], "", "Volume fraction of building block spheres"],90 ["volfraction", "", 1.0, [0.0, inf], "", "Volume fraction of building block spheres"], 91 91 ["fractal_dim", "", 2.0, [0.0, 6.0], "", "Fractal dimension"], 92 92 ["cor_length", "Ang", 100.0, [0.0, inf], "", "Correlation length of fractal-like aggregates"], … … 134 134 return radius + thickness 135 135 136 def VR(radius, thickness): 137 """ 138 Volume ratio 139 @param radius: core radius 140 @param thickness: shell thickness 141 """ 142 whole = 4.0/3.0 * pi * (radius + thickness)**3 143 core = 4.0/3.0 * pi * radius**3 144 return whole, whole-core 145 136 146 tests = [[{'radius': 20.0, 'thickness': 10.0}, 'ER', 30.0], 147 [{'radius': 20.0, 'thickness': 10.0}, 'VR', 0.703703704]] 137 148 138 # # At some point the SasView 3.x test result was deemed incorrect. The 139 #following tests were verified against NIST IGOR macros ver 7.850. 140 #NOTE: NIST macros do only provide for a polydispers core (no option 141 #for a poly shell or for a monodisperse core. The results seemed 142 #extremely sensitive to the core PD, varying non monotonically all 143 #the way to a PD of 1e-6. From 1e-6 to 1e-9 no changes in the 144 #results were observed and the values below were taken using PD=1e-9. 145 #Non-monotonically = I(0.001)=188 to 140 to 177 back to 160 etc. 146 [{'radius': 20.0, 147 'thickness': 5.0, 148 'sld_core': 3.5, 149 'sld_shell': 1.0, 150 'sld_solvent': 6.35, 151 'volfraction': 0.05, 152 'background': 0.0}, 153 [0.001,0.00291,0.0107944,0.029923,0.100726,0.476304], 154 [177.146,165.151,84.1596,20.1466,1.40906,0.00622666]]] 149 # # The SasView test result was 0.00169, with a background of 0.001 150 # # They are however wrong as we now know. IGOR might be a more 151 # # appropriate source. Otherwise will just have to assume this is now 152 # # correct and self generate a correct answer for the future. Until we 153 # # figure it out leave the tests commented out 154 # [{'radius': 60.0, 155 # 'thickness': 10.0, 156 # 'sld_core': 1.0, 157 # 'sld_shell': 2.0, 158 # 'sld_solvent': 3.0, 159 # 'background': 0.0 160 # }, 0.015211, 692.84]] -
sasmodels/models/hollow_cylinder.py
r455aaa1 r2d81cfe 1 1 r""" 2 Definition3 ----------4 5 2 This model provides the form factor, $P(q)$, for a monodisperse hollow right 6 angle circular cylinder (rigid tube) where the The inside and outside of the 7 hollow cylinder are assumed to have the same SLD and the form factor is thus 8 normalized by the volume of the tube (i.e. not by the total cylinder volume). 3 angle circular cylinder (rigid tube) where the form factor is normalized by the 4 volume of the tube (i.e. not by the external volume). 9 5 10 6 .. math:: … … 12 8 P(q) = \text{scale} \left<F^2\right>/V_\text{shell} + \text{background} 13 9 14 where the averaging $\left<\ldots\right>$ is applied only for the 1D 15 calculation. If Intensity is given on an absolute scale, the scale factor here 16 is the volume fraction of the shell. This differs from 17 the :ref:`core-shell-cylinder` in that, in that case, scale is the volume 18 fraction of the entire cylinder (core+shell). The application might be for a 19 bilayer which wraps into a hollow tube and the volume fraction of material is 20 all in the shell, whereas the :ref:`core-shell-cylinder` model might be used for 21 a cylindrical micelle where the tails in the core have a different SLD than the 22 headgroups (in the shell) and the volume fraction of material comes fromm the 23 whole cyclinder. NOTE: the hollow_cylinder represents a tube whereas the 24 core_shell_cylinder includes a shell layer covering the ends (end caps) as well. 10 where the averaging $\left<\ldots\right>$ is applied only for the 1D calculation. 25 11 12 The inside and outside of the hollow cylinder are assumed have the same SLD. 13 14 Definition 15 ---------- 26 16 27 17 The 1D scattering intensity is calculated in the following way (Guinier, 1955) … … 58 48 ---------- 59 49 60 .. [#]L A Feigin and D I Svergun, *Structure Analysis by Small-Angle X-Ray and61 50 L A Feigin and D I Svergun, *Structure Analysis by Small-Angle X-Ray and 51 Neutron Scattering*, Plenum Press, New York, (1987) 62 52 63 53 Authorship and Verification … … 65 55 66 56 * **Author:** NIST IGOR/DANSE **Date:** pre 2010 67 * **Last Modified by:** Paul Butler **Date:** September 06, 201868 ( corrected VR calculation)69 * **Last Reviewed by:** Paul Butler **Date:** September 06, 201857 * **Last Modified by:** Richard Heenan **Date:** October 06, 2016 58 (reparametrised to use thickness, not outer radius) 59 * **Last Reviewed by:** Richard Heenan **Date:** October 06, 2016 70 60 """ 71 61 … … 130 120 vol_total = pi*router*router*length 131 121 vol_shell = vol_total - vol_core 132 return vol_ total, vol_shell122 return vol_shell, vol_total 133 123 134 124 def random(): … … 161 151 tests = [ 162 152 [{}, 0.00005, 1764.926], 163 [{}, 'VR', 0.55555556],153 [{}, 'VR', 1.8], 164 154 [{}, 0.001, 1756.76], 165 155 [{}, (qx, qy), 2.36885476192], -
sasmodels/models/hollow_rectangular_prism.py
r455aaa1 r2d81cfe 2 2 # Note: model title and parameter table are inserted automatically 3 3 r""" 4 5 This model provides the form factor, $P(q)$, for a hollow rectangular 6 parallelepiped with a wall of thickness $\Delta$. 7 8 4 9 Definition 5 10 ---------- 6 11 7 This model provides the form factor, $P(q)$, for a hollow rectangular 8 parallelepiped with a wall of thickness $\Delta$. The 1D scattering intensity 9 for this model is calculated by forming the difference of the amplitudes of two 10 massive parallelepipeds differing in their outermost dimensions in each 11 direction by the same length increment $2\Delta$ (\ [#Nayuk2012]_ Nayuk, 2012). 12 The 1D scattering intensity for this model is calculated by forming 13 the difference of the amplitudes of two massive parallelepipeds 14 differing in their outermost dimensions in each direction by the 15 same length increment $2\Delta$ (Nayuk, 2012). 12 16 13 17 As in the case of the massive parallelepiped model (:ref:`rectangular-prism`), … … 57 61 \rho_\text{solvent})^2 \times P(q) + \text{background} 58 62 59 where $\rho_\text{p}$ is the scattering length densityof the parallelepiped,60 $\rho_\text{solvent}$ is the scattering length densityof the solvent,63 where $\rho_\text{p}$ is the scattering length of the parallelepiped, 64 $\rho_\text{solvent}$ is the scattering length of the solvent, 61 65 and (if the data are in absolute units) *scale* represents the volume fraction 62 (which is unitless) of the rectangular shell of material (i.e. not including 63 the volume of the solvent filled core). 66 (which is unitless). 64 67 65 68 For 2d data the orientation of the particle is required, described using … … 70 73 71 74 For 2d, constraints must be applied during fitting to ensure that the inequality 72 $A < B < C$ is not violated, and hence the correct definition of angles is 73 preserved. The calculation will not report an error if the inequality is *not* 74 preserved, but the results may be not correct. 75 $A < B < C$ is not violated, and hence the correct definition of angles is preserved. The calculation will not report an error, 76 but the results may be not correct. 75 77 76 78 .. figure:: img/parallelepiped_angle_definition.png … … 97 99 ---------- 98 100 99 .. [#Nayuk2012] R Nayuk and K Huber, *Z. Phys. Chem.*, 226 (2012) 837-854 100 101 102 Authorship and Verification 103 ---------------------------- 104 105 * **Author:** Miguel Gonzales **Date:** February 26, 2016 106 * **Last Modified by:** Paul Kienzle **Date:** December 14, 2017 107 * **Last Reviewed by:** Paul Butler **Date:** September 06, 2018 101 R Nayuk and K Huber, *Z. Phys. Chem.*, 226 (2012) 837-854 108 102 """ 109 103 -
sasmodels/models/hollow_rectangular_prism_thin_walls.py
r6e7d7b6 r2d81cfe 2 2 # Note: model title and parameter table are inserted automatically 3 3 r""" 4 5 This model provides the form factor, $P(q)$, for a hollow rectangular 6 prism with infinitely thin walls. It computes only the 1D scattering, not the 2D. 7 8 4 9 Definition 5 10 ---------- 6 11 7 8 This model provides the form factor, $P(q)$, for a hollow rectangular9 prism with infinitely thin walls. It computes only the 1D scattering, not the 2D.10 12 The 1D scattering intensity for this model is calculated according to the 11 equations given by Nayuk and Huber \ [#Nayuk2012]_.13 equations given by Nayuk and Huber (Nayuk, 2012). 12 14 13 15 Assuming a hollow parallelepiped with infinitely thin walls, edge lengths … … 53 55 I(q) = \text{scale} \times V \times (\rho_\text{p} - \rho_\text{solvent})^2 \times P(q) 54 56 55 where $V$ is the surface areaof the rectangular prism, $\rho_\text{p}$56 is the scattering length densityof the parallelepiped, $\rho_\text{solvent}$57 is the scattering length density of the solvent, and (if the data are in58 absolute units) *scale* is related to the total surface area.57 where $V$ is the volume of the rectangular prism, $\rho_\text{p}$ 58 is the scattering length of the parallelepiped, $\rho_\text{solvent}$ 59 is the scattering length of the solvent, and (if the data are in absolute 60 units) *scale* represents the volume fraction (which is unitless). 59 61 60 62 **The 2D scattering intensity is not computed by this model.** … … 65 67 66 68 Validation of the code was conducted by qualitatively comparing the output 67 of the 1D model to the curves shown in (Nayuk, 2012 \ [#Nayuk2012]_).69 of the 1D model to the curves shown in (Nayuk, 2012). 68 70 69 71 … … 71 73 ---------- 72 74 73 .. [#Nayuk2012] R Nayuk and K Huber, *Z. Phys. Chem.*, 226 (2012) 837-854 74 75 76 Authorship and Verification 77 ---------------------------- 78 79 * **Author:** Miguel Gonzales **Date:** February 26, 2016 80 * **Last Modified by:** Paul Kienzle **Date:** October 15, 2016 81 * **Last Reviewed by:** Paul Butler **Date:** September 07, 2018 75 R Nayuk and K Huber, *Z. Phys. Chem.*, 226 (2012) 837-854 82 76 """ 83 77 -
sasmodels/models/spherical_sld.py
r5601947 r2d81cfe 1 1 r""" 2 Definition3 ----------4 5 2 Similarly to the onion, this model provides the form factor, $P(q)$, for 6 3 a multi-shell sphere, where the interface between the each neighboring … … 19 16 interface. The form factor is normalized by the total volume of the sphere. 20 17 21 Interface shapes are as follows: 18 Interface shapes are as follows:: 22 19 23 20 0: erf($\nu z$) 24 25 21 1: Rpow($z^\nu$) 26 27 22 2: Lpow($z^\nu$) 28 29 23 3: Rexp($-\nu z$) 30 31 24 4: Lexp($-\nu z$) 25 26 Definition 27 ---------- 32 28 33 29 The form factor $P(q)$ in 1D is calculated by: … … 178 174 when $P(Q) * S(Q)$ is applied. 179 175 180 181 176 References 182 177 ---------- 183 184 .. [#] L A Feigin and D I Svergun, Structure Analysis by Small-Angle X-Ray 185 and Neutron Scattering, Plenum Press, New York, (1987) 186 187 188 Authorship and Verification 189 ---------------------------- 190 191 * **Author:** Jae-Hie Cho **Date:** Nov 1, 2010 192 * **Last Modified by:** Paul Kienzle **Date:** Dec 20, 2016 193 * **Last Reviewed by:** Paul Butler **Date:** September 8, 2018 178 L A Feigin and D I Svergun, Structure Analysis by Small-Angle X-Ray 179 and Neutron Scattering, Plenum Press, New York, (1987) 194 180 """ 195 181 -
sasmodels/models/spinodal.py
r475ff58 ref07e95 3 3 ---------- 4 4 5 This model calculates the SAS signal of a phase separating system 6 undergoing spinodal decomposition. The scattering intensity $I(q)$ is calculated 7 as 5 This model calculates the SAS signal of a phase separating solution 6 under spinodal decomposition. The scattering intensity $I(q)$ is calculated as 8 7 9 8 .. math:: 10 9 I(q) = I_{max}\frac{(1+\gamma/2)x^2}{\gamma/2+x^{2+\gamma}}+B 11 10 12 where $x=q/q_0$, $q_0$ is the peak position, $I_{max}$ is the intensity 13 at $q_0$ (parameterised as the $scale$ parameter), and $B$ is a flat 14 background. The spinodal wavelength is given by $2\pi/q_0$. 15 16 The exponent $\gamma$ is equal to $d+1$ for off-critical concentration 17 mixtures (smooth interfaces) and $2d$ for critical concentration mixtures 18 (entangled interfaces), where $d$ is the dimensionality (ie, 1, 2, 3) of the 19 system. Thus 2 <= $\gamma$ <= 6. A transition from $\gamma=d+1$ to $\gamma=2d$ 20 is expected near the percolation threshold. 21 22 As this function tends to zero as $q$ tends to zero, in practice it may be 23 necessary to combine it with another function describing the low-angle 24 scattering, or to simply omit the low-angle scattering from the fit. 11 where $x=q/q_0$ and $B$ is a flat background. The characteristic structure 12 length scales with the correlation peak at $q_0$. The exponent $\gamma$ is 13 equal to $d+1$ with d the dimensionality of the off-critical concentration 14 mixtures. A transition to $\gamma=2d$ is seen near the percolation threshold 15 into the critical concentration regime. 25 16 26 17 References … … 31 22 Physica A 123,497 (1984). 32 23 33 Revision History 34 ---------------- 24 Authorship and Verification 25 ---------------------------- 35 26 36 * **Author:** Dirk Honecker **Date:** Oct 7, 2016 37 * **Revised:** Steve King **Date:** Sep 7, 2018 27 * **Author:** Dirk Honecker **Date:** Oct 7, 2016 38 28 """ 39 29 … … 44 34 title = "Spinodal decomposition model" 45 35 description = """\ 46 I(q) = Imax ((1+gamma/2)x^2)/(gamma/2+x^(2+gamma)) +background36 I(q) = scale ((1+gamma/2)x^2)/(gamma/2+x^(2+gamma))+background 47 37 48 38 List of default parameters: 49 50 Imax = correlation peak intensity at q_0 51 background = incoherent background 52 gamma = exponent (see model documentation) 39 scale = scaling 40 gamma = exponent 41 x = q/q_0 53 42 q_0 = correlation peak position [1/A] 54 x = q/q_0""" 55 43 background = Incoherent background""" 56 44 category = "shape-independent" 57 45 -
sasmodels/models/vesicle.py
rb477605 ref07e95 3 3 ---------- 4 4 5 This model provides the form factor, *P(q)*, for an unilamellar vesicle and is 6 effectively identical to the hollow sphere reparameterized to be 7 more intuitive for a vesicle and normalizing the form factor by the volume of 8 the shell. The 1D scattering intensity is calculated in the following way 9 (Guinier,1955\ [#Guinier1955]_) 5 The 1D scattering intensity is calculated in the following way (Guinier, 1955) 10 6 11 7 .. math:: … … 57 53 ---------- 58 54 59 .. [#Guinier1955] A Guinier and G. Fournet, *Small-Angle Scattering of X-Rays*, John Wiley and 60 Sons, New York, (1955) 61 62 63 Authorship and Verification 64 ---------------------------- 55 A Guinier and G. Fournet, *Small-Angle Scattering of X-Rays*, John Wiley and 56 Sons, New York, (1955) 65 57 66 58 * **Author:** NIST IGOR/DANSE **Date:** pre 2010 67 59 * **Last Modified by:** Paul Butler **Date:** March 20, 2016 68 * **Last Reviewed by:** Paul Butler **Date:** September 7, 201860 * **Last Reviewed by:** Paul Butler **Date:** March 20, 2016 69 61 """ 70 62 … … 73 65 74 66 name = "vesicle" 75 title = "Vesicle model representing a hollow sphere" 67 title = "This model provides the form factor, *P(q)*, for an unilamellar \ 68 vesicle. This is model is effectively identical to the hollow sphere \ 69 reparameterized to be more intuitive for a vesicle and normalizing the \ 70 form factor by the volume of the shell." 76 71 description = """ 77 72 Model parameters: -
sasmodels/resolution.py
r9e7837a r0b9c6df 20 20 MINIMUM_RESOLUTION = 1e-8 21 21 MINIMUM_ABSOLUTE_Q = 0.02 # relative to the minimum q in the data 22 # According to (Barker & Pedersen 1995 JAC), 2.5 sigma is a good limit. 23 # According to simulations with github.com:scattering/sansresolution.git 24 # it is better to use asymmetric bounds (2.5, 3.0) 25 PINHOLE_N_SIGMA = (2.5, 3.0) 22 PINHOLE_N_SIGMA = 2.5 # From: Barker & Pedersen 1995 JAC 26 23 27 24 class Resolution(object): … … 93 90 # from the geometry, they may appear since we are using a truncated 94 91 # gaussian to represent resolution rather than a skew distribution. 95 #cutoff = MINIMUM_ABSOLUTE_Q*np.min(self.q)96 #self.q_calc = self.q_calc[self.q_calc >= cutoff]92 cutoff = MINIMUM_ABSOLUTE_Q*np.min(self.q) 93 self.q_calc = self.q_calc[self.q_calc >= cutoff] 97 94 98 95 # Build weight matrix from calculated q values … … 191 188 cdf = erf((edges[:, None] - q[None, :]) / (sqrt(2.0)*q_width)[None, :]) 192 189 weights = cdf[1:] - cdf[:-1] 193 # Limit q range to (-2.5,+3) sigma 194 try: 195 nsigma_low, nsigma_high = nsigma 196 except TypeError: 197 nsigma_low = nsigma_high = nsigma 198 qhigh = q + nsigma_high*q_width 199 qlow = q - nsigma_low*q_width # linear limits 200 ##qlow = q*q/qhigh # log limits 190 # Limit q range to +/- 2.5 sigma 191 qhigh = q + nsigma*q_width 192 #qlow = q - nsigma*q_width # linear limits 193 qlow = q*q/qhigh # log limits 201 194 weights[q_calc[:, None] < qlow[None, :]] = 0. 202 195 weights[q_calc[:, None] > qhigh[None, :]] = 0. … … 372 365 373 366 374 def pinhole_extend_q(q, q_width, nsigma= PINHOLE_N_SIGMA):367 def pinhole_extend_q(q, q_width, nsigma=3): 375 368 """ 376 369 Given *q* and *q_width*, find a set of sampling points *q_calc* so … … 378 371 function. 379 372 """ 380 try: 381 nsigma_low, nsigma_high = nsigma 382 except TypeError: 383 nsigma_low = nsigma_high = nsigma 384 q_min, q_max = np.min(q - nsigma_low*q_width), np.max(q + nsigma_high*q_width) 373 q_min, q_max = np.min(q - nsigma*q_width), np.max(q + nsigma*q_width) 385 374 return linear_extrapolation(q, q_min, q_max) 386 375
Note: See TracChangeset
for help on using the changeset viewer.