Changes in / [94d13f1:1a580fb] in sasmodels
- Location:
- sasmodels
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/conversion_table.py
rfa6d6fc rbb584b3 5 5 names for each parameter in sasmodels. This is used by :mod:`convert` to 6 6 determine the equivalent parameter set when comparing a sasmodels model to 7 the models defined in SasView 3.1. 7 the models defined in previous versions of SasView and sasmodels. This is now 8 versioned based on the version number of SasView. 9 10 When any sasmodels parameter or model name is changed, this must be modified to 11 account for that. 12 13 Usage: 14 <old_Sasview_version> : { 15 <new_model_name> : [ 16 <old_model_name> , 17 { 18 <new_param_name_1> : <old_param_name_1>, 19 ... 20 <new_param_name_n> : <old_param_name_n> 21 } 22 ] 23 } 24 25 Any future parameter and model name changes can and should be given in this 26 table for future compatibility. 8 27 """ 9 28 10 11 29 CONVERSION_TABLE = { 30 (3,1,2) : { 12 31 "adsorbed_layer": [ 13 32 "Core2ndMomentModel", … … 211 230 ], 212 231 "correlation_length": [ 213 "CorrLength Model",232 "CorrLength", 214 233 { 215 234 "porod_scale": "scale_p", … … 218 237 "lorentz_exp": "exponent_l", 219 238 "cor_length": "length_l" 220 } 239 }, 240 "CorrLengthModel" 221 241 ], 222 242 "cylinder": [ … … 299 319 ], 300 320 "fractal_core_shell": [ 301 "FractalCoreShell Model",321 "FractalCoreShell", 302 322 { 303 323 "sld_core": "core_sld", … … 309 329 "cor_length": "cor_length", 310 330 "volfraction": "volfraction", 311 } 331 }, 332 "FractalCoreShellModel" 312 333 ], 313 334 "fuzzy_sphere": [ … … 321 342 ], 322 343 "gauss_lorentz_gel": [ 323 "GaussLorentzGel Model",344 "GaussLorentzGel", 324 345 { 325 346 "gauss_scale": "scale_g", … … 328 349 "background": "background", 329 350 "lorentz_scale": "scale_l" 330 } 351 }, 352 "GaussLorentzGelModel" 331 353 ], 332 354 "gaussian_peak": [ 333 "Peak GaussModel",355 "Peak Gauss Model", 334 356 { 335 357 "peak_pos": "q0", 336 358 "sigma": "B", 337 } 359 }, 360 "PeakGaussModel", 338 361 ], 339 362 "gel_fit": [ … … 343 366 "lorentz_scale": "lScale", 344 367 "guinier_scale": "gScale", 345 "fractal_dim": " scale",368 "fractal_dim": "FractalExp", 346 369 "cor_length": "zeta", 347 370 } 348 371 ], 349 372 "guinier": [ 373 "Guinier", 374 { 375 "rg": "rg" 376 }, 350 377 "GuinierModel", 351 {352 "rg": "rg"353 }354 378 ], 355 379 "guinier_porod": [ 356 "GuinierPorod Model",380 "GuinierPorod", 357 381 { 358 382 "s": "dim", … … 361 385 "scale": "scale", 362 386 "background": "background" 363 } 387 }, 388 "GuinierPorodModel", 364 389 ], 365 390 "hardsphere": [ … … 454 479 "d_spacing": "spacing", 455 480 "Caille_parameter": "caille", 456 "Nlayers": " N_plates",481 "Nlayers": "n_plates", 457 482 } 458 483 ], … … 486 511 ], 487 512 "lorentz": [ 513 "Lorentz", 514 { 515 "cor_length": "length" 516 }, 488 517 "LorentzModel", 489 {490 "cor_length": "length"491 }492 518 ], 493 519 "mass_fractal": [ … … 510 536 ], 511 537 "mono_gauss_coil": [ 512 "Debye Model",538 "Debye", 513 539 { 514 540 "rg": "rg", 515 541 "i_zero": "scale", 516 542 "background": "background", 517 } 543 }, 544 "DebyeModel", 518 545 ], 519 546 "multilayer_vesicle": [ … … 564 591 ], 565 592 "peak_lorentz": [ 566 "Peak LorentzModel",593 "Peak Lorentz Model", 567 594 { 568 595 "peak_pos": "q0", 569 596 "peak_hwhm": "B" 570 } 597 }, 598 "PeakLorentzModel", 571 599 ], 572 600 "pearl_necklace": [ … … 802 830 ], 803 831 "two_lorentzian": [ 804 "TwoLorentzian Model",832 "TwoLorentzian", 805 833 { 806 834 "lorentz_scale_1": "scale_1", … … 811 839 "lorentz_length_1": "length_1", 812 840 "background": "background" 813 } 841 }, 842 "TwoLorentzianModel", 814 843 ], 815 844 "two_power_law": [ 816 "TwoPowerLaw Model",845 "TwoPowerLaw", 817 846 { 818 847 "coefficent_1": "coef_A", … … 821 850 "background": "background", 822 851 "crossover": "qc" 823 } 852 }, 853 "TwoPowerLawModel", 824 854 ], 825 855 "unified_power_Rg": [ 856 "UnifiedPowerRg", 857 dict(((field_new+str(index), field_old+str(index)) 858 for field_new, field_old in [("rg", "Rg"), 859 ("power", "power"), 860 ("G", "G"), 861 ("B", "B"),] 862 for index in range(11)), 863 **{ 864 "background": "background", 865 "scale": "scale", 866 }), 826 867 "UnifiedPowerRgModel", 827 {828 }829 868 ], 830 869 "vesicle": [ … … 835 874 } 836 875 ] 876 } 837 877 } -
sasmodels/convert.py
rf80f334 r07c8d46 53 53 ("_pd_nsigma", ".nsigmas"), 54 54 ("_pd_type", ".type"), 55 (".lower", ".lower"), 56 (".upper", ".upper"), 57 (".fittable", ".fittable"), 58 (".std", ".std"), 59 (".units", ".units"), 60 ("", "") 55 61 ] 56 62 … … 64 70 if id.startswith('M0:'): 65 71 return True 66 if id.startswith('volfraction') or id.startswith('radius_effective'):67 return False68 72 if '_pd' in id or '.' in id: 69 73 return False … … 75 79 if p.id == id: 76 80 return p.type == 'sld' 77 r aise ValueError("unknown parameter %r in conversion"%id)81 return False 78 82 79 83 def _rescale_sld(model_info, pars, scale): … … 88 92 89 93 90 def _get_translation_table(model_info ):91 _, translation = CONVERSION_TABLE.get(model_info.id, [None, {}])92 translation = translation.copy()94 def _get_translation_table(model_info, version=(3,1,2)): 95 conv_param = CONVERSION_TABLE.get(version, {}).get(model_info.id, [None, {}]) 96 translation = conv_param[1].copy() 93 97 for p in model_info.parameters.kernel_parameters: 94 98 if p.length > 1: … … 119 123 def _pd_to_underscores(pars): 120 124 return dict((_dot_pd_to_underscore_pd(k), v) for k, v in pars.items()) 121 122 def _convert_name(conv_dict, pars):123 """124 Renames parameter values (upper, lower, etc) to v4.0 names125 :param conv_dict: conversion dictionary mapping new name : old name126 :param pars: parameters to convert127 :return:128 """129 new_pars = {}130 i = 0131 j = 0132 for key_par, value_par in pars.iteritems():133 j += 1134 for key_conv, value_conv in conv_dict.iteritems():135 if re.search(value_conv, key_par):136 new_pars[key_par.replace(value_conv, key_conv)] = value_par137 i += 1138 break139 elif re.search("background", key_par) or re.search("scale", key_par):140 new_pars[key_par] = value_par141 i += 1142 break143 if i != j:144 new_pars[key_par] = value_par145 i += 1146 return new_pars147 125 148 126 def _convert_pars(pars, mapping): … … 167 145 return newpars 168 146 169 170 def _conversion_target(model_name): 147 def _conversion_target(model_name, version=(3,1,2)): 171 148 """ 172 149 Find the sasmodel name which translates into the sasview name. … … 176 153 two variants in sasview. 177 154 """ 178 for sasmodels_name, [sasview_name, _] in CONVERSION_TABLE.items(): 179 if sasview_name == model_name: 155 for sasmodels_name, sasview_dict in \ 156 CONVERSION_TABLE.get(version, {}).items(): 157 if sasview_dict[0] == model_name: 180 158 return sasmodels_name 181 159 return None 182 160 183 184 def _hand_convert(name, oldpars): 161 def _hand_convert(name, oldpars, version=(3,1,2)): 162 if version == (3,1,2): 163 oldpars = _hand_convert_3_1_2_to_4_1(name, oldpars) 164 return oldpars 165 166 def _hand_convert_3_1_2_to_4_1(name, oldpars): 185 167 if name == 'core_shell_parallelepiped': 186 168 # Make sure pd on rim parameters defaults to zero … … 215 197 pd = oldpars['radius.width']*oldpars['radius']/thickness 216 198 oldpars['radius.width'] = pd 199 elif name == 'multilayer_vesicle': 200 if 'scale' in oldpars: 201 oldpars['volfraction'] = oldpars['scale'] 202 oldpars['scale'] = 1.0 203 if 'scale.lower' in oldpars: 204 oldpars['volfraction.lower'] = oldpars['scale.lower'] 205 if 'scale.upper' in oldpars: 206 oldpars['volfraction.upper'] = oldpars['scale.upper'] 207 if 'scale.fittable' in oldpars: 208 oldpars['volfraction.fittable'] = oldpars['scale.fittable'] 209 if 'scale.std' in oldpars: 210 oldpars['volfraction.std'] = oldpars['scale.std'] 211 if 'scale.units' in oldpars: 212 oldpars['volfraction.units'] = oldpars['scale.units'] 217 213 elif name == 'pearl_necklace': 218 214 pass … … 236 232 oldpars[p + ".upper"] /= 1e-13 237 233 elif name == 'spherical_sld': 238 oldpars["CONTROL"] += 1 234 j = 0 235 while "func_inter" + str(j) in oldpars: 236 name = "func_inter" + str(j) 237 new_name = "shape" + str(j + 1) 238 if oldpars[name] == 'Erf(|nu|*z)': 239 oldpars[new_name] = int(0) 240 elif oldpars[name] == 'RPower(z^|nu|)': 241 oldpars[new_name] = int(1) 242 elif oldpars[name] == 'LPower(z^|nu|)': 243 oldpars[new_name] = int(2) 244 elif oldpars[name] == 'RExp(-|nu|*z)': 245 oldpars[new_name] = int(3) 246 elif oldpars[name] == 'LExp(-|nu|*z)': 247 oldpars[new_name] = int(4) 248 else: 249 oldpars[new_name] = int(0) 250 oldpars.pop(name) 251 oldpars['n_shells'] = str(j + 1) 252 j += 1 239 253 elif name == 'teubner_strey': 240 254 # basically undoing the entire Teubner-Strey calculations here. … … 281 295 return oldpars 282 296 283 def convert_model(name, pars, use_underscore=False ):297 def convert_model(name, pars, use_underscore=False, model_version=(3,1,2)): 284 298 """ 285 299 Convert model from old style parameter names to new style. 286 300 """ 287 newname = _conversion_target(name) 288 if newname is None: 289 return name, pars 290 if ':' in newname: # core_shell_ellipsoid:1 291 model_info = load_model_info(newname[:-2]) 292 # Know that the table exists and isn't multiplicity so grab it directly 293 # Can't use _get_translation_table since that will return the 'bare' 294 # version. 295 translation = CONVERSION_TABLE[newname][1] 296 else: 297 model_info = load_model_info(newname) 298 translation = _get_translation_table(model_info) 299 newpars = _hand_convert(newname, pars.copy()) 300 newpars = _convert_name(translation, newpars) 301 newpars = _convert_pars(newpars, translation) 302 if not model_info.structure_factor: 303 newpars = _rescale_sld(model_info, newpars, 1e6) 304 newpars.setdefault('scale', 1.0) 305 newpars.setdefault('background', 0.0) 306 if use_underscore: 307 newpars = _pd_to_underscores(newpars) 301 newpars = pars 302 keys = sorted(CONVERSION_TABLE.keys()) 303 for i, version in enumerate(keys): 304 # Don't allow indices outside list 305 next_i = i + 1 306 if next_i == len(keys): 307 next_i = i 308 # If the save state is from a later version, skip the check 309 if model_version <= keys[next_i]: 310 newname = _conversion_target(name, version) 311 else: 312 newname = None 313 # If no conversion is found, move on 314 if newname is None: 315 newname = name 316 continue 317 if ':' in newname: # core_shell_ellipsoid:1 318 model_info = load_model_info(newname[:-2]) 319 # Know the table exists and isn't multiplicity so grab it directly 320 # Can't use _get_translation_table since that will return the 'bare' 321 # version. 322 translation = CONVERSION_TABLE.get(version, {})[newname][1] 323 else: 324 model_info = load_model_info(newname) 325 translation = _get_translation_table(model_info, version) 326 newpars = _hand_convert(newname, newpars, version) 327 newpars = _convert_pars(newpars, translation) 328 # TODO: Still not convinced this is the best check 329 if not model_info.structure_factor and version == (3,1,2): 330 newpars = _rescale_sld(model_info, newpars, 1e6) 331 newpars.setdefault('scale', 1.0) 332 newpars.setdefault('background', 0.0) 333 if use_underscore: 334 newpars = _pd_to_underscores(newpars) 335 name = newname 308 336 return newname, newpars 309 310 337 311 338 # ========= BACKWARD CONVERSION sasmodels => sasview 3.x =========== -
sasmodels/kernelcl.py
r7fcdc9f rb8ddf2e 465 465 # architectures tested so far. 466 466 if self.is_2d: 467 # Note: 17 rather than 15 because results is 2 elements 468 # longer than input. 469 width = ((self.nq+17)//16)*16 467 # Note: 16 rather than 15 because result is 1 longer than input. 468 width = ((self.nq+16)//16)*16 470 469 self.q = np.empty((width, 2), dtype=dtype) 471 470 self.q[:self.nq, 0] = q_vectors[0] 472 471 self.q[:self.nq, 1] = q_vectors[1] 473 472 else: 474 # Note: 33 rather than 31 because results is 2 elements 475 # longer than input. 476 width = ((self.nq+33)//32)*32 473 # Note: 32 rather than 31 because result is 1 longer than input. 474 width = ((self.nq+32)//32)*32 477 475 self.q = np.empty(width, dtype=dtype) 478 476 self.q[:self.nq] = q_vectors[0] … … 524 522 self.dim = '2d' if q_input.is_2d else '1d' 525 523 # plus three for the normalization values 526 self.result = np.empty(q_input.nq+ 3, dtype)524 self.result = np.empty(q_input.nq+1, dtype) 527 525 528 526 # Inputs and outputs for each kernel call -
sasmodels/models/core_shell_bicelle.py
r4b541ac r8afefae 156 156 phi=0) 157 157 158 qx, qy = 0.4 * cos(90), 0.5 * sin(0)158 #qx, qy = 0.4 * cos(pi/2.0), 0.5 * sin(0) -
sasmodels/models/core_shell_bicelle_elliptical.py
r8e68ea0 r8afefae 83 83 84 84 Definition of the angles for the oriented core_shell_bicelle_elliptical model. 85 Note that *theta* and *phi* are currently defined differently to those for the core_shell_bicelle model. 85 86 86 87 … … 149 150 psi=0) 150 151 151 qx, qy = 0.4 * cos(90), 0.5 * sin(0)152 #qx, qy = 0.4 * cos(pi/2.0), 0.5 * sin(0) 152 153 153 154 tests = [ -
sasmodels/models/ellipsoid.c
r925ad6e r130d4c7 4 4 double radius_polar, double radius_equatorial, double theta, double phi); 5 5 6 double _ellipsoid_kernel(double q, double radius_polar, double radius_equatorial, double sin_alpha); 7 double _ellipsoid_kernel(double q, double radius_polar, double radius_equatorial, double sin_alpha)6 static double 7 _ellipsoid_kernel(double q, double radius_polar, double radius_equatorial, double cos_alpha) 8 8 { 9 9 double ratio = radius_polar/radius_equatorial; 10 // Given the following under the radical: 11 // 1 + sin^2(T) (v^2 - 1) 12 // we can expand to match the form given in Guinier (1955) 13 // = (1 - sin^2(T)) + v^2 sin^2(T) = cos^2(T) + sin^2(T) 10 // Using ratio v = Rp/Re, we can expand the following to match the 11 // form given in Guinier (1955) 12 // r = Re * sqrt(1 + cos^2(T) (v^2 - 1)) 13 // = Re * sqrt( (1 - cos^2(T)) + v^2 cos^2(T) ) 14 // = Re * sqrt( sin^2(T) + v^2 cos^2(T) ) 15 // = sqrt( Re^2 sin^2(T) + Rp^2 cos^2(T) ) 16 // 14 17 // Instead of using pythagoras we could pass in sin and cos; this may be 15 18 // slightly better for 2D which has already computed it, but it introduces … … 17 20 // leave it as is. 18 21 const double r = radius_equatorial 19 * sqrt(1.0 + sin_alpha*sin_alpha*(ratio*ratio - 1.0));22 * sqrt(1.0 + cos_alpha*cos_alpha*(ratio*ratio - 1.0)); 20 23 const double f = sas_3j1x_x(q*r); 21 24 … … 39 42 double total = 0.0; 40 43 for (int i=0;i<76;i++) { 41 //const double sin_alpha = (Gauss76Z[i]*(upper-lower) + upper + lower)/2;42 const double sin_alpha = Gauss76Z[i]*zm + zb;43 total += Gauss76Wt[i] * _ellipsoid_kernel(q, radius_polar, radius_equatorial, sin_alpha);44 //const double cos_alpha = (Gauss76Z[i]*(upper-lower) + upper + lower)/2; 45 const double cos_alpha = Gauss76Z[i]*zm + zb; 46 total += Gauss76Wt[i] * _ellipsoid_kernel(q, radius_polar, radius_equatorial, cos_alpha); 44 47 } 45 48 // translate dx in [-1,1] to dx in [lower,upper] … … 59 62 double q, sin_alpha, cos_alpha; 60 63 ORIENT_SYMMETRIC(qx, qy, theta, phi, q, sin_alpha, cos_alpha); 61 const double form = _ellipsoid_kernel(q, radius_polar, radius_equatorial, sin_alpha);64 const double form = _ellipsoid_kernel(q, radius_polar, radius_equatorial, cos_alpha); 62 65 const double s = (sld - sld_solvent) * form_volume(radius_polar, radius_equatorial); 63 66 -
sasmodels/models/guinier_porod.py
ra807206 rcdcebf1 4 4 and dimensionality of scattering objects, including asymmetric objects 5 5 such as rods or platelets, and shapes intermediate between spheres 6 and rods or between rods and platelets. 6 and rods or between rods and platelets, and overcomes some of the 7 deficiencies of the (Beaucage) Unified_Power_Rg model (see Hammouda, 2010). 7 8 8 9 Definition … … 59 60 --------- 60 61 61 A Guinier, G Fournet, *Small-Angle Scattering of X-Rays*, 62 John Wiley and Sons, New York, (1955) 62 B Hammouda, *A new Guinier-Porod model, J. Appl. Cryst.*, (2010), 43, 716-719 63 63 64 O Glatter, O Kratky, *Small-Angle X-Ray Scattering*, Academic Press (1982) 65 Check out Chapter 4 on Data Treatment, pages 155-156. 64 B Hammouda, *Analysis of the Beaucage model, J. Appl. Cryst.*, (2010), 43, 1474-1478 65 66 66 """ 67 67 -
sasmodels/models/unified_power_Rg.py
rb3f2a24 r66ca2a6 3 3 ---------- 4 4 5 Th e Beaucage model employs the empirical multiple level unified6 Exponential/Power-law fit method developed by G. Beaucage. Four functions 7 are included so that 1, 2, 3, or 4 levels can be used. In addition a 0 level 8 has been added which simplycalculates5 This model employs the empirical multiple level unified Exponential/Power-law 6 fit method developed by Beaucage. Four functions are included so that 1, 2, 3, 7 or 4 levels can be used. In addition a 0 level has been added which simply 8 calculates 9 9 10 10 .. math:: … … 15 15 many different types of particles, including fractal clusters, random coils 16 16 (Debye equation), ellipsoidal particles, etc. 17 18 The model works best for mass fractal systems characterized by Porod exponents 19 between 5/3 and 3. It should not be used for surface fractal systems. Hammouda 20 (2010) has pointed out a deficiency in the way this model handles the 21 transitioning between the Guinier and Porod regimes and which can create 22 artefacts that appear as kinks in the fitted model function. 23 24 Also see the Guinier_Porod model. 17 25 18 26 The empirical fit function is: … … 30 38 .. math:: 31 39 32 q_i^* = \frac{q}{\operatorname{erf}^3(q R_{gi}/\sqrt{6}} 40 q_i^* = q \left[\operatorname{erf} 41 \left(\frac{q R_{gi}}{\sqrt{6}}\right) 42 \right]^{-3} 33 43 34 44 … … 56 66 57 67 G Beaucage, *J. Appl. Cryst.*, 29 (1996) 134-146 68 69 B Hammouda, *Analysis of the Beaucage model, J. Appl. Cryst.*, (2010), 43, 1474-1478 58 70 59 71 """ -
sasmodels/sasview_model.py
r64614ad ra38b065 16 16 import logging 17 17 from os.path import basename, splitext 18 import thread 18 19 19 20 import numpy as np # type: ignore … … 39 40 pass 40 41 42 calculation_lock = thread.allocate_lock() 43 41 44 SUPPORT_OLD_STYLE_PLUGINS = True 42 45 … … 57 60 import sas.models 58 61 from sasmodels.conversion_table import CONVERSION_TABLE 59 for new_name, conversion in CONVERSION_TABLE. items():62 for new_name, conversion in CONVERSION_TABLE.get((3,1,2), {}).items(): 60 63 # CoreShellEllipsoidModel => core_shell_ellipsoid:1 61 64 new_name = new_name.split(':')[0] 62 old_name = conversion[0] 65 old_name = conversion[0] if len(conversion) < 3 else conversion[2] 63 66 module_attrs = {old_name: find_model(new_name)} 64 67 ConstructedModule = type(old_name, (), module_attrs) … … 605 608 to the card for each evaluation. 606 609 """ 610 ## uncomment the following when trying to debug the uncoordinated calls 611 ## to calculate_Iq 612 #if calculation_lock.locked(): 613 # logging.info("calculation waiting for another thread to complete") 614 # logging.info("\n".join(traceback.format_stack())) 615 616 with calculation_lock: 617 return self._calculate_Iq(qx, qy) 618 619 def _calculate_Iq(self, qx, qy=None): 607 620 #core.HAVE_OPENCL = False 608 621 if self._model is None:
Note: See TracChangeset
for help on using the changeset viewer.