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

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

(1) - cursors can now be used to select a subrange of USANS data to fit. This is done by th fit wrapper, assigning a subrange of resW to the struct

(2) all of the smeared model functions are now in the latest form of Smear_Model_N() that is NOT a pointwise calculation anymore, since the USANS matrix smearing in inherently not so.

File size: 15.7 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion = 6.0
3
4// be sure to include all the necessary files...
5#include "EffectiveDiameter"
6#include "CylinderForm"
7
8#include "HardSphereStruct"
9#include "HPMSA"
10#include "SquareWellStruct"
11#include "StickyHardSphereStruct"
12
13Proc PlotCylinder_HS(num,qmin,qmax)
14        Variable num=128,qmin=0.001,qmax=0.7
15        Prompt num "Enter number of data points for model: "
16        Prompt qmin "Enter minimum q-value (^-1) for model: "
17        Prompt qmax "Enter maximum q-value (^-1) for model: "
18       
19        Make/O/D/n=(num) xwave_CYL_HS,ywave_CYL_HS
20        xwave_CYL_HS =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
21        Make/O/D coef_CYL_HS = {0.01,20.,400,3.0e-6,0.01}
22        make/o/t parameters_CYL_HS = {"volume fraction","radius (A)","length (A)","contrast (A^-2)","incoh. bkg (cm^-1)"}
23        Edit parameters_CYL_HS,coef_CYL_HS
24       
25        Variable/G root:g_CYL_HS
26        g_CYL_HS := Cylinder_HS(coef_CYL_HS,ywave_CYL_HS,xwave_CYL_HS)
27        Display ywave_CYL_HS vs xwave_CYL_HS
28        ModifyGraph log=1,marker=29,msize=2,mode=4
29        Label bottom "q (\\S-1\\M)"
30        Label left "Intensity (cm\\S-1\\M)"
31
32        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
33End
34
35// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
36Proc PlotSmearedCylinder_HS(str)                                                               
37        String str
38        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
39       
40        // if any of the resolution waves are missing => abort
41        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
42                Abort
43        endif
44       
45        SetDataFolder $("root:"+str)
46       
47        // Setup parameter table for model function
48        Make/O/D smear_coef_CYL_HS = {0.01,20.,400,3.0e-6,0.01}
49        make/o/t smear_parameters_CYL_HS = {"volume fraction","radius (A)","length (A)","contrast (A^-2)","incoh. bkg (cm^-1)"}
50        Edit smear_parameters_CYL_HS,smear_coef_CYL_HS                                 
51       
52        // output smeared intensity wave, dimensions are identical to experimental QSIG values
53        // make extra copy of experimental q-values for easy plotting
54        Duplicate/O $(str+"_q") smeared_CYL_HS,smeared_qvals                           
55        SetScale d,0,0,"1/cm",smeared_CYL_HS                                                   
56                                       
57        Variable/G gs_CYL_HS=0
58        gs_CYL_HS := fSmearedCylinder_HS(smear_coef_CYL_HS,smeared_CYL_HS,smeared_qvals)        //this wrapper fills the STRUCT
59       
60        Display smeared_CYL_HS vs smeared_qvals                                                                 
61        ModifyGraph log=1,marker=29,msize=2,mode=4
62        Label bottom "q (\\S-1\\M)"
63        Label left "Intensity (cm\\S-1\\M)"
64
65        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
66       
67        SetDataFolder root:
68End
69               
70
71Function Cylinder_HS(w,yw,xw) : FitFunc
72        Wave w,yw,xw
73       
74        Variable inten,rad,len
75        rad=w[1]
76        len=w[2]
77       
78        //setup form factor coefficient wave
79        Make/O/D/N=5 form_CYL_HS
80        form_CYL_HS[0] = 1
81        form_CYL_HS[1] = w[1]
82        form_CYL_HS[2] = w[2]
83        form_CYL_HS[3] = w[3]
84        form_CYL_HS[4] = 0
85       
86        //setup structure factor coefficient wave
87        Make/O/D/N=2 struct_CYL_HS
88        struct_CYL_HS[0] = 0.5*DiamCyl(len,rad)
89        struct_CYL_HS[1] = w[0]
90       
91        //calculate each and combine
92        Duplicate/O xw temp_CYL_HS_PQ,temp_CYL_HS_SQ            //make waves for the AAO
93        CylinderForm(form_CYL_HS,temp_CYL_HS_PQ,xw)
94        HardSphereStruct(struct_CYL_HS,temp_CYL_HS_SQ,xw)
95        yw = temp_CYL_HS_PQ * temp_CYL_HS_SQ
96        yw *= w[0]
97        yw += w[4]
98       
99        //cleanup waves (don't do this - it takes a lot of time...)
100//      Killwaves/Z form_CYL_HS,struct_CYL_HS
101       
102        return (0)
103End
104
105Proc PlotCylinder_SW(num,qmin,qmax)
106        Variable num=128,qmin=0.001,qmax=0.7
107        Prompt num "Enter number of data points for model: "
108        Prompt qmin "Enter minimum q-value (^-1) for model: "
109        Prompt qmax "Enter maximum q-value (^-1) for model: "
110       
111        Make/O/D/n=(num) xwave_CYL_SW,ywave_CYL_SW
112        xwave_CYL_SW =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
113        Make/O/D coef_CYL_SW = {0.01,20.,400,3.0e-6,1.0,1.2,0.01}
114        make/o/t parameters_CYL_SW = {"volume fraction","radius (A)","length (A)","contrast (A^-2)","well depth (kT)","well width (diam.)","incoh. bkg (cm^-1)"}
115        Edit parameters_CYL_SW,coef_CYL_SW
116       
117        Variable/G root:g_CYL_SW
118        g_CYL_SW := Cylinder_SW(coef_CYL_SW,ywave_CYL_SW,xwave_CYL_SW)
119        Display ywave_CYL_SW vs xwave_CYL_SW
120        ModifyGraph log=1,marker=29,msize=2,mode=4
121        Label bottom "q (\\S-1\\M)"
122        Label left "Intensity (cm\\S-1\\M)"
123
124        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
125End
126
127// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
128Proc PlotSmearedCylinder_SW(str)                                                               
129        String str
130        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
131       
132        // if any of the resolution waves are missing => abort
133        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
134                Abort
135        endif
136       
137        SetDataFolder $("root:"+str)
138       
139        // Setup parameter table for model function
140        Make/O/D smear_coef_CYL_SW = {0.01,20.,400,3.0e-6,1.0,1.2,0.01}
141        make/o/t smear_parameters_CYL_SW = {"volume fraction","radius (A)","length (A)","contrast (A^-2)","well depth (kT)","well width (diam.)","incoh. bkg (cm^-1)"}
142        Edit smear_parameters_CYL_SW,smear_coef_CYL_SW                                 
143       
144        // output smeared intensity wave, dimensions are identical to experimental QSIG values
145        // make extra copy of experimental q-values for easy plotting
146        Duplicate/O $(str+"_q") smeared_CYL_SW,smeared_qvals                           
147        SetScale d,0,0,"1/cm",smeared_CYL_SW                                                   
148                                       
149        Variable/G gs_CYL_SW=0
150        gs_CYL_SW := fSmearedCylinder_SW(smear_coef_CYL_SW,smeared_CYL_SW,smeared_qvals)        //this wrapper fills the STRUCT
151       
152        Display smeared_CYL_SW vs smeared_qvals                                                                 
153        ModifyGraph log=1,marker=29,msize=2,mode=4
154        Label bottom "q (\\S-1\\M)"
155        Label left "Intensity (cm\\S-1\\M)"
156
157        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
158       
159        SetDataFolder root:
160End
161       
162
163Function Cylinder_SW(w,yw,xw) : FitFunc
164        Wave w,yw,xw
165       
166        Variable inten,rad,len
167        rad=w[1]
168        len=w[2]
169       
170        //setup form factor coefficient wave
171        Make/O/D/N=5 form_CYL_SW
172        form_CYL_SW[0] = 1
173        form_CYL_SW[1] = w[1]
174        form_CYL_SW[2] = w[2]
175        form_CYL_SW[3] = w[3]
176        form_CYL_SW[4] = 0
177       
178        //setup structure factor coefficient wave
179        Make/O/D/N=4 struct_CYL_SW
180        struct_CYL_SW[0] = 0.5*DiamCyl(len,rad)
181        struct_CYL_SW[1] = w[0]
182        struct_CYL_SW[2] = w[4]
183        struct_CYL_SW[3] = w[5]
184       
185        //calculate each and combine
186        Duplicate/O xw temp_CYL_SW_PQ,temp_CYL_SW_SQ            //make waves for the AAO
187        CylinderForm(form_CYL_SW,temp_CYL_SW_PQ,xw)
188        SquareWellStruct(struct_CYL_SW,temp_CYL_SW_SQ,xw)
189        yw = temp_CYL_SW_PQ * temp_CYL_SW_SQ
190        yw *= w[0]
191        yw += w[6]
192       
193        //cleanup waves
194//      Killwaves/Z form_CYL_SW,struct_CYL_SW
195       
196        return (0)
197End
198
199Proc PlotCylinder_SC(num,qmin,qmax)
200        Variable num=128,qmin=0.001,qmax=0.7
201        Prompt num "Enter number of data points for model: "
202        Prompt qmin "Enter minimum q-value (^-1) for model: "
203        Prompt qmax "Enter maximum q-value (^-1) for model: "
204       
205        if(!DataFolderExists(":HayPenMSA"))
206                NewDataFolder :HayPenMSA
207        endif
208        Make/O/D/N=17 :HayPenMSA:gMSAWave
209       
210        Make/O/D/n=(num) xwave_CYL_SC,ywave_CYL_SC
211        xwave_CYL_SC =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
212        Make/O/D coef_CYL_SC = {0.01,20.,400,3.0e-6,20,0,298,78,0.01}
213        make/o/t parameters_CYL_SC = {"volume fraction","radius (A)","length (A)","contrast (A^-2)","charge","movalent salt(M)","Temperature (K)","dielectric const","incoh. bkg (cm^-1)"}
214        Edit parameters_CYL_SC,coef_CYL_SC
215       
216        Variable/G root:g_CYL_SC
217        g_CYL_SC := Cylinder_SC(coef_CYL_SC,ywave_CYL_SC,xwave_CYL_SC)
218        Display ywave_CYL_SC vs xwave_CYL_SC
219        ModifyGraph log=1,marker=29,msize=2,mode=4
220        Label bottom "q (\\S-1\\M)"
221        Label left "Intensity (cm\\S-1\\M)"
222
223        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
224End
225
226// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
227Proc PlotSmearedCylinder_SC(str)                                                               
228        String str
229        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
230       
231        // if any of the resolution waves are missing => abort
232        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
233                Abort
234        endif
235       
236        SetDataFolder $("root:"+str)
237       
238        if(!DataFolderExists(":HayPenMSA"))
239                NewDataFolder :HayPenMSA
240        endif
241        Make/O/D/N=17 :HayPenMSA:gMSAWave
242       
243        // Setup parameter table for model function
244        Make/O/D smear_coef_CYL_SC = {0.01,20.,400,3.0e-6,20,0,298,78,0.01}
245        make/o/t smear_parameters_CYL_SC = {"volume fraction","radius (A)","length (A)","contrast (A^-2)","charge","movalent salt(M)","Temperature (K)","dielectric const","incoh. bkg (cm^-1)"}
246        Edit smear_parameters_CYL_SC,smear_coef_CYL_SC                                 
247       
248        // output smeared intensity wave, dimensions are identical to experimental QSIG values
249        // make extra copy of experimental q-values for easy plotting
250        Duplicate/O $(str+"_q") smeared_CYL_SC,smeared_qvals                           
251        SetScale d,0,0,"1/cm",smeared_CYL_SC                                                   
252                                       
253        Variable/G gs_CYL_SC=0
254        gs_CYL_SC := fSmearedCylinder_SC(smear_coef_CYL_SC,smeared_CYL_SC,smeared_qvals)        //this wrapper fills the STRUCT
255       
256        Display smeared_CYL_SC vs smeared_qvals                                                                 
257        ModifyGraph log=1,marker=29,msize=2,mode=4
258        Label bottom "q (\\S-1\\M)"
259        Label left "Intensity (cm\\S-1\\M)"
260
261        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
262       
263        SetDataFolder root:
264End
265
266
267Function Cylinder_SC(w,yw,xw) : FitFunc
268        Wave w,yw,xw
269       
270        Variable inten,rad,len
271        rad=w[1]
272        len=w[2]
273       
274        //setup form factor coefficient wave
275        Make/O/D/N=5 form_CYL_SC
276        form_CYL_SC[0] = 1
277        form_CYL_SC[1] = w[1]
278        form_CYL_SC[2] = w[2]
279        form_CYL_SC[3] = w[3]
280        form_CYL_SC[4] = 0
281       
282        //setup structure factor coefficient wave
283        Make/O/D/N=6 struct_CYL_SC
284        struct_CYL_SC[0] = DiamCyl(len,rad)
285        struct_CYL_SC[1] = w[4]
286        struct_CYL_SC[2] = w[0]
287        struct_CYL_SC[3] = w[6]
288        struct_CYL_SC[4] = w[5]
289        struct_CYL_SC[5] = w[7]
290       
291        //calculate each and combine
292        Duplicate/O xw temp_CYL_SC_PQ,temp_CYL_SC_SQ            //make waves for the AAO
293        CylinderForm(form_CYL_SC,temp_CYL_SC_PQ,xw)
294        HayterPenfoldMSA(struct_CYL_SC,temp_CYL_SC_SQ,xw)
295        yw = temp_CYL_SC_PQ * temp_CYL_SC_SQ
296        yw *= w[0]
297        yw += w[8]
298       
299        //cleanup waves
300//      Killwaves/Z form_CYL_SC,struct_CYL_SC
301       
302        return (0)
303End
304
305
306Proc PlotCylinder_SHS(num,qmin,qmax)
307        Variable num=128,qmin=0.001,qmax=0.7
308        Prompt num "Enter number of data points for model: "
309        Prompt qmin "Enter minimum q-value (^-1) for model: "
310        Prompt qmax "Enter maximum q-value (^-1) for model: "
311       
312        Make/O/D/n=(num) xwave_CYL_SHS,ywave_CYL_SHS
313        xwave_CYL_SHS =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
314        Make/O/D coef_CYL_SHS = {0.01,20.0,400,3.0e-6,0.05,0.2,0.01}
315        make/o/t parameters_CYL_SHS = {"volume fraction","radius (A)","length (A)","contrast (A^-2)","perturbation parameter (0.1)","stickiness, tau","incoh. bkg (cm^-1)"}
316        Edit parameters_CYL_SHS,coef_CYL_SHS
317       
318        Variable/G root:g_CYL_SHS
319        g_CYL_SHS := Cylinder_SHS(coef_CYL_SHS,ywave_CYL_SHS,xwave_CYL_SHS)
320        Display ywave_CYL_SHS vs xwave_CYL_SHS
321        ModifyGraph log=1,marker=29,msize=2,mode=4
322        Label bottom "q (\\S-1\\M)"
323        Label left "Intensity (cm\\S-1\\M)"
324
325        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
326End
327
328// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
329Proc PlotSmearedCylinder_SHS(str)                                                               
330        String str
331        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
332       
333        // if any of the resolution waves are missing => abort
334        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
335                Abort
336        endif
337       
338        SetDataFolder $("root:"+str)
339       
340        // Setup parameter table for model function
341        Make/O/D smear_coef_CYL_SHS = {0.01,20.0,400,3.0e-6,0.05,0.2,0.01}
342        make/o/t smear_parameters_CYL_SHS = {"volume fraction","radius (A)","length (A)","contrast (A^-2)","perturbation parameter (0.1)","stickiness, tau","incoh. bkg (cm^-1)"}
343        Edit smear_parameters_CYL_SHS,smear_coef_CYL_SHS                                       
344       
345        // output smeared intensity wave, dimensions are identical to experimental QSIG values
346        // make extra copy of experimental q-values for easy plotting
347        Duplicate/O $(str+"_q") smeared_CYL_SHS,smeared_qvals                           
348        SetScale d,0,0,"1/cm",smeared_CYL_SHS                                                   
349                                       
350        Variable/G gs_CYL_SHS=0
351        gs_CYL_SHS := fSmearedCylinder_SHS(smear_coef_CYL_SHS,smeared_CYL_SHS,smeared_qvals)    //this wrapper fills the STRUCT
352       
353        Display smeared_CYL_SHS vs smeared_qvals                                                                       
354        ModifyGraph log=1,marker=29,msize=2,mode=4
355        Label bottom "q (\\S-1\\M)"
356        Label left "Intensity (cm\\S-1\\M)"
357
358        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
359       
360        SetDataFolder root:
361End
362       
363
364Function Cylinder_SHS(w,yw,xw) : FitFunc
365        Wave w,yw,xw
366       
367        Variable inten,rad,len
368        rad=w[1]
369        len=w[2]
370       
371        //setup form factor coefficient wave
372        Make/O/D/N=5 form_CYL_SHS
373        form_CYL_SHS[0] = 1
374        form_CYL_SHS[1] = w[1]
375        form_CYL_SHS[2] = w[2]
376        form_CYL_SHS[3] = w[3]
377        form_CYL_SHS[4] = 0
378       
379        //setup structure factor coefficient wave
380        Make/O/D/N=4 struct_CYL_SHS
381        struct_CYL_SHS[0] = 0.5*DiamCyl(len,rad)
382        struct_CYL_SHS[1] = w[0]
383        struct_CYL_SHS[2] = w[4]
384        struct_CYL_SHS[3] = w[5]
385       
386        //calculate each and combine
387        Duplicate/O xw temp_CYL_SHS_PQ,temp_CYL_SHS_SQ          //make waves for the AAO
388        CylinderForm(form_CYL_SHS,temp_CYL_SHS_PQ,xw)
389        StickyHS_Struct(struct_CYL_SHS,temp_CYL_SHS_SQ,xw)
390        yw = temp_CYL_SHS_PQ * temp_CYL_SHS_SQ
391        yw *= w[0]
392        yw += w[6]
393       
394        //cleanup waves
395//      Killwaves/Z form_CYL_SHS,struct_CYL_SHS
396       
397        return (0)
398End
399
400
401
402// this is all there is to the smeared calculation!
403Function SmearedCylinder_HS(s) :FitFunc
404        Struct ResSmearAAOStruct &s
405
406//      the name of your unsmeared model is the first argument
407        Smear_Model_20(Cylinder_HS,s.coefW,s.xW,s.yW,s.resW)
408
409        return(0)
410End
411
412// this is all there is to the smeared calculation!
413Function SmearedCylinder_SW(s) :FitFunc
414        Struct ResSmearAAOStruct &s
415
416//      the name of your unsmeared model is the first argument
417        Smear_Model_20(Cylinder_SW,s.coefW,s.xW,s.yW,s.resW)
418
419        return(0)
420End
421
422// this is all there is to the smeared calculation!
423Function SmearedCylinder_SC(s) :FitFunc
424        Struct ResSmearAAOStruct &s
425
426//      the name of your unsmeared model is the first argument
427        Smear_Model_20(Cylinder_SC,s.coefW,s.xW,s.yW,s.resW)
428
429        return(0)
430End
431
432// this is all there is to the smeared calculation!
433Function SmearedCylinder_SHS(s) :FitFunc
434        Struct ResSmearAAOStruct &s
435
436//      the name of your unsmeared model is the first argument
437        Smear_Model_20(Cylinder_SHS,s.coefW,s.xW,s.yW,s.resW)
438
439        return(0)
440End
441
442//wrapper to calculate the smeared model as an AAO-Struct
443// fills the struct and calls the ususal function with the STRUCT parameter
444//
445// used only for the dependency, not for fitting
446//
447Function fSmearedCylinder_HS(coefW,yW,xW)
448        Wave coefW,yW,xW
449       
450        String str = getWavesDataFolder(yW,0)
451        String DF="root:"+str+":"
452       
453        WAVE resW = $(DF+str+"_res")
454       
455        STRUCT ResSmearAAOStruct fs
456        WAVE fs.coefW = coefW   
457        WAVE fs.yW = yW
458        WAVE fs.xW = xW
459        WAVE fs.resW = resW
460       
461        Variable err
462        err = SmearedCylinder_HS(fs)
463       
464        return (0)
465End
466
467//wrapper to calculate the smeared model as an AAO-Struct
468// fills the struct and calls the ususal function with the STRUCT parameter
469//
470// used only for the dependency, not for fitting
471//
472Function fSmearedCylinder_SW(coefW,yW,xW)
473        Wave coefW,yW,xW
474       
475        String str = getWavesDataFolder(yW,0)
476        String DF="root:"+str+":"
477       
478        WAVE resW = $(DF+str+"_res")
479       
480        STRUCT ResSmearAAOStruct fs
481        WAVE fs.coefW = coefW   
482        WAVE fs.yW = yW
483        WAVE fs.xW = xW
484        WAVE fs.resW = resW
485       
486        Variable err
487        err = SmearedCylinder_SW(fs)
488       
489        return (0)
490End
491
492//wrapper to calculate the smeared model as an AAO-Struct
493// fills the struct and calls the ususal function with the STRUCT parameter
494//
495// used only for the dependency, not for fitting
496//
497Function fSmearedCylinder_SC(coefW,yW,xW)
498        Wave coefW,yW,xW
499       
500        String str = getWavesDataFolder(yW,0)
501        String DF="root:"+str+":"
502       
503        WAVE resW = $(DF+str+"_res")
504       
505        STRUCT ResSmearAAOStruct fs
506        WAVE fs.coefW = coefW   
507        WAVE fs.yW = yW
508        WAVE fs.xW = xW
509        WAVE fs.resW = resW
510       
511        Variable err
512        err = SmearedCylinder_SC(fs)
513       
514        return (0)
515End
516
517//wrapper to calculate the smeared model as an AAO-Struct
518// fills the struct and calls the ususal function with the STRUCT parameter
519//
520// used only for the dependency, not for fitting
521//
522Function fSmearedCylinder_SHS(coefW,yW,xW)
523        Wave coefW,yW,xW
524       
525        String str = getWavesDataFolder(yW,0)
526        String DF="root:"+str+":"
527       
528        WAVE resW = $(DF+str+"_res")
529       
530        STRUCT ResSmearAAOStruct fs
531        WAVE fs.coefW = coefW   
532        WAVE fs.yW = yW
533        WAVE fs.xW = xW
534        WAVE fs.resW = resW
535       
536        Variable err
537        err = SmearedCylinder_SHS(fs)
538       
539        return (0)
540End
Note: See TracBrowser for help on using the repository browser.