source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/CoreShell_v40.ipf @ 510

Last change on this file since 510 was 510, checked in by srkline, 14 years ago

Simple change in all of the model function files to include the name of the parameter wave in the Keyword=list that is generated when a model is plotted. This is becoming an issue where the proper parameter wave can't be deduced from just the suffix, then there is nothing to put in the table.

I should have added this when I initially wrote the wrapper...

File size: 5.1 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion = 6.0
3
4////////////////////////////////////////////////
5// GaussUtils.proc and PlotUtils.proc MUST be included for the smearing calculation to compile
6// Adopting these into the experiment will insure that they are always present
7////////////////////////////////////////////////
8//
9// this function is for the form factor of a sphere with a core-shell structure
10//
11// 06 NOV 98 SRK
12////////////////////////////////////////////////
13
14Proc PlotCoreShellSphere(num,qmin,qmax)
15        Variable num=128,qmin=0.001,qmax=0.7
16        Prompt num "Enter number of data points for model: "
17        Prompt qmin "Enter minimum q-value (A^-1) for model: "
18        Prompt qmax "Enter maximum q-value (A^-1) for model: "
19       
20        make/o/d/n=(num) xwave_css,ywave_css
21        xwave_css =alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
22        make/o/d coef_css = {1.,60,10,1e-6,2e-6,3e-6,0.001}
23        make/o/t parameters_css = {"scale","core radius (A)","shell thickness (A)","Core SLD (A-2)","Shell SLD (A-2)","Solvent SLD (A-2)","bkg (cm-1)"}
24        Edit parameters_css,coef_css
25        Variable/G root:g_css
26        g_css := CoreShellSphere(coef_css,ywave_css,xwave_css)
27//      ywave_css := CoreShellSphere(coef_css,xwave_css)
28        Display ywave_css vs xwave_css
29        ModifyGraph log=1,marker=29,msize=2,mode=4
30        Label bottom "q (A\\S-1\\M)"
31        Label left "Intensity (cm\\S-1\\M)"
32        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
33       
34        AddModelToStrings("CoreShellSphere","coef_css","parameters_css","css")
35End
36
37///////////////////////////////////////////////////////////
38// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
39Proc PlotSmearedCoreShellSphere(str)                                                           
40        String str
41        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
42       
43        // if any of the resolution waves are missing => abort
44        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
45                Abort
46        endif
47       
48        SetDataFolder $("root:"+str)
49       
50        // Setup parameter table for model function
51        make/o/d smear_coef_css = {1.,60,10,1e-6,2e-6,3e-6,0.001}
52        make/o/t smear_parameters_css = {"scale","core radius (A)","shell thickness (A)","Core SLD (A-2)","Shell SLD (A-2)","Solvent SLD (A-2)","bkg (cm-1)"}
53        Edit smear_parameters_css,smear_coef_css
54       
55        // output smeared intensity wave, dimensions are identical to experimental QSIG values
56        // make extra copy of experimental q-values for easy plotting
57       
58        Duplicate/O $(str+"_q") smeared_css,smeared_qvals                               
59        SetScale d,0,0,"1/cm",smeared_css                                                       
60                                       
61        Variable/G gs_css=0
62        gs_css := fSmearedCoreShellSphere(smear_coef_css,smeared_css,smeared_qvals)     //this wrapper fills the STRUCT
63       
64        Display smeared_css vs smeared_qvals                                                                   
65        ModifyGraph log=1,marker=29,msize=2,mode=4
66        Label bottom "q (A\\S-1\\M)"
67        Label left "Intensity (cm\\S-1\\M)"
68        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
69       
70        SetDataFolder root:
71        AddModelToStrings("SmearedCoreShellSphere","smear_coef_css","smear_parameters_css","css")
72End
73
74
75//AAO version
76Function CoreShellSphere(cw,yw,xw) : FitFunc
77        Wave cw,yw,xw
78
79#if exists("CoreShellSphereX")
80        yw = CoreShellSphereX(cw,xw)
81#else
82        yw = fCoreShellSphere(cw,xw)
83#endif
84        return(0)
85End
86
87///////////////////////////////////////////////////////////////
88// unsmeared model calculation
89///////////////////////////
90Function fCoreShellSphere(w,x) : FitFunc
91        Wave w
92        Variable x
93       
94        // variables are:
95        //[0] scale factor
96        //[1] radius of core [A]
97        //[2] thickness of the shell    [A]
98        //[3] SLD of the core   [A-2]
99        //[4] SLD of the shell
100        //[5] SLD of the solvent
101        //[6] background        [cm-1]
102       
103        // All inputs are in ANGSTROMS
104        //OUTPUT is normalized by the particle volume, and converted to [cm-1]
105       
106       
107        Variable scale,rcore,thick,rhocore,rhoshel,rhosolv,bkg
108        scale = w[0]
109        rcore = w[1]
110        thick = w[2]
111        rhocore = w[3]
112        rhoshel = w[4]
113        rhosolv = w[5]
114        bkg = w[6]
115       
116        // calculates scale *( f^2 + bkg)
117        Variable bes,f,vol,qr,contr,f2
118       
119        // core first, then add in shell
120        qr=x*rcore
121        contr = rhocore-rhoshel
122        bes = 3*(sin(qr)-qr*cos(qr))/qr^3
123        vol = 4*pi/3*rcore^3
124        f = vol*bes*contr
125        //now the shell
126        qr=x*(rcore+thick)
127        contr = rhoshel-rhosolv
128        bes = 3*(sin(qr)-qr*cos(qr))/qr^3
129        vol = 4*pi/3*(rcore+thick)^3
130        f += vol*bes*contr
131       
132        // normalize to particle volume and rescale from [A-1] to [cm-1]
133        f2 = f*f/vol*1.0e8
134       
135        //scale if desired
136        f2 *= scale
137        // then add in the background
138        f2 += bkg
139       
140        return (f2)
141End
142
143// this is all there is to the smeared calculation!
144Function SmearedCoreShellSphere(s) :FitFunc
145        Struct ResSmearAAOStruct &s
146
147////the name of your unsmeared model is the first argument
148        Smear_Model_20(CoreShellSphere,s.coefW,s.xW,s.yW,s.resW)
149
150        return(0)
151End
152
153//wrapper to calculate the smeared model as an AAO-Struct
154// fills the struct and calls the ususal function with the STRUCT parameter
155//
156// used only for the dependency, not for fitting
157//
158Function fSmearedCoreShellSphere(coefW,yW,xW)
159        Wave coefW,yW,xW
160       
161        String str = getWavesDataFolder(yW,0)
162        String DF="root:"+str+":"
163       
164        WAVE resW = $(DF+str+"_res")
165       
166        STRUCT ResSmearAAOStruct fs
167        WAVE fs.coefW = coefW   
168        WAVE fs.yW = yW
169        WAVE fs.xW = xW
170        WAVE fs.resW = resW
171       
172        Variable err
173        err = SmearedCoreShellSphere(fs)
174       
175        return (0)
176End
Note: See TracBrowser for help on using the repository browser.