Changeset 1affe64 in sasview for sansmodels/src/sans/models
- Timestamp:
- Sep 11, 2009 10:41:02 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:
- 9002927
- Parents:
- c1e865a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/MultiplicationModel.py
r8b677ec r1affe64 6 6 class MultiplicationModel(BaseComponent): 7 7 """ 8 Use for P(Q)*S(Q); function call must be in order of P(Q) and then S(Q). 9 Perform multiplication of two models. 10 Contains the models parameters combined. 8 Use for P(Q)*S(Q); function call must be in the order of P(Q) and then S(Q): 9 The model parameters are combined from both models, P(Q) and S(Q), except 'effective_radius' of S(Q) 10 which will be calculated from P(Q) via calculate_ER(). 11 The polydispersion is applicable only to P(Q), not to S(Q). 12 Note: P(Q) refers to 'form factor' model while S(Q) does to 'structure factor'. 11 13 """ 12 def __init__(self, model1, model2):14 def __init__(self, p_model, s_model ): 13 15 BaseComponent.__init__(self) 14 15 16 """ 17 @param p_model: form factor, P(Q) 18 @param s_model: structure factor, S(Q) 19 """ 20 16 21 ## Setting model name model description 17 22 self.description="" 18 if model1.name != "NoStructure" and model2.name != "NoStructure": 19 self.name = model1.name +" * "+ model2.name 20 self.description= self.name+"\n" 21 self.fill_description(model1, model2) 22 elif model2.name != "NoStructure": 23 self.name = model2.name 24 self.description= model2.description 25 else : 26 self.name = model1.name 27 self.description= model1.description 23 self.name = p_model.name +" * "+ s_model.name 24 self.description= self.name+"\n" 25 self.fill_description(p_model, s_model) 28 26 29 30 self. model1= model131 self. model2= model227 ##models 28 self.p_model= p_model 29 self.s_model= s_model 32 30 33 31 … … 41 39 self._set_fixed_params() 42 40 ## parameters with orientation 43 for item in self. model1.orientation_params:41 for item in self.p_model.orientation_params: 44 42 self.orientation_params.append(item) 45 43 46 for item in self. model2.orientation_params:44 for item in self.s_model.orientation_params: 47 45 if not item in self.orientation_params: 48 46 self.orientation_params.append(item) … … 58 56 obj.details = copy.deepcopy(self.details) 59 57 obj.dispersion = copy.deepcopy(self.dispersion) 60 obj. model1 = self.model1.clone()61 obj. model2 = self.model2.clone()58 obj.p_model = self.p_model.clone() 59 obj.s_model = self.s_model.clone() 62 60 63 61 return obj … … 67 65 """ 68 66 combined the two models dispersions 69 """ 70 for name , value in self.model1.dispersion.iteritems(): 71 self.dispersion[name]= value 72 73 for name , value in self.model2.dispersion.iteritems(): 74 ## All S(Q) has only 'effect_radius' for dispersion which 75 # will not be allowed for now. 76 if not name in self.dispersion.keys(): 77 if name != 'effect_radius': 78 self.dispersion[name]= value 79 80 81 82 67 Polydispersion should not be applied to s_model 68 """ 69 ##set dispersion only from p_model 70 for name , value in self.p_model.dispersion.iteritems(): 71 self.dispersion[name]= value 72 83 73 def _set_params(self): 84 74 """ … … 86 76 this model parameters 87 77 """ 88 dia_rad = 0 89 for name , value in self. model1.params.iteritems():78 79 for name , value in self.p_model.params.iteritems(): 90 80 self.params[name]= value 91 81 92 for name , value in self.model2.params.iteritems(): 93 if not name in self.params.keys(): 94 #effect_radius is not treated as a parameter anymore. 95 if name != 'effect_radius': 96 self.params[name]= value 82 for name , value in self.s_model.params.iteritems(): 83 #Remove the effect_radius from the (P*S) model parameters. 84 if not name in self.params.keys() and name != 'effect_radius': 85 self.params[name]= value 97 86 98 87 def _set_details(self): … … 101 90 this model details 102 91 """ 103 for name ,detail in self. model1.details.iteritems():92 for name ,detail in self.p_model.details.iteritems(): 104 93 self.details[name]= detail 105 94 106 for name , detail in self.model2.details.iteritems(): 107 if not name in self.details.keys(): 108 if name != 'effect_radius': 109 self.details[name]= detail 95 for name , detail in self.s_model.details.iteritems(): 96 if not name in self.details.keys(): 97 self.details[name]= detail 110 98 111 99 def setParam(self, name, value): … … 119 107 self._setParamHelper( name, value) 120 108 121 if name in self. model1.getParamList():122 self. model1.setParam( name, value)123 124 if name in self. model2.getParamList():125 self. model2.setParam( name, value)109 if name in self.p_model.getParamList(): 110 self.p_model.setParam( name, value) 111 112 if name in self.s_model.getParamList(): 113 self.s_model.setParam( name, value) 126 114 127 115 self._setParamHelper( name, value) … … 152 140 def _set_fixed_params(self): 153 141 """ 154 fill the self.fixed list with the two modelsfixed list155 """ 156 for item in self. model1.fixed:142 fill the self.fixed list with the p_model fixed list 143 """ 144 for item in self.p_model.fixed: 157 145 self.fixed.append(item) 158 #S(Q) should not have fixed items for P*S for now.159 #for item in self.model2.fixed:160 # if not item in self.fixed:161 # self.fixed.append(item)162 146 163 147 self.fixed.sort() … … 169 153 @return: (DAB value) 170 154 """ 171 #Reset radius of model2 just before the run 172 effective_radius = None 173 effective_radius = self.model1.calculate_ER() 174 if effective_radius !=None: 175 self.model2.setParam( 'effect_radius',effective_radius) 176 177 return self.model1.run(x)*self.model2.run(x) 178 155 156 effective_radius = self.p_model.calculate_ER() 157 #Reset the effective_radius of s_model just before the run 158 if effective_radius != None and effective_radius != NotImplemented: 159 self.s_model.setParam('effect_radius',effective_radius) 160 return self.p_model.run(x)*self.s_model.run(x) 161 179 162 def runXY(self, x = 0.0): 180 163 """ Evaluate the model … … 183 166 """ 184 167 185 #Reset radius of model2 just before the run 186 effective_radius = None 187 effective_radius = self.model1.calculate_ER() 188 if effective_radius !=None: 189 self.model2.setParam( 'effect_radius',effective_radius) 190 191 return self.model1.runXY(x)* self.model2.runXY(x) 192 168 effective_radius = self.p_model.calculate_ER() 169 #Reset the effective_radius of s_model just before the run 170 if effective_radius != None and effective_radius != NotImplemented: 171 self.s_model.setParam('effect_radius',effective_radius) 172 return self.p_model.runXY(x)* self.s_model.runXY(x) 173 193 174 def set_dispersion(self, parameter, dispersion): 194 175 """ … … 199 180 value= None 200 181 try: 201 if parameter in self.model1.dispersion.keys(): 202 value= self.model1.set_dispersion(parameter, dispersion) 203 #There is no dispersion for the structure factors(S(Q)). 204 #ToDo: need to decide whether or not the dispersion for S(Q) has to be considered for P*S. 205 #elif parameter in self.model2.dispersion.keys(): 206 # if item != 'effect_radius': 207 # value= self.model2.set_dispersion(parameter, dispersion) 182 if parameter in self.p_model.dispersion.keys(): 183 value= self.p_model.set_dispersion(parameter, dispersion) 208 184 self._set_dispersion() 209 185 return value … … 211 187 raise 212 188 213 def fill_description(self, model1, model2):189 def fill_description(self, p_model, s_model): 214 190 """ 215 191 Fill the description for P(Q)*S(Q) 216 192 """ 217 193 description = "" 218 description += "Note:1) The effect_radius (effective radius) of %s \n"% ( model2.name)194 description += "Note:1) The effect_radius (effective radius) of %s \n"% (s_model.name) 219 195 description +=" is automatically calculated from size parameters (radius...).\n" 220 196 description += " 2) For non-spherical shape, this approximation is valid \n" 221 description += " only for highly dilutesystems. Thus, use it at your own risk.\n"222 description +="See %s description and %s description \n"%( model1.name,model2.name )223 description += " for details ."197 description += " only for limited systems. Thus, use it at your own risk.\n" 198 description +="See %s description and %s description \n"%( p_model.name, s_model.name ) 199 description += " for details of individual models." 224 200 self.description += description 225 201
Note: See TracChangeset
for help on using the changeset viewer.