Changeset ab62adb in sasview for sansmodels
- Timestamp:
- Aug 31, 2009 11:01:51 AM (15 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:
- 1467e1a6
- Parents:
- 25baf31
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/MultiplicationModel.py
r3ba03a4c rab62adb 18 18 ## Setting model name model description 19 19 self.description="" 20 if model1.name != "NoStructure" and model2.name != "NoStructure":20 if model1.name != "NoStructure" and model2.name != "NoStructure": 21 21 self.name = model1.name +" * "+ model2.name 22 22 self.description= self.name+"\n" … … 30 30 self.description= model1.description 31 31 32 #For virial coefficients for only two P(Q) models,"CylinderModel","EllipsoidModel". SphereModel works w/o it. 33 modelDiam = None 34 if model1.__class__.__name__ == "CylinderModel": 35 Model1DPlugin("DiamCylFunc") 36 modelDiam = DiamCylFunc() 37 para1 = 'radius' 38 para2 = 'length' 39 40 elif model1.__class__.__name__ == "EllipsoidModel": 41 Model1DPlugin("DiamEllipFunc") 42 modelDiam = DiamEllipFunc() 43 para1 = 'radius_a' 44 para2 = 'radius_b' 45 46 self.modelD = modelDiam 47 48 if model1.__class__.__name__ == "CylinderModel" \ 49 or model1.__class__.__name__ == "EllipsoidModel": 50 51 self.para1 = para1 52 self.para2 = para2 53 54 32 33 55 34 self.model1= model1 56 35 self.model2= model2 57 58 36 37 ## Define diaparams 38 self._set_diaparams() 59 39 ## dispersion 60 40 self._set_dispersion() … … 73 53 self.orientation_params.append(item) 74 54 75 55 76 56 def _clone(self, obj): 77 57 """ … … 101 81 self.dispersion[name]= value 102 82 103 104 83 105 84 106 85 def _set_params(self): … … 109 88 this model parameters 110 89 """ 90 #Prepare for radius calculation for Diam** functions 91 #Only allows two case of radius modifications (radius = core_radius + thickness or just radius =radius). 92 dia_rad = 0 111 93 112 94 for name , value in self.model1.params.iteritems(): 113 95 self.params[name]= value 114 96 115 if self.modelD !=None: 116 if name == self.para1 or name == self.para2: 117 self.modelD.params[name]= value 118 elif name in self.model2.getParamList() and name !='radius': 97 if self.model2.name != 'NoStructure': 98 if len(self.diapara[self.para[0]])>1 and \ 99 (name == self.diapara[self.para[0]][0] or \ 100 name == self.diapara[self.para[0]][1]): 101 dia_rad += value 102 103 if self.modelD !=None: 104 self.modelD.params[self.para[0]]= dia_rad 105 else: 106 self.model2.setParam("radius", dia_rad) 107 108 elif self.modelD !=None: 109 if name == self.diapara[self.para[0]]: 110 self.modelD.params[self.para[0]]= value 111 elif name == self.diapara[self.para[1]]: 112 self.modelD.params[self.para[1]]= value 113 elif name in self.model2.getParamList(): 119 114 self.model2.setParam( name, value) 120 121 elif name in self.model2.getParamList():122 self.model2.setParam(name, value)115 116 117 print "value=",dia_rad 123 118 if self.modelD !=None: 124 119 self.model2.setParam('radius', self.modelD.run()) … … 152 147 if name in self.model1.getParamList(): 153 148 self.model1.setParam( name, value) 154 if self.modelD !=None: 155 if name==self.para1 or name == self.para2: 156 self.modelD.params[name]= value 149 150 if self.model2.name != 'NoStructure': 151 if len(self.diapara[self.para[0]])>1 and \ 152 (name == self.diapara[self.para[0]][0] or \ 153 name == self.diapara[self.para[0]][1]): 154 self._set_params() 155 elif self.modelD !=None: 156 if name == self.diapara[self.para[0]]: 157 self.modelD.params[self.para[0]]= value 158 self.model2.setParam('radius', self.modelD.run()) 159 elif name == self.diapara[self.para[1]]: 160 self.modelD.params[self.para[1]]= value 157 161 self.model2.setParam('radius', self.modelD.run()) 158 162 elif name in self.model2.getParamList(): 159 self.model2.setParam( name, value)160 else:161 if name in self.model2.getParamList():162 163 self.model2.setParam( name, value) 163 164 164 165 #print "val2=",name,self.model2.params['radius'] 165 166 166 167 self._setParamHelper( name, value) … … 203 204 self.fixed.append(item) 204 205 self.fixed.sort() 205 206 206 207 208 def _set_diaparams(self): 209 """ 210 Assign diamfunction parameters from model1. 211 """ 212 #For virial coefficients for only two P(Q) models,"CylinderModel","EllipsoidModel". SphereModel works w/o it. 213 modelDiam = None 214 215 #List of models by type that can be multiplied of P(Q)*S(Q) 216 #Parameters of model1 that need apply to the modelDiam corresponding to the models above 217 list_sph_model_param = {'SphereModel':[['radius']],\ 218 'CoreShellModel':[['radius','thickness']],\ 219 'VesicleModel':[['radius','thickness']], \ 220 'BinaryHSModel':[['l_radius']], \ 221 'MultiShellModel':[['core_radius','s_thickness']]} 222 list_cyl_model_param = {'CylinderModel':[['radius'],['length']],\ 223 'CoreShellCylinderModel':[['radius','thickness'],['length']],\ 224 'HollowCylinderModel':[['radius'],['length']],\ 225 'FlexibleCylinderModel':[['radius'],['length']]} 226 list_ell_model_param = {'EllipsoidModel':[['radius_a'],['radius_b']],\ 227 'CoreShellEllipsoidModel':[['polar_shell'],['equat_shell']]} 228 229 #This is where the list of the input parameters for ModelDiam will be. 230 self.diapara = {} 231 for key in list_sph_model_param: 232 print "list_sph_models.param[]",len(list_sph_model_param['SphereModel']) 233 #Find the input parameters for ModelDiam depending on model1. 234 para = {} 235 self.para = {} 236 237 #Determine the type of the model1 238 if self.model1.__class__.__name__ in list_cyl_model_param.keys(): 239 Model1DPlugin("DiamCylFunc") 240 basename = 'CylinderModel' 241 modelDiam = DiamCylFunc() 242 #loop for the # of parameters of DiamCylFunc() 243 for idx in (0,len(list_cyl_model_param[basename])-1): 244 #Parameter names of DiamCYlFunc 245 para[idx] = list_cyl_model_param[basename][idx][0] 246 #Find the equivalent parameters of model1 function . 247 self.diapara[para[idx]] = list_cyl_model_param[self.model1.__class__.__name__][idx] 248 self.para[idx] = para[idx] 249 250 elif self.model1.__class__.__name__ in list_ell_model_param.keys(): 251 Model1DPlugin("DiamEllipFunc") 252 basename = 'EllipsoidModel' 253 modelDiam = DiamEllipFunc() 254 for idx in (0,len(list_ell_model_param[basename])-1): 255 para[idx ] = list_ell_model_param[basename][idx ][0] 256 self.diapara[para[idx]] = list_ell_model_param[self.model1.__class__.__name__][idx] 257 self.para[idx] = para[idx] 258 259 elif self.model1.__class__.__name__ in list_sph_model_param.keys() : 260 basename = 'SphereModel' 261 for idx in (0,len(list_sph_model_param[basename])-1): 262 para[idx] = list_sph_model_param[basename][idx][0] 263 self.diapara[para[idx]] = list_sph_model_param[self.model1.__class__.__name__][idx] 264 self.para[idx] = para[idx] 265 266 #print "self.diapara1",para[0],self.diapara[para[0]] 267 268 self.modelD = modelDiam 269 207 270 def run(self, x = 0.0): 208 271 """ Evaluate the model … … 217 280 @return: DAB value 218 281 """ 282 print "model1.effecitve_radius",self.model1.calculate_ER() 219 283 return self.model1.runXY(x)* self.model2.runXY(x) 220 284 … … 229 293 if parameter in self.model1.dispersion.keys(): 230 294 value= self.model1.set_dispersion(parameter, dispersion) 231 #There is no dispersion for the structure factors(S(Q)) .295 #There is no dispersion for the structure factors(S(Q)) for now. 232 296 #ToDo: need to decide whether or not the dispersion for S(Q) has to be considered for P*S. 233 297 elif parameter in self.model2.dispersion.keys()and name !='radius':
Note: See TracChangeset
for help on using the changeset viewer.