Changeset cd5e29b in sasview for src/sas/models
- Timestamp:
- Sep 1, 2015 9:20:05 AM (9 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:
- f0d720b
- Parents:
- 40c5104 (diff), 600bea1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- src/sas/models
- Files:
-
- 3 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/models/BEPolyelectrolyte.py
r79492222 rac7be54 1 """ 2 Provide F(x) = K*1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k2)/(1+(r02)^(2))*(q^(2)+k2)\ 3 *(q^(2)-(12*h*C/b^(2))) 1 """ 4 2 BEPolyelectrolyte as a BaseComponent model 5 3 """ … … 12 10 Class that evaluates a BEPolyelectrolyte. 13 11 14 F(x) = K *1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k2)/(1+(r02)^(2))*(q^(2)+k2)\15 *(q^(2)-(12*h*C/b^(2)))12 F(x) = K/(4 pi Lb (alpha)^(2)) (q^(2)+k2)/(1+(r02)^(2)) (q^(2)+k2)\ 13 (q^(2)-(12 h C/b^(2))) 16 14 17 The model has Eight parameters: 18 K = Constrast factor of the polymer 19 Lb = Bjerrum length 20 H = virial parameter 21 B = monomer length 22 Cs = Concentration of monovalent salt 23 alpha = ionazation degree 15 The model has Eight parameters:: 16 17 K = Constrast factor of the polymer 18 Lb = Bjerrum length 19 H = virial parameter 20 B = monomer length 21 Cs = Concentration of monovalent salt 22 alpha = ionazation degree 24 23 C = polymer molar concentration 25 24 bkd = background … … 75 74 """ 76 75 Evaluate 77 F(x) = K *1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k2)/(1+(r02)^(2))78 *(q^(2)+k2)*(q^(2)-(12*h*C/b^(2)))76 F(x) = K 1/(4 pi Lb (alpha)^(2)) (q^(2)+k2)/(1+(r02)^(2)) 77 (q^(2)+k2) (q^(2)-(12 h C/b^(2))) 79 78 80 79 has 3 internal parameters : 81 The inverse Debye Length: K2 = 4 *pi*Lb*(2*Cs+alpha*C)82 r02 =1/alpha/Ca^(0.5) *(B/(48*pi*Lb)^(0.5))83 Ca = C*6.022136e-480 The inverse Debye Length: K2 = 4 pi Lb (2 Cs+alpha C) 81 r02 =1/alpha/Ca^(0.5) (B/(48 pi Lb)^(0.5)) 82 Ca = 6.022136e-4 C 84 83 """ 85 84 Ca = self.params['c'] * 6.022136e-4 -
src/sas/models/CoreMultiShellModel.py
r79492222 re0c16ce 53 53 ## parameters with orientation: can be removed since there is no orientational params 54 54 self._set_orientation_params() 55 56 55 57 56 def _clone(self, obj): 58 57 """ … … 67 66 68 67 return obj 69 70 68 71 69 def _set_dispersion(self): 72 70 """ 73 71 model dispersions 74 72 Polydispersion should not be applied to s_model 75 """ 76 ##set dispersion from model 73 """ 74 ##set dispersion from model 77 75 for name , value in self.model.dispersion.iteritems(): 78 76 nshell = 0 … … 82 80 if name.split('_')[-1] == 'shell%s' % str(nshell): 83 81 self.dispersion[name] = value 84 else: 82 else: 85 83 continue 86 84 else: 87 85 self.dispersion[name] = value 88 86 89 87 def _set_orientation_params(self): 90 88 """ 91 89 model orientation and magnetic parameters, same params for this model 92 """ 90 """ 93 91 ##set dispersion from model 94 92 for param in self.model.orientation_params: … … 104 102 self.orientation_params.append(param) 105 103 self.magnetic_params.append(param) 106 continue 104 continue 107 105 108 106 def _set_params(self): 109 107 """ 110 108 Concatenate the parameters of the model to create 111 this model parameters 109 this model parameters 112 110 """ 113 111 # rearrange the parameters for the given # of shells … … 128 126 else: 129 127 self.params[name]= value 130 128 131 129 # set constrained values for the original model params 132 self._set_xtra_model_param() 133 130 self._set_xtra_model_param() 131 134 132 def _set_details(self): 135 133 """ 136 134 Concatenate details of the original model to create 137 this model details 135 this model details 138 136 """ 139 137 for name ,detail in self.model.details.iteritems(): 140 138 if name in self.params.iterkeys(): 141 139 self.details[name]= detail 142 143 140 141 144 142 def _set_xtra_model_param(self): 145 143 """ … … 163 161 self.model.setParam(key, 0.0) 164 162 except: pass 165 163 166 164 167 165 def getProfile(self): 168 166 """ 169 Get SLD profile 170 171 : return: (r, beta) where r is a list of radius of the transition points 172 beta is a list of the corresponding SLD values173 : Note: This works only for func_shell# = 2.167 Get SLD profile 168 **Note:** This works only for func_shell num = 2. 169 170 :return: (r, beta) where r is a list of radius of the transition points\ 171 and beta is a list of the corresponding SLD values. 174 172 """ 175 173 r = [] … … 181 179 r.append(self.params['rad_core0']) 182 180 beta.append(self.params['sld_core0']) 183 181 184 182 # for shells 185 183 for n in range(1, self.n_shells+1): 186 184 # Left side of each shells 187 r0 = r[len(r)-1] 185 r0 = r[len(r)-1] 188 186 r.append(r0) 189 187 exec "beta.append(self.params['sld_shell%s'% str(n)])" … … 193 191 r.append(r0) 194 192 exec "beta.append(self.params['sld_shell%s'% str(n)])" 195 193 196 194 # for solvent 197 195 r0 = r[len(r)-1] … … 201 199 r.append(r_solv) 202 200 beta.append(self.params['sld_solv']) 203 201 204 202 return r, beta 205 203 206 204 def setParam(self, name, value): 207 """ 205 """ 208 206 Set the value of a model parameter 209 210 : 211 : 207 208 :param name: name of the parameter 209 :param value: value of the parameter 212 210 """ 213 211 # set param to new model 214 212 self._setParamHelper( name, value) 215 ## setParam to model 213 ## setParam to model 216 214 if name == 'sld_solv': 217 215 # the sld_*** model.params not in params must set to value of sld_solv … … 243 241 self.params[item] = value 244 242 return 245 246 243 #raise ValueError, "Model does not contain parameter %s" % name 247 248 244 245 249 246 def _set_fixed_params(self): 250 247 """ … … 252 249 """ 253 250 for item in self.model.fixed: 254 if item.split('.')[0] in self.params.keys(): 251 if item.split('.')[0] in self.params.keys(): 255 252 self.fixed.append(item) 256 253 257 254 self.fixed.sort() 258 255 259 256 def run(self, x = 0.0): 260 """ 257 """ 261 258 Evaluate the model 262 263 : 264 : 259 260 :param x: input q-value (float or [float, float] as [r, theta]) 261 :return: (DAB value) 265 262 """ 266 263 # set effective radius and scaling factor before run … … 269 266 270 267 def runXY(self, x = 0.0): 271 """ 268 """ 272 269 Evaluate the model 273 274 : 275 : 270 271 :param x: input q-value (float or [float, float] as [qx, qy]) 272 :return: DAB value 276 273 """ 277 274 # set effective radius and scaling factor before run 278 275 279 276 return self.model.runXY(x) 280 277 281 278 ## Now (May27,10) directly uses the model eval function 282 279 ## instead of the for-loop in Base Component. 283 280 def evalDistribution(self, x = []): 284 """ 281 """ 285 282 Evaluate the model in cartesian coordinates 286 287 : 288 : 283 284 :param x: input q[], or [qx[], qy[]] 285 :return: scattering function P(q[]) 289 286 """ 290 287 # set effective radius and scaling factor before run 291 288 return self.model.evalDistribution(x) 292 289 293 290 def calculate_ER(self): 294 """ 291 """ 295 292 Calculate the effective radius for P(q)*S(q) 296 293 297 294 :return: the value of the effective radius 298 299 """ 295 """ 300 296 return self.model.calculate_ER() 301 297 302 298 def calculate_VR(self): 303 """ 299 """ 304 300 Calculate the volf ratio for P(q)*S(q) 305 301 306 302 :return: the value of the volf ratio 307 308 """ 303 """ 309 304 return self.model.calculate_VR() 310 305 311 306 def set_dispersion(self, parameter, dispersion): 312 307 """ 313 308 Set the dispersion object for a model parameter 314 315 : 316 : dispersion: dispersion object of type DispersionModel309 310 :param parameter: name of the parameter [string] 311 :param dispersion: dispersion object of type DispersionModel 317 312 """ 318 313 value = None … … 323 318 return value 324 319 except: 325 raise 320 raise -
src/sas/models/GuinierPorodModel.py
r79492222 rac7be54 1 1 """ 2 I(q) = scale/q^s* exp ( - R_g^2 q^2 / (3-s) ) for q<= ql 3 = scale/q^m*exp((-ql^2*Rg^2)/(3-s))*ql^(m-s) for q>=ql 4 Guinier function as a BaseComponent model 2 Guinier function as a BaseComponent model 5 3 """ 6 4 from sas.models.BaseComponent import BaseComponent … … 11 9 Class that evaluates a GuinierPorod model. 12 10 13 I(q) = scale/q^s* exp ( - R_g^2 q^2 / (3-s) ) for q<= ql 14 = scale/q^m*exp((-ql^2*Rg^2)/(3-s))*ql^(m-s) for q>=ql 11 Calculate:: 12 13 I(q) = scale/q^s exp(-q^2 Rg^2 / (3-s) ) for q<= ql 14 I(q) = scale/q^m exp(-ql^2 Rg^2 / (3-s)) ql^(m-s) for q>=ql 15 15 """ 16 16 def __init__(self): -
src/sas/models/MultiplicationModel.py
r79492222 rfb3f9af 5 5 #from sas.models.pluginmodel import Model1DPlugin 6 6 class MultiplicationModel(BaseComponent): 7 """8 Use for P(Q) *S(Q); function call must be in the order of P(Q) and then S(Q):7 r""" 8 Use for P(Q)\*S(Q); function call must be in the order of P(Q) and then S(Q): 9 9 The model parameters are combined from both models, P(Q) and S(Q), except 1) 'effect_radius' of S(Q) 10 10 which will be calculated from P(Q) via calculate_ER(), 11 11 and 2) 'scale' in P model which is synchronized w/ volfraction in S 12 then P*S is multiplied by a new param , 'scale_factor'.12 then P*S is multiplied by a new parameter, 'scale_factor'. 13 13 The polydispersion is applicable only to P(Q), not to S(Q). 14 Note: P(Q) refers to 'form factor' model while S(Q) does to 'structure factor'. 14 15 .. note:: P(Q) refers to 'form factor' model while S(Q) does to 'structure factor'. 15 16 """ 16 17 def __init__(self, p_model, s_model ): … … 81 82 def _clone(self, obj): 82 83 """ 83 Internal utility function to copy the internal84 data members to afresh copy.84 Internal utility function to copy the internal data members to a 85 fresh copy. 85 86 """ 86 87 obj.params = copy.deepcopy(self.params) … … 96 97 def _set_dispersion(self): 97 98 """ 98 combined the two models dispersions99 Polydispersion should not beapplied to s_model99 combine the two models' dispersions. Polydispersity should not be 100 applied to s_model 100 101 """ 101 102 ##set dispersion only from p_model … … 107 108 Get SLD profile of p_model if exists 108 109 109 : return: (r, beta) where r is a list of radius of the transition points 110 beta is a list of the corresponding SLD values 111 : Note: This works only for func_shell# = 2 (exp function). 110 :return: (r, beta) where r is a list of radius of the transition points\ 111 beta is a list of the corresponding SLD values 112 113 .. note:: This works only for func_shell num = 2 (exp function). 112 114 """ 113 115 try: … … 121 123 def _set_params(self): 122 124 """ 123 124 thismodel parameters125 Concatenate the parameters of the two models to create 126 these model parameters 125 127 """ 126 128 … … 141 143 def _set_details(self): 142 144 """ 143 144 this modeldetails145 Concatenate details of the two models to create 146 this model's details 145 147 """ 146 148 for name, detail in self.p_model.details.iteritems(): … … 154 156 def _set_scale_factor(self): 155 157 """ 156 Set scale=volfraction toP model158 Set scale=volfraction for P model 157 159 """ 158 160 value = self.params['volfraction'] … … 168 170 def _set_effect_radius(self): 169 171 """ 170 172 Set effective radius to S(Q) model 171 173 """ 172 174 if not 'effect_radius' in self.s_model.params.keys(): … … 206 208 def _setParamHelper(self, name, value): 207 209 """ 208 210 Helper function to setparam 209 211 """ 210 212 # Look for dispersion parameters … … 229 231 def _set_fixed_params(self): 230 232 """ 231 fill the self.fixed list with the p_model fixed list233 Fill the self.fixed list with the p_model fixed list 232 234 """ 233 235 for item in self.p_model.fixed: … … 240 242 """ 241 243 Evaluate the model 244 242 245 :param x: input q-value (float or [float, float] as [r, theta]) 243 246 :return: (scattering function value) … … 250 253 251 254 def runXY(self, x = 0.0): 252 """ Evaluate the model 253 @param x: input q-value (float or [float, float] as [qx, qy]) 254 @return: scattering function value 255 """ 256 Evaluate the model 257 258 :param x: input q-value (float or [float, float] as [qx, qy]) 259 :return: scattering function value 255 260 """ 256 261 # set effective radius and scaling factor before run … … 266 271 """ 267 272 Evaluate the model in cartesian coordinates 273 268 274 :param x: input q[], or [qx[], qy[]] 269 275 :return: scattering function P(q[]) … … 279 285 """ 280 286 Set the dispersion object for a model parameter 287 281 288 :param parameter: name of the parameter [string] 282 289 :dispersion: dispersion object of type DispersionModel … … 293 300 def fill_description(self, p_model, s_model): 294 301 """ 295 302 Fill the description for P(Q)*S(Q) 296 303 """ 297 304 description = "" -
src/sas/models/PeakGaussModel.py
r79492222 rac7be54 1 1 #!/usr/bin/env python 2 2 """ 3 Model describes a Gaussian shaped peak including a flat background 4 Provide F(q) = scale*exp( -1/2 *[(q-q0)/B]^2 )+ background 5 PeakGaussModel function as a BaseComponent model 3 PeakGaussModel function as a BaseComponent model 6 4 """ 7 5 … … 12 10 13 11 """ 14 Class that evaluates a gaussian shaped peak.12 Class that evaluates a gaussian shaped peak with a flat background. 15 13 16 F(q) = scale *exp( -1/2 *[(q-qo)/B]^2 )+ background14 F(q) = scale exp( -1/2 [(q-qo)/B]^2 )+ background 17 15 18 16 The model has three parameters: … … 56 54 def _PeakGauss(self, x): 57 55 """ 58 Evaluate F(x) = scale *exp( -1/2 *[(x-q0)/B]^2 )+ background56 Evaluate F(x) = scale exp( -1/2 [(x-q0)/B]^2 )+ background 59 57 60 58 """ -
src/sas/models/TwoPowerLawModel.py
r79492222 rac7be54 1 1 #!/usr/bin/env python 2 2 """ 3 Provide I(q) = A*pow(qval,-1.0*m1) for q<=qc4 =scale*pow(qval,-1.0*m2) for q>qc5 3 TwoPowerLaw function as a BaseComponent model 4 5 Calculate:: 6 7 I(q) = A pow(qval,-m1) for q<=qc 8 I(q) = scale pow(qval,-m2) for q>qc 6 9 """ 7 10 … … 14 17 Class that evaluates a TwoPowerLawModel. 15 18 16 I(q) = coef_A*pow(qval,-1.0*power1) for q<=qc 17 =C*pow(qval,-1.0*power2) for q>qc 18 where C=coef_A*pow(qc,-1.0*power1)/pow(qc,-1.0*power2). 19 Calculate:: 20 21 I(q) = coef_A pow(qval,-power1) for q<=qc 22 I(q) = C pow(qval,-power2) for q>qc 23 24 where C=coef_A pow(qc,-power1)/pow(qc,-power2). 19 25 20 26 List of default parameters: -
src/sas/models/c_extension/c_models/GelFit.cpp
r79492222 r1d115ef 34 34 radius = Parameter(104.0,true); 35 35 radius.set_min(2.0); 36 scale= Parameter(2.0,true);36 FractalExp = Parameter(2.0,true); 37 37 background = Parameter(0.01); 38 38 } … … 43 43 dp[0] = zeta(); 44 44 dp[1] = radius(); 45 dp[2] = scale();45 dp[2] = FractalExp(); 46 46 47 47 if (dp[2] <= 0) -
src/sas/models/c_extension/c_models/lamellarPS.cpp
r79492222 r37649847 68 68 ii=0; 69 69 Sq = 0.0; 70 for(ii=1;ii< (NNint-1);ii+=1) {70 for(ii=1;ii<=(NNint-1);ii+=1) { 71 71 72 72 fii = (double)ii; //do I really need to do this? … … 144 144 for(int i=0; i< (int)weights_spacing.size(); i++) { 145 145 dp[1] = weights_spacing[i].value; 146 for(int j=0; j< (int)weights_spacing.size(); j++) { 147 dp[2] = weights_delta[i].value; 146 //for(int j=0; j< (int)weights_spacing.size(); j++) { BUGS fixed March 2015 147 for(int j=0; j< (int)weights_delta.size(); j++) { 148 //dp[2] = weights_delta[i].value; BUG 149 dp[2] = weights_delta[j].value; 148 150 149 151 sum += weights_spacing[i].weight * weights_delta[j].weight * LamellarPS_kernel(dp, q); -
src/sas/models/c_extension/c_models/pearlnecklace.cpp
r79492222 r422e7e8 16 16 double edge_separation = dp[2]; 17 17 double thick_string = dp[3]; 18 double num_pearls = dp[4];18 double num_pearls = floor(dp[4]+0.5); // Force integer number of pearls 19 19 double sld_pearl = dp[5]; 20 20 double sld_string = dp[6]; -
src/sas/models/c_extension/libigor/libCylinder.c
r79492222 r8d302cd 1379 1379 ii=0; 1380 1380 Sq = 0.0; 1381 for(ii=1;ii< (NNint-1);ii+=1) {1381 for(ii=1;ii<=(NNint-1);ii+=1) { 1382 1382 1383 1383 fii = (double)ii; //do I really need to do this? … … 1451 1451 ii=0; 1452 1452 Sq = 0.0; 1453 for(ii=1;ii< (NNint-1);ii+=1) {1453 for(ii=1;ii<=(NNint-1);ii+=1) { 1454 1454 1455 1455 fii = (double)ii; //do I really need to do this? -
src/sas/models/c_extension/python_wrapper/WrapperGenerator.py
rfd5ac0d r1f5f206 3 3 """ 4 4 5 import os, sys, re5 import os, sys, re 6 6 import lineparser 7 7 8 class WrapperGenerator :8 class WrapperGenerator(object): 9 9 """ Python wrapper generator for C models 10 11 The developer must provide a header file describing 10 11 The developer must provide a header file describing 12 12 the new model. 13 13 14 14 To provide the name of the Python class to be 15 generated, the .h file must contain the following 15 generated, the .h file must contain the following 16 16 string in the comments: 17 17 18 18 // [PYTHONCLASS] = my_model 19 19 20 20 where my_model must be replaced by the name of the 21 21 class that you want to import from sas.models. 22 22 (example: [PYTHONCLASS] = MyModel 23 23 will create a class MyModel in sas.models.MyModel. 24 It will also create a class CMyModel in 24 It will also create a class CMyModel in 25 25 sas_extension.c_models.) 26 27 Also in comments, each parameter of the params 26 27 Also in comments, each parameter of the params 28 28 dictionary must be declared with a default value 29 29 in the following way: 30 30 31 31 // [DEFAULT]=param_name=default_value 32 32 33 33 (example: 34 34 // [DEFAULT]=radius=20.0 35 35 ) 36 36 37 37 See cylinder.h for an example. 38 39 38 40 39 A .c file corresponding to the .h file should also 41 40 be provided (example: my_model.h, my_model.c). 42 41 43 42 The .h file should define two function definitions. For example, 44 43 cylinder.h defines the following: 45 44 46 45 /// 1D scattering function 47 46 double cylinder_analytical_1D(CylinderParameters *pars, double q); 48 47 49 48 /// 2D scattering function 50 49 double cylinder_analytical_2D(CylinderParameters *pars, double q, double phi); 51 50 52 51 The .c file implements those functions. 53 52 54 53 @author: Mathieu Doucet / UTK 55 54 @contact: mathieu.doucet@nist.gov 56 55 """ 57 56 58 57 def __init__(self, filename, output_dir='.', c_wrapper_dir='.'): 59 58 """ Initialization """ 60 59 61 60 ## Name of .h file to generate wrapper from 62 61 self.file = filename 63 62 64 63 # Info read from file 65 64 66 65 ## Name of python class to write 67 66 self.pythonClass = None … … 83 82 self.disp_params = [] 84 83 #model description 85 self.description =''84 self.description = '' 86 85 # paramaters for fittable 87 self.fixed = []86 self.fixed = [] 88 87 # paramaters for non-fittable 89 self.non_fittable = []88 self.non_fittable = [] 90 89 ## parameters with orientation 91 self.orientation_params = []90 self.orientation_params = [] 92 91 ## parameter with magnetism 93 92 self.magentic_params = [] … … 100 99 self.c_wrapper_dir = c_wrapper_dir 101 100 102 103 104 101 def __repr__(self): 105 102 """ Simple output for printing """ 106 107 rep 103 104 rep = "\n Python class: %s\n\n" % self.pythonClass 108 105 rep += " struc name: %s\n\n" % self.structName 109 106 rep += " params: %s\n\n" % self.params 110 107 rep += " description: %s\n\n" % self.description 111 rep += " Fittable parameters: %s\n\n" % self.fixed112 rep += " Non-Fittable parameters: %s\n\n" % self.non_fittable113 rep += " Orientation parameters: %s\n\n" % self.orientation_params114 rep += " Magnetic parameters: %s\n\n" % self.magnetic_params108 rep += " Fittable parameters: %s\n\n" % self.fixed 109 rep += " Non-Fittable parameters: %s\n\n" % self.non_fittable 110 rep += " Orientation parameters: %s\n\n" % self.orientation_params 111 rep += " Magnetic parameters: %s\n\n" % self.magnetic_params 115 112 return rep 116 113 117 114 def read(self): 118 115 """ Reads in the .h file to catch parameters of the wrapper """ 119 116 120 117 # Check if the file is there 121 118 if not os.path.isfile(self.file): 122 119 raise ValueError, "File %s is not a regular file" % self.file 123 120 124 121 # Read file 125 f = open(self.file, 'r')122 f = open(self.file, 'r') 126 123 buf = f.read() 127 124 128 125 self.default_list = "\n List of default parameters:\n\n" 129 126 #lines = string.split(buf,'\n') 130 127 lines = buf.split('\n') 131 self.details 128 self.details = "## Parameter details [units, min, max]\n" 132 129 self.details += " self.details = {}\n" 133 130 134 131 #open item in this case Fixed 135 text ='text'136 key2 ="<%s>"%text.lower()132 text = 'text' 133 key2 = "<%s>" % text.lower() 137 134 # close an item in this case fixed 138 text ='TexT'139 key3 ="</%s>"%text.lower()140 135 text = 'TexT' 136 key3 = "</%s>" % text.lower() 137 141 138 ## Catch fixed parameters 142 139 key = "[FIXED]" 143 140 try: 144 self.fixed = lineparser.readhelper(lines, key,145 key2, key3, file=self.file)141 self.fixed = lineparser.readhelper(lines, key, 142 key2, key3, file=self.file) 146 143 except: 147 raise144 raise 148 145 ## Catch non-fittable parameters parameters 149 146 key = "[NON_FITTABLE_PARAMS]" 150 147 try: 151 self.non_fittable = lineparser.readhelper(lines, key, key2,152 key3, file=self.file)148 self.non_fittable = lineparser.readhelper(lines, key, key2, 149 key3, file=self.file) 153 150 except: 154 raise151 raise 155 152 156 153 ## Catch parameters with orientation 157 key = "[ORIENTATION_PARAMS]" 154 key = "[ORIENTATION_PARAMS]" 158 155 try: 159 self.orientation_params = lineparser.readhelper(lines, key, 160 key2, key3, file=self.file)156 self.orientation_params = lineparser.readhelper(lines, key, 157 key2, key3, file=self.file) 161 158 except: 162 raise163 159 raise 160 164 161 ## Catch parameters with orientation 165 key = "[MAGNETIC_PARAMS]" 162 key = "[MAGNETIC_PARAMS]" 166 163 try: 167 self.magnetic_params = lineparser.readhelper( lines,key,168 key2,key3, file=self.file)164 self.magnetic_params = lineparser.readhelper(lines, key, 165 key2, key3, file=self.file) 169 166 except: 170 raise171 167 raise 168 172 169 ## Catch Description 173 170 key = "[DESCRIPTION]" 174 171 175 172 find_description = False 176 temp =""173 temp = "" 177 174 for line in lines: 178 if line.count(key)>0 : 179 175 if line.count(key) > 0: 180 176 try: 181 find_description = True177 find_description = True 182 178 index = line.index(key) 183 toks = line[index:].split("=", 1)184 temp =toks[1].lstrip().rstrip()185 text ='text'186 key2 ="<%s>"%text.lower()187 if re.match(key2, temp)!=None:188 189 toks2 =temp.split(key2,1)190 self.description =toks2[1]191 text ='text'192 key2 ="</%s>"%text.lower()193 if re.search(key2, toks2[1])!=None:194 temp =toks2[1].split(key2,1)195 self.description =temp[0]179 toks = line[index:].split("=", 1) 180 temp = toks[1].lstrip().rstrip() 181 text = 'text' 182 key2 = "<%s>" % text.lower() 183 if re.match(key2, temp) != None: 184 185 toks2 = temp.split(key2, 1) 186 self.description = toks2[1] 187 text = 'text' 188 key2 = "</%s>" % text.lower() 189 if re.search(key2, toks2[1]) != None: 190 temp = toks2[1].split(key2, 1) 191 self.description = temp[0] 196 192 break 197 193 198 194 else: 199 self.description =temp195 self.description = temp 200 196 break 201 197 except: 202 198 raise ValueError, "Could not parse file %s" % self.file 203 199 elif find_description: 204 text ='text'205 key2 ="</%s>"%text.lower()206 if re.search(key2, line)!=None:207 tok =line.split(key2,1)208 temp =tok[0].split("//",1)209 self.description +=tok[1].lstrip().rstrip()200 text = 'text' 201 key2 = "</%s>" % text.lower() 202 if re.search(key2, line) != None: 203 tok = line.split(key2, 1) 204 temp = tok[0].split("//", 1) 205 self.description += tok[1].lstrip().rstrip() 210 206 break 211 207 else: 212 if re.search("//", line)!=None:213 temp =line.split("//",1)214 self.description +='\n\t\t'+temp[1].lstrip().rstrip()215 208 if re.search("//", line) != None: 209 temp = line.split("//", 1) 210 self.description += '\n\t\t' + temp[1].lstrip().rstrip() 211 216 212 else: 217 self.description +='\n\t\t'+line.lstrip().rstrip()218 219 220 213 self.description += '\n\t\t' + line.lstrip().rstrip() 214 215 216 221 217 for line in lines: 222 218 223 219 # Catch class name 224 220 key = "[PYTHONCLASS]" 225 if line.count(key) >0:221 if line.count(key) > 0: 226 222 try: 227 223 index = line.index(key) 228 toks = line[index:].split("=" 224 toks = line[index:].split("=") 229 225 self.pythonClass = toks[1].lstrip().rstrip() 230 226 231 227 except: 232 228 raise ValueError, "Could not parse file %s" % self.file 233 229 234 230 key = "[CATEGORY]" 235 if line.count(key) >0:231 if line.count(key) > 0: 236 232 try: 237 233 index = line.index(key) … … 255 251 # Catch struct name 256 252 # C++ class definition 257 if line.count("class") >0:253 if line.count("class") > 0: 258 254 # We are entering a class definition 259 255 self.inParDefs = True 260 256 self.foundCPP = True 261 257 262 258 # Old-Style C struct definition 263 if line.count("typedef struct") >0:259 if line.count("typedef struct") > 0: 264 260 # We are entering a struct block 265 261 self.inParDefs = True 266 262 self.inStruct = True 267 268 if self.inParDefs and line.count("}") >0:263 264 if self.inParDefs and line.count("}") > 0: 269 265 # We are exiting a struct block 270 266 self.inParDefs = False 271 267 272 268 if self.inStruct: 273 269 self.inStruct = False 274 270 # Catch the name of the struct 275 271 index = line.index("}") 276 toks = line[index +1:].split(";")272 toks = line[index + 1:].split(";") 277 273 # Catch pointer definition 278 274 toks2 = toks[0].split(',') 279 275 self.structName = toks2[0].lstrip().rstrip() 280 276 281 277 # Catch struct content 282 278 key = "[DEFAULT]" 283 if self.inParDefs and line.count(key) >0:279 if self.inParDefs and line.count(key) > 0: 284 280 # Found a new parameter 285 281 try: … … 295 291 self.default_list += " * %-15s = %s %s\n" % \ 296 292 (toks[1], val, units) 297 293 298 294 # Check for min and max 299 min = "None"300 max = "None"295 value_min = "None" 296 value_max = "None" 301 297 if len(toks2) == 4: 302 min = toks2[2]303 max = toks2[3]304 298 value_min = toks2[2] 299 value_max = toks2[3] 300 305 301 self.details += " self.details['%s'] = ['%s', %s, %s]\n" % \ 306 (toks[1].lstrip().rstrip(), units.lstrip().rstrip(), min,max)302 (toks[1].lstrip().rstrip(), units.lstrip().rstrip(), value_min, value_max) 307 303 except: 308 304 raise ValueError, "Could not parse input file %s \n %s" % \ 309 305 (self.file, sys.exc_value) 310 311 306 307 312 308 # Catch need for numerical calculations 313 309 key = "CalcParameters calcPars" 314 if line.count(key) >0:310 if line.count(key) > 0: 315 311 self.modelCalcFlag = True 316 312 317 313 # Catch list of dispersed parameters 318 314 key = "[DISP_PARAMS]" 319 if line.count(key) >0:315 if line.count(key) > 0: 320 316 try: 321 317 index = line.index(key) … … 330 326 The file is written in C[PYTHONCLASS].c 331 327 """ 332 file_path = os.path.join(self.c_wrapper_dir, 333 "C" +self.pythonClass+'.cpp')328 file_path = os.path.join(self.c_wrapper_dir, 329 "C" + self.pythonClass + '.cpp') 334 330 file = open(file_path, 'w') 335 336 template = open(os.path.join(os.path.dirname(__file__), 331 332 template = open(os.path.join(os.path.dirname(__file__), 337 333 "classTemplate.txt"), 'r') 338 334 339 335 tmp_buf = template.read() 340 336 #tmp_lines = string.split(tmp_buf,'\n') 341 337 tmp_lines = tmp_buf.split('\n') 342 338 343 339 for tmp_line in tmp_lines: 344 340 345 341 # Catch class name 346 newline = self.replaceToken(tmp_line, 347 "[PYTHONCLASS]", 'C' +self.pythonClass)342 newline = self.replaceToken(tmp_line, 343 "[PYTHONCLASS]", 'C' + self.pythonClass) 348 344 #Catch model description 349 345 #newline = self.replaceToken(tmp_line, 350 346 # "[DESCRIPTION]", self.description) 351 347 # Catch C model name 352 newline = self.replaceToken(newline, 348 newline = self.replaceToken(newline, 353 349 "[CMODEL]", self.pythonClass) 354 350 355 351 # Catch class name 356 newline = self.replaceToken(newline, 352 newline = self.replaceToken(newline, 357 353 "[MODELSTRUCT]", self.structName) 358 354 359 355 # Sort model initialization based on multifunc 360 if (self.is_multifunc):356 if self.is_multifunc: 361 357 line = "int level = 1;\nPyArg_ParseTuple(args,\"i\",&level);\n" 362 358 line += "self->model = new " + self.pythonClass + "(level);" 363 359 else: 364 360 line = "self->model = new " + self.pythonClass + "();" 365 366 newline = self.replaceToken(newline,"[INITIALIZE_MODEL]", 367 line) 368 361 362 newline = self.replaceToken(newline, "[INITIALIZE_MODEL]", line) 363 369 364 # Dictionary initialization 370 param_str = "// Initialize parameter dictionary\n" 365 param_str = "// Initialize parameter dictionary\n" 371 366 for par in self.params: 372 367 param_str += " PyDict_SetItemString(self->params,\"%s\",Py_BuildValue(\"d\",%10.12f));\n" % \ 373 368 (par, self.params[par]) 374 369 375 if len(self.disp_params) >0:370 if len(self.disp_params) > 0: 376 371 param_str += " // Initialize dispersion / averaging parameter dict\n" 377 372 param_str += " DispersionVisitor* visitor = new DispersionVisitor();\n" … … 384 379 param_str += " self->model->%s.dispersion->accept_as_source(visitor, self->model->%s.dispersion, disp_dict);\n" % (par, par) 385 380 param_str += " PyDict_SetItemString(self->dispersion, \"%s\", disp_dict);\n" % par 386 381 387 382 # Initialize dispersion object dictionnary 388 383 param_str += "\n" 389 390 384 385 391 386 newline = self.replaceToken(newline, 392 387 "[INITDICTIONARY]", param_str) 393 388 394 389 # Read dictionary 395 390 param_str = " // Reader parameter dictionary\n" … … 397 392 param_str += " self->model->%s = PyFloat_AsDouble( PyDict_GetItemString(self->params, \"%s\") );\n" % \ 398 393 (par, par) 399 400 if len(self.disp_params) >0:394 395 if len(self.disp_params) > 0: 401 396 param_str += " // Read in dispersion parameters\n" 402 397 param_str += " PyObject* disp_dict;\n" … … 408 403 param_str += " disp_dict = PyDict_GetItemString(self->dispersion, \"%s\");\n" % par 409 404 param_str += " self->model->%s.dispersion->accept_as_destination(visitor, self->model->%s.dispersion, disp_dict);\n" % (par, par) 410 405 411 406 newline = self.replaceToken(newline, "[READDICTIONARY]", param_str) 412 407 413 408 # Name of .c file 414 409 #toks = string.split(self.file,'.') … … 416 411 toks = basename.split('.') 417 412 newline = self.replaceToken(newline, "[C_FILENAME]", toks[0]) 418 413 419 414 # Include file 420 415 basename = os.path.basename(self.file) 421 newline = self.replaceToken(newline, 422 "[INCLUDE_FILE]", self.file) 416 newline = self.replaceToken(newline, 417 "[INCLUDE_FILE]", self.file) 423 418 if self.foundCPP: 424 newline = self.replaceToken(newline, 425 "[C_INCLUDE_FILE]", "") 426 newline = self.replaceToken(newline, 427 "[CPP_INCLUDE_FILE]", "#include \"%s\"" % basename) 428 else: 429 newline = self.replaceToken(newline, 430 "[C_INCLUDE_FILE]", "#include \"%s\"" % basename) 431 newline = self.replaceToken(newline, 432 "[CPP_INCLUDE_FILE]", "#include \"models.hh\"") 433 419 newline = self.replaceToken(newline, "[C_INCLUDE_FILE]", "") 420 newline = self.replaceToken(newline, 421 "[CPP_INCLUDE_FILE]", 422 "#include \"%s\"" % basename) 423 else: 424 newline = self.replaceToken(newline, 425 "[C_INCLUDE_FILE]", 426 "#include \"%s\"" % basename) 427 newline = self.replaceToken(newline, 428 "[CPP_INCLUDE_FILE]", 429 "#include \"models.hh\"") 430 434 431 # Numerical calcs dealloc 435 432 dealloc_str = "\n" 436 433 if self.modelCalcFlag: 437 434 dealloc_str = " modelcalculations_dealloc(&(self->model_pars.calcPars));\n" 438 newline = self.replaceToken(newline, 439 "[NUMERICAL_DEALLOC]", dealloc_str) 440 435 newline = self.replaceToken(newline, 436 "[NUMERICAL_DEALLOC]", dealloc_str) 437 441 438 # Numerical calcs init 442 439 init_str = "\n" 443 440 if self.modelCalcFlag: 444 441 init_str = " modelcalculations_init(&(self->model_pars.calcPars));\n" 445 newline = self.replaceToken(newline, 446 "[NUMERICAL_INIT]", init_str) 447 442 newline = self.replaceToken(newline, 443 "[NUMERICAL_INIT]", init_str) 444 448 445 # Numerical calcs reset 449 446 reset_str = "\n" 450 447 if self.modelCalcFlag: 451 448 reset_str = "modelcalculations_reset(&(self->model_pars.calcPars));\n" 452 newline = self.replaceToken(newline, 453 "[NUMERICAL_RESET]", reset_str) 454 449 newline = self.replaceToken(newline, 450 "[NUMERICAL_RESET]", reset_str) 451 455 452 # Setting dispsertion weights 456 453 set_weights = " // Ugliness necessary to go from python to C\n" … … 463 460 set_weights += " self->model->%s.dispersion = dispersion;\n" % par 464 461 set_weights += " } else" 465 newline = self.replaceToken(newline, 466 "[SET_DISPERSION]", set_weights) 467 462 newline = self.replaceToken(newline, 463 "[SET_DISPERSION]", set_weights) 464 468 465 # Write new line to the wrapper .c file 469 file.write(newline +'\n')470 471 466 file.write(newline + '\n') 467 468 472 469 file.close() 473 470 474 471 def write_python_wrapper(self): 475 472 """ Writes the python file to create the python extension class 476 473 The file is written in ../[PYTHONCLASS].py 477 474 """ 478 file_path = os.path.join(self.output_dir, self.pythonClass +'.py')475 file_path = os.path.join(self.output_dir, self.pythonClass + '.py') 479 476 file = open(file_path, 'w') 480 template = open(os.path.join(os.path.dirname(__file__), 477 template = open(os.path.join(os.path.dirname(__file__), 481 478 "modelTemplate.txt"), 'r') 482 479 483 480 tmp_buf = template.read() 484 481 tmp_lines = tmp_buf.split('\n') 485 482 486 483 for tmp_line in tmp_lines: 487 484 488 485 # Catch class name 489 newline = self.replaceToken(tmp_line, 490 "[CPYTHONCLASS]", 486 newline = self.replaceToken(tmp_line, 487 "[CPYTHONCLASS]", 491 488 'C' + self.pythonClass) 492 489 493 490 # Catch class name 494 newline = self.replaceToken(newline, 491 newline = self.replaceToken(newline, 495 492 "[PYTHONCLASS]", self.pythonClass) 496 493 497 494 # Include file 498 newline = self.replaceToken(newline, 499 "[INCLUDE_FILE]", self.file) 500 495 newline = self.replaceToken(newline, 496 "[INCLUDE_FILE]", self.file) 497 501 498 # Include file 502 newline = self.replaceToken(newline, 499 newline = self.replaceToken(newline, 503 500 "[DEFAULT_LIST]", self.default_list) 504 501 # model description 505 newline = self.replaceToken(newline, 502 newline = self.replaceToken(newline, 506 503 "[DESCRIPTION]", self.description) 507 504 # Parameter details 508 newline = self.replaceToken(newline, 505 newline = self.replaceToken(newline, 509 506 "[PAR_DETAILS]", self.details) 510 507 511 508 # Call base constructor 512 509 if self.is_multifunc: 513 newline = self.replaceToken(newline, "[CALL_CPYTHON_INIT]",514 'C' + self.pythonClass + \510 newline = self.replaceToken(newline, "[CALL_CPYTHON_INIT]", 511 'C' + self.pythonClass + \ 515 512 ".__init__(self,multfactor)\n\tself.is_multifunc = True") 516 newline = self.replaceToken(newline, "[MULTIPLICITY_INFO]",513 newline = self.replaceToken(newline, "[MULTIPLICITY_INFO]", 517 514 self.multiplicity_info) 518 515 else: 519 newline = self.replaceToken(newline, "[CALL_CPYTHON_INIT]",520 'C' + self.pythonClass + \516 newline = self.replaceToken(newline, "[CALL_CPYTHON_INIT]", 517 'C' + self.pythonClass + \ 521 518 ".__init__(self)\n self.is_multifunc = False") 522 newline = self.replaceToken(newline, 519 newline = self.replaceToken(newline, 523 520 "[MULTIPLICITY_INFO]", "None") 524 521 525 526 522 # fixed list details 527 523 fixed_str = str(self.fixed) 528 524 fixed_str = fixed_str.replace(', ', ',\n ') 529 525 newline = self.replaceToken(newline, "[FIXED]", fixed_str) 530 526 531 527 # non-fittable list details 532 528 pars_str = str(self.non_fittable) 533 pars_str = pars_str.replace(', ', 529 pars_str = pars_str.replace(', ', 534 530 ',\n ') 535 newline = self.replaceToken(newline, 531 newline = self.replaceToken(newline, 536 532 "[NON_FITTABLE_PARAMS]", pars_str) 537 533 538 534 ## parameters with orientation 539 535 oriented_str = str(self.orientation_params) 540 536 formatted_endl = ',\n ' 541 537 oriented_str = oriented_str.replace(', ', formatted_endl) 542 newline = self.replaceToken(newline, 543 "[ORIENTATION_PARAMS]", oriented_str) 544 ## parameters with magnetism 545 newline = self.replaceToken(newline, 546 "[MAGNETIC_PARAMS]", str(self.magnetic_params)) 538 newline = self.replaceToken(newline, 539 "[ORIENTATION_PARAMS]", oriented_str) 540 ## parameters with magnetism 541 newline = self.replaceToken(newline, 542 "[MAGNETIC_PARAMS]", 543 str(self.magnetic_params)) 547 544 548 545 if self.category: 549 newline = self.replaceToken(newline, "[CATEGORY]", 546 newline = self.replaceToken(newline, "[CATEGORY]", 550 547 '"' + self.category + '"') 551 548 else: 552 549 newline = self.replaceToken(newline, "[CATEGORY]", 553 550 "None") 554 551 555 552 556 553 557 554 # Write new line to the wrapper .c file 558 file.write(newline +'\n')559 555 file.write(newline + '\n') 556 560 557 file.close() 561 562 558 559 563 560 def replaceToken(self, line, key, value): #pylint: disable-msg=R0201 564 561 """ Replace a token in the template file 565 @param line: line of text to inspect566 @param key: token to look for567 @param value: string value to replace the token with568 @return: new string value562 :param line: line of text to inspect 563 :param key: token to look for 564 :param value: string value to replace the token with 565 :return: new string value 569 566 """ 567 _str_value = str(value) 568 _new_value = _str_value.replace('\\','/') 570 569 lenkey = len(key) 571 570 newline = line 572 573 while newline.count(key) >0:571 572 while newline.count(key) > 0: 574 573 index = newline.index(key) 575 newline = newline[:index] +value+newline[index+lenkey:]576 574 newline = newline[:index] + _new_value + newline[index + lenkey:] 575 577 576 return newline 578 577 579 578 def getModelName(self): 580 579 return self.pythonClass 581 580 582 581 583 582 584 583 # main 585 584 if __name__ == '__main__': 586 if len(sys.argv) >1:585 if len(sys.argv) > 1: 587 586 print "Will look for file %s" % sys.argv[1] 588 587 app = WrapperGenerator(sys.argv[1]) … … 593 592 app.write_python_wrapper() 594 593 print app 595 594 596 595 # End of file -
src/sas/models/c_extension/python_wrapper/modelTemplate.txt
r8836849 r1f5f206 13 13 ############################################################################## 14 14 15 """ 15 """ 16 16 Provide functionality for a C extension model 17 17 18 18 .. WARNING:: 19 20 19 THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY 21 20 DO NOT MODIFY THIS FILE, MODIFY … … 30 29 def create_[PYTHONCLASS](): 31 30 """ 32 31 Create a model instance 33 32 """ 34 33 obj = [PYTHONCLASS]() … … 38 37 39 38 class [PYTHONCLASS]([CPYTHONCLASS], BaseComponent): 40 """ 41 Class that evaluates a [PYTHONCLASS] model. 39 """ 40 Class that evaluates a [PYTHONCLASS] model. 42 41 This file was auto-generated from [INCLUDE_FILE]. 43 42 Refer to that file and the structure it contains … … 45 44 [DEFAULT_LIST] 46 45 """ 47 46 48 47 def __init__(self, multfactor=1): 49 48 """ Initialization """ 50 49 self.__dict__ = {} 51 50 52 51 # Initialize BaseComponent first, then sphere 53 52 BaseComponent.__init__(self) … … 55 54 56 55 [CALL_CPYTHON_INIT] 57 56 58 57 ## Name of the model 59 58 self.name = "[PYTHONCLASS]" … … 62 61 [DESCRIPTION] 63 62 """ 64 63 65 64 [PAR_DETAILS] 66 65 ## fittable parameters 67 66 self.fixed = [FIXED] 68 67 69 68 ## non-fittable parameters 70 69 self.non_fittable = [NON_FITTABLE_PARAMS] 71 70 72 71 ## parameters with orientation 73 72 self.orientation_params = [ORIENTATION_PARAMS] … … 78 77 self.category = [CATEGORY] 79 78 self.multiplicity_info = [MULTIPLICITY_INFO] 80 79 81 80 def __setstate__(self, state): 82 81 """ … … 84 83 """ 85 84 self.__dict__, self.params, self.dispersion = state 86 85 87 86 def __reduce_ex__(self, proto): 88 87 """ 89 Overwrite the __reduce_ex__ of PyTypeObject *type call in the init of 88 Overwrite the __reduce_ex__ of PyTypeObject *type call in the init of 90 89 c model. 91 90 """ 92 91 state = (self.__dict__, self.params, self.dispersion) 93 92 return (create_[PYTHONCLASS], tuple(), state, None, None) 94 93 95 94 def clone(self): 96 95 """ Return a identical copy of self """ 97 return self._clone([PYTHONCLASS]()) 98 96 return self._clone([PYTHONCLASS]()) 97 99 98 def run(self, x=0.0): 100 """ 99 """ 101 100 Evaluate the model 102 101 103 102 :param x: input q, or [q,phi] 104 105 103 :return: scattering function P(q) 106 107 104 """ 108 105 return [CPYTHONCLASS].run(self, x) 109 106 110 107 def runXY(self, x=0.0): 111 """ 108 """ 112 109 Evaluate the model in cartesian coordinates 113 110 114 111 :param x: input q, or [qx, qy] 115 116 112 :return: scattering function P(q) 117 118 113 """ 119 114 return [CPYTHONCLASS].runXY(self, x) 120 115 121 116 def evalDistribution(self, x): 122 """ 117 """ 123 118 Evaluate the model in cartesian coordinates 124 119 125 120 :param x: input q[], or [qx[], qy[]] 126 127 121 :return: scattering function P(q[]) 128 129 122 """ 130 123 return [CPYTHONCLASS].evalDistribution(self, x) 131 124 132 125 def calculate_ER(self): 133 """ 126 """ 134 127 Calculate the effective radius for P(q)*S(q) 135 128 136 129 :return: the value of the effective radius 137 138 """ 130 """ 139 131 return [CPYTHONCLASS].calculate_ER(self) 140 132 141 133 def calculate_VR(self): 142 """ 134 """ 143 135 Calculate the volf ratio for P(q)*S(q) 144 136 145 137 :return: the value of the volf ratio 146 147 """ 138 """ 148 139 return [CPYTHONCLASS].calculate_VR(self) 149 140 150 141 def set_dispersion(self, parameter, dispersion): 151 142 """ 152 143 Set the dispersion object for a model parameter 153 144 154 145 :param parameter: name of the parameter [string] 155 146 :param dispersion: dispersion object of type DispersionModel 156 157 147 """ 158 148 return [CPYTHONCLASS].set_dispersion(self, 159 149 parameter, dispersion.cdisp) 160 161 150 162 151 # End of file -
src/sas/models/include/GelFit.h
r79492222 r1d115ef 33 33 Parameter radius; 34 34 35 // [DEFAULT]= scale= 236 Parameter scale;35 // [DEFAULT]=FractalExp= 2 36 Parameter FractalExp; 37 37 38 38 // [DEFAULT]=background= 0.01 -
src/sas/models/include/dabmodel.h
r79492222 rf008ee2 17 17 // [PYTHONCLASS] = DABModel 18 18 // [DISP_PARAMS] = length, scale, background 19 // [DESCRIPTION] = <text>Provide F(x) = scale/( 1 + (x*L)^2 )^(2) + background 20 // DAB (Debye Anderson Brumberger) function as a BaseComponent model 19 // [DESCRIPTION] = <text>DAB (Debye Anderson Brumberger) Model 20 // F(x) = scale * L^3/( 1 + (q*L)^2 )^2 + background 21 // L: the correlation length 21 22 // </text> 22 23 // [FIXED] = -
src/sas/models/media/model_functions.rst
rcd06a5f ra342928 10 10 11 11 .. To do: 12 .. Remove the 'This is xi' & 'This is zeta' lines before release!13 12 .. Add example parameters/plots for the CoreShellEllipsoidXTModel 14 13 .. Add example parameters/plots for the RectangularPrism models … … 20 19 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 21 20 21 22 .. note:: The contents of this document are presented in good faith and are 23 believed to be mostly correct and accurate, however they have not 24 yet been rigorously checked for errors. June2015 22 25 23 26 … … 77 80 .. Actual document starts here... 78 81 82 .. _SasView_model_functions: 83 79 84 SasView Model Functions 80 85 ======================= 81 82 Contents83 --------84 1. Background_85 86 2. Model_ Functions87 88 2.1 Shape-based_ Functions89 90 2.2 Shape-independent_ Functions91 92 2.3 Structure-factor_ Functions93 94 2.4 Customised_ Functions95 96 3. References_97 98 99 100 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ101 102 103 86 104 87 .. _Background: … … 169 152 - RaspBerryModel_ 170 153 - CoreShellModel_ (including magnetic 2D version) 154 - MicelleSphCoreModel_ 171 155 - CoreMultiShellModel_ (including magnetic 2D version) 172 156 - Core2ndMomentModel_ … … 286 270 - sph_bessel_jn_ 287 271 272 Also see the documentation on :ref:`Adding_your_own_models` under Fitting Data. 273 288 274 289 275 … … 2253 2239 2254 2240 *equat_core* = equatorial core radius = *Rminor_core* 2241 2255 2242 *X_core* = *polar_core* / *equat_core* = *Rmajor_core* / *Rminor_core* 2243 2256 2244 *T_shell* = *equat_outer* - *equat_core* = *Rminor_outer* - *Rminor_core* 2245 2257 2246 *XpolarShell* = *Tpolar_shell* / *T_shell* = (*Rmajor_outer* - *Rmajor_core*)/(*Rminor_outer* - *Rminor_core*) 2258 2247 … … 2260 2249 2261 2250 *polar_core* = *equat_core* \* *X_core* 2251 2262 2252 *equat_shell* = *equat_core* + *T_shell* 2253 2263 2254 *polar_shell* = *equat_core* \* *X_core* + *T_shell* \* *XpolarShell* 2264 2255 … … 2444 2435 2445 2436 where |delta|\ T = tail length (or *t_length*), |delta|\ H = head thickness (or *h_thickness*), 2446 |drho|\ H = SLD(headgroup) - SLD(solvent), and |drho|\ T = SLD(tail) - SLD(solvent). 2437 |drho|\ H = SLD(headgroup) - SLD(solvent), and |drho|\ T = SLD(tail) - SLD(solvent). The total thickness is 2(H+T). 2447 2438 2448 2439 The 2D scattering intensity is calculated in the same way as 1D, where the *q* vector is defined as … … 3372 3363 3373 3364 3365 .. _MicelleSphCoreModel: 3366 3367 **2.1.42. MicelleSphCoreModel** 3368 3369 This model provides the form factor, *P(q)*, for a micelle with a spherical core 3370 and Gaussian polymer chains attached to the surface. 3371 3372 *2.1.42.1. Definition* 3373 3374 The 1D scattering intensity for this model is calculated according to the equations given by Pedersen 3375 (Pedersen, 2000). 3376 3377 *2.1.42.2. Validation of the MicelleSphCoreModel* 3378 3379 This model has not yet been validated. Feb2015 3380 3381 REFERENCES 3382 3383 J Pedersen, *J. Appl. Cryst.*, 33 (2000) 637-640 3384 3385 3386 3374 3387 2.2 Shape-independent Functions 3375 3388 ------------------------------- … … 3554 3567 *2.2.5.1. Definition* 3555 3568 3556 .. image:: img/image180 .PNG3569 .. image:: img/image180_corrected.PNG 3557 3570 3558 3571 The parameter *L* is the correlation length. … … 4070 4083 This model fits the Porod function 4071 4084 4072 .. image:: img/image197 .PNG4085 .. image:: img/image197_corrected.PNG 4073 4086 4074 4087 to the data directly without any need for linearisation (*cf*. Log *I(q)* vs Log *q*). … … 4776 4789 **2.3.3. HayterMSAStructure Factor** 4777 4790 4778 This calculates the structure factor (the Fourier transform of the pair correlation function *g(r)*) for a system of4779 charged, spheroidal objects in a dielectric medium. When combined with an appropriate form factor (such as sphere, 4780 core+shell, ellipsoid, etc), this allows for inclusion of the interparticle interference effects due to screened coulomb 4781 repulsion between charged particles.4791 This is an implementation of the Rescaled Mean Spherical Approximation which calculates the structure factor (the 4792 Fourier transform of the pair correlation function *g(r)*) for a system of charged, spheroidal objects in a 4793 dielectric medium. When combined with an appropriate form factor (such as sphere,core+shell, ellipsoid, etc), this 4794 allows for inclusion of the interparticle interference effects due to screened coulomb repulsion between charged particles. 4782 4795 4783 4796 **This routine only works for charged particles**. If the charge is set to zero the routine will self-destruct! -
src/sas/models/qsmearing.py
rfd5ac0d ra3f125f0 59 59 if _found_resolution == True: 60 60 return QSmearer(data1D, model) 61 #return pinhole_smear(data1D, model) 61 62 62 63 # Look for slit smearing data … … 81 82 # If we found slit smearing data, return a slit smearer 82 83 if _found_slit == True: 83 return SlitSmearer(data1D, model) 84 #return SlitSmearer(data1D, model) 85 return slit_smear(data1D, model) 84 86 return None 85 87 … … 198 200 iq_in[len(iq_in) - 1] = iq_in_high[0] 199 201 # Append the extrapolated points to the data points 200 if self.nbins_low > 0: 202 if self.nbins_low > 0: 201 203 iq_in_temp = numpy.append(iq_in_low, iq_in) 202 204 if self.nbins_high > 0: … … 583 585 return nbins_low, nbins_high, \ 584 586 new_width[data_x_ext > 0], data_x_ext[data_x_ext > 0] 587 588 589 590 from .resolution import Slit1D, Pinhole1D 591 class PySmear(object): 592 """ 593 Wrapper for pure python sasmodels resolution functions. 594 """ 595 def __init__(self, resolution, model): 596 self.model = model 597 self.resolution = resolution 598 self.offset = numpy.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 599 600 def apply(self, iq_in, first_bin=0, last_bin=None): 601 """ 602 Apply the resolution function to the data. 603 604 Note that this is called with iq_in matching data.x, but with 605 iq_in[first_bin:last_bin] set to theory values for these bins, 606 and the remainder left undefined. The first_bin, last_bin values 607 should be those returned from get_bin_range. 608 609 The returned value is of the same length as iq_in, with the range 610 first_bin:last_bin set to the resolution smeared values. 611 """ 612 if last_bin is None: last_bin = len(iq_in) 613 start, end = first_bin + self.offset, last_bin + self.offset 614 q_calc = self.resolution.q_calc 615 iq_calc = numpy.empty_like(q_calc) 616 if start > 0: 617 iq_calc[:start] = self.model.evalDistribution(q_calc[:start]) 618 if end+1 < len(q_calc): 619 iq_calc[end+1:] = self.model.evalDistribution(q_calc[end+1:]) 620 iq_calc[start:end+1] = iq_in[first_bin:last_bin+1] 621 smeared = self.resolution.apply(iq_calc) 622 return smeared 623 __call__ = apply 624 625 def get_bin_range(self, q_min=None, q_max=None): 626 """ 627 For a given q_min, q_max, find the corresponding indices in the data. 628 629 Returns first, last. 630 631 Note that these are indexes into q from the data, not the q_calc 632 needed by the resolution function. Note also that these are the 633 indices, not the range limits. That is, the complete range will be 634 q[first:last+1]. 635 """ 636 q = self.resolution.q 637 first = numpy.searchsorted(q, q_min) 638 last = numpy.searchsorted(q, q_max) 639 return first, min(last,len(q)-1) 640 641 def slit_smear(data, model=None): 642 q = data.x 643 width = data.dxw if data.dxw is not None else 0 644 height = data.dxl if data.dxl is not None else 0 645 # TODO: width and height seem to be reversed 646 return PySmear(Slit1D(q, height, width), model) 647 648 def pinhole_smear(data, model=None): 649 q = data.x 650 width = data.dx if data.dx is not None else 0 651 return PySmear(Pinhole1D(q, width), model) -
src/sas/models/sas_extension/__init__.py
r79492222 rfb3f9af 1 """ 2 This is an empty package - should probably delete 3 """ -
src/sas/models/dispersion_models.py
rfd5ac0d r0e4e554 154 154 c_models.set_dispersion_weights(self.cdisp, values, weights) 155 155 156 models = {"gaussian":GaussianDispersion, "rectangula ":RectangleDispersion,156 models = {"gaussian":GaussianDispersion, "rectangular":RectangleDispersion, 157 157 "array":ArrayDispersion, "schulz":SchulzDispersion, 158 158 "lognormal":LogNormalDispersion}
Note: See TracChangeset
for help on using the changeset viewer.