source: sans/Release/trunk/NCNR_User_Procedures/SANS/Analysis/Models/BE_Polyelectrolyte_v40.ipf @ 338

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

merging structural changes from Dev/trunk into Release/trunk

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