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

Last change on this file since 91 was 42, checked in by srkline, 16 years ago

initial checkin of Analysis v.3.00 files

File size: 6.9 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2
3////////////////////////////////////////////////////
4//
5// model function that calculates the scattering from
6// lamellar surfactant structures. contrast is two-phase,
7// from the solvent and uniform bilayer. Integer numbers of
8// repeating bilayers (at a repeat spacing) leads to the
9// familiar lamellar peaks. Bending constant information
10// can be extracted from the Caille parameter with moderate
11// success. A number of the parameters should be held
12// fixed during the fitting procedure, as they should be well
13// known:
14//              repeat spacing D = 2*pi/Qo
15//              contrast = calculated value
16//              polydispersity should be close to 0.1-0.3
17//   Caille parameter <0.8 or 1.0
18//
19// NOTES for Curve Fitting:
20// the epsilon wave "epsilon_Lamellar" should be used to force a
21// larger derivative step for the # of repeat units, which is an integer.
22// a singular matix error will always result if you don't follow this.
23// Also, the # of repeats should be constrained to ~3<N<200, otherwise
24// the optimization can pick a VERY large N, and waste lots of time
25// in the summation loop
26//
27// instrumental resolution is taken into account in the REGULAR
28// model calculation. resolution of ONLY the S(Q) peaks are
29// included. performing the typical smearing calculation would
30// be "double smearing", so is not done.
31//
32// the delta Q parameter "gDelQ" or "dQ" is taken from the q-dependent
33// instrument resolution "abssq" column as this is the identical definition
34// as in the original reference. If the real resolution function cannot be
35// found, a default value, typical of a "medium" q-range on the NG3 SANS is
36// used, although the real values are highly preferred
37//
38// REFERENCE:   Nallet, Laversanne, and Roux, J. Phys. II France, 3, (1993) 487-502.
39//              also in J. Phys. Chem. B, 105, (2001) 11081-11088.
40//
41// 14 JULY 2003 SRK
42//
43////////////////////////////////////////////////////
44
45//this macro sets up all the necessary parameters and waves that are
46//needed to calculate the model function.
47//
48Proc Plot_LamellarPS(num,qmin,qmax)
49        Variable num=128, qmin=.001, qmax=.5
50        Prompt num "Enter number of data points for model: "
51        Prompt qmin "Enter minimum q-value (^1) for model: "
52        Prompt qmax "Enter maximum q-value (^1) for model: "
53//
54        // constants
55        Variable/G root:gEuler = 0.5772156649           // Euler's constant
56        Variable/G root:gDelQ = 0.0025          //[=] 1/A, q-resolution, default value
57       
58        Make/O/D/n=(num) xwave_LamellarPS, ywave_LamellarPS
59        xwave_LamellarPS =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
60        Make/O/D coef_LamellarPS = {1,400,30,0.15,6e-6,20,0.1,0}                        //CH#2
61        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
62        Edit parameters_LamellarPS, coef_LamellarPS
63        ModifyTable width(parameters_LamellarPS)=160
64        ywave_LamellarPS  := LamellarPS(coef_LamellarPS, xwave_LamellarPS)
65        Display ywave_LamellarPS vs xwave_LamellarPS
66        ModifyGraph marker=29, msize=2, mode=4
67        ModifyGraph log=1
68        Label bottom "q (\\S-1\\M) "
69        Label left "I(q) (cm\\S-1\\M)"
70        //
71        // make epsilon wave appropriate for integer number of lamellar repeats
72        Duplicate/O coef_LamellarPS epsilon_LamellarPS
73        epsilon_LamellarPS = 1e-4
74        epsilon_LamellarPS[5] = 1               //to make the derivative useful
75        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
76End
77
78////
79////this macro sets up all the necessary parameters and waves that are
80////needed to calculate the  smeared model function.
81////
82////no input parameters are necessary, it MUST use the experimental q-values
83//// from the experimental data read in from an AVE/QSIG data file
84//////////////////////////////////////////////////////
85//Macro PlotSmeared_LamellarPS()                                                                //Lamellar
86//     
87//     
88//      // if no gQvals wave, data must not have been loaded => abort
89//      If(ResolutionWavesMissing())            //part of GaussUtils
90//              Abort
91//      endif
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 $gQvals smeared_LamellarPS,smeared_qvals                            //
104//      SetScale d,0,0,"1/cm",smeared_LamellarPS                                                        //
105//
106//      smeared_LamellarPS := LamellarPS_Smeared(smear_coef_LamellarPS,$gQvals)         // SMEARED function name
107//      Display smeared_LamellarPS vs $gQvals                                                                   //
108//      ModifyGraph log=1,marker=29,msize=2,mode=4
109//      Label bottom "q (\\S-1\\M)"
110//      Label left "I(q) (cm\\S-1\\M)"
111//
112//End     // end macro
113
114// instrument resolution IS included here in S(Q)
115Function LamellarPS(w,x) : FitFunc
116        Wave w
117        Variable x
118//       Input (fitting) variables are:
119//[0]Scale
120//[1]Lam spacing, D
121//[2]Bilay Thick (delta)
122//[3]polydisp of the bilayer thickness
123//[4]contrast
124//[5]# of Lam plates
125//[6]Caille parameter
126//[7]Incoherent Bgd (cm-1)
127       
128//      give them nice names
129        Variable scale,dd,del,sig,contr,NN,Cp,bkg
130        scale = w[0]
131        dd = w[1]
132        del = w[2]
133        sig = w[3]*del
134        contr = w[4]
135        NN = trunc(w[5])                //be sure that NN is an integer
136        Cp = w[6]
137        bkg = w[7]
138       
139//      local variables
140        Variable inten, qval,Pq,Sq,ii,alpha,temp,t1,t2,t3,dQ
141       
142        NVAR Euler = root:gEuler
143        NVAR dQDefault = root:gDelQ
144        //      x is the q-value for the calculation
145        qval = x
146        //get the instrument resolution
147        SVAR/Z sigQ = gSig_Q
148        SVAR/Z qStr = gQVals
149       
150        if(SVAR_Exists(sigQ) && SVAR_Exists(qStr))
151                Wave/Z sigWave=$sigQ
152                Wave/Z sig_Qwave = $qStr
153                if(waveexists(sigWave)&&waveexists(sig_qwave))
154                        dQ = interp(qval, sig_Qwave, sigWave )
155                else
156//                      if(qval>0.01 && qval<0.012)
157//                              print "using default resolution"
158//                      endif
159                        dQ = dQDefault
160                endif
161        else
162                dQ = dQDefault
163        endif
164       
165        Pq = 2*contr^2/qval/qval*(1-cos(qval*del)*exp(-0.5*qval^2*sig^2))
166       
167        ii=0
168        Sq = 0
169        for(ii=1;ii<(NN-1);ii+=1)
170                temp = 0
171                alpha = Cp/4/pi/pi*(ln(pi*ii) + Euler)
172                t1 = 2*dQ*dQ*dd*dd*alpha
173                t2 = 2*qval*qval*dd*dd*alpha
174                t3 = dQ*dQ*dd*dd*ii*ii
175               
176                temp = 1-ii/NN
177                temp *= cos(dd*qval*ii/(1+t1))
178                temp *= exp(-1*(t2 + t3)/(2*(1+t1)) )
179                temp /= sqrt(1+t1)
180               
181                Sq += temp
182        endfor
183        Sq *= 2
184        Sq += 1
185       
186        inten = 2*Pi*scale*Pq*Sq/(dd*Qval^2)
187       
188        inten *= 1e8            // 1/A to 1/cm
189        //inten = Sq
190        Return (inten+bkg)
191End
192       
193//the smeared model calculation
194//Function LamellarPS_Smeared(w,x) :FitFunc
195//      Wave w
196//      Variable x
197//     
198//      Variable ans
199//      SVAR sq = gSig_Q
200//      SVAR qb = gQ_bar
201//      SVAR sh = gShadow
202//      SVAR gQ = gQVals
203//     
204//      ans = Smear_Model_20(LamellarPS,$sq,$qb,$sh,$gQ,w,x)   
205//
206//      return(ans)
207//End
208//
Note: See TracBrowser for help on using the repository browser.