source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Alpha/Tinker/FFT_Fit_Cylinder.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.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 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       
100        FFT_SolventSLD = trunc(sldSolv*1e6)             //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(sldCyl*1e6)
113       
114        FillXCylinder(m,FFT_T,radius,ctr,ctr,ctr,length,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 the model requires this)
120        fDoCalc(xw,yw,FFT_T,2,0)                //the binned calculation
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 SmearedCylinderFFT(s) :FitFunc
140        Struct ResSmearAAOStruct &s
141
142////the name of your unsmeared model is the first argument
143        Smear_Model_20(CylinderFFT,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 fSmearedCylinderFFT(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 = SmearedCylinderFFT(fs)
170       
171        return (0)
172End
Note: See TracBrowser for help on using the repository browser.