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

Last change on this file since 151 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.3 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
6#include "Sphere"
7
8#include "HardSphereStruct"
9#include "HPMSA"
10#include "SquareWellStruct"
11#include "StickyHardSphereStruct"
12
13Proc PlotSphere_HS(num,qmin,qmax)                                               
14        Variable num=256,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 the normal model waves
20        Make/O/D/n=(num) xwave_S_HS,ywave_S_HS                                 
21        xwave_S_HS =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))                                   
22        Make/O/D coef_S_HS = {0.1,60,1e-6,0.01}                                         
23        make/o/t parameters_S_HS = {"volume fraction","Radius (A)","contrast (-2)","bkgd (cm-1)"}             
24        Edit/K=1 parameters_S_HS,coef_S_HS
25        Variable/G root:g_S_HS                                         
26        g_S_HS := Sphere_HS(coef_S_HS,ywave_S_HS,xwave_S_HS)                   
27//      ywave_S_HS := Sphere_HS(coef_S_HS,xwave_S_HS)                   
28        Display/K=1 ywave_S_HS vs xwave_S_HS                                                   
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
33        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
34End
35
36// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
37Proc PlotSmearedSphere_HS(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_S_HS = {0.1,60,1e-6,0.01}                                           
50        make/o/t smear_parameters_S_HS = {"volume fraction","Radius (A)","contrast (-2)","bkgd (cm-1)"}               
51        Edit smear_parameters_S_HS,smear_coef_S_HS                                     
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        Duplicate/O $(str+"_q") smeared_S_HS,smeared_qvals                             
56        SetScale d,0,0,"1/cm",smeared_S_HS                                                     
57                                       
58        Variable/G gs_S_HS=0
59        gs_S_HS := fSmearedSphere_HS(smear_coef_S_HS,smeared_S_HS,smeared_qvals)        //this wrapper fills the STRUCT
60       
61        Display smeared_S_HS vs smeared_qvals                                                                   
62        ModifyGraph log=1,marker=29,msize=2,mode=4
63        Label bottom "q (\\S-1\\M)"
64        Label left "Intensity (cm\\S-1\\M)"
65
66        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
67       
68        SetDataFolder root:
69End
70
71
72//AAO function
73Function Sphere_HS(w,yw,xw) : FitFunc
74        Wave w,yw,xw
75               
76        //setup form factor coefficient wave
77        Make/O/D/N=4 form_S_HS
78        form_S_HS[0] = 1
79        form_S_HS[1] = w[1]
80        form_S_HS[2] = w[2]
81        form_S_HS[3] = 0
82       
83        //setup structure factor coefficient wave
84        Make/O/D/N=2 struct_S_HS
85        struct_S_HS[0] = w[1]
86        struct_S_HS[1] = w[0]
87       
88        //calculate each and combine
89        Duplicate/O xw temp_S_HS_PQ,temp_S_HS_SQ                //make waves for the AAO
90        SphereForm(form_S_HS,temp_S_HS_PQ,xw)
91        HardSphereStruct(struct_S_HS,temp_S_HS_SQ,xw)
92        yw = temp_S_HS_PQ * temp_S_HS_SQ
93        yw *= w[0]
94        yw += w[3]
95       
96        //cleanup waves
97        //Killwaves/Z form_S_HS,struct_S_HS
98       
99        return (0)
100End
101
102/////////////////////////////////
103Proc PlotSphere_SW(num,qmin,qmax)                                               
104        Variable num=256,qmin=0.001,qmax=0.7
105        Prompt num "Enter number of data points for model: "
106        Prompt qmin "Enter minimum q-value (^-1) for model: "
107        Prompt qmax "Enter maximum q-value (^-1) for model: "
108       
109        ///
110        Make/O/D/N=4 form_S_SW
111        Make/O/D/N=4 struct_S_SW
112        ///
113        Make/O/D/n=(num) xwave_S_SW,ywave_S_SW                                 
114        xwave_S_SW =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))                                   
115        Make/O/D coef_S_SW = {0.1,60,1e-6,1.0,1.2,0.01}                                         
116        make/o/t parameters_S_SW = {"volume fraction","Radius (A)","contrast (-2)","well depth (kT)","well width (diam.)","bkgd (cm-1)"}               
117        Edit/K=1 parameters_S_SW,coef_S_SW     
118        Variable/G root:g_S_SW                                                 
119        g_S_SW := Sphere_SW(coef_S_SW,ywave_S_SW,xwave_S_SW)                   
120//      ywave_S_SW := Sphere_SW(coef_S_SW,xwave_S_SW)                   
121        Display/K=1 ywave_S_SW vs xwave_S_SW                                                   
122        ModifyGraph log=1,marker=29,msize=2,mode=4                     
123        Label bottom "q (\\S-1\\M)"
124        Label left "Intensity (cm\\S-1\\M)"                                     
125
126        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
127End
128
129// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
130Proc PlotSmearedSphere_SW(str)                                                         
131        String str
132        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
133       
134        // if any of the resolution waves are missing => abort
135        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
136                Abort
137        endif
138       
139        SetDataFolder $("root:"+str)
140       
141        // Setup parameter table for model function
142        Make/O/D smear_coef_S_SW = {0.1,60,1e-6,1.0,1.2,0.01}                                           
143        make/o/t smear_parameters_S_SW = {"volume fraction","Radius (A)","contrast (-2)","well depth (kT)","well width (diam.)","bkgd (cm-1)"}         
144        Edit smear_parameters_S_SW,smear_coef_S_SW                                     
145       
146        // output smeared intensity wave, dimensions are identical to experimental QSIG values
147        // make extra copy of experimental q-values for easy plotting
148        Duplicate/O $(str+"_q") smeared_S_SW,smeared_qvals                             
149        SetScale d,0,0,"1/cm",smeared_S_SW                                                     
150                                       
151        Variable/G gs_S_SW=0
152        gs_S_SW := fSmearedSphere_SW(smear_coef_S_SW,smeared_S_SW,smeared_qvals)        //this wrapper fills the STRUCT
153       
154        Display smeared_S_SW vs smeared_qvals                                                                   
155        ModifyGraph log=1,marker=29,msize=2,mode=4
156        Label bottom "q (\\S-1\\M)"
157        Label left "Intensity (cm\\S-1\\M)"
158
159        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
160       
161        SetDataFolder root:
162End
163       
164
165//AAO function
166Function Sphere_SW(w,yw,xw) : FitFunc
167        Wave w,yw,xw
168               
169        //setup form factor coefficient wave
170        Make/O/D/N=4 form_S_SW
171        form_S_SW[0] = 1
172        form_S_SW[1] = w[1]
173        form_S_SW[2] = w[2]
174        form_S_SW[3] = 0
175       
176        //setup structure factor coefficient wave
177        Make/O/D/N=4 struct_S_SW
178        struct_S_SW[0] = w[1]
179        struct_S_SW[1] = w[0]
180        struct_S_SW[2] = w[3]
181        struct_S_SW[3] = w[4]
182       
183        //calculate each and combine
184        Duplicate/O xw temp_S_SW_PQ,temp_S_SW_SQ
185        SphereForm(form_S_SW,temp_S_SW_PQ,xw)
186        SquareWellStruct(struct_S_SW,temp_S_SW_SQ,xw)
187        yw = temp_S_SW_PQ * temp_S_SW_SQ
188        yw *= w[0]
189        yw += w[5]
190       
191        //cleanup waves
192        //Killwaves/Z form_S_SW,struct_S_SW
193       
194        return (0)
195End
196
197/////////////////////////////////
198Proc PlotSphere_SC(num,qmin,qmax)                                               
199        Variable num=256,qmin=0.001,qmax=0.7
200        Prompt num "Enter number of data points for model: "
201        Prompt qmin "Enter minimum q-value (^-1) for model: "
202        Prompt qmax "Enter maximum q-value (^-1) for model: "
203       
204        if(!DataFolderExists(":HayPenMSA"))
205                NewDataFolder :HayPenMSA
206        endif
207        Make/O/D/N=17 :HayPenMSA:gMSAWave
208       
209        ///
210        Make/O/D/n=(num) xwave_S_SC,ywave_S_SC                                 
211        xwave_S_SC =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))                           
212        Make/O/D coef_S_SC = {0.2,50,3e-6,20,0,298,78,0.0001}                                           
213        make/o/t parameters_S_SC = {"volume fraction","Radius (A)","contrast (-2)","charge","movalent salt(M)","Temperature (K)","dielectric const","bkgd (cm-1)"}             
214        Edit/K=1 parameters_S_SC,coef_S_SC
215        Variable/G root:g_S_SC                                                 
216        g_S_SC := Sphere_SC(coef_S_SC,ywave_S_SC,xwave_S_SC)                   
217//      ywave_S_SC := Sphere_SC(coef_S_SC,xwave_S_SC)                   
218        Display/K=1 ywave_S_SC vs xwave_S_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 PlotSmearedSphere_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_S_SC = {0.2,50,3e-6,20,0,298,78,0.0001}                                             
245        make/o/t smear_parameters_S_SC = {"volume fraction","Radius (A)","contrast (-2)","charge","movalent salt(M)","Temperature (K)","dielectric const","bkgd (cm-1)"}               
246        Edit smear_parameters_S_SC,smear_coef_S_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_S_SC,smeared_qvals                             
251        SetScale d,0,0,"1/cm",smeared_S_SC                                                     
252                                       
253        Variable/G gs_S_SC=0
254        gs_S_SC := fSmearedSphere_SC(smear_coef_S_SC,smeared_S_SC,smeared_qvals)        //this wrapper fills the STRUCT
255       
256        Display smeared_S_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
267//AAO function
268Function Sphere_SC(w,yw,xw) : FitFunc
269        Wave w,yw,xw
270
271        //setup form factor coefficient wave
272        Make/O/D/N=4 form_S_SC
273        form_S_SC[0] = 1
274        form_S_SC[1] = w[1]
275        form_S_SC[2] = w[2]
276        form_S_SC[3] = 0
277       
278        //setup structure factor coefficient wave
279        Make/O/D/N=6 struct_S_SC
280        struct_S_SC[0] = 2*w[1]         //diameter
281        struct_S_SC[1] = w[3]
282        struct_S_SC[2] = w[0]
283        struct_S_SC[3] = w[5]
284        struct_S_SC[4] = w[4]
285        struct_S_SC[5] = w[6]
286       
287        //calculate each and combine
288        Duplicate/O xw temp_S_SC_PQ,temp_S_SC_SQ
289        SphereForm(form_S_SC,temp_S_SC_PQ,xw)
290        HayterPenfoldMSA(struct_S_SC,temp_S_SC_SQ,xw)
291        yw = temp_S_SC_PQ * temp_S_SC_SQ
292        yw *= w[0]
293        yw += w[7]
294       
295        //cleanup waves
296        //Killwaves/Z form_S_SC,struct_S_SC
297        return (0)
298End
299
300/////////////////////////////////
301Proc PlotSphere_SHS(num,qmin,qmax)                                             
302        Variable num=256,qmin=0.001,qmax=0.7
303        Prompt num "Enter number of data points for model: "
304        Prompt qmin "Enter minimum q-value (^-1) for model: "
305        Prompt qmax "Enter maximum q-value (^-1) for model: "
306       
307        ///
308        Make/O/D/N=4 form_S_SHS
309        Make/O/D/N=4 struct_S_SHS
310        ///
311        Make/O/D/n=(num) xwave_S_SHS,ywave_S_SHS                                       
312        xwave_S_SHS =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))                                 
313        Make/O/D coef_S_SHS = {0.1,60,1e-6,0.05,0.2,0.01}                                               
314        make/o/t parameters_S_SHS = {"volume fraction","Radius (A)","contrast (-2)","perturbation parameter (0.1)","stickiness, tau","bkgd (cm-1)"}           
315        Edit/K=1 parameters_S_SHS,coef_S_SHS
316        Variable/G root:g_S_SHS                                         
317        g_S_SHS := Sphere_SHS(coef_S_SHS,ywave_S_SHS,xwave_S_SHS)                       
318//      ywave_S_SHS := Sphere_SHS(coef_S_SHS,xwave_S_SHS)                       
319        Display/K=1 ywave_S_SHS vs xwave_S_SHS                                                 
320        ModifyGraph log=1,marker=29,msize=2,mode=4                     
321        Label bottom "q (\\S-1\\M)"
322        Label left "Intensity (cm\\S-1\\M)"                                     
323
324        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
325End
326
327// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
328Proc PlotSmearedSphere_SHS(str)                                                         
329        String str
330        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
331       
332        // if any of the resolution waves are missing => abort
333        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
334                Abort
335        endif
336       
337        SetDataFolder $("root:"+str)
338       
339        // Setup parameter table for model function
340        Make/O/D smear_coef_S_SHS = {0.1,60,1e-6,0.05,0.2,0.01}                                         
341        make/o/t smear_parameters_S_SHS = {"volume fraction","Radius (A)","contrast (-2)","perturbation parameter (0.1)","stickiness, tau","bkgd (cm-1)"}             
342        Edit smear_parameters_S_SHS,smear_coef_S_SHS                                   
343       
344        // output smeared intensity wave, dimensions are identical to experimental QSIG values
345        // make extra copy of experimental q-values for easy plotting
346        Duplicate/O $(str+"_q") smeared_S_SHS,smeared_qvals                             
347        SetScale d,0,0,"1/cm",smeared_S_SHS                                                     
348                                       
349        Variable/G gs_S_SHS=0
350        gs_S_SHS := fSmearedSphere_SHS(smear_coef_S_SHS,smeared_S_SHS,smeared_qvals)    //this wrapper fills the STRUCT
351       
352        Display smeared_S_SHS vs smeared_qvals                                                                 
353        ModifyGraph log=1,marker=29,msize=2,mode=4
354        Label bottom "q (\\S-1\\M)"
355        Label left "Intensity (cm\\S-1\\M)"
356
357        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
358       
359        SetDataFolder root:
360End
361
362
363//AAO function
364Function Sphere_SHS(w,yw,xw) : FitFunc
365        Wave w,yw,xw
366       
367        //setup form factor coefficient wave
368        Make/O/D/N=4 form_S_SHS
369        form_S_SHS[0] = 1
370        form_S_SHS[1] = w[1]
371        form_S_SHS[2] = w[2]
372        form_S_SHS[3] = 0
373       
374        //setup structure factor coefficient wave
375        Make/O/D/N=4 struct_S_SHS
376        struct_S_SHS[0] = w[1]
377        struct_S_SHS[1] = w[0]
378        struct_S_SHS[2] = w[3]
379        struct_S_SHS[3] = w[4]
380       
381        //calculate each and combine
382        Duplicate/O xw temp_S_SHS_PQ,temp_S_SHS_SQ
383        SphereForm(form_S_SHS,temp_S_SHS_PQ,xw)
384        StickyHS_Struct(struct_S_SHS,temp_S_SHS_SQ,xw)
385        yw = temp_S_SHS_PQ * temp_S_SHS_SQ
386        yw *= w[0]
387        yw += w[5]
388       
389        //cleanup waves
390        //Killwaves/Z form_S_SHS,struct_S_SHS
391       
392        return (0)
393End
394
395
396
397// this is all there is to the smeared calculation!
398Function SmearedSphere_HS(s) :FitFunc
399        Struct ResSmearAAOStruct &s
400
401//      the name of your unsmeared model is the first argument
402        Smear_Model_20(Sphere_HS,s.coefW,s.xW,s.yW,s.resW)
403
404        return(0)
405End
406 
407// this is all there is to the smeared calculation!
408Function SmearedSphere_SW(s) :FitFunc
409        Struct ResSmearAAOStruct &s
410
411//      the name of your unsmeared model is the first argument
412        Smear_Model_20(Sphere_SW,s.coefW,s.xW,s.yW,s.resW)
413
414        return(0)
415End
416
417// this is all there is to the smeared calculation!
418Function SmearedSphere_SC(s) :FitFunc
419        Struct ResSmearAAOStruct &s
420
421//      the name of your unsmeared model is the first argument
422        Smear_Model_20(Sphere_SC,s.coefW,s.xW,s.yW,s.resW)
423
424        return(0)
425End
426
427// this is all there is to the smeared calculation!
428Function SmearedSphere_SHS(s) :FitFunc
429        Struct ResSmearAAOStruct &s
430
431//      the name of your unsmeared model is the first argument
432        Smear_Model_20(Sphere_SHS,s.coefW,s.xW,s.yW,s.resW)
433
434        return(0)
435End
436
437//wrapper to calculate the smeared model as an AAO-Struct
438// fills the struct and calls the ususal function with the STRUCT parameter
439//
440// used only for the dependency, not for fitting
441//
442Function fSmearedSphere_HS(coefW,yW,xW)
443        Wave coefW,yW,xW
444       
445        String str = getWavesDataFolder(yW,0)
446        String DF="root:"+str+":"
447       
448        WAVE resW = $(DF+str+"_res")
449       
450        STRUCT ResSmearAAOStruct fs
451        WAVE fs.coefW = coefW   
452        WAVE fs.yW = yW
453        WAVE fs.xW = xW
454        WAVE fs.resW = resW
455       
456        Variable err
457        err = SmearedSphere_HS(fs)
458       
459        return (0)
460End
461
462//wrapper to calculate the smeared model as an AAO-Struct
463// fills the struct and calls the ususal function with the STRUCT parameter
464//
465// used only for the dependency, not for fitting
466//
467Function fSmearedSphere_SW(coefW,yW,xW)
468        Wave coefW,yW,xW
469       
470        String str = getWavesDataFolder(yW,0)
471        String DF="root:"+str+":"
472       
473        WAVE resW = $(DF+str+"_res")
474       
475        STRUCT ResSmearAAOStruct fs
476        WAVE fs.coefW = coefW   
477        WAVE fs.yW = yW
478        WAVE fs.xW = xW
479        WAVE fs.resW = resW
480       
481        Variable err
482        err = SmearedSphere_SW(fs)
483       
484        return (0)
485End
486
487//wrapper to calculate the smeared model as an AAO-Struct
488// fills the struct and calls the ususal function with the STRUCT parameter
489//
490// used only for the dependency, not for fitting
491//
492Function fSmearedSphere_SC(coefW,yW,xW)
493        Wave coefW,yW,xW
494       
495        String str = getWavesDataFolder(yW,0)
496        String DF="root:"+str+":"
497       
498        WAVE resW = $(DF+str+"_res")
499       
500        STRUCT ResSmearAAOStruct fs
501        WAVE fs.coefW = coefW   
502        WAVE fs.yW = yW
503        WAVE fs.xW = xW
504        WAVE fs.resW = resW
505       
506        Variable err
507        err = SmearedSphere_SC(fs)
508       
509        return (0)
510End
511
512//wrapper to calculate the smeared model as an AAO-Struct
513// fills the struct and calls the ususal function with the STRUCT parameter
514//
515// used only for the dependency, not for fitting
516//
517Function fSmearedSphere_SHS(coefW,yW,xW)
518        Wave coefW,yW,xW
519       
520        String str = getWavesDataFolder(yW,0)
521        String DF="root:"+str+":"
522       
523        WAVE resW = $(DF+str+"_res")
524       
525        STRUCT ResSmearAAOStruct fs
526        WAVE fs.coefW = coefW   
527        WAVE fs.yW = yW
528        WAVE fs.xW = xW
529        WAVE fs.resW = resW
530       
531        Variable err
532        err = SmearedSphere_SHS(fs)
533       
534        return (0)
535End
Note: See TracBrowser for help on using the repository browser.