1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma IgorVersion = 6.0 |
---|
3 | |
---|
4 | //////////////////////////////////////////////////// |
---|
5 | // |
---|
6 | // model function that calculates the scattering from |
---|
7 | // lamellar surfactant structures. contrast includes the |
---|
8 | // bilayer core, headgroups, and solvent. Integer numbers of |
---|
9 | // repeating bilayers (at a repeat spacing) leads to the |
---|
10 | // familiar lamellar peaks. Bending constant information |
---|
11 | // can be extracted from the Caille parameter with moderate |
---|
12 | // success. A number of the parameters should be held |
---|
13 | // fixed during the fitting procedure, as they should be well |
---|
14 | // known: |
---|
15 | // repeat spacing D = 2*pi/Qo |
---|
16 | // contrast = calculated value |
---|
17 | // polydispersity should be close to 0.1-0.3 |
---|
18 | // Caille parameter <0.8 or 1.0 |
---|
19 | // |
---|
20 | // NOTES for Curve Fitting: |
---|
21 | // the epsilon wave "epsilon_LamellarPS_HG" should be used to force a |
---|
22 | // larger derivative step for the # of repeat units, which is an integer. |
---|
23 | // a singular matix error will always result if you don't follow this. |
---|
24 | // Also, the # of repeats should be constrained to ~3<N<200, otherwise |
---|
25 | // the optimization can pick a VERY large N, and waste lots of time |
---|
26 | // in the summation loop |
---|
27 | // |
---|
28 | // instrumental resolution is taken into account in the REGULAR |
---|
29 | // model calculation. resolution of ONLY the S(Q) peaks are |
---|
30 | // included. performing the typical smearing calculation would |
---|
31 | // be "double smearing", so is not done. |
---|
32 | // |
---|
33 | // the delta Q parameter "gDelQ" or "dQ" is taken from the q-dependent |
---|
34 | // instrument resolution "abssq" column as this is the identical definition |
---|
35 | // as in the original reference. If the real resolution function cannot be |
---|
36 | // found, a default value, typical of a "medium" q-range on the NG3 SANS is |
---|
37 | // used, although the real values are highly preferred |
---|
38 | // |
---|
39 | // REFERENCE: Nallet, Laversanne, and Roux, J. Phys. II France, 3, (1993) 487-502. |
---|
40 | // also in J. Phys. Chem. B, 105, (2001) 11081-11088. |
---|
41 | // |
---|
42 | // 14 JULY 2003 SRK |
---|
43 | // |
---|
44 | //////////////////////////////////////////////////// |
---|
45 | |
---|
46 | //this macro sets up all the necessary parameters and waves that are |
---|
47 | //needed to calculate the model function. |
---|
48 | // |
---|
49 | Proc PlotLamellarPS_HG(num,qmin,qmax) |
---|
50 | Variable num=128, qmin=.001, qmax=.5 |
---|
51 | Prompt num "Enter number of data points for model: " |
---|
52 | Prompt qmin "Enter minimum q-value (A^1) for model: " |
---|
53 | Prompt qmax "Enter maximum q-value (A^1) for model: " |
---|
54 | // |
---|
55 | // constants |
---|
56 | // Variable/G root:gEuler = 0.5772156649 // Euler's constant |
---|
57 | // Variable/G root:gDelQ = 0.0025 //[=] 1/A, q-resolution, default value |
---|
58 | |
---|
59 | Make/O/D/n=(num) xwave_LamellarPS_HG, ywave_LamellarPS_HG |
---|
60 | xwave_LamellarPS_HG = alog(log(qmin) + x*((log(qmax)-log(qmin))/num)) |
---|
61 | Make/O/D coef_LamellarPS_HG = {1,40,10,2,0.4e-6,2e-6,6e-6,30,0.001,0.001} //CH#2 |
---|
62 | make/o/t parameters_LamellarPS_HG = {"Scale","Lamellar spacing, D (A)","Tail Thick (delT) (A)","HG Thick (delH) (A)","SLD of tails (A^-2)","SLD of HG (A^-2)","SLD of solvent (A^-2)","# of Lamellar plates","Caille parameter","Incoherent Bgd (cm-1)"} //CH#3 |
---|
63 | Edit parameters_LamellarPS_HG, coef_LamellarPS_HG |
---|
64 | ModifyTable width(parameters_LamellarPS_HG)=160 |
---|
65 | |
---|
66 | Variable/G root:g_LamellarPS_HG |
---|
67 | g_LamellarPS_HG := LamellarPS_HG(coef_LamellarPS_HG, ywave_LamellarPS_HG,xwave_LamellarPS_HG) |
---|
68 | Display ywave_LamellarPS_HG vs xwave_LamellarPS_HG |
---|
69 | ModifyGraph marker=29, msize=2, mode=4 |
---|
70 | ModifyGraph log=1 |
---|
71 | Label bottom "q (A\\S-1\\M) " |
---|
72 | Label left "I(q) (cm\\S-1\\M)" |
---|
73 | // |
---|
74 | // make epsilon wave appropriate for integer number of lamellar repeats |
---|
75 | Duplicate/O coef_LamellarPS_HG epsilon_LamellarPS_HG |
---|
76 | epsilon_LamellarPS_HG = 1e-4 |
---|
77 | epsilon_LamellarPS_HG[7] = 1 //to make the derivative useful |
---|
78 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
79 | |
---|
80 | AddModelToStrings("LamellarPS_HG","coef_LamellarPS_HG","LamellarPS_HG") |
---|
81 | End |
---|
82 | |
---|
83 | // - sets up a dependency to a wrapper, not the actual SmearedModelFunction |
---|
84 | Proc PlotSmearedLamellarPS_HG(str) |
---|
85 | String str |
---|
86 | Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4) |
---|
87 | |
---|
88 | // if any of the resolution waves are missing => abort |
---|
89 | if(ResolutionWavesMissingDF(str)) //updated to NOT use global strings (in GaussUtils) |
---|
90 | Abort |
---|
91 | endif |
---|
92 | |
---|
93 | SetDataFolder $("root:"+str) |
---|
94 | |
---|
95 | // constants |
---|
96 | // Variable/G root:gEuler = 0.5772156649 // Euler's constant |
---|
97 | // Variable/G root:gDelQ = 0.0025 //[=] 1/A, q-resolution, default value |
---|
98 | // Setup parameter table for model function |
---|
99 | Make/O/D smear_coef_LamellarPS_HG = {1,40,10,2,0.4e-6,2e-6,6e-6,30,0.001,0.001} //CH#4 |
---|
100 | make/o/t smear_parameters_LamellarPS_HG = {"Scale","Lamellar spacing, D (A)","Tail Thick (delT) (A)","HG Thick (delH) (A)","SLD of tails (A^-2)","SLD of HG (A^-2)","SLD of solvent (A^-2)","# of Lamellar plates","Caille parameter","Incoherent Bgd (cm-1)"} |
---|
101 | Edit smear_parameters_LamellarPS_HG,smear_coef_LamellarPS_HG //display parameters in a table |
---|
102 | |
---|
103 | // output smeared intensity wave, dimensions are identical to experimental QSIG values |
---|
104 | // make extra copy of experimental q-values for easy plotting |
---|
105 | Duplicate/O $(str+"_q") smeared_LamellarPS_HG,smeared_qvals // |
---|
106 | SetScale d,0,0,"1/cm",smeared_LamellarPS_HG // |
---|
107 | |
---|
108 | Variable/G gs_LamellarPS_HG =0 |
---|
109 | gs_LamellarPS_HG := fSmearedLamellarPS_HG(smear_coef_LamellarPS_HG ,smeared_LamellarPS_HG ,smeared_qvals) //this wrapper fills the STRUCT |
---|
110 | |
---|
111 | Display smeared_LamellarPS_HG vs smeared_qvals // |
---|
112 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
113 | Label bottom "q (A\\S-1\\M)" |
---|
114 | Label left "I(q) (cm\\S-1\\M)" |
---|
115 | |
---|
116 | SetDataFolder root: |
---|
117 | AddModelToStrings("SmearedLamellarPS_HG","smear_coef_LamellarPS_HG","LamellarPS_HG") |
---|
118 | End |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | //AAO version, uses XOP if available |
---|
123 | // simply calls the original single point calculation with |
---|
124 | // a wave assignment (this will behave nicely if given point ranges) |
---|
125 | Function LamellarPS_HG(cw,yw,xw) : FitFunc |
---|
126 | Wave cw,yw,xw |
---|
127 | |
---|
128 | #if exists("LamellarPS_HGX") |
---|
129 | yw = LamellarPS_HGX(cw,xw) |
---|
130 | #else |
---|
131 | yw = fLamellarPS_HG(cw,xw) |
---|
132 | #endif |
---|
133 | return(0) |
---|
134 | End |
---|
135 | |
---|
136 | // |
---|
137 | Function fLamellarPS_HG(w,x) : FitFunc |
---|
138 | Wave w |
---|
139 | Variable x |
---|
140 | // Input (fitting) variables are: |
---|
141 | //[0]Scale |
---|
142 | //[1]repeat spacing, D |
---|
143 | //[2]Tail Thickness (delT) |
---|
144 | //[3]HG thickness (delH) |
---|
145 | //[4]SLD tails |
---|
146 | //[5]SLD HG |
---|
147 | //[6]SLD solvent |
---|
148 | //[7]# of Lam plates |
---|
149 | //[8]Caille parameter |
---|
150 | //[9]Incoherent Bgd (cm-1) |
---|
151 | |
---|
152 | // give them nice names |
---|
153 | Variable scale,dd,delT,delH,SLD_T,SLD_H,SLD_S,NN,Cp,bkg |
---|
154 | scale = w[0] |
---|
155 | dd = w[1] |
---|
156 | delT = w[2] |
---|
157 | delH = w[3] |
---|
158 | SLD_T = w[4] |
---|
159 | SLD_H = w[5] |
---|
160 | SLD_S = w[6] |
---|
161 | NN = trunc(w[7]) //be sure that NN is an integer |
---|
162 | Cp = w[8] |
---|
163 | bkg = w[9] |
---|
164 | |
---|
165 | // local variables |
---|
166 | Variable inten, qval,Pq,Sq,ii,alpha,temp,t1,t2,t3,dQ,drh,drt |
---|
167 | Variable Euler = 0.5772156649 |
---|
168 | Variable dQDefault = 0 |
---|
169 | dQ = dQDefault |
---|
170 | // NVAR Euler = root:gEuler |
---|
171 | // NVAR dQDefault = root:gDelQ |
---|
172 | // x is the q-value for the calculation |
---|
173 | qval = x |
---|
174 | //get the instrument resolution |
---|
175 | // SVAR/Z sigQ = gSig_Q |
---|
176 | // SVAR/Z qStr = gQVals |
---|
177 | // |
---|
178 | // if(SVAR_Exists(sigQ) && SVAR_Exists(qStr)) |
---|
179 | // Wave/Z sigWave=$sigQ |
---|
180 | // Wave/Z sig_Qwave = $qStr |
---|
181 | // if(waveexists(sigWave)&&waveexists(sig_qwave)) |
---|
182 | // dQ = interp(qval, sig_Qwave, sigWave ) |
---|
183 | // else |
---|
184 | // if(qval>0.01 && qval<0.012) |
---|
185 | // print "using default resolution" |
---|
186 | // endif |
---|
187 | // dQ = dQDefault |
---|
188 | // endif |
---|
189 | // else |
---|
190 | // dQ = dQDefault |
---|
191 | // endif |
---|
192 | |
---|
193 | drh = SLD_H - SLD_S |
---|
194 | // drt = SLD_T - SLD_H //original |
---|
195 | drt = SLD_T - SLD_S //matches Lionel's changes in the Lamellar_HG model |
---|
196 | |
---|
197 | Pq = drh*(sin(qval*(delH+delT))-sin(qval*delT)) + drt*sin(qval*delT) |
---|
198 | Pq *= Pq |
---|
199 | Pq *= 4/(qval^2) |
---|
200 | |
---|
201 | ii=0 |
---|
202 | Sq = 0 |
---|
203 | for(ii=1;ii<(NN-1);ii+=1) |
---|
204 | temp = 0 |
---|
205 | alpha = Cp/4/pi/pi*(ln(pi*ii) + Euler) |
---|
206 | t1 = 2*dQ*dQ*dd*dd*alpha |
---|
207 | t2 = 2*qval*qval*dd*dd*alpha |
---|
208 | t3 = dQ*dQ*dd*dd*ii*ii |
---|
209 | |
---|
210 | temp = 1-ii/NN |
---|
211 | temp *= cos(dd*qval*ii/(1+t1)) |
---|
212 | temp *= exp(-1*(t2 + t3)/(2*(1+t1)) ) |
---|
213 | temp /= sqrt(1+t1) |
---|
214 | |
---|
215 | Sq += temp |
---|
216 | endfor |
---|
217 | Sq *= 2 |
---|
218 | Sq += 1 |
---|
219 | |
---|
220 | inten = 2*Pi*scale*Pq*Sq/(dd*Qval^2) |
---|
221 | |
---|
222 | inten *= 1e8 // 1/A to 1/cm |
---|
223 | //inten = Sq |
---|
224 | Return (inten+bkg) |
---|
225 | End |
---|
226 | |
---|
227 | //wrapper to calculate the smeared model as an AAO-Struct |
---|
228 | // fills the struct and calls the ususal function with the STRUCT parameter |
---|
229 | // |
---|
230 | // used only for the dependency, not for fitting |
---|
231 | // |
---|
232 | Function fSmearedLamellarPS_HG(coefW,yW,xW) |
---|
233 | Wave coefW,yW,xW |
---|
234 | |
---|
235 | String str = getWavesDataFolder(yW,0) |
---|
236 | String DF="root:"+str+":" |
---|
237 | |
---|
238 | WAVE resW = $(DF+str+"_res") |
---|
239 | |
---|
240 | STRUCT ResSmearAAOStruct fs |
---|
241 | WAVE fs.coefW = coefW |
---|
242 | WAVE fs.yW = yW |
---|
243 | WAVE fs.xW = xW |
---|
244 | WAVE fs.resW = resW |
---|
245 | |
---|
246 | Variable err |
---|
247 | err = SmearedLamellarPS_HG(fs) |
---|
248 | |
---|
249 | return (0) |
---|
250 | End |
---|
251 | |
---|
252 | ////the smeared model calculation |
---|
253 | Function SmearedLamellarPS_HG(s) :FitFunc |
---|
254 | Struct ResSmearAAOStruct &s |
---|
255 | |
---|
256 | // the name of your unsmeared model (AAO) is the first argument |
---|
257 | Smear_Model_76(LamellarPS_HG,s.coefW,s.xW,s.yW,s.resW) |
---|
258 | |
---|
259 | return(0) |
---|
260 | End |
---|
261 | |
---|