source: sans/Analysis/trunk/Put in User Procedures/SANS_Models_v3.00/NewModels_2006/MultiShell.ipf @ 178

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

Changed StackedDiscs? and MultiShell? to use 76 point quadrature. I though this was done long ago, but the RT ticket was still open. Now it's done. The branch also has these changes.

File size: 4.5 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2
3// calculates the scattering from a spherical particle made up of a core (aqueous) surrounded
4// by N spherical layers, each of which is a PAIR of shells, solvent + surfactant since there
5//must always be a surfactant layer on the outside
6//
7// bragg peaks arise naturally from the periodicity of the sample
8// resolution smeared version gives he most appropriate view of the model
9
10//
11//
12Proc PlotMultiShellSphere(num,qmin,qmax)
13        Variable num=100,qmin=0.001,qmax=0.7
14        Prompt num "Enter number of data points for model: "
15        Prompt qmin "Enter minimum q-value (^-1) for model: "
16        Prompt qmax "Enter maximum q-value (^-1) for model: "
17       
18        make/O/D/N=(num) xwave_mss,ywave_mss
19        xwave_mss =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
20        make/O/D coef_mss = {1.,60,10,10,6.4e-6,0.4e-6,2,0.001}
21        make/O/T parameters_mss = {"scale","core radius (A)","shell thickness (A)","water thickness","core & solvent SLD (A-2)","Shell SLD (A-2)","number of water/shell pairs","bkg (cm-1)"}
22        Edit/K=1 parameters_mss,coef_mss
23        ywave_mss := MultiShellForm(coef_mss,xwave_mss)
24        Display/K=1 ywave_mss vs xwave_mss
25        ModifyGraph log=1,marker=29,msize=2,mode=4
26        Label bottom "q (\\S-1\\M)"
27        Label left "Intensity (cm\\S-1\\M)"
28        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
29End
30
31Proc PlotSmearedMultiShell()                                                           
32        //no input parameters necessary, it MUST use the experimental q-values
33        // from the experimental data read in from an AVE/QSIG data file
34       
35        // if no gQvals wave, data must not have been loaded => abort
36        if(Exists("gQvals") != 2)               // 2 = string or numeric variable exists
37                Abort "6-column QSIG data not loaded. Use LoadQSIGData macro"
38        else
39                if(WaveExists($gQvals) ==0)     //wave ref does not exist
40                        Abort "6-column QSIG waves are missing. Re-load with LoadQSIGData macro"
41                endif
42        endif
43       
44        // Setup parameter table for model function
45        make/O/D smear_coef_mss = {1.,60,10,10,6.4e-6,0.4e-6,2,0.001}                                   
46        make/O/T smear_parameters_mss = {"scale","core radius (A)","shell thickness (A)","water thickness","core & solvent SLD (A-2)","Shell SLD (A-2)","number of water/shell pairs","bkg (cm-1)"}
47        Edit/K=1 smear_parameters_mss,smear_coef_mss                                   
48       
49        // output smeared intensity wave, dimensions are identical to experimental QSIG values
50        // make extra copy of experimental q-values for easy plotting
51        Duplicate/O $gQvals smeared_mss,smeared_qvals                           
52        SetScale d,0,0,"1/cm",smeared_mss                                                       
53
54        smeared_mss := SmearedMultiShell(smear_coef_mss,$gQvals)               
55        Display/K=1 smeared_mss vs smeared_qvals                                                                       
56        ModifyGraph log=1,marker=29,msize=2,mode=4
57        Label bottom "q (\\S-1\\M)"
58        Label left "Intensity (cm\\S-1\\M)"
59        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
60End
61
62Function MultiShellForm(w,x) :FitFunc
63        Wave w
64        Variable x
65       
66        // variables are:
67        //[0] scale factor
68        //[1] radius of core []
69        //[2] thickness of the shell    []
70        //[3] thickness of the water layer
71        //[4] SLD of the core = sld of the solvent[-2]
72        //[5] SLD of the shell
73        //[6] number of pairs (tw+tsh)
74        //[7] background        [cm-1]
75       
76        // All inputs are in ANGSTROMS
77        //OUTPUT is normalized by the particle volume, and converted to [cm-1]
78       
79       
80        Variable scale,rcore,tw,ts,rhocore,rhoshel,num,bkg
81        scale = w[0]
82        rcore = w[1]
83        ts = w[2]
84        tw = w[3]
85        rhocore = w[4]
86        rhoshel = w[5]
87        num = w[6]
88        bkg = w[7]
89       
90        //calculate with a loop, two shells at a time
91        Variable ii=0,fval=0,voli,ri,sldi
92
93        do
94                ri = rcore + ii*ts + ii*tw
95                voli = 4*pi/3*ri^3
96                sldi = rhocore-rhoshel
97                fval += voli*sldi*F_func(ri*x)
98                ri += ts
99                voli = 4*pi/3*ri^3
100                sldi = rhoshel-rhocore
101                fval += voli*sldi*F_func(ri*x)
102                ii+=1           //do 2 layers at a time
103        while(ii<=num-1)  //change to make 0 < num < 2 correspond to unilamellar vesicles (C. Glinka, 11/24/03)
104       
105        fval *=fval             //square it
106        fval /=voli             //normalize by the overall volume
107        fval *=scale*1e8
108        fval += bkg
109       
110        return(fval)
111End
112
113Function F_func(qr)
114        Variable qr
115       
116        Variable val=0
117       
118        val = 3*(sin(qr) - qr*cos(qr))/qr^3
119       
120        return(val)
121End
122
123
124//
125//Function Schulz_Point_ms(x,avg,zz)
126//
127//      //Wave w
128//      Variable x,avg,zz
129//      Variable dr
130//     
131//      dr = zz*ln(x) - gammln(zz+1)+(zz+1)*ln((zz+1)/avg)-(x/avg*(zz+1))
132//     
133//      return (exp(dr))
134//     
135//End
136
137// this model needs 76 Gauss points for a proper smearing calculation
138// since there can be sharp interference fringes that develop from the stacking
139Function SmearedMultiShell(w,x) :FitFunc
140        Wave w
141        Variable x
142       
143        Variable ans
144        SVAR sq = gSig_Q
145        SVAR qb = gQ_bar
146        SVAR sh = gShadow
147        SVAR gQ = gQVals
148       
149        //the name of your unsmeared model is the first argument
150        ans = Smear_Model_76(MultiShellForm,$sq,$qb,$sh,$gQ,w,x)
151
152        return(ans)
153End
Note: See TracBrowser for help on using the repository browser.