source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/NewModels_2006/LamellarPS.ipf @ 151

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

(1) - cursors can now be used to select a subrange of USANS data to fit. This is done by th fit wrapper, assigning a subrange of resW to the struct

(2) all of the smeared model functions are now in the latest form of Smear_Model_N() that is NOT a pointwise calculation anymore, since the USANS matrix smearing in inherently not so.

File size: 7.8 KB
Line 
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 is two-phase,
8// from the solvent and uniform bilayer. 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_Lamellar" 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//
49Proc Plot_LamellarPS(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 (^1) for model: "
53        Prompt qmax "Enter maximum q-value (^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, ywave_LamellarPS
60        xwave_LamellarPS =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
61        Make/O/D coef_LamellarPS = {1,400,30,0.15,6e-6,20,0.1,0}                        //CH#2
62        make/o/t parameters_LamellarPS = {"Scale","Lamellar spacing, D (A)","Bilayer Thick (delta) (A)","polydisp of Bilayer Thickness","contrast (A^-2)","# of Lamellar plates","Caille parameter","Incoherent Bgd (cm-1)"}    //CH#3
63        Edit parameters_LamellarPS, coef_LamellarPS
64        ModifyTable width(parameters_LamellarPS)=160
65       
66        Variable/G root:g_LamellarPS
67        g_LamellarPS := LamellarPS(coef_LamellarPS, ywave_LamellarPS, xwave_LamellarPS)
68        Display ywave_LamellarPS vs xwave_LamellarPS
69        ModifyGraph marker=29, msize=2, mode=4
70        ModifyGraph log=1
71        Label bottom "q (\\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 epsilon_LamellarPS
76        epsilon_LamellarPS = 1e-4
77        epsilon_LamellarPS[5] = 1               //to make the derivative useful
78        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
79End
80
81// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
82//Proc PlotSmeared_LamellarPS(str)                                                             
83//      String str
84//      Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
85//     
86//      // if any of the resolution waves are missing => abort
87//      if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
88//              Abort
89//      endif
90//     
91//      SetDataFolder $("root:"+str)
92//     
93//      // constants
94//      Variable/G root:gEuler = 0.5772156649           // Euler's constant
95//      Variable/G root:gDelQ = 0.0025          //[=] 1/A, q-resolution, default value
96//      // Setup parameter table for model function
97//      Make/O/D smear_coef_LamellarPS = {1,400,30,0.15,6e-6,20,0.1,0}          //CH#4
98//      make/o/t smear_parameters_LamellarPS = {"Scale","Lamellar spacing, D (A)","Bilayer Thick (delta) (A)","polydisp of Bilayer Thickness","contrast (A^-2)","# of Lamellar plates","Caille parameter","Incoherent Bgd (cm-1)"}
99//      Edit smear_parameters_LamellarPS,smear_coef_LamellarPS                                  //display parameters in a table
100//     
101//      // output smeared intensity wave, dimensions are identical to experimental QSIG values
102//      // make extra copy of experimental q-values for easy plotting
103//      Duplicate/O $(str+"_q") smeared_LamellarPS,smeared_qvals                                //
104//      SetScale d,0,0,"1/cm",smeared_LamellarPS                                                        //
105//                                     
106//      Variable/G gs_LamellarPS=0
107//      gs_LamellarPS := fLamellarPS_Smeared(smear_coef_LamellarPS,smeared_LamellarPS,smeared_qvals)    //this wrapper fills the STRUCT
108//     
109//      Display smeared_LamellarPS vs smeared_qvals                                                                     //
110//      ModifyGraph log=1,marker=29,msize=2,mode=4
111//      Label bottom "q (\\S-1\\M)"
112//      Label left "I(q) (cm\\S-1\\M)"
113//     
114//      SetDataFolder root:
115//End
116
117
118
119
120
121//AAO version, uses XOP if available
122// simply calls the original single point calculation with
123// a wave assignment (this will behave nicely if given point ranges)
124Function LamellarPS(cw,yw,xw) : FitFunc
125        Wave cw,yw,xw
126       
127#if exists("LamellarPSX")
128        yw = LamellarPSX(cw,xw)
129#else
130        yw = fLamellarPS(cw,xw)
131#endif
132        return(0)
133End
134
135// instrument resolution IS included here in S(Q)
136Function fLamellarPS(w,x) : FitFunc
137        Wave w
138        Variable x
139//       Input (fitting) variables are:
140//[0]Scale
141//[1]Lam spacing, D
142//[2]Bilay Thick (delta)
143//[3]polydisp of the bilayer thickness
144//[4]contrast
145//[5]# of Lam plates
146//[6]Caille parameter
147//[7]Incoherent Bgd (cm-1)
148       
149//      give them nice names
150        Variable scale,dd,del,sig,contr,NN,Cp,bkg
151        scale = w[0]
152        dd = w[1]
153        del = w[2]
154        sig = w[3]*del
155        contr = w[4]
156        NN = trunc(w[5])                //be sure that NN is an integer
157        Cp = w[6]
158        bkg = w[7]
159       
160//      local variables
161        Variable inten, qval,Pq,Sq,ii,alpha,temp,t1,t2,t3,dQ
162       
163        NVAR Euler = root:gEuler
164        NVAR dQDefault = root:gDelQ
165        //      x is the q-value for the calculation
166        qval = x
167        //get the instrument resolution
168        SVAR/Z sigQ = gSig_Q
169        SVAR/Z qStr = gQVals
170       
171        if(SVAR_Exists(sigQ) && SVAR_Exists(qStr))
172                Wave/Z sigWave=$sigQ
173                Wave/Z sig_Qwave = $qStr
174                if(waveexists(sigWave)&&waveexists(sig_qwave))
175                        dQ = interp(qval, sig_Qwave, sigWave )
176                else
177//                      if(qval>0.01 && qval<0.012)
178//                              print "using default resolution"
179//                      endif
180                        dQ = dQDefault
181                endif
182        else
183                dQ = dQDefault
184        endif
185       
186        Pq = 2*contr^2/qval/qval*(1-cos(qval*del)*exp(-0.5*qval^2*sig^2))
187       
188        ii=0
189        Sq = 0
190        for(ii=1;ii<(NN-1);ii+=1)
191                temp = 0
192                alpha = Cp/4/pi/pi*(ln(pi*ii) + Euler)
193                t1 = 2*dQ*dQ*dd*dd*alpha
194                t2 = 2*qval*qval*dd*dd*alpha
195                t3 = dQ*dQ*dd*dd*ii*ii
196               
197                temp = 1-ii/NN
198                temp *= cos(dd*qval*ii/(1+t1))
199                temp *= exp(-1*(t2 + t3)/(2*(1+t1)) )
200                temp /= sqrt(1+t1)
201               
202                Sq += temp
203        endfor
204        Sq *= 2
205        Sq += 1
206       
207        inten = 2*Pi*scale*Pq*Sq/(dd*Qval^2)
208       
209        inten *= 1e8            // 1/A to 1/cm
210        //inten = Sq
211        Return (inten+bkg)
212End
213
214//wrapper to calculate the smeared model as an AAO-Struct
215// fills the struct and calls the ususal function with the STRUCT parameter
216//
217// used only for the dependency, not for fitting
218//
219//Function fLamellarPS_Smeared(coefW,yW,xW)
220//      Wave coefW,yW,xW
221//     
222//      String str = getWavesDataFolder(yW,0)
223//      String DF="root:"+str+":"
224//     
225//      WAVE resW = $(DF+str+"_res")
226//     
227//      STRUCT ResSmearAAOStruct fs
228//      WAVE fs.coefW = coefW   
229//      WAVE fs.yW = yW
230//      WAVE fs.xW = xW
231//      WAVE fs.resW = resW
232//     
233//      Variable err
234//      err = LamellarPS_Smeared(fs)
235//     
236//      return (0)
237//End
238
239//the smeared model calculation
240//Function LamellarPS_Smeared(s) :FitFunc
241//      Struct ResSmearAAOStruct &s
242//
243////    the name of your unsmeared model (AAO) is the first argument
244//      Smear_Model_20(LamellarPS,s.coefW,s.xW,s.yW,s.resW)
245//
246//      return(0)
247//End
248////
Note: See TracBrowser for help on using the repository browser.