1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma IgorVersion=6.1 |
---|
3 | |
---|
4 | //////////////////////////////////////////////// |
---|
5 | // |
---|
6 | // This is a proof of principle to convert a structure built of spheres |
---|
7 | // into a fitting function |
---|
8 | // |
---|
9 | //////////////////////////////////////////////// |
---|
10 | |
---|
11 | Proc PlotMixedDumbbellFFT(num,qmin,qmax) |
---|
12 | Variable num=100,qmin=0.004,qmax=0.4 |
---|
13 | Prompt num "Enter number of data points for model: " |
---|
14 | Prompt qmin "Enter minimum q-value (A^-1) for model: " |
---|
15 | Prompt qmax "Enter maximum q-value (A^-1) for model: " |
---|
16 | |
---|
17 | make/o/D/n=(num) xwave_MixDumFFT,ywave_MixDumFFT |
---|
18 | xwave_MixDumFFT = alog(log(qmin) + x*((log(qmax)-log(qmin))/num)) |
---|
19 | make/o/D coef_MixDumFFT = {0.01,40,80,1e-6,3e-6,6e-6,0.0} |
---|
20 | make/o/t parameters_MixDumFFT = {"scale","Radius 1 (A)","Radius 2 (A)","SLD sphere 1 (A-2)","SLD sphere 2 (A-2)","SLD solvent (A-2)","bkgd (cm-1)"} |
---|
21 | Edit parameters_MixDumFFT,coef_MixDumFFT |
---|
22 | Variable/G root:g_MixDumFFT |
---|
23 | g_MixDumFFT := MixedDumbbellFFT(coef_MixDumFFT,ywave_MixDumFFT,xwave_MixDumFFT) |
---|
24 | |
---|
25 | Display ywave_MixDumFFT vs xwave_MixDumFFT |
---|
26 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
27 | Label bottom "q (A\\S-1\\M)" |
---|
28 | Label left "Intensity (cm\\S-1\\M)" |
---|
29 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
30 | |
---|
31 | AddModelToStrings("MixedDumbbellFFT","coef_MixDumFFT","parameters_MixDumFFT","MixDumFFT") |
---|
32 | End |
---|
33 | |
---|
34 | ///////////////////////////////////////////////////////////// |
---|
35 | //// - sets up a dependency to a wrapper, not the actual SmearedModelFunction |
---|
36 | Proc PlotSmearedMixedDumbbellFFT(str) |
---|
37 | String str |
---|
38 | Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4) |
---|
39 | |
---|
40 | // if any of the resolution waves are missing => abort |
---|
41 | if(ResolutionWavesMissingDF(str)) //updated to NOT use global strings (in GaussUtils) |
---|
42 | Abort |
---|
43 | endif |
---|
44 | |
---|
45 | SetDataFolder $("root:"+str) |
---|
46 | |
---|
47 | // Setup parameter table for model function |
---|
48 | make/o/D smear_coef_MixDumFFT = {0.01,40,80,1e-6,3e-6,6e-6,0.0} |
---|
49 | make/o/t smear_parameters_MixDumFFT = {"scale","Radius 1 (A)","Radius 2 (A)","SLD sphere 1 (A-2)","SLD sphere 2 (A-2)","SLD solvent (A-2)","bkgd (cm-1)"} |
---|
50 | Edit smear_parameters_MixDumFFT,smear_coef_MixDumFFT |
---|
51 | |
---|
52 | // output smeared intensity wave, dimensions are identical to experimental QSIG values |
---|
53 | // make extra copy of experimental q-values for easy plotting |
---|
54 | Duplicate/O $(str+"_q") smeared_MixDumFFT,smeared_qvals |
---|
55 | SetScale d,0,0,"1/cm",smeared_MixDumFFT |
---|
56 | |
---|
57 | Variable/G gs_MixDumFFT=0 |
---|
58 | gs_MixDumFFT := fSmearedMixedDumbbellFFT(smear_coef_MixDumFFT,smeared_MixDumFFT,smeared_qvals) //this wrapper fills the STRUCT |
---|
59 | |
---|
60 | Display smeared_MixDumFFT vs smeared_qvals |
---|
61 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
62 | Label bottom "q (A\\S-1\\M)" |
---|
63 | Label left "Intensity (cm\\S-1\\M)" |
---|
64 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
65 | |
---|
66 | SetDataFolder root: |
---|
67 | AddModelToStrings("SmearedMixedDumbbellFFT","smear_coef_MixDumFFT","smear_parameters_MixDumFFT","MixDumFFT") |
---|
68 | End |
---|
69 | |
---|
70 | // The calculation is inherently AAO, so it's all done here, not passed to another FitFunc |
---|
71 | // |
---|
72 | // not quite sure how to handle the SLDs yet, since I'm treating them as 1 or 2 digit integers |
---|
73 | // |
---|
74 | Function MixedDumbbellFFT(cw,yw,xw) : FitFunc |
---|
75 | Wave cw,yw,xw |
---|
76 | |
---|
77 | // Variable t1=StopMSTimer(-2) |
---|
78 | |
---|
79 | //The input variables are (and output) |
---|
80 | Variable scale,radius1,radius2,separation,number,delrho,bkg,edgeSeparation,rho1,rho2,rhos |
---|
81 | Variable ctr,fill1,fill2 |
---|
82 | |
---|
83 | scale = cw[0] |
---|
84 | radius1 = cw[1] |
---|
85 | radius2 = cw[2] |
---|
86 | rho1 = cw[3] |
---|
87 | rho2 = cw[4] |
---|
88 | rhos = cw[5] |
---|
89 | bkg = cw[6] |
---|
90 | |
---|
91 | separation = radius1 + radius2 // edge contact |
---|
92 | number = 2 //fixed |
---|
93 | |
---|
94 | |
---|
95 | // make sure all of the globals are set correctly |
---|
96 | NVAR FFT_T = root:FFT_T |
---|
97 | NVAR FFT_N = root:FFT_N |
---|
98 | NVAR FFT_SolventSLD = root:FFT_SolventSLD |
---|
99 | |
---|
100 | FFT_SolventSLD = trunc(rhos*1e6) //spits back an integer, maybe not correct |
---|
101 | |
---|
102 | // generate the matrix and erase it |
---|
103 | // FFT_MakeMatrixButtonProc("") |
---|
104 | FFTEraseMatrixButtonProc("") |
---|
105 | Wave m=root:mat |
---|
106 | |
---|
107 | // fill the matrix with solvent |
---|
108 | FFTFillSolventMatrixProc("") |
---|
109 | |
---|
110 | // with the input parameters, build the structure |
---|
111 | ctr = trunc(FFT_N/2) |
---|
112 | fill1 = trunc(rho1*1e6) |
---|
113 | fill2 = trunc(rho2*1e6) |
---|
114 | |
---|
115 | FillSphereRadius(m,FFT_T,radius1,ctr,ctr,ctr,fill1) |
---|
116 | FillSphereRadius(m,FFT_T,radius2,ctr+separation/FFT_T,ctr,ctr,fill2) |
---|
117 | |
---|
118 | // set up for the calculation |
---|
119 | |
---|
120 | |
---|
121 | // do the calculation (use the binned if only one SLD, or bin+SLD if the model requires this) |
---|
122 | fDoCalc(xw,yw,FFT_T,3,0) //the binned SLD calculation |
---|
123 | |
---|
124 | // reset the volume fraction to get the proper scaling |
---|
125 | // the calculation is normalized to the volume fraction of spheres filling the matrix |
---|
126 | Variable frac |
---|
127 | frac = VolumeFraction_Occ(m) |
---|
128 | |
---|
129 | yw /= frac |
---|
130 | yw *= scale |
---|
131 | yw += bkg |
---|
132 | |
---|
133 | // Print "elapsed time = ",(StopMSTimer(-2) - t1)/1e6 |
---|
134 | |
---|
135 | return(0) |
---|
136 | End |
---|
137 | |
---|
138 | |
---|
139 | // |
---|
140 | //// this is all there is to the smeared calculation! |
---|
141 | Function SmearedMixedDumbbellFFT(s) :FitFunc |
---|
142 | Struct ResSmearAAOStruct &s |
---|
143 | |
---|
144 | ////the name of your unsmeared model is the first argument |
---|
145 | Smear_Model_20(MixedDumbbellFFT,s.coefW,s.xW,s.yW,s.resW) |
---|
146 | |
---|
147 | return(0) |
---|
148 | End |
---|
149 | // |
---|
150 | // |
---|
151 | ////wrapper to calculate the smeared model as an AAO-Struct |
---|
152 | //// fills the struct and calls the ususal function with the STRUCT parameter |
---|
153 | //// |
---|
154 | //// used only for the dependency, not for fitting |
---|
155 | //// |
---|
156 | Function fSmearedMixedDumbbellFFT(coefW,yW,xW) |
---|
157 | Wave coefW,yW,xW |
---|
158 | |
---|
159 | String str = getWavesDataFolder(yW,0) |
---|
160 | String DF="root:"+str+":" |
---|
161 | |
---|
162 | WAVE resW = $(DF+str+"_res") |
---|
163 | |
---|
164 | STRUCT ResSmearAAOStruct fs |
---|
165 | WAVE fs.coefW = coefW |
---|
166 | WAVE fs.yW = yW |
---|
167 | WAVE fs.xW = xW |
---|
168 | WAVE fs.resW = resW |
---|
169 | |
---|
170 | Variable err |
---|
171 | err = SmearedMixedDumbbellFFT(fs) |
---|
172 | |
---|
173 | return (0) |
---|
174 | End |
---|
175 | |
---|
176 | //Function MixTest() |
---|
177 | // |
---|
178 | //// make sure all of the globals are set correctly |
---|
179 | // NVAR FFT_T = root:FFT_T |
---|
180 | // NVAR FFT_N = root:FFT_N |
---|
181 | // NVAR FFT_SolventSLD = root:FFT_SolventSLD |
---|
182 | // |
---|
183 | // Variable rho1,rho2,rhos,radius1,radius2,ctr,separation,fill1,fill2 |
---|
184 | // rho1=1e-6 |
---|
185 | // rho2=3e-6 |
---|
186 | // rhos=6e-6 |
---|
187 | // |
---|
188 | // radius1 = 40 |
---|
189 | // radius2 = 80 |
---|
190 | // ctr=50 |
---|
191 | // separation = radius1 + radius2 |
---|
192 | // |
---|
193 | // FFT_SolventSLD = trunc(rhos*1e6) //spits back an integer, maybe not correct |
---|
194 | // |
---|
195 | //// generate the matrix and erase it |
---|
196 | //// FFT_MakeMatrixButtonProc("") |
---|
197 | // FFTEraseMatrixButtonProc("") |
---|
198 | // Wave m=root:mat |
---|
199 | // |
---|
200 | //// fill the matrix with solvent |
---|
201 | // FFTFillSolventMatrixProc("") |
---|
202 | // |
---|
203 | //// with the input parameters, build the structure |
---|
204 | // ctr = trunc(FFT_N/2) |
---|
205 | // fill1 = trunc(rho1*1e6) |
---|
206 | // fill2 = trunc(rho2*1e6) |
---|
207 | // |
---|
208 | // FillSphereRadius(m,FFT_T,radius1,ctr,ctr,ctr,fill1) |
---|
209 | // FillSphereRadius(m,FFT_T,radius2,ctr+separation/FFT_T,ctr,ctr,fill2) |
---|
210 | // |
---|
211 | //End |
---|
212 | // |
---|
213 | //Function CoreShellTest() |
---|
214 | // |
---|
215 | //// make sure all of the globals are set correctly |
---|
216 | // NVAR FFT_T = root:FFT_T |
---|
217 | // NVAR FFT_N = root:FFT_N |
---|
218 | // NVAR FFT_SolventSLD = root:FFT_SolventSLD |
---|
219 | // |
---|
220 | // Variable rho1,rho2,rhos,radius1,radius2,ctr,separation,fill1,fill2 |
---|
221 | // rho1=1e-6 |
---|
222 | // rho2=3e-6 |
---|
223 | // rhos=6e-6 |
---|
224 | // |
---|
225 | //// rho1 += 3e-6 |
---|
226 | //// rho2 += 3e-6 |
---|
227 | //// rhos += 3e-6 |
---|
228 | // |
---|
229 | // radius1 = 20 |
---|
230 | // radius2 = 40 |
---|
231 | // ctr=50 |
---|
232 | // |
---|
233 | // FFT_SolventSLD = trunc(rhos*1e6) //spits back an integer, maybe not correct |
---|
234 | // |
---|
235 | //// generate the matrix and erase it |
---|
236 | //// FFT_MakeMatrixButtonProc("") |
---|
237 | // FFTEraseMatrixButtonProc("") |
---|
238 | // Wave m=root:mat |
---|
239 | // |
---|
240 | //// fill the matrix with solvent |
---|
241 | // FFTFillSolventMatrixProc("") |
---|
242 | // |
---|
243 | //// with the input parameters, build the structure |
---|
244 | // ctr = trunc(FFT_N/2) |
---|
245 | // fill1 = trunc(rho1*1e6) |
---|
246 | // fill2 = trunc(rho2*1e6) |
---|
247 | // |
---|
248 | // FillSphereRadius(m,FFT_T,radius2,ctr,ctr,ctr,fill2) |
---|
249 | // FillSphereRadius(m,FFT_T,radius1,ctr,ctr,ctr,fill1) |
---|
250 | // |
---|
251 | //End |
---|
252 | // |
---|
253 | //Function ThreeShellTest() |
---|
254 | // |
---|
255 | //// make sure all of the globals are set correctly |
---|
256 | // NVAR FFT_T = root:FFT_T |
---|
257 | // NVAR FFT_N = root:FFT_N |
---|
258 | // NVAR FFT_SolventSLD = root:FFT_SolventSLD |
---|
259 | // |
---|
260 | // Variable rcore,rhocore,thick1,rhoshel1,thick2,rhoshel2,thick3,rhoshel3,rhos,fill1,fill2,fill3,fillc,ctr |
---|
261 | // WAVE w=root:coef_ThreeShell |
---|
262 | // |
---|
263 | // rcore = w[1] |
---|
264 | // rhocore = w[2] |
---|
265 | // thick1 = w[3] |
---|
266 | // rhoshel1 = w[4] |
---|
267 | // thick2 = w[5] |
---|
268 | // rhoshel2 = w[6] |
---|
269 | // thick3 = w[7] |
---|
270 | // rhoshel3 = w[8] |
---|
271 | // rhos = w[9] |
---|
272 | // |
---|
273 | //// rho1 += 3e-6 |
---|
274 | //// rho2 += 3e-6 |
---|
275 | //// rhos += 3e-6 |
---|
276 | // |
---|
277 | // FFT_SolventSLD = trunc(rhos*1e6) //spits back an integer, maybe not correct |
---|
278 | // |
---|
279 | //// generate the matrix and erase it |
---|
280 | //// FFT_MakeMatrixButtonProc("") |
---|
281 | // FFTEraseMatrixButtonProc("") |
---|
282 | // Wave m=root:mat |
---|
283 | // |
---|
284 | //// fill the matrix with solvent |
---|
285 | // FFTFillSolventMatrixProc("") |
---|
286 | // |
---|
287 | //// with the input parameters, build the structure |
---|
288 | // ctr = trunc(FFT_N/2) |
---|
289 | // fillc = trunc(rhocore*1e6) |
---|
290 | // fill1 = trunc(rhoshel1*1e6) |
---|
291 | // fill2 = trunc(rhoshel2*1e6) |
---|
292 | // fill3 = trunc(rhoshel3*1e6) |
---|
293 | // |
---|
294 | // FillSphereRadius(m,FFT_T,rcore+thick1+thick2+thick3,ctr,ctr,ctr,fill3) //outer size (shell 3) |
---|
295 | // FillSphereRadius(m,FFT_T,rcore+thick1+thick2,ctr,ctr,ctr,fill2) //outer size (shell 2) |
---|
296 | // FillSphereRadius(m,FFT_T,rcore+thick1,ctr,ctr,ctr,fill1) //outer size (shell 1) |
---|
297 | // FillSphereRadius(m,FFT_T,rcore,ctr,ctr,ctr,fillc) //core |
---|
298 | // |
---|
299 | //End |
---|