1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma IgorVersion = 6.0 |
---|
3 | |
---|
4 | // plots scattering from a mass fractal object |
---|
5 | // uses the model of Teixeria |
---|
6 | // |
---|
7 | // REFERENCE: J. Appl. Cryst. vol 21, p781-785 |
---|
8 | // Uses eq.1, 4, and 16 |
---|
9 | // |
---|
10 | // Macro for fractal parameters added JGB 2004 |
---|
11 | |
---|
12 | Proc PlotFractal(num,qmin,qmax) |
---|
13 | Variable num=128,qmin=0.001,qmax=0.5 |
---|
14 | Prompt num "Enter number of data points for model: " |
---|
15 | Prompt qmin "Enter minimum q-value (^-1) for model: " |
---|
16 | Prompt qmax "Enter maximum q-value (^-1) for model: " |
---|
17 | |
---|
18 | Make/O/D/n=(num) xwave_fra,ywave_fra |
---|
19 | xwave_fra = alog(log(qmin) + x*((log(qmax)-log(qmin))/num)) |
---|
20 | Make/O/D coef_fra = {0.05,5,2,100,2e-6,6.35e-6,0} |
---|
21 | make/o/t parameters_fra = {"Volume Fraction (scale)","Block Radius (A)","fractal dimension","correlation length (A)","SLD block (A-2)","SLD solvent (A-2)","bkgd (cm^-1 sr^-1)"} |
---|
22 | Edit parameters_fra,coef_fra |
---|
23 | |
---|
24 | Variable/G root:g_fra |
---|
25 | g_fra := Fractal(coef_fra,ywave_fra,xwave_fra) |
---|
26 | Display ywave_fra vs xwave_fra |
---|
27 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
28 | Label bottom "q (\\S-1\\M)" |
---|
29 | Label left "Intensity (cm\\S-1\\M)" |
---|
30 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
31 | End |
---|
32 | |
---|
33 | // - sets up a dependency to a wrapper, not the actual SmearedModelFunction |
---|
34 | Proc PlotSmearedFractal(str) |
---|
35 | String str |
---|
36 | Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4) |
---|
37 | |
---|
38 | // if any of the resolution waves are missing => abort |
---|
39 | if(ResolutionWavesMissingDF(str)) //updated to NOT use global strings (in GaussUtils) |
---|
40 | Abort |
---|
41 | endif |
---|
42 | |
---|
43 | SetDataFolder $("root:"+str) |
---|
44 | |
---|
45 | // Setup parameter table for model function |
---|
46 | Make/O/D smear_coef_fractal = {0.05,5,2,100,2e-6,6.35e-6,0} |
---|
47 | make/o/t smear_parameters_fractal = {"Volume Fraction (scale)","Block Radius (A)","fractal dimension","correlation length (A)","SLD block (A-2)","SLD solvent (A-2)","bkgd (cm^-1 sr^-1)"} |
---|
48 | Edit smear_parameters_fractal,smear_coef_fractal //display parameters in a table |
---|
49 | |
---|
50 | // output smeared intensity wave, dimensions are identical to experimental QSIG values |
---|
51 | // make extra copy of experimental q-values for easy plotting |
---|
52 | Duplicate/O $(str+"_q") smeared_fractal,smeared_qvals // |
---|
53 | SetScale d,0,0,"1/cm",smeared_fractal // |
---|
54 | |
---|
55 | Variable/G gs_fractal=0 |
---|
56 | gs_fractal := fSmearedFractal(smear_coef_fractal,smeared_fractal,smeared_qvals) //this wrapper fills the STRUCT |
---|
57 | |
---|
58 | Display smeared_fractal vs smeared_qvals |
---|
59 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
60 | Label bottom "q (\\S-1\\M)" |
---|
61 | Label left "I(q) (cm\\S-1\\M)" |
---|
62 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
63 | |
---|
64 | SetDataFolder root: |
---|
65 | End |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | //calculates the physical parameters related to the |
---|
70 | //model parameters. See the reference at the top of the |
---|
71 | //file for details |
---|
72 | Macro NumberDensity_Fractal() |
---|
73 | |
---|
74 | Variable nden,phi,r0,Df,corr,s0,vpoly,i0,rg |
---|
75 | |
---|
76 | if(WaveExists(coef_fra)==0) |
---|
77 | abort "You need to plot the model first to create the coefficient table" |
---|
78 | Endif |
---|
79 | |
---|
80 | phi = coef_fra[0] // volume fraction of building blocks |
---|
81 | r0 = coef_fra[1] // building block radius |
---|
82 | Df = coef_fra[2] // fractal dimension |
---|
83 | corr = coef_fra[3] // fractal correlation length (of cluster) |
---|
84 | |
---|
85 | Print "mean building block radius (A) = ",r0 |
---|
86 | Print "volume fraction = ",phi |
---|
87 | |
---|
88 | // average particle volume |
---|
89 | vpoly = 4*Pi/3*r0^3 |
---|
90 | nden = phi/vpoly //nden in 1/A^3 |
---|
91 | i0 = 1.0e8*phi*vpoly*(coef_fra[4]-coef_fra[5])^2 // 1/cm/sr |
---|
92 | rg = corr*( Df*(Df+1)/2 )^0.5 |
---|
93 | s0 = exp(gammln(Df+1))*(corr/r0)^Df |
---|
94 | Print "number density (A^-3) = ",nden |
---|
95 | Print "Guinier radius (A) = ",rg |
---|
96 | Print "Aggregation number G = ",s0 |
---|
97 | Print "Forward cross section of building blocks (cm-1 sr-1) I(0) = ",i0 |
---|
98 | Print "Forward cross section of clusters (cm-1 sr-1) I(0) = ",i0*s0 |
---|
99 | End |
---|
100 | |
---|
101 | //AAO version, uses XOP if available |
---|
102 | // simply calls the original single point calculation with |
---|
103 | // a wave assignment (this will behave nicely if given point ranges) |
---|
104 | Function Fractal(cw,yw,xw) : FitFunc |
---|
105 | Wave cw,yw,xw |
---|
106 | |
---|
107 | #if exists("FractalX") |
---|
108 | yw = FractalX(cw,xw) |
---|
109 | #else |
---|
110 | yw = fFractal(cw,xw) |
---|
111 | #endif |
---|
112 | return(0) |
---|
113 | End |
---|
114 | |
---|
115 | //fractal scattering function |
---|
116 | Function fFractal(w,x) :FitFunc |
---|
117 | wave w |
---|
118 | variable x |
---|
119 | |
---|
120 | variable r0,Df,corr,phi,sldp,sldm,bkg |
---|
121 | variable pq,sq,ans |
---|
122 | phi=w[0] // volume fraction of building block spheres... |
---|
123 | r0=w[1] // radius of building block |
---|
124 | Df=w[2] // fractal dimension |
---|
125 | corr=w[3] // correlation length of fractal-like aggregates |
---|
126 | sldp = w[4] // SLD of building block |
---|
127 | sldm = w[5] // SLD of matrix or solution |
---|
128 | bkg=w[6] // flat background |
---|
129 | |
---|
130 | //calculate P(q) for the spherical subunits, units cm-1 sr-1 |
---|
131 | pq = 1.0e8*phi*4/3*pi*r0^3*(sldp-sldm)^2*(3*(sin(x*r0) - x*r0*cos(x*r0))/(x*r0)^3)^2 |
---|
132 | |
---|
133 | //calculate S(q) |
---|
134 | sq = Df*exp(gammln(Df-1))*sin((Df-1)*atan(x*corr)) |
---|
135 | sq /= (x*r0)^Df * (1 + 1/(x*corr)^2)^((Df-1)/2) |
---|
136 | sq += 1 |
---|
137 | //combine and return |
---|
138 | ans = pq*sq + bkg |
---|
139 | |
---|
140 | return (ans) |
---|
141 | End |
---|
142 | |
---|
143 | //wrapper to calculate the smeared model as an AAO-Struct |
---|
144 | // fills the struct and calls the ususal function with the STRUCT parameter |
---|
145 | // |
---|
146 | // used only for the dependency, not for fitting |
---|
147 | // |
---|
148 | Function fSmearedFractal(coefW,yW,xW) |
---|
149 | Wave coefW,yW,xW |
---|
150 | |
---|
151 | String str = getWavesDataFolder(yW,0) |
---|
152 | String DF="root:"+str+":" |
---|
153 | |
---|
154 | WAVE resW = $(DF+str+"_res") |
---|
155 | |
---|
156 | STRUCT ResSmearAAOStruct fs |
---|
157 | WAVE fs.coefW = coefW |
---|
158 | WAVE fs.yW = yW |
---|
159 | WAVE fs.xW = xW |
---|
160 | WAVE fs.resW = resW |
---|
161 | |
---|
162 | Variable err |
---|
163 | err = SmearedFractal(fs) |
---|
164 | |
---|
165 | return (0) |
---|
166 | End |
---|
167 | |
---|
168 | //the smeared model calculation |
---|
169 | Function SmearedFractal(s) :FitFunc |
---|
170 | Struct ResSmearAAOStruct &s |
---|
171 | |
---|
172 | // the name of your unsmeared model (AAO) is the first argument |
---|
173 | s.yW = Smear_Model_20(Fractal,s.coefW,s.xW,s.resW) |
---|
174 | |
---|
175 | return(0) |
---|
176 | End |
---|