source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/NewModels_2008/PolyGaussShell_v40.ipf @ 445

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

Adding a pile of new model functions. Some are from Boualem, some old code from Danilo, some from me.

As far as I can tell, these replicate the original references (not the empirical models).

Help file and XOPs have net been done yet.

File size: 6.5 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.0
3
4////////////////////////////////////////////////////
5// calculates the scattering from a polydisperse spherical shell with a diffuse interface
6//
7// - the radius of the shell has a gaussian polydispersity
8// - the shell has a Gaussian SLD profile, rather than a slab
9// - currently normalized by the total sphere excluded volume
10//
11// M. Gradzielski, D. Langevin, L. Magid, R. Strey, JPC 99 (1995) 13232
12//
13// keep polydispersity < 0.35 for approximations to be valid
14//
15////////////////////////////////////////////////////
16
17//
18Proc PlotGaussianShell(num,qmin,qmax)
19        Variable num=200, qmin=0.001, qmax=0.7
20        Prompt num "Enter number of data points for model: "
21        Prompt qmin "Enter minimum q-value (^-1) for model: "
22        Prompt qmax "Enter maximum q-value (^-1) for model: "
23//
24        Make/O/D/n=(num) xwave_GaussianShell, ywave_GaussianShell
25        xwave_GaussianShell =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
26        Make/O/D coef_GaussianShell = {1.,100,5,0.2,1e-6,6.34e-6,0}             
27        make/o/t parameters_GaussianShell = {"scale","Radius (A)","Shell thickness Std. Dev. (A)","radius polydispersity","SLD Shell (A-2)","SLD solvent (A-2)","bkgd (cm-1)"}
28        Edit parameters_GaussianShell, coef_GaussianShell
29       
30        Variable/G root:g_GaussianShell
31        g_GaussianShell := GaussianShell(coef_GaussianShell, ywave_GaussianShell, xwave_GaussianShell)
32        Display ywave_GaussianShell vs xwave_GaussianShell
33        ModifyGraph marker=29, msize=2, mode=4
34        ModifyGraph log=1,grid=1,mirror=2
35        Label bottom "q (\\S-1\\M) "
36        Label left "I(q) (cm\\S-1\\M)"
37        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
38       
39        AddModelToStrings("GaussianShell","coef_GaussianShell","GaussianShell")
40//
41End
42
43
44//
45//no input parameters are necessary, it MUST use the experimental q-values
46// from the experimental data read in from an AVE/QSIG data file
47////////////////////////////////////////////////////
48// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
49Proc PlotSmearedGaussianShell(str)                                                             
50        String str
51        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
52       
53        // if any of the resolution waves are missing => abort
54        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
55                Abort
56        endif
57       
58        SetDataFolder $("root:"+str)
59       
60        // Setup parameter table for model function
61        Make/O/D smear_coef_GaussianShell = {1.,100,5,0.2,1e-6,6.34e-6,0}               
62        make/o/t smear_parameters_GaussianShell = {"scale","Radius (A)","Shell thickness Std. Dev. (A)","radius polydispersity","SLD Shell (A-2)","SLD solvent (A-2)","bkgd (cm-1)"}
63        Edit smear_parameters_GaussianShell,smear_coef_GaussianShell                                    //display parameters in a table
64       
65        // output smeared intensity wave, dimensions are identical to experimental QSIG values
66        // make extra copy of experimental q-values for easy plotting
67        Duplicate/O $(str+"_q") smeared_GaussianShell,smeared_qvals
68        SetScale d,0,0,"1/cm",smeared_GaussianShell
69                                       
70        Variable/G gs_GaussianShell=0
71        gs_GaussianShell := fSmearedGaussianShell(smear_coef_GaussianShell,smeared_GaussianShell,smeared_qvals) //this wrapper fills the STRUCT
72       
73        Display smeared_GaussianShell vs smeared_qvals
74        ModifyGraph log=1,marker=29,msize=2,mode=4
75        Label bottom "q (\\S-1\\M)"
76        Label left "I(q) (cm\\S-1\\M)"
77        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
78       
79        SetDataFolder root:
80        AddModelToStrings("SmearedGaussianShell","smear_coef_GaussianShell","GaussianShell")
81End
82
83
84//
85//AAO version, uses XOP if available
86// simply calls the original single point calculation with
87// a wave assignment (this will behave nicely if given point ranges)
88Function GaussianShell(cw,yw,xw) : FitFunc
89        Wave cw,yw,xw
90       
91#if exists("GaussianShellX")
92        yw = GaussianShellX(cw,xw)
93#else
94        yw = fGaussianShell(cw,xw)
95#endif
96        return(0)
97End
98
99//
100// unsmeared model calculation
101//
102Function fGaussianShell(w,x) : FitFunc
103        Wave w
104        Variable x
105       
106        // variables are:                                                       
107        //[0] scale
108        //[1] radius ()
109        //[2] thick () (thickness parameter - this is the std. dev. of the Gaussian width of the shell)
110        //[3] polydispersity of the radius
111        //[4] sld shell (-2)
112        //[5] sld solvent
113        //[6] background (cm-1)
114       
115        Variable scale,rad,delrho,bkg,del,thick,pd,sig,zf
116        Variable t1,t2,t3,t4,retval,exfact,vshell,vexcl,sldShell,sldSolvent
117        scale = w[0]
118        rad = w[1]
119        thick = w[2]
120        pd = w[3]
121        sldShell = w[4]
122        sldSolvent = w[5]
123        bkg = w[6]
124       
125        delrho = w[4] - w[5]
126        sig = pd*rad
127       
128        ///APPROXIMATION (see eqn 4 - but not a bad approximation)
129        // del is the equivalent shell thickness with sharp boundaries, centered at mean radius
130        del = thick*sqrt(2*pi)
131       
132        // calculate the polydisperse shell volume and the excluded volume
133        vshell=4*pi/3*( (rad+del/2)^3 - (rad-del/2)^3 ) *(1+pd^2)
134        vexcl=4*pi/3*( (rad+del/2)^3 ) *(1+pd^2)
135       
136        //intensity, eqn 9(a-d)
137        exfact = exp(-2*sig^2*x^2)
138       
139        t1 = 0.5*x^2*thick^4*(1+cos(2*x*rad)*exfact)
140        t2 = x*thick^2*(rad*sin(2*x*rad) + 2*x*sig^2*cos(2*x*rad))*exfact
141        t3 = 0.5*rad^2*(1-cos(2*x*rad)*exfact)
142        t4 = 0.5*sig^2*(1+4*x*rad*sin(2*x*rad)*exfact+cos(2*x*rad)*(4*sig^2*x^2-1)*exfact)
143       
144        retval = t1+t2+t3+t4
145        retval *= exp(-1*x*x*thick*thick)
146        retval *= (del*del/x/x)
147        retval *= 16*pi*pi*delrho*delrho*scale
148        retval *= 1e8
149       
150        //NORMALIZED by the AVERAGE shell volume, since scale is the volume fraction of material
151//      retval /= vshell
152        retval /= vexcl
153        //re-normalize by polydisperse sphere volume, Gaussian distribution
154        retval /= (1+3*pd^2)
155       
156        retval += bkg
157       
158        return(retval)
159       
160End
161
162//CH#4 
163///////////////////////////////////////////////////////////////
164// smeared model calculation
165//
166// you don't need to do anything with this function, as long as
167// your GaussianShell works correctly, you get the resolution-smeared
168// version for free.
169//
170// this is all there is to the smeared model calculation!
171Function SmearedGaussianShell(s) : FitFunc
172        Struct ResSmearAAOStruct &s
173
174//      the name of your unsmeared model (AAO) is the first argument
175        Smear_Model_20(GaussianShell,s.coefW,s.xW,s.yW,s.resW)
176
177        return(0)
178End
179
180
181///////////////////////////////////////////////////////////////
182
183
184// nothing to change here
185//
186//wrapper to calculate the smeared model as an AAO-Struct
187// fills the struct and calls the ususal function with the STRUCT parameter
188//
189// used only for the dependency, not for fitting
190//
191Function fSmearedGaussianShell(coefW,yW,xW)
192        Wave coefW,yW,xW
193       
194        String str = getWavesDataFolder(yW,0)
195        String DF="root:"+str+":"
196       
197        WAVE resW = $(DF+str+"_res")
198       
199        STRUCT ResSmearAAOStruct fs
200        WAVE fs.coefW = coefW   
201        WAVE fs.yW = yW
202        WAVE fs.xW = xW
203        WAVE fs.resW = resW
204       
205        Variable err
206        err = SmearedGaussianShell(fs)
207       
208        return (0)
209End
Note: See TracBrowser for help on using the repository browser.