1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma IgorVersion = 6.0 |
---|
3 | |
---|
4 | //////////////////////////////////////////////// |
---|
5 | // this procedure calculates the form factor of a sphere |
---|
6 | // |
---|
7 | // 06 NOV 98 SRK |
---|
8 | // |
---|
9 | // modified June 2007 to calculate all-at-once |
---|
10 | // and to use a structure for resolution information |
---|
11 | // |
---|
12 | //////////////////////////////////////////////// |
---|
13 | |
---|
14 | Proc PlotSphereForm(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 (A^-1) for model: " |
---|
18 | Prompt qmax "Enter maximum q-value (A^-1) for model: " |
---|
19 | |
---|
20 | Make/O/D/n=(num) xwave_sf,ywave_sf |
---|
21 | xwave_sf = alog(log(qmin) + x*((log(qmax)-log(qmin))/num)) |
---|
22 | Make/O/D coef_sf = {1.,60,1e-6,6.3e-6,0.01} |
---|
23 | make/o/t parameters_sf = {"scale","Radius (A)","SLD sphere (A-2)","SLD solvent (A-2)","bkgd (cm-1)"} |
---|
24 | Edit parameters_sf,coef_sf |
---|
25 | Variable/G root:g_sf=0 |
---|
26 | root:g_sf := SphereForm(coef_sf,ywave_sf,xwave_sf) // AAO calculation, "fake" dependency |
---|
27 | // ywave_sf := SphereForm(coef_sf,xwave_sf) //point calculation |
---|
28 | Display ywave_sf vs xwave_sf |
---|
29 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
30 | Label bottom "q (A\\S-1\\M)" |
---|
31 | Label left "Intensity (cm\\S-1\\M)" |
---|
32 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
33 | |
---|
34 | AddModelToStrings("SphereForm","coef_sf","parameters_sf","sf") |
---|
35 | End |
---|
36 | |
---|
37 | // - sets up a dependency to a wrapper, not the actual SmearedModelFunction |
---|
38 | Proc PlotSmearedSphereForm(str) |
---|
39 | String str |
---|
40 | Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4) |
---|
41 | |
---|
42 | // if any of the resolution waves are missing => abort |
---|
43 | if(ResolutionWavesMissingDF(str)) //updated to NOT use global strings (in GaussUtils) |
---|
44 | Abort |
---|
45 | endif |
---|
46 | |
---|
47 | SetDataFolder $("root:"+str) |
---|
48 | |
---|
49 | // Setup parameter table for model function |
---|
50 | Make/O/D smear_coef_sf = {1.,60,1e-6,6.3e-6,0.01} |
---|
51 | make/o/t smear_parameters_sf = {"scale","Radius (A)","SLD sphere (A-2)","SLD solvent (A-2)","bkgd (cm-1)"} |
---|
52 | Edit smear_parameters_sf,smear_coef_sf |
---|
53 | |
---|
54 | Duplicate/O $(str+"_q") smeared_sf,smeared_qvals |
---|
55 | SetScale d,0,0,"1/cm",smeared_sf |
---|
56 | |
---|
57 | Variable/G gs_sf=0 |
---|
58 | gs_sf := fSmearedSphereForm(smear_coef_sf,smeared_sf,smeared_qvals) //this wrapper fills the STRUCT |
---|
59 | Display smeared_sf vs smeared_qvals |
---|
60 | |
---|
61 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
62 | Label bottom "q (A\\S-1\\M)" |
---|
63 | Label left "Intensity (cm\\S-1\\M)" |
---|
64 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
65 | |
---|
66 | SetDataFolder root: |
---|
67 | AddModelToStrings("SmearedSphereForm","smear_coef_sf","smear_parameters_sf","sf") |
---|
68 | End |
---|
69 | |
---|
70 | //AAO version, uses XOP if available |
---|
71 | // simply calls the original single point calculation with |
---|
72 | // a wave assignment (this will behave nicely if given point ranges) |
---|
73 | Function SphereForm(cw,yw,xw) : FitFunc |
---|
74 | Wave cw,yw,xw |
---|
75 | |
---|
76 | #if exists("SphereFormX") |
---|
77 | yw = SphereFormX(cw,xw) |
---|
78 | #else |
---|
79 | yw = fSphereForm(cw,xw) |
---|
80 | #endif |
---|
81 | return(0) |
---|
82 | End |
---|
83 | |
---|
84 | /////////////////////////////////////////////////////////////// |
---|
85 | // unsmeared model calculation |
---|
86 | // this is a "regular" calculation at a single q-value |
---|
87 | /////////////////////////// |
---|
88 | Function fSphereForm(w,x) |
---|
89 | Wave w |
---|
90 | Variable x |
---|
91 | |
---|
92 | // variables are: |
---|
93 | //[0] scale |
---|
94 | //[1] radius (A) |
---|
95 | //[2] sld sphere (A-2) |
---|
96 | //[3] sld solv |
---|
97 | //[4] background (cm-1) |
---|
98 | |
---|
99 | Variable scale,radius,delrho,bkg,sldSph,sldSolv |
---|
100 | scale = w[0] |
---|
101 | radius = w[1] |
---|
102 | sldSph = w[2] |
---|
103 | sldSolv = w[3] |
---|
104 | bkg = w[4] |
---|
105 | |
---|
106 | delrho = sldSph - sldSolv |
---|
107 | // calculates scale * f^2/Vol where f=Vol*3*delrho*((sin(qr)-qrcos(qr))/qr^3 |
---|
108 | // and is rescaled to give [=] cm^-1 |
---|
109 | |
---|
110 | Variable bes,f,vol,f2 |
---|
111 | // |
---|
112 | //handle q==0 separately |
---|
113 | If(x==0) |
---|
114 | f = 4/3*pi*radius^3*delrho*delrho*scale*1e8 + bkg |
---|
115 | return(f) |
---|
116 | Endif |
---|
117 | |
---|
118 | bes = 3*(sin(x*radius)-x*radius*cos(x*radius))/x^3/radius^3 |
---|
119 | vol = 4*pi/3*radius^3 |
---|
120 | f = vol*bes*delrho // [=] A |
---|
121 | // normalize to single particle volume, convert to 1/cm |
---|
122 | f2 = f * f / vol * 1.0e8 // [=] 1/cm |
---|
123 | |
---|
124 | return (scale*f2+bkg) // Scale, then add in the background |
---|
125 | End |
---|
126 | |
---|
127 | |
---|
128 | //wrapper to calculate the smeared model as an AAO-Struct |
---|
129 | // fills the struct |
---|
130 | // calls the ususal function with the STRUCT parameter |
---|
131 | // |
---|
132 | // -- problem- this assumes USANS w/no matrix |
---|
133 | // -- needs experimental q-values to properly calculate the fitted curve?? is this true? |
---|
134 | // -- how to fill the struct if the type of data is unknown? |
---|
135 | // -- where do I find the matrix? |
---|
136 | // |
---|
137 | Function fSmearedSphereForm(coefW,yW,xW) |
---|
138 | Wave coefW,yW,xW |
---|
139 | |
---|
140 | String str = getWavesDataFolder(yW,0) |
---|
141 | String DF="root:"+str+":" |
---|
142 | |
---|
143 | WAVE resW = $(DF+str+"_res") |
---|
144 | |
---|
145 | STRUCT ResSmearAAOStruct fs |
---|
146 | WAVE fs.coefW = coefW //is this the proper way to populate? seems redundant... |
---|
147 | WAVE fs.yW = yW |
---|
148 | WAVE fs.xW = xW |
---|
149 | WAVE fs.resW = resW |
---|
150 | |
---|
151 | Variable err |
---|
152 | err = SmearedSphereForm(fs) |
---|
153 | |
---|
154 | return (0) |
---|
155 | End |
---|
156 | |
---|
157 | // smeared calculation, AAO and using a structure... |
---|
158 | // defined as as STRUCT, there can never be a dependency linked directly to this function |
---|
159 | // - so set a dependency to the wrapper |
---|
160 | // |
---|
161 | // like the unsmeared function, AAO is equivalent to a wave assignment to the point calculation |
---|
162 | // - but now the function passed is an AAO function |
---|
163 | // |
---|
164 | // Smear_Model_20() takes care of what calculation is done, depending on the resolution information |
---|
165 | // |
---|
166 | // |
---|
167 | Function SmearedSphereForm(s) : FitFunc |
---|
168 | Struct ResSmearAAOStruct &s |
---|
169 | |
---|
170 | ////the name of your unsmeared model is the first argument |
---|
171 | Smear_Model_20(SphereForm,s.coefW,s.xW,s.yW,s.resW) |
---|
172 | |
---|
173 | return(0) |
---|
174 | End |
---|
175 | |
---|