source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Alpha/Tinker/FFT_Fit_Cylinder.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.2 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 PlotCylinderFFT(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_cylFFT,ywave_cylFFT
18        xwave_cylFFT =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
19        make/o/D coef_cylFFT = {1.,20.,400,1e-6,6.3e-6,0.01}
20        make/o/t parameters_cylFFT = {"scale","radius (A)","length (A)","SLD cylinder (A^-2)","SLD solvent (A^-2)","incoh. bkg (cm^-1)"}
21        Edit parameters_cylFFT,coef_cylFFT
22        Variable/G root:g_cylFFT
23        g_cylFFT := CylinderFFT(coef_cylFFT,ywave_cylFFT,xwave_cylFFT)
24
25        Display ywave_cylFFT vs xwave_cylFFT
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("CylinderFFT","coef_cylFFT","parameters_cylFFT","cylFFT")
32End
33
34/////////////////////////////////////////////////////////////
35//// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
36Proc PlotSmearedCylinderFFT(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_cylFFT = {1.,20.,400,1e-6,6.3e-6,0.01}
49        make/o/t smear_parameters_cylFFT = {"scale","radius (A)","length (A)","SLD cylinder (A^-2)","SLD solvent (A^-2)","incoh. bkg (cm^-1)"}
50        Edit smear_parameters_cylFFT,smear_coef_cylFFT
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_cylFFT,smeared_qvals
55        SetScale d,0,0,"1/cm",smeared_cylFFT   
56                                       
57        Variable/G gs_cylFFT=0
58        gs_cylFFT := fSmearedCylinderFFT(smear_coef_cylFFT,smeared_cylFFT,smeared_qvals)        //this wrapper fills the STRUCT
59       
60        Display smeared_cylFFT 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("SmearedCylinderFFT","smear_coef_cylFFT","smear_parameters_cylFFT","cylFFT")
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 CylinderFFT(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] cylinder RADIUS (A)
82        //[2] total cylinder LENGTH (A)
83        //[3] sld cylinder (A^-2)
84        //[4] sld solvent
85        //[5] background (cm^-1)
86        Variable scale, radius,length,delrho,bkg,sldCyl,sldSolv,ctr,fill
87        scale = cw[0]
88        radius = cw[1]
89        length = cw[2]
90        sldCyl = cw[3]
91        sldSolv = cw[4]
92        bkg = cw[5]
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        FFT_SolventSLD = trunc(sldSolv/FFT_delRho)              //spits back an integer, maybe not correct
102
103// generate the matrix and erase it
104//      FFT_MakeMatrixButtonProc("")
105        FFTEraseMatrixButtonProc("")
106        Wave m=root:mat
107
108// fill the matrix with solvent
109        FFTFillSolventMatrixProc("")
110
111// with the input parameters, build the structure
112        ctr = trunc(FFT_N/2)
113        fill = trunc(sldCyl/FFT_delRho)
114       
115        FillXCylinder(m,FFT_T,radius,ctr,ctr,ctr,length,fill)
116
117// set up for the calculation
118
119
120// do the calculation (use the binned if only one SLD, or bin+SLD if the model requires this)
121        fDoCalc(xw,yw,FFT_T,2,0)                //the binned calculation
122
123// reset the volume fraction to get the proper scaling
124// the calculation is normalized to the volume fraction of spheres filling the matrix
125        Variable frac
126        frac = VolumeFraction_Occ(m)
127
128        yw /= frac
129        yw *= scale
130        yw += bkg
131
132//      Print "elapsed time = ",(StopMSTimer(-2) - t1)/1e6
133
134        return(0)
135End
136
137
138//
139//// this is all there is to the smeared calculation!
140Function SmearedCylinderFFT(s) :FitFunc
141        Struct ResSmearAAOStruct &s
142
143////the name of your unsmeared model is the first argument
144        Smear_Model_20(CylinderFFT,s.coefW,s.xW,s.yW,s.resW)
145
146        return(0)
147End
148//
149//
150////wrapper to calculate the smeared model as an AAO-Struct
151//// fills the struct and calls the ususal function with the STRUCT parameter
152////
153//// used only for the dependency, not for fitting
154////
155Function fSmearedCylinderFFT(coefW,yW,xW)
156        Wave coefW,yW,xW
157       
158        String str = getWavesDataFolder(yW,0)
159        String DF="root:"+str+":"
160       
161        WAVE resW = $(DF+str+"_res")
162       
163        STRUCT ResSmearAAOStruct fs
164        WAVE fs.coefW = coefW   
165        WAVE fs.yW = yW
166        WAVE fs.xW = xW
167        WAVE fs.resW = resW
168       
169        Variable err
170        err = SmearedCylinderFFT(fs)
171       
172        return (0)
173End
Note: See TracBrowser for help on using the repository browser.