# source:sans/Dev/trunk/NCNR_User_Procedures/Analysis/Alpha/Tinker/FFT_Fit_Sphere.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: 5.0 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 PlotSphereFFT(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_sfFFT,ywave_sfFFT
18        xwave_sfFFT =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
19        make/o/D coef_sfFFT = {1.,60.,1e-6,6.3e-6,0.01}
20        make/o/t parameters_sfFFT = {"scale","radius (A)","SLD Sphere (A^-2)","SLD solvent (A^-2)","incoh. bkg (cm^-1)"}
21        Edit parameters_sfFFT,coef_sfFFT
22        Variable/G root:g_sfFFT
23        g_sfFFT := SphereFFT(coef_sfFFT,ywave_sfFFT,xwave_sfFFT)
24
25        Display ywave_sfFFT vs xwave_sfFFT
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 PlotSmearedSphereFFT(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_sfFFT = {1.,60.,1e-6,6.3e-6,0.01}
49        make/o/t smear_parameters_sfFFT = {"scale","radius (A)","SLD Sphere (A^-2)","SLD solvent (A^-2)","incoh. bkg (cm^-1)"}
50        Edit smear_parameters_sfFFT,smear_coef_sfFFT
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_sfFFT,smeared_qvals
55        SetScale d,0,0,"1/cm",smeared_sfFFT
56
57        Variable/G gs_sfFFT=0
58        gs_sfFFT := fSmearedSphereFFT(smear_coef_sfFFT,smeared_sfFFT,smeared_qvals)     //this wrapper fills the STRUCT
59
60        Display smeared_sfFFT 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 SphereFFT(cw,yw,xw) : FitFunc
75        Wave cw,yw,xw
76
77//      Variable t1=StopMSTimer(-2)
78
79//The input variables are (and output)
80        //[0] scale
81        //[1] Sphere RADIUS (A)
82        //[2] total Sphere LENGTH (A)
83        //[3] sld Sphere (A^-2)
84        //[4] sld solvent
85        //[5] background (cm^-1)
86        Variable scale, radius,bkg,sldSph,sldSolv,ctr,fill,err
87        scale = cw[0]
88        radius = cw[1]
89        sldSph = cw[2]
90        sldSolv = cw[3]
91        bkg = cw[4]
92
93
94// make sure all of the globals are set correctly
95        NVAR grid = root:FFT_T
96        NVAR FFT_N = root:FFT_N
97        NVAR FFT_SolventSLD = root:FFT_SolventSLD
98
99        FFT_SolventSLD = trunc(sldSolv*1e6)             //spits back an integer, maybe not correct
100
101// generate the matrix and erase it
102//      FFT_MakeMatrixButtonProc("")
103        FFTEraseMatrixButtonProc("")
104        Wave m=root:mat
105
106// fill the matrix with solvent
107        FFTFillSolventMatrixProc("")
108
109// with the input parameters, build the structure
110        ctr = trunc(FFT_N/2)
111        fill = trunc(sldSph*1e6)
112
114
115// set up for the calculation
116
117
118// do the calculation (use the binned if only one SLD, or bin+SLD if themodel requires this)
119        fDoCalc(xw,yw,grid,2,0)         // ,2,0) = the binned calculation, quiet
120
121// reset the volume fraction to get the proper scaling
122// the calculation is normalized to the volume fraction of spheres filling the matrix
123        Variable frac
124        frac = VolumeFraction_Occ(m)
125
126        yw /= frac
127        yw *= scale
128        yw += bkg
129
130//      Print "elapsed time = ",(StopMSTimer(-2) - t1)/1e6
131
132        return(0)
133End
134
135
136//
137// this is all there is to the smeared calculation!
138Function SmearedSphereFFT(s) :FitFunc
139        Struct ResSmearAAOStruct &s
140
141////the name of your unsmeared model is the first argument
142        Smear_Model_20(SphereFFT,s.coefW,s.xW,s.yW,s.resW)
143
144        return(0)
145End
146//
147//
148////wrapper to calculate the smeared model as an AAO-Struct
149//// fills the struct and calls the ususal function with the STRUCT parameter
150////
151//// used only for the dependency, not for fitting
152////
153Function fSmearedSphereFFT(coefW,yW,xW)
154        Wave coefW,yW,xW
155
156        String str = getWavesDataFolder(yW,0)
157        String DF="root:"+str+":"
158
159        WAVE resW = \$(DF+str+"_res")
160
161        STRUCT ResSmearAAOStruct fs
162        WAVE fs.coefW = coefW
163        WAVE fs.yW = yW
164        WAVE fs.xW = xW
165        WAVE fs.resW = resW
166
167        Variable err
168        err = SmearedSphereFFT(fs)
169
170        return (0)
171End
Note: See TracBrowser for help on using the repository browser.