1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma IgorVersion=6.1 |
---|
3 | |
---|
4 | |
---|
5 | //////////////////////////////////////////////// |
---|
6 | // this procedure is for the Teubner-Strey Model |
---|
7 | // |
---|
8 | // 06 NOV 98 SRK |
---|
9 | // |
---|
10 | // JAN 2014 - SRK |
---|
11 | // |
---|
12 | // Changed the input parameters to be the length scales rather than a2, c1, c2 |
---|
13 | // which have no physical meaning. |
---|
14 | //////////////////////////////////////////////// |
---|
15 | |
---|
16 | Proc PlotTeubnerStreyModel(num,qmin,qmax) |
---|
17 | Variable num=128,qmin=0.001,qmax=0.7 |
---|
18 | Prompt num "Enter number of data points for model: " |
---|
19 | Prompt qmin "Enter minimum q-value (A^-1) for model: " |
---|
20 | Prompt qmax "Enter maximum q-value (A^-1) for model: " |
---|
21 | |
---|
22 | Make/O/D/n=(num) xwave_ts,ywave_ts |
---|
23 | xwave_ts = alog(log(qmin) + x*((log(qmax)-log(qmin))/num)) |
---|
24 | // Make/O/D coef_ts = {0.1,-30,5000,0.1} |
---|
25 | // make/o/t parameters_ts = {"scale (a2)","c1","c2","bkg"} |
---|
26 | |
---|
27 | Make/O/D coef_ts = {0.3,6e-6,30,100,0.1} |
---|
28 | make/o/t parameters_ts = {"scale","SLD difference (A^-2)","correlation length (xi) (A)","repeat distance, d, (A)","bkg (1/cm)"} |
---|
29 | |
---|
30 | Edit parameters_ts,coef_ts |
---|
31 | Variable/G root:g_ts |
---|
32 | g_ts := TeubnerStreyModel(coef_ts,ywave_ts,xwave_ts) |
---|
33 | // ywave_ts := TeubnerStreyModel(coef_ts,xwave_ts) |
---|
34 | Display ywave_ts vs xwave_ts |
---|
35 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
36 | Label bottom "q (A\\S-1\\M)" |
---|
37 | Label left "Intensity (cm\\S-1\\M)" |
---|
38 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
39 | |
---|
40 | AddModelToStrings("TeubnerStreyModel","coef_ts","parameters_ts","ts") |
---|
41 | End |
---|
42 | |
---|
43 | /////////////////////////////////////////////////////////// |
---|
44 | |
---|
45 | // - sets up a dependency to a wrapper, not the actual SmearedModelFunction |
---|
46 | Proc PlotSmearedTeubnerStreyModel(str) |
---|
47 | String str |
---|
48 | Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4) |
---|
49 | |
---|
50 | // if any of the resolution waves are missing => abort |
---|
51 | if(ResolutionWavesMissingDF(str)) //updated to NOT use global strings (in GaussUtils) |
---|
52 | Abort |
---|
53 | endif |
---|
54 | |
---|
55 | SetDataFolder $("root:"+str) |
---|
56 | |
---|
57 | // Setup parameter table for model function |
---|
58 | Make/O/D smear_coef_ts = {0.3,6e-6,30,100,0.1} |
---|
59 | make/o/t smear_parameters_ts = {"scale","SLD difference (A^-2)","correlation length (xi) (A)","repeat distance, d, (A)","bkg (1/cm)"} |
---|
60 | Edit smear_parameters_ts,smear_coef_ts |
---|
61 | |
---|
62 | // output smeared intensity wave, dimensions are identical to experimental QSIG values |
---|
63 | // make extra copy of experimental q-values for easy plotting |
---|
64 | Duplicate/O $(str+"_q") smeared_ts,smeared_qvals |
---|
65 | SetScale d,0,0,"1/cm",smeared_ts |
---|
66 | |
---|
67 | Variable/G gs_ts=0 |
---|
68 | gs_ts := fSmearedTeubnerStreyModel(smear_coef_ts,smeared_ts,smeared_qvals) //this wrapper fills the STRUCT |
---|
69 | |
---|
70 | Display smeared_ts vs smeared_qvals |
---|
71 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
72 | Label bottom "q (A\\S-1\\M)" |
---|
73 | Label left "Intensity (cm\\S-1\\M)" |
---|
74 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
75 | |
---|
76 | SetDataFolder root: |
---|
77 | AddModelToStrings("SmearedTeubnerStreyModel","smear_coef_ts","smear_parameters_ts","ts") |
---|
78 | End |
---|
79 | |
---|
80 | //AAO version |
---|
81 | Function TeubnerStreyModel(cw,yw,xw) : FitFunc |
---|
82 | Wave cw,yw,xw |
---|
83 | |
---|
84 | Variable a2, c1, c2 |
---|
85 | Variable d,xi,scale,delrho |
---|
86 | |
---|
87 | scale = cw[0] |
---|
88 | delrho = cw[1] |
---|
89 | xi = cw[2] |
---|
90 | d = cw[3] |
---|
91 | |
---|
92 | |
---|
93 | a2 = (1 + (2*pi*xi/d)^2)^2 |
---|
94 | c1 = -2*xi*xi*(2*pi*xi/d)^2+2*xi*xi |
---|
95 | c2 = xi^4 |
---|
96 | |
---|
97 | a2 /= 8*pi*xi^3*scale*delrho^2*1e8 //this makes the units work out |
---|
98 | c1 /= 8*pi*xi^3*scale*delrho^2*1e8 |
---|
99 | c2 /= 8*pi*xi^3*scale*delrho^2*1e8 |
---|
100 | |
---|
101 | // Print a2,c1,c2 |
---|
102 | |
---|
103 | Duplicate/O cw tmp_ts_cw |
---|
104 | tmp_ts_cw[0] = a2 |
---|
105 | tmp_ts_cw[1] = c1 |
---|
106 | tmp_ts_cw[2] = c2 |
---|
107 | tmp_ts_cw[3] = cw[4] |
---|
108 | |
---|
109 | #if exists("TeubnerStreyModelX") |
---|
110 | yw = TeubnerStreyModelX(tmp_ts_cw,xw) |
---|
111 | #else |
---|
112 | yw = fTeubnerStreyModel(tmp_ts_cw,xw) |
---|
113 | #endif |
---|
114 | return(0) |
---|
115 | End |
---|
116 | |
---|
117 | /////////////////////////////////////////////////////////////// |
---|
118 | // unsmeared model calculation |
---|
119 | /////////////////////////// |
---|
120 | Function fTeubnerStreyModel(w,x) : FitFunc |
---|
121 | Wave w;Variable x |
---|
122 | |
---|
123 | //Varialbes are: |
---|
124 | //[0] scale factor a2 |
---|
125 | //[1] coeff c1 |
---|
126 | //[2] coeff c2 |
---|
127 | //[3] incoh. background |
---|
128 | |
---|
129 | Variable inten,q2,q4 |
---|
130 | |
---|
131 | q2 = x*x |
---|
132 | q4 = q2*q2 |
---|
133 | inten = 1.0/(w[0]+w[1]*q2+w[2]*q4) |
---|
134 | inten += w[3] |
---|
135 | |
---|
136 | return (inten) |
---|
137 | |
---|
138 | End |
---|
139 | |
---|
140 | Macro TeubnerStreyLengths() |
---|
141 | If(exists("coef_ts")!=1) //coefficients don't exist |
---|
142 | Abort "You must plot the Teubner-Strey model before calculating the lengths" |
---|
143 | Endif |
---|
144 | // calculate the correlation length and the repeat distance |
---|
145 | // Variable a2,c1,c2,xi,dd,fa |
---|
146 | // a2 = coef_ts[0] |
---|
147 | // c1 = coef_ts[1] |
---|
148 | // c2 = coef_ts[2] |
---|
149 | // |
---|
150 | // xi = 0.5*sqrt(a2/c2) + c1/4/c2 |
---|
151 | // xi = 1/sqrt(xi) |
---|
152 | // |
---|
153 | // dd = 0.5*sqrt(a2/c2) - c1/4/c2 |
---|
154 | // dd = 1/sqrt(dd) |
---|
155 | // dd *=2*Pi |
---|
156 | // |
---|
157 | |
---|
158 | Variable a2, c1, c2 |
---|
159 | Variable d,xi,scale,delrho,fa |
---|
160 | xi = coef_ts[2] |
---|
161 | d = coef_ts[3] |
---|
162 | |
---|
163 | |
---|
164 | a2 = (1 + (2*pi*xi/d)^2)^2 |
---|
165 | c1 = -2*xi*xi*(2*pi*xi/d)^2+2*xi*xi |
---|
166 | c2 = xi^4 |
---|
167 | |
---|
168 | fa = c1/(sqrt(4*a2*c2)) |
---|
169 | |
---|
170 | Printf "The correlation length (the dispersion of d) xi = %g A\r",xi |
---|
171 | Printf "The quasi-periodic repeat distance, d = %g A\r",d |
---|
172 | Printf "The amphiphilicity factor, fa = %g\r",fa |
---|
173 | |
---|
174 | End |
---|
175 | |
---|
176 | // this is all there is to the smeared calculation! |
---|
177 | Function SmearedTeubnerStreyModel(s) :FitFunc |
---|
178 | Struct ResSmearAAOStruct &s |
---|
179 | |
---|
180 | ////the name of your unsmeared model is the first argument |
---|
181 | Smear_Model_20(TeubnerStreyModel,s.coefW,s.xW,s.yW,s.resW) |
---|
182 | |
---|
183 | return(0) |
---|
184 | End |
---|
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 | // |
---|
191 | Function fSmearedTeubnerStreyModel(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 = SmearedTeubnerStreyModel(fs) |
---|
207 | |
---|
208 | return (0) |
---|
209 | End |
---|