Changeset a261a83 in sasmodels
- Timestamp:
- Nov 30, 2017 12:25:06 AM (7 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 7dde87f
- Parents:
- 0b07b91 (diff), 10ee838 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 2 added
- 136 edited
Legend:
- Unmodified
- Added
- Removed
-
example/sesans_parameters_sphere.py
r9217ef8 rfa79f5c 46 46 # DO NOT MODIFY THIS LINE 47 47 problem = sesansfit.sesans_fit(sesans_file, model, initial_vals, custom_params, param_range) 48 -
example/sesans_sphere_2micron.py
r3330bb4 rfa79f5c 1 1 """ 2 This is a data file 2 This is a data file used to load in sesans data and fit it using the bumps engine 3 3 """ 4 4 from bumps.names import * … … 38 38 # Constraints 39 39 # model.param_name = f(other params) 40 # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius and scale are model functions and phi is41 # a custom parameter40 # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius 41 # and scale are model functions and phi is a custom parameter 42 42 model.scale = phi*(1-phi) 43 43 … … 45 45 # DO NOT MODIFY THIS LINE 46 46 problem = sesansfit.sesans_fit(sesans_file, model, initial_vals, custom_params, param_range) 47 -
example/sesansfit.py
r9217ef8 rfa79f5c 1 import logging 2 1 3 from bumps.names import * 2 4 from sasmodels import core, bumps_model, sesans … … 8 10 return model 9 11 10 def sesans_fit(file, model, initial_vals={}, custom_params={}, param_range=[], acceptance_angle=None): 12 def sesans_fit(file, model, initial_vals={}, custom_params={}, param_range=[], 13 acceptance_angle=None): 11 14 """ 12 15 … … 19 22 @return: FitProblem for Bumps usage 20 23 """ 24 logging.basicConfig() 25 21 26 initial_vals['background'] = 0.0 22 27 try: 23 28 loader = Loader() 24 data = loader.load(file) 25 if data is None: raise IOError("Could not load file %r"%(file)) 29 data = loader.load(file)[0] 30 if data is None: 31 raise IOError("Could not load file %r"%(file)) 26 32 27 except: 33 except Exception: 34 raise 28 35 # If no loadable data file, generate random data 29 36 SElength = np.linspace(0, 2400, 61) # [A] … … 50 57 data.Rmax = 30*radius # [A] 51 58 52 if isinstance(model, basestring):59 if isinstance(model, str): 53 60 model = get_bumps_model(model) 54 61 -
example/spheres2micron.ses
r6abf703 rfa79f5c 1 DataFileTitle Polystyrene of Markus Strobl, Full Sine, ++ only 2 Sample Polystyrene 2 um in 53% H2O, 47% D2O 3 Settings D1=D2=20x8 mm,Ds = 16x10 mm (WxH), GF1 =scanning, GF2 = 2.5 A. 2 um polystyrene in 53% H2O, 47% D2O; 8.55% contrast 4 Operator CPD 5 Date ma 7 jul 2014 18:54:43 6 ScanType sine one element scan 7 Thickness [mm] 2 8 Q_zmax [\AA^-1] 0.05 9 Q_ymax [\AA^-1] 0.05 10 11 spin echo length [nm] error SEL wavelength [nm] error wavelength polarisation error pol 12 49.778 2.4889 0.211 0.01055 0.99782 0.0044367 13 63.041 3.152 0.211 0.01055 1.0026 0.0047862 14 76.487 3.8244 0.211 0.01055 0.99601 0.0060598 15 89.847 4.4924 0.211 0.01055 0.99175 0.0058257 16 103.41 5.1705 0.211 0.01055 0.99543 0.0060966 17 116.95 5.8475 0.211 0.01055 0.99512 0.0048106 18 130.61 6.5303 0.211 0.01055 0.9975 0.0062594 19 144.37 7.2184 0.211 0.01055 0.99473 0.005293 20 158.2 7.9102 0.211 0.01055 0.9927 0.0053389 21 172.12 8.6062 0.211 0.01055 0.99453 0.0064548 22 186.17 9.3087 0.211 0.01055 0.98641 0.0073259 23 200.28 10.014 0.211 0.01055 0.98879 0.0078682 24 214.46 10.723 0.211 0.01055 0.9895 0.0068058 25 228.73 11.436 0.211 0.01055 0.99204 0.0082509 26 243.12 12.156 0.211 0.01055 0.99406 0.0051381 27 257.55 12.878 0.211 0.01055 0.97965 0.0055447 28 272.22 13.611 0.211 0.01055 0.97982 0.0065843 29 286.9 14.345 0.211 0.01055 0.97793 0.0071814 30 301.73 15.087 0.211 0.01055 0.97835 0.0066197 31 316.75 15.838 0.211 0.01055 0.98125 0.0069484 32 331.82 16.591 0.211 0.01055 0.97828 0.0068737 33 347.16 17.358 0.211 0.01055 0.97682 0.006744 34 362.45 18.122 0.211 0.01055 0.98155 0.0059865 35 378.09 18.904 0.211 0.01055 0.96446 0.0066788 36 393.74 19.687 0.211 0.01055 0.97276 0.0073781 37 409.61 20.481 0.211 0.01055 0.97101 0.0071053 38 425.55 21.278 0.211 0.01055 0.97501 0.0068244 39 441.91 22.096 0.211 0.01055 0.96958 0.0072272 40 458.12 22.906 0.211 0.01055 0.95991 0.0064035 41 474.77 23.739 0.211 0.01055 0.96219 0.0059227 42 491.52 24.576 0.211 0.01055 0.96016 0.0058606 43 508.51 25.426 0.211 0.01055 0.9509 0.0049836 44 525.68 26.284 0.211 0.01055 0.95558 0.0055218 45 543.08 27.154 0.211 0.01055 0.95079 0.0058258 46 560.74 28.037 0.211 0.01055 0.9514 0.0043921 47 578.69 28.935 0.211 0.01055 0.94562 0.0046962 48 596.75 29.838 0.211 0.01055 0.94588 0.0047341 49 615.17 30.758 0.211 0.01055 0.93958 0.0045821 50 633.77 31.688 0.211 0.01055 0.93731 0.0043108 51 652.82 32.641 0.211 0.01055 0.93664 0.0052044 52 672.04 33.602 0.211 0.01055 0.93209 0.0035563 53 691.57 34.578 0.211 0.01055 0.93385 0.0046002 54 711.48 35.574 0.211 0.01055 0.93028 0.0051136 55 731.67 36.583 0.211 0.01055 0.93012 0.0035279 56 752.17 37.608 0.211 0.01055 0.92594 0.0039458 57 773.1 38.655 0.211 0.01055 0.92352 0.0027613 58 794.42 39.721 0.211 0.01055 0.91823 0.0034587 59 816.14 40.807 0.211 0.01055 0.90862 0.0034262 60 838.19 41.91 0.211 0.01055 0.91909 0.003498 61 860.69 43.034 0.211 0.01055 0.91013 0.0030537 62 883.74 44.187 0.211 0.01055 0.90449 0.0035391 63 907.04 45.352 0.211 0.01055 0.90057 0.0029672 64 930.95 46.547 0.211 0.01055 0.90316 0.0031245 65 955.38 47.769 0.211 0.01055 0.89492 0.0030981 66 980.25 49.013 0.211 0.01055 0.89636 0.0036625 67 1005.7 50.284 0.211 0.01055 0.88808 0.0022652 68 1031.7 51.586 0.211 0.01055 0.88665 0.0044622 69 1058.3 52.914 0.211 0.01055 0.88205 0.0030275 70 1085.5 54.276 0.211 0.01055 0.88257 0.0028637 71 1113.4 55.669 0.211 0.01055 0.87629 0.0030312 72 1141.9 57.093 0.211 0.01055 0.87732 0.0026539 73 1171 58.55 0.211 0.01055 0.87361 0.0034591 74 1201 60.052 0.211 0.01055 0.86595 0.0028129 75 1231.6 61.582 0.211 0.01055 0.86804 0.0043311 76 1263 63.151 0.211 0.01055 0.86676 0.0028806 77 1295.2 64.762 0.211 0.01055 0.85655 0.0028657 78 1328.4 66.419 0.211 0.01055 0.85794 0.0034773 79 1362.3 68.113 0.211 0.01055 0.85521 0.0032798 80 1397.1 69.854 0.211 0.01055 0.84974 0.0044537 81 1432.9 71.644 0.211 0.01055 0.84149 0.0032738 82 1469.7 73.487 0.211 0.01055 0.84801 0.0037874 83 1507.5 75.376 0.211 0.01055 0.84334 0.003206 84 1546.4 77.318 0.211 0.01055 0.83749 0.0040707 85 1586.4 79.322 0.211 0.01055 0.83921 0.0049938 86 1627.6 81.381 0.211 0.01055 0.83434 0.0057337 87 1669.9 83.497 0.211 0.01055 0.82878 0.0062417 88 1713.6 85.678 0.211 0.01055 0.82309 0.0080179 89 1758.5 87.927 0.211 0.01055 0.82433 0.0074191 90 1804.8 90.239 0.211 0.01055 0.82023 0.0076431 91 1852.5 92.627 0.211 0.01055 0.82756 0.0063064 92 1901.7 95.087 0.211 0.01055 0.82584 0.0052944 93 1952.4 97.622 0.211 0.01055 0.82799 0.0050662 94 2004.8 100.24 0.211 0.01055 0.82345 0.0043127 95 2058.8 102.94 0.211 0.01055 0.82296 0.0038 96 2114.5 105.72 0.211 0.01055 0.81987 0.0034072 97 2172 108.6 0.211 0.01055 0.82021 0.0036752 98 2231.4 111.57 0.211 0.01055 0.82765 0.0028851 99 2292.8 114.64 0.211 0.01055 0.82664 0.0038942 100 2356.2 117.81 0.211 0.01055 0.82702 0.0047371 101 2421.8 121.09 0.211 0.01055 0.81593 0.0043772 102 2489.6 124.48 0.211 0.01055 0.8251 0.0028026 103 2559.5 127.98 0.211 0.01055 0.8292 0.0024574 104 2631.9 131.59 0.211 0.01055 0.82626 0.0036198 105 2706.8 135.34 0.211 0.01055 0.8208 0.0032314 106 2784.3 139.22 0.211 0.01055 0.81959 0.0042731 107 2864.5 143.23 0.211 0.01055 0.82653 0.002699 108 2947.5 147.38 0.211 0.01055 0.82401 0.0036726 109 3033.5 151.67 0.211 0.01055 0.82361 0.0048224 110 3122.4 156.12 0.211 0.01055 0.82358 0.0041221 111 3214.5 160.73 0.211 0.01055 0.82187 0.0028807 112 3310.1 165.5 0.211 0.01055 0.82644 0.003516 113 3409 170.45 0.211 0.01055 0.82355 0.0021166 114 3511.4 175.57 0.211 0.01055 0.82513 0.0033911 115 3617.6 180.88 0.211 0.01055 0.82802 0.0015342 116 3727.6 186.38 0.211 0.01055 0.82663 0.0029222 117 3841.7 192.08 0.211 0.01055 0.82026 0.0020755 118 3960 198 0.211 0.01055 0.83079 0.0026394 119 4082.7 204.13 0.211 0.01055 0.82665 0.0027466 120 4209.9 210.5 0.211 0.01055 0.82774 0.0025199 121 4341.9 217.09 0.211 0.01055 0.83489 0.0030619 122 4478.7 223.94 0.211 0.01055 0.81987 0.0020988 123 4620.8 231.04 0.211 0.01055 0.8253 0.0023899 124 4768.2 238.41 0.211 0.01055 0.82653 0.0022851 125 4921.1 246.06 0.211 0.01055 0.82442 0.003383 126 5079.8 253.99 0.211 0.01055 0.82827 0.0015979 127 5244.7 262.23 0.211 0.01055 0.82494 0.0031129 128 5415.7 270.79 0.211 0.01055 0.82183 0.0030149 129 5593.3 279.67 0.211 0.01055 0.83217 0.0046976 130 5777.8 288.89 0.211 0.01055 0.82227 0.005574 131 5969.3 298.46 0.211 0.01055 0.82338 0.0025569 1 FileFormatVersion 1.0 2 DataFileTitle Polystyrene of Markus Strobl, Full Sine, ++ only 3 Sample Polystyrene 2 um in 53% H2O, 47% D2O 4 Settings D1=D2=20x8 mm,Ds = 16x10 mm (WxH), GF1 =scanning, GF2 = 2.5 A. 2 um polystyrene in 53% H2O, 47% D2O; 8.55% contrast 5 Operator CPD 6 Date do 10 jul 2014 16:37:30 7 ScanType sine one element scan 8 Thickness 2.00E-01 9 Thickness_unit cm 10 Theta_zmax 0.0168 11 Theta_zmax_unit radians 12 Theta_ymax 0.0168 13 Theta_ymax_unit radians 14 Orientation Z 15 SpinEchoLength_unit A 16 Depolarisation_unit A-2 cm-1 17 Wavelength_unit A 18 19 BEGIN_DATA 20 SpinEchoLength Depolarisation Depolarisation_error SpinEchoLength_error Wavelength Wavelength_error Polarisation Polarisation_error 21 391.56 0.0041929 0.0036894 19.578 2.11 0.1055 1.0037 0.0032974 22 1564 -0.0046571 0.0038185 78.2 2.11 0.1055 0.99586 0.003386 23 2735.6 -0.017007 0.0038132 136.78 2.11 0.1055 0.98497 0.0033444 24 3907.9 -0.033462 0.0035068 195.39 2.11 0.1055 0.97064 0.0030309 25 5080.2 -0.047483 0.0038208 254.01 2.11 0.1055 0.9586 0.0032613 26 6251.8 -0.070375 0.00376 312.59 2.11 0.1055 0.93926 0.0031446 27 7423.2 -0.092217 0.0037927 371.16 2.11 0.1055 0.92117 0.0031108 28 8595.5 -0.10238 0.004006 429.77 2.11 0.1055 0.91287 0.0032562 29 9767.7 -0.12672 0.0038534 488.39 2.11 0.1055 0.8933 0.0030651 30 10940 -0.1374 0.004243 546.98 2.11 0.1055 0.88484 0.003343 31 12112 -0.16072 0.0045837 605.58 2.11 0.1055 0.86666 0.0035372 32 13284 -0.16623 0.0045613 664.2 2.11 0.1055 0.86242 0.0035027 33 14456 -0.18468 0.0044918 722.79 2.11 0.1055 0.84837 0.0033931 34 15628 -0.19143 0.0048967 781.38 2.11 0.1055 0.84328 0.0036768 35 16800 -0.20029 0.0045421 840.02 2.11 0.1055 0.83666 0.0033837 36 17971 -0.19798 0.0046642 898.56 2.11 0.1055 0.83838 0.0034819 37 19143 -0.21442 0.0047052 957.17 2.11 0.1055 0.82619 0.0034614 38 20316 -0.20885 0.0044931 1015.8 2.11 0.1055 0.8303 0.0033218 39 21488 -0.21393 0.0049186 1074.4 2.11 0.1055 0.82655 0.00362 40 22660 -0.20685 0.004423 1133 2.11 0.1055 0.83179 0.0032758 41 23832 -0.20802 0.0046979 1191.6 2.11 0.1055 0.83092 0.0034758 42 25003 -0.19848 0.0045953 1250.2 2.11 0.1055 0.838 0.0034289 43 26175 -0.21117 0.0044567 1308.8 2.11 0.1055 0.82859 0.0032881 44 27347 -0.21283 0.004137 1367.4 2.11 0.1055 0.82736 0.0030477 45 28520 -0.2042 0.0044587 1426 2.11 0.1055 0.83375 0.0033101 46 29692 -0.2112 0.0042852 1484.6 2.11 0.1055 0.82857 0.0031615 47 30864 -0.20319 0.0043483 1543.2 2.11 0.1055 0.8345 0.003231 48 32036 -0.20752 0.0044297 1601.8 2.11 0.1055 0.83129 0.0032788 49 33207 -0.20654 0.0043188 1660.4 2.11 0.1055 0.83201 0.0031995 50 34380 -0.20126 0.0046375 1719 2.11 0.1055 0.83593 0.0034518 51 35551 -0.20924 0.0042871 1777.6 2.11 0.1055 0.83001 0.0031684 52 36724 -0.21323 0.0045471 1836.2 2.11 0.1055 0.82707 0.0033487 53 37895 -0.21324 0.0045354 1894.7 2.11 0.1055 0.82706 0.00334 54 39067 -0.19905 0.0044141 1953.4 2.11 0.1055 0.83758 0.003292 55 40239 -0.1991 0.0047441 2012 2.11 0.1055 0.83754 0.003538 56 41411 -0.20359 0.0050136 2070.5 2.11 0.1055 0.8342 0.003724 57 42583 -0.21032 0.0049474 2129.1 2.11 0.1055 0.82922 0.0036529 58 43755 -0.20689 0.0048203 2187.8 2.11 0.1055 0.83176 0.00357 59 44927 -0.21075 0.0052337 2246.4 2.11 0.1055 0.8289 0.0038628 60 46099 -0.19956 0.0047827 2304.9 2.11 0.1055 0.8372 0.0035653 -
extra/pylint.rc
r823e620 rb669b49 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/__init__.py
r997c9ca re65c3ba 47 47 ] 48 48 return return_list 49 50 -
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
rff31782 ra261a83 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_pars, constrain_new_to_old46 44 from .generate import FLOAT_RE, set_integration_size 47 45 from .weights import plot_weights 48 46 47 # pylint: disable=unused-import 49 48 try: 50 49 from typing import Optional, Dict, Any, Callable, Tuple 51 except Exception:50 except ImportError: 52 51 pass 53 52 else: … … 55 54 from .data import Data 56 55 Calculator = Callable[[float], np.ndarray] 56 # pylint: enable=unused-import 57 57 58 58 USAGE = """ … … 97 97 -single/-double/-half/-fast sets an OpenCL calculation engine 98 98 -single!/-double!/-quad! sets an OpenMP calculation engine 99 -sasview sets the sasview calculation engine100 99 101 100 === plotting === … … 150 149 kerneldll.ALLOW_SINGLE_PRECISION_DLLS = True 151 150 152 # list of math functions for use in evaluating parameters 153 MATH = dict((k,getattr(math, k)) for k in dir(math) if not k.startswith('_')) 151 def build_math_context(): 152 # type: () -> Dict[str, Callable] 153 """build dictionary of functions from math module""" 154 return dict((k, getattr(math, k)) 155 for k in dir(math) if not k.startswith('_')) 156 157 #: list of math functions for use in evaluating parameters 158 MATH = build_math_context() 154 159 155 160 # CRUFT python 2.6 … … 231 236 pass 232 237 233 def __exit__(self, exc_type, exc_value, trace back):238 def __exit__(self, exc_type, exc_value, trace): 234 239 # type: (Any, BaseException, Any) -> None 235 # TODO: better typing for __exit__ method236 240 np.random.set_state(self._state) 237 241 … … 252 256 """ 253 257 Add a beam stop of the given *radius*. If *outer*, make an annulus. 254 255 Note: this function does not require sasview256 258 """ 257 259 if hasattr(data, 'qx_data'): … … 374 376 375 377 def _random_pd(model_info, pars): 378 # type: (ModelInfo, Dict[str, float]) -> None 379 """ 380 Generate a random dispersity distribution for the model. 381 382 1% no shape dispersity 383 85% single shape parameter 384 13% two shape parameters 385 1% three shape parameters 386 387 If oriented, then put dispersity in theta, add phi and psi dispersity 388 with 10% probability for each. 389 """ 376 390 pd = [p for p in model_info.parameters.kernel_parameters if p.polydisperse] 377 391 pd_volume = [] … … 444 458 value = pars[p.name] 445 459 if p.units == 'Ang' and value > maxdim: 446 pars[p.name] = maxdim*10**np.random.uniform(-3, 0)460 pars[p.name] = maxdim*10**np.random.uniform(-3, 0) 447 461 448 462 def constrain_pars(model_info, pars): … … 490 504 if pars['radius'] < pars['thick_string']: 491 505 pars['radius'], pars['thick_string'] = pars['thick_string'], pars['radius'] 492 pass493 506 494 507 elif name == 'rpa': … … 608 621 return pars 609 622 610 def eval_sasview(model_info, data):611 # type: (Modelinfo, Data) -> Calculator612 """613 Return a model calculator using the pre-4.0 SasView models.614 """615 # importing sas here so that the error message will be that sas failed to616 # import rather than the more obscure smear_selection not imported error617 import sas618 import sas.models619 from sas.models.qsmearing import smear_selection620 from sas.models.MultiplicationModel import MultiplicationModel621 from sas.models.dispersion_models import models as dispersers622 623 def get_model_class(name):624 # type: (str) -> "sas.models.BaseComponent"625 #print("new",sorted(_pars.items()))626 __import__('sas.models.' + name)627 ModelClass = getattr(getattr(sas.models, name, None), name, None)628 if ModelClass is None:629 raise ValueError("could not find model %r in sas.models"%name)630 return ModelClass631 632 # WARNING: ugly hack when handling model!633 # Sasview models with multiplicity need to be created with the target634 # multiplicity, so we cannot create the target model ahead of time for635 # for multiplicity models. Instead we store the model in a list and636 # update the first element of that list with the new multiplicity model637 # every time we evaluate.638 639 # grab the sasview model, or create it if it is a product model640 if model_info.composition:641 composition_type, parts = model_info.composition642 if composition_type == 'product':643 P, S = [get_model_class(revert_name(p))() for p in parts]644 model = [MultiplicationModel(P, S)]645 else:646 raise ValueError("sasview mixture models not supported by compare")647 else:648 old_name = revert_name(model_info)649 if old_name is None:650 raise ValueError("model %r does not exist in old sasview"651 % model_info.id)652 ModelClass = get_model_class(old_name)653 model = [ModelClass()]654 model[0].disperser_handles = {}655 656 # build a smearer with which to call the model, if necessary657 smearer = smear_selection(data, model=model)658 if hasattr(data, 'qx_data'):659 q = np.sqrt(data.qx_data**2 + data.qy_data**2)660 index = ((~data.mask) & (~np.isnan(data.data))661 & (q >= data.qmin) & (q <= data.qmax))662 if smearer is not None:663 smearer.model = model # because smear_selection has a bug664 smearer.accuracy = data.accuracy665 smearer.set_index(index)666 def _call_smearer():667 smearer.model = model[0]668 return smearer.get_value()669 theory = _call_smearer670 else:671 theory = lambda: model[0].evalDistribution([data.qx_data[index],672 data.qy_data[index]])673 elif smearer is not None:674 theory = lambda: smearer(model[0].evalDistribution(data.x))675 else:676 theory = lambda: model[0].evalDistribution(data.x)677 678 def calculator(**pars):679 # type: (float, ...) -> np.ndarray680 """681 Sasview calculator for model.682 """683 oldpars = revert_pars(model_info, pars)684 # For multiplicity models, create a model with the correct multiplicity685 control = oldpars.pop("CONTROL", None)686 if control is not None:687 # sphericalSLD has one fewer multiplicity. This update should688 # happen in revert_pars, but it hasn't been called yet.689 model[0] = ModelClass(control)690 # paying for parameter conversion each time to keep life simple, if not fast691 for k, v in oldpars.items():692 if k.endswith('.type'):693 par = k[:-5]694 if v == 'gaussian': continue695 cls = dispersers[v if v != 'rectangle' else 'rectangula']696 handle = cls()697 model[0].disperser_handles[par] = handle698 try:699 model[0].set_dispersion(par, handle)700 except Exception:701 exception.annotate_exception("while setting %s to %r"702 %(par, v))703 raise704 705 706 #print("sasview pars",oldpars)707 for k, v in oldpars.items():708 name_attr = k.split('.') # polydispersity components709 if len(name_attr) == 2:710 par, disp_par = name_attr711 model[0].dispersion[par][disp_par] = v712 else:713 model[0].setParam(k, v)714 return theory()715 716 calculator.engine = "sasview"717 return calculator718 623 719 624 DTYPE_MAP = { … … 812 717 set_integration_size(model_info, ngauss) 813 718 814 if dtype == 'sasview': 815 return eval_sasview(model_info, data) 816 elif dtype is None or not dtype.endswith('!'): 719 if dtype is None or not dtype.endswith('!'): 817 720 return eval_opencl(model_info, data, dtype=dtype, cutoff=cutoff) 818 721 else: … … 850 753 # print a separate seed for each dataset for better reproducibility 851 754 new_seed = np.random.randint(1000000) 852 print("Set %d uses -random=%i"%(k+1, new_seed))755 print("Set %d uses -random=%i"%(k+1, new_seed)) 853 756 np.random.seed(new_seed) 854 757 opts['pars'] = parse_pars(opts, maxdim=maxdim) … … 871 774 def run_models(opts, verbose=False): 872 775 # type: (Dict[str, Any]) -> Dict[str, Any] 776 """ 777 Process a parameter set, return calculation results and times. 778 """ 873 779 874 780 base, comp = opts['engines'] … … 926 832 # work with trimmed data, not the full set 927 833 sorted_err = np.sort(abs(err.compressed())) 928 if len(sorted_err) == 0 .:834 if len(sorted_err) == 0: 929 835 print(label + " no valid values") 930 836 return … … 944 850 def plot_models(opts, result, limits=None, setnum=0): 945 851 # type: (Dict[str, Any], Dict[str, Any], Optional[Tuple[float, float]]) -> Tuple[float, float] 852 """ 853 Plot the results from :func:`run_model`. 854 """ 946 855 import matplotlib.pyplot as plt 947 856 … … 990 899 errview = 'linear' 991 900 if 0: # 95% cutoff 992 sorted = np.sort(err.flatten())993 cutoff = sorted [int(sorted.size*0.95)]901 sorted_err = np.sort(err.flatten()) 902 cutoff = sorted_err[int(sorted_err.size*0.95)] 994 903 err[err > cutoff] = cutoff 995 904 #err,errstr = base/comp,"ratio" … … 1054 963 'engine=', 1055 964 'half', 'fast', 'single', 'double', 'single!', 'double!', 'quad!', 1056 'sasview', # TODO: remove sasview 3.x support1057 965 1058 966 # Output options … … 1060 968 ] 1061 969 1062 NAME_OPTIONS = set(k for k in OPTIONS if not k.endswith('='))1063 VALUE_OPTIONS = [k[:-1] for k in OPTIONS if k.endswith('=')]970 NAME_OPTIONS = (lambda: set(k for k in OPTIONS if not k.endswith('=')))() 971 VALUE_OPTIONS = (lambda: [k[:-1] for k in OPTIONS if k.endswith('=')])() 1064 972 1065 973 … … 1109 1017 1110 1018 INTEGER_RE = re.compile("^[+-]?[1-9][0-9]*$") 1111 def isnumber(str): 1112 match = FLOAT_RE.match(str) 1113 isfloat = (match and not str[match.end():]) 1114 return isfloat or INTEGER_RE.match(str) 1019 def isnumber(s): 1020 # type: (str) -> bool 1021 """Return True if string contains an int or float""" 1022 match = FLOAT_RE.match(s) 1023 isfloat = (match and not s[match.end():]) 1024 return isfloat or INTEGER_RE.match(s) 1115 1025 1116 1026 # For distinguishing pairs of models for comparison … … 1151 1061 name = positional_args[-1] 1152 1062 1153 # pylint: disable=bad-whitespace 1063 # pylint: disable=bad-whitespace,C0321 1154 1064 # Interpret the flags 1155 1065 opts = { … … 1237 1147 elif arg == '-double!': opts['engine'] = 'double!' 1238 1148 elif arg == '-quad!': opts['engine'] = 'quad!' 1239 elif arg == '-sasview': opts['engine'] = 'sasview'1240 1149 elif arg == '-edit': opts['explore'] = True 1241 1150 elif arg == '-demo': opts['use_demo'] = True … … 1244 1153 elif arg == '-html': opts['html'] = True 1245 1154 elif arg == '-help': opts['html'] = True 1246 # pylint: enable=bad-whitespace 1155 # pylint: enable=bad-whitespace,C0321 1247 1156 1248 1157 # Magnetism forces 2D for now … … 1328 1237 1329 1238 def set_spherical_integration_parameters(opts, steps): 1239 # type: (Dict[str, Any], int) -> None 1330 1240 """ 1331 1241 Set integration parameters for spherical integration over the entire … … 1351 1261 'psi_pd_type=rectangle', 1352 1262 ]) 1353 pass1354 1263 1355 1264 def parse_pars(opts, maxdim=np.inf): 1265 # type: (Dict[str, Any], float) -> Tuple[Dict[str, float], Dict[str, float]] 1266 """ 1267 Generate a parameter set. 1268 1269 The default values come from the model, or a randomized model if a seed 1270 value is given. Next, evaluate any parameter expressions, constraining 1271 the value of the parameter within and between models. If *maxdim* is 1272 given, limit parameters with units of Angstrom to this value. 1273 1274 Returns a pair of parameter dictionaries for base and comparison models. 1275 """ 1356 1276 model_info, model_info2 = opts['info'] 1357 1277 … … 1392 1312 print("%r invalid; parameters are: %s"%(k, ", ".join(sorted(s)))) 1393 1313 return None 1394 v1, v2 = v.split(PAR_SPLIT, 2) if PAR_SPLIT in v else (v, v)1314 v1, v2 = v.split(PAR_SPLIT, 2) if PAR_SPLIT in v else (v, v) 1395 1315 if v1 and k in pars: 1396 1316 presets[k] = float(v1) if isnumber(v1) else v1 … … 1441 1361 show html docs for the model 1442 1362 """ 1443 import os1444 1363 from .generate import make_html 1445 1364 from . import rst2html … … 1448 1367 html = make_html(info) 1449 1368 path = os.path.dirname(info.filename) 1450 url = "file://" +path.replace("\\","/")[2:]+"/"1369 url = "file://" + path.replace("\\", "/")[2:] + "/" 1451 1370 rst2html.view_html_qtapp(html, url) 1452 1371 … … 1472 1391 frame.panel.Layout() 1473 1392 frame.panel.aui.Split(0, wx.TOP) 1474 def reset_parameters(event):1393 def _reset_parameters(event): 1475 1394 model.revert_values() 1476 1395 signal.update_parameters(problem) 1477 frame.Bind(wx.EVT_TOOL, reset_parameters, frame.ToolBar.GetToolByPos(1)) 1478 if is_mac: frame.Show() 1396 frame.Bind(wx.EVT_TOOL, _reset_parameters, frame.ToolBar.GetToolByPos(1)) 1397 if is_mac: 1398 frame.Show() 1479 1399 # If running withing an app, start the main loop 1480 1400 if app: … … 1518 1438 1519 1439 def revert_values(self): 1440 # type: () -> None 1441 """ 1442 Restore starting values of the parameters. 1443 """ 1520 1444 for k, v in self.starting_values.items(): 1521 1445 self.pars[k].value = v 1522 1446 1523 1447 def model_update(self): 1448 # type: () -> None 1449 """ 1450 Respond to signal that model parameters have been changed. 1451 """ 1524 1452 pass 1525 1453 -
sasmodels/compare_many.py
rf72d70a r2d81cfe 22 22 from .compare import (randomize_pars, suppress_pd, make_data, 23 23 make_engine, get_pars, columnize, 24 constrain_pars , constrain_new_to_old)24 constrain_pars) 25 25 26 26 MODELS = core.list_models() … … 80 80 'double!': 5e-14, 81 81 'quad!': 5e-18, 82 'sasview': 5e-14,83 82 } 84 83 def compare_instance(name, data, index, N=1, mono=True, cutoff=1e-5, 85 base='s asview', comp='double'):84 base='single', comp='double'): 86 85 r""" 87 86 Compare the model under different calculation engines. … … 164 163 print("Model %s %d"%(name, k+1), file=sys.stderr) 165 164 seed = np.random.randint(1e6) 166 pars_i = randomize_pars(model_info, pars, seed) 165 np.random.seed(seed) 166 pars_i = randomize_pars(model_info, pars) 167 167 constrain_pars(model_info, pars_i) 168 if 'sasview' in (base, comp):169 constrain_new_to_old(model_info, pars_i)170 168 if mono: 171 169 pars_i = suppress_pd(pars_i) … … 266 264 return 267 265 268 data, index = make_data({'qmax':1.0, 'is2d':is2D, 'nq':Nq, 'res':0., 269 '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 }) 270 270 for model in model_list: 271 271 compare_instance(model, data, index, N=count, mono=mono, -
sasmodels/conversion_table.py
r505d0ad re65c3ba 29 29 30 30 CONVERSION_TABLE = { 31 (3, 1,2) : {32 "adsorbed_layer": [33 "Core2ndMomentModel",34 {35 "scale": "scale",36 "second_moment": "second_moment",37 "density_shell": "density_poly",38 "sld_solvent": "sld_solv",39 "radius": "radius_core",40 "volfraction": "volf_cores",41 "background": "background",42 "adsorbed_amount": "ads_amount",43 "sld_shell": "sld_poly"44 }45 ],46 "barbell": [47 "BarBellModel",48 {49 "sld": "sld_barbell",50 "length": "len_bar",51 "radius_bell": "rad_bell",52 "radius": "rad_bar",53 "sld_solvent": "sld_solv"54 }55 ],56 "bcc_paracrystal": [57 "BCCrystalModel",58 {59 "sld": "sldSph",60 "sld_solvent": "sldSolv"61 }62 ],63 "be_polyelectrolyte": [64 "BEPolyelectrolyte",65 {66 "ionization_degree": "alpha",67 "polymer_concentration": "c",68 "salt_concentration": "cs",69 "virial_param": "h",70 "background": "background",71 "contrast_factor": "k",72 "bjerrum_length": "lb",73 "monomer_length": "b"74 }75 ],76 "binary_hard_sphere": [77 "BinaryHSModel",78 {79 "sld_sm": "ss_sld",80 "sld_lg": "ls_sld",81 "volfraction_sm": "vol_frac_ss",82 "radius_lg": "l_radius",83 "radius_sm": "s_radius",84 "volfraction_lg": "vol_frac_ls",85 "sld_solvent": "solvent_sld"86 }87 ],88 "broad_peak": [89 "BroadPeakModel",90 {91 "peak_pos": "q_peak",92 "scale": None,93 "lorentz_length": "length_l",94 "porod_scale": "scale_p",95 "lorentz_exp": "exponent_l",96 "lorentz_scale": "scale_l",97 "porod_exp": "exponent_p"98 }99 ],100 "capped_cylinder": [101 "CappedCylinderModel",102 {103 "sld": "sld_capcyl",104 "length": "len_cyl",105 "radius_cap": "rad_cap",106 "radius": "rad_cyl",107 "sld_solvent": "sld_solv"108 }109 ],110 "core_multi_shell": [111 "CoreMultiShellModel",112 {113 "thickness": "thick_shell",114 "sld": "sld_shell",115 "radius": "rad_core0",116 "sld_core": "sld_core0",117 "sld_solvent": "sld_solv",118 "n": "n_shells",119 "M0:sld_core": "M0_sld_core0",120 "mtheta:sld_core": "M_theta_core0",121 "mphi:sld_core": "M_phi_core0",122 "M0:sld1": "M0_sld_shell1",123 "mtheta:sld1": "M_theta_shell1",124 "mphi:sld1": "M_phi_shell1",125 "M0:sld2": "M0_sld_shell2",126 "mtheta:sld2": "M_theta_shell2",127 "mphi:sld2": "M_phi_shell2",128 "M0:sld3": "M0_sld_shell3",129 "mtheta:sld3": "M_theta_shell3",130 "mphi:sld3": "M_phi_shell3",131 "M0:sld4": "M0_sld_shell4",132 "mtheta:sld4": "M_theta_shell4",133 "mphi:sld4": "M_phi_shell4",134 "M0:sld_solvent": "M0_sld_solv",135 "mtheta:sld_solvent": "M_theta_solv",136 "mphi:sld_solvent": "M_phi_solv",137 "up:frac_i": "Up_frac_i",138 "up:frac_f": "Up_frac_f",139 "up:angle": "Up_theta",140 }141 ],142 "core_shell_bicelle": [143 "CoreShellBicelleModel",144 {145 "phi": "axis_phi",146 "sld_core": "core_sld",147 "sld_rim": "rim_sld",148 "thick_face": "face_thick",149 "sld_solvent": "solvent_sld",150 "thick_rim": "rim_thick",151 "sld_face": "face_sld",152 "theta": "axis_theta"153 }154 ],155 "core_shell_cylinder": [156 "CoreShellCylinderModel",157 {158 "theta": "axis_theta",159 "phi": "axis_phi",160 "sld_shell": "shell_sld",161 "sld_solvent": "solvent_sld",162 "sld_core": "core_sld"163 }164 ],165 "core_shell_ellipsoid:1": [166 "CoreShellEllipsoidModel",167 {168 "sld_core": "sld_core",169 "sld_shell": "sld_shell",170 "sld_solvent": "sld_solvent",171 "radius_equat_core": "equat_core",172 "x_core": "polar_core",173 "thick_shell": "equat_shell",174 "x_polar_shell": "polar_shell",175 "theta": "axis_theta",176 "phi": "axis_phi",177 }178 ],179 "core_shell_ellipsoid": [180 "CoreShellEllipsoidXTModel",181 {182 "sld_core": "sld_core",183 "sld_shell": "sld_shell",184 "sld_solvent": "sld_solvent",185 "radius_equat_core": "equat_core",186 "thick_shell": "T_shell",187 "x_core": "X_core",188 "x_polar_shell": "XpolarShell",189 "theta": "axis_theta",190 "phi": "axis_phi",191 }192 ],193 "core_shell_parallelepiped": [194 "CSParallelepipedModel",195 {196 "sld_core": "sld_pcore",197 "sld_a": "sld_rimA",198 "sld_b": "sld_rimB",199 "sld_c": "sld_rimC",200 "sld_solvent": "sld_solv",201 "length_a": "shortA",202 "length_b": "midB",203 "length_c": "longC",204 "thick_rim_a": "rimA",205 "thick_rim_c": "rimC",206 "thick_rim_b": "rimB",207 "theta": "parallel_theta",208 "phi": "parallel_phi",209 "psi": "parallel_psi",210 }211 ],212 "core_shell_sphere": [213 "CoreShellModel",214 {215 "sld_core": "core_sld",216 "sld_shell": "shell_sld",217 "sld_solvent": "solvent_sld",218 "M0:sld_core": "M0_sld_core",219 "mtheta:sld_core": "M_theta_core",220 "mphi:sld_core": "M_phi_core",221 "M0:sld_shell": "M0_sld_shell",222 "mtheta:sld_shell": "M_theta_shell",223 "mphi:sld_shell": "M_phi_shell",224 "M0:sld_solvent": "M0_sld_solv",225 "mtheta:sld_solvent": "M_theta_solv",226 "mphi:sld_solvent": "M_phi_solv",227 "up:frac_i": "Up_frac_i",228 "up:frac_f": "Up_frac_f",229 "up:angle": "Up_theta"230 }231 ],232 "correlation_length": [233 "CorrLength",234 {235 "porod_scale": "scale_p",236 "lorentz_scale": "scale_l",237 "porod_exp": "exponent_p",238 "lorentz_exp": "exponent_l",239 "cor_length": "length_l"240 },241 "CorrLengthModel"242 ],243 "cylinder": [244 "CylinderModel",245 {246 "sld": "sldCyl",247 "theta": "cyl_theta",248 "phi": "cyl_phi",249 "sld_solvent": "sldSolv",250 "M0:sld": "M0_sld_cyl",251 "mtheta:sld": "M_theta_cyl",252 "mphi:sld": "M_phi_cyl",253 "M0:sld_solvent": "M0_sld_solv",254 "mtheta:sld_solvent": "M_theta_solv",255 "mphi:sld_solvent": "M_phi_solv",256 "up:frac_i": "Up_frac_i",257 "up:frac_f": "Up_frac_f",258 "up:angle": "Up_theta"259 }260 ],261 "dab": [262 "DABModel",263 {264 "cor_length": "length"265 }266 ],267 "ellipsoid": [268 "EllipsoidModel",269 {270 "phi": "axis_phi",271 "radius_equatorial": "radius_b",272 "sld": "sldEll",273 "theta": "axis_theta",274 "radius_polar": "radius_a",275 "sld_solvent": "sldSolv"276 }277 ],278 "elliptical_cylinder": [279 "EllipticalCylinderModel",280 {281 "axis_ratio": "r_ratio",282 "radius_minor": "r_minor",283 "sld": "sldCyl",284 "sld_solvent": "sldSolv",285 "theta": "cyl_theta",286 "phi": "cyl_phi",287 "psi": "cyl_psi",288 }289 ],290 "fcc_paracrystal": [291 "FCCrystalModel",292 {293 "sld": "sldSph",294 "sld_solvent": "sldSolv"295 }296 ],297 "flexible_cylinder": [298 "FlexibleCylinderModel",299 {300 "sld": "sldCyl",301 "sld_solvent": "sldSolv"302 }303 ],304 "flexible_cylinder_elliptical": [305 "FlexCylEllipXModel",306 {307 "sld": "sldCyl",308 "sld_solvent": "sldSolv"309 }310 ],311 "fractal": [312 "FractalModel",313 {314 "sld_block": "sldBlock",315 "radius": "radius",316 "cor_length": "cor_length",317 "sld_solvent": "sldSolv",318 "fractal_dim": "fractal_dim"319 }320 ],321 "fractal_core_shell": [322 "FractalCoreShell",323 {324 "sld_core": "core_sld",325 "sld_shell": "shell_sld",326 "sld_solvent": "solvent_sld",327 "radius": "radius",328 "thickness": "thickness",329 "fractal_dim": "frac_dim",330 "cor_length": "cor_length",331 "volfraction": "volfraction",332 },333 "FractalCoreShellModel"334 ],335 "fuzzy_sphere": [336 "FuzzySphereModel",337 {338 "sld": "sldSph",339 "fuzziness": "fuzziness",340 "radius": "radius",341 "sld_solvent": "sldSolv"342 }343 ],344 "gauss_lorentz_gel": [345 "GaussLorentzGel",346 {347 "gauss_scale": "scale_g",348 "cor_length_dynamic": "dyn_colength",349 "cor_length_static": "stat_colength",350 "background": "background",351 "lorentz_scale": "scale_l"352 },353 "GaussLorentzGelModel"354 ],355 "gaussian_peak": [356 "Peak Gauss Model",357 {358 "peak_pos": "q0",359 "sigma": "B",360 },361 "PeakGaussModel",362 ],363 "gel_fit": [364 "GelFitModel",365 {366 "rg": "radius",367 "lorentz_scale": "lScale",368 "guinier_scale": "gScale",369 "fractal_dim": "FractalExp",370 "cor_length": "zeta",371 }372 ],373 "guinier": [374 "Guinier",375 {376 "rg": "rg"377 },378 "GuinierModel",379 ],380 "guinier_porod": [381 "GuinierPorod",382 {383 "s": "dim",384 "rg": "rg",385 "porod_exp": "m",386 "scale": "scale",387 "background": "background"388 },389 "GuinierPorodModel",390 ],391 "hardsphere": [392 "HardsphereStructure",393 {394 "scale": "scale_factor",395 "radius_effective": "effect_radius",396 }397 ],398 "hayter_msa": [399 "HayterMSAStructure",400 {401 "scale": "scale_factor",402 "radius_effective": "effect_radius",403 "volfraction": "volfraction",404 "charge": "charge",405 "temperature": "temperature",406 "concentration_salt": "saltconc",407 "dielectconst": "dielectconst",408 }409 ],410 "hollow_cylinder": [411 "HollowCylinderModel",412 {413 "sld": "sldCyl",414 "sld_solvent": "sldSolv",415 "radius": "core_radius",416 "thickness": "radius",417 "length": "length",418 "theta": "axis_theta",419 "phi": "axis_phi",420 }421 ],422 "hollow_rectangular_prism": [423 "RectangularHollowPrismModel",424 {425 "sld": "sldPipe",426 "sld_solvent": "sldSolv",427 "length_a": "short_side",428 "b2a_ratio": "b2a_ratio",429 "c2a_ratio": "c2a_ratio",430 "thickness": "thickness",431 }432 ],433 "hollow_rectangular_prism_thin_walls": [434 "RectangularHollowPrismInfThinWallsModel",435 {436 "sld": "sldPipe",437 "sld_solvent": "sldSolv",438 "length_a": "short_side",439 "b2a_ratio": "b2a_ratio",440 "c2a_ratio": "c2a_ratio",441 }442 ],443 "lamellar": [444 "LamellarModel",445 {446 "sld": "sld_bi",447 "sld_solvent": "sld_sol",448 "thickness": "bi_thick"449 }450 ],451 "lamellar_hg": [452 "LamellarFFHGModel",453 {454 "sld": "sld_tail",455 "sld_solvent": "sld_solvent",456 "sld_head": "sld_head",457 "length_tail": "t_length",458 "length_head": "h_thickness"459 }460 ],461 "lamellar_hg_stack_caille": [462 "LamellarPSHGModel",463 {464 "sld": "sld_tail",465 "sld_head": "sld_head",466 "sld_solvent": "sld_solvent",467 "length_tail": "deltaT",468 "length_head": "deltaH",469 "d_spacing": "spacing",470 "Caille_parameter": "caille",471 "Nlayers": "n_plates",472 }473 ],474 "lamellar_stack_caille": [475 "LamellarPSModel",476 {477 "sld": "sld_bi",478 "sld_solvent": "sld_sol",479 "thickness": "delta",480 "d_spacing": "spacing",481 "Caille_parameter": "caille",482 "Nlayers": "n_plates",483 }484 ],485 "lamellar_stack_paracrystal": [486 "LamellarPCrystalModel",487 {488 "sld": "sld_layer",489 "sld_solvent": "sld_solvent",490 "thickness": "thickness",491 "d_spacing": "spacing",492 "sigma_d": "pd_spacing",493 "Nlayers": "Nlayers",494 }495 ],496 "line": [497 "LineModel",498 {499 "slope": "B",500 "scale": None,501 "background": None,502 "intercept": "A"503 }504 ],505 "linear_pearls": [506 "LinearPearlsModel",507 {508 "sld": "sld_pearl",509 "sld_solvent": "sld_solv",510 "edge_sep": "edge_separation"511 }512 ],513 "lorentz": [514 "Lorentz",515 {516 "cor_length": "length"517 },518 "LorentzModel",519 ],520 "mass_fractal": [521 "MassFractalModel",522 {523 "cutoff_length": "co_length",524 "radius": "radius",525 "fractal_dim_mass": "mass_dim"526 }527 ],528 "mass_surface_fractal": [529 "MassSurfaceFractal",530 {531 "rg_cluster": "cluster_rg",532 "fractal_dim_mass": "mass_dim",533 "radius": "radius",534 "fractal_dim_surf": "surface_dim",535 "rg_primary": "primary_rg"536 }537 ],538 "mono_gauss_coil": [539 "Debye",540 {541 "rg": "rg",542 "i_zero": "scale",543 "background": "background",544 },545 "DebyeModel",546 ],547 "multilayer_vesicle": [548 "MultiShellModel",549 {550 "radius": "core_radius",551 "sld_solvent": "core_sld",552 "n_shells": "n_pairs",553 "thick_shell": "s_thickness",554 "sld": "shell_sld",555 "thick_solvent": "w_thickness",556 }557 ],558 "onion": [559 "OnionExpShellModel",560 {561 "n_shells": "n_shells",562 "A": "A_shell",563 "sld_core": "sld_core0",564 "radius_core": "rad_core0",565 "sld_solvent": "sld_solv",566 "thickness": "thick_shell",567 "sld_in": "sld_in_shell",568 "sld_out": "sld_out_shell"569 }570 ],571 "parallelepiped": [572 "ParallelepipedModel",573 {574 "phi": "parallel_phi",575 "psi": "parallel_psi",576 "sld_solvent": "sldSolv",577 "length_a": "short_a",578 "length_b": "short_b",579 "sld": "sldPipe",580 "theta": "parallel_theta",581 "length_c": "long_c",582 "M0:sld": "M0_sld_pipe",583 "mtheta:sld": "M_theta_pipe",584 "mphi:sld": "M_phi_pipe",585 "M0:sld_solvent": "M0_sld_solv",586 "mtheta:sld_solvent": "M_theta_solv",587 "mphi:sld_solvent": "M_phi_solv",588 "up:frac_i": "Up_frac_i",589 "up:frac_f": "Up_frac_f",590 "up:angle": "Up_theta",591 }592 ],593 "peak_lorentz": [594 "Peak Lorentz Model",595 {596 "peak_pos": "q0",597 "peak_hwhm": "B"598 },599 "PeakLorentzModel",600 ],601 "pearl_necklace": [602 "PearlNecklaceModel",603 {604 "scale": "scale",605 "thick_string": "thick_string",606 "sld_string": "sld_string",607 "sld_solvent": "sld_solv",608 "edge_sep": "edge_separation",609 "num_pearls": "num_pearls",610 "radius": "radius",611 "background": "background",612 "sld": "sld_pearl"613 }614 ],615 "poly_gauss_coil": [616 "Poly_GaussCoil",617 {618 "rg": "rg",619 "polydispersity": "poly_m",620 "i_zero": "scale",621 "background": "background",622 }623 ],624 "polymer_excl_volume": [625 "PolymerExclVolume",626 {627 "rg": "rg",628 "scale": "scale",629 "background": "background",630 "porod_exp": "m"631 }632 ],633 "polymer_micelle": [634 "MicelleSphCoreModel",635 {636 "sld_corona": "rho_corona",637 "sld_solvent": "rho_solv",638 "sld_core": "rho_core",639 "ndensity": "ndensity",640 "v_core": "v_core",641 "v_corona": "v_corona",642 "radius_core": "radius_core",643 "rg": "radius_gyr",644 "d_penetration": "d_penetration",645 "n_aggreg": "n_aggreg",646 }647 ],648 "porod": [649 "PorodModel",650 {651 "scale": "scale",652 "background": "background"653 }654 ],655 "power_law": [656 "PowerLawAbsModel",657 {658 "scale": "scale",659 "background": "background",660 "power": "m"661 }662 ],663 "pringle": [664 "PringlesModel",665 {666 "scale": "scale",667 "sld_solvent": "sld_solvent",668 "thickness": "thickness",669 "beta": "beta",670 "radius": "radius",671 "background": "background",672 "alpha": "alpha",673 "sld": "sld_pringle"674 }675 ],676 "raspberry": [677 "RaspBerryModel",678 {679 "volfraction_lg": "volf_Lsph",680 "volfraction_sm": "volf_Ssph",681 "radius_sm": "radius_Ssph",682 "radius_lg": "radius_Lsph",683 "sld_lg": "sld_Lsph",684 "sld_sm": "sld_Ssph",685 "sld_solvent": "sld_solv",686 "surface_fraction": "surfrac_Ssph",687 "penetration": "delta_Ssph"688 }689 ],690 "rectangular_prism": [691 "RectangularPrismModel",692 {693 "sld": "sldPipe",694 "length_a": "short_side",695 "b2a_ratio": "b2a_ratio",696 "c2a_ratio": "c2a_ratio",697 "sld_solvent": "sldSolv"698 }699 ],700 "rpa": [701 "RPA10Model",702 {703 "K12": "Kab", "K13": "Kac", "K14": "Kad",704 "K23": "Kbc", "K24": "Kbd", "K34": "Kcd",705 "N1": "Na", "N2": "Nb", "N3": "Nc", "N4": "Nd",706 "L1": "La", "L2": "Lb", "L3": "Lc", "L4": "Ld",707 "v1": "va", "v2": "vb", "v3": "vc", "v4": "vd",708 "b1": "ba", "b2": "bb", "b3": "bc", "b4": "bd",709 "Phi1": "Phia", "Phi2": "Phib", "Phi3": "Phic", "Phi4": "Phid",710 "case_num": "lcase_n"711 }712 ],713 "sc_paracrystal": [714 "SCCrystalModel",715 {716 "sld": "sldSph",717 "sld_solvent": "sldSolv"718 }719 ],720 "sphere": [721 "SphereModel",722 {723 "sld": "sldSph",724 "radius": "radius",725 "sld_solvent": "sldSolv",726 "M0:sld": "M0_sld_sph",727 "mtheta:sld": "M_theta_sph",728 "mphi:sld": "M_phi_sph",729 "M0:sld_solvent": "M0_sld_solv",730 "mtheta:sld_solvent": "M_theta_solv",731 "mphi:sld_solvent": "M_phi_solv",732 "up:frac_i": "Up_frac_i",733 "up:frac_f": "Up_frac_f",734 "up:angle": "Up_theta"735 }736 ],737 "spherical_sld": [738 "SphericalSLDModel",739 # Be lazy and use a generator expression to define740 # sld1: sld_flat0, ...741 # thickness1: thick_flat0, ...742 # interface1: thick_inter0, ...743 # shape1: func_inter0, ...744 # nu1: nu_inter0, ...745 # but override thickness1 => rad_cor0 and sld1 => sld_core0.746 # Note: explicit key,value pairs given by **{...} override the747 # keys from the gnerator expression ((k,v) for k,v in seq) when748 # used as dict((generator), **{...})749 dict(((field_new+str(index+1), field_old+str(index))750 for field_new, field_old in [("sld", "sld_flat"),751 ("thickness", "thick_flat"),752 ("interface", "thick_inter"),753 ("shape", "func_inter"),754 ("nu", "nu_inter"),]755 for index in range(11)),756 **{757 "n_shells": "n_shells",758 "n_steps": "npts_inter",759 "sld_solvent": "sld_solv",760 "thickness1": "rad_core0",761 "sld1": "sld_core0",762 })763 ],764 "squarewell": [765 "SquareWellStructure",766 {767 "scale": "scale_factor",768 "radius_effective": "effect_radius",769 "wellwidth": "wellwidth",770 "welldepth": "welldepth",771 }772 ],773 "stacked_disks": [774 "StackedDisksModel",775 {776 "phi": "axis_phi",777 "sld_layer": "layer_sld",778 "sld_core": "core_sld",779 "theta": "axis_theta",780 "sld_solvent": "solvent_sld",781 "n_stacking": "n_stacking",782 "thick_layer": "layer_thick",783 "thick_core": "core_thick",784 }785 ],786 "star_polymer": [787 "StarPolymer",788 {789 "arms": "arms",790 "rg_squared": "R2"791 }792 ],793 "stickyhardsphere": [794 "StickyHSStructure",795 {796 "scale": "scale_factor",797 "radius_effective": "effect_radius",798 }799 ],800 "surface_fractal": [801 "SurfaceFractalModel",802 {803 "cutoff_length": "co_length",804 "radius": "radius",805 "fractal_dim_surf": "surface_dim"806 }807 ],808 "teubner_strey": [809 "TeubnerStreyModel",810 {811 # Note: parameters are completely rewritten in convert.py812 "volfraction_a": "volfraction_a",813 "sld_a": "sld_a",814 "sld_b": "sld_b",815 "d": "d",816 "xi": "xi",817 }818 ],819 "triaxial_ellipsoid": [820 "TriaxialEllipsoidModel",821 {822 "phi": "axis_phi",823 "radius_equat_minor": "semi_axisA",824 "radius_polar": "semi_axisC",825 "radius_equat_major": "semi_axisB",826 "sld_solvent": "sldSolv",827 "psi": "axis_psi",828 "sld": "sldEll",829 "theta": "axis_theta"830 }831 ],832 "two_lorentzian": [833 "TwoLorentzian",834 {835 "lorentz_scale_1": "scale_1",836 "lorentz_scale_2": "scale_2",837 "lorentz_exp_1": "exponent_1",838 "lorentz_exp_2": "exponent_2",839 "lorentz_length_2": "length_2",840 "lorentz_length_1": "length_1",841 "background": "background"842 },843 "TwoLorentzianModel",844 ],845 "two_power_law": [846 "TwoPowerLaw",847 {848 "coefficent_1": "coef_A",849 "power_2": "power2",850 "power_1": "power1",851 "background": "background",852 "crossover": "qc"853 },854 "TwoPowerLawModel",855 ],856 "unified_power_Rg": [857 "UnifiedPowerRg",858 dict(((field_new+str(index), field_old+str(index))859 for field_new, field_old in [("rg", "Rg"),860 ("power", "power"),861 ("G", "G"),862 ("B", "B"),]863 for index in range(11)),864 **{865 "background": "background",866 "scale": "scale",867 }),868 "UnifiedPowerRgModel",869 ],870 "vesicle": [871 "VesicleModel",872 {873 "sld": "shell_sld",874 "sld_solvent": "solv_sld"875 }876 ]31 (3, 1, 2) : { 32 "adsorbed_layer": [ 33 "Core2ndMomentModel", 34 { 35 "scale": "scale", 36 "second_moment": "second_moment", 37 "density_shell": "density_poly", 38 "sld_solvent": "sld_solv", 39 "radius": "radius_core", 40 "volfraction": "volf_cores", 41 "background": "background", 42 "adsorbed_amount": "ads_amount", 43 "sld_shell": "sld_poly" 44 } 45 ], 46 "barbell": [ 47 "BarBellModel", 48 { 49 "sld": "sld_barbell", 50 "length": "len_bar", 51 "radius_bell": "rad_bell", 52 "radius": "rad_bar", 53 "sld_solvent": "sld_solv" 54 } 55 ], 56 "bcc_paracrystal": [ 57 "BCCrystalModel", 58 { 59 "sld": "sldSph", 60 "sld_solvent": "sldSolv" 61 } 62 ], 63 "be_polyelectrolyte": [ 64 "BEPolyelectrolyte", 65 { 66 "ionization_degree": "alpha", 67 "polymer_concentration": "c", 68 "salt_concentration": "cs", 69 "virial_param": "h", 70 "background": "background", 71 "contrast_factor": "k", 72 "bjerrum_length": "lb", 73 "monomer_length": "b" 74 } 75 ], 76 "binary_hard_sphere": [ 77 "BinaryHSModel", 78 { 79 "sld_sm": "ss_sld", 80 "sld_lg": "ls_sld", 81 "volfraction_sm": "vol_frac_ss", 82 "radius_lg": "l_radius", 83 "radius_sm": "s_radius", 84 "volfraction_lg": "vol_frac_ls", 85 "sld_solvent": "solvent_sld" 86 } 87 ], 88 "broad_peak": [ 89 "BroadPeakModel", 90 { 91 "peak_pos": "q_peak", 92 "scale": None, 93 "lorentz_length": "length_l", 94 "porod_scale": "scale_p", 95 "lorentz_exp": "exponent_l", 96 "lorentz_scale": "scale_l", 97 "porod_exp": "exponent_p" 98 } 99 ], 100 "capped_cylinder": [ 101 "CappedCylinderModel", 102 { 103 "sld": "sld_capcyl", 104 "length": "len_cyl", 105 "radius_cap": "rad_cap", 106 "radius": "rad_cyl", 107 "sld_solvent": "sld_solv" 108 } 109 ], 110 "core_multi_shell": [ 111 "CoreMultiShellModel", 112 { 113 "thickness": "thick_shell", 114 "sld": "sld_shell", 115 "radius": "rad_core0", 116 "sld_core": "sld_core0", 117 "sld_solvent": "sld_solv", 118 "n": "n_shells", 119 "M0:sld_core": "M0_sld_core0", 120 "mtheta:sld_core": "M_theta_core0", 121 "mphi:sld_core": "M_phi_core0", 122 "M0:sld1": "M0_sld_shell1", 123 "mtheta:sld1": "M_theta_shell1", 124 "mphi:sld1": "M_phi_shell1", 125 "M0:sld2": "M0_sld_shell2", 126 "mtheta:sld2": "M_theta_shell2", 127 "mphi:sld2": "M_phi_shell2", 128 "M0:sld3": "M0_sld_shell3", 129 "mtheta:sld3": "M_theta_shell3", 130 "mphi:sld3": "M_phi_shell3", 131 "M0:sld4": "M0_sld_shell4", 132 "mtheta:sld4": "M_theta_shell4", 133 "mphi:sld4": "M_phi_shell4", 134 "M0:sld_solvent": "M0_sld_solv", 135 "mtheta:sld_solvent": "M_theta_solv", 136 "mphi:sld_solvent": "M_phi_solv", 137 "up:frac_i": "Up_frac_i", 138 "up:frac_f": "Up_frac_f", 139 "up:angle": "Up_theta", 140 } 141 ], 142 "core_shell_bicelle": [ 143 "CoreShellBicelleModel", 144 { 145 "phi": "axis_phi", 146 "sld_core": "core_sld", 147 "sld_rim": "rim_sld", 148 "thick_face": "face_thick", 149 "sld_solvent": "solvent_sld", 150 "thick_rim": "rim_thick", 151 "sld_face": "face_sld", 152 "theta": "axis_theta" 153 } 154 ], 155 "core_shell_cylinder": [ 156 "CoreShellCylinderModel", 157 { 158 "theta": "axis_theta", 159 "phi": "axis_phi", 160 "sld_shell": "shell_sld", 161 "sld_solvent": "solvent_sld", 162 "sld_core": "core_sld" 163 } 164 ], 165 "core_shell_ellipsoid:1": [ 166 "CoreShellEllipsoidModel", 167 { 168 "sld_core": "sld_core", 169 "sld_shell": "sld_shell", 170 "sld_solvent": "sld_solvent", 171 "radius_equat_core": "equat_core", 172 "x_core": "polar_core", 173 "thick_shell": "equat_shell", 174 "x_polar_shell": "polar_shell", 175 "theta": "axis_theta", 176 "phi": "axis_phi", 177 } 178 ], 179 "core_shell_ellipsoid": [ 180 "CoreShellEllipsoidXTModel", 181 { 182 "sld_core": "sld_core", 183 "sld_shell": "sld_shell", 184 "sld_solvent": "sld_solvent", 185 "radius_equat_core": "equat_core", 186 "thick_shell": "T_shell", 187 "x_core": "X_core", 188 "x_polar_shell": "XpolarShell", 189 "theta": "axis_theta", 190 "phi": "axis_phi", 191 } 192 ], 193 "core_shell_parallelepiped": [ 194 "CSParallelepipedModel", 195 { 196 "sld_core": "sld_pcore", 197 "sld_a": "sld_rimA", 198 "sld_b": "sld_rimB", 199 "sld_c": "sld_rimC", 200 "sld_solvent": "sld_solv", 201 "length_a": "shortA", 202 "length_b": "midB", 203 "length_c": "longC", 204 "thick_rim_a": "rimA", 205 "thick_rim_c": "rimC", 206 "thick_rim_b": "rimB", 207 "theta": "parallel_theta", 208 "phi": "parallel_phi", 209 "psi": "parallel_psi", 210 } 211 ], 212 "core_shell_sphere": [ 213 "CoreShellModel", 214 { 215 "sld_core": "core_sld", 216 "sld_shell": "shell_sld", 217 "sld_solvent": "solvent_sld", 218 "M0:sld_core": "M0_sld_core", 219 "mtheta:sld_core": "M_theta_core", 220 "mphi:sld_core": "M_phi_core", 221 "M0:sld_shell": "M0_sld_shell", 222 "mtheta:sld_shell": "M_theta_shell", 223 "mphi:sld_shell": "M_phi_shell", 224 "M0:sld_solvent": "M0_sld_solv", 225 "mtheta:sld_solvent": "M_theta_solv", 226 "mphi:sld_solvent": "M_phi_solv", 227 "up:frac_i": "Up_frac_i", 228 "up:frac_f": "Up_frac_f", 229 "up:angle": "Up_theta" 230 } 231 ], 232 "correlation_length": [ 233 "CorrLength", 234 { 235 "porod_scale": "scale_p", 236 "lorentz_scale": "scale_l", 237 "porod_exp": "exponent_p", 238 "lorentz_exp": "exponent_l", 239 "cor_length": "length_l" 240 }, 241 "CorrLengthModel" 242 ], 243 "cylinder": [ 244 "CylinderModel", 245 { 246 "sld": "sldCyl", 247 "theta": "cyl_theta", 248 "phi": "cyl_phi", 249 "sld_solvent": "sldSolv", 250 "M0:sld": "M0_sld_cyl", 251 "mtheta:sld": "M_theta_cyl", 252 "mphi:sld": "M_phi_cyl", 253 "M0:sld_solvent": "M0_sld_solv", 254 "mtheta:sld_solvent": "M_theta_solv", 255 "mphi:sld_solvent": "M_phi_solv", 256 "up:frac_i": "Up_frac_i", 257 "up:frac_f": "Up_frac_f", 258 "up:angle": "Up_theta" 259 } 260 ], 261 "dab": [ 262 "DABModel", 263 { 264 "cor_length": "length" 265 } 266 ], 267 "ellipsoid": [ 268 "EllipsoidModel", 269 { 270 "phi": "axis_phi", 271 "radius_equatorial": "radius_b", 272 "sld": "sldEll", 273 "theta": "axis_theta", 274 "radius_polar": "radius_a", 275 "sld_solvent": "sldSolv" 276 } 277 ], 278 "elliptical_cylinder": [ 279 "EllipticalCylinderModel", 280 { 281 "axis_ratio": "r_ratio", 282 "radius_minor": "r_minor", 283 "sld": "sldCyl", 284 "sld_solvent": "sldSolv", 285 "theta": "cyl_theta", 286 "phi": "cyl_phi", 287 "psi": "cyl_psi", 288 } 289 ], 290 "fcc_paracrystal": [ 291 "FCCrystalModel", 292 { 293 "sld": "sldSph", 294 "sld_solvent": "sldSolv" 295 } 296 ], 297 "flexible_cylinder": [ 298 "FlexibleCylinderModel", 299 { 300 "sld": "sldCyl", 301 "sld_solvent": "sldSolv" 302 } 303 ], 304 "flexible_cylinder_elliptical": [ 305 "FlexCylEllipXModel", 306 { 307 "sld": "sldCyl", 308 "sld_solvent": "sldSolv" 309 } 310 ], 311 "fractal": [ 312 "FractalModel", 313 { 314 "sld_block": "sldBlock", 315 "radius": "radius", 316 "cor_length": "cor_length", 317 "sld_solvent": "sldSolv", 318 "fractal_dim": "fractal_dim" 319 } 320 ], 321 "fractal_core_shell": [ 322 "FractalCoreShell", 323 { 324 "sld_core": "core_sld", 325 "sld_shell": "shell_sld", 326 "sld_solvent": "solvent_sld", 327 "radius": "radius", 328 "thickness": "thickness", 329 "fractal_dim": "frac_dim", 330 "cor_length": "cor_length", 331 "volfraction": "volfraction", 332 }, 333 "FractalCoreShellModel" 334 ], 335 "fuzzy_sphere": [ 336 "FuzzySphereModel", 337 { 338 "sld": "sldSph", 339 "fuzziness": "fuzziness", 340 "radius": "radius", 341 "sld_solvent": "sldSolv" 342 } 343 ], 344 "gauss_lorentz_gel": [ 345 "GaussLorentzGel", 346 { 347 "gauss_scale": "scale_g", 348 "cor_length_dynamic": "dyn_colength", 349 "cor_length_static": "stat_colength", 350 "background": "background", 351 "lorentz_scale": "scale_l" 352 }, 353 "GaussLorentzGelModel" 354 ], 355 "gaussian_peak": [ 356 "Peak Gauss Model", 357 { 358 "peak_pos": "q0", 359 "sigma": "B", 360 }, 361 "PeakGaussModel", 362 ], 363 "gel_fit": [ 364 "GelFitModel", 365 { 366 "rg": "radius", 367 "lorentz_scale": "lScale", 368 "guinier_scale": "gScale", 369 "fractal_dim": "FractalExp", 370 "cor_length": "zeta", 371 } 372 ], 373 "guinier": [ 374 "Guinier", 375 { 376 "rg": "rg" 377 }, 378 "GuinierModel", 379 ], 380 "guinier_porod": [ 381 "GuinierPorod", 382 { 383 "s": "dim", 384 "rg": "rg", 385 "porod_exp": "m", 386 "scale": "scale", 387 "background": "background" 388 }, 389 "GuinierPorodModel", 390 ], 391 "hardsphere": [ 392 "HardsphereStructure", 393 { 394 "scale": "scale_factor", 395 "radius_effective": "effect_radius", 396 } 397 ], 398 "hayter_msa": [ 399 "HayterMSAStructure", 400 { 401 "scale": "scale_factor", 402 "radius_effective": "effect_radius", 403 "volfraction": "volfraction", 404 "charge": "charge", 405 "temperature": "temperature", 406 "concentration_salt": "saltconc", 407 "dielectconst": "dielectconst", 408 } 409 ], 410 "hollow_cylinder": [ 411 "HollowCylinderModel", 412 { 413 "sld": "sldCyl", 414 "sld_solvent": "sldSolv", 415 "radius": "core_radius", 416 "thickness": "radius", 417 "length": "length", 418 "theta": "axis_theta", 419 "phi": "axis_phi", 420 } 421 ], 422 "hollow_rectangular_prism": [ 423 "RectangularHollowPrismModel", 424 { 425 "sld": "sldPipe", 426 "sld_solvent": "sldSolv", 427 "length_a": "short_side", 428 "b2a_ratio": "b2a_ratio", 429 "c2a_ratio": "c2a_ratio", 430 "thickness": "thickness", 431 } 432 ], 433 "hollow_rectangular_prism_thin_walls": [ 434 "RectangularHollowPrismInfThinWallsModel", 435 { 436 "sld": "sldPipe", 437 "sld_solvent": "sldSolv", 438 "length_a": "short_side", 439 "b2a_ratio": "b2a_ratio", 440 "c2a_ratio": "c2a_ratio", 441 } 442 ], 443 "lamellar": [ 444 "LamellarModel", 445 { 446 "sld": "sld_bi", 447 "sld_solvent": "sld_sol", 448 "thickness": "bi_thick" 449 } 450 ], 451 "lamellar_hg": [ 452 "LamellarFFHGModel", 453 { 454 "sld": "sld_tail", 455 "sld_solvent": "sld_solvent", 456 "sld_head": "sld_head", 457 "length_tail": "t_length", 458 "length_head": "h_thickness" 459 } 460 ], 461 "lamellar_hg_stack_caille": [ 462 "LamellarPSHGModel", 463 { 464 "sld": "sld_tail", 465 "sld_head": "sld_head", 466 "sld_solvent": "sld_solvent", 467 "length_tail": "deltaT", 468 "length_head": "deltaH", 469 "d_spacing": "spacing", 470 "Caille_parameter": "caille", 471 "Nlayers": "n_plates", 472 } 473 ], 474 "lamellar_stack_caille": [ 475 "LamellarPSModel", 476 { 477 "sld": "sld_bi", 478 "sld_solvent": "sld_sol", 479 "thickness": "delta", 480 "d_spacing": "spacing", 481 "Caille_parameter": "caille", 482 "Nlayers": "n_plates", 483 } 484 ], 485 "lamellar_stack_paracrystal": [ 486 "LamellarPCrystalModel", 487 { 488 "sld": "sld_layer", 489 "sld_solvent": "sld_solvent", 490 "thickness": "thickness", 491 "d_spacing": "spacing", 492 "sigma_d": "pd_spacing", 493 "Nlayers": "Nlayers", 494 } 495 ], 496 "line": [ 497 "LineModel", 498 { 499 "slope": "B", 500 "scale": None, 501 "background": None, 502 "intercept": "A" 503 } 504 ], 505 "linear_pearls": [ 506 "LinearPearlsModel", 507 { 508 "sld": "sld_pearl", 509 "sld_solvent": "sld_solv", 510 "edge_sep": "edge_separation" 511 } 512 ], 513 "lorentz": [ 514 "Lorentz", 515 { 516 "cor_length": "length" 517 }, 518 "LorentzModel", 519 ], 520 "mass_fractal": [ 521 "MassFractalModel", 522 { 523 "cutoff_length": "co_length", 524 "radius": "radius", 525 "fractal_dim_mass": "mass_dim" 526 } 527 ], 528 "mass_surface_fractal": [ 529 "MassSurfaceFractal", 530 { 531 "rg_cluster": "cluster_rg", 532 "fractal_dim_mass": "mass_dim", 533 "radius": "radius", 534 "fractal_dim_surf": "surface_dim", 535 "rg_primary": "primary_rg" 536 } 537 ], 538 "mono_gauss_coil": [ 539 "Debye", 540 { 541 "rg": "rg", 542 "i_zero": "scale", 543 "background": "background", 544 }, 545 "DebyeModel", 546 ], 547 "multilayer_vesicle": [ 548 "MultiShellModel", 549 { 550 "radius": "core_radius", 551 "sld_solvent": "core_sld", 552 "n_shells": "n_pairs", 553 "thick_shell": "s_thickness", 554 "sld": "shell_sld", 555 "thick_solvent": "w_thickness", 556 } 557 ], 558 "onion": [ 559 "OnionExpShellModel", 560 { 561 "n_shells": "n_shells", 562 "A": "A_shell", 563 "sld_core": "sld_core0", 564 "radius_core": "rad_core0", 565 "sld_solvent": "sld_solv", 566 "thickness": "thick_shell", 567 "sld_in": "sld_in_shell", 568 "sld_out": "sld_out_shell" 569 } 570 ], 571 "parallelepiped": [ 572 "ParallelepipedModel", 573 { 574 "phi": "parallel_phi", 575 "psi": "parallel_psi", 576 "sld_solvent": "sldSolv", 577 "length_a": "short_a", 578 "length_b": "short_b", 579 "sld": "sldPipe", 580 "theta": "parallel_theta", 581 "length_c": "long_c", 582 "M0:sld": "M0_sld_pipe", 583 "mtheta:sld": "M_theta_pipe", 584 "mphi:sld": "M_phi_pipe", 585 "M0:sld_solvent": "M0_sld_solv", 586 "mtheta:sld_solvent": "M_theta_solv", 587 "mphi:sld_solvent": "M_phi_solv", 588 "up:frac_i": "Up_frac_i", 589 "up:frac_f": "Up_frac_f", 590 "up:angle": "Up_theta", 591 } 592 ], 593 "peak_lorentz": [ 594 "Peak Lorentz Model", 595 { 596 "peak_pos": "q0", 597 "peak_hwhm": "B" 598 }, 599 "PeakLorentzModel", 600 ], 601 "pearl_necklace": [ 602 "PearlNecklaceModel", 603 { 604 "scale": "scale", 605 "thick_string": "thick_string", 606 "sld_string": "sld_string", 607 "sld_solvent": "sld_solv", 608 "edge_sep": "edge_separation", 609 "num_pearls": "num_pearls", 610 "radius": "radius", 611 "background": "background", 612 "sld": "sld_pearl" 613 } 614 ], 615 "poly_gauss_coil": [ 616 "Poly_GaussCoil", 617 { 618 "rg": "rg", 619 "polydispersity": "poly_m", 620 "i_zero": "scale", 621 "background": "background", 622 } 623 ], 624 "polymer_excl_volume": [ 625 "PolymerExclVolume", 626 { 627 "rg": "rg", 628 "scale": "scale", 629 "background": "background", 630 "porod_exp": "m" 631 } 632 ], 633 "polymer_micelle": [ 634 "MicelleSphCoreModel", 635 { 636 "sld_corona": "rho_corona", 637 "sld_solvent": "rho_solv", 638 "sld_core": "rho_core", 639 "ndensity": "ndensity", 640 "v_core": "v_core", 641 "v_corona": "v_corona", 642 "radius_core": "radius_core", 643 "rg": "radius_gyr", 644 "d_penetration": "d_penetration", 645 "n_aggreg": "n_aggreg", 646 } 647 ], 648 "porod": [ 649 "PorodModel", 650 { 651 "scale": "scale", 652 "background": "background" 653 } 654 ], 655 "power_law": [ 656 "PowerLawAbsModel", 657 { 658 "scale": "scale", 659 "background": "background", 660 "power": "m" 661 } 662 ], 663 "pringle": [ 664 "PringlesModel", 665 { 666 "scale": "scale", 667 "sld_solvent": "sld_solvent", 668 "thickness": "thickness", 669 "beta": "beta", 670 "radius": "radius", 671 "background": "background", 672 "alpha": "alpha", 673 "sld": "sld_pringle" 674 } 675 ], 676 "raspberry": [ 677 "RaspBerryModel", 678 { 679 "volfraction_lg": "volf_Lsph", 680 "volfraction_sm": "volf_Ssph", 681 "radius_sm": "radius_Ssph", 682 "radius_lg": "radius_Lsph", 683 "sld_lg": "sld_Lsph", 684 "sld_sm": "sld_Ssph", 685 "sld_solvent": "sld_solv", 686 "surface_fraction": "surfrac_Ssph", 687 "penetration": "delta_Ssph" 688 } 689 ], 690 "rectangular_prism": [ 691 "RectangularPrismModel", 692 { 693 "sld": "sldPipe", 694 "length_a": "short_side", 695 "b2a_ratio": "b2a_ratio", 696 "c2a_ratio": "c2a_ratio", 697 "sld_solvent": "sldSolv" 698 } 699 ], 700 "rpa": [ 701 "RPA10Model", 702 { 703 "K12": "Kab", "K13": "Kac", "K14": "Kad", 704 "K23": "Kbc", "K24": "Kbd", "K34": "Kcd", 705 "N1": "Na", "N2": "Nb", "N3": "Nc", "N4": "Nd", 706 "L1": "La", "L2": "Lb", "L3": "Lc", "L4": "Ld", 707 "v1": "va", "v2": "vb", "v3": "vc", "v4": "vd", 708 "b1": "ba", "b2": "bb", "b3": "bc", "b4": "bd", 709 "Phi1": "Phia", "Phi2": "Phib", "Phi3": "Phic", "Phi4": "Phid", 710 "case_num": "lcase_n" 711 } 712 ], 713 "sc_paracrystal": [ 714 "SCCrystalModel", 715 { 716 "sld": "sldSph", 717 "sld_solvent": "sldSolv" 718 } 719 ], 720 "sphere": [ 721 "SphereModel", 722 { 723 "sld": "sldSph", 724 "radius": "radius", 725 "sld_solvent": "sldSolv", 726 "M0:sld": "M0_sld_sph", 727 "mtheta:sld": "M_theta_sph", 728 "mphi:sld": "M_phi_sph", 729 "M0:sld_solvent": "M0_sld_solv", 730 "mtheta:sld_solvent": "M_theta_solv", 731 "mphi:sld_solvent": "M_phi_solv", 732 "up:frac_i": "Up_frac_i", 733 "up:frac_f": "Up_frac_f", 734 "up:angle": "Up_theta" 735 } 736 ], 737 "spherical_sld": [ 738 "SphericalSLDModel", 739 # Be lazy and use a generator expression to define 740 # sld1: sld_flat0, ... 741 # thickness1: thick_flat0, ... 742 # interface1: thick_inter0, ... 743 # shape1: func_inter0, ... 744 # nu1: nu_inter0, ... 745 # but override thickness1 => rad_cor0 and sld1 => sld_core0. 746 # Note: explicit key,value pairs given by **{...} override the 747 # keys from the gnerator expression ((k,v) for k,v in seq) when 748 # used as dict((generator), **{...}) 749 dict(((field_new+str(index+1), field_old+str(index)) 750 for field_new, field_old in [("sld", "sld_flat"), 751 ("thickness", "thick_flat"), 752 ("interface", "thick_inter"), 753 ("shape", "func_inter"), 754 ("nu", "nu_inter"),] 755 for index in range(11)), 756 **{ 757 "n_shells": "n_shells", 758 "n_steps": "npts_inter", 759 "sld_solvent": "sld_solv", 760 "thickness1": "rad_core0", 761 "sld1": "sld_core0", 762 }) 763 ], 764 "squarewell": [ 765 "SquareWellStructure", 766 { 767 "scale": "scale_factor", 768 "radius_effective": "effect_radius", 769 "wellwidth": "wellwidth", 770 "welldepth": "welldepth", 771 } 772 ], 773 "stacked_disks": [ 774 "StackedDisksModel", 775 { 776 "phi": "axis_phi", 777 "sld_layer": "layer_sld", 778 "sld_core": "core_sld", 779 "theta": "axis_theta", 780 "sld_solvent": "solvent_sld", 781 "n_stacking": "n_stacking", 782 "thick_layer": "layer_thick", 783 "thick_core": "core_thick", 784 } 785 ], 786 "star_polymer": [ 787 "StarPolymer", 788 { 789 "arms": "arms", 790 "rg_squared": "R2" 791 } 792 ], 793 "stickyhardsphere": [ 794 "StickyHSStructure", 795 { 796 "scale": "scale_factor", 797 "radius_effective": "effect_radius", 798 } 799 ], 800 "surface_fractal": [ 801 "SurfaceFractalModel", 802 { 803 "cutoff_length": "co_length", 804 "radius": "radius", 805 "fractal_dim_surf": "surface_dim" 806 } 807 ], 808 "teubner_strey": [ 809 "TeubnerStreyModel", 810 { 811 # Note: parameters are completely rewritten in convert.py 812 "volfraction_a": "volfraction_a", 813 "sld_a": "sld_a", 814 "sld_b": "sld_b", 815 "d": "d", 816 "xi": "xi", 817 } 818 ], 819 "triaxial_ellipsoid": [ 820 "TriaxialEllipsoidModel", 821 { 822 "phi": "axis_phi", 823 "radius_equat_minor": "semi_axisA", 824 "radius_polar": "semi_axisC", 825 "radius_equat_major": "semi_axisB", 826 "sld_solvent": "sldSolv", 827 "psi": "axis_psi", 828 "sld": "sldEll", 829 "theta": "axis_theta" 830 } 831 ], 832 "two_lorentzian": [ 833 "TwoLorentzian", 834 { 835 "lorentz_scale_1": "scale_1", 836 "lorentz_scale_2": "scale_2", 837 "lorentz_exp_1": "exponent_1", 838 "lorentz_exp_2": "exponent_2", 839 "lorentz_length_2": "length_2", 840 "lorentz_length_1": "length_1", 841 "background": "background" 842 }, 843 "TwoLorentzianModel", 844 ], 845 "two_power_law": [ 846 "TwoPowerLaw", 847 { 848 "coefficent_1": "coef_A", 849 "power_2": "power2", 850 "power_1": "power1", 851 "background": "background", 852 "crossover": "qc" 853 }, 854 "TwoPowerLawModel", 855 ], 856 "unified_power_Rg": [ 857 "UnifiedPowerRg", 858 dict(((field_new+str(index), field_old+str(index)) 859 for field_new, field_old in [("rg", "Rg"), 860 ("power", "power"), 861 ("G", "G"), 862 ("B", "B"),] 863 for index in range(11)), 864 **{ 865 "background": "background", 866 "scale": "scale", 867 }), 868 "UnifiedPowerRgModel", 869 ], 870 "vesicle": [ 871 "VesicleModel", 872 { 873 "sld": "shell_sld", 874 "sld_solvent": "solv_sld" 875 } 876 ] 877 877 } 878 878 } -
sasmodels/convert.py
r07c8d46 r2d81cfe 4 4 from __future__ import print_function, division 5 5 6 import re7 6 import math 8 7 import warnings 8 9 import numpy as np 9 10 10 11 from .conversion_table import CONVERSION_TABLE … … 64 65 return [pk*scale for pk in par] if isinstance(par, list) else par*scale 65 66 66 def _is_sld(model_info, id):67 def _is_sld(model_info, par): 67 68 """ 68 69 Return True if parameter is a magnetic magnitude or SLD parameter. 69 70 """ 70 if id.startswith('M0:'):71 if par.startswith('M0:'): 71 72 return True 72 if '_pd' in id or '.' in id:73 if '_pd' in par or '.' in par: 73 74 return False 74 75 for p in model_info.parameters.call_parameters: 75 if p.id == id:76 if p.id == par: 76 77 return p.type == 'sld' 77 78 # check through kernel parameters in case it is a named as a vector 78 79 for p in model_info.parameters.kernel_parameters: 79 if p.id == id:80 if p.id == par: 80 81 return p.type == 'sld' 81 82 return False … … 88 89 *scale=1e-6*. For forward conversion use *scale=1e6*. 89 90 """ 90 return dict(( id, (_rescale(v, scale) if _is_sld(model_info, id) else v))91 for id, v in pars.items())92 93 94 def _get_translation_table(model_info, version=(3, 1,2)):91 return dict((par, (_rescale(v, scale) if _is_sld(model_info, par) else v)) 92 for par, v in pars.items()) 93 94 95 def _get_translation_table(model_info, version=(3, 1, 2)): 95 96 conv_param = CONVERSION_TABLE.get(version, {}).get(model_info.id, [None, {}]) 96 97 translation = conv_param[1].copy() … … 130 131 newpars = pars.copy() 131 132 for new, old in mapping.items(): 132 if old == new: continue 133 if old is None: continue 134 for underscore, dot in PD_DOT: 133 if old == new: 134 continue 135 if old is None: 136 continue 137 for _, dot in PD_DOT: 135 138 source = old+dot 136 139 if source in newpars: … … 145 148 return newpars 146 149 147 def _conversion_target(model_name, version=(3, 1,2)):150 def _conversion_target(model_name, version=(3, 1, 2)): 148 151 """ 149 152 Find the sasmodel name which translates into the sasview name. … … 159 162 return None 160 163 161 def _hand_convert(name, oldpars, version=(3, 1,2)):162 if version == (3, 1,2):164 def _hand_convert(name, oldpars, version=(3, 1, 2)): 165 if version == (3, 1, 2): 163 166 oldpars = _hand_convert_3_1_2_to_4_1(name, oldpars) 164 167 return oldpars … … 272 275 p_scale = oldpars['scale'] 273 276 p_c1 = oldpars['c1'] 274 p_c2 = oldpars['c2']277 p_c2 = oldpars['c2'] 275 278 i_1 = 0.5*p_c1/p_c2 276 279 i_2 = math.sqrt(math.fabs(p_scale/p_c2)) … … 295 298 return oldpars 296 299 297 def convert_model(name, pars, use_underscore=False, model_version=(3, 1,2)):300 def convert_model(name, pars, use_underscore=False, model_version=(3, 1, 2)): 298 301 """ 299 302 Convert model from old style parameter names to new style. … … 327 330 newpars = _convert_pars(newpars, translation) 328 331 # TODO: Still not convinced this is the best check 329 if not model_info.structure_factor and version == (3, 1,2):332 if not model_info.structure_factor and version == (3, 1, 2): 330 333 newpars = _rescale_sld(model_info, newpars, 1e6) 331 334 newpars.setdefault('scale', 1.0) … … 599 602 600 603 pars = compare.get_pars(model_info, use_demo=False) 601 pars = compare.randomize_pars(model_info, pars, seed=seed) 604 if seed is not None: 605 np.random.seed(seed) 606 pars = compare.randomize_pars(model_info, pars) 602 607 if name == "teubner_strey": 603 608 # T-S model is underconstrained, so fix the assumptions. … … 615 620 print("==== %s out ====="%new_name) 616 621 print(str(compare.parlist(model_info, new_pars, True))) 617 assert name ==new_name, "%r != %r"%(name, new_name)622 assert name == new_name, "%r != %r"%(name, new_name) 618 623 for k, v in new_pars.items(): 619 624 assert k in pars, "%s: %r appeared from conversion"%(name, k) 620 625 if isinstance(v, float): 621 assert abs(v-pars[k])<=abs(1e-12*v), "%s: %r %s != %s"%(name, k, v, pars[k]) 626 assert abs(v-pars[k]) <= abs(1e-12*v), \ 627 "%s: %r %s != %s"%(name, k, v, pars[k]) 622 628 else: 623 629 assert v == pars[k], "%s: %r %s != %s"%(name, k, v, pars[k]) -
sasmodels/core.py
r9e771a3 r2d81cfe 10 10 11 11 import os 12 from os.path import basename, join as joinpath 13 from glob import glob 12 14 import re 13 from os.path import basename, dirname, join as joinpath14 from glob import glob15 15 16 16 import numpy as np # type: ignore … … 35 35 CUSTOM_MODEL_PATH = os.environ.get('SAS_MODELPATH', "") 36 36 if CUSTOM_MODEL_PATH == "": 37 path= joinpath(os.path.expanduser("~"), ".sasmodels", "custom_models")38 if not os.path.isdir( path):39 os.makedirs( path)40 CUSTOM_MODEL_PATH = path 41 37 CUSTOM_MODEL_PATH = joinpath(os.path.expanduser("~"), ".sasmodels", "custom_models") 38 if not os.path.isdir(CUSTOM_MODEL_PATH): 39 os.makedirs(CUSTOM_MODEL_PATH) 40 41 # pylint: disable=unused-import 42 42 try: 43 43 from typing import List, Union, Optional, Any … … 46 46 except ImportError: 47 47 pass 48 # pylint: enable=unused-import 48 49 49 50 # TODO: refactor composite model support -
sasmodels/data.py
ra1c5758 r2d81cfe 37 37 import numpy as np # type: ignore 38 38 39 # pylint: disable=unused-import 39 40 try: 40 41 from typing import Union, Dict, List, Optional … … 43 44 else: 44 45 Data = Union["Data1D", "Data2D", "SesansData"] 46 # pylint: enable=unused-import 45 47 46 48 def load_data(filename, index=0): … … 64 66 data.qmin, data.qmax = data.x.min(), data.x.max() 65 67 data.mask = (np.isnan(data.y) if data.y is not None 66 else np.zeros_like(data.x, dtype='bool'))68 else np.zeros_like(data.x, dtype='bool')) 67 69 elif hasattr(data, 'qx_data'): 68 70 data.mask = ~data.mask … … 137 139 *_yaxis*, *_yunit*: label and units for the *y* axis 138 140 """ 139 def __init__(self, x=None, y=None, dx=None, dy=None): 140 # type: (Optional[np.ndarray], Optional[np.ndarray], Optional[np.ndarray], Optional[np.ndarray]) -> None 141 def __init__(self, 142 x=None, # type: Optional[np.ndarray] 143 y=None, # type: Optional[np.ndarray] 144 dx=None, # type: Optional[np.ndarray] 145 dy=None # type: Optional[np.ndarray] 146 ): 147 # type: (...) -> None 141 148 self.x, self.y, self.dx, self.dy = x, y, dx, dy 142 149 self.dxl = None … … 211 218 *x_bins*, *y_bins*: grid steps in *x* and *y* directions 212 219 """ 213 def __init__(self, x=None, y=None, z=None, dx=None, dy=None, dz=None): 214 # type: (Optional[np.ndarray], Optional[np.ndarray], Optional[np.ndarray], Optional[np.ndarray], Optional[np.ndarray], Optional[np.ndarray]) -> None 220 def __init__(self, 221 x=None, # type: Optional[np.ndarray] 222 y=None, # type: Optional[np.ndarray] 223 z=None, # type: Optional[np.ndarray] 224 dx=None, # type: Optional[np.ndarray] 225 dy=None, # type: Optional[np.ndarray] 226 dz=None # type: Optional[np.ndarray] 227 ): 228 # type: (...) -> None 215 229 self.qx_data, self.dqx_data = x, dx 216 230 self.qy_data, self.dqy_data = y, dy … … 369 383 370 384 371 def plot_theory(data, theory, resid=None, view='log', 372 use_data=True, limits=None, Iq_calc=None): 373 # type: (Data, Optional[np.ndarray], Optional[np.ndarray], str, bool, Optional[Tuple[float,float]], Optional[np.ndarray]) -> None 385 def plot_theory(data, # type: Data 386 theory, # type: Optional[np.ndarray] 387 resid=None, # type: Optional[np.ndarray] 388 view='log', # type: str 389 use_data=True, # type: bool 390 limits=None, # type: Optional[np.ndarray] 391 Iq_calc=None # type: Optional[np.ndarray] 392 ): 393 # type: (...) -> None 374 394 """ 375 395 Plot theory calculation. … … 417 437 418 438 @protect 419 def _plot_result1D(data, theory, resid, view, use_data, 420 limits=None, Iq_calc=None): 421 # type: (Data1D, Optional[np.ndarray], Optional[np.ndarray], str, bool, Optional[Tuple[float, float]], Optional[np.ndarray]) -> None 439 def _plot_result1D(data, # type: Data1D 440 theory, # type: Optional[np.ndarray] 441 resid, # type: Optional[np.ndarray] 442 view, # type: str 443 use_data, # type: bool 444 limits=None, # type: Optional[Tuple[float, float]] 445 Iq_calc=None # type: Optional[np.ndarray] 446 ): 447 # type: (...) -> None 422 448 """ 423 449 Plot the data and residuals for 1D data. … … 427 453 428 454 if getattr(data, 'radial', False): 429 radial_data.x = radial_data.q_data430 radial_data.y = radial_data.data455 data.x = data.q_data 456 data.y = data.data 431 457 432 458 use_data = use_data and data.y is not None … … 515 541 516 542 @protect 517 def _plot_result_sesans(data, theory, resid, use_data, limits=None): 518 # type: (SesansData, Optional[np.ndarray], Optional[np.ndarray], bool, Optional[Tuple[float, float]]) -> None 543 def _plot_result_sesans(data, # type: SesansData 544 theory, # type: Optional[np.ndarray] 545 resid, # type: Optional[np.ndarray] 546 use_data, # type: bool 547 limits=None # type: Optional[Tuple[float, float]] 548 ): 549 # type: (...) -> None 519 550 """ 520 551 Plot SESANS results. … … 527 558 528 559 if use_data or use_theory: 529 is_tof = (data.lam != data.lam[0]).any()560 is_tof = data.lam is not None and (data.lam != data.lam[0]).any() 530 561 if num_plots > 1: 531 562 plt.subplot(1, num_plots, 1) … … 560 591 561 592 @protect 562 def _plot_result2D(data, theory, resid, view, use_data, limits=None): 563 # type: (Data2D, Optional[np.ndarray], Optional[np.ndarray], str, bool, Optional[Tuple[float,float]]) -> None 593 def _plot_result2D(data, # type: Data2D 594 theory, # type: Optional[np.ndarray] 595 resid, # type: Optional[np.ndarray] 596 view, # type: str 597 use_data, # type: bool 598 limits=None # type: Optional[Tuple[float, float]] 599 ): 600 # type: (...) -> None 564 601 """ 565 602 Plot the data and residuals for 2D data. … … 621 658 622 659 @protect 623 def _plot_2d_signal(data, signal, vmin=None, vmax=None, view='log'): 624 # type: (Data2D, np.ndarray, Optional[float], Optional[float], str) -> Tuple[float, float] 660 def _plot_2d_signal(data, # type: Data2D 661 signal, # type: np.ndarray 662 vmin=None, # type: Optional[float] 663 vmax=None, # type: Optional[float] 664 view='log' # type: str 665 ): 666 # type: (...) -> Tuple[float, float] 625 667 """ 626 668 Plot the target value for the data. This could be the data itself, … … 637 679 if view == 'log': 638 680 valid[valid] = (image[valid] > 0) 639 if vmin is None: vmin = image[valid & ~data.mask].min() 640 if vmax is None: vmax = image[valid & ~data.mask].max() 681 if vmin is None: 682 vmin = image[valid & ~data.mask].min() 683 if vmax is None: 684 vmax = image[valid & ~data.mask].max() 641 685 image[valid] = np.log10(image[valid]) 642 686 elif view == 'q4': 643 687 image[valid] *= (data.qx_data[valid]**2+data.qy_data[valid]**2)**2 644 if vmin is None: vmin = image[valid & ~data.mask].min() 645 if vmax is None: vmax = image[valid & ~data.mask].max() 688 if vmin is None: 689 vmin = image[valid & ~data.mask].min() 690 if vmax is None: 691 vmax = image[valid & ~data.mask].max() 646 692 else: 647 if vmin is None: vmin = image[valid & ~data.mask].min() 648 if vmax is None: vmax = image[valid & ~data.mask].max() 693 if vmin is None: 694 vmin = image[valid & ~data.mask].min() 695 if vmax is None: 696 vmax = image[valid & ~data.mask].max() 649 697 650 698 image[~valid | data.mask] = 0 … … 655 703 ymin, ymax = min(data.qy_data), max(data.qy_data) 656 704 if view == 'log': 657 vmin_scaled, vmax_scaled = np.log10(vmin), np.log10(vmax)705 vmin_scaled, vmax_scaled = np.log10(vmin), np.log10(vmax) 658 706 else: 659 707 vmin_scaled, vmax_scaled = vmin, vmax -
sasmodels/details.py
rce99754 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: … … 23 23 # CRUFT: np.meshgrid requires multiple vectors 24 24 def meshgrid(*args): 25 """See docs from a recent version of numpy""" 25 26 if len(args) > 1: 26 27 return np.meshgrid(*args) … … 28 29 return [np.asarray(v) for v in args] 29 30 31 # pylint: disable=unused-import 30 32 try: 31 33 from typing import List, Tuple, Sequence … … 35 37 from .modelinfo import ModelInfo 36 38 from .modelinfo import ParameterTable 39 # pylint: enable=unused-import 37 40 38 41 … … 219 222 220 223 ZEROS = tuple([0.]*31) 221 def make_kernel_args(kernel, mesh): 222 # 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] 223 228 """ 224 229 Converts (value, dispersity, weight) for each parameter into kernel pars. … … 231 236 npars = kernel.info.parameters.npars 232 237 nvalues = kernel.info.parameters.nvalues 233 scalars = [value for value, dispersity,weight in mesh]238 scalars = [value for value, _dispersity, _weight in mesh] 234 239 # skipping scale and background when building values and weights 235 values, dispersity, weights = zip(*mesh[2:npars+2]) if npars else ((), (), ())240 _values, dispersity, weights = zip(*mesh[2:npars+2]) if npars else ((), (), ()) 236 241 #weights = correct_theta_weights(kernel.info.parameters, dispersity, weights) 237 242 length = np.array([len(w) for w in weights]) … … 247 252 return call_details, data, is_magnetic 248 253 249 def correct_theta_weights(parameters, dispersity, weights): 250 # 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] 251 259 """ 252 260 If there is a theta parameter, update the weights of that parameter so that … … 287 295 mag = values[parameters.nvalues-3*parameters.nmagnetic:parameters.nvalues] 288 296 mag = mag.reshape(-1, 3) 289 scale = mag[:, 0]297 scale = mag[:, 0] 290 298 if np.any(scale): 291 299 theta, phi = radians(mag[:, 1]), radians(mag[:, 2]) -
sasmodels/direct_model.py
r9e771a3 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 … … 175 177 dispersity, weight = dispersion_mesh(model_info, vol_pars) 176 178 return dispersity, weight 179 180 181 def _make_sesans_transform(data): 182 from sas.sascalc.data_util.nxsunit import Converter 183 184 # Pre-compute the Hankel matrix (H) 185 SElength = Converter(data._xunit)(data.x, "A") 186 187 theta_max = Converter("radians")(data.sample.zacceptance)[0] 188 q_max = 2 * np.pi / np.max(data.source.wavelength) * np.sin(theta_max) 189 zaccept = Converter("1/A")(q_max, "1/" + data.source.wavelength_unit), 190 191 Rmax = 10000000 192 hankel = sesans.SesansTransform(data.x, SElength, 193 data.source.wavelength, 194 zaccept, Rmax) 195 return hankel 177 196 178 197 … … 216 235 217 236 if self.data_type == 'sesans': 218 q = sesans.make_q(data.sample.zacceptance, data.Rmax)237 res = _make_sesans_transform(data) 219 238 index = slice(None, None) 220 res = None221 239 if data.y is not None: 222 240 Iq, dIq = data.y, data.dy … … 224 242 Iq, dIq = None, None 225 243 #self._theory = np.zeros_like(q) 226 q_vectors = [q] 227 q_mono = sesans.make_all_q(data) 244 q_vectors = [res.q_calc] 228 245 elif self.data_type == 'Iqxy': 229 246 #if not model.info.parameters.has_2d: … … 244 261 #self._theory = np.zeros_like(self.Iq) 245 262 q_vectors = res.q_calc 246 q_mono = []247 263 elif self.data_type == 'Iq': 248 264 index = (data.x >= data.qmin) & (data.x <= data.qmax) … … 269 285 #self._theory = np.zeros_like(self.Iq) 270 286 q_vectors = [res.q_calc] 271 q_mono = []272 287 elif self.data_type == 'Iq-oriented': 273 288 index = (data.x >= data.qmin) & (data.x <= data.qmax) … … 286 301 qy_width=data.dxl[index]) 287 302 q_vectors = res.q_calc 288 q_mono = []289 303 else: 290 304 raise ValueError("Unknown data type") # never gets here … … 293 307 # so we can save/restore state 294 308 self._kernel_inputs = q_vectors 295 self._kernel_mono_inputs = q_mono296 309 self._kernel = None 297 310 self.Iq, self.dIq, self.index = Iq, dIq, index … … 331 344 if self._kernel is None: 332 345 self._kernel = self._model.make_kernel(self._kernel_inputs) 333 self._kernel_mono = (334 self._model.make_kernel(self._kernel_mono_inputs)335 if self._kernel_mono_inputs else None)336 346 337 347 Iq_calc = call_kernel(self._kernel, pars, cutoff=cutoff) … … 341 351 # TODO: refactor so we don't store the result in the model 342 352 self.Iq_calc = Iq_calc 343 if self.data_type == 'sesans': 344 Iq_mono = (call_kernel(self._kernel_mono, pars, mono=True) 345 if self._kernel_mono_inputs else None) 346 result = sesans.transform(self._data, 347 self._kernel_inputs[0], Iq_calc, 348 self._kernel_mono_inputs, Iq_mono) 349 else: 350 result = self.resolution.apply(Iq_calc) 351 if hasattr(self.resolution, 'nx'): 352 self.Iq_calc = ( 353 self.resolution.qx_calc, self.resolution.qy_calc, 354 np.reshape(Iq_calc, (self.resolution.ny, self.resolution.nx)) 355 ) 353 result = self.resolution.apply(Iq_calc) 354 if hasattr(self.resolution, 'nx'): 355 self.Iq_calc = ( 356 self.resolution.qx_calc, self.resolution.qy_calc, 357 np.reshape(Iq_calc, (self.resolution.ny, self.resolution.nx)) 358 ) 356 359 return result 357 360 … … 410 413 try: 411 414 values = [float(v) for v in call.split(',')] 412 except Exception:415 except ValueError: 413 416 values = [] 414 417 if len(values) == 1: -
sasmodels/generate.py
rff31782 ra261a83 163 163 164 164 import sys 165 from os.path import abspath, dirname, join as joinpath, exists, isdir,getmtime165 from os.path import abspath, dirname, join as joinpath, exists, getmtime 166 166 import re 167 167 import string … … 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 … … 672 674 line instead. 673 675 """ 674 for path, code in sources:676 for _path, code in sources: 675 677 if _IQXY_PATTERN.search(code): 676 678 return True 677 else: 678 return False 679 return False 679 680 680 681 … … 790 791 # TODO: allow mixed python/opencl kernels? 791 792 792 ocl = kernels(kernel_code, call_iq, call_iqxy, clear_iqxy, model_info.name)793 dll = kernels(kernel_code, call_iq, call_iqxy, clear_iqxy, model_info.name)793 ocl = _kernels(kernel_code, call_iq, call_iqxy, clear_iqxy, model_info.name) 794 dll = _kernels(kernel_code, call_iq, call_iqxy, clear_iqxy, model_info.name) 794 795 result = { 795 796 'dll': '\n'.join(source+dll[0]+dll[1]+dll[2]), … … 800 801 801 802 802 def kernels(kernel, call_iq, call_iqxy, clear_iqxy, name):803 def _kernels(kernel, call_iq, call_iqxy, clear_iqxy, name): 803 804 # type: ([str,str], str, str, str) -> List[str] 804 805 code = kernel[0] … … 949 950 950 951 def make_html(model_info): 952 # type: (ModelInfo) -> str 951 953 """ 952 954 Convert model docs directly to html. … … 958 960 959 961 def view_html(model_name): 962 # type: (str) -> None 963 """ 964 Load the model definition and view its help. 965 """ 960 966 from . import modelinfo 961 967 kernel_module = load_kernel_module(model_name) … … 964 970 965 971 def view_html_from_info(info): 972 # type: (ModelInfo) -> None 973 """ 974 View the help for a loaded model definition. 975 """ 966 976 from . import rst2html 967 977 url = "file://"+dirname(info.filename)+"/" … … 988 998 Program which prints the source produced by the model. 989 999 """ 990 import sys991 1000 from .modelinfo import make_model_info 992 1001 -
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
r6aee3ab 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 21 from types import ModuleType 20 22 except ImportError: 21 23 pass … … 29 31 TestValue = Union[float, List[float]] 30 32 TestCondition = Tuple[ParameterSetUser, TestInput, TestValue] 33 # pylint: enable=unused-import 31 34 32 35 # If MAX_PD changes, need to change the loop macros in kernel_iq.c … … 499 502 for par in self.call_parameters: 500 503 if par.name == key: 501 break 502 else: 503 raise KeyError("unknown parameter %r"%key) 504 return par 504 return par 505 raise KeyError("unknown parameter %r"%key) 505 506 506 507 def __contains__(self, key): … … 508 509 if par.name == key: 509 510 return True 510 else: 511 return False 511 return False 512 512 513 513 def _set_vector_lengths(self): … … 526 526 """ 527 527 # Sort out the length of the vector parameters such as thickness[n] 528 529 528 for p in self.kernel_parameters: 530 529 if p.length_control: 531 for ref in self.kernel_parameters: 532 if ref.id == p.length_control: 533 break 534 else: 535 raise ValueError("no reference variable %r for %s" 536 % (p.length_control, p.name)) 530 ref = self._get_ref(p) 537 531 ref.is_control = True 538 532 ref.polydisperse = False … … 542 536 % ref.name) 543 537 p.length = int(high) 538 539 def _get_ref(self, p): 540 # type: (Parameter) -> Parameter 541 for ref in self.kernel_parameters: 542 if ref.id == p.length_control: 543 return ref 544 raise ValueError("no reference variable %r for %s" 545 % (p.length_control, p.name)) 544 546 545 547 def _get_defaults(self): … … 714 716 715 717 def _find_source_lines(model_info, kernel_module): 718 # type: (ModelInfo, ModuleType) -> None 716 719 """ 717 720 Identify the location of the C source inside the model definition file. … … 967 970 #: the SESANS correlation function. Note: not currently implemented. 968 971 sesans = None # type: Optional[Callable[[np.ndarray], np.ndarray]] 972 #: Returns a random parameter set for the model 973 random = None # type: Optional[Callable[[], Dict[str, float]]] 969 974 970 975 # line numbers within the python file for bits of C source, if defined -
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_bicelle_elliptical_belt_rough.py
r129bdc4 r110f69c 6 6 core-shell scattering length density profile. Thus this is a variation 7 7 of the core-shell bicelle model, but with an elliptical cylinder for the core. 8 In this version the "rim" or "belt" does NOT extend the full length of the particle,9 but has the same length as the core. 10 Outer shells on the rims and flat ends may be of different thicknesses and 11 scattering lengthdensities. The form factor is normalized by the total particle volume.8 In this version the "rim" or "belt" does NOT extend the full length of 9 the particle, but has the same length as the core. Outer shells on the 10 rims and flat ends may be of different thicknesses and scattering length 11 densities. The form factor is normalized by the total particle volume. 12 12 This version includes an approximate "interfacial roughness". 13 13 … … 15 15 .. figure:: img/core_shell_bicelle_belt_geometry.png 16 16 17 Schematic cross-section of bicelle with belt. Note however that the model here18 calculates for rectangular, not curved, rims as shown below.17 Schematic cross-section of bicelle with belt. Note however that the model 18 here calculates for rectangular, not curved, rims as shown below. 19 19 20 20 .. figure:: img/core_shell_bicelle_belt_parameters.png 21 21 22 Cross section of model used here. Users will have 23 to decide how to distribute "heads" and "tails" between the rim, face 22 Cross section of model used here. Users will have 23 to decide how to distribute "heads" and "tails" between the rim, face 24 24 and core regions in order to estimate appropriate starting parameters. 25 25 … … 30 30 .. math:: 31 31 32 \rho(r) = 33 \begin{cases} 32 \rho(r) = 33 \begin{cases} 34 34 &\rho_c \text{ for } 0 \lt r \lt R; -L/2 \lt z\lt L/2 \\[1.5ex] 35 &\rho_f \text{ for } 0 \lt r \lt R; -(L/2 +t_ {face}) \lt z\lt -L/2;36 L/2 \lt z\lt (L/2+t_ {face}) \\[1.5ex]37 &\rho_r\text{ for } R \lt r \lt R+t_ {rim}; -L/2 \lt z\lt L/235 &\rho_f \text{ for } 0 \lt r \lt R; -(L/2 +t_\text{face}) \lt z\lt -L/2; 36 L/2 \lt z\lt (L/2+t_\text{face}) \\[1.5ex] 37 &\rho_r\text{ for } R \lt r \lt R+t_\text{rim}; -L/2 \lt z\lt L/2 38 38 \end{cases} 39 39 40 40 The form factor for the bicelle is calculated in cylindrical coordinates, where 41 $\alpha$ is the angle between the $Q$ vector and the cylinder axis, and $\psi$ is the angle42 for the ellipsoidal cross section core, to give:41 $\alpha$ is the angle between the $Q$ vector and the cylinder axis, and $\psi$ 42 is the angle for the ellipsoidal cross section core, to give: 43 43 44 44 .. math:: 45 45 46 I(Q,\alpha,\psi) = \frac{\text{scale}}{V_t} \cdot 47 F(Q,\alpha, \psi)^2.sin(\alpha).exp\left \{ -\frac{1}{2}Q^2\sigma^2 \right \} + \text{background} 46 I(Q,\alpha,\psi) = \frac{\text{scale}}{V_t} 47 \cdot F(Q,\alpha, \psi)^2 \cdot \sin(\alpha) 48 \cdot\exp\left\{ -\frac{1}{2}Q^2\sigma^2 \right\} + \text{background} 48 49 49 where a numerical integration of $F(Q,\alpha, \psi)^2.sin(\alpha)$ is carried out over \alpha and \psi for: 50 where a numerical integration of $F(Q,\alpha, \psi)^2\sin(\alpha)$ is 51 carried out over $\alpha$ and $\psi$ for: 50 52 51 53 .. math:: 52 54 53 \begin{align} 54 F(Q,\alpha,\psi) = &\bigg[ 55 (\rho_c -\rho_r - \rho_f + \rho_s) V_c \frac{2J_1(QR'sin \alpha)}{QR'sin\alpha}\frac{sin(QLcos\alpha/2)}{Q(L/2)cos\alpha} \\ 56 &+(\rho_f - \rho_s) 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} \\ 57 &+(\rho_r - \rho_s) V_{c+r} \frac{2J_1(Q(R'+t_r)sin\alpha)}{Q(R'+t_r)sin\alpha}\frac{sin(Q(L/2)cos\alpha)}{Q(L/2)cos\alpha} 55 F(Q,\alpha,\psi) = &\bigg[ 56 (\rho_c -\rho_r - \rho_f + \rho_s) V_c 57 \frac{2J_1(QR'\sin \alpha)}{QR'\sin\alpha} 58 \frac{\sin(QL\cos\alpha/2)}{Q(L/2)\cos\alpha} \\ 59 &+(\rho_f - \rho_s) V_{c+f} 60 \frac{2J_1(QR'\sin\alpha)}{QR'\sin\alpha} 61 \frac{\sin(Q(L/2+t_f)\cos\alpha)}{Q(L/2+t_f)\cos\alpha} \\ 62 &+(\rho_r - \rho_s) V_{c+r} 63 \frac{2J_1(Q(R'+t_r)\sin\alpha)}{Q(R'+t_r)\sin\alpha} 64 \frac{\sin(Q(L/2)\cos\alpha)}{Q(L/2)\cos\alpha} 58 65 \bigg] 59 \end{align}60 66 61 67 where … … 63 69 .. math:: 64 70 65 R'=\frac{R}{\sqrt{2}}\sqrt{(1+X_{core}^{2}) + (1-X_{core}^{2})cos(\psi)} 66 67 68 and $V_t = \pi.(R+t_r)(Xcore.R+t_r).L + 2.\pi.Xcore.R^2.t_f$ is the total volume of the bicelle, 69 $V_c = \pi.Xcore.R^2.L$ the volume of the core, $V_{c+f} = \pi.Xcore.R^2.(L+2.t_f)$ 70 the volume of the core plus the volume of the faces, $V_{c+r} = \pi.(R+t_r)(Xcore.R+t_r),.L$ 71 the volume of the core plus the rim, $R$ is the radius 72 of the core, $Xcore$ is the axial ratio of the core, $L$ the length of the core, 73 $t_f$ the thickness of the face, $t_r$ the thickness of the rim and $J_1$ the usual 74 first order bessel function. The core has radii $R$ and $Xcore.R$ so is circular, 75 as for the core_shell_bicelle model, for $Xcore$ =1. Note that you may need to 76 limit the range of $Xcore$, especially if using the Monte-Carlo algorithm, as 77 setting radius to $R/Xcore$ and axial ratio to $1/Xcore$ gives an equivalent solution! 71 R' = \frac{R}{\sqrt{2}} 72 \sqrt{(1+X_\text{core}^{2}) + (1-X_\text{core}^{2})\cos(\psi)} 78 73 79 An approximation for the effects of "Gaussian interfacial roughness" $\sigma$ is included, 80 by multiplying $I(Q)$ by $exp\left \{ -\frac{1}{2}Q^2\sigma^2 \right \}$ . This 81 applies, in some way, to all interfaces in the model not just the external ones. 82 (Note that for a one dimensional system convolution of the scattering length density profile 83 with a Gaussian of standard deviation $\sigma$ does exactly this multiplication.) Leave 84 $\sigma$ set to zero for the usual sharp interfaces. 74 75 and $V_t = \pi (R+t_r)(X_\text{core} R+t_r) L + 2 \pi X_\text{core} R^2 t_f$ is 76 the total volume of the bicelle, $V_c = \pi X_\text{core} R^2 L$ the volume of 77 the core, $V_{c+f} = \pi X_\text{core} R^2 (L+2 t_f)$ the volume of the core 78 plus the volume of the faces, $V_{c+r} = \pi (R+t_r)(X_\text{core} R+t_r) L$ 79 the volume of the core plus the rim, $R$ is the radius of the core, 80 $X_\text{core}$ is the axial ratio of the core, $L$ the length of the core, 81 $t_f$ the thickness of the face, $t_r$ the thickness of the rim and $J_1$ the 82 usual first order bessel function. The core has radii $R$ and $X_\text{core} R$ 83 so is circular, as for the core_shell_bicelle model, for $X_\text{core}=1$. 84 Note that you may need to limit the range of $X_\text{core}$, especially if 85 using the Monte-Carlo algorithm, as setting radius to $R/X_\text{core}$ and 86 axial ratio to $1/X_\text{core}$ gives an equivalent solution! 87 88 An approximation for the effects of "Gaussian interfacial roughness" $\sigma$ 89 is included, by multiplying $I(Q)$ by 90 $\exp\left \{ -\frac{1}{2}Q^2\sigma^2 \right \}$. This applies, in some way, to 91 all interfaces in the model not just the external ones. (Note that for a one 92 dimensional system convolution of the scattering length density profile with 93 a Gaussian of standard deviation $\sigma$ does exactly this multiplication.) 94 Leave $\sigma$ set to zero for the usual sharp interfaces. 85 95 86 96 The output of the 1D scattering intensity function for randomly oriented 87 97 bicelles is then given by integrating over all possible $\alpha$ and $\psi$. 88 98 89 For oriented bicelles the *theta*, *phi* and *psi* orientation parameters will appear when fitting 2D data, 90 for further details of the calculation and angular dispersions see :ref:`orientation` . 99 For oriented bicelles the *theta*, *phi* and *psi* orientation parameters 100 will appear when fitting 2D data, for further details of the calculation 101 and angular dispersions see :ref:`orientation` . 91 102 92 103 .. figure:: img/elliptical_cylinder_angle_definition.png 93 104 94 Definition of the angles for the oriented core_shell_bicelle_elliptical particles. 105 Definition of the angles for the oriented core_shell_bicelle_elliptical 106 particles. 95 107 96 108 … … 115 127 description = """ 116 128 core_shell_bicelle_elliptical_belt_rough 117 Elliptical cylinder core, optional shell on the two flat faces, and "belt" shell of 129 Elliptical cylinder core, optional shell on the two flat faces, and "belt" shell of 118 130 uniform thickness on its rim (in this case NOT extending around the end faces). 119 131 with approximate interfacial roughness. … … 173 185 174 186 [{'radius': 30.0, 'x_core': 3.0, 'thick_rim':8.0, 'thick_face':14.0, 'length':50.0, 175 'sld_core':4.0, 'sld_face':7.0, 'sld_rim':1.0, 'sld_solvent':6.0, 'background':0.0},176 0.015, 189.328],177 #[{'theta':80., 'phi':10.}, (qx, qy), 7.88866563001 ],178 187 'sld_core':4.0, 'sld_face':7.0, 'sld_rim':1.0, 'sld_solvent':6.0, 'background':0.0}, 188 0.015, 189.328], 189 #[{'theta':80., 'phi':10.}, (qx, qy), 7.88866563001 ], 190 ] 179 191 180 192 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.c
r74768cb ra261a83 43 43 // Code converted from functions CSPPKernel and CSParallelepiped in libCylinder.c 44 44 // Did not understand the code completely, it should be rechecked (Miguel Gonzalez) 45 //Code is rewritten,the code is compliant with Diva Singhs thesis now (Dirk Honecker) 45 // Code is rewritten,the code is compliant with Diva Singhs thesis now (Dirk Honecker) 46 // Code rewritten (PAK) 46 47 47 const double mu = 0.5 * q * length_b;48 const double half_q = 0.5*q; 48 49 49 // Scale sides by B50 const double a_over_b = length_a / length_b;51 const double c_over_b = length_c / length_b;50 const double tA = length_a + 2.0*thick_rim_a; 51 const double tB = length_b + 2.0*thick_rim_b; 52 const double tC = length_c + 2.0*thick_rim_c; 52 53 53 double tA_over_b = a_over_b + 2.0*thick_rim_a/length_b; 54 double tB_over_b = 1+ 2.0*thick_rim_b/length_b; 55 double tC_over_b = c_over_b + 2.0*thick_rim_c/length_b; 56 57 double Vin = length_a * length_b * length_c; 58 #if OVERLAPPING 59 const double capA_area = length_b*length_c; 60 const double capB_area = (length_a+2.*thick_rim_a)*length_c; 61 const double capC_area = (length_a+2.*thick_rim_a)*(length_b+2.*thick_rim_b); 62 #else 63 const double capA_area = length_b*length_c; 64 const double capB_area = length_a*length_c; 65 const double capC_area = length_a*length_b; 66 #endif 67 const double Va = length_a * capA_area; 68 const double Vb = length_b * capB_area; 69 const double Vc = length_c * capC_area; 70 const double Vat = Va + 2.0 * thick_rim_a * capA_area; 71 const double Vbt = Vb + 2.0 * thick_rim_b * capB_area; 72 const double Vct = Vc + 2.0 * thick_rim_c * capC_area; 73 74 // Scale factors (note that drC is not used later) 54 // Scale factors 75 55 const double dr0 = (core_sld-solvent_sld); 76 56 const double drA = (arim_sld-solvent_sld); … … 81 61 double outer_sum = 0; //initialize integral 82 62 for( int i=0; i<GAUSS_N; i++) { 83 double sigma = 0.5 * ( GAUSS_Z[i] + 1.0 );84 double mu_proj = mu * sqrt(1.0-sigma*sigma);63 const double cos_alpha = 0.5 * ( GAUSS_Z[i] + 1.0 ); 64 const double mu = half_q * sqrt(1.0-cos_alpha*cos_alpha); 85 65 86 66 // inner integral (with gauss points), integration limits = 0, pi/2 87 const double siC = sas_sinx_x(mu * sigma * c_over_b);88 const double siCt = sas_sinx_x(mu * sigma * tC_over_b);67 const double siC = length_c * sas_sinx_x(length_c * cos_alpha * half_q); 68 const double siCt = tC * sas_sinx_x(tC * cos_alpha * half_q); 89 69 double inner_sum = 0.0; 90 70 for(int j=0; j<GAUSS_N; j++) { 91 const double uu= 0.5 * ( GAUSS_Z[j] + 1.0 );92 double sin_ uu, cos_uu;93 SINCOS(M_PI_2* uu, sin_uu, cos_uu);94 const double siA = sas_sinx_x(mu_proj * sin_uu * a_over_b);95 const double siB = sas_sinx_x(mu_proj * cos_uu);96 const double siAt = sas_sinx_x(mu_proj * sin_uu * tA_over_b);97 const double siBt = sas_sinx_x(mu_proj * cos_uu * tB_over_b);71 const double beta = 0.5 * ( GAUSS_Z[j] + 1.0 ); 72 double sin_beta, cos_beta; 73 SINCOS(M_PI_2*beta, sin_beta, cos_beta); 74 const double siA = length_a * sas_sinx_x(length_a * mu * sin_beta); 75 const double siB = length_b * sas_sinx_x(length_b * mu * cos_beta); 76 const double siAt = tA * sas_sinx_x(tA * mu * sin_beta); 77 const double siBt = tB * sas_sinx_x(tB * mu * cos_beta); 98 78 99 79 #if OVERLAPPING 100 const double f = dr0* Vin*siA*siB*siC101 + drA*( Vat*siAt-Va*siA)*siB*siC102 + drB*siAt*( Vbt*siBt-Vb*siB)*siC103 + drC*siAt*siBt*( Vct*siCt-Vc*siC);80 const double f = dr0*siA*siB*siC 81 + drA*(siAt-siA)*siB*siC 82 + drB*siAt*(siBt-siB)*siC 83 + drC*siAt*siBt*(siCt-siC); 104 84 #else 105 const double f = dr0* Vin*siA*siB*siC106 + drA*( Vat*siAt-Va*siA)*siB*siC107 + drB*siA*( Vbt*siBt-Vb*siB)*siC108 + drC*siA*siB*( Vct*siCt-Vc*siC);85 const double f = dr0*siA*siB*siC 86 + drA*(siAt-siA)*siB*siC 87 + drB*siA*(siBt-siB)*siC 88 + drC*siA*siB*(siCt-siC); 109 89 #endif 110 90 … … 141 121 const double drC = crim_sld-solvent_sld; 142 122 143 double Vin = length_a * length_b * length_c;144 #if OVERLAPPING145 const double capA_area = length_b*length_c;146 const double capB_area = (length_a+2.*thick_rim_a)*length_c;147 const double capC_area = (length_a+2.*thick_rim_a)*(length_b+2.*thick_rim_b);148 #else149 const double capA_area = length_b*length_c;150 const double capB_area = length_a*length_c;151 const double capC_area = length_a*length_b;152 #endif153 const double Va = length_a * capA_area;154 const double Vb = length_b * capB_area;155 const double Vc = length_c * capC_area;156 const double Vat = Va + 2.0 * thick_rim_a * capA_area;157 const double Vbt = Vb + 2.0 * thick_rim_b * capB_area;158 const double Vct = Vc + 2.0 * thick_rim_c * capC_area;159 160 123 // The definitions of ta, tb, tc are not the same as in the 1D case because there is no 161 124 // the scaling by B. … … 163 126 const double tB = length_b + 2.0*thick_rim_b; 164 127 const double tC = length_c + 2.0*thick_rim_c; 165 const double siA = sas_sinx_x(0.5*length_a*qa);166 const double siB = sas_sinx_x(0.5*length_b*qb);167 const double siC = sas_sinx_x(0.5*length_c*qc);168 const double siAt = sas_sinx_x(0.5*tA*qa);169 const double siBt = sas_sinx_x(0.5*tB*qb);170 const double siCt = sas_sinx_x(0.5*tC*qc);128 const double siA = length_a*sas_sinx_x(0.5*length_a*qa); 129 const double siB = length_b*sas_sinx_x(0.5*length_b*qb); 130 const double siC = length_c*sas_sinx_x(0.5*length_c*qc); 131 const double siAt = tA*sas_sinx_x(0.5*tA*qa); 132 const double siBt = tB*sas_sinx_x(0.5*tB*qb); 133 const double siCt = tC*sas_sinx_x(0.5*tC*qc); 171 134 172 135 #if OVERLAPPING 173 const double f = dr0* Vin*siA*siB*siC174 + drA*( Vat*siAt-Va*siA)*siB*siC175 + drB*siAt*( Vbt*siBt-Vb*siB)*siC176 + drC*siAt*siBt*( Vct*siCt-Vc*siC);136 const double f = dr0*siA*siB*siC 137 + drA*(siAt-siA)*siB*siC 138 + drB*siAt*(siBt-siB)*siC 139 + drC*siAt*siBt*(siCt-siC); 177 140 #else 178 const double f = dr0* Vin*siA*siB*siC179 + drA*( Vat*siAt-Va*siA)*siB*siC180 + drB*siA*( Vbt*siBt-Vb*siB)*siC181 + drC*siA*siB*( Vct*siCt-Vc*siC);141 const double f = dr0*siA*siB*siC 142 + drA*(siAt-siA)*siB*siC 143 + drB*siA*(siBt-siB)*siC 144 + drC*siA*siB*(siCt-siC); 182 145 #endif 183 146 -
sasmodels/models/core_shell_parallelepiped.py
r688d315 r10ee838 7 7 "rim" can be different on each (pair) of faces. 8 8 9 10 9 The form factor is normalized by the particle volume $V$ such that 11 10 … … 16 15 where $\langle \ldots \rangle$ is an average over all possible orientations 17 16 of the rectangular solid. 18 19 17 20 18 The function calculated is the form factor of the rectangular solid below. … … 42 40 amplitudes of the core and the slabs on the edges. 43 41 44 the scattering amplitude is computed for a particular orientation of the core-shell 45 parallelepiped with respect to the scattering vector and then averaged over all 46 possible orientations, where $\alpha$ is the angle between the $z$ axis and the longest axis $C$ 47 of the parallelepiped, $\beta$ is the angle between projection of the particle in the $xy$ detector plane and the $y$ axis. 48 49 .. math:: 50 \begin{align*} 51 F(Q)&=A B C (\rho_\text{core}-\rho_\text{solvent}) S(A \sin\alpha \sin\beta)S(B \sin\alpha \cos\beta)S(C \cos\alpha) \\ 52 &+ 2t_A B C (\rho_\text{A}-\rho_\text{solvent}) \left[S((A+t_A) \sin\alpha \sin\beta)-S(A \sin\alpha \sin\beta)\right] S(B \sin\alpha \cos\beta) S(C \cos\alpha)\\ 53 &+ 2 A t_B C (\rho_\text{B}-\rho_\text{solvent}) S(A \sin\alpha \sin\beta) \left[S((B+t_B) \sin\alpha \cos\beta)-S(B \sin\alpha \cos\beta)\right] S(C \cos\alpha)\\ 54 &+ 2 A B t_C (\rho_\text{C}-\rho_\text{solvent}) S(A \sin\alpha \sin\beta) S(B \sin\alpha \cos\beta) \left[S((C+t_C) \cos\alpha)-S(C \cos\alpha)\right] 55 \end{align*} 42 the scattering amplitude is computed for a particular orientation of the 43 core-shell parallelepiped with respect to the scattering vector and then 44 averaged over all possible orientations, where $\alpha$ is the angle between 45 the $z$ axis and the $C$ axis of the parallelepiped, $\beta$ is 46 the angle between projection of the particle in the $xy$ detector plane 47 and the $y$ axis. 48 49 .. math:: 50 51 F(Q) 52 &= (\rho_\text{core}-\rho_\text{solvent}) 53 S(Q_A, A) S(Q_B, B) S(Q_C, C) \\ 54 &+ (\rho_\text{A}-\rho_\text{solvent}) 55 \left[S(Q_A, A+2t_A) - S(Q_A, Q)\right] S(Q_B, B) S(Q_C, C) \\ 56 &+ (\rho_\text{B}-\rho_\text{solvent}) 57 S(Q_A, A) \left[S(Q_B, B+2t_B) - S(Q_B, B)\right] S(Q_C, C) \\ 58 &+ (\rho_\text{C}-\rho_\text{solvent}) 59 S(Q_A, A) S(Q_B, B) \left[S(Q_C, C+2t_C) - S(Q_C, C)\right] 56 60 57 61 with … … 59 63 .. math:: 60 64 61 S(x) = \frac{\sin \tfrac{1}{2}Q x}{\tfrac{1}{2}Q x} 62 63 where $\rho_\text{core}$, $\rho_\text{A}$, $\rho_\text{B}$ and $\rho_\text{C}$ are 64 the scattering length of the parallelepiped core, and the rectangular slabs of 65 thickness $t_A$, $t_B$ and $t_C$, respectively. 66 $\rho_\text{solvent}$ is the scattering length of the solvent. 65 S(Q, L) = L \frac{\sin \tfrac{1}{2} Q L}{\tfrac{1}{2} Q L} 66 67 and 68 69 .. math:: 70 71 Q_A &= \sin\alpha \sin\beta \\ 72 Q_B &= \sin\alpha \cos\beta \\ 73 Q_C &= \cos\alpha 74 75 76 where $\rho_\text{core}$, $\rho_\text{A}$, $\rho_\text{B}$ and $\rho_\text{C}$ 77 are the scattering length of the parallelepiped core, and the rectangular 78 slabs of thickness $t_A$, $t_B$ and $t_C$, respectively. $\rho_\text{solvent}$ 79 is the scattering length of the solvent. 67 80 68 81 FITTING NOTES 82 ~~~~~~~~~~~~~ 83 69 84 If the scale is set equal to the particle volume fraction, $\phi$, the returned 70 value is the scattered intensity per unit volume, $I(q) = \phi P(q)$. 71 However, **no interparticle interference effects are included in this 72 calculation.** 85 value is the scattered intensity per unit volume, $I(q) = \phi P(q)$. However, 86 **no interparticle interference effects are included in this calculation.** 73 87 74 88 There are many parameters in this model. Hold as many fixed as possible with … … 79 93 NB: The 2nd virial coefficient of the core_shell_parallelepiped is calculated 80 94 based on the the averaged effective radius $(=\sqrt{(A+2t_A)(B+2t_B)/\pi})$ 81 and length $(C+2t_C)$ values, after appropriately 82 sorting the three dimensions to give an oblate or prolate particle, to give an 83 effective radius,for $S(Q)$ when $P(Q) * S(Q)$ is applied.95 and length $(C+2t_C)$ values, after appropriately sorting the three dimensions 96 to give an oblate or prolate particle, to give an effective radius, 97 for $S(Q)$ when $P(Q) * S(Q)$ is applied. 84 98 85 99 For 2d data the orientation of the particle is required, described using 86 angles $\theta$, $\phi$ and $\Psi$ as in the diagrams below, for further details87 of the calculation and angular dispersions see :ref:`orientation`.100 angles $\theta$, $\phi$ and $\Psi$ as in the diagrams below, for further 101 details of the calculation and angular dispersions see :ref:`orientation`. 88 102 The angle $\Psi$ is the rotational angle around the *long_c* axis. For example, 89 103 $\Psi = 0$ when the *short_b* axis is parallel to the *x*-axis of the detector. 90 104 91 For 2d, constraints must be applied during fitting to ensure that the inequality 92 $A < B < C$ is not violated, and hence the correct definition of angles is preserved. The calculation will not report an error, 105 For 2d, constraints must be applied during fitting to ensure that the 106 inequality $A < B < C$ is not violated, and hence the correct definition 107 of angles is preserved. The calculation will not report an error, 93 108 but the results may be not correct. 94 109 … … 96 111 97 112 Definition of the angles for oriented core-shell parallelepipeds. 98 Note that rotation $\theta$, initially in the $xz$ plane, is carried out first, then 99 rotation $\phi$ about the $z$ axis, finally rotation $\Psi$ is now around the axis of the parallelepiped. 100 The neutron or X-ray beam is along the $z$ axis. 113 Note that rotation $\theta$, initially in the $xz$ plane, is carried 114 out first, then rotation $\phi$ about the $z$ axis, finally rotation 115 $\Psi$ is now around the axis of the cylinder. The neutron or X-ray 116 beam is along the $z$ axis. 101 117 102 118 .. figure:: img/parallelepiped_angle_projection.png … … 172 188 Return equivalent radius (ER) 173 189 """ 174 175 # surface average radius (rough approximation) 176 surf_rad = sqrt((length_a + 2.0*thick_rim_a) * (length_b + 2.0*thick_rim_b) / pi) 177 178 height = length_c + 2.0*thick_rim_c 179 180 ddd = 0.75 * surf_rad * (2 * surf_rad * height + (height + surf_rad) * (height + pi * surf_rad)) 181 return 0.5 * (ddd) ** (1. / 3.) 190 from .parallelepiped import ER as ER_p 191 192 a = length_a + 2*thick_rim_a 193 b = length_b + 2*thick_rim_b 194 c = length_c + 2*thick_rim_c 195 return ER_p(a, b, c) 182 196 183 197 # VR defaults to 1.0 184 198 185 199 def random(): 186 import numpy as np187 200 outer = 10**np.random.uniform(1, 4.7, size=3) 188 201 thick = np.random.beta(0.5, 0.5, size=3)*(outer-2) + 1 … … 214 227 psi_pd=10, psi_pd_n=1) 215 228 216 # rkh 7/4/17 add random unit test for 2d, note make all params different, 2d values not tested against other codes or models 229 # rkh 7/4/17 add random unit test for 2d, note make all params different, 230 # 2d values not tested against other codes or models 217 231 if 0: # pak: model rewrite; need to update tests 218 232 qx, qy = 0.2 * cos(pi/6.), 0.2 * sin(pi/6.) 219 233 tests = [[{}, 0.2, 0.533149288477], 220 [{}, [0.2], [0.533149288477]],221 [{'theta':10.0, 'phi':20.0}, (qx, qy), 0.0853299803222],222 [{'theta':10.0, 'phi':20.0}, [(qx, qy)], [0.0853299803222]],234 [{}, [0.2], [0.533149288477]], 235 [{'theta':10.0, 'phi':20.0}, (qx, qy), 0.0853299803222], 236 [{'theta':10.0, 'phi':20.0}, [(qx, qy)], [0.0853299803222]], 223 237 ] 224 238 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
reda8b30 r2d81cfe 53 53 r = R_e \left[ 1 + u^2\left(R_p^2/R_e^2 - 1\right)\right]^{1/2} 54 54 55 For 2d data from oriented ellipsoids the direction of the rotation axis of 56 the ellipsoid is defined using two angles $\theta$ and $\phi$ as for the 55 For 2d data from oriented ellipsoids the direction of the rotation axis of 56 the ellipsoid is defined using two angles $\theta$ and $\phi$ as for the 57 57 :ref:`cylinder orientation figure <cylinder-angle-definition>`. 58 58 For the ellipsoid, $\theta$ is the angle between the rotational axis 59 59 and the $z$ -axis in the $xz$ plane followed by a rotation by $\phi$ 60 in the $xy$ plane, for further details of the calculation and angular 60 in the $xy$ plane, for further details of the calculation and angular 61 61 dispersions see :ref:`orientation` . 62 62 … … 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
r74768cb ra261a83 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 … … 140 140 141 141 def random(): 142 import numpy as np143 142 # V = pi * radius_major * radius_minor * length; 144 V= 10**np.random.uniform(3, 9)143 volume = 10**np.random.uniform(3, 9) 145 144 length = 10**np.random.uniform(1, 3) 146 145 axis_ratio = 10**np.random.uniform(0, 2) 147 radius_minor = np.sqrt( V/length/axis_ratio)148 Vf= 10**np.random.uniform(-4, -2)146 radius_minor = np.sqrt(volume/length/axis_ratio) 147 volfrac = 10**np.random.uniform(-4, -2) 149 148 pars = dict( 150 149 #background=0, sld=0, sld_solvent=1, 151 scale=1e9* Vf/V,150 scale=1e9*volfrac/volume, 152 151 length=length, 153 152 radius_minor=radius_minor, … … 169 168 'sld_solvent':1.0, 'background':0.0}, 170 169 0.001, 675.504402], 171 #[{'theta':80., 'phi':10.}, (qx, qy), 7.88866563001 ],170 #[{'theta':80., 'phi':10.}, (qx, qy), 7.88866563001 ], 172 171 ] -
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
r393facf r0e55afe 100 100 101 101 R Nayuk and K Huber, *Z. Phys. Chem.*, 226 (2012) 837-854 102 103 102 """ 104 103 104 import numpy as np 105 105 from numpy import pi, inf, sqrt 106 106 … … 173 173 174 174 def random(): 175 import numpy as np176 175 a, b, c = 10**np.random.uniform(1, 4.7, size=3) 177 176 # Thickness is limited to 1/2 the smallest dimension -
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