source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/PolyCoreShellRatio_v40.ipf @ 510

Last change on this file since 510 was 510, checked in by srkline, 14 years ago

Simple change in all of the model function files to include the name of the parameter wave in the Keyword=list that is generated when a model is plotted. This is becoming an issue where the proper parameter wave can't be deduced from just the suffix, then there is nothing to put in the table.

I should have added this when I initially wrote the wrapper...

File size: 8.1 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion = 6.0
3
4////////////////////////////////////////////////
5// GaussUtils.proc and PlotUtils.proc MUST be included for the smearing calculation to compile
6// Adopting these into the experiment will insure that they are always present
7////////////////////////////////////////////////
8//
9// this function is for the form factor of a polydisperse spherical particle, with a core-shell structure
10// the polydispersity of the overall (core+shell) radius is described by a Schulz distribution
11// the ratio R(core)/ R (total) is constant
12//
13// 06 NOV 98 SRK
14////////////////////////////////////////////////
15
16Proc PlotPolyCoreShellRatio(num,qmin,qmax)
17        Variable num=128,qmin=0.001,qmax=0.7
18        Prompt num "Enter number of data points for model: "
19        Prompt qmin "Enter minimum q-value (A^-1) for model: "
20        Prompt qmax "Enter maximum q-value (A^-1) for model: "
21       
22        Make/O/D/n=(num) xwave_pcr,ywave_pcr
23        xwave_pcr = alog(log(qmin) + x*((log(qmax)-log(qmin))/num))     
24        Make/O/D coef_pcr = {1.,60,10,.2,1e-6,2e-6,3e-6,0.001}
25        Make/O/t parameters_pcr = {"scale","avg core rad (A)","avg shell thickness (A)","overall polydisp (0,1)",,"SLD core (A-2)","SLD shell (A-2)","SLD solvent (A-2)","bkg (cm-1)"}
26        Edit parameters_pcr,coef_pcr
27        Variable/G root:g_pcr
28        g_pcr := PolyCoreShellRatio(coef_pcr,ywave_pcr,xwave_pcr)
29//      ywave_pcr := PolyCoreShellRatio(coef_pcr,xwave_pcr)
30        Display ywave_pcr vs xwave_pcr
31        ModifyGraph log=1,marker=29,msize=2,mode=4
32        Label bottom "q (A\\S-1\\M)"
33        Label left "Intensity (cm\\S-1\\M)"
34        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
35       
36        AddModelToStrings("PolyCoreShellRatio","coef_pcr","parameters_pcr","pcr")
37End
38
39///////////////////////////////////////////////////////////
40// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
41Proc PlotSmearedPolyCoreShellRatio(str)                                                         
42        String str
43        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
44       
45        // if any of the resolution waves are missing => abort
46        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
47                Abort
48        endif
49       
50        SetDataFolder $("root:"+str)
51       
52        // Setup parameter table for model function
53        Make/O/D smear_coef_pcr = {1.,60,10,.2,1e-6,2e-6,3e-6,0.001}
54        make/o/t smear_parameters_pcr = {"scale","avg core rad (A)","avg shell thickness (A)","overall polydisp (0,1)",,"SLD core (A-2)","SLD shell (A-2)","SLD solvent (A-2)","bkg (cm-1)"}
55        Edit smear_parameters_pcr,smear_coef_pcr
56       
57        // output smeared intensity wave, dimensions are identical to experimental QSIG values
58        // make extra copy of experimental q-values for easy plotting
59        Duplicate/O $(str+"_q") smeared_pcr,smeared_qvals                               //**** mod
60        SetScale d,0,0,"1/cm",smeared_pcr                                                       //**** mod                                     
61               
62        Variable/G gs_pcr=0
63        gs_pcr := fSmearedPolyCoreShellRatio(smear_coef_pcr,smeared_pcr,smeared_qvals)  //this wrapper fills the STRUCT
64
65        Display smeared_pcr vs smeared_qvals
66        ModifyGraph log=1,marker=29,msize=2,mode=4
67        Label bottom "q (A\\S-1\\M)"
68        Label left "Intensity (cm\\S-1\\M)"
69        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) 
70       
71        SetDataFolder root:
72        AddModelToStrings("SmearedPolyCoreShellRatio","smear_coef_pcr","smear_parameters_pcr","pcr")
73End
74
75
76//AAO version
77Function PolyCoreShellRatio(cw,yw,xw) : FitFunc
78        Wave cw,yw,xw
79
80#if exists("PolyCoreShellRatioX")
81        yw = PolyCoreShellRatioX(cw,xw)
82#else
83        yw = fPolyCoreShellRatio(cw,xw)
84#endif
85        return(0)
86End
87
88///////////////////////////////////////////////////////////////
89// unsmeared model calculation
90///////////////////////////
91//C     CALC'S THE FORM FACTOR FOR A MONOMODAL
92//c     POPULATION OF POLYDISPERSE SHERES WITH A
93//c     CORE AND SHELL TYPE SLD DISTRIBUTION. IT
94//c     ASSUMES THAT THE CORE RADIUS IS A CONSTANT
95//c     FRACTION (P) OF THE SHELL  RADIUS.
96//c
97//c
98//c     REF.:    "DETERMINATION OF THE STRUCTURE AND DYNAMICS OF
99//c              MICELLAR SOLUTIONS BY NEUTRON SMALL-ANGLE SCATTERING"
100//c              BY J.B.HAYTER IN PHYSICS OF AMPHIPHILES--MICELLES,
101//c              VESICLES, AND MICROEMULSIONS ED BY  DEGIORGIO,V;  CORTI,M,
102//c              PP59-93,1983.
103//c
104//c     EQNS: 32-37
105//c
106Function fPolyCoreShellRatio(w,x) : FitFunc
107        Wave w;Variable x
108
109        //assign nice names to the input wave
110        //w[0] = scale
111        //w[1] = core radius [A]
112        //w[2] = shell thickness [A]
113        //w[3] = polydispersity index (0<p<1)
114        //w[4] = SLD core [A^-2]
115        //w[5] = SLD shell  [A^-2]
116        //w[6] = SLD solvent [A^-2]
117        //w[7] = bkg [cm-1]
118        Variable scale,corrad,thick,shlrad,pp,drho1,drho2,sig,zz,bkg
119        Variable sld1,sld2,sld3,zp1,zp2,zp3,vpoly
120       
121        scale = w[0]
122        corrad = w[1]
123        thick = w[2]
124        sig = w[3]
125        sld1 = w[4]
126        sld2 = w[5]
127        sld3 = w[6]
128        bkg = w[7]
129       
130        //calculations on input parameters
131        shlrad = corrad + thick
132        zz = (1/sig)^2-1
133        drho1 = sld1-sld2               //core-shell
134        drho2 = sld2-sld3               //shell-solvent
135        zp1 = zz + 1.
136        zp2 = zz + 2.
137        zp3 = zz + 3.
138        vpoly = 4*Pi/3*zp3*zp2/zp1/zp1*(corrad+thick)^3
139       
140        //local variables
141        Variable pi43,c1,c2,form,volume,arg1,arg2
142       
143        PI43=4.0/3.0*PI
144        Pp=CORRAD/SHLRAD
145        VOLUME=PI43*SHLRAD*SHLRAD*SHLRAD
146        C1=DRHO1*VOLUME
147        C2=DRHO2*VOLUME
148       
149        // the beta factor is not calculated
150        // the calculated form factor <f^2> has units [length^2]
151        // and must be multiplied by number density [l^-3] and the correct unit
152        // conversion to get to absolute scale
153       
154//      DO 10  I=1,NPTSM
155//        F=P*P*P*C1*FNT1(QVALSM(I)*P*SHLRAD,Z)
156//     2   +C2*FNT1(QVALSM(I)*SHLRAD,Z)
157//       FAVE2=F*F
158               
159        arg1 = x*shlrad*pp
160        arg2 = x*shlrad
161               
162        FORM=(Pp^6.0)*C1*C1*FNT2(arg1,Zz)
163        form += C2*C2*FNT2(arg2,Zz)
164        form += 2.0*C1*C2*FNT3(arg2,Pp,Zz)
165       
166        //convert the result to [cm^-1]
167       
168        //scale the result
169        // - divide by the polydisperse volume, mult by 10^8
170        form  /= vpoly
171        form *= 1.0e8
172        form *= scale
173
174        //add in the background
175        form += bkg
176     
177        RETURN (form)
178END
179//////////////////////////////////////
180//cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
181//c
182//c      FUNCTION FNT1(Y,Z)
183//c
184        Function FNT1(Yy,Zz)
185        Variable yy,zz
186       
187        //local variables
188        Variable z1,z2,uu,vv,ww,term1,term2,fnt1
189
190        Z1=Zz+1.0
191        Z2=Zz+2.0
192        Uu=Yy/Z1
193        Vv=ATAN(Uu)
194        Ww=ATAN(2.0*Uu)
195        TERM1=SIN(Z1*Vv)/((1.0+Uu*Uu)^(Z1/2.0))
196        TERM2=Yy*COS(Z2*Vv)/((1.0+Uu*Uu)^(Z2/2.0))
197        FNT1=3.0/Yy/Yy/Yy*(TERM1-TERM2)
198       
199        RETURN (fnt1)
200END
201
202//cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
203//c
204//c      FUNCTION FNT2(Y,Z)
205//c
206FUNCTION FNT2(Yy,Zz)
207        Variable yy,zz
208       
209        //local variables
210        Variable z1,z2,z3,uu,ww,term1,term2,term3,fnt2
211       
212        Z1=Zz+1.0
213        Z2=Zz+2.0
214        Z3=Zz+3.0
215        Uu=Yy/Z1
216        Ww=ATAN(2.0*Uu)
217        TERM1=COS(Z1*Ww)/((1.0+4.0*Uu*Uu)^(Z1/2.0))
218        TERM2=2.0*Yy*SIN(Z2*Ww)/((1.0+4.0*Uu*Uu)^(Z2/2.0))
219        TERM3=1.0+COS(Z3*Ww)/((1.0+4.0*Uu*Uu)^(Z3/2.0))
220        FNT2=(4.50/Z1/Yy^6.0)*(Z1*(1.0-TERM1-TERM2)+Yy*Yy*Z2*TERM3)
221       
222        RETURN (fnt2)
223END
224
225//cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
226//c
227//c      FUNCTION FNT3(Y,P,Z)
228//c
229FUNCTION FNT3(Yy,Pp,Zz)
230        Variable yy,pp,zz
231       
232        //local variables
233        Variable z1,z2,z3,yp,yn,up,un,vp,vn,term1,term2,term3,term4,term5,term6,fnt3
234       
235        Z1=Zz+1
236        Z2=Zz+2
237        Z3=Zz+3
238        YP=(1.0+Pp)*Yy
239        YN=(1.0-Pp)*Yy
240        UP=YP/Z1
241        UN=YN/Z1
242        VP=ATAN(UP)
243        VN=ATAN(UN)
244        TERM1=COS(Z1*VN)/((1.0+UN*UN)^(Z1/2.0))
245        TERM2=COS(Z1*VP)/((1.0+UP*UP)^(Z1/2.0))
246        TERM3=COS(Z3*VN)/((1.0+UN*UN)^(Z3/2.0))
247        TERM4=COS(Z3*VP)/((1.0+UP*UP)^(Z3/2.0))
248        TERM5=YN*SIN(Z2*VN)/((1.0+UN*UN)^(Z2/2.0))
249        TERM6=YP*SIN(Z2*VP)/((1.0+UP*UP)^(Z2/2.0))
250        FNT3=(4.5/Z1/Yy^6.0)
251        fnt3 *=(Z1*(TERM1-TERM2)+Yy*Yy*Pp*Z2*(TERM3+TERM4)+Z1*(TERM5-TERM6))
252     
253        RETURN (fnt3)
254END
255/////////////////////////////////
256
257// this is all there is to the smeared calculation!
258Function SmearedPolyCoreShellRatio(s) :FitFunc
259        Struct ResSmearAAOStruct &s
260
261////the name of your unsmeared model is the first argument
262        Smear_Model_20(PolyCoreShellRatio,s.coefW,s.xW,s.yW,s.resW)
263
264        return(0)
265End
266
267//wrapper to calculate the smeared model as an AAO-Struct
268// fills the struct and calls the ususal function with the STRUCT parameter
269//
270// used only for the dependency, not for fitting
271//
272Function fSmearedPolyCoreShellRatio(coefW,yW,xW)
273        Wave coefW,yW,xW
274       
275        String str = getWavesDataFolder(yW,0)
276        String DF="root:"+str+":"
277       
278        WAVE resW = $(DF+str+"_res")
279       
280        STRUCT ResSmearAAOStruct fs
281        WAVE fs.coefW = coefW   
282        WAVE fs.yW = yW
283        WAVE fs.xW = xW
284        WAVE fs.resW = resW
285       
286        Variable err
287        err = SmearedPolyCoreShellRatio(fs)
288       
289        return (0)
290End
Note: See TracBrowser for help on using the repository browser.