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

Last change on this file since 127 was 127, checked in by srkline, 16 years ago

LOTS of changes to the analysis ipf files:

-- see sphere.ipf for the simplest example of the changes --

  • #pragma Igor 6
  • #if directive to look for XOP
  • AAO unsmeared functions
  • STRUCT functions for smearing (also AAO)
  • new wrappers for dependencies to struct functions

(2006 models have NOT been completed yet, only the old models)

  • loading data files into data folders (PlotUtils?) + some streamlining of the loaders
  • Smear_Model_N is now AAO + some streamlining of the quadrature code

-- SHS and SW structure factor XOPs are crashing (need DP wave, I may have old XOP)
-- this breaks fitting of the smeared models until wrappers can be devised
-- all packages will be broken due to the new data folder structure
-- multiple instances of functions will now cause problems (MSA)
-- RPA model is a problem with its odd functional form (extra wave)

-- lots of other carnage to follow as the bugs and typos are shaken out

24 JUL 2007 SRK

File size: 15.5 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 conatining 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 conatining 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("root:HayPenMSA"))
205                Make/O/D/N=17 root:HayPenMSA:gMSAWave
206        else
207                NewDataFolder root:HayPenMSA
208                Make/O/D/N=17 root:HayPenMSA:gMSAWave
209        endif
210       
211        ///
212        Make/O/D/n=(num) xwave_S_SC,ywave_S_SC                                 
213        xwave_S_SC =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))                           
214        Make/O/D coef_S_SC = {0.2,50,3e-6,20,0,298,78,0.0001}                                           
215        make/o/t parameters_S_SC = {"volume fraction","Radius (A)","contrast (-2)","charge","movalent salt(M)","Temperature (K)","dielectric const","bkgd (cm-1)"}             
216        Edit/K=1 parameters_S_SC,coef_S_SC
217        Variable/G root:g_S_SC                                                 
218        g_S_SC := Sphere_SC(coef_S_SC,ywave_S_SC,xwave_S_SC)                   
219//      ywave_S_SC := Sphere_SC(coef_S_SC,xwave_S_SC)                   
220        Display/K=1 ywave_S_SC vs xwave_S_SC                                                   
221        ModifyGraph log=1,marker=29,msize=2,mode=4                     
222        Label bottom "q (\\S-1\\M)"
223        Label left "Intensity (cm\\S-1\\M)"                                     
224
225        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
226End
227
228// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
229Proc PlotSmearedSphere_SC(str)                                                         
230        String str
231        Prompt str,"Pick the data folder conatining the resolution you want",popup,getAList(4)
232       
233        // if any of the resolution waves are missing => abort
234        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
235                Abort
236        endif
237       
238        SetDataFolder $("root:"+str)
239       
240        if (DataFolderExists("root:HayPenMSA"))
241                Make/O/D/N=17 root:HayPenMSA:gMSAWave
242        else
243                NewDataFolder root:HayPenMSA
244                Make/O/D/N=17 root:HayPenMSA:gMSAWave
245        endif
246       
247        // Setup parameter table for model function
248        Make/O/D smear_coef_S_SC = {0.2,50,3e-6,20,0,298,78,0.0001}                                             
249        make/o/t smear_parameters_S_SC = {"volume fraction","Radius (A)","contrast (-2)","charge","movalent salt(M)","Temperature (K)","dielectric const","bkgd (cm-1)"}               
250        Edit smear_parameters_S_SC,smear_coef_S_SC                                     
251       
252        // output smeared intensity wave, dimensions are identical to experimental QSIG values
253        // make extra copy of experimental q-values for easy plotting
254        Duplicate/O $(str+"_q") smeared_S_SC,smeared_qvals                             
255        SetScale d,0,0,"1/cm",smeared_S_SC                                                     
256                                       
257        Variable/G gs_S_SC=0
258        gs_S_SC := fSmearedSphere_SC(smear_coef_S_SC,smeared_S_SC,smeared_qvals)        //this wrapper fills the STRUCT
259       
260        Display smeared_S_SC vs smeared_qvals                                                                   
261        ModifyGraph log=1,marker=29,msize=2,mode=4
262        Label bottom "q (\\S-1\\M)"
263        Label left "Intensity (cm\\S-1\\M)"
264
265        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
266       
267        SetDataFolder root:
268End
269       
270
271//AAO function
272Function Sphere_SC(w,yw,xw) : FitFunc
273        Wave w,yw,xw
274
275        //setup form factor coefficient wave
276        Make/O/D/N=4 form_S_SC
277        form_S_SC[0] = 1
278        form_S_SC[1] = w[1]
279        form_S_SC[2] = w[2]
280        form_S_SC[3] = 0
281       
282        //setup structure factor coefficient wave
283        Make/O/D/N=6 struct_S_SC
284        struct_S_SC[0] = 2*w[1]         //diameter
285        struct_S_SC[1] = w[3]
286        struct_S_SC[2] = w[0]
287        struct_S_SC[3] = w[5]
288        struct_S_SC[4] = w[4]
289        struct_S_SC[5] = w[6]
290       
291        //calculate each and combine
292        Duplicate/O xw temp_S_SC_PQ,temp_S_SC_SQ
293        SphereForm(form_S_SC,temp_S_SC_PQ,xw)
294        HayterPenfoldMSA(struct_S_SC,temp_S_SC_SQ,xw)
295        yw = temp_S_SC_PQ * temp_S_SC_SQ
296        yw *= w[0]
297        yw += w[7]
298       
299        //cleanup waves
300        //Killwaves/Z form_S_SC,struct_S_SC
301        return (0)
302End
303
304/////////////////////////////////
305Proc PlotSphere_SHS(num,qmin,qmax)                                             
306        Variable num=256,qmin=0.001,qmax=0.7
307        Prompt num "Enter number of data points for model: "
308        Prompt qmin "Enter minimum q-value (^-1) for model: "
309        Prompt qmax "Enter maximum q-value (^-1) for model: "
310       
311        ///
312        Make/O/D/N=4 form_S_SHS
313        Make/O/D/N=4 struct_S_SHS
314        ///
315        Make/O/D/n=(num) xwave_S_SHS,ywave_S_SHS                                       
316        xwave_S_SHS =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))                                 
317        Make/O/D coef_S_SHS = {0.1,60,1e-6,0.05,0.2,0.01}                                               
318        make/o/t parameters_S_SHS = {"volume fraction","Radius (A)","contrast (-2)","perturbation parameter (0.1)","stickiness, tau","bkgd (cm-1)"}           
319        Edit/K=1 parameters_S_SHS,coef_S_SHS
320        Variable/G root:g_S_SHS                                         
321        g_S_SHS := Sphere_SHS(coef_S_SHS,ywave_S_SHS,xwave_S_SHS)                       
322//      ywave_S_SHS := Sphere_SHS(coef_S_SHS,xwave_S_SHS)                       
323        Display/K=1 ywave_S_SHS vs xwave_S_SHS                                                 
324        ModifyGraph log=1,marker=29,msize=2,mode=4                     
325        Label bottom "q (\\S-1\\M)"
326        Label left "Intensity (cm\\S-1\\M)"                                     
327
328        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
329End
330
331// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
332Proc PlotSmearedSphere_SHS(str)                                                         
333        String str
334        Prompt str,"Pick the data folder conatining the resolution you want",popup,getAList(4)
335       
336        // if any of the resolution waves are missing => abort
337        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
338                Abort
339        endif
340       
341        SetDataFolder $("root:"+str)
342       
343        // Setup parameter table for model function
344        Make/O/D smear_coef_S_SHS = {0.1,60,1e-6,0.05,0.2,0.01}                                         
345        make/o/t smear_parameters_S_SHS = {"volume fraction","Radius (A)","contrast (-2)","perturbation parameter (0.1)","stickiness, tau","bkgd (cm-1)"}             
346        Edit smear_parameters_S_SHS,smear_coef_S_SHS                                   
347       
348        // output smeared intensity wave, dimensions are identical to experimental QSIG values
349        // make extra copy of experimental q-values for easy plotting
350        Duplicate/O $(str+"_q") smeared_S_SHS,smeared_qvals                             
351        SetScale d,0,0,"1/cm",smeared_S_SHS                                                     
352                                       
353        Variable/G gs_S_SHS=0
354        gs_S_SHS := fSmearedSphere_SHS(smear_coef_S_SHS,smeared_S_SHS,smeared_qvals)    //this wrapper fills the STRUCT
355       
356        Display smeared_S_SHS vs smeared_qvals                                                                 
357        ModifyGraph log=1,marker=29,msize=2,mode=4
358        Label bottom "q (\\S-1\\M)"
359        Label left "Intensity (cm\\S-1\\M)"
360
361        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
362       
363        SetDataFolder root:
364End
365
366
367//AAO function
368Function Sphere_SHS(w,yw,xw) : FitFunc
369        Wave w,yw,xw
370       
371        //setup form factor coefficient wave
372        Make/O/D/N=4 form_S_SHS
373        form_S_SHS[0] = 1
374        form_S_SHS[1] = w[1]
375        form_S_SHS[2] = w[2]
376        form_S_SHS[3] = 0
377       
378        //setup structure factor coefficient wave
379        Make/O/D/N=4 struct_S_SHS
380        struct_S_SHS[0] = w[1]
381        struct_S_SHS[1] = w[0]
382        struct_S_SHS[2] = w[3]
383        struct_S_SHS[3] = w[4]
384       
385        //calculate each and combine
386        Duplicate/O xw temp_S_SHS_PQ,temp_S_SHS_SQ
387        SphereForm(form_S_SHS,temp_S_SHS_PQ,xw)
388        StickyHS_Struct(struct_S_SHS,temp_S_SHS_SQ,xw)
389        yw = temp_S_SHS_PQ * temp_S_SHS_SQ
390        yw *= w[0]
391        yw += w[5]
392       
393        //cleanup waves
394        //Killwaves/Z form_S_SHS,struct_S_SHS
395       
396        return (0)
397End
398
399
400
401// this is all there is to the smeared calculation!
402Function SmearedSphere_HS(s) :FitFunc
403        Struct ResSmearAAOStruct &s
404
405//      the name of your unsmeared model is the first argument
406        s.yW = Smear_Model_20(Sphere_HS,s.coefW,s.xW,s.resW)
407
408        return(0)
409End
410 
411// this is all there is to the smeared calculation!
412Function SmearedSphere_SW(s) :FitFunc
413        Struct ResSmearAAOStruct &s
414
415//      the name of your unsmeared model is the first argument
416        s.yW = Smear_Model_20(Sphere_SW,s.coefW,s.xW,s.resW)
417
418        return(0)
419End
420
421// this is all there is to the smeared calculation!
422Function SmearedSphere_SC(s) :FitFunc
423        Struct ResSmearAAOStruct &s
424
425//      the name of your unsmeared model is the first argument
426        s.yW = Smear_Model_20(Sphere_SC,s.coefW,s.xW,s.resW)
427
428        return(0)
429End
430
431// this is all there is to the smeared calculation!
432Function SmearedSphere_SHS(s) :FitFunc
433        Struct ResSmearAAOStruct &s
434
435//      the name of your unsmeared model is the first argument
436        s.yW = Smear_Model_20(Sphere_SHS,s.coefW,s.xW,s.resW)
437
438        return(0)
439End
440
441//wrapper to calculate the smeared model as an AAO-Struct
442// fills the struct and calls the ususal function with the STRUCT parameter
443//
444// used only for the dependency, not for fitting
445//
446Function fSmearedSphere_HS(coefW,yW,xW)
447        Wave coefW,yW,xW
448       
449        String str = getWavesDataFolder(yW,0)
450        String DF="root:"+str+":"
451       
452        WAVE resW = $(DF+str+"_res")
453       
454        STRUCT ResSmearAAOStruct fs
455        WAVE fs.coefW = coefW   
456        WAVE fs.yW = yW
457        WAVE fs.xW = xW
458        WAVE fs.resW = resW
459       
460        Variable err
461        err = SmearedSphere_HS(fs)
462       
463        return (0)
464End
465
466//wrapper to calculate the smeared model as an AAO-Struct
467// fills the struct and calls the ususal function with the STRUCT parameter
468//
469// used only for the dependency, not for fitting
470//
471Function fSmearedSphere_SW(coefW,yW,xW)
472        Wave coefW,yW,xW
473       
474        String str = getWavesDataFolder(yW,0)
475        String DF="root:"+str+":"
476       
477        WAVE resW = $(DF+str+"_res")
478       
479        STRUCT ResSmearAAOStruct fs
480        WAVE fs.coefW = coefW   
481        WAVE fs.yW = yW
482        WAVE fs.xW = xW
483        WAVE fs.resW = resW
484       
485        Variable err
486        err = SmearedSphere_SW(fs)
487       
488        return (0)
489End
490
491//wrapper to calculate the smeared model as an AAO-Struct
492// fills the struct and calls the ususal function with the STRUCT parameter
493//
494// used only for the dependency, not for fitting
495//
496Function fSmearedSphere_SC(coefW,yW,xW)
497        Wave coefW,yW,xW
498       
499        String str = getWavesDataFolder(yW,0)
500        String DF="root:"+str+":"
501       
502        WAVE resW = $(DF+str+"_res")
503       
504        STRUCT ResSmearAAOStruct fs
505        WAVE fs.coefW = coefW   
506        WAVE fs.yW = yW
507        WAVE fs.xW = xW
508        WAVE fs.resW = resW
509       
510        Variable err
511        err = SmearedSphere_SC(fs)
512       
513        return (0)
514End
515
516//wrapper to calculate the smeared model as an AAO-Struct
517// fills the struct and calls the ususal function with the STRUCT parameter
518//
519// used only for the dependency, not for fitting
520//
521Function fSmearedSphere_SHS(coefW,yW,xW)
522        Wave coefW,yW,xW
523       
524        String str = getWavesDataFolder(yW,0)
525        String DF="root:"+str+":"
526       
527        WAVE resW = $(DF+str+"_res")
528       
529        STRUCT ResSmearAAOStruct fs
530        WAVE fs.coefW = coefW   
531        WAVE fs.yW = yW
532        WAVE fs.xW = xW
533        WAVE fs.resW = resW
534       
535        Variable err
536        err = SmearedSphere_SHS(fs)
537       
538        return (0)
539End
Note: See TracBrowser for help on using the repository browser.