1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma IgorVersion=6.0 |
---|
3 | |
---|
4 | //////////////////////////////////////////////////// |
---|
5 | // Raspberry model - Pozzo & Larson |
---|
6 | // Default parameters are for a 5000A hexadecane drop stabilized by 100A silica particles |
---|
7 | // in D2O. The particles are 50% inserted into the interface (delta = 0) and surface coverage is 50% |
---|
8 | //////////////////////////////////////////////////// |
---|
9 | |
---|
10 | //this macro sets up all the necessary parameters and waves that are |
---|
11 | //needed to calculate the model function. |
---|
12 | // |
---|
13 | Macro PlotRaspberry(num,qmin,qmax) |
---|
14 | Variable num=500, qmin=1e-5, qmax=0.7 |
---|
15 | Prompt num "Enter number of data points for model: " |
---|
16 | Prompt qmin "Enter minimum q-value (^-1) for model: " |
---|
17 | Prompt qmax "Enter maximum q-value (^-1) for model: " |
---|
18 | // |
---|
19 | Make/O/D/n=(num) xwave_Raspberry, ywave_Raspberry |
---|
20 | xwave_Raspberry = alog(log(qmin) + x*((log(qmax)-log(qmin))/num)) |
---|
21 | Make/O/D coef_Raspberry = {0.05,5000,-4e-7,0.005,100,0.4,3.5e-6,0,6.3e-6,0.0} |
---|
22 | make/o/t parameters_Raspberry = {"vf Large","Radius Large (A)","SLD Large sphere (A-2)","vf Small", "Radius Small (A)","surface coverage","SLD Small sphere (A-2)","delta","SLD solvent (A-2)","bkgd (cm-1)"} |
---|
23 | Edit parameters_Raspberry, coef_Raspberry |
---|
24 | |
---|
25 | Variable/G root:g_Raspberry |
---|
26 | g_Raspberry := Raspberry(coef_Raspberry, ywave_Raspberry, xwave_Raspberry) |
---|
27 | Display ywave_Raspberry vs xwave_Raspberry |
---|
28 | ModifyGraph marker=29, msize=2, mode=4 |
---|
29 | ModifyGraph log=1,grid=1,mirror=2 |
---|
30 | Label bottom "q (\\S-1\\M) " |
---|
31 | Label left "I(q) (cm\\S-1\\M)" |
---|
32 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
33 | |
---|
34 | AddModelToStrings("Raspberry","coef_Raspberry","parameters_Raspberry","Raspberry") |
---|
35 | // |
---|
36 | End |
---|
37 | |
---|
38 | |
---|
39 | // |
---|
40 | //this macro sets up all the necessary parameters and waves that are |
---|
41 | //needed to calculate the smeared model function. |
---|
42 | // |
---|
43 | //no input parameters are necessary, it MUST use the experimental q-values |
---|
44 | // from the experimental data read in from an AVE/QSIG data file |
---|
45 | //////////////////////////////////////////////////// |
---|
46 | // - sets up a dependency to a wrapper, not the actual SmearedModelFunction |
---|
47 | Macro PlotSmearedRaspberry(str) |
---|
48 | String str |
---|
49 | Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4) |
---|
50 | |
---|
51 | // if any of the resolution waves are missing => abort |
---|
52 | if(ResolutionWavesMissingDF(str)) //updated to NOT use global strings (in GaussUtils) |
---|
53 | Abort |
---|
54 | endif |
---|
55 | |
---|
56 | SetDataFolder $("root:"+str) |
---|
57 | |
---|
58 | // Setup parameter table for model function |
---|
59 | Make/O/D smear_coef_Raspberry = {0.05,5000,-4e-7,0.005,100,0.4,3.5e-6,0,6.3e-6,0.0} |
---|
60 | make/o/t smear_parameters_Raspberry = {"vf Large","Radius Large (A)","SLD Large sphere (A-2)","vf Small", "Radius Small (A)","surface coverage","SLD Small sphere (A-2)","delta","SLD solvent (A-2)","bkgd (cm-1)"} |
---|
61 | Edit smear_parameters_Raspberry,smear_coef_Raspberry //display parameters in a table |
---|
62 | |
---|
63 | // output smeared intensity wave, dimensions are identical to experimental QSIG values |
---|
64 | // make extra copy of experimental q-values for easy plotting |
---|
65 | Duplicate/O $(str+"_q") smeared_Raspberry,smeared_qvals |
---|
66 | SetScale d,0,0,"1/cm",smeared_Raspberry |
---|
67 | |
---|
68 | Variable/G gs_Raspberry=0 |
---|
69 | gs_Raspberry := fSmearedRaspberry(smear_coef_Raspberry,smeared_Raspberry,smeared_qvals) //this wrapper fills the STRUCT |
---|
70 | |
---|
71 | Display smeared_Raspberry vs smeared_qvals |
---|
72 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
73 | Label bottom "q (\\S-1\\M)" |
---|
74 | Label left "I(q) (cm\\S-1\\M)" |
---|
75 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
76 | |
---|
77 | SetDataFolder root: |
---|
78 | AddModelToStrings("SmearedRaspberry","smear_coef_Raspberry","smear_parameters_Raspberry","Raspberry") |
---|
79 | End |
---|
80 | |
---|
81 | |
---|
82 | Macro CalcRaspberryStats() |
---|
83 | |
---|
84 | Variable vfL,rL,sldL,vfS,rS,sldS,deltaS,delrhoL,delrhoS,bkg,sldSolv,qval ,aSs |
---|
85 | vfL = coef_Raspberry[0] |
---|
86 | rL = coef_Raspberry[1] |
---|
87 | sldL = coef_Raspberry[2] |
---|
88 | vfS = coef_Raspberry[3] |
---|
89 | rS = coef_Raspberry[4] |
---|
90 | aSs = coef_Raspberry[5] |
---|
91 | sldS = coef_Raspberry[6] |
---|
92 | deltaS = coef_Raspberry[7] |
---|
93 | sldSolv = coef_Raspberry[8] |
---|
94 | bkg = coef_Raspberry[9] |
---|
95 | |
---|
96 | Variable fractionsmall,Np,VL,VS |
---|
97 | |
---|
98 | VL = 4*pi/3*rL^3 |
---|
99 | VS = 4*pi/3*rS^3 |
---|
100 | |
---|
101 | //Np = aSs*0.04*(rS/(rL+deltaS))*(VL/VS) |
---|
102 | Np = aSs*4*((rL+deltaS)/rS)^2 |
---|
103 | fractionsmall = Np*vfL*VS/vfS/VL |
---|
104 | |
---|
105 | print "Fraction small on large = "+num2str(fractionsmall)+"\r" |
---|
106 | print "Number of small particles on large = "+num2str(Np)+"\r" |
---|
107 | |
---|
108 | End |
---|
109 | |
---|
110 | Macro PlotRaspberrySq() |
---|
111 | |
---|
112 | setdatafolder root: |
---|
113 | |
---|
114 | Variable vfL,rL,sldL,vfS,rS,sldS,deltaS,delrhoL,delrhoS,bkg,sldSolv,qval ,aSs |
---|
115 | vfL = coef_Raspberry[0] |
---|
116 | rL = coef_Raspberry[1] |
---|
117 | delrhoL = coef_Raspberry[2] |
---|
118 | vfS = coef_Raspberry[3] |
---|
119 | rS = coef_Raspberry[4] |
---|
120 | aSs = coef_Raspberry[5] |
---|
121 | delrhoS = coef_Raspberry[6] |
---|
122 | deltaS = coef_Raspberry[7] |
---|
123 | |
---|
124 | Duplicate/O xwave_Raspberry ywave_sfLS_Rasp |
---|
125 | Duplicate/O xwave_Raspberry ywave_sfSS_Rasp |
---|
126 | |
---|
127 | Variable psiL,psiS,vol,f2 |
---|
128 | Variable VL,VS,slT,Np,fSs |
---|
129 | |
---|
130 | VL = 4*pi/3*rL^3 |
---|
131 | VS = 4*pi/3*rS^3 |
---|
132 | Np = aSs*4*((rL+deltaS)/rS)^2 |
---|
133 | |
---|
134 | ywave_sfLS_Rasp = fRaspBes(xwave_Raspberry,rL)*fRaspBes(xwave_Raspberry,rS)*(sin(xwave_Raspberry*(rL+deltaS*rS))/xwave_Raspberry/(rL+deltaS*rS)) |
---|
135 | ywave_sfSS_Rasp = fRaspBes(xwave_Raspberry,rS)*fRaspBes(xwave_Raspberry,rS)*(sin(xwave_Raspberry*(rL+deltaS*rS))/xwave_Raspberry/(rL+deltaS*rS))^2 |
---|
136 | |
---|
137 | Display ywave_sfLS_Rasp vs xwave_Raspberry |
---|
138 | AppendToGraph ywave_sfSS_Rasp vs xwave_Raspberry |
---|
139 | ModifyGraph log(bottom)=1 |
---|
140 | |
---|
141 | End |
---|
142 | |
---|
143 | // nothing to change here |
---|
144 | // |
---|
145 | //AAO version, uses XOP if available |
---|
146 | // simply calls the original single point calculation with |
---|
147 | // a wave assignment (this will behave nicely if given point ranges) |
---|
148 | Function Raspberry(cw,yw,xw) : FitFunc |
---|
149 | Wave cw,yw,xw |
---|
150 | |
---|
151 | #if exists("RaspberryX") |
---|
152 | yw = RaspberryX(cw,xw) |
---|
153 | #else |
---|
154 | yw = fRaspberry(cw,xw) |
---|
155 | #endif |
---|
156 | return(0) |
---|
157 | End |
---|
158 | |
---|
159 | |
---|
160 | // you should write your function to calculate the intensity |
---|
161 | // for a single q-value (that's the input parameter x) |
---|
162 | // based on the wave (array) of parameters that you send it (w) |
---|
163 | // |
---|
164 | // unsmeared model calculation |
---|
165 | // |
---|
166 | Function fRaspberry(w,x) : FitFunc |
---|
167 | Wave w |
---|
168 | Variable x |
---|
169 | |
---|
170 | // variables are: |
---|
171 | //[0] volume fraction large spheres |
---|
172 | //[1] radius large sphere () |
---|
173 | //[2] sld large sphere (-2) |
---|
174 | //[3] volume fraction small spheres |
---|
175 | //[4] fraction of small spheres at surface |
---|
176 | //[5] radius small sphere (A) |
---|
177 | //[6] sld small sphere |
---|
178 | //[7] small sphere penetration (A) |
---|
179 | //[8] sld solvent |
---|
180 | //[9] background (cm-1) |
---|
181 | |
---|
182 | Variable vfL,rL,sldL,vfS,rS,sldS,deltaS,delrhoL,delrhoS,bkg,sldSolv,qval ,aSs |
---|
183 | vfL = w[0] |
---|
184 | rL = w[1] |
---|
185 | sldL = w[2] |
---|
186 | vfS = w[3] |
---|
187 | rS = w[4] |
---|
188 | aSs = w[5] |
---|
189 | sldS = w[6] |
---|
190 | deltaS = w[7] |
---|
191 | sldSolv = w[8] |
---|
192 | bkg = w[9] |
---|
193 | |
---|
194 | delrhoL = abs(sldL - sldSolv) |
---|
195 | delrhoS = abs(sldS - sldSolv) |
---|
196 | |
---|
197 | Variable VL,VS,Np,f2,fSs |
---|
198 | |
---|
199 | VL = 4*pi/3*rL^3 |
---|
200 | VS = 4*pi/3*rS^3 |
---|
201 | |
---|
202 | //Np = vfS*fSs*VL/vfL/VS |
---|
203 | //Np = aSs*4*(rS/(rL+deltaS))*(VL/VS) |
---|
204 | Np = aSs*4*((rL+deltaS)/rS)^2 |
---|
205 | |
---|
206 | fSs = Np*vfL*VS/vfS/VL |
---|
207 | |
---|
208 | Make/O/N=9 rasp_temp |
---|
209 | rasp_temp[0] = w[0] |
---|
210 | rasp_temp[1] = w[1] |
---|
211 | rasp_temp[2] = delrhoL |
---|
212 | rasp_temp[3] = w[3] |
---|
213 | rasp_temp[4] = w[4] |
---|
214 | rasp_temp[5] = w[5] |
---|
215 | rasp_temp[6] = delrhoS |
---|
216 | rasp_temp[7] = w[7] |
---|
217 | |
---|
218 | //f2 = (vfL*delrhoL^2*VL + vfS*fSs*Np*delrhoS^2*VS)*fRaspberryKernel(rasp_temp,x) |
---|
219 | f2 = fRaspberryKernel(rasp_temp,x) |
---|
220 | f2+= vfS*(1-fSs)*delrhoS^2*VS*fRaspBes(x,rS)*fRaspBes(x,rS) |
---|
221 | |
---|
222 | // normalize to single particle volume and convert to 1/cm |
---|
223 | f2 *= 1e8 // [=] 1/cm |
---|
224 | |
---|
225 | return (f2+bkg) // Scale, then add in the background |
---|
226 | |
---|
227 | End |
---|
228 | |
---|
229 | Function fRaspberryKernel(w,x) |
---|
230 | Wave w |
---|
231 | Variable x |
---|
232 | |
---|
233 | // variables are: |
---|
234 | //[0] volume fraction large spheres |
---|
235 | //[1] radius large sphere () |
---|
236 | //[2] sld large sphere (-2) |
---|
237 | //[3] volume fraction small spheres |
---|
238 | //[4] fraction of small spheres at surface |
---|
239 | //[5] radius small sphere (A) |
---|
240 | //[6] sld small sphere |
---|
241 | //[7] small sphere penetration (A) |
---|
242 | //[8] sld solvent |
---|
243 | |
---|
244 | Variable vfL,rL,sldL,vfS,rS,sldS,deltaS,delrhoL,delrhoS,bkg,sldSolv,qval ,aSs |
---|
245 | vfL = w[0] |
---|
246 | rL = w[1] |
---|
247 | delrhoL = w[2] |
---|
248 | vfS = w[3] |
---|
249 | rS = w[4] |
---|
250 | aSs = w[5] |
---|
251 | delrhoS = w[6] |
---|
252 | deltaS = w[7] |
---|
253 | |
---|
254 | qval = x //rename the input q-value, purely for readability |
---|
255 | |
---|
256 | Variable psiL,psiS,vol,f2 |
---|
257 | Variable sfLS,sfSS |
---|
258 | Variable VL,VS,slT,Np,fSs |
---|
259 | |
---|
260 | VL = 4*pi/3*rL^3 |
---|
261 | VS = 4*pi/3*rS^3 |
---|
262 | |
---|
263 | Np = aSs*4*(rS/(rL+deltaS))*VL/VS |
---|
264 | //Np = aSs*4*((rL+deltaS)/rS)^2 |
---|
265 | |
---|
266 | fSs = Np*vfL*VS/vfS/VL |
---|
267 | |
---|
268 | slT = delrhoL*VL + Np*delrhoS*VS |
---|
269 | |
---|
270 | psiL = fRaspBes(qval,rL) |
---|
271 | psiS = fRaspBes(qval,rS) |
---|
272 | |
---|
273 | sfLS = psiL*psiS*(sin(qval*(rL+deltaS*rS))/qval/(rL+deltaS*rS)) |
---|
274 | sfSS = psiS*psiS*(sin(qval*(rL+deltaS*rS))/qval/(rL+deltaS*rS))^2 |
---|
275 | |
---|
276 | f2 = delrhoL^2*VL^2*psiL^2 |
---|
277 | f2 += Np*delrhoS^2*VS^2*psiS^2 |
---|
278 | f2 += Np*(Np-1)*delrhoS^2*VS^2*sfSS |
---|
279 | f2 += 2*Np*delrhoL*delrhoS*VL*VS*sfLS |
---|
280 | if (f2 != 0) |
---|
281 | f2 = f2/slT/slT |
---|
282 | endif |
---|
283 | |
---|
284 | f2 = f2*(vfL*delrhoL^2*VL + vfS*fSs*Np*delrhoS^2*VS) |
---|
285 | |
---|
286 | return f2 |
---|
287 | End |
---|
288 | |
---|
289 | Function fRaspBes(Qval,Rad) |
---|
290 | Variable Qval,Rad |
---|
291 | |
---|
292 | Variable retval |
---|
293 | |
---|
294 | retval = 3*(sin(qval*rad)-qval*rad*cos(qval*rad))/qval^3/rad^3 |
---|
295 | |
---|
296 | return retval |
---|
297 | End |
---|
298 | |
---|
299 | /////////////////////////////////////////////////////////////// |
---|
300 | // smeared model calculation |
---|
301 | // |
---|
302 | // you don't need to do anything with this function, as long as |
---|
303 | // your Raspberry works correctly, you get the resolution-smeared |
---|
304 | // version for free. |
---|
305 | // |
---|
306 | // this is all there is to the smeared model calculation! |
---|
307 | Function SmearedRaspberry(s) : FitFunc |
---|
308 | Struct ResSmearAAOStruct &s |
---|
309 | |
---|
310 | // the name of your unsmeared model (AAO) is the first argument |
---|
311 | Smear_Model_20(Raspberry,s.coefW,s.xW,s.yW,s.resW) |
---|
312 | |
---|
313 | return(0) |
---|
314 | End |
---|
315 | |
---|
316 | |
---|
317 | /////////////////////////////////////////////////////////////// |
---|
318 | |
---|
319 | |
---|
320 | // nothing to change here |
---|
321 | // |
---|
322 | //wrapper to calculate the smeared model as an AAO-Struct |
---|
323 | // fills the struct and calls the ususal function with the STRUCT parameter |
---|
324 | // |
---|
325 | // used only for the dependency, not for fitting |
---|
326 | // |
---|
327 | Function fSmearedRaspberry(coefW,yW,xW) |
---|
328 | Wave coefW,yW,xW |
---|
329 | |
---|
330 | String str = getWavesDataFolder(yW,0) |
---|
331 | String DF="root:"+str+":" |
---|
332 | |
---|
333 | WAVE resW = $(DF+str+"_res") |
---|
334 | |
---|
335 | STRUCT ResSmearAAOStruct fs |
---|
336 | WAVE fs.coefW = coefW |
---|
337 | WAVE fs.yW = yW |
---|
338 | WAVE fs.xW = xW |
---|
339 | WAVE fs.resW = resW |
---|
340 | |
---|
341 | Variable err |
---|
342 | err = SmearedRaspberry(fs) |
---|
343 | |
---|
344 | return (0) |
---|
345 | End |
---|