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