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

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

LOTS of changes to the analysis ipf files:

-- see sphere.ipf for the simplest example of the changes --

  • #pragma Igor 6
  • #if directive to look for XOP
  • AAO unsmeared functions
  • STRUCT functions for smearing (also AAO)
  • new wrappers for dependencies to struct functions

(2006 models have NOT been completed yet, only the old models)

  • loading data files into data folders (PlotUtils?) + some streamlining of the loaders
  • Smear_Model_N is now AAO + some streamlining of the quadrature code

-- SHS and SW structure factor XOPs are crashing (need DP wave, I may have old XOP)
-- this breaks fitting of the smeared models until wrappers can be devised
-- all packages will be broken due to the new data folder structure
-- multiple instances of functions will now cause problems (MSA)
-- RPA model is a problem with its odd functional form (extra wave)

-- lots of other carnage to follow as the bugs and typos are shaken out

24 JUL 2007 SRK

File size: 6.9 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        ywave_LamellarPS  := LamellarPS(coef_LamellarPS, xwave_LamellarPS)
66        Display ywave_LamellarPS vs xwave_LamellarPS
67        ModifyGraph marker=29, msize=2, mode=4
68        ModifyGraph log=1
69        Label bottom "q (\\S-1\\M) "
70        Label left "I(q) (cm\\S-1\\M)"
71        //
72        // make epsilon wave appropriate for integer number of lamellar repeats
73        Duplicate/O coef_LamellarPS epsilon_LamellarPS
74        epsilon_LamellarPS = 1e-4
75        epsilon_LamellarPS[5] = 1               //to make the derivative useful
76        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
77End
78
79////
80////this macro sets up all the necessary parameters and waves that are
81////needed to calculate the  smeared model function.
82////
83////no input parameters are necessary, it MUST use the experimental q-values
84//// from the experimental data read in from an AVE/QSIG data file
85//////////////////////////////////////////////////////
86//Macro PlotSmeared_LamellarPS()                                                                //Lamellar
87//     
88//     
89//      // if no gQvals wave, data must not have been loaded => abort
90//      If(ResolutionWavesMissing())            //part of GaussUtils
91//              Abort
92//      endif
93//     
94//      // constants
95//      Variable/G root:gEuler = 0.5772156649           // Euler's constant
96//      Variable/G root:gDelQ = 0.0025          //[=] 1/A, q-resolution, default value
97//      // Setup parameter table for model function
98//      Make/O/D smear_coef_LamellarPS = {1,400,30,0.15,6e-6,20,0.1,0}          //CH#4
99//      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)"}
100//      Edit smear_parameters_LamellarPS,smear_coef_LamellarPS                                  //display parameters in a table
101//     
102//      // output smeared intensity wave, dimensions are identical to experimental QSIG values
103//      // make extra copy of experimental q-values for easy plotting
104//      Duplicate/O $gQvals smeared_LamellarPS,smeared_qvals                            //
105//      SetScale d,0,0,"1/cm",smeared_LamellarPS                                                        //
106//
107//      smeared_LamellarPS := LamellarPS_Smeared(smear_coef_LamellarPS,$gQvals)         // SMEARED function name
108//      Display smeared_LamellarPS vs $gQvals                                                                   //
109//      ModifyGraph log=1,marker=29,msize=2,mode=4
110//      Label bottom "q (\\S-1\\M)"
111//      Label left "I(q) (cm\\S-1\\M)"
112//
113//End     // end macro
114
115// instrument resolution IS included here in S(Q)
116Function LamellarPS(w,x) : FitFunc
117        Wave w
118        Variable x
119//       Input (fitting) variables are:
120//[0]Scale
121//[1]Lam spacing, D
122//[2]Bilay Thick (delta)
123//[3]polydisp of the bilayer thickness
124//[4]contrast
125//[5]# of Lam plates
126//[6]Caille parameter
127//[7]Incoherent Bgd (cm-1)
128       
129//      give them nice names
130        Variable scale,dd,del,sig,contr,NN,Cp,bkg
131        scale = w[0]
132        dd = w[1]
133        del = w[2]
134        sig = w[3]*del
135        contr = w[4]
136        NN = trunc(w[5])                //be sure that NN is an integer
137        Cp = w[6]
138        bkg = w[7]
139       
140//      local variables
141        Variable inten, qval,Pq,Sq,ii,alpha,temp,t1,t2,t3,dQ
142       
143        NVAR Euler = root:gEuler
144        NVAR dQDefault = root:gDelQ
145        //      x is the q-value for the calculation
146        qval = x
147        //get the instrument resolution
148        SVAR/Z sigQ = gSig_Q
149        SVAR/Z qStr = gQVals
150       
151        if(SVAR_Exists(sigQ) && SVAR_Exists(qStr))
152                Wave/Z sigWave=$sigQ
153                Wave/Z sig_Qwave = $qStr
154                if(waveexists(sigWave)&&waveexists(sig_qwave))
155                        dQ = interp(qval, sig_Qwave, sigWave )
156                else
157//                      if(qval>0.01 && qval<0.012)
158//                              print "using default resolution"
159//                      endif
160                        dQ = dQDefault
161                endif
162        else
163                dQ = dQDefault
164        endif
165       
166        Pq = 2*contr^2/qval/qval*(1-cos(qval*del)*exp(-0.5*qval^2*sig^2))
167       
168        ii=0
169        Sq = 0
170        for(ii=1;ii<(NN-1);ii+=1)
171                temp = 0
172                alpha = Cp/4/pi/pi*(ln(pi*ii) + Euler)
173                t1 = 2*dQ*dQ*dd*dd*alpha
174                t2 = 2*qval*qval*dd*dd*alpha
175                t3 = dQ*dQ*dd*dd*ii*ii
176               
177                temp = 1-ii/NN
178                temp *= cos(dd*qval*ii/(1+t1))
179                temp *= exp(-1*(t2 + t3)/(2*(1+t1)) )
180                temp /= sqrt(1+t1)
181               
182                Sq += temp
183        endfor
184        Sq *= 2
185        Sq += 1
186       
187        inten = 2*Pi*scale*Pq*Sq/(dd*Qval^2)
188       
189        inten *= 1e8            // 1/A to 1/cm
190        //inten = Sq
191        Return (inten+bkg)
192End
193       
194//the smeared model calculation
195//Function LamellarPS_Smeared(w,x) :FitFunc
196//      Wave w
197//      Variable x
198//     
199//      Variable ans
200//      SVAR sq = gSig_Q
201//      SVAR qb = gQ_bar
202//      SVAR sh = gShadow
203//      SVAR gQ = gQVals
204//     
205//      ans = Smear_Model_20(LamellarPS,$sq,$qb,$sh,$gQ,w,x)   
206//
207//      return(ans)
208//End
209//
Note: See TracBrowser for help on using the repository browser.