# source:sans/Dev/trunk/NCNR_User_Procedures/Analysis/Alpha/Tinker/FFT_Fit_MixedDumbbell.ipf@843

Last change on this file since 843 was 843, checked in by srkline, 11 years ago

Corrected the FFT fit functions to use the 10-7 multiplier for the SLD. Included the MixedDumbbell? model to the included model list. Tested all of the functions.

File size: 8.6 KB
Line
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
11Proc 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
32End
33
34/////////////////////////////////////////////////////////////
35//// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
36Proc 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:
68End
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//
74Function MixedDumbbellFFT(cw,yw,xw) : FitFunc
75        Wave cw,yw,xw
76
77//      Variable t1=StopMSTimer(-2)
78
79//The input variables are (and output)
81        Variable ctr,fill1,fill2
82
83        scale = cw[0]
86        rho1 = cw[3]
87        rho2 = cw[4]
88        rhos = cw[5]
89        bkg = cw[6]
90
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        NVAR FFT_delRho = root:FFT_delRho               //the SLD multiplier, should have been initialized to 1e-7
100
101
102        FFT_SolventSLD = trunc(rhos/FFT_delRho)         //spits back an integer, maybe not correct
103
104// generate the matrix and erase it
105//      FFT_MakeMatrixButtonProc("")
106        FFTEraseMatrixButtonProc("")
107        Wave m=root:mat
108
109// fill the matrix with solvent
110        FFTFillSolventMatrixProc("")
111
112// with the input parameters, build the structure
113        ctr = trunc(FFT_N/2)
114        fill1 = trunc(rho1/FFT_delRho)
115        fill2 = trunc(rho2/FFT_delRho)
116
119
120// set up for the calculation
121
122
123// do the calculation (use the binned if only one SLD, or bin+SLD if the model requires this)
124        fDoCalc(xw,yw,FFT_T,3,0)                //the binned SLD calculation
125
126// reset the volume fraction to get the proper scaling
127// the calculation is normalized to the volume fraction of spheres filling the matrix
128        Variable frac
129        frac = VolumeFraction_Occ(m)
130
131        yw /= frac
132        yw *= scale
133        yw += bkg
134
135//      Print "elapsed time = ",(StopMSTimer(-2) - t1)/1e6
136
137        return(0)
138End
139
140
141//
142//// this is all there is to the smeared calculation!
143Function SmearedMixedDumbbellFFT(s) :FitFunc
144        Struct ResSmearAAOStruct &s
145
146////the name of your unsmeared model is the first argument
147        Smear_Model_20(MixedDumbbellFFT,s.coefW,s.xW,s.yW,s.resW)
148
149        return(0)
150End
151//
152//
153////wrapper to calculate the smeared model as an AAO-Struct
154//// fills the struct and calls the ususal function with the STRUCT parameter
155////
156//// used only for the dependency, not for fitting
157////
158Function fSmearedMixedDumbbellFFT(coefW,yW,xW)
159        Wave coefW,yW,xW
160
161        String str = getWavesDataFolder(yW,0)
162        String DF="root:"+str+":"
163
164        WAVE resW = \$(DF+str+"_res")
165
166        STRUCT ResSmearAAOStruct fs
167        WAVE fs.coefW = coefW
168        WAVE fs.yW = yW
169        WAVE fs.xW = xW
170        WAVE fs.resW = resW
171
172        Variable err
173        err = SmearedMixedDumbbellFFT(fs)
174
175        return (0)
176End
177
178//Function MixTest()
179//
180//// make sure all of the globals are set correctly
181//      NVAR FFT_T = root:FFT_T
182//      NVAR FFT_N = root:FFT_N
183//      NVAR FFT_SolventSLD = root:FFT_SolventSLD
184//
186//      rho1=1e-6
187//      rho2=3e-6
188//      rhos=6e-6
189//
192//      ctr=50
194//
195//      FFT_SolventSLD = trunc(rhos*1e6)                //spits back an integer, maybe not correct
196//
197//// generate the matrix and erase it
198////    FFT_MakeMatrixButtonProc("")
199//      FFTEraseMatrixButtonProc("")
200//      Wave m=root:mat
201//
202//// fill the matrix with solvent
203//      FFTFillSolventMatrixProc("")
204//
205//// with the input parameters, build the structure
206//      ctr = trunc(FFT_N/2)
207//      fill1 = trunc(rho1*1e6)
208//      fill2 = trunc(rho2*1e6)
209//
212//
213//End
214//
215//Function CoreShellTest()
216//
217//// make sure all of the globals are set correctly
218//      NVAR FFT_T = root:FFT_T
219//      NVAR FFT_N = root:FFT_N
220//      NVAR FFT_SolventSLD = root:FFT_SolventSLD
221//
223//      rho1=1e-6
224//      rho2=3e-6
225//      rhos=6e-6
226//
227////    rho1 += 3e-6
228////    rho2 += 3e-6
229////    rhos += 3e-6
230//
233//      ctr=50
234//
235//      FFT_SolventSLD = trunc(rhos*1e6)                //spits back an integer, maybe not correct
236//
237//// generate the matrix and erase it
238////    FFT_MakeMatrixButtonProc("")
239//      FFTEraseMatrixButtonProc("")
240//      Wave m=root:mat
241//
242//// fill the matrix with solvent
243//      FFTFillSolventMatrixProc("")
244//
245//// with the input parameters, build the structure
246//      ctr = trunc(FFT_N/2)
247//      fill1 = trunc(rho1*1e6)
248//      fill2 = trunc(rho2*1e6)
249//
252//
253//End
254//
255//Function ThreeShellTest()
256//
257//// make sure all of the globals are set correctly
258//      NVAR FFT_T = root:FFT_T
259//      NVAR FFT_N = root:FFT_N
260//      NVAR FFT_SolventSLD = root:FFT_SolventSLD
261//
262//      Variable rcore,rhocore,thick1,rhoshel1,thick2,rhoshel2,thick3,rhoshel3,rhos,fill1,fill2,fill3,fillc,ctr
263//      WAVE w=root:coef_ThreeShell
264//
265//      rcore = w[1]
266//      rhocore = w[2]
267//      thick1 = w[3]
268//      rhoshel1 = w[4]
269//      thick2 = w[5]
270//      rhoshel2 = w[6]
271//      thick3 = w[7]
272//      rhoshel3 = w[8]
273//      rhos = w[9]
274//
275////    rho1 += 3e-6
276////    rho2 += 3e-6
277////    rhos += 3e-6
278//
279//      FFT_SolventSLD = trunc(rhos*1e6)                //spits back an integer, maybe not correct
280//
281//// generate the matrix and erase it
282////    FFT_MakeMatrixButtonProc("")
283//      FFTEraseMatrixButtonProc("")
284//      Wave m=root:mat
285//
286//// fill the matrix with solvent
287//      FFTFillSolventMatrixProc("")
288//
289//// with the input parameters, build the structure
290//      ctr = trunc(FFT_N/2)
291//      fillc = trunc(rhocore*1e6)
292//      fill1 = trunc(rhoshel1*1e6)
293//      fill2 = trunc(rhoshel2*1e6)
294//      fill3 = trunc(rhoshel3*1e6)
295//
296//      FillSphereRadius(m,FFT_T,rcore+thick1+thick2+thick3,ctr,ctr,ctr,fill3)          //outer size (shell 3)
297//      FillSphereRadius(m,FFT_T,rcore+thick1+thick2,ctr,ctr,ctr,fill2)         //outer size (shell 2)
298//      FillSphereRadius(m,FFT_T,rcore+thick1,ctr,ctr,ctr,fill1)                //outer size (shell 1)