1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma IgorVersion = 6.0 |
---|
3 | |
---|
4 | // plots the Debye function for polymer scattering |
---|
5 | // |
---|
6 | Proc PlotDebye(num,qmin,qmax) |
---|
7 | Variable num=256,qmin=0.001,qmax=0.7 |
---|
8 | Prompt num "Enter number of data points for model: " |
---|
9 | Prompt qmin "Enter minimum q-value (A^-1) for model: " |
---|
10 | Prompt qmax "Enter maximum q-value (A^-1) for model: " |
---|
11 | |
---|
12 | make/O/D/N=(num) xwave_deb,ywave_deb |
---|
13 | xwave_deb = alog( log(qmin) + x*((log(qmax)-log(qmin))/num) ) |
---|
14 | make/O/D coef_deb = {1.,50,0.001} |
---|
15 | make/O/T parameters_deb = {"scale","Rg (A)","bkg (cm-1)"} |
---|
16 | Edit parameters_deb,coef_deb |
---|
17 | |
---|
18 | Variable/G root:g_deb |
---|
19 | g_deb := Debye(coef_deb,ywave_deb,xwave_deb) |
---|
20 | Display ywave_deb vs xwave_deb |
---|
21 | ModifyGraph marker=29,msize=2,mode=4,log=1 |
---|
22 | Label bottom "q (A\\S-1\\M)" |
---|
23 | Label left "Intensity (cm\\S-1\\M)" |
---|
24 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
25 | |
---|
26 | AddModelToStrings("Debye","coef_deb","deb") |
---|
27 | End |
---|
28 | |
---|
29 | /////////////////////////////////////////////////////////// |
---|
30 | // - sets up a dependency to a wrapper, not the actual SmearedModelFunction |
---|
31 | Proc PlotSmearedDebye(str) |
---|
32 | String str |
---|
33 | Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4) |
---|
34 | |
---|
35 | // if any of the resolution waves are missing => abort |
---|
36 | if(ResolutionWavesMissingDF(str)) //updated to NOT use global strings (in GaussUtils) |
---|
37 | Abort |
---|
38 | endif |
---|
39 | |
---|
40 | SetDataFolder $("root:"+str) |
---|
41 | |
---|
42 | // Setup parameter table for model function |
---|
43 | make/O/D smear_coef_deb = {1.,50,0.001} |
---|
44 | make/O/T smear_parameters_deb = {"scale","Rg (A)","bkg (cm-1)"} |
---|
45 | Edit smear_parameters_deb,smear_coef_deb |
---|
46 | |
---|
47 | // output smeared intensity wave |
---|
48 | Duplicate/O $(str+"_q") smeared_deb,smeared_qvals |
---|
49 | SetScale d,0,0,"1/cm",smeared_deb |
---|
50 | |
---|
51 | Variable/G gs_deb=0 |
---|
52 | gs_deb := fSmearedDebye(smear_coef_deb,smeared_deb,smeared_qvals) //this wrapper fills the STRUCT |
---|
53 | |
---|
54 | Display smeared_deb vs smeared_qvals |
---|
55 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
56 | Label bottom "q (A\\S-1\\M)" |
---|
57 | Label left "Intensity (cm\\S-1\\M)" |
---|
58 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
59 | |
---|
60 | SetDataFolder root: |
---|
61 | AddModelToStrings("SmearedDebye","smear_coef_deb","deb") |
---|
62 | End |
---|
63 | |
---|
64 | |
---|
65 | /////////////////////////////////////////////////////////////// |
---|
66 | |
---|
67 | |
---|
68 | //AAO version, uses XOP if available |
---|
69 | // simply calls the original single point calculation with |
---|
70 | // a wave assignment (this will behave nicely if given point ranges) |
---|
71 | Function Debye(cw,yw,xw) : FitFunc |
---|
72 | Wave cw,yw,xw |
---|
73 | |
---|
74 | #if exists("DebyeX") |
---|
75 | yw = DebyeX(cw,xw) |
---|
76 | #else |
---|
77 | yw = fDebye(cw,xw) |
---|
78 | #endif |
---|
79 | return(0) |
---|
80 | End |
---|
81 | |
---|
82 | Function fDebye(w,x) : FitFunc |
---|
83 | Wave w |
---|
84 | Variable x |
---|
85 | |
---|
86 | // variables are: |
---|
87 | //[0] scale factor |
---|
88 | //[1] radius of gyration [A] |
---|
89 | //[2] background [cm-1] |
---|
90 | |
---|
91 | Variable scale,rg,bkg |
---|
92 | scale = w[0] |
---|
93 | rg = w[1] |
---|
94 | bkg = w[2] |
---|
95 | |
---|
96 | // calculates (scale*debye)+bkg |
---|
97 | Variable Pq,qr2 |
---|
98 | |
---|
99 | qr2=(x*rg)^2 |
---|
100 | Pq = 2*(exp(-(qr2))-1+qr2)/qr2^2 |
---|
101 | |
---|
102 | //scale |
---|
103 | Pq *= scale |
---|
104 | // then add in the background |
---|
105 | return (Pq+bkg) |
---|
106 | End |
---|
107 | |
---|
108 | //wrapper to calculate the smeared model as an AAO-Struct |
---|
109 | // fills the struct and calls the ususal function with the STRUCT parameter |
---|
110 | // |
---|
111 | // used only for the dependency, not for fitting |
---|
112 | // |
---|
113 | Function fSmearedDebye(coefW,yW,xW) |
---|
114 | Wave coefW,yW,xW |
---|
115 | |
---|
116 | String str = getWavesDataFolder(yW,0) |
---|
117 | String DF="root:"+str+":" |
---|
118 | |
---|
119 | WAVE resW = $(DF+str+"_res") |
---|
120 | |
---|
121 | STRUCT ResSmearAAOStruct fs |
---|
122 | WAVE fs.coefW = coefW |
---|
123 | WAVE fs.yW = yW |
---|
124 | WAVE fs.xW = xW |
---|
125 | WAVE fs.resW = resW |
---|
126 | |
---|
127 | Variable err |
---|
128 | err = SmearedDebye(fs) |
---|
129 | |
---|
130 | return (0) |
---|
131 | End |
---|
132 | |
---|
133 | // this is all there is to the smeared calculation! |
---|
134 | Function SmearedDebye(s) :FitFunc |
---|
135 | Struct ResSmearAAOStruct &s |
---|
136 | |
---|
137 | // the name of your unsmeared model (AAO) is the first argument |
---|
138 | Smear_Model_20(Debye,s.coefW,s.xW,s.yW,s.resW) |
---|
139 | |
---|
140 | return(0) |
---|
141 | End |
---|
142 | |
---|