source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/PolyCore.ipf @ 145

Last change on this file since 145 was 131, checked in by srkline, 15 years ago

Typo in dialog in every model...

File size: 6.6 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 calculates the form factor for polydisperse spherical particles
10// the polydispersity is a Schulz distribution
11// the spherical particles have a core-shell structure, with a polydisperse core and constant
12// shell thickness
13//
14// 06 NOV 98 SRK
15////////////////////////////////////////////////
16
17Proc PlotPolyCoreForm(num,qmin,qmax)
18        Variable num=256,qmin=0.001,qmax=0.7
19        Prompt num "Enter number of data points for model: "
20        Prompt qmin "Enter minimum q-value (^-1) for model: "
21        Prompt qmax "Enter maximum q-value (^-1) for model: "
22       
23        Make/O/D/n=(num) xwave_pcf,ywave_pcf
24        //xwave_pcf = qmin + x*((qmax-qmin)/num)
25        xwave_pcf = alog( log(qmin) + x*((log(qmax)-log(qmin))/num) )
26        Make/O/D coef_pcf = {1.,60,.2,10,1e-6,2e-6,3e-6,0.001}
27        make/o/t parameters_pcf = {"scale","avg core rad (A)","core polydisp (0,1)","shell thickness (A)","SLD core (A-2)","SLD shell (A-2)","SLD solvent (A-2)","bkg (cm-1)"}
28        Edit parameters_pcf,coef_pcf
29        Variable/G root:g_pcf
30        g_pcf := PolyCoreForm(coef_pcf,ywave_pcf,xwave_pcf)
31//      ywave_pcf := PolyCoreForm(coef_pcf,xwave_pcf)
32        Display ywave_pcf vs xwave_pcf
33        ModifyGraph log=1,marker=29,msize=2,mode=4
34        Label bottom "q (\\S-1\\M)"
35        Label left "Intensity (cm\\S-1\\M)"
36        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
37End
38
39///////////////////////////////////////////////////////////
40// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
41Proc PlotSmearedPolyCoreForm(str)                                                               
42        String str
43        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
44       
45        // if any of the resolution waves are missing => abort
46        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
47                Abort
48        endif
49       
50        SetDataFolder $("root:"+str)
51       
52        // Setup parameter table for model function
53        Make/O/D smear_coef_pcf = {1.,60,.2,10,1e-6,2e-6,3e-6,0.001}
54        make/o/t smear_parameters_pcf = {"scale","avg core rad (A)","core polydisp (0,1)","shell thickness (A)","SLD core (A-2)","SLD shell (A-2)","SLD solvent (A-2)","bkg (cm-1)"}
55        Edit smear_parameters_pcf,smear_coef_pcf
56       
57        // output smeared intensity wave, dimensions are identical to experimental QSIG values
58        // make extra copy of experimental q-values for easy plotting
59        Duplicate/O $(str+"_q") smeared_pcf,smeared_qvals
60        SetScale d,0,0,"1/cm",smeared_pcf                                       
61               
62        Variable/G gs_pcf=0
63        gs_pcf := fSmearedPolyCoreForm(smear_coef_pcf,smeared_pcf,smeared_qvals)        //this wrapper fills the STRUCT
64
65        Display smeared_pcf vs smeared_qvals
66        ModifyGraph log=1,marker=29,msize=2,mode=4
67        Label bottom "q (\\S-1\\M)"
68        Label left "Intensity (cm\\S-1\\M)"
69        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) 
70       
71        SetDataFolder root:
72End
73
74
75//AAO verison
76Function PolyCoreForm(cw,yw,xw) : FitFunc
77        Wave cw,yw,xw
78
79#if exists("PolyCoreFormX")
80        yw = PolyCoreFormX(cw,xw)
81#else
82        yw = fPolyCoreForm(cw,xw)
83#endif
84        return(0)
85End
86
87///////////////////////////////////////////////////////////////
88// unsmeared model calculation
89///////////////////////////
90Function fPolyCoreForm(w,h) : FitFunc
91        Wave w
92        Variable h      // x is already used below
93
94//*             calculates <f^2> for a spherical core/shell */
95//*             geometry with a polydispersity of the core only */
96//*             The shell thickness is constant */
97//*     from  J. Chem. Phys. 96 (1992) 3306. */
98//*     beta factor is not calculated */
99
100// input parameters are
101        //[0] scale
102        //[1] average core radius       []
103        //[2] polydispersity of core (0<sig<1)
104        //[3] shell thickness   []
105        //[4] SLD core          [-2]
106        //[5] SLD shell
107        //[6] SLD solvent
108        //[7] background [cm-1]
109
110
111// OUTPUT <f^2>/Vavg IN [cm-1]
112       
113// names for inputs and returned value
114        Variable scale,corrad,sig,zz,del,drho1,drho2,form,bkg
115        scale = w[0]
116        corrad = w[1]
117        sig = w[2]
118        zz = (1/sig)^2 - 1
119        del = w[3]
120        drho1 = w[4]-w[5]               //core-shell
121        drho2 = w[5]-w[6]               //shell-solvent
122        bkg = w[7]
123       
124       
125   //* Local variables */
126    Variable d, g
127    Variable qq, x, y, c1, c2, c3, c4, c5, c6, c7, c8, c9, t1, t2, t3
128    Variable t4, t5, tb, cy, sy, tb1, tb2, tb3, c2y, zp1, zp2
129    Variable zp3,vpoly
130    Variable s2y, arg1, arg2, arg3, drh1, drh2
131
132
133//*    !!!!! drh NOW given in 1/A^2  */
134//*    core radius, del, and 1/q must be in Angstroms */
135
136    drh1 = drho1
137    drh2 = drho2
138    g = drh2 * -1. / drh1
139    zp1 = zz + 1.
140    zp2 = zz + 2.
141    zp3 = zz + 3.
142    vpoly = 4*Pi/3*zp3*zp2/zp1/zp1*(corrad+del)^3
143
144
145        qq = h  // remember that h is the passed in value of q for the calculation
146        y = h *del
147        x = h *corrad
148        d = atan(x * 2. / zp1)
149        arg1 = zp1 * d
150        arg2 = zp2 * d
151        arg3 = zp3 * d
152        sy = sin(y)
153        cy = cos(y)
154        s2y = sin(y * 2.)
155        c2y = cos(y * 2.)
156        c1 = .5 - g * (cy + y * sy) + g * g * .5 * (y * y + 1.)
157        c2 = g * y * (g - cy)
158        c3 = (g * g + 1.) * .5 - g * cy
159        c4 = g * g * (y * cy - sy) * (y * cy - sy) - c1
160        c5 = g * 2. * sy * (1. - g * (y * sy + cy)) + c2
161        c6 = c3 - g * g * sy * sy
162        c7 = g * sy - g * .5 * g * (y * y + 1.) * s2y - c5
163        c8 = c4 - .5 + g * cy - g * .5 * g * (y * y + 1.) * c2y
164        c9 = g * sy * (1. - g * cy)
165
166        tb = ln(zp1 * zp1 / (zp1 * zp1 + x * 4. * x))
167        tb1 = exp(zp1 * .5 * tb)
168        tb2 = exp(zp2 * .5 * tb)
169        tb3 = exp(zp3 * .5 * tb)
170
171        t1 = c1 + c2 * x + c3 * x * x * zp2 / zp1
172        t2 = tb1 * (c4 * cos(arg1) + c7 * sin(arg1))
173        t3 = x * tb2 * (c5 * cos(arg2) + c8 * sin(arg2))
174        t4 = zp2 / zp1 * x * x * tb3 * (c6 * cos(arg3) + c9 * sin(arg3))
175        t5 = t1 + t2 + t3 + t4
176        form = t5 * 16. * pi * pi * drh1 * drh1 / (qq^6)
177//      normalize by the average volume !!! corrected for polydispersity
178// and convert to cm-1
179        form /= vpoly
180        form *= 1.0e8
181        //Scale
182        form *= scale
183        // then add in the background
184        form += bkg
185       
186  return (form)
187
188End // end of polyCoreform
189
190// this is all there is to the smeared calculation!
191Function SmearedPolyCoreForm(s) :FitFunc
192        Struct ResSmearAAOStruct &s
193
194////the name of your unsmeared model is the first argument
195        s.yW = Smear_Model_20(PolyCoreForm,s.coefW,s.xW,s.resW)
196
197        return(0)
198End
199
200//wrapper to calculate the smeared model as an AAO-Struct
201// fills the struct and calls the ususal function with the STRUCT parameter
202//
203// used only for the dependency, not for fitting
204//
205Function fSmearedPolyCoreForm(coefW,yW,xW)
206        Wave coefW,yW,xW
207       
208        String str = getWavesDataFolder(yW,0)
209        String DF="root:"+str+":"
210       
211        WAVE resW = $(DF+str+"_res")
212       
213        STRUCT ResSmearAAOStruct fs
214        WAVE fs.coefW = coefW   
215        WAVE fs.yW = yW
216        WAVE fs.xW = xW
217        WAVE fs.resW = resW
218       
219        Variable err
220        err = SmearedPolyCoreForm(fs)
221       
222        return (0)
223End
Note: See TracBrowser for help on using the repository browser.