source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/NewModels_2008/LamellarParacrystal_v40.ipf @ 1028

Last change on this file since 1028 was 1028, checked in by srkline, 6 years ago

adding marquee operations to do a simple box sum, for manual calculation of transmission

Error in LamellarParacrystalline? model has been fixed.

File size: 6.7 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.1
3
4////////////////////////////////////////////////////
5//
6// paracrystalline model of Lamellar stacks from J. Pedersen
7//
8// non-integer # of stacks are calculated as linear combination of trunc(N) and trunc(N+1)
9//
10// References:
11// - J. Appl. cryst. 30 (1997) 975.
12// - JPC B 103 (1999) 9888-9897.
13//
14////////////////////////////////////////////////////
15
16//
17Proc PlotLamellar_ParaCrystal(num,qmin,qmax)
18        Variable num=200, qmin=0.001, qmax=0.7
19        Prompt num "Enter number of data points for model: "
20        Prompt qmin "Enter minimum q-value (^-1) for model: "
21        Prompt qmax "Enter maximum q-value (^-1) for model: "
22//
23        Make/O/D/n=(num) xwave_LamParaCryst, ywave_LamParaCryst
24        xwave_LamParaCryst =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
25        Make/O/D coef_LamParaCryst = {1,33,20,250,0.2,1e-6,6.34e-6,0}           
26        make/o/t parameters_LamParaCryst = {"scale","Lamellar thickness (A)","N Layers","layer spacing (A)","polydisp of spacing","SLD of Layer (A-2)","SLD of solvent (A-2)","Incoherent Bgd (cm-1)"}  //CH#2
27        Edit parameters_LamParaCryst, coef_LamParaCryst
28       
29        Variable/G root:g_LamParaCryst
30        g_LamParaCryst := Lamellar_ParaCrystal(coef_LamParaCryst, ywave_LamParaCryst, xwave_LamParaCryst)
31        Display ywave_LamParaCryst vs xwave_LamParaCryst
32        ModifyGraph marker=29, msize=2, mode=4
33        ModifyGraph log=1,grid=1,mirror=2
34        Label bottom "q (\\S-1\\M) "
35        Label left "I(q) (cm\\S-1\\M)"
36        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
37       
38        AddModelToStrings("Lamellar_ParaCrystal","coef_LamParaCryst","parameters_LamParaCryst","LamParaCryst")
39//
40End
41
42
43//
44//no input parameters are necessary, it MUST use the experimental q-values
45// from the experimental data read in from an AVE/QSIG data file
46////////////////////////////////////////////////////
47// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
48Proc PlotSmearedLamellar_ParaCrystal(str)                                                               
49        String str
50        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
51       
52        // if any of the resolution waves are missing => abort
53        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
54                Abort
55        endif
56       
57        SetDataFolder $("root:"+str)
58       
59        // Setup parameter table for model function
60        Make/O/D smear_coef_LamParaCryst = {1,33,20,250,0.2,1e-6,6.34e-6,0}             
61        make/o/t smear_parameters_LamParaCryst = {"scale","Lamellar thickness (A)","N Layers","layer spacing (A)","polydisp of spacing","SLD of Layer (A-2)","SLD of solvent (A-2)","Incoherent Bgd (cm-1)"}
62        Edit smear_parameters_LamParaCryst,smear_coef_LamParaCryst                                      //display parameters in a table
63       
64        // output smeared intensity wave, dimensions are identical to experimental QSIG values
65        // make extra copy of experimental q-values for easy plotting
66        Duplicate/O $(str+"_q") smeared_LamParaCryst,smeared_qvals
67        SetScale d,0,0,"1/cm",smeared_LamParaCryst
68                                       
69        Variable/G gs_LamParaCryst=0
70        gs_LamParaCryst := fSmearedLamellar_ParaCrystal(smear_coef_LamParaCryst,smeared_LamParaCryst,smeared_qvals)     //this wrapper fills the STRUCT
71       
72        Display smeared_LamParaCryst vs smeared_qvals
73        ModifyGraph log=1,marker=29,msize=2,mode=4
74        Label bottom "q (\\S-1\\M)"
75        Label left "I(q) (cm\\S-1\\M)"
76        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
77       
78        SetDataFolder root:
79        AddModelToStrings("SmearedLamellar_ParaCrystal","smear_coef_LamParaCryst","smear_parameters_LamParaCryst","LamParaCryst")
80End
81
82
83//
84//AAO version, uses XOP if available
85// simply calls the original single point calculation with
86// a wave assignment (this will behave nicely if given point ranges)
87Function Lamellar_ParaCrystal(cw,yw,xw) : FitFunc
88        Wave cw,yw,xw
89       
90#if exists("Lamellar_ParaCrystalX")
91        yw = Lamellar_ParaCrystalX(cw,xw)
92        yw *= cw[1]
93#else
94        yw = fLamellar_ParaCrystal(cw,xw)
95        yw *= cw[1]
96#endif
97        return(0)
98End
99
100//
101// unsmeared model calculation
102//
103Function fLamellar_ParaCrystal(w,x) : FitFunc
104        Wave w
105        Variable x
106       
107//       Input (fitting) variables are:
108        //[0] scale factor
109        //[1]   thickness
110        //[2]   number of layers
111        //[3]   spacing between layers
112        //[4]   polydispersity of spacing
113        //[5] SLD lamellar
114        //[6] SLD solvent
115        //[7] incoherent background
116//      give them nice names
117        Variable inten,qval,scale,th,nl,davg,pd,contr,bkg
118        Variable xi,ww,Pbil,Zq,Znq,Snq,an,sldLayer,sldSolvent
119       
120        scale = w[0]
121        th = w[1]
122        nl = w[2]
123        davg = w[3]
124        pd = w[4]
125        sldLayer = w[5]
126        sldSolvent = w[6]
127        bkg = w[7]
128       
129        contr = w[5] - w[6]
130        qval = x
131               
132        //get the fractional part of nl, to determine the "mixing" of N's
133        Variable n1,n2,xn
134       
135        n1 = trunc(nl)          //rounds towards zero
136        n2 = n1 + 1
137        xn = n2 - nl                    //fractional contribution of n1
138       
139        ww = exp(-qval*qval*pd*pd*davg*davg/2)
140       
141        //calculate the n1 contribution
142        an = paraCryst_an(ww,qval,davg,n1)
143        Snq = paraCryst_sn(ww,qval,davg,n1,an)
144       
145        Znq = xn*Snq
146       
147        //calculate the n2 contribution
148        an = paraCryst_an(ww,qval,davg,n2)
149        Snq = paraCryst_sn(ww,qval,davg,n2,an)
150       
151        Znq += (1-xn)*Snq
152       
153        //and the independent contribution
154        Znq += (1-ww^2)/(1+ww^2-2*ww*cos(qval*davg))
155       
156        //the limit when NL approaches infinity
157//      Zq = (1-ww^2)/(1+ww^2-2*ww*cos(qval*davg))
158       
159        xi = th/2               //use 1/2 the bilayer thickness
160        Pbil = (sin(qval*xi)/(qval*xi))^2
161       
162        inten = 2*pi*contr*contr*Pbil*Znq/qval^2
163        inten *= 1e8
164       
165        Return (scale*inten+bkg)
166End
167
168Function paraCryst_sn(ww,qval,davg,nl,an)
169        Variable ww,qval,davg,nl,an
170       
171        Variable snq
172        Snq = an/(nl*(1+ww^2-2*ww*cos(qval*davg))^2)
173        return(snq)
174end
175
176
177Function paraCryst_an(ww,qval,davg,nl)
178        Variable ww,qval,davg,nl
179       
180        Variable an
181        an = 4*ww^2 - 2*(ww^3+ww)*cos(qval*davg)
182        an -= 4*ww^(nl+2)*cos(nl*qval*davg)
183        an += 2*ww^(nl+3)*cos((nl-1)*qval*davg)
184        an += 2*ww^(nl+1)*cos((nl+1)*qval*davg)
185        return(an)
186end
187
188
189///////////////////////////////////////////////////////////////
190// smeared model calculation
191//
192// you don't need to do anything with this function, as long as
193// your Lamellar_ParaCrystal works correctly, you get the resolution-smeared
194// version for free.
195//
196// this is all there is to the smeared model calculation!
197Function SmearedLamellar_ParaCrystal(s) : FitFunc
198        Struct ResSmearAAOStruct &s
199
200//      the name of your unsmeared model (AAO) is the first argument
201        Smear_Model_20(Lamellar_ParaCrystal,s.coefW,s.xW,s.yW,s.resW)
202
203        return(0)
204End
205
206
207///////////////////////////////////////////////////////////////
208
209
210// nothing to change here
211//
212//wrapper to calculate the smeared model as an AAO-Struct
213// fills the struct and calls the ususal function with the STRUCT parameter
214//
215// used only for the dependency, not for fitting
216//
217Function fSmearedLamellar_ParaCrystal(coefW,yW,xW)
218        Wave coefW,yW,xW
219       
220        String str = getWavesDataFolder(yW,0)
221        String DF="root:"+str+":"
222       
223        WAVE resW = $(DF+str+"_res")
224       
225        STRUCT ResSmearAAOStruct fs
226        WAVE fs.coefW = coefW   
227        WAVE fs.yW = yW
228        WAVE fs.xW = xW
229        WAVE fs.resW = resW
230       
231        Variable err
232        err = SmearedLamellar_ParaCrystal(fs)
233       
234        return (0)
235End
Note: See TracBrowser for help on using the repository browser.