Changeset 2e0053e in sasview for sansmodels
- Timestamp:
- Apr 18, 2012 2:10:29 PM (13 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 364658d
- Parents:
- 2dda7ae1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/SphericalSLDModel.py
rcd075e8 r2e0053e 1 1 """ 2 Spherical SLD model 3 """ 2 4 from sans.models.BaseComponent import BaseComponent 3 5 from sans.models.SphereSLDModel import SphereSLDModel 4 6 from copy import deepcopy 5 7 from math import floor 6 #from scipy.special import erf7 8 func_list = {'Erf(|nu|*z)':0, 'RPower(z^|nu|)':1, 'LPower(z^|nu|)':2, \ 8 9 'RExp(-|nu|*z)':3, 'LExp(-|nu|*z)':4} 9 10 max_nshells = 10 11 10 12 class SphericalSLDModel(BaseComponent): 11 13 """ … … 14 16 """ 15 17 def __init__(self, multfactor=1): 18 """ 19 :param multfactor: number of layers in the model, 20 assumes 0<= n_shells <=10. 21 """ 16 22 BaseComponent.__init__(self) 17 """18 :param multfactor: number of layers in the model,19 assumes 0<= n_shells <=10.20 """21 23 22 24 ## Setting model name model description 23 self.description =""25 self.description = "" 24 26 model = SphereSLDModel() 25 27 self.model = model 26 28 self.name = "SphericalSLDModel" 27 self.description =model.description29 self.description = model.description 28 30 self.n_shells = multfactor 29 31 ## Define parameters … … 53 55 # [int(maximum no. of functionality),"str(Titl), 54 56 # [str(name of function0),...], [str(x-asix name of sld),...]] 55 self.multiplicity_info = [max_nshells, "No. of Shells:",[],['Radius']]57 self.multiplicity_info = [max_nshells, "No. of Shells:", [], ['Radius']] 56 58 57 59 … … 80 82 nshell = -1 81 83 if name.split('_')[0] == 'thick': 82 while nshell <1:84 while nshell < 1: 83 85 nshell += 1 84 86 if name.split('_')[1] == 'inter%s' % str(nshell): 85 self.dispersion[name] = value87 self.dispersion[name] = value 86 88 else: 87 89 continue 88 90 else: 89 self.dispersion[name] = value91 self.dispersion[name] = value 90 92 91 93 def _set_params(self): … … 101 103 last_name = name.split('_')[pos] 102 104 if first_name == 'npts': 103 self.params[name] =value105 self.params[name] = value 104 106 continue 105 107 elif first_name == 'func': 106 n = -1107 while n <self.n_shells:108 n = -1 109 while n < self.n_shells: 108 110 n += 1 109 111 if last_name == 'inter%s' % str(n): 110 self.params[name] =value112 self.params[name] = value 111 113 continue 112 114 elif last_name[0:5] == 'inter': 113 n = -1114 while n <self.n_shells:115 n = -1 116 while n < self.n_shells: 115 117 n += 1 116 118 if last_name == 'inter%s' % str(n): 117 self.params[name] = value119 self.params[name] = value 118 120 continue 119 121 elif last_name[0:4] == 'flat': 120 while n <self.n_shells:122 while n < self.n_shells: 121 123 n += 1 122 124 if last_name == 'flat%s' % str(n): 123 self.params[name] = value125 self.params[name] = value 124 126 continue 125 127 elif name == 'n_shells': 126 128 continue 127 129 else: 128 self.params[name] = value130 self.params[name] = value 129 131 130 132 self.model.params['n_shells'] = self.n_shells … … 138 140 this model details 139 141 """ 140 for name ,detail in self.model.details.iteritems():142 for name, detail in self.model.details.iteritems(): 141 143 if name in self.params.iterkeys(): 142 self.details[name] = detail144 self.details[name] = detail 143 145 144 146 … … 150 152 for key in self.model.params.iterkeys(): 151 153 if key not in self.params.keys(): 152 if 154 if key.split('_')[0] == 'thick': 153 155 self.model.setParam(key, 0) 154 156 continue 155 if 156 157 157 if key.split('_')[0] == 'func': 158 self.model.setParam(key, 0) 159 continue 158 160 159 161 for nshell in range(self.n_shells,max_nshells): … … 163 165 value = self.model.params['sld_solv'] 164 166 self.model.setParam(key, value) 165 except: pass 167 except: 168 raise RuntimeError, "SphericalSLD model problem" 166 169 167 170 def _get_func_list(self): … … 169 172 Get the list of functions in each layer (shell) 170 173 """ 171 #func_list = {}172 174 return func_list 173 175 … … 184 186 beta = [] 185 187 z0 = 0 186 sub_range = floor(n_sub/2.0)187 188 # two sld points for core 188 189 z.append(0) … … 192 193 z0 += self.params['rad_core0'] 193 194 # for layers from the core 194 for n in range(1, self.n_shells+2):195 for n in range(1, self.n_shells+2): 195 196 i = n 197 dz = self.params['thick_inter%s'% str(i-1)]/n_sub 196 198 # j=0 for interface, j=1 for flat layer 197 for j in range(0, 2):199 for j in range(0, 2): 198 200 # interation for sub-layers 199 for n_s in range(0, n_sub+1):200 if j ==1:201 if i ==self.n_shells+1:201 for n_s in range(0, n_sub+1): 202 if j == 1: 203 if i == self.n_shells+1: 202 204 break 203 205 # shift half sub thickness for the first point … … 205 207 z.append(z0) 206 208 #z0 -= dz/2.0 207 z0 += self.params['thick_flat%s' % str(i)]209 z0 += self.params['thick_flat%s' % str(i)] 208 210 209 sld_i = self.params['sld_flat%s' % str(i)]210 beta.append(self.params['sld_flat%s' % str(i)])211 sld_i = self.params['sld_flat%s' % str(i)] 212 beta.append(self.params['sld_flat%s' % str(i)]) 211 213 dz = 0 212 214 else: 213 dz = self.params['thick_inter%s'% str(i-1)]/n_sub 214 nu = self.params['nu_inter%s'% str(i-1)] 215 nu = self.params['nu_inter%s' % str(i-1)] 215 216 # decide which sld is which, sld_r or sld_l 216 217 if i == 1: 217 218 sld_l = self.params['sld_core0'] 218 219 else: 219 sld_l = self.params['sld_flat%s' % str(i-1)]220 sld_l = self.params['sld_flat%s' % str(i-1)] 220 221 if i == self.n_shells+1: 221 222 sld_r = self.params['sld_solv'] 222 223 else: 223 sld_r = self.params['sld_flat%s' % str(i)]224 sld_r = self.params['sld_flat%s' % str(i)] 224 225 # get function type 225 func_idx = self.params['func_inter%s' % str(i-1)]226 func_idx = self.params['func_inter%s' % str(i-1)] 226 227 # calculate the sld 227 228 sld_i = self._get_sld(func_idx, n_sub, n_s, nu, … … 231 232 beta.append(sld_i) 232 233 z0 += dz 233 if j==1: break 234 if j == 1: 235 break 234 236 # put sld of solvent 235 237 z.append(z0) … … 256 258 sld_cal = SLDCalFunc() 257 259 # set params 258 sld_cal.setParam('fun_type', func_idx)259 sld_cal.setParam('npts_inter', n_sub)260 sld_cal.setParam('shell_num', n_s)261 sld_cal.setParam('nu_inter', nu)262 sld_cal.setParam('sld_left', sld_l)263 sld_cal.setParam('sld_right', sld_r)260 sld_cal.setParam('fun_type', func_idx) 261 sld_cal.setParam('npts_inter', n_sub) 262 sld_cal.setParam('shell_num', n_s) 263 sld_cal.setParam('nu_inter', nu) 264 sld_cal.setParam('sld_left', sld_l) 265 sld_cal.setParam('sld_right', sld_r) 264 266 # return sld value 265 267 return sld_cal.run() … … 273 275 """ 274 276 # set param to new model 275 self._setParamHelper( 277 self._setParamHelper(name, value) 276 278 277 279 ## setParam to model 278 if name =='sld_solv':280 if name == 'sld_solv': 279 281 # the sld_*** model.params not in params must set to 280 282 # value of sld_solv 281 283 for key in self.model.params.iterkeys(): 282 if key not in self.params.keys() and key.split('_')[0] == 'sld':283 284 if key not in self.params.keys() and key.split('_')[0] == 'sld': 285 self.model.setParam(key, value) 284 286 285 self.model.setParam( 287 self.model.setParam(name, value) 286 288 287 289 def _setParamHelper(self, name, value): … … 290 292 """ 291 293 toks = name.split('.') 292 if len(toks) ==2:294 if len(toks) == 2: 293 295 for item in self.dispersion.keys(): 294 if item.lower() ==toks[0].lower():296 if item.lower() == toks[0].lower(): 295 297 for par in self.dispersion[item]: 296 298 if par.lower() == toks[1].lower(): … … 299 301 # Look for standard parameter 300 302 for item in self.params.keys(): 301 if item.lower() ==name.lower():303 if item.lower() == name.lower(): 302 304 self.params[item] = value 303 305 return … … 315 317 316 318 self.fixed.sort() 317 pass318 319 319 320 def run(self, x = 0.0): … … 341 342 ## Now (May27,10) directly uses the model eval function 342 343 ## instead of the for-loop in Base Component. 343 def evalDistribution(self, x = []):344 def evalDistribution(self, x): 344 345 """ 345 346 Evaluate the model in cartesian coordinates … … 350 351 # set effective radius and scaling factor before run 351 352 return self.model.evalDistribution(x) 353 352 354 def calculate_ER(self): 353 355 """ 354 356 """ 355 357 return self.model.calculate_ER() 358 356 359 def set_dispersion(self, parameter, dispersion): 357 360 """ … … 361 364 :dispersion: dispersion object of type DispersionModel 362 365 """ 363 value= None 364 try: 365 if parameter in self.model.dispersion.keys(): 366 value= self.model.set_dispersion(parameter, dispersion) 367 self._set_dispersion() 368 return value 369 except: 370 raise 366 value = None 367 if parameter in self.model.dispersion.keys(): 368 value = self.model.set_dispersion(parameter, dispersion) 369 self._set_dispersion() 370 return value
Note: See TracChangeset
for help on using the changeset viewer.