Changeset ce896fd in sasmodels
- Timestamp:
- Mar 28, 2016 9:27:22 AM (9 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- fb5914f, d1c4760
- Parents:
- 5c028e3
- Location:
- sasmodels
- Files:
-
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/convert.py
rc6ca41e rce896fd 73 73 new model definition end with sld. 74 74 """ 75 print "pars",pars 75 76 return dict((p, (v*1e-6 if p.startswith('sld') or p.endswith('sld') 76 77 else v*1e15 if 'ndensity' in p -
sasmodels/generate.py
rd19962c rce896fd 192 192 import numpy as np 193 193 194 from .modelinfo import ModelInfo, Parameter, make_parameter_table 194 from .modelinfo import ModelInfo, Parameter, make_parameter_table, set_demo 195 195 196 196 # TODO: identify model files which have changed since loading and reload them. … … 539 539 return '\n'.join(source) 540 540 541 def process_parameters(model_info):542 """543 Process parameter block, precalculating parameter details.544 """545 partable = model_info['parameters']546 if model_info.get('demo', None) is None:547 model_info['demo'] = partable.defaults548 549 541 class CoordinationDetails(object): 550 542 def __init__(self, model_info): … … 664 656 if callable(model_info['Iq']) and model_info['Iqxy'] is None: 665 657 partable = model_info['parameters'] 666 if partable. type['1d'] != partable.type['2d']:658 if partable.has_2d: 667 659 raise ValueError("Iqxy model is missing") 668 660 Iq = model_info['Iq'] … … 735 727 single=getattr(kernel_module, 'single', True), 736 728 structure_factor=getattr(kernel_module, 'structure_factor', False), 729 profile_axes=getattr(kernel_module, 'profile_axes', ['x','y']), 737 730 variant_info=getattr(kernel_module, 'invariant_info', None), 738 731 demo=getattr(kernel_module, 'demo', None), … … 742 735 tests=getattr(kernel_module, 'tests', []), 743 736 ) 744 process_parameters(model_info)737 set_demo(model_info, getattr(kernel_module, 'demo', None)) 745 738 # Check for optional functions 746 functions = "ER VR form_volume Iq Iqxy shape sesans".split()739 functions = "ER VR form_volume Iq Iqxy profile sesans".split() 747 740 model_info.update((k, getattr(kernel_module, k, None)) for k in functions) 748 741 create_default_functions(model_info) -
sasmodels/modelinfo.py
rd19962c rce896fd 45 45 if isinstance(limits, list) and all(isstr(k) for k in limits): 46 46 choices = limits 47 limits = [ 1, len(choices)]47 limits = [0, len(choices)-1] 48 48 else: 49 choices = None49 choices = [] 50 50 # TODO: maybe allow limits of None for (-inf, inf) 51 51 try: … … 115 115 return parameter 116 116 117 118 def set_demo(model_info, demo): 119 """ 120 Assign demo parameters to model_info['demo'] 121 122 If demo is not defined, then use defaults. 123 124 If demo is defined, override defaults with value from demo. 125 126 If demo references vector fields, such as thickness[n], then support 127 different ways of assigning the demo values, including assigning a 128 specific value (e.g., thickness3=50.0), assigning a new value to all 129 (e.g., thickness=50.0) or assigning values using list notation. 130 """ 131 partable = model_info['parameters'] 132 if demo is None: 133 result = partable.defaults 134 else: 135 pars = dict((p.id, p) for p in partable.kernel_parameters) 136 result = partable.defaults.copy() 137 vectors = dict((name,value) for name,value in demo.items() 138 if name in pars and pars[name].length > 1) 139 if vectors: 140 scalars = dict((name, value) for name, value in demo.items() 141 if name not in pars or pars[name].length == 1) 142 for name, value in vectors.items(): 143 if np.isscalar(value): 144 # support for the form 145 # demo(thickness=0, thickness2=50) 146 for k in pars[name].length: 147 key = name+str(k) 148 if key not in scalars: 149 scalars[key] = vectors 150 else: 151 # supoprt for the form 152 # demo(thickness=[20,10,3]) 153 for (k,v) in enumerate(value): 154 scalars[name+str(k)] = v 155 result.update(scalars) 156 else: 157 result.update(demo) 158 159 model_info['demo'] = result 160 117 161 class Parameter(object): 118 162 """ … … 171 215 self.type = type 172 216 self.description = description 173 self.choices = None174 217 175 218 # Length and length_control will be filled in once the complete … … 182 225 self.polydisperse = False 183 226 self.relative_pd = False 227 228 # choices are also set externally. 229 self.choices = [] 184 230 185 231 def as_definition(self): -
sasmodels/models/onion.c
rfdb1487 rce896fd 4 4 double thickness, double A) 5 5 { 6 const double vol = 4.0/3.0 * M_PI * r * r * r;6 const double vol = M_4PI_3 * cube(r); 7 7 const double qr = q * r; 8 8 const double alpha = A * r/thickness; … … 19 19 double sinqr, cosqr; 20 20 SINCOS(qr, sinqr, cosqr); 21 fun = -3.0 (21 fun = -3.0*( 22 22 ((alphasq - qrsq)*sinqr/qr - 2.0*alpha*cosqr) / sumsq 23 23 - (alpha*sinqr/qr - cosqr) … … 32 32 f_linear(double q, double r, double sld, double slope) 33 33 { 34 const double vol = 4.0/3.0 * M_PI * r * r * r;34 const double vol = M_4PI_3 * cube(r); 35 35 const double qr = q * r; 36 36 const double bes = sph_j1c(qr); … … 52 52 { 53 53 const double bes = sph_j1c(q * r); 54 const double vol = 4.0/3.0 * M_PI * r * r * r;54 const double vol = M_4PI_3 * cube(r); 55 55 return sld * vol * bes; 56 56 } … … 64 64 r += thickness[i]; 65 65 } 66 return 4.0/3.0 * M_PI * r * r * r;66 return M_4PI_3*cube(r); 67 67 } 68 68 69 69 static double 70 Iq(double q, double core_sld, double core_radius, double solvent_sld,71 double n, double in_sld[], double out_sld[], double thickness[],70 Iq(double q, double sld_core, double core_radius, double sld_solvent, 71 double n, double sld_in[], double sld_out[], double thickness[], 72 72 double A[]) 73 73 { 74 74 int i; 75 r = core_radius;76 f = f_constant(q, r, core_sld);75 double r = core_radius; 76 double f = f_constant(q, r, sld_core); 77 77 for (i=0; i<n; i++){ 78 78 const double r0 = r; … … 92 92 } 93 93 } 94 f -= f_constant(q, r, s olvent_sld);95 f2 = f * f * 1.0e-4;94 f -= f_constant(q, r, sld_solvent); 95 const double f2 = f * f * 1.0e-4; 96 96 97 97 return f2; -
sasmodels/models/onion.py
r6a8fdfe rce896fd 292 292 293 293 # ["name", "units", default, [lower, upper], "type","description"], 294 parameters = [[" core_sld", "1e-6/Ang^2", 1.0, [-inf, inf], "",294 parameters = [["sld_core", "1e-6/Ang^2", 1.0, [-inf, inf], "", 295 295 "Core scattering length density"], 296 ["core_radius", "Ang", 200., [0, inf], " ",296 ["core_radius", "Ang", 200., [0, inf], "volume", 297 297 "Radius of the core"], 298 ["s olvent_sld", "1e-6/Ang^2", 6.4, [-inf, inf], "",298 ["sld_solvent", "1e-6/Ang^2", 6.4, [-inf, inf], "", 299 299 "Solvent scattering length density"], 300 300 ["n", "", 1, [0, 10], "volume", 301 301 "number of shells"], 302 [" in_sld[n]", "1e-6/Ang^2", 1.7, [-inf, inf], "",302 ["sld_in[n]", "1e-6/Ang^2", 1.7, [-inf, inf], "", 303 303 "scattering length density at the inner radius of shell k"], 304 [" out_sld[n]", "1e-6/Ang^2", 2.0, [-inf, inf], "",304 ["sld_out[n]", "1e-6/Ang^2", 2.0, [-inf, inf], "", 305 305 "scattering length density at the outer radius of shell k"], 306 306 ["thickness[n]", "Ang", 40., [0, inf], "volume", … … 310 310 ] 311 311 312 #source = ["lib/sph_j1c.c", "onion.c"] 313 314 def Iq(q, *args, **kw): 315 return q 316 317 def Iqxy(qx, *args, **kw): 318 return qx 319 320 321 def shape(core_sld, core_radius, solvent_sld, n, in_sld, out_sld, thickness, A): 312 source = ["lib/sph_j1c.c", "onion.c"] 313 314 #def Iq(q, *args, **kw): 315 # return q 316 317 profile_axes = ['Radius (A)', 'SLD (1e-6/A^2)'] 318 def profile(core_sld, core_radius, solvent_sld, n, in_sld, out_sld, thickness, A): 322 319 """ 323 320 SLD profile … … 373 370 374 371 demo = { 375 "s olvent_sld": 2.2,376 " core_sld": 1.0,372 "sld_solvent": 2.2, 373 "sld_core": 1.0, 377 374 "core_radius": 100, 378 375 "n": 4, 379 " in_sld": [0.5, 1.5, 0.9, 2.0],380 " out_sld": [nan, 0.9, 1.2, 1.6],376 "sld_in": [0.5, 1.5, 0.9, 2.0], 377 "sld_out": [nan, 0.9, 1.2, 1.6], 381 378 "thickness": [50, 75, 150, 75], 382 379 "A": [0, -1, 1e-4, 1], -
sasmodels/models/spherical_sld.py
re42b0b9 rce896fd 163 163 title = "Sperical SLD intensity calculation" 164 164 description = """ 165 166 167 165 I(q) = 166 background = Incoherent background [1/cm] 167 """ 168 168 category = "sphere-based" 169 169 170 170 # pylint: disable=bad-whitespace, line-too-long 171 171 # ["name", "units", default, [lower, upper], "type", "description"], 172 parameters = [["n_shells", "", 1, [0, 9],"", "number of shells"],173 ["thick_inter[n ]", "Ang", 50, [-inf, inf],"", "intern layer thickness"],174 ["func_inter[n ]", "", 0, [0, 4],"", "Erf:0, RPower:1, LPower:2, RExp:3, LExp:4"],175 ["sld_core", "1e-6/Ang^2", 2.07, [-inf, inf],"", "sld function flat"],176 ["sld_solvent", "1e-6/Ang^2", 1.0, [-inf, inf],"", "sld function solvent"],177 ["sld_flat[n ]", "1e-6/Ang^2", 4.06, [-inf, inf],"", "sld function flat"],178 ["thick_inter[n ]", "Ang", 50.0, [0, inf], "", "intern layer thickness"],179 ["thick_flat[n ]", "Ang", 100.0, [0, inf], "", "flat layer_thickness"],180 ["inter_nu[n ]", "", 2.5, [-inf, inf],"", "steepness parameter"],181 ["npts_inter", "", 35, [0, 35],"", "number of points in each sublayer Must be odd number"],182 ["core_rad", "Ang", 50.0, [0, inf], "", "intern layer thickness"],172 parameters = [["n_shells", "", 1, [0, 9], "", "number of shells"], 173 ["thick_inter[n_shells]", "Ang", 50, [-inf, inf], "", "intern layer thickness"], 174 ["func_inter[n_shells]", "", 0, [0, 4], "", "Erf:0, RPower:1, LPower:2, RExp:3, LExp:4"], 175 ["sld_core", "1e-6/Ang^2", 2.07, [-inf, inf], "", "sld function flat"], 176 ["sld_solvent", "1e-6/Ang^2", 1.0, [-inf, inf], "", "sld function solvent"], 177 ["sld_flat[n_shells]", "1e-6/Ang^2", 4.06, [-inf, inf], "", "sld function flat"], 178 ["thick_inter[n_shells]", "Ang", 50.0, [0, inf], "", "intern layer thickness"], 179 ["thick_flat[n_shells]", "Ang", 100.0, [0, inf], "", "flat layer_thickness"], 180 ["inter_nu[n_shells]", "", 2.5, [-inf, inf], "", "steepness parameter"], 181 ["npts_inter", "", 35, [0, 35], "", "number of points in each sublayer Must be odd number"], 182 ["core_rad", "Ang", 50.0, [0, inf], "", "intern layer thickness"], 183 183 ] 184 184 # pylint: enable=bad-whitespace, line-too-long 185 185 186 #source = ["lib/librefl.c", "lib/sph_j1c.c", "spherical_sld.c"] 186 187 187 def Iq(q, *args, **kw): 188 188 return q 189 189 190 def Iqxy(qx, *args, **kw):191 return qx192 193 194 190 demo = dict( 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 191 n_shells=4, 192 scale=1.0, 193 solvent_sld=1.0, 194 background=0.0, 195 npts_inter=35.0, 196 func_inter_0=0, 197 nu_inter_0=2.5, 198 rad_core_0=50.0, 199 core0_sld=2.07, 200 thick_inter_0=50.0, 201 func_inter_1=0, 202 nu_inter_1=2.5, 203 thick_inter_1=50.0, 204 flat1_sld=4.0, 205 thick_flat_1=100.0, 206 func_inter_2=0, 207 nu_inter_2=2.5, 208 thick_inter_2=50.0, 209 flat2_sld=3.5, 210 thick_flat_2=100.0, 211 func_inter_3=0, 212 nu_inter_3=2.5, 213 thick_inter_3=50.0, 214 flat3_sld=4.0, 215 thick_flat_3=100.0, 216 func_inter_4=0, 217 nu_inter_4=2.5, 218 thick_inter_4=50.0, 219 flat4_sld=3.5, 220 thick_flat_4=100.0, 221 func_inter_5=0, 222 nu_inter_5=2.5, 223 thick_inter_5=50.0, 224 flat5_sld=4.0, 225 thick_flat_5=100.0, 226 func_inter_6=0, 227 nu_inter_6=2.5, 228 thick_inter_6=50.0, 229 flat6_sld=3.5, 230 thick_flat_6=100.0, 231 func_inter_7=0, 232 nu_inter_7=2.5, 233 thick_inter_7=50.0, 234 flat7_sld=4.0, 235 thick_flat_7=100.0, 236 func_inter_8=0, 237 nu_inter_8=2.5, 238 thick_inter_8=50.0, 239 flat8_sld=3.5, 240 thick_flat_8=100.0, 241 func_inter_9=0, 242 nu_inter_9=2.5, 243 thick_inter_9=50.0, 244 flat9_sld=4.0, 245 thick_flat_9=100.0, 246 func_inter_10=0, 247 nu_inter_10=2.5, 248 thick_inter_10=50.0, 249 flat10_sld=3.5, 250 thick_flat_10=100.0 251 ) 256 252 257 253 oldname = "SphereSLDModel" 258 254 oldpars = dict( 259 n_shells="n_shells", 260 scale="scale", 261 npts_inter='npts_inter', 262 solvent_sld='sld_solv', 263 func_inter_0='func_inter0', 264 nu_inter_0='nu_inter0', 265 background='background', 266 rad_core_0='rad_core0', 267 core0_sld='sld_core0', 268 thick_inter_0='thick_inter0', 269 func_inter_1='func_inter1', 270 nu_inter_1='nu_inter1', 271 thick_inter_1='thick_inter1', 272 flat1_sld='sld_flat1', 273 thick_flat_1='thick_flat1', 274 func_inter_2='func_inter2', 275 nu_inter_2='nu_inter2', 276 thick_inter_2='thick_inter2', 277 flat2_sld='sld_flat2', 278 thick_flat_2='thick_flat2', 279 func_inter_3='func_inter3', 280 nu_inter_3='nu_inter3', 281 thick_inter_3='thick_inter3', 282 flat3_sld='sld_flat3', 283 thick_flat_3='thick_flat3', 284 func_inter_4='func_inter4', 285 nu_inter_4='nu_inter4', 286 thick_inter_4='thick_inter4', 287 flat4_sld='sld_flat4', 288 thick_flat_4='thick_flat4', 289 func_inter_5='func_inter5', 290 nu_inter_5='nu_inter5', 291 thick_inter_5='thick_inter5', 292 flat5_sld='sld_flat5', 293 thick_flat_5='thick_flat5', 294 func_inter_6='func_inter6', 295 nu_inter_6='nu_inter6', 296 thick_inter_6='thick_inter6', 297 flat6_sld='sld_flat6', 298 thick_flat_6='thick_flat6', 299 func_inter_7='func_inter7', 300 nu_inter_7='nu_inter7', 301 thick_inter_7='thick_inter7', 302 flat7_sld='sld_flat7', 303 thick_flat_7='thick_flat7', 304 func_inter_8='func_inter8', 305 nu_inter_8='nu_inter8', 306 thick_inter_8='thick_inter8', 307 flat8_sld='sld_flat8', 308 thick_flat_8='thick_flat8', 309 func_inter_9='func_inter9', 310 nu_inter_9='nu_inter9', 311 thick_inter_9='thick_inter9', 312 flat9_sld='sld_flat9', 313 thick_flat_9='thick_flat9', 314 func_inter_10='func_inter10', 315 nu_inter_10='nu_inter10', 316 thick_inter_10='thick_inter10', 317 flat10_sld='sld_flat10', 318 thick_flat_10='thick_flat10') 255 n_shells="n_shells", 256 scale="scale", 257 background='background', 258 npts_inter='npts_inter', 259 solvent_sld='sld_solv', 260 261 func_inter_0='func_inter0', 262 nu_inter_0='nu_inter0', 263 rad_core_0='rad_core0', 264 core0_sld='sld_core0', 265 thick_inter_0='thick_inter0', 266 func_inter_1='func_inter1', 267 nu_inter_1='nu_inter1', 268 thick_inter_1='thick_inter1', 269 flat1_sld='sld_flat1', 270 thick_flat_1='thick_flat1', 271 func_inter_2='func_inter2', 272 nu_inter_2='nu_inter2', 273 thick_inter_2='thick_inter2', 274 flat2_sld='sld_flat2', 275 thick_flat_2='thick_flat2', 276 func_inter_3='func_inter3', 277 nu_inter_3='nu_inter3', 278 thick_inter_3='thick_inter3', 279 flat3_sld='sld_flat3', 280 thick_flat_3='thick_flat3', 281 func_inter_4='func_inter4', 282 nu_inter_4='nu_inter4', 283 thick_inter_4='thick_inter4', 284 flat4_sld='sld_flat4', 285 thick_flat_4='thick_flat4', 286 func_inter_5='func_inter5', 287 nu_inter_5='nu_inter5', 288 thick_inter_5='thick_inter5', 289 flat5_sld='sld_flat5', 290 thick_flat_5='thick_flat5', 291 func_inter_6='func_inter6', 292 nu_inter_6='nu_inter6', 293 thick_inter_6='thick_inter6', 294 flat6_sld='sld_flat6', 295 thick_flat_6='thick_flat6', 296 func_inter_7='func_inter7', 297 nu_inter_7='nu_inter7', 298 thick_inter_7='thick_inter7', 299 flat7_sld='sld_flat7', 300 thick_flat_7='thick_flat7', 301 func_inter_8='func_inter8', 302 nu_inter_8='nu_inter8', 303 thick_inter_8='thick_inter8', 304 flat8_sld='sld_flat8', 305 thick_flat_8='thick_flat8', 306 func_inter_9='func_inter9', 307 nu_inter_9='nu_inter9', 308 thick_inter_9='thick_inter9', 309 flat9_sld='sld_flat9', 310 thick_flat_9='thick_flat9', 311 func_inter_10='func_inter10', 312 nu_inter_10='nu_inter10', 313 thick_inter_10='thick_inter10', 314 flat10_sld='sld_flat10', 315 thick_flat_10='thick_flat10') 319 316 320 317 #TODO: Not working yet -
sasmodels/product.py
re9b1663d rce896fd 14 14 15 15 from .core import call_ER_VR 16 from .generate import process_parameters17 16 18 17 SCALE=0 … … 64 63 model_info['oldpars'] = oldpars 65 64 model_info['composition'] = ('product', [p_info, s_info]) 66 process_parameters(model_info)67 65 return model_info 68 66 -
sasmodels/sasview_model.py
r787be86 rce896fd 32 32 33 33 Returns a class that can be used directly as a sasview model.t 34 35 Defaults to using the new name for a model. Setting36 *namestyle='oldname'* will produce a class with a name37 compatible with SasView.38 34 """ 39 35 model_info = core.load_model_info(model_name) … … 58 54 self._kernel = None 59 55 model_info = self._model_info 56 parameters = model_info['parameters'] 60 57 61 58 self.name = model_info['name'] 62 self.oldname = model_info['oldname']63 59 self.description = model_info['description'] 64 60 self.category = None 65 self.multiplicity_info = None 66 self.is_multifunc = False 61 #self.is_multifunc = False 62 for p in parameters.kernel_parameters: 63 if p.is_control: 64 profile_axes = model_info['profile_axes'] 65 self.multiplicity_info = [ 66 p.limits[1], p.name, p.choices, profile_axes[0] 67 ] 68 break 69 else: 70 self.multiplicity_info = [] 67 71 68 72 ## interpret the parameters
Note: See TracChangeset
for help on using the changeset viewer.