source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/NewModels_2006/Vesicle_UL_v40.ipf @ 633

Last change on this file since 633 was 633, checked in by srkline, 13 years ago

Corrected models to explicitly return proper values for I(q=0). There are some models that just can't be fixed, and these typically return NaN. Some, however, are simply numerically unstable at extreme conditions. Beware.

File size: 7.2 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.1
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 unilamellar vesicle
10//
11// the "scale" or "volume fraction" factor is the "material" volume fraction
12// - i.e. the volume fraction of surfactant added. NOT the excluded volume
13// of the vesicles, which can be much larger. See the Vesicle_Volume_N_Rg macro
14//
15// this excluded volume is accounted for in the structure factor calculations.
16//
17// a macro is also provided to calculate the number density, I(q=0)
18// the Rg, and all of the volumes of the particle.
19//
20// 13 JUL 04 SRK
21////////////////////////////////////////////////
22
23Proc PlotVesicleForm(num,qmin,qmax)
24        Variable num=128,qmin=0.001,qmax=0.7
25        Prompt num "Enter number of data points for model: "
26        Prompt qmin "Enter minimum q-value (A^-1) for model: "
27        Prompt qmax "Enter maximum q-value (A^-1) for model: "
28       
29        make/o/d/n=(num) xwave_vesicle,ywave_vesicle
30        xwave_vesicle =alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
31        make/o/d coef_vesicle = {1.,100,30,6.36e-6,0.5e-6,0}
32        make/o/t parameters_vesicle = {"scale","core radius (A)","shell thickness (A)","Core and Solvent SLD (A-2)","Shell SLD (A-2)","bkg (cm-1)"}
33        Edit parameters_vesicle,coef_vesicle
34       
35        Variable/G root:g_vesicle
36        g_vesicle := VesicleForm(coef_vesicle,ywave_vesicle,xwave_vesicle)
37        Display ywave_vesicle vs xwave_vesicle
38        ModifyGraph log=1,marker=29,msize=2,mode=4
39        Label bottom "q (A\\S-1\\M)"
40        Label left "Intensity (cm\\S-1\\M)"
41        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
42       
43        AddModelToStrings("VesicleForm","coef_vesicle","parameters_vesicle","vesicle")
44End
45
46///////////////////////////////////////////////////////////
47
48// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
49Proc PlotSmearedVesicleForm(str)                                                               
50        String str
51        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
52       
53        // if any of the resolution waves are missing => abort
54        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
55                Abort
56        endif
57       
58        SetDataFolder $("root:"+str)
59       
60        // Setup parameter table for model function
61        make/o/d smear_coef_vesicle = {1.,100,30,6.36e-6,0.5e-6,0}
62        make/o/t smear_parameters_vesicle = {"scale","core radius (A)","shell thickness (A)","Core and Solvent SLD (A-2)","Shell SLD (A-2)","bkg (cm-1)"}
63        Edit smear_parameters_vesicle,smear_coef_vesicle
64       
65        // output smeared intensity wave, dimensions are identical to experimental QSIG values
66        // make extra copy of experimental q-values for easy plotting
67       
68        Duplicate/O $(str+"_q") smeared_vesicle,smeared_qvals                           
69        SetScale d,0,0,"1/cm",smeared_vesicle                                                   
70                                       
71        Variable/G gs_vesicle=0
72        gs_vesicle := fSmearedVesicleForm(smear_coef_vesicle,smeared_vesicle,smeared_qvals)     //this wrapper fills the STRUCT
73       
74        Display smeared_vesicle vs smeared_qvals                                                                       
75        ModifyGraph log=1,marker=29,msize=2,mode=4
76        Label bottom "q (A\\S-1\\M)"
77        Label left "Intensity (cm\\S-1\\M)"
78        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
79       
80        SetDataFolder root:
81        AddModelToStrings("SmearedVesicleForm","smear_coef_vesicle","smear_parameters_vesicle","vesicle")
82End
83
84
85//AAO version, uses XOP if available
86// simply calls the original single point calculation with
87// a wave assignment (this will behave nicely if given point ranges)
88Function VesicleForm(cw,yw,xw) : FitFunc
89        Wave cw,yw,xw
90       
91#if exists("VesicleFormX")
92        yw = VesicleFormX(cw,xw)
93#else
94        yw = fVesicleForm(cw,xw)
95#endif
96        return(0)
97End
98
99///////////////////////////////////////////////////////////////
100// unsmeared model calculation
101///////////////////////////
102Function fVesicleForm(w,x) : FitFunc
103        Wave w
104        Variable x
105       
106        // variables are:
107        //[0] scale factor
108        //[1] radius of core [A]
109        //[2] thickness of the shell    [A]
110        //[3] SLD of the core and solvent[A-2]
111        //[4] SLD of the shell
112        //[5] background        [cm-1]
113       
114        // All inputs are in ANGSTROMS
115        //OUTPUT is normalized by the particle volume, and converted to [cm-1]
116       
117       
118        Variable scale,rcore,thick,rhocore,rhoshel,rhosolv,bkg
119        scale = w[0]
120        rcore = w[1]
121        thick = w[2]
122        rhocore = w[3]
123        rhosolv = rhocore
124        rhoshel = w[4]
125        bkg = w[5]
126       
127        // calculates scale *( f^2 + bkg)
128        Variable bes,f,vol,qr,contr,f2
129       
130        // core first, then add in shell
131        qr=x*rcore
132        contr = rhocore-rhoshel
133        if(qr == 0)
134                bes = 1
135        else
136                bes = 3*(sin(qr)-qr*cos(qr))/qr^3
137        endif
138        vol = 4*pi/3*rcore^3
139        f = vol*bes*contr
140        //now the shell
141        qr=x*(rcore+thick)
142        contr = rhoshel-rhosolv
143       
144        if(qr == 0)
145                bes = 1
146        else
147                bes = 3*(sin(qr)-qr*cos(qr))/qr^3
148        endif
149       
150        vol = 4*pi/3*(rcore+thick)^3
151        f += vol*bes*contr
152       
153        // normalize to the particle volume and rescale from [A-1] to [cm-1]
154        //note that for the vesicle model, the volume is ONLY the shell volume
155        vol = 4*pi/3*((rcore+thick)^3-rcore^3)
156        f2 = f*f/vol*1.0e8
157       
158        //scale if desired
159        f2 *= scale
160        // then add in the background
161        f2 += bkg
162       
163        return (f2)
164End
165
166//wrapper to calculate the smeared model as an AAO-Struct
167// fills the struct and calls the ususal function with the STRUCT parameter
168//
169// used only for the dependency, not for fitting
170//
171Function fSmearedVesicleForm(coefW,yW,xW)
172        Wave coefW,yW,xW
173       
174        String str = getWavesDataFolder(yW,0)
175        String DF="root:"+str+":"
176       
177        WAVE resW = $(DF+str+"_res")
178       
179        STRUCT ResSmearAAOStruct fs
180        WAVE fs.coefW = coefW   
181        WAVE fs.yW = yW
182        WAVE fs.xW = xW
183        WAVE fs.resW = resW
184       
185        Variable err
186        err = SmearedVesicleForm(fs)
187       
188        return (0)
189End
190
191// this is all there is to the smeared calculation!
192Function SmearedVesicleForm(s) :FitFunc
193        Struct ResSmearAAOStruct &s
194
195//      the name of your unsmeared model (AAO) is the first argument
196        Smear_Model_20(VesicleForm,s.coefW,s.xW,s.yW,s.resW)
197
198        return(0)
199End
200
201Macro Vesicle_Volume_N_Rg()
202        Variable totVol,core,shell,i0,nden,rhoCore,rhoShell,rhoSolvent
203        Variable phi
204       
205        if(Exists("coef_vesicle")!=1)
206                abort "You need to plot the unsmeared vesicle model first to create the coefficient table"
207        Endif
208        totvol=4*pi/3*(coef_vesicle[1]+coef_vesicle[2])^3
209        core=4*pi/3*(coef_vesicle[1])^3
210        shell = totVol-core
211       
212//      nden = phi/(shell volume) or phi/Vtotal
213        nden = coef_vesicle[0]/shell
214        rhoCore = coef_vesicle[3]
215        rhoShell = coef_vesicle[4]
216        rhoSolvent = rhoCore
217       
218        i0 = nden*shell*shell*(rhoCore-rhoShell)^2*1e8
219        Print "Total Volume [A^3] = ",totVol
220        Print "Core Volume [A^3] = ",core
221        Print "Shell Volume [A^3] = ",shell
222        Print "Material volume fraction = ",coef_vesicle[0]
223        Print "Excluded volume fraction = ",nden*totvol
224//      Print "I(q=0) = ",i0
225        Print "I(Q=0) = n Vshell^2(DR)^2 [1/cm] = ",i0
226        Print "Number Density [1/A^3]= ",nden
227//      Print "model I(0) = ",ywave_vesicle[0]
228//      Print "model/limit = ",ywave_vesicle[0]/i0
229       
230        CalcRg_Vesicle(coef_vesicle)
231End
232
233
234Function CalcRg_Vesicle(coef_vesicle)
235        Wave coef_vesicle
236
237        Variable Rc,Rsh,r1,r2,rs,ans
238       
239        Rc = coef_vesicle[1]
240        Rsh = Rc + coef_vesicle[2]
241        r1 = coef_vesicle[3]
242        r2 = coef_vesicle[4]
243        rs = coef_vesicle[3]
244       
245//      ans = 0
246//      ans = ( (r1-r2)/(r2-rs) )*Rc^5/Rsh^5 - 1
247//      ans /= ( (r1-r2)/(r2-rs) )*Rc^3/Rsh^3 - 1
248//      ans *= 3/5*Rsh^2
249//      Print "Rg of vesicle [A] = ",sqrt(ans)
250       
251        ans = 0
252        ans = Rc^5/Rsh^5 + 1
253        ans /= Rc^3/Rsh^3 + 1
254        ans *= 3/5*Rsh^2
255       
256        Print "Rg of vesicle [A] = ",sqrt(ans)
257End
Note: See TracBrowser for help on using the repository browser.