source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/NewModels_2008/Fractal_PolySphere_v40.ipf @ 595

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

XOPs added for CSParallelepiped, not for fractal_polysphere

Removed garbage from function popup list in SumSANSModels (changing the common filter function in PlotUtilsMacro?)

File size: 6.6 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.1
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// - basic subunit is a polydisperse (Schulz) sphere - SRK July 2008
11//
12// no XOP was written for this - it is not necessary
13//
14// Macro for fractal parameters added JGB 2004
15
16Proc PlotFractalPolySphere(num,qmin,qmax)                                               
17        Variable num=128,qmin=0.001,qmax=0.5
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_fraPolySph,ywave_fraPolySph                                     
23        xwave_fraPolySph = alog(log(qmin) + x*((log(qmax)-log(qmin))/num))                                     
24        Make/O/D coef_fraPolySph = {0.05,5,0.1,2,100,2e-6,6.35e-6,0}                                           
25        make/o/t parameters_fraPolySph = {"Volume Fraction (scale)","Block Radius (A)","block polydispersity (0,1)","fractal dimension","correlation length (A)","SLD block (A-2)","SLD solvent (A-2)","bkgd (cm^-1 sr^-1)"}           
26        Edit parameters_fraPolySph,coef_fraPolySph             
27       
28        Variable/G root:g_fraPolySph
29        g_fraPolySph := FractalPolySphere(coef_fraPolySph,ywave_fraPolySph,xwave_fraPolySph)                   
30        Display ywave_fraPolySph vs xwave_fraPolySph                                                   
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("FractalPolySphere","coef_fraPolySph","parameters_fraPolySph","fraPolySph")
37End
38
39// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
40Proc PlotSmearedFractalPolySphere(str)                                                         
41        String str
42        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
43       
44        // if any of the resolution waves are missing => abort
45        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
46                Abort
47        endif
48       
49        SetDataFolder $("root:"+str)
50       
51        // Setup parameter table for model function
52        Make/O/D smear_coef_fraPolySph =  {0.05,5,0.1,2,100,2e-6,6.35e-6,0}
53        make/o/t smear_parameters_fraPolySph = {"Volume Fraction (scale)","Block Radius (A)","block polydispersity (0,1)","fractal dimension","correlation length (A)","SLD block (A-2)","SLD solvent (A-2)","bkgd (cm^-1 sr^-1)"}
54        Edit smear_parameters_fraPolySph,smear_coef_fraPolySph                                  //display parameters in a table
55       
56        // output smeared intensity wave, dimensions are identical to experimental QSIG values
57        // make extra copy of experimental q-values for easy plotting
58        Duplicate/O $(str+"_q") smeared_fraPolySph,smeared_qvals                                //
59        SetScale d,0,0,"1/cm",smeared_fraPolySph                                                //
60                                       
61        Variable/G gs_fraPolySph=0
62        gs_fraPolySph := fSmearedFractalPolySphere(smear_coef_fraPolySph,smeared_fraPolySph,smeared_qvals)      //this wrapper fills the STRUCT
63       
64        Display smeared_fraPolySph vs smeared_qvals             
65        ModifyGraph log=1,marker=29,msize=2,mode=4
66        Label bottom "q (A\\S-1\\M)"
67        Label left "I(q) (cm\\S-1\\M)"
68        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
69       
70        SetDataFolder root:
71        AddModelToStrings("SmearedFractalPolySphere","smear_coef_fraPolySph","smear_parameters_fraPolySph","fraPolySph")
72End
73
74
75
76//calculates the physical parameters related to the
77//model parameters. See the reference at the top of the
78//file for details
79//
80// this macro is currently only appicable to the monodisperse case and must be appropriately
81// modified before use
82//
83//Macro NumberDensity_FractalPolySphere()
84//     
85//      Variable nden,phi,r0,Df,corr,s0,vpoly,i0,rg
86//     
87//      if(Exists("coef_fraPolySph")!=1)
88//              abort "You need to plot the unsmeared model first to create the coefficient table"
89//      Endif
90//     
91//      phi = coef_fraPolySph[0]   // volume fraction of building blocks
92//      r0 = coef_fraPolySph[1]    // building block radius
93//      Df = coef_fraPolySph[2]    // fractal dimension
94//      corr = coef_fraPolySph[3]  // fractal correlation length (of cluster)
95//     
96//      Print "mean building block radius (A) = ",r0
97//      Print "volume fraction = ",phi
98//     
99// //  average particle volume         
100//      vpoly = 4*Pi/3*r0^3
101//      nden = phi/vpoly                //nden in 1/A^3
102//      i0 = 1.0e8*phi*vpoly*(coef_fraPolySph[4]-coef_fraPolySph[5])^2  // 1/cm/sr
103//      rg = corr*( Df*(Df+1)/2 )^0.5
104//      s0 = exp(gammln(Df+1))*(corr/r0)^Df
105//      Print "number density (A^-3) = ",nden
106//      Print "Guinier radius (A) = ",rg
107//      Print "Aggregation number G = ",s0
108//      Print "Forward cross section of building blocks (cm-1 sr-1) I(0) = ",i0
109//      Print "Forward cross section of clusters (cm-1 sr-1) I(0) = ",i0*s0
110//End
111
112//AAO version, uses XOP if available
113// simply calls the original single point calculation with
114// a wave assignment (this will behave nicely if given point ranges)
115Function FractalPolySphere(cw,yw,xw) : FitFunc
116        Wave cw,yw,xw
117       
118#if exists("FractalPolySphereX")
119        yw = FractalPolySphereX(cw,xw)
120#else
121        yw = fFractalPolySphere(cw,xw)
122#endif
123        return(0)
124End
125
126//fractal scattering function
127Function fFractalPolySphere(w,x) :FitFunc
128        wave w
129        variable x
130       
131        variable r0,Df,corr,phi,sldp,sldm,bkg
132        variable pq,sq,ans,pd
133        phi=w[0]   // volume fraction of building block spheres...
134        r0=w[1]    //  radius of building block
135        pd = w[2]               // polydispersity of sphere
136        Df=w[3]     //  fractal dimension
137        corr=w[4] //  correlation length of fractal-like aggregates
138        sldp = w[5] // SLD of building block
139        sldm = w[6] // SLD of matrix or solution
140        bkg=w[7]  //  flat background
141       
142        //calculate P(q) for the spherical subunits, units cm-1 sr-1
143//      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
144        Make/O/D/N=6 tmp_SchSph
145        tmp_SchSph[0] = phi
146        tmp_SchSph[1] = r0
147        tmp_SchSph[2] = pd
148        tmp_SchSph[3] = sldp
149        tmp_SchSph[4] = sldm
150        tmp_SchSph[5] = 0
151
152#if exists("SchulzSpheresX")
153        pq = SchulzSpheresX(tmp_SchSph,x)
154#else
155        pq = fSchulzSpheres(tmp_SchSph,x)
156#endif
157
158        //calculate S(q)
159        sq = Df*exp(gammln(Df-1))*sin((Df-1)*atan(x*corr))
160        sq /= (x*r0)^Df * (1 + 1/(x*corr)^2)^((Df-1)/2)
161        sq += 1
162        //combine and return
163        ans = pq*sq + bkg
164
165        return (ans)
166End
167
168//wrapper to calculate the smeared model as an AAO-Struct
169// fills the struct and calls the ususal function with the STRUCT parameter
170//
171// used only for the dependency, not for fitting
172//
173Function fSmearedFractalPolySphere(coefW,yW,xW)
174        Wave coefW,yW,xW
175       
176        String str = getWavesDataFolder(yW,0)
177        String DF="root:"+str+":"
178       
179        WAVE resW = $(DF+str+"_res")
180       
181        STRUCT ResSmearAAOStruct fs
182        WAVE fs.coefW = coefW   
183        WAVE fs.yW = yW
184        WAVE fs.xW = xW
185        WAVE fs.resW = resW
186       
187        Variable err
188        err = SmearedFractalPolySphere(fs)
189       
190        return (0)
191End
192
193//the smeared model calculation
194Function SmearedFractalPolySphere(s) :FitFunc
195        Struct ResSmearAAOStruct &s
196
197//      the name of your unsmeared model (AAO) is the first argument
198        Smear_Model_20(FractalPolySphere,s.coefW,s.xW,s.yW,s.resW)
199
200        return(0)
201End
Note: See TracBrowser for help on using the repository browser.