source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Alpha/Tinker/FFT_Fit_Sphere.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: 5.1 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       
31        AddModelToStrings("SphereFFT","coef_sfFFT","parameters_sfFFT","sfFFT")
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:
67        AddModelToStrings("SmearedSphereFFT","smear_coef_sfFFT","smear_parameters_sfFFT","sfFFT")
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        NVAR FFT_delRho = root:FFT_delRho               //the SLD multiplier, should have been initialized to 1e-7
99       
100        FFT_SolventSLD = trunc(sldSolv/FFT_delRho)              //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        fill = trunc(sldSph/FFT_delRho)
113       
114        err = FillSphereRadiusNoOverlap(m,grid,radius,ctr,ctr,ctr,fill)
115
116// set up for the calculation
117
118
119// do the calculation (use the binned if only one SLD, or bin+SLD if themodel requires this)
120        fDoCalc(xw,yw,grid,2,0)         // ,2,0) = the binned calculation, quiet
121
122// reset the volume fraction to get the proper scaling
123// the calculation is normalized to the volume fraction of spheres filling the matrix
124        Variable frac
125        frac = VolumeFraction_Occ(m)
126
127        yw /= frac
128        yw *= scale
129        yw += bkg
130
131//      Print "elapsed time = ",(StopMSTimer(-2) - t1)/1e6
132
133        return(0)
134End
135
136
137//
138// this is all there is to the smeared calculation!
139Function SmearedSphereFFT(s) :FitFunc
140        Struct ResSmearAAOStruct &s
141
142////the name of your unsmeared model is the first argument
143        Smear_Model_20(SphereFFT,s.coefW,s.xW,s.yW,s.resW)
144
145        return(0)
146End
147//
148//
149////wrapper to calculate the smeared model as an AAO-Struct
150//// fills the struct and calls the ususal function with the STRUCT parameter
151////
152//// used only for the dependency, not for fitting
153////
154Function fSmearedSphereFFT(coefW,yW,xW)
155        Wave coefW,yW,xW
156       
157        String str = getWavesDataFolder(yW,0)
158        String DF="root:"+str+":"
159       
160        WAVE resW = $(DF+str+"_res")
161       
162        STRUCT ResSmearAAOStruct fs
163        WAVE fs.coefW = coefW   
164        WAVE fs.yW = yW
165        WAVE fs.xW = xW
166        WAVE fs.resW = resW
167       
168        Variable err
169        err = SmearedSphereFFT(fs)
170       
171        return (0)
172End
Note: See TracBrowser for help on using the repository browser.