source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/NewModels_2008/PolyGaussCoil_v40.ipf @ 445

Last change on this file since 445 was 445, checked in by srkline, 14 years ago

Adding a pile of new model functions. Some are from Boualem, some old code from Danilo, some from me.

As far as I can tell, these replicate the original references (not the empirical models).

Help file and XOPs have net been done yet.

File size: 4.3 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion = 6.0
3
4
5//
6// this function is for the form factor of polydisperse Gaussian coil
7//
8// -- see Boualem's book - pg 298 (Higgins and Benoit)
9// -- Glatter & Kratky - pg.404
10//
11// June 2008 SRK
12////////////////////////////////////////////////
13
14Proc PlotPolyGaussCoil(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 (^-1) for model: "
18        Prompt qmax "Enter maximum q-value (^-1) for model: "
19       
20        make/o/d/n=(num) xwave_pgc,ywave_pgc
21        xwave_pgc =alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
22        make/o/d coef_pgc = {1.,60,2,0.001}
23        make/o/t parameters_pgc = {"scale","Rg (A)","polydispersity (Mw/Mn)","bkg (cm-1)"}
24        Edit parameters_pgc,coef_pgc
25        Variable/G root:g_pgc
26        g_pgc := PolyGaussCoil(coef_pgc,ywave_pgc,xwave_pgc)
27//      ywave_pgc := PolyGaussCoil(coef_pgc,xwave_pgc)
28        Display ywave_pgc vs xwave_pgc
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        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
33       
34        AddModelToStrings("PolyGaussCoil","coef_pgc","pgc")
35End
36
37///////////////////////////////////////////////////////////
38// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
39Proc PlotSmearedPolyGaussCoil(str)                                                             
40        String str
41        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
42       
43        // if any of the resolution waves are missing => abort
44        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
45                Abort
46        endif
47       
48        SetDataFolder $("root:"+str)
49       
50        // Setup parameter table for model function
51        make/o/d smear_coef_pgc = {1.,60,2,0.001}
52        make/o/t smear_parameters_pgc = {"scale","Rg (A)","polydispersity (Mw/Mn)","bkg (cm-1)"}
53        Edit smear_parameters_pgc,smear_coef_pgc
54       
55        // output smeared intensity wave, dimensions are identical to experimental QSIG values
56        // make extra copy of experimental q-values for easy plotting
57       
58        Duplicate/O $(str+"_q") smeared_pgc,smeared_qvals                               
59        SetScale d,0,0,"1/cm",smeared_pgc                                                       
60                                       
61        Variable/G gs_pgc=0
62        gs_pgc := fSmearedPolyGaussCoil(smear_coef_pgc,smeared_pgc,smeared_qvals)       //this wrapper fills the STRUCT
63       
64        Display smeared_pgc vs smeared_qvals                                                                   
65        ModifyGraph log=1,marker=29,msize=2,mode=4
66        Label bottom "q (\\S-1\\M)"
67        Label left "Intensity (cm\\S-1\\M)"
68        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
69       
70        SetDataFolder root:
71        AddModelToStrings("SmearedPolyGaussCoil","smear_coef_pgc","pgc")
72End
73
74
75//AAO version
76Function PolyGaussCoil(cw,yw,xw) : FitFunc
77        Wave cw,yw,xw
78
79#if exists("PolyGaussCoilX")
80        yw = PolyGaussCoilX(cw,xw)
81#else
82        yw = fPolyGaussCoil(cw,xw)
83#endif
84        return(0)
85End
86
87///////////////////////////////////////////////////////////////
88// unsmeared model calculation
89///////////////////////////
90Function fPolyGaussCoil(w,x) : FitFunc
91        Wave w
92        Variable x
93       
94        //assign nice names to the input wave
95        //w[0] = scale
96        //w[1] = radius of gyration []
97        //w[2] = polydispersity, ratio of Mw/Mn
98        //w[3] = bkg [cm-1]
99        Variable scale,bkg,Rg,uval,Mw_Mn
100               
101        scale = w[0]
102        Rg = w[1]
103        Mw_Mn = w[2]
104        bkg = w[3]
105       
106        uval = Mw_Mn - 1
107        if(uval == 0)
108                uval = 1e-6             //avoid divide by zero error
109        endif
110        //calculations on input parameters
111       
112        //local variables
113        Variable xi,inten
114       
115        xi = Rg^2*x^2/(1+2*uval)
116       
117        if(xi < 1e-3)
118                return(scale+bkg)               //limiting value
119        endif
120       
121        inten = 2*((1+uval*xi)^(-1/uval)+xi-1)
122        inten /= (1+uval)*xi^2
123
124        inten *= scale
125        //add in the background
126        inten += bkg
127     
128        Return (inten)
129End
130
131// this is all there is to the smeared calculation!
132Function SmearedPolyGaussCoil(s) :FitFunc
133        Struct ResSmearAAOStruct &s
134
135////the name of your unsmeared model is the first argument
136        Smear_Model_20(PolyGaussCoil,s.coefW,s.xW,s.yW,s.resW)
137
138        return(0)
139End
140
141//wrapper to calculate the smeared model as an AAO-Struct
142// fills the struct and calls the ususal function with the STRUCT parameter
143//
144// used only for the dependency, not for fitting
145//
146Function fSmearedPolyGaussCoil(coefW,yW,xW)
147        Wave coefW,yW,xW
148       
149        String str = getWavesDataFolder(yW,0)
150        String DF="root:"+str+":"
151       
152        WAVE resW = $(DF+str+"_res")
153       
154        STRUCT ResSmearAAOStruct fs
155        WAVE fs.coefW = coefW   
156        WAVE fs.yW = yW
157        WAVE fs.xW = xW
158        WAVE fs.resW = resW
159       
160        Variable err
161        err = SmearedPolyGaussCoil(fs)
162       
163        return (0)
164End
Note: See TracBrowser for help on using the repository browser.