source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/CoreShell.ipf @ 146

Last change on this file since 146 was 146, checked in by srkline, 15 years ago

updated smeared function in CoreShell?

commented out test wrapper in Sphere

File size: 4.9 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 sphere with a core-shell structure
10//
11// 06 NOV 98 SRK
12////////////////////////////////////////////////
13
14Proc PlotCoreShellSphere(num,qmin,qmax)
15        Variable num=128,qmin=0.001,qmax=0.7
16        Prompt num "Enter number of data points for model: "
17        Prompt qmin "Enter minimum q-value (^-1) for model: "
18        Prompt qmax "Enter maximum q-value (^-1) for model: "
19       
20        make/o/d/n=(num) xwave_css,ywave_css
21        xwave_css =alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
22        make/o/d coef_css = {1.,60,10,1e-6,2e-6,3e-6,0.001}
23        make/o/t parameters_css = {"scale","core radius (A)","shell thickness (A)","Core SLD (A-2)","Shell SLD (A-2)","Solvent SLD (A-2)","bkg (cm-1)"}
24        Edit parameters_css,coef_css
25        Variable/G root:g_css
26        g_css := CoreShellForm(coef_css,ywave_css,xwave_css)
27//      ywave_css := CoreShellForm(coef_css,xwave_css)
28        Display ywave_css vs xwave_css
29        ModifyGraph log=1,marker=29,msize=2,mode=4
30        Label bottom "q (\\S-1\\M)"
31        Label left "Intensity (cm\\S-1\\M)"
32        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
33End
34
35///////////////////////////////////////////////////////////
36// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
37Proc PlotSmearedCoreShellSphere(str)                                                           
38        String str
39        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
40       
41        // if any of the resolution waves are missing => abort
42        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
43                Abort
44        endif
45       
46        SetDataFolder $("root:"+str)
47       
48        // Setup parameter table for model function
49        make/o/d smear_coef_css = {1.,60,10,1e-6,2e-6,3e-6,0.001}
50        make/o/t smear_parameters_css = {"scale","core radius (A)","shell thickness (A)","Core SLD (A-2)","Shell SLD (A-2)","Solvent SLD (A-2)","bkg (cm-1)"}
51        Edit smear_parameters_css,smear_coef_css
52       
53        // output smeared intensity wave, dimensions are identical to experimental QSIG values
54        // make extra copy of experimental q-values for easy plotting
55       
56        Duplicate/O $(str+"_q") smeared_css,smeared_qvals                               
57        SetScale d,0,0,"1/cm",smeared_css                                                       
58                                       
59        Variable/G gs_css=0
60        gs_css := fSmearedCoreShellForm(smear_coef_css,smeared_css,smeared_qvals)       //this wrapper fills the STRUCT
61       
62        Display smeared_css vs smeared_qvals                                                                   
63        ModifyGraph log=1,marker=29,msize=2,mode=4
64        Label bottom "q (\\S-1\\M)"
65        Label left "Intensity (cm\\S-1\\M)"
66        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
67       
68        SetDataFolder root:
69End
70
71
72//AAO version
73Function CoreShellForm(cw,yw,xw) : FitFunc
74        Wave cw,yw,xw
75
76#if exists("CoreShellFormX")
77        yw = CoreShellFormX(cw,xw)
78#else
79        yw = fCoreShellForm(cw,xw)
80#endif
81        return(0)
82End
83
84///////////////////////////////////////////////////////////////
85// unsmeared model calculation
86///////////////////////////
87Function fCoreShellForm(w,x) : FitFunc
88        Wave w
89        Variable x
90       
91        // variables are:
92        //[0] scale factor
93        //[1] radius of core []
94        //[2] thickness of the shell    []
95        //[3] SLD of the core   [-2]
96        //[4] SLD of the shell
97        //[5] SLD of the solvent
98        //[6] background        [cm-1]
99       
100        // All inputs are in ANGSTROMS
101        //OUTPUT is normalized by the particle volume, and converted to [cm-1]
102       
103       
104        Variable scale,rcore,thick,rhocore,rhoshel,rhosolv,bkg
105        scale = w[0]
106        rcore = w[1]
107        thick = w[2]
108        rhocore = w[3]
109        rhoshel = w[4]
110        rhosolv = w[5]
111        bkg = w[6]
112       
113        // calculates scale *( f^2 + bkg)
114        Variable bes,f,vol,qr,contr,f2
115       
116        // core first, then add in shell
117        qr=x*rcore
118        contr = rhocore-rhoshel
119        bes = 3*(sin(qr)-qr*cos(qr))/qr^3
120        vol = 4*pi/3*rcore^3
121        f = vol*bes*contr
122        //now the shell
123        qr=x*(rcore+thick)
124        contr = rhoshel-rhosolv
125        bes = 3*(sin(qr)-qr*cos(qr))/qr^3
126        vol = 4*pi/3*(rcore+thick)^3
127        f += vol*bes*contr
128       
129        // normalize to particle volume and rescale from [-1] to [cm-1]
130        f2 = f*f/vol*1.0e8
131       
132        //scale if desired
133        f2 *= scale
134        // then add in the background
135        f2 += bkg
136       
137        return (f2)
138End
139
140// this is all there is to the smeared calculation!
141Function SmearedCoreShellForm(s) :FitFunc
142        Struct ResSmearAAOStruct &s
143
144////the name of your unsmeared model is the first argument
145        Smear_Model_20(CoreShellForm,s.coefW,s.xW,s.yW,s.resW)
146
147        return(0)
148End
149
150//wrapper to calculate the smeared model as an AAO-Struct
151// fills the struct and calls the ususal function with the STRUCT parameter
152//
153// used only for the dependency, not for fitting
154//
155Function fSmearedCoreShellForm(coefW,yW,xW)
156        Wave coefW,yW,xW
157       
158        String str = getWavesDataFolder(yW,0)
159        String DF="root:"+str+":"
160       
161        WAVE resW = $(DF+str+"_res")
162       
163        STRUCT ResSmearAAOStruct fs
164        WAVE fs.coefW = coefW   
165        WAVE fs.yW = yW
166        WAVE fs.xW = xW
167        WAVE fs.resW = resW
168       
169        Variable err
170        err = SmearedCoreShellForm(fs)
171       
172        return (0)
173End
Note: See TracBrowser for help on using the repository browser.