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

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

Changed Plot* and PlotSmeared?* naming schemes to be all consistent prefixes for the actual function name, so that the macros can be constructed from the function name, or vice versa.

also some tweaks to the wrapper to make sure that plot and append really work

File size: 5.9 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion = 6.0
3
4////////////////////////////////////////////////
5// Template:
6// 06 NOV 98 SRK
7////////////////////////////////////////////////
8// Giovanni Nisato 30 Nov 1998
9// Borue-Erukhimovich RPA for linear polyelectrolytes
10// references:  Borue, V. Y.; Erukhimovich, I. Y. Macromolecules 1988, 21, 3240.
11//                      Joanny, J.-F.; Leibler, L. Journal de Physique 1990, 51, 545.
12//                      Moussaid, A.; Schosseler, F.; Munch, J.-P.; Candau, S. J. Journal de Physique II France 1993, 3, 573.
13////////////////////////////////////////////////
14
15Proc PlotBEPolyelectrolyte(num,qmin,qmax)
16        Variable num=512,qmin=0.001,qmax=0.2
17        Prompt num "Enter number of data points for model: "
18        Prompt qmin "Enter minimum q-value (^-1) for model: "
19        Prompt qmax "Enter maximum q-value (^-1) for model: " 
20
21        make/o/n=(num) xwave_BE,ywave_BE
22        xwave_BE =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))     
23        make/o coef_BE = {10,7.1,12,10,0.00,0.05,0.7,0.001}
24        make/o/t parameters_BE = {"K (barns)","Lb ()","h (-3)","b ()","Cs (mol/L)","alpha","C (mol/L)","Background"}
25        Edit parameters_BE,coef_BE
26        Variable/G root:g_BE
27        g_BE := BEPolyelectrolyte(coef_BE,ywave_BE,xwave_BE)
28//      ywave_BE := BEPolyelectrolyte(coef_BE,xwave_BE)
29        Display ywave_BE vs xwave_BE
30        ModifyGraph log=0,marker=29,msize=2,mode=4                      //**** log=0 if linear scale desired
31        Label bottom "q (\\S-1\\M)"
32        Label left "S(q) BE , cm\\S-1\\M"
33        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
34End
35
36///////////////////////////////////////////////////////////
37// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
38Proc PlotSmearedBEPolyelectrolyte(str)                                                         
39        String str
40        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
41       
42        // if any of the resolution waves are missing => abort
43        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
44                Abort
45        endif
46       
47        SetDataFolder $("root:"+str)
48       
49        // Setup parameter table for model function
50        make/o smear_coef_BE = {10,7.1,12,10,0.00,0.05,0.7,0.001}                                       //**** mod, coef values to match unsmeared model above
51        make/o/t smear_parameters_BE= {"K (barns)","Lb ()","h (-3)","b ()","Cs (mol/L)","alpha","C (mol/L)","Background"}   
52        Edit smear_parameters_BE,smear_coef_BE                                  //**** mod
53       
54        // output smeared intensity wave, dimensions are identical to experimental QSIG values
55        // make extra copy of experimental q-values for easy plotting
56        Duplicate/O $(str+"_q") smeared_BE,smeared_qvals                                //**** mod
57        SetScale d,0,0,"1/cm",smeared_BE                                                //**** mod
58                                       
59        Variable/G gs_BE=0
60        gs_BE := fSmearedBEPolyelectrolyte(smear_coef_BE,smeared_BE,smeared_qvals)      //this wrapper fills the STRUCT
61       
62        Display smeared_BE vs smeared_qvals                                                                     //**** mod
63        ModifyGraph log=0,marker=29,msize=2,mode=4
64        Label bottom "q (\\S-1\\M)"
65        Label left "I  sBE (cm\\S-1\\M)"
66        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
67       
68        SetDataFolder root:
69End
70       
71
72//AAO version
73Function BEPolyelectrolyte(cw,yw,xw) : FitFunc
74        Wave cw,yw,xw
75
76#if exists("BEPolyelectrolyteX")
77        yw = BEPolyelectrolyteX(cw,xw)
78#else
79        yw = fBEPolyelectrolyte(cw,xw)
80#endif
81        return(0)
82End
83
84///////////////////////////////////////////////////////////////
85// unsmeared model calculation
86///////////////////////////
87// Borue-Erukhimovich RPA model for linear polyelectrolytes
88///////////////////////////
89Function fBEPolyelectrolyte(w,q) : FitFunc
90        Wave w
91        Variable q
92// Input (fitting) variables are:
93        //[0] K  = contrast factor  (barns = 10-24 cm^2=10-4 ^2)
94        //[1] Lb = Bjerrum length ; this parameter needs to be kept constant for a given solvent and temperature!  ()
95        //[2]  h = virial parameter (3)
96        //[3]  b = monomer length  ()
97        //[4]  Cs = concentration of monovalent salt (mol/L)
98        //[5]  alpha = ionization degree : ratio of charged monomers  to total number of monomers
99        //[6]  C  = polymer molar concentration (mol/L)
100        //[7]  Bkd = Background
101//  local variables
102        Variable K,Lb,h,b,alpha,C,Ca,Cs,Csa,r02,K2,q2,Sq,Bkd
103        K = w[0] 
104        Lb = w[1]
105        h = w[2] 
106        b = w[3]
107        Cs = w[4]
108        alpha = w[5]
109        C  = w[6]
110        Bkd =w[7]
111       
112        Ca = C *6.022136e-4                     //   polymer number concentration in angstroms-3
113        Csa = Cs * 6.022136e-4          //  1:1 salt concentration, angstroms-3
114        k2= 4*Pi*Lb*(2*Cs+alpha*Ca)     //    inverse Debye length, squared; classical definition
115
116// alternative definitionfor ANNEALED (weak) polyelectrolytes (e.g. : polyacrylic acid):
117// k2= 4*Pi*Lb*(2*Cs+2*alpha*Ca)       
118// reference:  Rapha‘l, E.; Joanny, J.-F. Europhysics Letters 1990, 11, 179.                                                                                                   
119                                                               
120        r02 = 1./alpha / Ca^0.5*( b / (48*Pi*Lb) ^0.5 )
121        q2 = q^2       
122       
123
124//   K = a^2  with:  a = (bp - vp/vsolvent * bsolvent)
125// where : b = Sum(batom) ; batom = scattering length in cm-12
126//              vp = partial molar volume of the polymer ; vsolvent= partial molar volume of the solvent
127// NB :K in  Barns = 10^-24 cm2 ; the rest of the expression is in -3 = 10^24 cm3
128//  -> there is no multiplication factor to get the result in cm-1 .
129// Returns S(q) in cm-1
130
131        Sq = K*1./(4*Pi*Lb*alpha^2)  * (q2 + k2)  /  (1+(r02^2) * (q2+k2) * (q2- (12*h*Ca/b^2)) ) + Bkd
132       
133        Return (Sq)
134End
135//End of function BE()
136///////////////////////////////////////////////////////////////
137
138
139// this is all there is to the smeared calculation!
140Function SmearedBEPolyelectrolyte(s) :FitFunc
141        Struct ResSmearAAOStruct &s
142
143////the name of your unsmeared model is the first argument
144        Smear_Model_20(BEPolyelectrolyte,s.coefW,s.xW,s.yW,s.resW)
145
146        return(0)
147End
148
149//wrapper to calculate the smeared model as an AAO-Struct
150// fills the struct and calls the ususal function with the STRUCT parameter
151//
152// used only for the dependency, not for fitting
153//
154Function fSmearedBEPolyelectrolyte(coefW,yW,xW)
155        Wave coefW,yW,xW
156       
157        String str = getWavesDataFolder(yW,0)
158        String DF="root:"+str+":"
159       
160        WAVE resW = $(DF+str+"_res")
161       
162        STRUCT ResSmearAAOStruct fs
163        WAVE fs.coefW = coefW   
164        WAVE fs.yW = yW
165        WAVE fs.xW = xW
166        WAVE fs.resW = resW
167       
168        Variable err
169        err = SmearedBEPolyelectrolyte(fs)
170       
171        return (0)
172End
173
174
Note: See TracBrowser for help on using the repository browser.