Changeset 2d81cfe in sasmodels
- Timestamp:
- Nov 29, 2017 1:13:23 PM (5 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 237b800f
- Parents:
- a839b22
- Files:
-
- 100 edited
Legend:
- Unmodified
- Added
- Removed
-
extra/pylint.rc
r823e620 r2d81cfe 21 21 # List of plugins (as comma separated values of python modules names) to load, 22 22 # usually to register additional checkers. 23 load-plugins=pylint_numpy,pylint_pyopencl 23 load-plugins=pylint_numpy,pylint_pyopencl,pylint_sas 24 24 25 25 # Use multiple processes to speed up Pylint. -
sasmodels/bumps_model.py
r74b0495 r2d81cfe 20 20 from .direct_model import DataMixin 21 21 22 # pylint: disable=unused-import 22 23 try: 23 24 from typing import Dict, Union, Tuple, Any … … 28 29 except ImportError: 29 30 pass 31 # pylint: enable=unused-import 30 32 31 33 try: … … 37 39 38 40 39 def create_parameters(model_info, **kwargs): 40 # type: (ModelInfo, **Union[float, str, Parameter]) -> Tuple[Dict[str, Parameter], Dict[str, str]] 41 def create_parameters(model_info, # type: ModelInfo 42 **kwargs # type: Union[float, str, Parameter] 43 ): 44 # type: (...) -> Tuple[Dict[str, Parameter], Dict[str, str]] 41 45 """ 42 46 Generate Bumps parameters from the model info. … … 238 242 # pylint: disable=attribute-defined-outside-init 239 243 self.__dict__ = state 240 -
sasmodels/compare.py
r32398dc r2d81cfe 40 40 from . import core 41 41 from . import kerneldll 42 from . import exception43 42 from .data import plot_theory, empty_data1D, empty_data2D, load_data 44 43 from .direct_model import DirectModel, get_mesh 45 from .convert import revert_name, revert_pars46 44 from .generate import FLOAT_RE 47 45 from .weights import plot_weights -
sasmodels/compare_many.py
r32398dc r2d81cfe 264 264 return 265 265 266 data, index = make_data({'qmax':1.0, 'is2d':is2D, 'nq':Nq, 'res':0., 267 'accuracy': 'Low', 'view':'log', 'zero': False}) 266 data, index = make_data({ 267 'qmin': 0.001, 'qmax': 1.0, 'is2d': is2D, 'nq': Nq, 'res': 0., 268 'accuracy': 'Low', 'view':'log', 'zero': False 269 }) 268 270 for model in model_list: 269 271 compare_instance(model, data, index, N=count, mono=mono, -
sasmodels/convert.py
r32398dc r2d81cfe 275 275 p_scale = oldpars['scale'] 276 276 p_c1 = oldpars['c1'] 277 p_c2 = oldpars['c2']277 p_c2 = oldpars['c2'] 278 278 i_1 = 0.5*p_c1/p_c2 279 279 i_2 = math.sqrt(math.fabs(p_scale/p_c2)) -
sasmodels/core.py
re65c3ba r2d81cfe 39 39 os.makedirs(CUSTOM_MODEL_PATH) 40 40 41 # pylint: disable=unused-import 41 42 try: 42 43 from typing import List, Union, Optional, Any … … 45 46 except ImportError: 46 47 pass 48 # pylint: enable=unused-import 47 49 48 50 # TODO: refactor composite model support -
sasmodels/data.py
ra839b22 r2d81cfe 633 633 _plot_2d_signal(data, target, view=view, vmin=vmin, vmax=vmax) 634 634 plt.title('data') 635 h andle= plt.colorbar()636 h andle.set_label('$I(q)$')635 h = plt.colorbar() 636 h.set_label('$I(q)$') 637 637 638 638 # plot theory … … 642 642 _plot_2d_signal(data, theory, view=view, vmin=vmin, vmax=vmax) 643 643 plt.title('theory') 644 h andle= plt.colorbar()645 h andle.set_label(r'$\log_{10}I(q)$' if view == 'log'646 647 644 h = plt.colorbar() 645 h.set_label(r'$\log_{10}I(q)$' if view == 'log' 646 else r'$q^4 I(q)$' if view == 'q4' 647 else '$I(q)$') 648 648 649 649 # plot resid … … 653 653 _plot_2d_signal(data, resid, view='linear') 654 654 plt.title('residuals') 655 h andle= plt.colorbar()656 h andle.set_label(r'$\Delta I(q)$')655 h = plt.colorbar() 656 h.set_label(r'$\Delta I(q)$') 657 657 658 658 -
sasmodels/details.py
r110f69c r2d81cfe 15 15 16 16 import numpy as np # type: ignore 17 from numpy import pi,cos, sin, radians17 from numpy import cos, sin, radians 18 18 19 19 try: … … 29 29 return [np.asarray(v) for v in args] 30 30 31 # pylint: disable=unused-import 31 32 try: 32 33 from typing import List, Tuple, Sequence … … 36 37 from .modelinfo import ModelInfo 37 38 from .modelinfo import ParameterTable 39 # pylint: enable=unused-import 38 40 39 41 … … 220 222 221 223 ZEROS = tuple([0.]*31) 222 def make_kernel_args(kernel, mesh): 223 # type: (Kernel, Tuple[List[np.ndarray], List[np.ndarray]]) -> Tuple[CallDetails, np.ndarray, bool] 224 def make_kernel_args(kernel, # type: Kernel 225 mesh # type: Tuple[List[np.ndarray], List[np.ndarray]] 226 ): 227 # type: (...) -> Tuple[CallDetails, np.ndarray, bool] 224 228 """ 225 229 Converts (value, dispersity, weight) for each parameter into kernel pars. … … 248 252 return call_details, data, is_magnetic 249 253 250 def correct_theta_weights(parameters, dispersity, weights): 251 # type: (ParameterTable, Sequence[np.ndarray], Sequence[np.ndarray]) -> Sequence[np.ndarray] 254 def correct_theta_weights(parameters, # type: ParameterTable 255 dispersity, # type: Sequence[np.ndarray] 256 weights # type: Sequence[np.ndarray] 257 ): 258 # type: (...) -> Sequence[np.ndarray] 252 259 """ 253 260 If there is a theta parameter, update the weights of that parameter so that -
sasmodels/direct_model.py
rfa79f5c r2d81cfe 32 32 from .details import make_kernel_args, dispersion_mesh 33 33 34 # pylint: disable=unused-import 34 35 try: 35 36 from typing import Optional, Dict, Tuple … … 40 41 from .kernel import Kernel, KernelModel 41 42 from .modelinfo import Parameter, ParameterSet 43 # pylint: enable=unused-import 42 44 43 45 def call_kernel(calculator, pars, cutoff=0., mono=False): … … 163 165 nsigma = values.get(parameter.name+'_pd_nsigma', 3.0) 164 166 pd = weights.get_weights(disperser, npts, width, nsigma, 165 value, limits, relative)167 value, limits, relative) 166 168 return value, pd[0], pd[1] 167 169 … … 411 413 try: 412 414 values = [float(v) for v in call.split(',')] 413 except Exception:415 except ValueError: 414 416 values = [] 415 417 if len(values) == 1: -
sasmodels/generate.py
re65c3ba r2d81cfe 174 174 from .custom import load_custom_kernel_module 175 175 176 # pylint: disable=unused-import 176 177 try: 177 178 from typing import Tuple, Sequence, Iterator, Dict … … 179 180 except ImportError: 180 181 pass 182 # pylint: enable=unused-import 181 183 182 184 # jitter projection to use in the kernel code. See explore/jitter.py -
sasmodels/kernel.py
rbde38b5 r2d81cfe 12 12 from __future__ import division, print_function 13 13 14 import numpy as np 15 14 # pylint: disable=unused-import 16 15 try: 17 16 from typing import List … … 19 18 pass 20 19 else: 20 import numpy as np 21 21 from .details import CallDetails 22 22 from .modelinfo import ModelInfo 23 import numpy as np # type: ignore 23 # pylint: enable=unused-import 24 24 25 25 class KernelModel(object): -
sasmodels/kernelcl.py
rc1114bf r2d81cfe 74 74 from .kernel import KernelModel, Kernel 75 75 76 # pylint: disable=unused-import 76 77 try: 77 78 from typing import Tuple, Callable, Any … … 80 81 except ImportError: 81 82 pass 83 # pylint: enable=unused-import 82 84 83 85 # CRUFT: pyopencl < 2017.1 (as of June 2016 needs quotes around include path) -
sasmodels/kerneldll.py
rb2f1d2f r2d81cfe 39 39 Install locations are system dependent, such as: 40 40 41 C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat 41 C:\Program Files (x86)\Common Files\Microsoft\Visual 42 C++ for Python\9.0\vcvarsall.bat 42 43 43 44 or maybe 44 45 45 C:\Users\yourname\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat 46 C:\Users\yourname\AppData\Local\Programs\Common\Microsoft\Visual 47 C++ for Python\9.0\vcvarsall.bat 46 48 47 49 OpenMP for *msvc* requires the Microsoft vcomp90.dll library, which doesn't … … 89 91 from .generate import F16, F32, F64 90 92 93 # pylint: disable=unused-import 91 94 try: 92 95 from typing import Tuple, Callable, Any … … 95 98 except ImportError: 96 99 pass 100 # pylint: enable=unused-import 97 101 98 102 if "SAS_COMPILER" in os.environ: -
sasmodels/kernelpy.py
r8698a0d r2d81cfe 12 12 13 13 import numpy as np # type: ignore 14 from numpy import pi, sin, cos #type: ignore 15 16 from . import details 14 17 15 from .generate import F64 18 16 from .kernel import KernelModel, Kernel 19 17 18 # pylint: disable=unused-import 20 19 try: 21 20 from typing import Union, Callable … … 23 22 pass 24 23 else: 24 from . import details 25 25 DType = Union[None, str, np.dtype] 26 # pylint: enable=unused-import 26 27 27 28 class PyModel(KernelModel): … … 179 180 self.q_input = None 180 181 181 def _loops(parameters, form, form_volume, nq, call_details, values, cutoff): 182 # type: (np.ndarray, Callable[[], np.ndarray], Callable[[], float], int, details.CallDetails, np.ndarray, np.ndarray, float) -> None 182 def _loops(parameters, # type: np.ndarray 183 form, # type: Callable[[], np.ndarray] 184 form_volume, # type: Callable[[], float] 185 nq, # type: int 186 call_details, # type: details.CallDetails 187 values, # type: np.ndarray 188 cutoff # type: float 189 ): 190 # type: (...) -> None 183 191 ################################################################ 184 192 # # -
sasmodels/list_pars.py
r72be531 r2d81cfe 11 11 from __future__ import print_function 12 12 13 import sys14 13 import argparse 15 14 -
sasmodels/mixture.py
r0edb6c1 r2d81cfe 20 20 from .details import make_details 21 21 22 # pylint: disable=unused-import 22 23 try: 23 24 from typing import List 24 25 except ImportError: 25 26 pass 27 # pylint: enable=unused-import 26 28 27 29 def make_mixture_info(parts, operation='+'): … … 33 35 combined_pars = [] 34 36 35 model_num = 036 37 all_parts = copy(parts) 37 38 is_flat = False … … 89 90 used_prefixes.append(prefix) 90 91 prefix += '_' 91 92 92 93 if operation == '+': 93 94 # If model is a sum model, each constituent model gets its own scale parameter … … 105 106 # Concatenate sub_prefixes to form prefix for the scale 106 107 scale_prefix = ''.join(sub_prefixes) + '_' 107 scale = 108 description="model intensity for " + part.name)108 scale = Parameter(scale_prefix + 'scale', default=1.0, 109 description="model intensity for " + part.name) 109 110 combined_pars.append(scale) 110 111 for p in part.parameters.kernel_parameters: … … 179 180 # type: (ModelInfo, List[Kernel]) -> None 180 181 self.dim = kernels[0].dim 181 self.info = 182 self.info = model_info 182 183 self.kernels = kernels 183 184 self.dtype = self.kernels[0].dtype -
sasmodels/model_test.py
r20fe0cd r2d81cfe 63 63 from .modelinfo import expand_pars 64 64 65 # pylint: disable=unused-import 65 66 try: 66 67 from typing import List, Iterator, Callable … … 70 71 from .modelinfo import ParameterTable, ParameterSet, TestCondition, ModelInfo 71 72 from .kernel import KernelModel 73 # pylint: enable=unused-import 72 74 73 75 … … 211 213 if self.stash: 212 214 for test, target, actual in zip(tests, self.stash[0], results): 213 assert np.all(abs(target-actual) < 5e-5*abs(actual)),\ 214 "GPU/CPU comparison expected %s but got %s for %s"%(target, actual, test[0]) 215 assert np.all(abs(target-actual) < 5e-5*abs(actual)), \ 216 ("GPU/CPU comparison expected %s but got %s for %s" 217 % (target, actual, test[0])) 215 218 else: 216 219 self.stash.append(results) -
sasmodels/modelinfo.py
re65c3ba r2d81cfe 16 16 17 17 # Optional typing 18 # pylint: disable=unused-import 18 19 try: 19 20 from typing import Tuple, List, Union, Dict, Optional, Any, Callable, Sequence, Set … … 30 31 TestValue = Union[float, List[float]] 31 32 TestCondition = Tuple[ParameterSetUser, TestInput, TestValue] 33 # pylint: enable=unused-import 32 34 33 35 # If MAX_PD changes, need to change the loop macros in kernel_iq.c -
sasmodels/models/__init__.py
r306e354 r2d81cfe 2 2 1D Modeling for SAS 3 3 """ 4 -
sasmodels/models/_spherepy.py
rec45c4f r2d81cfe 1 1 r""" 2 For information about polarised and magnetic scattering, see 2 For information about polarised and magnetic scattering, see 3 3 the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 4 4 … … 104 104 dlow = d[low] 105 105 dlow2 = dlow ** 2 106 g[low] = sqrt(1 - dlow2 / 4.) * (1 + dlow2 / 8.) + dlow2 / 2.*(1 - dlow2 / 16.) * log(dlow / (2. + sqrt(4. - dlow2))) 106 g[low] = (sqrt(1 - dlow2/4.) * (1 + dlow2/8.) 107 + dlow2/2.*(1 - dlow2/16.) * log(dlow / (2. + sqrt(4. - dlow2)))) 107 108 return g 108 109 sesans.vectorized = True # sesans accepts an array of z values -
sasmodels/models/adsorbed_layer.py
r8f04da4 r2d81cfe 57 57 """ 58 58 59 import numpy as np 59 60 from numpy import inf, pi, exp, errstate 60 61 … … 100 101 # the remaining parameters can be randomly generated from zero to 101 102 # twice the default value as done by default in compare.py 102 import numpy as np103 103 pars = dict( 104 104 scale=1, -
sasmodels/models/barbell.py
r31df0c9 r2d81cfe 87 87 * **Last Reviewed by:** Richard Heenan **Date:** January 4, 2017 88 88 """ 89 90 import numpy as np 89 91 from numpy import inf, sin, cos, pi 90 92 … … 116 118 117 119 def random(): 118 import numpy as np119 120 # TODO: increase volume range once problem with bell radius is fixed 120 121 # The issue is that bell radii of more than about 200 fail at high q 121 V= 10**np.random.uniform(7, 9)122 bar_volume = 10**np.random.uniform(-4, -1)* V123 bell_volume = V- bar_volume122 volume = 10**np.random.uniform(7, 9) 123 bar_volume = 10**np.random.uniform(-4, -1)*volume 124 bell_volume = volume - bar_volume 124 125 bell_radius = (bell_volume/6)**0.3333 # approximate 125 126 min_bar = bar_volume/np.pi/bell_radius**2 … … 150 151 qx = q*cos(pi/6.0) 151 152 qy = q*sin(pi/6.0) 152 tests = [[{}, 0.075, 25.5691260532], 153 [{'theta':80., 'phi':10.}, (qx, qy), 3.04233067789], 154 ] 153 tests = [ 154 [{}, 0.075, 25.5691260532], 155 [{'theta':80., 'phi':10.}, (qx, qy), 3.04233067789], 156 ] 155 157 del qx, qy # not necessary to delete, but cleaner -
sasmodels/models/bcc_paracrystal.py
r1f159bd r2d81cfe 104 104 """ 105 105 106 import numpy as np 106 107 from numpy import inf, pi 107 108 … … 136 137 137 138 def random(): 138 import numpy as np139 139 # Define lattice spacing as a multiple of the particle radius 140 140 # using the formulat a = 4 r/sqrt(3). Systems which are ordered -
sasmodels/models/be_polyelectrolyte.py
r8f04da4 r2d81cfe 71 71 """ 72 72 73 import numpy as np 73 74 from numpy import inf, pi, sqrt 74 75 … … 140 141 141 142 def random(): 142 import numpy as np143 143 # TODO: review random be_polyelectrolyte model generation 144 144 pars = dict( -
sasmodels/models/binary_hard_sphere.py
r30b60d2 r2d81cfe 73 73 """ 74 74 75 import numpy as np 75 76 from numpy import inf 76 77 … … 111 112 112 113 def random(): 113 import numpy as np114 114 # TODO: binary_hard_sphere fails at low qr 115 115 radius_lg = 10**np.random.uniform(2, 4.7) … … 137 137 # NOTE: test results taken from values returned by SasView 3.1.2 138 138 tests = [[{}, 0.001, 25.8927262013]] 139 -
sasmodels/models/broad_peak.py
r0bdddc2 r2d81cfe 41 41 """ 42 42 43 import numpy as np 43 44 from numpy import inf, errstate 44 45 … … 95 96 96 97 def random(): 97 import numpy as np98 98 pars = dict( 99 99 scale=1, -
sasmodels/models/capped_cylinder.py
r31df0c9 r2d81cfe 89 89 * **Last Modified by:** Paul Butler **Date:** September 30, 2016 90 90 * **Last Reviewed by:** Richard Heenan **Date:** January 4, 2017 91 """ 91 92 92 """ 93 import numpy as np 93 94 from numpy import inf, sin, cos, pi 94 95 … … 137 138 138 139 def random(): 139 import numpy as np140 140 # TODO: increase volume range once problem with bell radius is fixed 141 141 # The issue is that bell radii of more than about 200 fail at high q 142 V= 10**np.random.uniform(7, 9)143 bar_volume = 10**np.random.uniform(-4, -1)* V144 bell_volume = V- bar_volume142 volume = 10**np.random.uniform(7, 9) 143 bar_volume = 10**np.random.uniform(-4, -1)*volume 144 bell_volume = volume - bar_volume 145 145 bell_radius = (bell_volume/6)**0.3333 # approximate 146 146 min_bar = bar_volume/np.pi/bell_radius**2 … … 171 171 qx = q*cos(pi/6.0) 172 172 qy = q*sin(pi/6.0) 173 tests = [[{}, 0.075, 26.0698570695], 174 [{'theta':80., 'phi':10.}, (qx, qy), 0.561811990502], 175 ] 173 tests = [ 174 [{}, 0.075, 26.0698570695], 175 [{'theta':80., 'phi':10.}, (qx, qy), 0.561811990502], 176 ] 176 177 del qx, qy # not necessary to delete, but cleaner -
sasmodels/models/core_multi_shell.py
r1511c37c r2d81cfe 46 46 * **Last Reviewed by:** Paul Kienzle **Date:** September 12, 2016 47 47 """ 48 49 50 51 48 from __future__ import division 52 49 … … 104 101 105 102 def random(): 106 import numpy as np107 103 num_shells = np.minimum(np.random.poisson(3)+1, 10) 108 104 total_radius = 10**np.random.uniform(1.7, 4) … … 162 158 thickness1_pd_n=10, 163 159 thickness2_pd_n=10, 164 160 ) -
sasmodels/models/core_shell_bicelle.py
r30b60d2 r2d81cfe 50 50 \begin{align*} 51 51 F(Q,\alpha) = &\bigg[ 52 (\rho_c - \rho_f) V_c \frac{2J_1(QRsin \alpha)}{QRsin\alpha}\frac{sin(QLcos\alpha/2)}{Q(L/2)cos\alpha} \\ 53 &+(\rho_f - \rho_r) V_{c+f} \frac{2J_1(QRsin\alpha)}{QRsin\alpha}\frac{sin(Q(L/2+t_f)cos\alpha)}{Q(L/2+t_f)cos\alpha} \\ 54 &+(\rho_r - \rho_s) V_t \frac{2J_1(Q(R+t_r)sin\alpha)}{Q(R+t_r)sin\alpha}\frac{sin(Q(L/2+t_f)cos\alpha)}{Q(L/2+t_f)cos\alpha} 52 (\rho_c - \rho_f) V_c 53 \frac{2J_1(QRsin \alpha)}{QRsin\alpha} 54 \frac{sin(QLcos\alpha/2)}{Q(L/2)cos\alpha} \\ 55 &+(\rho_f - \rho_r) V_{c+f} 56 \frac{2J_1(QRsin\alpha)}{QRsin\alpha} 57 \frac{sin(Q(L/2+t_f)cos\alpha)}{Q(L/2+t_f)cos\alpha} \\ 58 &+(\rho_r - \rho_s) V_t 59 \frac{2J_1(Q(R+t_r)sin\alpha)}{Q(R+t_r)sin\alpha} 60 \frac{sin(Q(L/2+t_f)cos\alpha)}{Q(L/2+t_f)cos\alpha} 55 61 \bigg] 56 62 \end{align*} … … 64 70 cylinders is then given by integrating over all possible $\theta$ and $\phi$. 65 71 66 For oriented bicelles the *theta*, and *phi* orientation parameters will appear when fitting 2D data,67 see the :ref:`cylinder` model for further information.72 For oriented bicelles the *theta*, and *phi* orientation parameters will appear 73 when fitting 2D data, see the :ref:`cylinder` model for further information. 68 74 Our implementation of the scattering kernel and the 1D scattering intensity 69 75 use the c-library from NIST. … … 92 98 """ 93 99 100 import numpy as np 94 101 from numpy import inf, sin, cos, pi 95 102 … … 149 156 150 157 def random(): 151 import numpy as np152 158 pars = dict( 153 159 radius=10**np.random.uniform(1.3, 3), … … 173 179 qx = q*cos(pi/6.0) 174 180 qy = q*sin(pi/6.0) 175 tests = [[{}, 0.05, 7.4883545957], 176 [{'theta':80., 'phi':10.}, (qx, qy), 2.81048892474 ] 177 ] 181 tests = [ 182 [{}, 0.05, 7.4883545957], 183 [{'theta':80., 'phi':10.}, (qx, qy), 2.81048892474] 184 ] 178 185 del qx, qy # not necessary to delete, but cleaner 179 -
sasmodels/models/core_shell_bicelle_elliptical.py
r30b60d2 r2d81cfe 7 7 of the core-shell bicelle model, but with an elliptical cylinder for the core. 8 8 Outer shells on the rims and flat ends may be of different thicknesses and 9 scattering length densities. The form factor is normalized by the total particle volume. 9 scattering length densities. The form factor is normalized by the total 10 particle volume. 10 11 11 12 … … 36 37 37 38 The form factor for the bicelle is calculated in cylindrical coordinates, where 38 $\alpha$ is the angle between the $Q$ vector and the cylinder axis, and $\psi$ is the angle39 for the ellipsoidal cross section core, to give:39 $\alpha$ is the angle between the $Q$ vector and the cylinder axis, and $\psi$ 40 is the angle for the ellipsoidal cross section core, to give: 40 41 41 42 .. math:: … … 44 45 F(Q,\alpha, \psi)^2 \cdot sin(\alpha) + \text{background} 45 46 46 where a numerical integration of $F(Q,\alpha, \psi)^2 \cdot sin(\alpha)$ is carried out over \alpha and \psi for: 47 where a numerical integration of $F(Q,\alpha, \psi)^2 \cdot sin(\alpha)$ 48 is carried out over \alpha and \psi for: 47 49 48 50 .. math:: … … 51 53 \begin{align*} 52 54 F(Q,\alpha,\psi) = &\bigg[ 53 (\rho_c - \rho_f) V_c \frac{2J_1(QR'sin \alpha)}{QR'sin\alpha}\frac{sin(QLcos\alpha/2)}{Q(L/2)cos\alpha} \\ 54 &+(\rho_f - \rho_r) V_{c+f} \frac{2J_1(QR'sin\alpha)}{QR'sin\alpha}\frac{sin(Q(L/2+t_f)cos\alpha)}{Q(L/2+t_f)cos\alpha} \\ 55 &+(\rho_r - \rho_s) V_t \frac{2J_1(Q(R'+t_r)sin\alpha)}{Q(R'+t_r)sin\alpha}\frac{sin(Q(L/2+t_f)cos\alpha)}{Q(L/2+t_f)cos\alpha} 55 (\rho_c - \rho_f) V_c 56 \frac{2J_1(QR'sin \alpha)}{QR'sin\alpha} 57 \frac{sin(QLcos\alpha/2)}{Q(L/2)cos\alpha} \\ 58 &+(\rho_f - \rho_r) V_{c+f} 59 \frac{2J_1(QR'sin\alpha)}{QR'sin\alpha} 60 \frac{sin(Q(L/2+t_f)cos\alpha)}{Q(L/2+t_f)cos\alpha} \\ 61 &+(\rho_r - \rho_s) V_t 62 \frac{2J_1(Q(R'+t_r)sin\alpha)}{Q(R'+t_r)sin\alpha} 63 \frac{sin(Q(L/2+t_f)cos\alpha)}{Q(L/2+t_f)cos\alpha} 56 64 \bigg] 57 65 \end{align*} … … 64 72 65 73 66 and $V_t = \pi.(R+t_r)(Xcore.R+t_r)^2.(L+2.t_f)$ is the total volume of the bicelle, 67 $V_c = \pi.Xcore.R^2.L$ the volume of the core, $V_{c+f} = \pi.Xcore.R^2.(L+2.t_f)$ 68 the volume of the core plus the volume of the faces, $R$ is the radius 69 of the core, $Xcore$ is the axial ratio of the core, $L$ the length of the core, 70 $t_f$ the thickness of the face, $t_r$ the thickness of the rim and $J_1$ the usual 71 first order bessel function. The core has radii $R$ and $Xcore.R$ so is circular, 72 as for the core_shell_bicelle model, for $Xcore$ =1. Note that you may need to 73 limit the range of $Xcore$, especially if using the Monte-Carlo algorithm, as 74 setting radius to $R/Xcore$ and axial ratio to $1/Xcore$ gives an equivalent solution! 74 and $V_t = \pi.(R+t_r)(Xcore.R+t_r)^2.(L+2.t_f)$ is the total volume of 75 the bicelle, $V_c = \pi.Xcore.R^2.L$ the volume of the core, 76 $V_{c+f} = \pi.Xcore.R^2.(L+2.t_f)$ the volume of the core plus the volume 77 of the faces, $R$ is the radius of the core, $Xcore$ is the axial ratio of 78 the core, $L$ the length of the core, $t_f$ the thickness of the face, $t_r$ 79 the thickness of the rim and $J_1$ the usual first order bessel function. 80 The core has radii $R$ and $Xcore.R$ so is circular, as for the 81 core_shell_bicelle model, for $Xcore$ =1. Note that you may need to 82 limit the range of $Xcore$, especially if using the Monte-Carlo algorithm, 83 as setting radius to $R/Xcore$ and axial ratio to $1/Xcore$ gives an 84 equivalent solution! 75 85 76 86 The output of the 1D scattering intensity function for randomly oriented 77 87 bicelles is then given by integrating over all possible $\alpha$ and $\psi$. 78 88 79 For oriented bicelles the *theta*, *phi* and *psi* orientation parameters will appear when fitting 2D data, 80 see the :ref:`elliptical-cylinder` model for further information. 89 For oriented bicelles the *theta*, *phi* and *psi* orientation parameters will 90 appear when fitting 2D data, see the :ref:`elliptical-cylinder` model 91 for further information. 81 92 82 93 … … 100 111 """ 101 112 113 import numpy as np 102 114 from numpy import inf, sin, cos, pi 103 115 … … 138 150 139 151 def random(): 140 import numpy as np141 152 outer_major = 10**np.random.uniform(1, 4.7) 142 153 outer_minor = 10**np.random.uniform(1, 4.7) … … 170 181 171 182 tests = [ 172 [{'radius': 30.0, 'x_core': 3.0, 'thick_rim':8.0, 'thick_face':14.0, 'length':50.0}, 'ER', 1], 173 [{'radius': 30.0, 'x_core': 3.0, 'thick_rim':8.0, 'thick_face':14.0, 'length':50.0}, 'VR', 1], 183 [{'radius': 30.0, 'x_core': 3.0, 184 'thick_rim': 8.0, 'thick_face': 14.0, 'length': 50.0}, 'ER', 1], 185 [{'radius': 30.0, 'x_core': 3.0, 186 'thick_rim': 8.0, 'thick_face': 14.0, 'length': 50.0}, 'VR', 1], 174 187 175 [{'radius': 30.0, 'x_core': 3.0, 'thick_rim':8.0, 'thick_face':14.0, 'length':50.0, 176 'sld_core':4.0, 'sld_face':7.0, 'sld_rim':1.0, 'sld_solvent':6.0, 'background':0.0}, 177 0.015, 286.540286], 178 # [{'theta':80., 'phi':10.}, (qx, qy), 7.88866563001 ], 179 ] 188 [{'radius': 30.0, 'x_core': 3.0, 189 'thick_rim': 8.0, 'thick_face': 14.0, 'length': 50.0, 190 'sld_core': 4.0, 'sld_face': 7.0, 'sld_rim': 1.0, 191 'sld_solvent': 6.0, 'background': 0.0}, 192 0.015, 286.540286], 193 #[{'theta':80., 'phi':10.}, (qx, qy), 7.88866563001], 194 ] 180 195 181 196 del qx, qy # not necessary to delete, but cleaner -
sasmodels/models/core_shell_cylinder.py
r9f6823b r2d81cfe 73 73 """ 74 74 75 import numpy as np 75 76 from numpy import pi, inf, sin, cos 76 77 … … 119 120 ["theta", "degrees", 60, [-360, 360], "orientation", 120 121 "cylinder axis to beam angle"], 121 ["phi", "degrees", 122 ["phi", "degrees", 60, [-360, 360], "orientation", 122 123 "rotation about beam"], 123 124 ] … … 143 144 144 145 def random(): 145 import numpy as np146 146 outer_radius = 10**np.random.uniform(1, 4.7) 147 147 # Use a distribution with a preference for thin shell or thin core … … 170 170 qx = q*cos(pi/6.0) 171 171 qy = q*sin(pi/6.0) 172 tests = [[{}, 0.075, 10.8552692237], 173 [{}, (qx, qy), 0.444618752741 ], 174 ] 172 tests = [ 173 [{}, 0.075, 10.8552692237], 174 [{}, (qx, qy), 0.444618752741], 175 ] 175 176 del qx, qy # not necessary to delete, but cleaner -
sasmodels/models/core_shell_ellipsoid.py
r8db25bf r2d81cfe 26 26 ellipsoid is large (ie, if $X << 1$ or $X >> 1$ ), when the $S(q)$ 27 27 - which assumes spheres - will not in any case be valid. Generating a 28 custom product model will enable separate effective volume fraction and effective29 radius in the $S(q)$.28 custom product model will enable separate effective volume fraction and 29 effective radius in the $S(q)$. 30 30 31 31 If SAS data are in absolute units, and the SLDs are correct, then scale should 32 32 be the total volume fraction of the "outer particle". When $S(q)$ is introduced 33 this moves to the $S(q)$ volume fraction, and scale should then be 1.0, 34 orcontain some other units conversion factor (for example, if you have SAXS data).35 36 The calculation of intensity follows that for the solid ellipsoid, but with separate37 terms for the core-shell and shell-solvent boundaries.33 this moves to the $S(q)$ volume fraction, and scale should then be 1.0, or 34 contain some other units conversion factor (for example, if you have SAXS data). 35 36 The calculation of intensity follows that for the solid ellipsoid, but 37 with separate terms for the core-shell and shell-solvent boundaries. 38 38 39 39 .. math:: … … 48 48 \begin{align*} 49 49 F(q,\alpha) = &f(q,radius\_equat\_core,radius\_equat\_core.x\_core,\alpha) \\ 50 &+ f(q,radius\_equat\_core + thick\_shell,radius\_equat\_core.x\_core + thick\_shell.x\_polar\_shell,\alpha) 50 &+ f(q,radius\_equat\_core + thick\_shell, 51 radius\_equat\_core.x\_core + thick\_shell.x\_polar\_shell,\alpha) 51 52 \end{align*} 52 53 … … 68 69 69 70 $\alpha$ is the angle between the axis of the ellipsoid and $\vec q$, 70 $V = (4/3)\pi R_pR_e^2$ is the volume of the ellipsoid , $R_p$ is the polar radius along the 71 rotational axis of the ellipsoid, $R_e$ is the equatorial radius perpendicular 72 to the rotational axis of the ellipsoid and $\Delta \rho$ (contrast) is the 73 scattering length density difference, either $(sld\_core - sld\_shell)$ or $(sld\_shell - sld\_solvent)$. 71 $V = (4/3)\pi R_pR_e^2$ is the volume of the ellipsoid , $R_p$ is the 72 polar radius along the rotational axis of the ellipsoid, $R_e$ is the 73 equatorial radius perpendicular to the rotational axis of the ellipsoid 74 and $\Delta \rho$ (contrast) is the scattering length density difference, 75 either $(sld\_core - sld\_shell)$ or $(sld\_shell - sld\_solvent)$. 74 76 75 77 For randomly oriented particles: … … 79 81 F^2(q)=\int_{0}^{\pi/2}{F^2(q,\alpha)\sin(\alpha)d\alpha} 80 82 81 For oriented ellipsoids the *theta*, *phi* and *psi* orientation parameters will appear when fitting 2D data, 82 see the :ref:`elliptical-cylinder` model for further information. 83 For oriented ellipsoids the *theta*, *phi* and *psi* orientation parameters 84 will appear when fitting 2D data, see the :ref:`elliptical-cylinder` model 85 for further information. 83 86 84 87 References … … 94 97 * **Last Modified by:** Richard Heenan (reparametrised model) **Date:** 2015 95 98 * **Last Reviewed by:** Richard Heenan **Date:** October 6, 2016 96 97 99 """ 98 100 101 import numpy as np 99 102 from numpy import inf, sin, cos, pi 100 103 … … 153 156 154 157 def random(): 155 import numpy as np 156 V = 10**np.random.uniform(5, 12) 158 volume = 10**np.random.uniform(5, 12) 157 159 outer_polar = 10**np.random.uniform(1.3, 4) 158 outer_equatorial = np.sqrt( V/outer_polar) # ignore 4/3 pi160 outer_equatorial = np.sqrt(volume/outer_polar) # ignore 4/3 pi 159 161 # Use a distribution with a preference for thin shell or thin core 160 162 # Avoid core,shell radii < 1 … … 180 182 # 11Jan2017 RKH sorted tests after redefinition of angles 181 183 tests = [ 182 184 # Accuracy tests based on content in test/utest_coreshellellipsoidXTmodel.py 183 185 [{'radius_equat_core': 200.0, 184 186 'x_core': 0.1, … … 206 208 }, 0.01, 8688.53], 207 209 208 # 2D tests209 [{'background': 0.001,210 'theta': 90.0,211 'phi': 0.0,210 # 2D tests 211 [{'background': 0.001, 212 'theta': 90.0, 213 'phi': 0.0, 212 214 }, (0.4, 0.5), 0.00690673], 213 215 214 [{'radius_equat_core': 20.0,216 [{'radius_equat_core': 20.0, 215 217 'x_core': 200.0, 216 218 'thick_shell': 54.0, … … 224 226 'phi': 0.0, 225 227 }, (qx, qy), 0.01000025], 226 228 ] -
sasmodels/models/core_shell_parallelepiped.py
r8c7d5d5 r2d81cfe 5 5 Calculates the form factor for a rectangular solid with a core-shell structure. 6 6 The thickness and the scattering length density of the shell or 7 "rim" can be different on each (pair) of faces. However at this time 8 the 1D calculation does **NOT** actually calculate a c face rim despite the presence of 9 the parameter. Some other aspects of the 1D calculation may be wrong.7 "rim" can be different on each (pair) of faces. However at this time the 1D 8 calculation does **NOT** actually calculate a c face rim despite the presence 9 of the parameter. Some other aspects of the 1D calculation may be wrong. 10 10 11 11 .. note:: … … 51 51 52 52 F_{a}(Q,\alpha,\beta)= 53 \left[\frac{\sin(\tfrac{1}{2}Q(L_A+2t_A)\sin\alpha \sin\beta)}{\tfrac{1}{2}Q(L_A+2t_A)\sin\alpha\sin\beta} 54 - \frac{\sin(\tfrac{1}{2}QL_A\sin\alpha \sin\beta)}{\tfrac{1}{2}QL_A\sin\alpha \sin\beta} \right] 55 \left[\frac{\sin(\tfrac{1}{2}QL_B\sin\alpha \sin\beta)}{\tfrac{1}{2}QL_B\sin\alpha \sin\beta} \right] 56 \left[\frac{\sin(\tfrac{1}{2}QL_C\sin\alpha \sin\beta)}{\tfrac{1}{2}QL_C\sin\alpha \sin\beta} \right] 53 \left[\frac{\sin(\tfrac{1}{2}Q(L_A+2t_A)\sin\alpha \sin\beta) 54 }{\tfrac{1}{2}Q(L_A+2t_A)\sin\alpha\sin\beta} 55 - \frac{\sin(\tfrac{1}{2}QL_A\sin\alpha \sin\beta) 56 }{\tfrac{1}{2}QL_A\sin\alpha \sin\beta} \right] 57 \left[\frac{\sin(\tfrac{1}{2}QL_B\sin\alpha \sin\beta) 58 }{\tfrac{1}{2}QL_B\sin\alpha \sin\beta} \right] 59 \left[\frac{\sin(\tfrac{1}{2}QL_C\sin\alpha \sin\beta) 60 }{\tfrac{1}{2}QL_C\sin\alpha \sin\beta} \right] 57 61 58 62 .. note:: … … 94 98 95 99 Definition of the angles for oriented core-shell parallelepipeds. 96 Note that rotation $\theta$, initially in the $xz$ plane, is carried out first, then 97 rotation $\phi$ about the $z$ axis, finally rotation $\Psi$ is now around the axis of the cylinder. 98 The neutron or X-ray beam is along the $z$ axis. 100 Note that rotation $\theta$, initially in the $xz$ plane, is carried 101 out first, then rotation $\phi$ about the $z$ axis, finally rotation 102 $\Psi$ is now around the axis of the cylinder. The neutron or X-ray 103 beam is along the $z$ axis. 99 104 100 105 .. figure:: img/parallelepiped_angle_projection.png … … 182 187 183 188 def random(): 184 import numpy as np185 189 outer = 10**np.random.uniform(1, 4.7, size=3) 186 190 thick = np.random.beta(0.5, 0.5, size=3)*(outer-2) + 1 … … 216 220 qx, qy = 0.2 * cos(pi/6.), 0.2 * sin(pi/6.) 217 221 tests = [[{}, 0.2, 0.533149288477], 218 [{}, [0.2], [0.533149288477]],219 [{'theta':10.0, 'phi':20.0}, (qx, qy), 0.0853299803222],220 [{'theta':10.0, 'phi':20.0}, [(qx, qy)], [0.0853299803222]],222 [{}, [0.2], [0.533149288477]], 223 [{'theta':10.0, 'phi':20.0}, (qx, qy), 0.0853299803222], 224 [{'theta':10.0, 'phi':20.0}, [(qx, qy)], [0.0853299803222]], 221 225 ] 222 226 del qx, qy # not necessary to delete, but cleaner -
sasmodels/models/core_shell_sphere.py
r9f6823b r2d81cfe 52 52 """ 53 53 54 import numpy as np 54 55 from numpy import pi, inf 55 56 … … 100 101 101 102 def random(): 102 import numpy as np103 103 outer_radius = 10**np.random.uniform(1.3, 4.3) 104 104 # Use a distribution with a preference for thin shell or thin core -
sasmodels/models/cylinder.py
reda8b30 r2d81cfe 64 64 65 65 Angles $\theta$ and $\phi$ orient the cylinder relative 66 to the beam line coordinates, where the beam is along the $z$ axis. Rotation $\theta$, initially 66 to the beam line coordinates, where the beam is along the $z$ axis. Rotation $\theta$, initially 67 67 in the $xz$ plane, is carried out first, then rotation $\phi$ about the $z$ axis. Orientation distributions 68 68 are described as rotations about two perpendicular axes $\delta_1$ and $\delta_2$ … … 133 133 ["theta", "degrees", 60, [-360, 360], "orientation", 134 134 "cylinder axis to beam angle"], 135 ["phi", "degrees", 135 ["phi", "degrees", 60, [-360, 360], "orientation", 136 136 "rotation about beam"], 137 137 ] 138 138 139 source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", 139 source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "cylinder.c"] 140 140 141 141 def ER(radius, length): … … 147 147 148 148 def random(): 149 import numpy as np 150 V = 10**np.random.uniform(5, 12) 151 length = 10**np.random.uniform(-2, 2)*V**0.333 152 radius = np.sqrt(V/length/np.pi) 149 volume = 10**np.random.uniform(5, 12) 150 length = 10**np.random.uniform(-2, 2)*volume**0.333 151 radius = np.sqrt(volume/length/np.pi) 153 152 pars = dict( 154 153 #scale=1, … … 172 171 qx, qy = 0.2 * np.cos(2.5), 0.2 * np.sin(2.5) 173 172 # After redefinition of angles, find new tests values. Was 10 10 in old coords 174 tests = [[{}, 0.2, 0.042761386790780453], 175 [{}, [0.2], [0.042761386790780453]], 176 # new coords 177 [{'theta':80.1534480601659, 'phi':10.1510817110481}, (qx, qy), 0.03514647218513852], 178 [{'theta':80.1534480601659, 'phi':10.1510817110481}, [(qx, qy)], [0.03514647218513852]], 179 # old coords [{'theta':10.0, 'phi':10.0}, (qx, qy), 0.03514647218513852], 180 # [{'theta':10.0, 'phi':10.0}, [(qx, qy)], [0.03514647218513852]], 181 ] 173 tests = [ 174 [{}, 0.2, 0.042761386790780453], 175 [{}, [0.2], [0.042761386790780453]], 176 # new coords 177 [{'theta':80.1534480601659, 'phi':10.1510817110481}, (qx, qy), 0.03514647218513852], 178 [{'theta':80.1534480601659, 'phi':10.1510817110481}, [(qx, qy)], [0.03514647218513852]], 179 # old coords 180 #[{'theta':10.0, 'phi':10.0}, (qx, qy), 0.03514647218513852], 181 #[{'theta':10.0, 'phi':10.0}, [(qx, qy)], [0.03514647218513852]], 182 ] 182 183 del qx, qy # not necessary to delete, but cleaner 183 184 # ADDED by: RKH ON: 18Mar2016 renamed sld's etc -
sasmodels/models/dab.py
r404ebbd r2d81cfe 38 38 39 39 *2013/09/09 - Description reviewed by King, S and Parker, P.* 40 41 40 """ 42 41 42 import numpy as np 43 43 from numpy import inf 44 44 … … 66 66 67 67 def random(): 68 import numpy as np69 68 pars = dict( 70 69 scale=10**np.random.uniform(1, 4), -
sasmodels/models/ellipsoid.py
r110f69c r2d81cfe 123 123 from __future__ import division 124 124 125 import numpy as np 125 126 from numpy import inf, sin, cos, pi 126 127 … … 163 164 164 165 def ER(radius_polar, radius_equatorial): 165 import numpy as np166 166 # see equation (26) in A.Isihara, J.Chem.Phys. 18(1950)1446-1449 167 167 ee = np.empty_like(radius_polar) … … 185 185 186 186 def random(): 187 import numpy as np 188 V = 10**np.random.uniform(5, 12) 187 volume = 10**np.random.uniform(5, 12) 189 188 radius_polar = 10**np.random.uniform(1.3, 4) 190 radius_equatorial = np.sqrt( V/radius_polar) # ignore 4/3 pi189 radius_equatorial = np.sqrt(volume/radius_polar) # ignore 4/3 pi 191 190 pars = dict( 192 191 #background=0, sld=0, sld_solvent=1, … … 208 207 qx = q*cos(pi/6.0) 209 208 qy = q*sin(pi/6.0) 210 tests = [[{}, 0.05, 54.8525847025], 211 [{'theta':80., 'phi':10.}, (qx, qy), 1.74134670026], 212 ] 209 tests = [ 210 [{}, 0.05, 54.8525847025], 211 [{'theta':80., 'phi':10.}, (qx, qy), 1.74134670026], 212 ] 213 213 del qx, qy # not necessary to delete, but cleaner -
sasmodels/models/elliptical_cylinder.py
reda8b30 r2d81cfe 43 43 P(q) = \text{scale} <F^2> / V 44 44 45 For 2d data the orientation of the particle is required, described using a different set 46 of angles as in the diagrams below, for further details of the calculation and angular 45 For 2d data the orientation of the particle is required, described using a different set 46 of angles as in the diagrams below, for further details of the calculation and angular 47 47 dispersions see :ref:`orientation` . 48 48 … … 95 95 * **Last Modified by:** 96 96 * **Last Reviewed by:** Richard Heenan - corrected equation in docs **Date:** December 21, 2016 97 98 97 """ 99 98 99 import numpy as np 100 100 from numpy import pi, inf, sqrt, sin, cos 101 101 … … 141 141 142 142 def random(): 143 import numpy as np144 143 # V = pi * radius_major * radius_minor * length; 145 V= 10**np.random.uniform(3, 9)144 volume = 10**np.random.uniform(3, 9) 146 145 length = 10**np.random.uniform(1, 3) 147 146 axis_ratio = 10**np.random.uniform(0, 2) 148 radius_minor = np.sqrt( V/length/axis_ratio)149 Vf= 10**np.random.uniform(-4, -2)147 radius_minor = np.sqrt(volume/length/axis_ratio) 148 volfrac = 10**np.random.uniform(-4, -2) 150 149 pars = dict( 151 150 #background=0, sld=0, sld_solvent=1, 152 scale=1e9* Vf/V,151 scale=1e9*volfrac/volume, 153 152 length=length, 154 153 radius_minor=radius_minor, … … 170 169 'sld_solvent':1.0, 'background':0.0}, 171 170 0.001, 675.504402], 172 #[{'theta':80., 'phi':10.}, (qx, qy), 7.88866563001 ],171 #[{'theta':80., 'phi':10.}, (qx, qy), 7.88866563001 ], 173 172 ] -
sasmodels/models/fcc_paracrystal.py
r1f159bd r2d81cfe 95 95 """ 96 96 97 import numpy as np 97 98 from numpy import inf, pi 98 99 … … 124 125 125 126 def random(): 126 import numpy as np127 127 # copied from bcc_paracrystal 128 128 radius = 10**np.random.uniform(1.3, 4) -
sasmodels/models/flexible_cylinder.py
r2573fa1 r2d81cfe 60 60 22(15) 2006 6539-6548 61 61 """ 62 63 import numpy as np 62 64 from numpy import inf 63 65 … … 87 89 88 90 def random(): 89 import numpy as np90 91 length = 10**np.random.uniform(2, 6) 91 92 radius = 10**np.random.uniform(1, 3) -
sasmodels/models/flexible_cylinder_elliptical.py
r31df0c9 r2d81cfe 83 83 22(15) 2006 6539-6548 84 84 """ 85 86 import numpy as np 85 87 from numpy import inf 86 88 … … 113 115 114 116 def random(): 115 import numpy as np116 117 length = 10**np.random.uniform(2, 6) 117 118 radius = 10**np.random.uniform(1, 3) … … 164 165 }, 1.0, 0.0016338264790] 165 166 ] 166 -
sasmodels/models/fractal.py
r1511c37c r2d81cfe 53 53 * **Last Modified by:** Paul Butler **Date:** March 12, 2017 54 54 * **Last Reviewed by:** Paul Butler **Date:** March 12, 2017 55 56 55 """ 57 56 from __future__ import division 58 57 58 import numpy as np 59 59 from numpy import inf 60 60 … … 100 100 101 101 def random(): 102 import numpy as np103 102 radius = 10**np.random.uniform(0.7, 4) 104 103 #radius = 5 -
sasmodels/models/fractal_core_shell.py
rca04add r2d81cfe 57 57 * **Last Modified by:** Paul Butler and Paul Kienzle **on:** November 27, 2016 58 58 * **Last Reviewed by:** Paul Butler and Paul Kienzle **on:** November 27, 2016 59 60 59 """ 61 60 61 import numpy as np 62 62 from numpy import pi, inf 63 63 … … 98 98 99 99 def random(): 100 import numpy as np101 100 outer_radius = 10**np.random.uniform(0.7, 4) 102 101 # Use a distribution with a preference for thin shell or thin core -
sasmodels/models/fuzzy_sphere.py
r31df0c9 r2d81cfe 55 55 """ 56 56 57 import numpy as np 57 58 from numpy import inf 58 59 … … 106 107 107 108 def random(): 108 import numpy as np109 109 radius = 10**np.random.uniform(1, 4.7) 110 110 fuzziness = 10**np.random.uniform(-2, -0.5)*radius # 1% to 31% fuzziness -
sasmodels/models/gauss_lorentz_gel.py
r48462b0 r2d81cfe 34 34 G Evmenenko, E Theunissen, K Mortensen, H Reynaers, *Polymer*, 35 35 42 (2001) 2907-2913 36 37 36 """ 38 37 38 import numpy as np 39 39 from numpy import inf, exp 40 40 … … 89 89 90 90 def random(): 91 import numpy as np92 91 gauss_scale = 10**np.random.uniform(1, 3) 93 92 lorentz_scale = 10**np.random.uniform(1, 3) -
sasmodels/models/gaussian_peak.py
r48462b0 r2d81cfe 28 28 """ 29 29 30 import numpy as np 30 31 from numpy import inf 31 32 … … 52 53 53 54 def random(): 54 import numpy as np55 55 peak_pos = 10**np.random.uniform(-3, -1) 56 56 sigma = 10**np.random.uniform(-1.3, -0.3)*peak_pos -
sasmodels/models/gel_fit.py
r48462b0 r2d81cfe 42 42 Simon Mallam, Ferenc Horkay, Anne-Marie Hecht, Adrian R Rennie, Erik Geissler, 43 43 *Macromolecules* 1991, 24, 543-548 44 45 44 """ 46 45 46 import numpy as np 47 47 from numpy import inf 48 48 … … 72 72 73 73 def random(): 74 import numpy as np75 74 guinier_scale = 10**np.random.uniform(1, 3) 76 75 lorentz_scale = 10**np.random.uniform(1, 3) -
sasmodels/models/guinier.py
r48462b0 r2d81cfe 27 27 """ 28 28 29 import numpy as np 29 30 from numpy import inf 30 31 … … 50 51 51 52 def random(): 52 import numpy as np53 53 scale = 10**np.random.uniform(1, 4) 54 54 # Note: compare.py has Rg cutoff of 1e-30 at q=1 for guinier, so use that -
sasmodels/models/guinier_porod.py
r48462b0 r2d81cfe 63 63 64 64 B Hammouda, *Analysis of the Beaucage model, J. Appl. Cryst.*, (2010), 43, 1474-1478 65 66 65 """ 67 66 67 import numpy as np 68 68 from numpy import inf, sqrt, exp, errstate 69 69 … … 115 115 116 116 def random(): 117 import numpy as np118 117 rg = 10**np.random.uniform(1, 5) 119 118 s = np.random.uniform(0, 3) -
sasmodels/models/hardsphere.py
r8f04da4 r2d81cfe 42 42 """ 43 43 44 import numpy as np 44 45 from numpy import inf 45 46 … … 77 78 // these are c compiler instructions, can also put normal code inside the "if else" structure 78 79 #if FLOAT_SIZE > 4 79 // double precision orig had 0.2, don't call the variable cutoff as PAK already has one called that! Must use UPPERCASE name please. 80 // 0.05 better, 0.1 OK 80 // double precision 81 // orig had 0.2, don't call the variable cutoff as PAK already has one called that! 82 // Must use UPPERCASE name please. 83 // 0.05 better, 0.1 OK 81 84 #define CUTOFFHS 0.05 82 85 #else … … 90 93 return(HARDSPH); 91 94 } 92 // removing use of pow(xxx,2) and rearranging the calcs of A, B & G cut ~40% off execution time ( 0.5 to 0.3 msec) 95 // removing use of pow(xxx,2) and rearranging the calcs 96 // of A, B & G cut ~40% off execution time ( 0.5 to 0.3 msec) 93 97 X = 1.0/( 1.0 -volfraction); 94 98 D= X*X; … … 110 114 if(X < CUTOFFHS) { 111 115 // RKH Feb 2016, use Taylor series expansion for small X 112 // else no obvious way to rearrange the equations to avoid needing a very high number of significant figures. 113 // Series expansion found using Mathematica software. Numerical test in .xls showed terms to X^2 are sufficient 116 // else no obvious way to rearrange the equations to avoid 117 // needing a very high number of significant figures. 118 // Series expansion found using Mathematica software. Numerical test 119 // in .xls showed terms to X^2 are sufficient 114 120 // for 5 or 6 significant figures, but I put the X^4 one in anyway 115 121 //FF = 8*A +6*B + 4*G - (0.8*A +2.0*B/3.0 +0.5*G)*X2 +(A/35. +B/40. +G/50.)*X4; … … 130 136 SINCOS(X,S,C); 131 137 132 // RKH Feb 2016, use version FISH code as is better than original sasview one at small Q in single precision, and more than twice as fast in double. 138 // RKH Feb 2016, use version FISH code as is better than original sasview one 139 // at small Q in single precision, and more than twice as fast in double. 133 140 //FF=A*(S-X*C)/X + B*(2.*X*S -(X2-2.)*C -2.)/X2 + G*( (4.*X2*X -24.*X)*S -(X4 -12.*X2 +24.)*C +24. )/X4; 134 141 // refactoring the polynomial here & above makes it slightly faster … … 154 161 155 162 def random(): 156 import numpy as np157 163 pars = dict( 158 164 scale=1, background=0, … … 167 173 demo = dict(radius_effective=200, volfraction=0.2, 168 174 radius_effective_pd=0.1, radius_effective_pd_n=40) 169 # Q=0.001 is in the Taylor series, low Q part, so add Q=0.1, assuming double precision sasview is correct 175 # Q=0.001 is in the Taylor series, low Q part, so add Q=0.1, 176 # assuming double precision sasview is correct 170 177 tests = [ 171 [ {'scale': 1.0, 'background' : 0.0, 'radius_effective' : 50.0, 172 'volfraction' : 0.2, 'radius_effective_pd' : 0}, 173 [0.001,0.1], [0.209128,0.930587]], 174 ] 175 # ADDED by: RKH ON: 16Mar2016 using equations from FISH as better than orig sasview, see notes above. Added Taylor expansions at small Q, 178 [{'scale': 1.0, 'background' : 0.0, 'radius_effective' : 50.0, 179 'volfraction' : 0.2, 'radius_effective_pd' : 0}, 180 [0.001, 0.1], [0.209128, 0.930587]], 181 ] 182 # ADDED by: RKH ON: 16Mar2016 using equations from FISH as better than 183 # orig sasview, see notes above. Added Taylor expansions at small Q. -
sasmodels/models/hayter_msa.py
r8f04da4 r2d81cfe 41 41 J P Hansen and J B Hayter, *Molecular Physics*, 46 (1982) 651-656 42 42 """ 43 44 import numpy as np 43 45 from numpy import inf 44 46 … … 91 93 92 94 def random(): 93 import numpy as np94 95 # TODO: too many failures for random hayter_msa parameters 95 96 pars = dict( -
sasmodels/models/hollow_cylinder.py
r8f04da4 r2d81cfe 38 38 for structure factor $S(q)$ when $P(q) \cdot S(q)$ is applied. 39 39 40 In the parameters,the *radius* is $R_\text{core}$ while *thickness* is $R_\text{outer} - R_\text{core}$. 40 In the parameters,the *radius* is $R_\text{core}$ while *thickness* 41 is $R_\text{outer} - R_\text{core}$. 41 42 42 43 To provide easy access to the orientation of the core-shell cylinder, we define … … 57 58 (reparametrised to use thickness, not outer radius) 58 59 * **Last Reviewed by:** Richard Heenan **Date:** October 06, 2016 59 60 60 """ 61 61 62 import numpy as np 62 63 from numpy import pi, inf, sin, cos 63 64 … … 122 123 123 124 def random(): 124 import numpy as np125 125 length = 10**np.random.uniform(1, 4.7) 126 126 outer_radius = 10**np.random.uniform(1, 4.7) … … 153 153 [{}, 'VR', 1.8], 154 154 [{}, 0.001, 1756.76], 155 [{}, (qx, qy), 2.36885476192 156 155 [{}, (qx, qy), 2.36885476192], 156 ] 157 157 del qx, qy # not necessary to delete, but cleaner -
sasmodels/models/hollow_rectangular_prism.py
r30b60d2 r2d81cfe 80 80 81 81 R Nayuk and K Huber, *Z. Phys. Chem.*, 226 (2012) 837-854 82 83 82 """ 84 83 84 import numpy as np 85 85 from numpy import pi, inf, sqrt 86 86 … … 147 147 148 148 def random(): 149 import numpy as np150 149 a, b, c = 10**np.random.uniform(1, 4.7, size=3) 151 150 # Thickness is limited to 1/2 the smallest dimension … … 175 174 [{}, [0.2], [0.76687283098]], 176 175 ] 177 -
sasmodels/models/hollow_rectangular_prism_thin_walls.py
r31df0c9 r2d81cfe 74 74 75 75 R Nayuk and K Huber, *Z. Phys. Chem.*, 226 (2012) 837-854 76 77 76 """ 78 77 78 import numpy as np 79 79 from numpy import pi, inf, sqrt 80 80 … … 128 128 129 129 def random(): 130 import numpy as np131 130 a, b, c = 10**np.random.uniform(1, 4.7, size=3) 132 131 pars = dict( … … 149 148 [{}, [0.2], [0.837719188592]], 150 149 ] 151 152 -
sasmodels/models/lamellar.py
r1511c37c r2d81cfe 43 43 44 44 also in J. Phys. Chem. B, 105, (2001) 11081-11088 45 46 47 45 """ 48 46 47 import numpy as np 49 48 from numpy import inf 50 49 … … 90 89 91 90 def random(): 92 import numpy as np93 91 thickness = 10**np.random.uniform(1, 4) 94 92 pars = dict( … … 104 102 thickness=40, 105 103 thickness_pd=0.2, thickness_pd_n=40) 104 # [(qx1, qy1), (qx2, qy2), ...], [I(qx1,qy1), I(qx2,qy2), ...]], 106 105 tests = [ 107 [{'scale': 1.0, 'background': 0.0, 'thickness': 50.0,108 109 110 111 # ADDED by: converted by PAK? (or RKH?) ON: 16Mar2016 - RKH adding unit tests from sasview to early 2015 conversion112 # [(qx1, qy1), (qx2, qy2), ...], [I(qx1,qy1), I(qx2,qy2), ...]],106 [{'scale': 1.0, 'background': 0.0, 'thickness': 50.0, 107 'sld': 1.0, 'sld_solvent': 6.3, 'thickness_pd': 0.0}, 108 [0.001], [882289.54309]] 109 ] 110 # ADDED by: converted by PAK? (or RKH?) 111 # ON: 16Mar2016 - RKH adding unit tests from sasview to early 2015 conversion -
sasmodels/models/lamellar_hg.py
r1511c37c r2d81cfe 48 48 """ 49 49 50 import numpy as np 50 51 from numpy import inf 51 52 … … 99 100 100 101 def random(): 101 import numpy as np102 102 thickness = 10**np.random.uniform(1, 4) 103 103 length_head = thickness * np.random.uniform(0, 1) -
sasmodels/models/lamellar_hg_stack_caille.py
r1511c37c r2d81cfe 73 73 also in J. Phys. Chem. B, 105, (2001) 11081-11088 74 74 """ 75 76 import numpy as np 75 77 from numpy import inf 76 78 … … 124 126 125 127 def random(): 126 import numpy as np127 128 total_thickness = 10**np.random.uniform(2, 4.7) 128 129 Nlayers = np.random.randint(2, 200) -
sasmodels/models/lamellar_stack_caille.py
r1511c37c r2d81cfe 68 68 also in J. Phys. Chem. B, 105, (2001) 11081-11088 69 69 """ 70 71 import numpy as np 70 72 from numpy import inf 71 73 … … 99 101 100 102 def random(): 101 import numpy as np102 103 total_thickness = 10**np.random.uniform(2, 4.7) 103 104 Nlayers = np.random.randint(2, 200) -
sasmodels/models/lamellar_stack_paracrystal.py
r8f04da4 r2d81cfe 90 90 M Bergstrom, J S Pedersen, P Schurtenberger, S U Egelhaaf, 91 91 *J. Phys. Chem. B*, 103 (1999) 9888-9897 92 93 92 """ 94 93 94 import numpy as np 95 95 from numpy import inf 96 96 … … 133 133 134 134 def random(): 135 import numpy as np136 135 total_thickness = 10**np.random.uniform(2, 4.7) 137 136 Nlayers = np.random.randint(2, 200) … … 158 157 # 159 158 tests = [ 160 [{'scale': 1.0, 'background': 0.0, 'thickness': 33., 'Nlayers': 20.0,159 [{'scale': 1.0, 'background': 0.0, 'thickness': 33., 'Nlayers': 20.0, 161 160 'd_spacing': 250., 'sigma_d': 0.2, 'sld': 1.0, 162 'sld_solvent': 6.34, 'thickness_pd': 0.0, 'thickness_pd_n': 40 161 'sld_solvent': 6.34, 'thickness_pd': 0.0, 'thickness_pd_n': 40}, 163 162 [0.001, 0.215268], [21829.3, 0.00487686]], 164 163 ] 165 # ADDED by: RKH ON: 18Mar2016 converted from sasview previously, now renaming everything & sorting the docs 164 # ADDED by: RKH ON: 18Mar2016 converted from sasview previously, 165 # now renaming everything & sorting the docs -
sasmodels/models/line.py
rc63a7c8 r2d81cfe 22 22 23 23 None. 24 """ 24 25 25 """ 26 import numpy as np 26 27 from numpy import inf 27 28 … … 70 71 71 72 def random(): 72 import numpy as np73 73 scale = 10**np.random.uniform(0, 3) 74 74 slope = np.random.uniform(-1, 1)*1e2 -
sasmodels/models/linear_pearls.py
r8f04da4 r2d81cfe 31 31 A V Dobrynin, M Rubinstein and S P Obukhov, *Macromol.*, 32 32 29 (1996) 2974-2979 33 34 33 """ 35 34 35 import numpy as np 36 36 from numpy import inf 37 37 … … 66 66 67 67 def random(): 68 import numpy as np69 68 radius = 10**np.random.uniform(1, 3) # 1 - 1000 70 69 edge_sep = 10**np.random.uniform(0, 3) # 1 - 1000 -
sasmodels/models/lorentz.py
r404ebbd r2d81cfe 24 24 """ 25 25 26 import numpy as np 26 27 from numpy import inf 27 28 … … 49 50 50 51 def random(): 51 import numpy as np52 52 pars = dict( 53 53 #background=0, -
sasmodels/models/mass_fractal.py
r4553dae r2d81cfe 51 51 D Mildner and P Hall, *J. Phys. D: Appl. Phys.*, 52 52 19 (1986) 1535-1545 Equation(9) 53 54 55 53 """ 56 54 55 import numpy as np 57 56 from numpy import inf 58 57 … … 89 88 90 89 def random(): 91 import numpy as np92 90 radius = 10**np.random.uniform(0.7, 4) 93 91 cutoff_length = 10**np.random.uniform(0.7, 2)*radius 94 92 # TODO: fractal dimension should range from 1 to 6 95 93 fractal_dim_mass = 2*np.random.beta(3, 4) + 1 96 Vf= 10**np.random.uniform(-4, -1)94 #volfrac = 10**np.random.uniform(-4, -1) 97 95 pars = dict( 98 96 #background=0, 99 scale=1, #1e5* Vf/radius**(fractal_dim_mass),97 scale=1, #1e5*volfrac/radius**(fractal_dim_mass), 100 98 radius=radius, 101 99 cutoff_length=cutoff_length, -
sasmodels/models/mass_surface_fractal.py
rca04add r2d81cfe 49 49 A J Hurd, D W Schaefer, J E Martin, *Phys. Rev. A*, 50 50 35 (1987) 2361-2364 Equation(2) 51 52 51 """ 53 52 53 import numpy as np 54 54 from numpy import inf 55 55 … … 86 86 87 87 def random(): 88 import numpy as np89 88 fractal_dim = np.random.uniform(0, 6) 90 89 surface_portion = np.random.uniform(0, 1) -
sasmodels/models/mono_gauss_coil.py
rca04add r2d81cfe 53 53 """ 54 54 55 import numpy as np 55 56 from numpy import inf, exp, errstate 56 57 … … 84 85 85 86 def random(): 86 import numpy as np87 87 rg = 10**np.random.uniform(0, 4) 88 88 #rg = 1e3 -
sasmodels/models/multilayer_vesicle.py
r64eecf7 r2d81cfe 110 110 """ 111 111 112 import numpy as np 112 113 from numpy import inf 113 114 … … 151 152 152 153 def random(): 153 import numpy as np154 154 volfraction = 10**np.random.uniform(-3, -0.5) # scale from 0.1% to 30% 155 155 radius = 10**np.random.uniform(0, 2.5) # core less than 300 A -
sasmodels/models/onion.py
rca04add r2d81cfe 260 260 # 261 261 262 263 262 from __future__ import division 263 264 from math import fabs, exp, expm1 264 265 265 266 import numpy as np 266 267 from numpy import inf, nan 267 from math import fabs, exp, expm1268 268 269 269 name = "onion" … … 356 356 z.append(z_current+z_shell) 357 357 rho.append(slope*exp(A[k]*z_shell/thickness[k]) + const) 358 358 359 359 # add in the solvent 360 360 z.append(z[-1]) … … 386 386 #"thickness4_pd": 0.4, 387 387 } 388 -
sasmodels/models/parallelepiped.py
reda8b30 r2d81cfe 74 74 $S(q)$ when $P(q) \cdot S(q)$ is applied. 75 75 76 For 2d data the orientation of the particle is required, described using 77 angles $\theta$, $\phi$ and $\Psi$ as in the diagrams below, for further details 76 For 2d data the orientation of the particle is required, described using 77 angles $\theta$, $\phi$ and $\Psi$ as in the diagrams below, for further details 78 78 of the calculation and angular dispersions see :ref:`orientation` . 79 79 … … 106 106 detector plane. 107 107 108 On introducing "Orientational Distribution" in the angles, "distribution of theta" and "distribution of phi" parameters will 109 appear. These are actually rotations about axes $\delta_1$ and $\delta_2$ of the parallelepiped, perpendicular to the $a$ x $c$ and $b$ x $c$ faces. 110 (When $\theta = \phi = 0$ these are parallel to the $Y$ and $X$ axes of the instrument.) The third orientation distribution, in $\psi$, is 111 about the $c$ axis of the particle, perpendicular to the $a$ x $b$ face. Some experimentation may be required to 112 understand the 2d patterns fully as discussed in :ref:`orientation` . 108 On introducing "Orientational Distribution" in the angles, "distribution of 109 theta" and "distribution of phi" parameters will appear. These are actually 110 rotations about axes $\delta_1$ and $\delta_2$ of the parallelepiped, 111 perpendicular to the $a$ x $c$ and $b$ x $c$ faces. (When $\theta = \phi = 0$ 112 these are parallel to the $Y$ and $X$ axes of the instrument.) The third 113 orientation distribution, in $\psi$, is about the $c$ axis of the particle, 114 perpendicular to the $a$ x $b$ face. Some experimentation may be required to 115 understand the 2d patterns fully as discussed in :ref:`orientation` . 113 116 114 117 For a given orientation of the parallelepiped, the 2D form factor is … … 165 168 166 169 * **Author:** This model is based on form factor calculations implemented 167 170 in a c-library provided by the NIST Center for Neutron Research (Kline, 2006). 168 171 * **Last Modified by:** Paul Kienzle **Date:** April 05, 2017 169 172 * **Last Reviewed by:** Richard Heenan **Date:** April 06, 2017 170 171 173 """ 172 174 … … 216 218 Return effective radius (ER) for P(q)*S(q) 217 219 """ 218 # now that axes can be in any size order, need to sort a,b,c where a~b and c is either much smaller219 # or much larger220 # now that axes can be in any size order, need to sort a,b,c 221 # where a~b and c is either much smaller or much larger 220 222 abc = np.vstack((length_a, length_b, length_c)) 221 223 abc = np.sort(abc, axis=0) … … 223 225 length = np.where(selector, abc[0], abc[2]) 224 226 # surface average radius (rough approximation) 225 radius = np.sqrt(np.where(~selector, abc[0]*abc[1], abc[1]*abc[2]) / pi)227 radius = sqrt(np.where(~selector, abc[0]*abc[1], abc[1]*abc[2]) / pi) 226 228 227 229 ddd = 0.75 * radius * (2*radius*length + (length + radius)*(length + pi*radius)) … … 232 234 233 235 def random(): 234 import numpy as np235 236 length = 10**np.random.uniform(1, 4.7, size=3) 236 237 pars = dict( … … 253 254 phi_pd=10, phi_pd_n=1, 254 255 psi_pd=10, psi_pd_n=10) 255 # rkh 7/4/17 add random unit test for 2d, note make all params different, 2d values not tested against other codes or models 256 # rkh 7/4/17 add random unit test for 2d, note make all params different, 257 # 2d values not tested against other codes or models 256 258 qx, qy = 0.2 * cos(pi/6.), 0.2 * sin(pi/6.) 257 259 tests = [[{}, 0.2, 0.17758004974], -
sasmodels/models/peak_lorentz.py
r404ebbd r2d81cfe 26 26 27 27 None. 28 29 28 """ 30 29 30 import numpy as np 31 31 from numpy import inf 32 32 … … 60 60 61 61 def random(): 62 import numpy as np63 62 peak_pos = 10**np.random.uniform(-3, -1) 64 63 peak_hwhm = peak_pos * 10**np.random.uniform(-3, 0) -
sasmodels/models/pearl_necklace.py
r8f04da4 r2d81cfe 55 55 """ 56 56 57 import numpy as np 57 58 from numpy import inf, pi 58 59 … … 118 119 119 120 def random(): 120 import numpy as np121 121 radius = 10**np.random.uniform(1, 3) # 1 - 1000 122 122 thick_string = 10**np.random.uniform(0, np.log10(radius)-1) # 1 - radius/10 -
sasmodels/models/poly_gauss_coil.py
rca04add r2d81cfe 106 106 107 107 def random(): 108 import numpy as np109 108 rg = 10**np.random.uniform(0, 4) 110 109 #rg = 1e3 -
sasmodels/models/polymer_excl_volume.py
r404ebbd r2d81cfe 90 90 B Hammouda, *SANS from Homogeneous Polymer Mixtures - A Unified Overview, 91 91 Advances in Polym. Sci.* 106(1993) 87-133 92 93 92 """ 94 93 94 import numpy as np 95 95 from numpy import inf, power, errstate 96 96 from scipy.special import gammainc, gamma … … 124 124 with errstate(divide='ignore', invalid='ignore'): 125 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)))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 129 result[q <= 0] = 1.0 130 130 … … 134 134 135 135 def random(): 136 import numpy as np137 136 rg = 10**np.random.uniform(0, 4) 138 137 porod_exp = np.random.uniform(1e-3, 6) -
sasmodels/models/polymer_micelle.py
rca04add r2d81cfe 13 13 the equations given by Pedersen (Pedersen, 2000), summarised briefly here. 14 14 15 The micelle core is imagined as $N\_aggreg$ polymer heads, each of volume $v\_core$, 16 which then defines a micelle core of $radius\_core$, which is a separate parameter 17 even though it could be directly determined. 18 The Gaussian random coil tails, of gyration radius $rg$, are imagined uniformly 19 distributed around the spherical core, centred at a distance $radius\_core + d\_penetration.rg$ 20 from the micelle centre, where $d\_penetration$ is of order unity. 21 A volume $v\_corona$ is defined for each coil. 22 The model in detail seems to separately parametrise the terms for the shape of I(Q) and the 23 relative intensity of each term, so use with caution and check parameters for consistency. 24 The spherical core is monodisperse, so it's intensity and the cross terms may have sharp 25 oscillations (use q resolution smearing if needs be to help remove them). 15 The micelle core is imagined as $N$ = *n_aggreg* polymer heads, each of volume 16 $V_\text{core}$, which then defines a micelle core of radius $r$ = *r_core*, 17 which is a separate parameter even though it could be directly determined. 18 The Gaussian random coil tails, of gyration radius $R_g$, are imagined 19 uniformly distributed around the spherical core, centred at a distance 20 $r + d \cdot R_g$ from the micelle centre, where $d$ = *d_penetration* is 21 of order unity. A volume $V_\text{corona}$ is defined for each coil. The 22 model in detail seems to separately parametrise the terms for the shape 23 of $I(Q)$ and the relative intensity of each term, so use with caution 24 and check parameters for consistency. The spherical core is monodisperse, 25 so it's intensity and the cross terms may have sharp oscillations (use $q$ 26 resolution smearing if needs be to help remove them). 26 27 27 28 .. math:: 28 P(q) = N^2\beta^2_s\Phi(qR)^2+N\beta^2_cP_c(q)+2N^2\beta_s\beta_cS_{sc}s_c(q)+N(N-1)\beta_c^2S_{cc}(q) \\ 29 \beta_s = v\_core(sld\_core - sld\_solvent) \\ 30 \beta_c = v\_corona(sld\_corona - sld\_solvent) 29 P(q) &= N^2\beta^2_s\Phi(qr)^2 + N\beta^2_cP_c(q) 30 + 2N^2\beta_s\beta_cS_{sc}s_c(q) + N(N-1)\beta_c^2S_{cc}(q) \\ 31 \beta_s &= V_\text{core}(\rho_\text{core} - \rho_\text{solvent}) \\ 32 \beta_c &= V_\text{corona}(\rho_\text{corona} - \rho_\text{solvent}) 31 33 32 where $N = n\_aggreg$, and for the spherical core of radius $R$ 34 where $\rho_\text{core}$, $\rho_\text{corona}$ and $\rho_\text{solvent}$ are 35 the scattering length densities *sld_core*, *sld_corona* and *sld_solvent*. 36 For the spherical core of radius $r$ 33 37 34 38 .. math:: 35 \Phi(q R)= \frac{\sin(qr) - qr\cos(qr)}{(qr)^3}39 \Phi(qr)= \frac{\sin(qr) - qr\cos(qr)}{(qr)^3} 36 40 37 41 whilst for the Gaussian coils … … 42 46 Z &= (q R_g)^2 43 47 44 The sphere to coil ( core to corona) and coil to coil (corona to corona) cross terms are45 approximated by:48 The sphere to coil (core to corona) and coil to coil (corona to corona) cross 49 terms are approximated by: 46 50 47 51 .. math:: 48 52 49 S_{sc}(q)=\Phi(qR)\psi(Z)\frac{sin(q(R+d.R_g))}{q(R+d.R_g)} \\ 50 S_{cc}(q)=\psi(Z)^2\left[\frac{sin(q(R+d.R_g))}{q(R+d.R_g)} \right ]^2 \\ 51 \psi(Z)=\frac{[1-exp^{-Z}]}{Z} 53 S_{sc}(q) &= \Phi(qr)\psi(Z) 54 \frac{\sin(q(r+d \cdot R_g))}{q(r+d \cdot R_g)} \\ 55 S_{cc}(q) &= \psi(Z)^2 56 \left[\frac{\sin(q(r+d \cdot R_g))}{q(r+d \cdot R_g)} \right]^2 \\ 57 \psi(Z) &= \frac{[1-\exp^{-Z}]}{Z} 52 58 53 59 Validation 54 60 ---------- 55 61 56 $P(q)$ above is multiplied by $ndensity$, and a units conversion of 10^{-13}, so $scale$57 is likely 1.0 if the scattering data is in absolute units. This model has not yet been 58 independently validated.62 $P(q)$ above is multiplied by *ndensity*, and a units conversion of $10^{-13}$, 63 so *scale* is likely 1.0 if the scattering data is in absolute units. This 64 model has not yet been independently validated. 59 65 60 66 … … 63 69 64 70 J Pedersen, *J. Appl. Cryst.*, 33 (2000) 637-640 65 66 71 """ 67 72 73 import numpy as np 68 74 from numpy import inf, pi 69 75 … … 102 108 103 109 def random(): 104 import numpy as np105 110 radius_core = 10**np.random.uniform(1, 3) 106 111 rg = radius_core * 10**np.random.uniform(-2, -0.3) -
sasmodels/models/porod.py
r232bb12 r2d81cfe 24 24 """ 25 25 26 from numpy import power, inf, errstate 26 import numpy as np 27 from numpy import inf, errstate 27 28 28 29 name = "porod" … … 46 47 47 48 def random(): 48 import numpy as np49 49 sld, solvent = np.random.uniform(-0.5, 12, size=2) 50 50 radius = 10**np.random.uniform(1, 4.7) -
sasmodels/models/power_law.py
r404ebbd r2d81cfe 27 27 """ 28 28 29 import numpy as np 29 30 from numpy import inf, errstate 30 31 … … 51 52 52 53 def random(): 53 import numpy as np54 54 power = np.random.uniform(1, 6) 55 55 pars = dict( -
sasmodels/models/pringle.py
r8f04da4 r2d81cfe 48 48 49 49 **Last Reviewed by:** Andrew Jackson **on:** September 26, 2016 50 51 50 """ 52 51 52 import numpy as np 53 53 from numpy import inf, pi 54 54 … … 86 86 87 87 def random(): 88 import numpy as np89 88 alpha, beta = 10**np.random.uniform(-1, 1, size=2) 90 89 radius = 10**np.random.uniform(1, 3) -
sasmodels/models/raspberry.py
r8f04da4 r2d81cfe 109 109 """ 110 110 111 import numpy as np 111 112 from numpy import inf 112 113 … … 155 156 156 157 def random(): 157 import numpy as np158 158 # Limit volume fraction to 20% each 159 159 volfraction_lg = 10**np.random.uniform(-3, -0.3) -
sasmodels/models/rectangular_prism.py
r31df0c9 r2d81cfe 81 81 82 82 R Nayuk and K Huber, *Z. Phys. Chem.*, 226 (2012) 837-854 83 84 83 """ 85 84 85 import numpy as np 86 86 from numpy import pi, inf, sqrt 87 87 … … 126 126 127 127 def random(): 128 import numpy as np129 128 a, b, c = 10**np.random.uniform(1, 4.7, size=3) 130 129 pars = dict( -
sasmodels/models/rpa.py
r30b60d2 r2d81cfe 150 150 else: 151 151 return HIDE_ALL 152 -
sasmodels/models/sc_paracrystal.py
reda8b30 r2d81cfe 23 23 equations (13)-(15) from the 1987 paper for Z1, Z2, and Z3. 24 24 25 The lattice correction (the occupied volume of the lattice) for a simple 26 cubicstructure of particles of radius *R* and nearest neighbor separation *D* is25 The lattice correction (the occupied volume of the lattice) for a simple cubic 26 structure of particles of radius *R* and nearest neighbor separation *D* is 27 27 28 28 .. math:: … … 73 73 carried out with a high density of points to properly capture the sharp 74 74 peaks of the paracrystalline scattering. 75 So be warned that the calculation is slow. Fitting of any experimental data 76 must be resolution smeared for any meaningful fit. This makes a triple integral77 which may be very slow.75 So be warned that the calculation is slow. Fitting of any experimental data 76 must be resolution smeared for any meaningful fit. This makes a triple 77 integral which may be very slow. 78 78 79 79 The 2D (Anisotropic model) is based on the reference below where *I(q)* is 80 80 approximated for 1d scattering. Thus the scattering pattern for 2D may not 81 be accurate particularly at low $q$. For general details of the calculation 81 be accurate particularly at low $q$. For general details of the calculation 82 82 and angular dispersions for oriented particles see :ref:`orientation` . 83 83 Note that we are not responsible for any incorrectness of the … … 96 96 Hideki Matsuoka et. al. *Physical Review B,* 41 (1990) 3854 -3856 97 97 (Corrections to FCC and BCC lattice structure calculation) 98 99 98 """ 100 99 100 import numpy as np 101 101 from numpy import inf 102 102 … … 140 140 141 141 def random(): 142 import numpy as np143 142 # copied from bcc_paracrystal 144 143 radius = 10**np.random.uniform(1.3, 4) -
sasmodels/models/sphere.py
r97d89af r2d81cfe 43 43 """ 44 44 45 import numpy as np 45 46 from numpy import inf 46 47 … … 87 88 88 89 def random(): 89 import numpy as np90 90 radius = 10**np.random.uniform(1.3, 4) 91 91 pars = dict( … … 102 102 [{"radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, "VR", 1.], 103 103 ] 104 105 -
sasmodels/models/spherical_sld.py
rca04add r2d81cfe 178 178 L A Feigin and D I Svergun, Structure Analysis by Small-Angle X-Ray 179 179 and Neutron Scattering, Plenum Press, New York, (1987) 180 181 180 """ 182 181 -
sasmodels/models/spinodal.py
r48462b0 r2d81cfe 3 3 ---------- 4 4 5 This model calculates the SAS signal of a phase separating solution under spinodal decomposition.6 The scattering intensity $I(q)$ is calculated as5 This model calculates the SAS signal of a phase separating solution 6 under spinodal decomposition. The scattering intensity $I(q)$ is calculated as 7 7 8 8 .. math:: 9 9 I(q) = I_{max}\frac{(1+\gamma/2)x^2}{\gamma/2+x^{2+\gamma}}+B 10 10 11 where $x=q/q_0$ and $B$ is a flat background. The characteristic structure length12 scales with the correlation peak at $q_0$. The exponent $\gamma$ is equal to 13 $d+1$ with d the dimensionality of the off-critical concentration mixtures. 14 A transition to $\gamma=2d$ is seen near the percolation threshold into the 15 critical concentration regime.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. 16 16 17 17 References … … 19 19 20 20 H. Furukawa. Dynamics-scaling theory for phase-separating unmixing mixtures: 21 Growth rates of droplets and scaling properties of autocorrelation functions. Physica A 123,497 (1984). 21 Growth rates of droplets and scaling properties of autocorrelation functions. 22 Physica A 123,497 (1984). 22 23 23 24 Authorship and Verification … … 29 30 """ 30 31 32 import numpy as np 31 33 from numpy import inf, errstate 32 34 … … 68 70 69 71 def random(): 70 import numpy as np71 72 pars = dict( 72 73 scale=10**np.random.uniform(1, 3), -
sasmodels/models/squarewell.py
r8f04da4 r2d81cfe 45 45 46 46 R V Sharma, K C Sharma, *Physica*, 89A (1977) 213. 47 """ 47 48 48 """ 49 import numpy as np 49 50 from numpy import inf 50 51 … … 133 134 134 135 def random(): 135 import numpy as np136 136 pars = dict( 137 137 scale=1, background=0, … … 148 148 tests = [ 149 149 [{'scale': 1.0, 'background': 0.0, 'radius_effective': 50.0, 150 'volfraction': 0.04, 'welldepth': 1.5, 'wellwidth': 1.2,150 'volfraction': 0.04, 'welldepth': 1.5, 'wellwidth': 1.2, 151 151 'radius_effective_pd': 0}, [0.001], [0.97665742]], 152 152 ] 153 153 # ADDED by: converting from sasview RKH ON: 16Mar2016 154 -
sasmodels/models/stacked_disks.py
r110f69c r2d81cfe 10 10 distribution. As such the normalization of this "composite" form factor is 11 11 relative to the individual disk volume, not the volume of the stack of disks. 12 This model is appropriate for example for non non exfoliated clay particles such13 as Laponite.12 This model is appropriate for example for non non exfoliated clay particles 13 such as Laponite. 14 14 15 15 .. figure:: img/stacked_disks_geometry.png … … 32 32 \Delta \rho_i = \rho_i - \rho_\text{solvent} 33 33 34 and $N$ is the number of individual (single) discs per unit volume, $\alpha$ is35 the angle between the axis of the disc and $q$, and $V_t$ and $V_c$ are the34 and $N$ is the number of individual (single) discs per unit volume, $\alpha$ 35 is the angle between the axis of the disc and $q$, and $V_t$ and $V_c$ are the 36 36 total volume and the core volume of a single disc, respectively, and 37 37 … … 110 110 """ 111 111 112 import numpy as np 112 113 from numpy import inf, sin, cos, pi 113 114 … … 146 147 147 148 def random(): 148 import numpy as np149 149 radius = 10**np.random.uniform(1, 4.7) 150 150 total_stack = 10**np.random.uniform(1, 4.7) … … 212 212 'scale': 0.01, 213 213 'background': 0.001, 214 # }, 0.001, 5065.12793824], n_stacking=1 not 5 ? slight change in value here 11jan2017, check other cpu types 215 # }, 0.001, 5075.11570493], 214 # n_stacking=1 not 5 ? slight change in value here 11jan2017, 215 # check other cpu types 216 #}, 0.001, 5065.12793824], 217 #}, 0.001, 5075.11570493], 216 218 }, 0.001, 25325.635693], 217 219 [{'thick_core': 10.0, … … 240 242 'scale': 0.01, 241 243 'background': 0.001, 242 # }, 0.164, 0.0127673597265], n_stacking=1 not 5 ? slight change in value here 11jan2017, check other cpu types 243 # }, 0.164, 0.01480812968], 244 # n_stacking=1 not 5 ? slight change in value here 11jan2017, 245 # check other cpu types 246 #}, 0.164, 0.0127673597265], 247 #}, 0.164, 0.01480812968], 244 248 }, 0.164, 0.0598367986509], 245 249 … … 256 260 'scale': 0.01, 257 261 'background': 0.001, 258 # second test here was at q=90, changed it to q=5, note I(q) is then just value of flat background 262 # second test here was at q=90, changed it to q=5, 263 # note I(q) is then just value of flat background 259 264 }, [0.001, 5.0], [5075.12, 0.001]], 260 265 … … 272 277 'background': 0.001, 273 278 }, ([0.4, 0.5]), [0.00105074, 0.00121761]], 274 # [{'thick_core': 10.0, 275 # 'thick_layer': 15.0, 276 # 'radius': 3000.0, 277 # 'n_stacking': 1.0, 278 # 'sigma_d': 0.0, 279 # 'sld_core': 4.0, 280 # 'sld_layer': -0.4, 281 # 'sld_solvent': 5.0, 282 # 'theta': 90.0, 283 # 'phi': 20.0, 284 # 'scale': 0.01, 285 # 'background': 0.001, 286 # 2017-05-18 PAK temporarily suppress output of qx,qy test; j1 is not accurate for large qr 287 # }, (qx, qy), 0.0341738733124], 288 # }, (qx, qy), None], 279 #[{'thick_core': 10.0, 280 # 'thick_layer': 15.0, 281 # 'radius': 3000.0, 282 # 'n_stacking': 1.0, 283 # 'sigma_d': 0.0, 284 # 'sld_core': 4.0, 285 # 'sld_layer': -0.4, 286 # 'sld_solvent': 5.0, 287 # 'theta': 90.0, 288 # 'phi': 20.0, 289 # 'scale': 0.01, 290 # 'background': 0.001, 291 # 2017-05-18 PAK temporarily suppress output of qx,qy test; j1 is 292 # not accurate for large qr 293 # }, (qx, qy), 0.0341738733124], 294 # }, (qx, qy), None], 289 295 290 296 [{'thick_core': 10.0, -
sasmodels/models/star_polymer.py
rbef029d r2d81cfe 58 58 """ 59 59 60 import numpy as np 60 61 from numpy import inf 61 62 … … 86 87 87 88 def random(): 88 import numpy as np89 89 pars = dict( 90 90 #background=0, -
sasmodels/models/stickyhardsphere.py
r8f04da4 r2d81cfe 68 68 # TODO: refactor so that we pull in the old sansmodels.c_extensions 69 69 70 import numpy as np 70 71 from numpy import inf 71 72 … … 99 100 100 101 def random(): 101 import numpy as np102 102 pars = dict( 103 103 scale=1, background=0, -
sasmodels/models/surface_fractal.py
r30b60d2 r2d81cfe 37 37 38 38 D Mildner and P Hall, *J. Phys. D: Appl. Phys.*, 19 (1986) 1535-1545 39 40 39 """ 41 40 41 import numpy as np 42 42 from numpy import inf 43 43 … … 78 78 79 79 def random(): 80 import numpy as np81 80 radius = 10**np.random.uniform(1, 4) 82 81 fractal_dim_surf = np.random.uniform(1, 3-1e-6) -
sasmodels/models/teubner_strey.py
r48462b0 r2d81cfe 103 103 104 104 def random(): 105 import numpy as np106 105 d = 10**np.random.uniform(1, 4) 107 106 xi = 10**np.random.uniform(-0.3, 2)*d -
sasmodels/models/triaxial_ellipsoid.py
r31df0c9 r2d81cfe 126 126 """ 127 127 128 import numpy as np 128 129 from numpy import inf, sin, cos, pi 129 130 … … 174 175 175 176 def random(): 176 import numpy as np177 177 a, b, c = 10**np.random.uniform(1, 4.7, size=3) 178 178 pars = dict( … … 201 201 qx = q*cos(pi/6.0) 202 202 qy = q*sin(pi/6.0) 203 tests = [[{}, 0.05, 24.8839548033], 204 [{'theta':80., 'phi':10.}, (qx, qy), 166.712060266 ], 205 ] 203 tests = [ 204 [{}, 0.05, 24.8839548033], 205 [{'theta':80., 'phi':10.}, (qx, qy), 166.712060266], 206 ] 206 207 del qx, qy # not necessary to delete, but cleaner -
sasmodels/models/two_lorentzian.py
r48462b0 r2d81cfe 34 34 """ 35 35 36 import numpy as np 36 37 from numpy import inf, power 37 38 … … 94 95 95 96 def random(): 96 import numpy as np97 97 scale = 10**np.random.uniform(0, 4, 2) 98 98 length = 10**np.random.uniform(1, 4, 2) -
sasmodels/models/two_power_law.py
r48462b0 r2d81cfe 44 44 """ 45 45 46 import numpy as np 46 47 from numpy import inf, power, empty, errstate 47 48 … … 88 89 :return: Calculated intensity 89 90 """ 90 result = empty(q.shape, 'd')91 result = empty(q.shape, 'd') 91 92 index = (q <= crossover) 92 93 with errstate(divide='ignore'): … … 99 100 100 101 def random(): 101 import numpy as np102 102 coefficient_1 = 1 103 103 crossover = 10**np.random.uniform(-3, -1) -
sasmodels/models/unified_power_Rg.py
r48462b0 r2d81cfe 68 68 69 69 B Hammouda, *Analysis of the Beaucage model, J. Appl. Cryst.*, (2010), 43, 1474-1478 70 71 70 """ 72 71 … … 75 74 import numpy as np 76 75 from numpy import inf, exp, sqrt, errstate 77 from scipy.special import erf 76 from scipy.special import erf, gamma 78 77 79 78 category = "shape-independent" … … 119 118 120 119 def random(): 121 import numpy as np122 from scipy.special import gamma123 120 level = np.minimum(np.random.poisson(0.5) + 1, 6) 124 121 n = level -
sasmodels/models/vesicle.py
r48462b0 r2d81cfe 63 63 """ 64 64 65 import numpy as np 65 66 from numpy import pi, inf 66 67 … … 121 122 122 123 def random(): 123 import numpy as np124 124 total_radius = 10**np.random.uniform(1.3, 5) 125 125 radius = total_radius * np.random.uniform(0, 1) -
sasmodels/product.py
rac60a39 r2d81cfe 16 16 import numpy as np # type: ignore 17 17 18 from .modelinfo import Parameter , ParameterTable, ModelInfo18 from .modelinfo import ParameterTable, ModelInfo 19 19 from .kernel import KernelModel, Kernel 20 20 from .details import make_details, dispersion_mesh 21 21 22 # pylint: disable=unused-import 22 23 try: 23 24 from typing import Tuple 24 25 except ImportError: 25 26 pass 27 else: 28 from .modelinfo import ParameterSet 29 # pylint: enable=unused-import 26 30 27 31 # TODO: make estimates available to constraints … … 76 80 combined_pars = p_info.random() 77 81 s_names = set(par.id for par in s_pars.kernel_parameters[1:]) 78 s = s_info.random()79 82 combined_pars.update((translate_name[k], v) 80 for k, v in s_info.random().items()81 if k in s_names)83 for k, v in s_info.random().items() 84 if k in s_names) 82 85 return combined_pars 83 86 -
sasmodels/resolution.py
r990d8df r2d81cfe 5 5 """ 6 6 from __future__ import division 7 8 import unittest 7 9 8 10 from scipy.special import erf # type: ignore … … 85 87 86 88 # Build weight matrix from calculated q values 87 self.weight_matrix = pinhole_resolution( self.q_calc, self.q,88 89 self.weight_matrix = pinhole_resolution( 90 self.q_calc, self.q, np.maximum(q_width, MINIMUM_RESOLUTION)) 89 91 self.q_calc = abs(self.q_calc) 90 92 … … 476 478 # unit tests 477 479 ############################################################################ 478 import unittest479 480 480 481 481 def eval_form(q, form, pars): … … 547 547 f_at_u = np.interp(u_sub, q_calc, Iq) 548 548 #print(np.trapz(Iu, w_grid, axis=1)) 549 total 549 total = np.trapz(np.trapz(f_at_u, w_grid, axis=1), h_grid[:, 0]) 550 550 result[i] = total / (2*h*w) 551 551 # from scipy.integrate import dblquad -
sasmodels/resolution2d.py
r7e94989 r2d81cfe 224 224 # Build weight matrix for resolution integration 225 225 if np.any(qx_width > 0): 226 self.weights = resolution.pinhole_resolution( qx_calc, q,227 226 self.weights = resolution.pinhole_resolution( 227 qx_calc, q, np.maximum(qx_width, resolution.MINIMUM_RESOLUTION)) 228 228 elif len(qx_calc) == len(q) and np.all(qx_calc == q): 229 229 self.weights = None … … 236 236 Iq = resolution.apply_resolution_matrix(self.weights, Iq) 237 237 return Iq 238 -
sasmodels/rst2html.py
re65c3ba r2d81cfe 249 249 view_url_wxapp(url) 250 250 251 if __name__ == "__main__":251 def main(): 252 252 import sys 253 253 view_help(sys.argv[1], qt=False) 254 255 if __name__ == "__main__": 256 main() -
sasmodels/sasview_model.py
re65c3ba r2d81cfe 31 31 from .details import make_kernel_args, dispersion_mesh 32 32 33 # pylint: disable=unused-import 33 34 try: 34 from typing import Dict, Mapping, Any, Sequence, Tuple, NamedTuple, List, Optional, Union, Callable 35 from typing import (Dict, Mapping, Any, Sequence, Tuple, NamedTuple, 36 List, Optional, Union, Callable) 35 37 from .modelinfo import ModelInfo, Parameter 36 38 from .kernel import KernelModel … … 42 44 except ImportError: 43 45 pass 46 # pylint: enable=unused-import 44 47 45 48 logger = logging.getLogger(__name__) … … 838 841 cylinder.setParam('background', 0.) 839 842 Iq = cylinder.evalDistribution(np.asarray([0.1])) 840 assert np.isnan(Iq[0]), "empty distribution fails"843 assert Iq[0] == 0., "empty distribution fails" 841 844 842 845 def test_model_list(): -
sasmodels/weights.py
r0db85af r2d81cfe 225 225 """ 226 226 if disperser == "array": 227 raise NotImplementedError("Don't handle arrays through get_weights; use values and weights directly") 227 raise NotImplementedError("Don't handle arrays through get_weights;" 228 " use values and weights directly") 228 229 cls = MODELS[disperser] 229 230 obj = cls(n, width, nsigmas) … … 245 246 import pylab 246 247 247 if any(len(dispersity) >1 for value, dispersity, weights in mesh):248 if any(len(dispersity) > 1 for value, dispersity, weights in mesh): 248 249 labels = [p.name for p in model_info.parameters.call_parameters] 249 250 #pylab.interactive(True) 250 251 pylab.figure() 251 for (v, x,w), s in zip(mesh, labels):252 for (v, x, w), s in zip(mesh, labels): 252 253 if len(x) > 1: 253 254 pylab.plot(x, w, '-o', label=s)
Note: See TracChangeset
for help on using the changeset viewer.