source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Alpha/Tinker/FFT_Fit_3Cyl_KR.ipf @ 798

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

I'm not sure this is a great idea, but I'm putting the FFT / Debye sphere work that I have completed into SVN. It's all really rough - the math, I believe is correct, but the interface if really, really rough. But it's not going to develop without help.

File size: 6.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 PlotThreeCylKR(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       
18        // make the needed waves, three rows for this case
19        Make/O/D/N=3 xCtr_KR,yCtr_KR,zCtr_KR,rad_KR,len_KR,sph_KR,rotx_KR,roty_KR,SLD_KR
20       
21        make/o/D/n=(num) xwave_c3KR,ywave_c3KR
22        xwave_c3KR =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
23        make/o/D coef_c3KR = {0.01,40,32,26,34,26,34,1e-6,2e-6,0.01}
24        make/o/t parameters_c3KR = {"scale","radius 1 (A)","length 1 (A)","radius 2 (A)","length 2 (A)","radius 3 (A)","length 3 (A)","SLD cylinder (A^-2)","SLD solvent (A^-2)","incoh. bkg (cm^-1)"}
25        Edit parameters_c3KR,coef_c3KR
26        Variable/G root:g_c3KR
27        g_c3KR := ThreeCylKR(coef_c3KR,ywave_c3KR,xwave_c3KR)
28
29        Display ywave_c3KR vs xwave_c3KR
30        ModifyGraph log=1,marker=29,msize=2,mode=4
31        Label bottom "q (A\\S-1\\M)"
32        Label left "Intensity (cm\\S-1\\M)"
33        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
34       
35        AddModelToStrings("ThreeCylKR","coef_c3KR","parameters_c3KR","c3KR")
36End
37
38/////////////////////////////////////////////////////////////
39//// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
40Proc PlotSmearedThreeCylKR(str)                                                         
41        String str
42        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
43       
44        // if any of the resolution waves are missing => abort
45        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
46                Abort
47        endif
48       
49        // make the needed waves, three rows for this case
50        Make/O/D/N=3 xCtr_KR,yCtr_KR,zCtr_KR,rad_KR,len_KR,sph_KR,rotx_KR,roty_KR,SLD_KR
51       
52        SetDataFolder $("root:"+str)
53       
54        // Setup parameter table for model function
55        make/o/D smear_coef_c3KR = {0.01,40,32,26,34,26,34,1e-6,2e-6,0.01}
56        make/o/t smear_parameters_c3KR = {"scale","radius 1 (A)","length 1 (A)","radius 2 (A)","length 2 (A)","radius 3 (A)","length 3 (A)","SLD cylinder (A^-2)","SLD solvent (A^-2)","incoh. bkg (cm^-1)"}
57        Edit smear_parameters_c3KR,smear_coef_c3KR
58       
59        // output smeared intensity wave, dimensions are identical to experimental QSIG values
60        // make extra copy of experimental q-values for easy plotting
61        Duplicate/O $(str+"_q") smeared_c3KR,smeared_qvals
62        SetScale d,0,0,"1/cm",smeared_c3KR     
63                                       
64        Variable/G gs_c3KR=0
65        gs_c3KR := fSmearedThreeCylKR(smear_coef_c3KR,smeared_c3KR,smeared_qvals)       //this wrapper fills the STRUCT
66       
67        Display smeared_c3KR vs smeared_qvals
68        ModifyGraph log=1,marker=29,msize=2,mode=4
69        Label bottom "q (A\\S-1\\M)"
70        Label left "Intensity (cm\\S-1\\M)"
71        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
72       
73        SetDataFolder root:
74        AddModelToStrings("SmearedThreeCylKR","smear_coef_c3KR","smear_parameters_c3KR","c3KR")
75End
76
77// The calculation is inherently AAO, so it's all done here, not passed to another FitFunc
78//
79// not quite sure how to handle the SLDs yet, since I'm treating them as 1 or 2 digit integers
80//
81Function ThreeCylKR(cw,yw,xw) : FitFunc
82        Wave cw,yw,xw
83
84//      Variable t1=StopMSTimer(-2)
85
86//The input variables are (and output)
87        //[0] scale
88        //[1] cylinder RADIUS (A)
89        //[2] total cylinder LENGTH (A)
90        //[3] sld cylinder (A^-2)
91        //[4] sld solvent
92        //[5] background (cm^-1)
93        Variable scale,delrho,bkg,sldCyl,sldSolv,ctr,fill
94        Variable r0,r1,r2,l0,l1,l2
95        scale = cw[0]
96        r0 = cw[1]
97        l0 = cw[2]
98        r1 = cw[3]
99        l1 = cw[4]
100        r2 = cw[5]
101        l2 = cw[6]
102        sldCyl = cw[7]
103        sldSolv = cw[8]
104        bkg = cw[9]
105
106
107// make sure all of the globals are set correctly
108        NVAR FFT_T = root:FFT_T
109        NVAR FFT_N = root:FFT_N
110        NVAR FFT_SolventSLD = root:FFT_SolventSLD
111       
112        FFT_SolventSLD = trunc(sldSolv*1e6)             //spits back an integer, maybe not correct
113
114// generate the matrix and erase it
115//      FFT_MakeMatrixButtonProc("")
116//      FFTEraseMatrixButtonProc("")
117//      Wave m=root:mat
118
119// fill the matrix with solvent
120//      FFTFillSolventMatrixProc("")
121
122        // waves to pass to parsing routine
123        WAVE xCtr_KR=root:xCtr_KR
124        WAVE yCtr_KR=root:yCtr_KR
125        WAVE zCtr_KR=root:zCtr_KR
126        WAVE rad_KR=root:rad_KR
127        WAVE len_KR=root:len_KR
128        WAVE sph_KR=root:sph_KR
129        WAVE rotx_KR=root:rotx_KR
130        WAVE roty_KR=root:roty_KR
131        WAVE SLD_KR=root:SLD_KR
132
133
134
135// with the input parameters, build the structure
136// the first cylinder is at 0,0,0
137// the second cylinder is on "top" (Z)
138// the third cylinder is on the "bottom" (-Z)
139        xCtr_KR[0] = 0
140        yCtr_KR[0] = 0
141        zCtr_KR[0] = 0
142        rad_KR[0] = r0
143        len_KR[0] = l0
144
145        xCtr_KR[1] = 0
146        yCtr_KR[1] = 0
147        zCtr_KR[1] = l0/2 + l1/2
148        rad_KR[1] = r1
149        len_KR[1] = l1
150       
151        xCtr_KR[2] = 0
152        yCtr_KR[2] = 0
153        zCtr_KR[2] = -(l0/2 + l2/2)
154        rad_KR[2] = r2
155        len_KR[2] = l2
156       
157        //no rotation here, only one SLD
158        sph_KR = FFT_T          //use the global
159        rotx_KR = 0
160        roty_KR = 0
161        SLD_KR = trunc(sldCyl*1e6)
162       
163
164
165// this parses the information and generates xoutW, youtW, zoutW, sldW in the root folder
166        KR_MultiCylinder(xCtr_KR,yCtr_KR,zCtr_KR,rad_KR,len_KR,sph_KR,rotx_KR,roty_KR,SLD_KR)
167       
168       
169        // these are really just for display, or if the FFT of mat is wanted later.
170        WAVE xoutW=root:xoutW
171        WAVE youtW=root:youtW
172        WAVE zoutW=root:zoutW
173        WAVE sldW=root:sldW
174               
175        XYZV_FillMat(xoutW,youtW,ZoutW,sldW,1)                  //last 1 will erase the matrix
176        MakeTriplet(xoutW,youtW,zoutW)
177
178
179
180// do the calculation (use the binned if only one SLD, or bin+SLD if the model requires this)
181        fDoCalc(xw,yw,FFT_T,12,0)               //the binned calculation
182
183// reset the volume fraction to get the proper scaling
184// the calculation is normalized to the volume fraction of spheres filling the matrix
185        Variable frac
186        Wave m=root:mat
187
188        frac = VolumeFraction_Occ(m)
189
190        yw /= frac
191        yw *= scale
192        yw += bkg
193
194//      Print "elapsed time = ",(StopMSTimer(-2) - t1)/1e6
195
196        return(0)
197End
198
199
200//
201//// this is all there is to the smeared calculation!
202Function SmearedThreeCylKR(s) :FitFunc
203        Struct ResSmearAAOStruct &s
204
205////the name of your unsmeared model is the first argument
206        Smear_Model_20(ThreeCylKR,s.coefW,s.xW,s.yW,s.resW)
207
208        return(0)
209End
210//
211//
212////wrapper to calculate the smeared model as an AAO-Struct
213//// fills the struct and calls the ususal function with the STRUCT parameter
214////
215//// used only for the dependency, not for fitting
216////
217Function fSmearedThreeCylKR(coefW,yW,xW)
218        Wave coefW,yW,xW
219       
220        String str = getWavesDataFolder(yW,0)
221        String DF="root:"+str+":"
222       
223        WAVE resW = $(DF+str+"_res")
224       
225        STRUCT ResSmearAAOStruct fs
226        WAVE fs.coefW = coefW   
227        WAVE fs.yW = yW
228        WAVE fs.xW = xW
229        WAVE fs.resW = resW
230       
231        Variable err
232        err = SmearedThreeCylKR(fs)
233       
234        return (0)
235End
Note: See TracBrowser for help on using the repository browser.