[35aface] | 1 | |
---|
[79492222] | 2 | from sas.models.BaseComponent import BaseComponent |
---|
| 3 | from sas.models.RPAModel import RPAModel |
---|
[35aface] | 4 | from copy import deepcopy |
---|
| 5 | max_case_n = 10 |
---|
| 6 | class RPA10Model(BaseComponent): |
---|
| 7 | """ |
---|
| 8 | This multi-model is based on Parratt formalism and provides the capability |
---|
| 9 | of changing the number of layers between 0 and 10. |
---|
| 10 | """ |
---|
| 11 | def __init__(self, multfactor=1): |
---|
| 12 | BaseComponent.__init__(self) |
---|
| 13 | """ |
---|
| 14 | :param multfactor: number of cases in the model, assumes 0<= case# <=10. |
---|
| 15 | """ |
---|
| 16 | |
---|
| 17 | ## Setting model name model description |
---|
| 18 | self.description="" |
---|
| 19 | model = RPAModel() |
---|
| 20 | self.model = model |
---|
| 21 | self.name = "RPA10Model" |
---|
| 22 | self.description=model.description |
---|
| 23 | self.case_num = multfactor |
---|
| 24 | ## Define parameters |
---|
| 25 | self.params = {} |
---|
| 26 | |
---|
| 27 | ## Parameter details [units, min, max] |
---|
| 28 | self.details = {} |
---|
| 29 | |
---|
| 30 | # non-fittable parameters |
---|
| 31 | self.non_fittable = model.non_fittable |
---|
| 32 | |
---|
| 33 | # list of function in order of the function number |
---|
| 34 | self.fun_list = self._get_func_list() |
---|
| 35 | ## dispersion |
---|
| 36 | self._set_dispersion() |
---|
| 37 | ## Define parameters |
---|
| 38 | self._set_params() |
---|
| 39 | |
---|
| 40 | ## Parameter details [units, min, max] |
---|
| 41 | self._set_details() |
---|
| 42 | |
---|
| 43 | #list of parameter that can be fitted |
---|
| 44 | self._set_fixed_params() |
---|
| 45 | self.model.params['lcase_n'] = self.case_num |
---|
| 46 | |
---|
| 47 | ## functional multiplicity of the model |
---|
[339ce67] | 48 | self.multiplicity_info = [max_case_n,"Case No.:",["C/D Binary Mixture of Homopolymers", |
---|
| 49 | "C-D Diblock Copolymer", |
---|
| 50 | "B/C/D Ternary Mixture of Homopolymers", |
---|
| 51 | "B/C-D Mixture of Homopolymer B and Diblock Copolymer C-D", |
---|
| 52 | "B-C-D Triblock Copolymer", |
---|
| 53 | "A/B/C/D Quaternary Mixture of Homopolymers", |
---|
| 54 | "A/B/C-D Mixture of Homopolymer A/B and Diblock C-D", |
---|
| 55 | "A/B-C-D Mixture of Homopolymer A and triblock B-C-D", |
---|
| 56 | "A-B/C-D Mixture of Diblock Copolymer A-B and Diblock C-D", |
---|
| 57 | "A-B-C-D Four-block Copolymer"], |
---|
| 58 | []] |
---|
[35aface] | 59 | |
---|
| 60 | def _clone(self, obj): |
---|
| 61 | """ |
---|
| 62 | Internal utility function to copy the internal |
---|
| 63 | data members to a fresh copy. |
---|
| 64 | """ |
---|
| 65 | obj.params = deepcopy(self.params) |
---|
| 66 | obj.non_fittable = deepcopy(self.non_fittable) |
---|
| 67 | obj.description = deepcopy(self.description) |
---|
| 68 | obj.details = deepcopy(self.details) |
---|
| 69 | obj.dispersion = deepcopy(self.dispersion) |
---|
| 70 | obj.model = self.model.clone() |
---|
| 71 | |
---|
| 72 | return obj |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | def _set_dispersion(self): |
---|
| 76 | """ |
---|
| 77 | model dispersions |
---|
| 78 | """ |
---|
| 79 | ##set dispersion from model |
---|
| 80 | self.dispersion = {} |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | def _set_params(self): |
---|
| 84 | """ |
---|
| 85 | Concatenate the parameters of the model to create |
---|
| 86 | this model parameters |
---|
| 87 | """ |
---|
| 88 | # set the case number first |
---|
| 89 | self.model.params['lcase_n'] = self.case_num |
---|
| 90 | # rearrange the parameters for the given # of shells |
---|
| 91 | for name , value in self.model.params.iteritems(): |
---|
| 92 | if name == 'lcase_n': |
---|
| 93 | continue |
---|
| 94 | elif name.lower() == 'scale' or \ |
---|
| 95 | name.lower() == 'background': |
---|
| 96 | self.params[name] = value |
---|
| 97 | elif self.case_num <= 1: |
---|
| 98 | if name.lower() == 'nc' or \ |
---|
| 99 | name.lower() == 'phic' or \ |
---|
| 100 | name.lower() == 'vc' or \ |
---|
| 101 | name.lower() == 'lc' or \ |
---|
| 102 | name.lower() == 'bc' or \ |
---|
| 103 | name.lower() == 'nd' or \ |
---|
| 104 | name.lower() == 'phid' or \ |
---|
| 105 | name.lower() == 'vd' or \ |
---|
| 106 | name.lower() == 'ld' or \ |
---|
| 107 | name.lower() == 'bd' or \ |
---|
| 108 | name.lower() == 'kcd': |
---|
| 109 | self.params[name] = value |
---|
| 110 | elif self.case_num > 1 and self.case_num <= 4: |
---|
| 111 | if name.lower() == 'nb' or \ |
---|
| 112 | name.lower() == 'phib' or \ |
---|
| 113 | name.lower() == 'vb' or \ |
---|
| 114 | name.lower() == 'lb' or \ |
---|
| 115 | name.lower() == 'bb' or \ |
---|
| 116 | name.lower() == 'nc' or \ |
---|
| 117 | name.lower() == 'phic' or \ |
---|
| 118 | name.lower() == 'vc' or \ |
---|
| 119 | name.lower() == 'lc' or \ |
---|
| 120 | name.lower() == 'bc' or \ |
---|
| 121 | name.lower() == 'nd' or \ |
---|
| 122 | name.lower() == 'phid' or \ |
---|
| 123 | name.lower() == 'vd' or \ |
---|
| 124 | name.lower() == 'ld' or \ |
---|
| 125 | name.lower() == 'bd' or \ |
---|
| 126 | name.lower() == 'kbc' or \ |
---|
| 127 | name.lower() == 'kbd' or \ |
---|
| 128 | name.lower() == 'kcd' : |
---|
| 129 | self.params[name] = value |
---|
| 130 | else: |
---|
| 131 | if name.lower() == 'na' or \ |
---|
| 132 | name.lower() == 'phia' or \ |
---|
| 133 | name.lower() == 'va' or \ |
---|
| 134 | name.lower() == 'la' or \ |
---|
| 135 | name.lower() == 'ba' or \ |
---|
| 136 | name.lower() == 'nb' or \ |
---|
| 137 | name.lower() == 'phib' or \ |
---|
| 138 | name.lower() == 'vb' or \ |
---|
| 139 | name.lower() == 'lb' or \ |
---|
| 140 | name.lower() == 'bb' or \ |
---|
| 141 | name.lower() == 'nc' or \ |
---|
| 142 | name.lower() == 'phic' or \ |
---|
| 143 | name.lower() == 'vc' or \ |
---|
| 144 | name.lower() == 'lc' or \ |
---|
| 145 | name.lower() == 'bc' or \ |
---|
| 146 | name.lower() == 'nd' or \ |
---|
| 147 | name.lower() == 'phid' or \ |
---|
| 148 | name.lower() == 'vd' or \ |
---|
| 149 | name.lower() == 'ld' or \ |
---|
| 150 | name.lower() == 'bd' or \ |
---|
| 151 | name.lower() == 'kab' or \ |
---|
| 152 | name.lower() == 'kac' or \ |
---|
| 153 | name.lower() == 'kad' or \ |
---|
| 154 | name.lower() == 'kbc' or \ |
---|
| 155 | name.lower() == 'kbd' or \ |
---|
| 156 | name.lower() == 'kcd' : |
---|
| 157 | self.params[name] = value |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | |
---|
| 161 | def _set_details(self): |
---|
| 162 | """ |
---|
| 163 | Concatenate details of the original model to create |
---|
| 164 | this model details |
---|
| 165 | """ |
---|
| 166 | for name ,detail in self.model.details.iteritems(): |
---|
| 167 | if name in self.params.iterkeys(): |
---|
| 168 | self.details[name]= detail |
---|
| 169 | |
---|
| 170 | def _get_func_list(self): |
---|
| 171 | """ |
---|
| 172 | Get the list of functions in each cases |
---|
| 173 | """ |
---|
| 174 | func_list = {} |
---|
| 175 | return func_list |
---|
| 176 | |
---|
| 177 | def getProfile(self): |
---|
| 178 | """ |
---|
| 179 | Get SLD profile |
---|
| 180 | |
---|
| 181 | : return: None, No SLD profile supporting for this model |
---|
| 182 | """ |
---|
| 183 | return None |
---|
| 184 | |
---|
| 185 | def setParam(self, name, value): |
---|
| 186 | """ |
---|
| 187 | Set the value of a model parameter |
---|
| 188 | |
---|
| 189 | : param name: name of the parameter |
---|
| 190 | : param value: value of the parameter |
---|
| 191 | """ |
---|
| 192 | # set param to new model |
---|
| 193 | self._setParamHelper( name, value) |
---|
| 194 | |
---|
| 195 | self.model.setParam( name, value) |
---|
| 196 | |
---|
| 197 | def _setParamHelper(self, name, value): |
---|
| 198 | """ |
---|
| 199 | Helper function to setParam |
---|
| 200 | """ |
---|
| 201 | |
---|
| 202 | # Look for standard parameter |
---|
| 203 | for item in self.params.keys(): |
---|
| 204 | if item.lower()==name.lower(): |
---|
| 205 | self.params[item] = value |
---|
| 206 | return |
---|
| 207 | |
---|
| 208 | raise ValueError, "Model does not contain parameter %s" % name |
---|
| 209 | |
---|
| 210 | |
---|
| 211 | def _set_fixed_params(self): |
---|
| 212 | """ |
---|
| 213 | Fill the self.fixed list with the model fixed list |
---|
| 214 | """ |
---|
| 215 | pass |
---|
| 216 | |
---|
| 217 | def run(self, x = 0.0): |
---|
| 218 | """ |
---|
| 219 | Evaluate the model |
---|
| 220 | |
---|
| 221 | :param x: input q, or [q,phi] |
---|
| 222 | |
---|
| 223 | :return: scattering function P(q) |
---|
| 224 | |
---|
| 225 | """ |
---|
| 226 | |
---|
| 227 | return self.model.run(x) |
---|
| 228 | |
---|
| 229 | def runXY(self, x = 0.0): |
---|
| 230 | """ |
---|
| 231 | Evaluate the model |
---|
| 232 | |
---|
| 233 | : param x: input q-value (float or [float, float] as [qx, qy]) |
---|
| 234 | : return: scattering function value |
---|
| 235 | """ |
---|
| 236 | |
---|
| 237 | return self.model.runXY(x) |
---|
| 238 | |
---|
| 239 | ## Now (May27,10) directly uses the model eval function |
---|
| 240 | ## instead of the for-loop in Base Component. |
---|
| 241 | def evalDistribution(self, x = []): |
---|
| 242 | """ |
---|
| 243 | Evaluate the model in cartesian coordinates |
---|
| 244 | |
---|
| 245 | : param x: input q[], or [qx[], qy[]] |
---|
| 246 | : return: scattering function P(q[]) |
---|
| 247 | """ |
---|
| 248 | # set effective radius and scaling factor before run |
---|
| 249 | return self.model.evalDistribution(x) |
---|
| 250 | def calculate_ER(self): |
---|
| 251 | """ |
---|
| 252 | """ |
---|
| 253 | return self.model.calculate_ER() |
---|
| 254 | def set_dispersion(self, parameter, dispersion): |
---|
| 255 | """ |
---|
| 256 | Set the dispersion object for a model parameter |
---|
| 257 | |
---|
| 258 | : param parameter: name of the parameter [string] |
---|
| 259 | :dispersion: dispersion object of type DispersionModel |
---|
| 260 | """ |
---|
| 261 | pass |
---|