source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/NewModels_2010/Raspberry_v40.ipf @ 774

Last change on this file since 774 was 774, checked in by srkline, 12 years ago

Added the Two-Yukawa structure factor calculations to those model functions with S(Q).

Fixed the name of Vesicle_UL_Sq.ipf to be consistent.

File size: 10.0 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.0
3
4////////////////////////////////////////////////////
5// Raspberry model
6//
7// Larson-Smith et al. Small angle scattering model for Pickering emulsions and raspberry particles.
8//   Journal of colloid and interface science (2010) vol. 343 (1) pp. 36-41
9//
10// Default parameters are for a 5000A hexadecane drop stabilized by 100A silica particles
11// in D2O. The particles are 50% inserted into the interface (delta = 0) and surface coverage is 50%
12//
13// -- bumped the smearing calculation to use 76 points, since the model is often used with a very
14// large radius of the "large" sphere, causing unsightly oscillations at low Q. Polydispersity
15// of the large sphere takes care of this too.
16//
17////////////////////////////////////////////////////
18
19//this macro sets up all the necessary parameters and waves that are
20//needed to calculate the model function.
21//
22Proc PlotRaspberry(num,qmin,qmax)
23        Variable num=500, qmin=1e-5, qmax=0.7
24        Prompt num "Enter number of data points for model: "
25        Prompt qmin "Enter minimum q-value (^-1) for model: "
26        Prompt qmax "Enter maximum q-value (^-1) for model: "
27//
28        Make/O/D/n=(num) xwave_Raspberry, ywave_Raspberry
29        xwave_Raspberry =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
30        Make/O/D coef_Raspberry = {0.05,5000,-4e-7,0.005,100,0.4,3.5e-6,0,6.3e-6,0.0}                   
31        make/o/t parameters_Raspberry =  {"vol fract Large","Radius Large (A)","SLD Large sphere (A-2)","vol fract Small", "Radius Small (A)","surface coverage","SLD Small sphere (A-2)","delta","SLD solvent (A-2)","bkgd (cm-1)"}
32        Edit parameters_Raspberry, coef_Raspberry
33       
34        Variable/G root:g_Raspberry
35        g_Raspberry := Raspberry(coef_Raspberry, ywave_Raspberry, xwave_Raspberry)
36        Display ywave_Raspberry vs xwave_Raspberry
37        ModifyGraph marker=29, msize=2, mode=4
38        ModifyGraph log=1,grid=1,mirror=2
39        Label bottom "q (\\S-1\\M) "
40        Label left "I(q) (cm\\S-1\\M)"
41        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
42       
43        AddModelToStrings("Raspberry","coef_Raspberry","parameters_Raspberry","Raspberry")
44//
45End
46
47
48//
49//this macro sets up all the necessary parameters and waves that are
50//needed to calculate the  smeared model function.
51//
52//no input parameters are necessary, it MUST use the experimental q-values
53// from the experimental data read in from an AVE/QSIG data file
54////////////////////////////////////////////////////
55// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
56Proc PlotSmearedRaspberry(str)                                                         
57        String str
58        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
59       
60        // if any of the resolution waves are missing => abort
61        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
62                Abort
63        endif
64       
65        SetDataFolder $("root:"+str)
66       
67        // Setup parameter table for model function
68        Make/O/D smear_coef_Raspberry = {0.05,5000,-4e-7,0.005,100,0.4,3.5e-6,0,6.3e-6,0.0}
69        make/o/t smear_parameters_Raspberry = {"vol fract Large","Radius Large (A)","SLD Large sphere (A-2)","vol fract Small", "Radius Small (A)","surface coverage","SLD Small sphere (A-2)","delta","SLD solvent (A-2)","bkgd (cm-1)"}
70        Edit smear_parameters_Raspberry,smear_coef_Raspberry                                    //display parameters in a table
71       
72        // output smeared intensity wave, dimensions are identical to experimental QSIG values
73        // make extra copy of experimental q-values for easy plotting
74        Duplicate/O $(str+"_q") smeared_Raspberry,smeared_qvals
75        SetScale d,0,0,"1/cm",smeared_Raspberry
76                                       
77        Variable/G gs_Raspberry=0
78        gs_Raspberry := fSmearedRaspberry(smear_coef_Raspberry,smeared_Raspberry,smeared_qvals) //this wrapper fills the STRUCT
79       
80        Display smeared_Raspberry vs smeared_qvals
81        ModifyGraph log=1,marker=29,msize=2,mode=4
82        Label bottom "q (\\S-1\\M)"
83        Label left "I(q) (cm\\S-1\\M)"
84        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
85       
86        SetDataFolder root:
87        AddModelToStrings("SmearedRaspberry","smear_coef_Raspberry","smear_parameters_Raspberry","Raspberry")
88End
89
90
91Macro CalcRaspberryStats()
92
93        Variable vfL,rL,sldL,vfS,rS,sldS,deltaS,delrhoL,delrhoS,bkg,sldSolv,qval        ,aSs   
94        vfL = coef_Raspberry[0]
95        rL = coef_Raspberry[1]
96        sldL = coef_Raspberry[2]
97        vfS = coef_Raspberry[3]
98        rS = coef_Raspberry[4]
99        aSs = coef_Raspberry[5]
100        sldS = coef_Raspberry[6]
101        deltaS = coef_Raspberry[7]
102        sldSolv = coef_Raspberry[8]
103        bkg = coef_Raspberry[9]
104
105        Variable fractionsmall,Np,VL,VS
106
107        VL = 4*pi/3*rL^3
108        VS = 4*pi/3*rS^3
109       
110        //Np = aSs*0.04*(rS/(rL+deltaS))*(VL/VS)
111        Np = aSs*4*((rL+deltaS)/rS)^2
112        fractionsmall = Np*vfL*VS/vfS/VL
113
114        print "Fraction small on large = "+num2str(fractionsmall)+"\r"
115        print "Number of small particles on large = "+num2str(Np)+"\r"
116
117End
118
119Proc PlotRaspberrySq()
120
121        setdatafolder root:
122
123        Variable vfL,rL,sldL,vfS,rS,sldS,deltaS,delrhoL,delrhoS,bkg,sldSolv,qval        ,aSs
124        vfL = coef_Raspberry[0]
125        rL = coef_Raspberry[1]
126        delrhoL = coef_Raspberry[2]
127        vfS = coef_Raspberry[3]
128        rS = coef_Raspberry[4]
129        aSs = coef_Raspberry[5]
130        delrhoS = coef_Raspberry[6]
131        deltaS = coef_Raspberry[7]
132                               
133        Duplicate/O xwave_Raspberry ywave_sfLS_Rasp     
134        Duplicate/O xwave_Raspberry ywave_sfSS_Rasp
135       
136        Variable psiL,psiS,vol,f2
137        Variable VL,VS,slT,Np,fSs
138
139        VL = 4*pi/3*rL^3
140        VS = 4*pi/3*rS^3
141        Np = aSs*4*((rL+deltaS)/rS)^2
142
143        ywave_sfLS_Rasp = fRaspBes(xwave_Raspberry,rL)*fRaspBes(xwave_Raspberry,rS)*(sin(xwave_Raspberry*(rL+deltaS*rS))/xwave_Raspberry/(rL+deltaS*rS))
144        ywave_sfSS_Rasp = fRaspBes(xwave_Raspberry,rS)*fRaspBes(xwave_Raspberry,rS)*(sin(xwave_Raspberry*(rL+deltaS*rS))/xwave_Raspberry/(rL+deltaS*rS))^2
145
146        Display ywave_sfLS_Rasp vs xwave_Raspberry
147        AppendToGraph ywave_sfSS_Rasp vs xwave_Raspberry
148        ModifyGraph log(bottom)=1
149
150End
151
152// nothing to change here
153//
154//AAO version, uses XOP if available
155// simply calls the original single point calculation with
156// a wave assignment (this will behave nicely if given point ranges)
157Function Raspberry(cw,yw,xw) : FitFunc
158        Wave cw,yw,xw
159       
160#if exists("RaspberryX")
161        yw = RaspberryX(cw,xw)
162#else
163        yw = fRaspberry(cw,xw)
164#endif
165        return(0)
166End
167
168
169// you should write your function to calculate the intensity
170// for a single q-value (that's the input parameter x)
171// based on the wave (array) of parameters that you send it (w)
172//
173// unsmeared model calculation
174//
175Function fRaspberry(w,x) : FitFunc
176        Wave w
177        Variable x
178       
179        // variables are:                                                       
180        //[0] volume fraction large spheres
181        //[1] radius large sphere ()
182        //[2] sld large sphere (-2)
183        //[3] volume fraction small spheres
184        //[4] fraction of small spheres at surface
185        //[5] radius small sphere (A)
186        //[6] sld small sphere
187        //[7] small sphere penetration (A)
188        //[8] sld solvent
189        //[9] background (cm-1)
190       
191        Variable vfL,rL,sldL,vfS,rS,sldS,deltaS,delrhoL,delrhoS,bkg,sldSolv,qval        ,aSs   
192        vfL = w[0]
193        rL = w[1]
194        sldL = w[2]
195        vfS = w[3]
196        rS = w[4]
197        aSs = w[5]
198        sldS = w[6]
199        deltaS = w[7]
200        sldSolv = w[8]
201        bkg = w[9]
202       
203        delrhoL = abs(sldL - sldSolv)
204        delrhoS = abs(sldS - sldSolv)   
205       
206        Variable VL,VS,Np,f2,fSs
207       
208        VL = 4*pi/3*rL^3
209        VS = 4*pi/3*rS^3
210       
211        //Np = vfS*fSs*VL/vfL/VS
212        //Np = aSs*4*(rS/(rL+deltaS))*(VL/VS)
213        Np = aSs*4*((rL+deltaS)/rS)^2
214       
215        fSs = Np*vfL*VS/vfS/VL
216       
217        Make/O/N=9 rasp_temp
218        rasp_temp[0] = w[0]
219        rasp_temp[1] = w[1]
220        rasp_temp[2] = delrhoL
221        rasp_temp[3] = w[3]
222        rasp_temp[4] = w[4]
223        rasp_temp[5] = w[5]
224        rasp_temp[6] = delrhoS
225        rasp_temp[7] = w[7]
226       
227        //f2 = (vfL*delrhoL^2*VL + vfS*fSs*Np*delrhoS^2*VS)*fRaspberryKernel(rasp_temp,x)
228        f2 = fRaspberryKernel(rasp_temp,x)
229        f2+= vfS*(1-fSs)*delrhoS^2*VS*fRaspBes(x,rS)*fRaspBes(x,rS)
230       
231        // normalize to single particle volume and convert to 1/cm
232        f2 *= 1e8               // [=] 1/cm
233       
234        return (f2+bkg) // Scale, then add in the background
235       
236End
237
238Function fRaspberryKernel(w,x)
239        Wave w
240        Variable x
241
242        // variables are:                                                       
243        //[0] volume fraction large spheres
244        //[1] radius large sphere ()
245        //[2] sld large sphere (-2)
246        //[3] volume fraction small spheres
247        //[4] fraction of small spheres at surface
248        //[5] radius small sphere (A)
249        //[6] sld small sphere
250        //[7] small sphere penetration (A)
251        //[8] sld solvent
252       
253        Variable vfL,rL,sldL,vfS,rS,sldS,deltaS,delrhoL,delrhoS,bkg,sldSolv,qval        ,aSs
254        vfL = w[0]
255        rL = w[1]
256        delrhoL = w[2]
257        vfS = w[3]
258        rS = w[4]
259        aSs = w[5]
260        delrhoS = w[6]
261        deltaS = w[7]
262                       
263        qval = x                //rename the input q-value, purely for readability
264               
265        Variable psiL,psiS,vol,f2
266        Variable sfLS,sfSS
267        Variable VL,VS,slT,Np,fSs
268
269        VL = 4*pi/3*rL^3
270        VS = 4*pi/3*rS^3
271
272        Np = aSs*4*(rS/(rL+deltaS))*VL/VS
273        //Np = aSs*4*((rL+deltaS)/rS)^2
274
275        fSs = Np*vfL*VS/vfS/VL
276
277        slT = delrhoL*VL + Np*delrhoS*VS
278
279        psiL = fRaspBes(qval,rL)
280        psiS = fRaspBes(qval,rS)
281
282        sfLS = psiL*psiS*(sin(qval*(rL+deltaS*rS))/qval/(rL+deltaS*rS))
283        sfSS = psiS*psiS*(sin(qval*(rL+deltaS*rS))/qval/(rL+deltaS*rS))^2
284               
285        f2 = delrhoL^2*VL^2*psiL^2
286        f2 += Np*delrhoS^2*VS^2*psiS^2
287        f2 += Np*(Np-1)*delrhoS^2*VS^2*sfSS
288        f2 += 2*Np*delrhoL*delrhoS*VL*VS*sfLS
289        if (f2 != 0)
290                f2 = f2/slT/slT
291        endif
292       
293        f2 = f2*(vfL*delrhoL^2*VL + vfS*fSs*Np*delrhoS^2*VS)
294       
295        return f2
296End
297
298Function fRaspBes(Qval,Rad)
299        Variable Qval,Rad
300       
301        Variable retval
302       
303        retval = 3*(sin(qval*rad)-qval*rad*cos(qval*rad))/qval^3/rad^3
304
305        return retval
306End
307
308///////////////////////////////////////////////////////////////
309// smeared model calculation
310//
311// you don't need to do anything with this function, as long as
312// your Raspberry works correctly, you get the resolution-smeared
313// version for free.
314//
315// this is all there is to the smeared model calculation!
316Function SmearedRaspberry(s) : FitFunc
317        Struct ResSmearAAOStruct &s
318
319//      the name of your unsmeared model (AAO) is the first argument
320        Smear_Model_76(Raspberry,s.coefW,s.xW,s.yW,s.resW)
321
322        return(0)
323End
324
325
326///////////////////////////////////////////////////////////////
327
328
329// nothing to change here
330//
331//wrapper to calculate the smeared model as an AAO-Struct
332// fills the struct and calls the ususal function with the STRUCT parameter
333//
334// used only for the dependency, not for fitting
335//
336Function fSmearedRaspberry(coefW,yW,xW)
337        Wave coefW,yW,xW
338       
339        String str = getWavesDataFolder(yW,0)
340        String DF="root:"+str+":"
341       
342        WAVE resW = $(DF+str+"_res")
343       
344        STRUCT ResSmearAAOStruct fs
345        WAVE fs.coefW = coefW   
346        WAVE fs.yW = yW
347        WAVE fs.xW = xW
348        WAVE fs.resW = resW
349       
350        Variable err
351        err = SmearedRaspberry(fs)
352       
353        return (0)
354End
Note: See TracBrowser for help on using the repository browser.