[798] | 1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
| 2 | #pragma IgorVersion=6.1 |
---|
| 3 | |
---|
| 4 | //////////////////////////////////////////////// |
---|
| 5 | // |
---|
| 6 | // This is a proof of principle to convert a structure built of spheres |
---|
| 7 | // into a fitting function |
---|
| 8 | // |
---|
| 9 | //////////////////////////////////////////////// |
---|
| 10 | |
---|
| 11 | Proc PlotThreeCylKR(num,qmin,qmax) |
---|
| 12 | Variable num=100,qmin=0.004,qmax=0.4 |
---|
| 13 | Prompt num "Enter number of data points for model: " |
---|
| 14 | Prompt qmin "Enter minimum q-value (A^-1) for model: " |
---|
| 15 | Prompt qmax "Enter maximum q-value (A^-1) for model: " |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | // make the needed waves, three rows for this case |
---|
| 19 | Make/O/D/N=3 xCtr_KR,yCtr_KR,zCtr_KR,rad_KR,len_KR,sph_KR,rotx_KR,roty_KR,SLD_KR |
---|
| 20 | |
---|
| 21 | make/o/D/n=(num) xwave_c3KR,ywave_c3KR |
---|
| 22 | xwave_c3KR = alog(log(qmin) + x*((log(qmax)-log(qmin))/num)) |
---|
| 23 | make/o/D coef_c3KR = {0.01,40,32,26,34,26,34,1e-6,2e-6,0.01} |
---|
| 24 | make/o/t parameters_c3KR = {"scale","radius 1 (A)","length 1 (A)","radius 2 (A)","length 2 (A)","radius 3 (A)","length 3 (A)","SLD cylinder (A^-2)","SLD solvent (A^-2)","incoh. bkg (cm^-1)"} |
---|
| 25 | Edit parameters_c3KR,coef_c3KR |
---|
| 26 | Variable/G root:g_c3KR |
---|
| 27 | g_c3KR := ThreeCylKR(coef_c3KR,ywave_c3KR,xwave_c3KR) |
---|
| 28 | |
---|
| 29 | Display ywave_c3KR vs xwave_c3KR |
---|
| 30 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
| 31 | Label bottom "q (A\\S-1\\M)" |
---|
| 32 | Label left "Intensity (cm\\S-1\\M)" |
---|
| 33 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
| 34 | |
---|
| 35 | AddModelToStrings("ThreeCylKR","coef_c3KR","parameters_c3KR","c3KR") |
---|
| 36 | End |
---|
| 37 | |
---|
| 38 | ///////////////////////////////////////////////////////////// |
---|
| 39 | //// - sets up a dependency to a wrapper, not the actual SmearedModelFunction |
---|
| 40 | Proc PlotSmearedThreeCylKR(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 | // make the needed waves, three rows for this case |
---|
| 50 | Make/O/D/N=3 xCtr_KR,yCtr_KR,zCtr_KR,rad_KR,len_KR,sph_KR,rotx_KR,roty_KR,SLD_KR |
---|
| 51 | |
---|
| 52 | SetDataFolder $("root:"+str) |
---|
| 53 | |
---|
| 54 | // Setup parameter table for model function |
---|
| 55 | make/o/D smear_coef_c3KR = {0.01,40,32,26,34,26,34,1e-6,2e-6,0.01} |
---|
| 56 | make/o/t smear_parameters_c3KR = {"scale","radius 1 (A)","length 1 (A)","radius 2 (A)","length 2 (A)","radius 3 (A)","length 3 (A)","SLD cylinder (A^-2)","SLD solvent (A^-2)","incoh. bkg (cm^-1)"} |
---|
| 57 | Edit smear_parameters_c3KR,smear_coef_c3KR |
---|
| 58 | |
---|
| 59 | // output smeared intensity wave, dimensions are identical to experimental QSIG values |
---|
| 60 | // make extra copy of experimental q-values for easy plotting |
---|
| 61 | Duplicate/O $(str+"_q") smeared_c3KR,smeared_qvals |
---|
| 62 | SetScale d,0,0,"1/cm",smeared_c3KR |
---|
| 63 | |
---|
| 64 | Variable/G gs_c3KR=0 |
---|
| 65 | gs_c3KR := fSmearedThreeCylKR(smear_coef_c3KR,smeared_c3KR,smeared_qvals) //this wrapper fills the STRUCT |
---|
| 66 | |
---|
| 67 | Display smeared_c3KR vs smeared_qvals |
---|
| 68 | ModifyGraph log=1,marker=29,msize=2,mode=4 |
---|
| 69 | Label bottom "q (A\\S-1\\M)" |
---|
| 70 | Label left "Intensity (cm\\S-1\\M)" |
---|
| 71 | AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) |
---|
| 72 | |
---|
| 73 | SetDataFolder root: |
---|
| 74 | AddModelToStrings("SmearedThreeCylKR","smear_coef_c3KR","smear_parameters_c3KR","c3KR") |
---|
| 75 | End |
---|
| 76 | |
---|
| 77 | // The calculation is inherently AAO, so it's all done here, not passed to another FitFunc |
---|
| 78 | // |
---|
| 79 | // not quite sure how to handle the SLDs yet, since I'm treating them as 1 or 2 digit integers |
---|
| 80 | // |
---|
| 81 | Function ThreeCylKR(cw,yw,xw) : FitFunc |
---|
| 82 | Wave cw,yw,xw |
---|
| 83 | |
---|
| 84 | // Variable t1=StopMSTimer(-2) |
---|
| 85 | |
---|
| 86 | //The input variables are (and output) |
---|
| 87 | //[0] scale |
---|
| 88 | //[1] cylinder RADIUS (A) |
---|
| 89 | //[2] total cylinder LENGTH (A) |
---|
| 90 | //[3] sld cylinder (A^-2) |
---|
| 91 | //[4] sld solvent |
---|
| 92 | //[5] background (cm^-1) |
---|
| 93 | Variable scale,delrho,bkg,sldCyl,sldSolv,ctr,fill |
---|
| 94 | Variable r0,r1,r2,l0,l1,l2 |
---|
| 95 | scale = cw[0] |
---|
| 96 | r0 = cw[1] |
---|
| 97 | l0 = cw[2] |
---|
| 98 | r1 = cw[3] |
---|
| 99 | l1 = cw[4] |
---|
| 100 | r2 = cw[5] |
---|
| 101 | l2 = cw[6] |
---|
| 102 | sldCyl = cw[7] |
---|
| 103 | sldSolv = cw[8] |
---|
| 104 | bkg = cw[9] |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | // make sure all of the globals are set correctly |
---|
| 108 | NVAR FFT_T = root:FFT_T |
---|
| 109 | NVAR FFT_N = root:FFT_N |
---|
| 110 | NVAR FFT_SolventSLD = root:FFT_SolventSLD |
---|
[838] | 111 | NVAR FFT_delRho = root:FFT_delRho //the SLD multiplier, should have been initialized to 1e-7 |
---|
[798] | 112 | |
---|
[838] | 113 | FFT_SolventSLD = trunc(sldSolv/FFT_delRho) //spits back an integer, maybe not correct |
---|
[798] | 114 | |
---|
| 115 | // generate the matrix and erase it |
---|
| 116 | // FFT_MakeMatrixButtonProc("") |
---|
| 117 | // FFTEraseMatrixButtonProc("") |
---|
| 118 | // Wave m=root:mat |
---|
| 119 | |
---|
| 120 | // fill the matrix with solvent |
---|
| 121 | // FFTFillSolventMatrixProc("") |
---|
| 122 | |
---|
| 123 | // waves to pass to parsing routine |
---|
| 124 | WAVE xCtr_KR=root:xCtr_KR |
---|
| 125 | WAVE yCtr_KR=root:yCtr_KR |
---|
| 126 | WAVE zCtr_KR=root:zCtr_KR |
---|
| 127 | WAVE rad_KR=root:rad_KR |
---|
| 128 | WAVE len_KR=root:len_KR |
---|
| 129 | WAVE sph_KR=root:sph_KR |
---|
| 130 | WAVE rotx_KR=root:rotx_KR |
---|
| 131 | WAVE roty_KR=root:roty_KR |
---|
| 132 | WAVE SLD_KR=root:SLD_KR |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | // with the input parameters, build the structure |
---|
| 137 | // the first cylinder is at 0,0,0 |
---|
| 138 | // the second cylinder is on "top" (Z) |
---|
| 139 | // the third cylinder is on the "bottom" (-Z) |
---|
| 140 | xCtr_KR[0] = 0 |
---|
| 141 | yCtr_KR[0] = 0 |
---|
| 142 | zCtr_KR[0] = 0 |
---|
| 143 | rad_KR[0] = r0 |
---|
| 144 | len_KR[0] = l0 |
---|
| 145 | |
---|
| 146 | xCtr_KR[1] = 0 |
---|
| 147 | yCtr_KR[1] = 0 |
---|
| 148 | zCtr_KR[1] = l0/2 + l1/2 |
---|
| 149 | rad_KR[1] = r1 |
---|
| 150 | len_KR[1] = l1 |
---|
| 151 | |
---|
| 152 | xCtr_KR[2] = 0 |
---|
| 153 | yCtr_KR[2] = 0 |
---|
| 154 | zCtr_KR[2] = -(l0/2 + l2/2) |
---|
| 155 | rad_KR[2] = r2 |
---|
| 156 | len_KR[2] = l2 |
---|
| 157 | |
---|
| 158 | //no rotation here, only one SLD |
---|
| 159 | sph_KR = FFT_T //use the global |
---|
| 160 | rotx_KR = 0 |
---|
| 161 | roty_KR = 0 |
---|
| 162 | SLD_KR = trunc(sldCyl*1e6) |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | // this parses the information and generates xoutW, youtW, zoutW, sldW in the root folder |
---|
| 167 | KR_MultiCylinder(xCtr_KR,yCtr_KR,zCtr_KR,rad_KR,len_KR,sph_KR,rotx_KR,roty_KR,SLD_KR) |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | // these are really just for display, or if the FFT of mat is wanted later. |
---|
| 171 | WAVE xoutW=root:xoutW |
---|
| 172 | WAVE youtW=root:youtW |
---|
| 173 | WAVE zoutW=root:zoutW |
---|
| 174 | WAVE sldW=root:sldW |
---|
| 175 | |
---|
| 176 | XYZV_FillMat(xoutW,youtW,ZoutW,sldW,1) //last 1 will erase the matrix |
---|
| 177 | MakeTriplet(xoutW,youtW,zoutW) |
---|
| 178 | |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | // do the calculation (use the binned if only one SLD, or bin+SLD if the model requires this) |
---|
| 182 | fDoCalc(xw,yw,FFT_T,12,0) //the binned calculation |
---|
| 183 | |
---|
| 184 | // reset the volume fraction to get the proper scaling |
---|
| 185 | // the calculation is normalized to the volume fraction of spheres filling the matrix |
---|
| 186 | Variable frac |
---|
| 187 | Wave m=root:mat |
---|
| 188 | |
---|
| 189 | frac = VolumeFraction_Occ(m) |
---|
| 190 | |
---|
| 191 | yw /= frac |
---|
| 192 | yw *= scale |
---|
| 193 | yw += bkg |
---|
| 194 | |
---|
| 195 | // Print "elapsed time = ",(StopMSTimer(-2) - t1)/1e6 |
---|
| 196 | |
---|
| 197 | return(0) |
---|
| 198 | End |
---|
| 199 | |
---|
| 200 | |
---|
| 201 | // |
---|
| 202 | //// this is all there is to the smeared calculation! |
---|
| 203 | Function SmearedThreeCylKR(s) :FitFunc |
---|
| 204 | Struct ResSmearAAOStruct &s |
---|
| 205 | |
---|
| 206 | ////the name of your unsmeared model is the first argument |
---|
| 207 | Smear_Model_20(ThreeCylKR,s.coefW,s.xW,s.yW,s.resW) |
---|
| 208 | |
---|
| 209 | return(0) |
---|
| 210 | End |
---|
| 211 | // |
---|
| 212 | // |
---|
| 213 | ////wrapper to calculate the smeared model as an AAO-Struct |
---|
| 214 | //// fills the struct and calls the ususal function with the STRUCT parameter |
---|
| 215 | //// |
---|
| 216 | //// used only for the dependency, not for fitting |
---|
| 217 | //// |
---|
| 218 | Function fSmearedThreeCylKR(coefW,yW,xW) |
---|
| 219 | Wave coefW,yW,xW |
---|
| 220 | |
---|
| 221 | String str = getWavesDataFolder(yW,0) |
---|
| 222 | String DF="root:"+str+":" |
---|
| 223 | |
---|
| 224 | WAVE resW = $(DF+str+"_res") |
---|
| 225 | |
---|
| 226 | STRUCT ResSmearAAOStruct fs |
---|
| 227 | WAVE fs.coefW = coefW |
---|
| 228 | WAVE fs.yW = yW |
---|
| 229 | WAVE fs.xW = xW |
---|
| 230 | WAVE fs.resW = resW |
---|
| 231 | |
---|
| 232 | Variable err |
---|
| 233 | err = SmearedThreeCylKR(fs) |
---|
| 234 | |
---|
| 235 | return (0) |
---|
| 236 | End |
---|