|
| 1 | +################################################################################ |
| 2 | +# |
| 3 | +# SrRietveld Refinement of RaPDF Ni data. |
| 4 | +# |
| 5 | +################################################################################ |
| 6 | +__id__ = "$Id$" |
| 7 | + |
| 8 | +from SrRietveld import * |
| 9 | + |
| 10 | +def runfit(fit): |
| 11 | + |
| 12 | + # Fit |
| 13 | + #from RefinementAPI.park.ParkOptimizer import ParkOptimizer |
| 14 | + #fit.setOptimizer(ParkOptimizer()) |
| 15 | + # Set the number of refinement cycles |
| 16 | + fit.setNumCycles(-1) |
| 17 | + |
| 18 | + # set component |
| 19 | + comp = RietveldComponent() |
| 20 | + comp.setName("Ni") |
| 21 | + fit.addComponent(comp) |
| 22 | + |
| 23 | + ### Instantiate the pattern |
| 24 | + pat = CWXPattern() |
| 25 | + comp.setPattern(pat) |
| 26 | + pat.loadData("nickel_5f_300K_1500msec_2theta.dat", XYSigmaParser()) |
| 27 | + pat.setPrimaryWavelength(0.125677) |
| 28 | + |
| 29 | + lp = StandardDebyeScherrerLPFactor() |
| 30 | + lp.setMonoPolarizationCorrection(0.91) |
| 31 | + pat.setLorentzPolarizationFactor(lp) |
| 32 | + |
| 33 | + # setup the excluded region |
| 34 | + comp.setFitRange(xmin = 2.50) |
| 35 | + |
| 36 | + # Set the zero parameters |
| 37 | + pat.setValue("zshift", 0) |
| 38 | + fit.mapVP("v_zshift", pat, "zshift") |
| 39 | + |
| 40 | + # Instantiate the background |
| 41 | + bkgd = InterpolatedBackground("Cubic") |
| 42 | + comp.setBackground(bkgd) |
| 43 | + # setup the background |
| 44 | + bkgdpointlist = [ |
| 45 | + ( 2.506 , 1060.166 ), |
| 46 | + ( 3.010 , 872.325 ), |
| 47 | + ( 5.176 , 801.970 ), |
| 48 | + ( 6.310 , 799.834 ), |
| 49 | + ( 7.871 , 663.524 ), |
| 50 | + ( 8.451 , 672.373 ), |
| 51 | + ( 9.685 , 627.120 ), |
| 52 | + ( 10.365 , 605.252 ), |
| 53 | + ( 11.247 , 532.866 ), |
| 54 | + ( 11.776 , 584.413 ), |
| 55 | + ( 12.733 , 545.038 ), |
| 56 | + ( 13.186 , 530.719 ), |
| 57 | + ( 13.942 , 498.045 ), |
| 58 | + ( 15.050 , 525.185 ), |
| 59 | + ( 16.234 , 482.769 ), |
| 60 | + ( 16.562 , 475.984 ), |
| 61 | + ( 17.166 , 483.853 ), |
| 62 | + ( 18.148 , 482.349 ), |
| 63 | + ( 19.080 , 470.769 ), |
| 64 | + ( 19.912 , 442.536 ), |
| 65 | + ( 20.743 , 466.518 ), |
| 66 | + ( 21.675 , 443.857 ), |
| 67 | + ( 23.060 , 422.947 ), |
| 68 | + ( 23.363 , 431.474 ), |
| 69 | + ( 23.841 , 432.576 ), |
| 70 | + ( 24.572 , 418.514 ), |
| 71 | + ( 25.227 , 407.441 ), |
| 72 | + ( 25.529 , 412.225 ), |
| 73 | + ( 25.932 , 399.844 ), |
| 74 | + ( 26.587 , 403.386 ), |
| 75 | + ( 27.468 , 396.797 ), |
| 76 | + ( 27.897 , 392.290 ), |
| 77 | + ( 28.451 , 381.667 ), |
| 78 | + ( 29.080 , 384.864 ), |
| 79 | + ( 29.685 , 378.912 ), |
| 80 | + ( 30.264 , 379.603 ), |
| 81 | + ( 30.793 , 365.727 ) |
| 82 | + ] |
| 83 | + bkgd.addBackgroundPoints(bkgdpointlist) |
| 84 | + |
| 85 | + ### Instantiate the phase 1 |
| 86 | + pha1 = CrystalPhase() |
| 87 | + pha1.setName("Ni") |
| 88 | + comp.addPhase(pha1) |
| 89 | + pha1.setATZ(540979.1880) |
| 90 | + # Set the space group |
| 91 | + pha1.setSpaceGroup("Fm-3m") |
| 92 | + |
| 93 | + # Create a lattice for the phase |
| 94 | + lat1 = Lattice() |
| 95 | + pha1.setLattice(lat1) |
| 96 | + lat1.setValue("a", 3.524) |
| 97 | + fit.mapVP("v_a", lat1, "a") |
| 98 | + # Add an atom |
| 99 | + a1 = configureAtom(pha1, "Ni", "Ni", 0.0, 0.00000, 0.0, 0.38787, 1.0) |
| 100 | + fit.mapVP("v_biso", a1.getADP(), "Biso") |
| 101 | + |
| 102 | + # Instantiate the peak-shape profile function. |
| 103 | + prof1 = PseudoVoigtProfile() |
| 104 | + pha1.setPeakProfile(prof1) |
| 105 | + prof1.setValue("scale" , 0.34741e-7) |
| 106 | + prof1.setValue("eta0", 0.8) |
| 107 | + prof1.setValue("V", -0.007618) |
| 108 | + prof1.setValue("W", 0.006255) |
| 109 | + prof1.setValue("X", 0.018961) |
| 110 | + # do some constraints |
| 111 | + fit.mapVP("v_pscale", prof1, "scale") |
| 112 | + fit.mapVP("v_eta0", prof1, "eta0") |
| 113 | + fit.mapVP("v_V", prof1, "V") |
| 114 | + fit.mapVP("v_W", prof1, "W") |
| 115 | + fit.mapVP("v_X", prof1, "X") |
| 116 | + |
| 117 | + # Fitting |
| 118 | + stage1(fit) |
| 119 | + stage2(fit) |
| 120 | + stage3(fit) |
| 121 | + stage3b(fit) |
| 122 | + stage4(fit) |
| 123 | + stage5(fit) |
| 124 | + stage6(fit) |
| 125 | + stage7(fit) |
| 126 | + stage8(fit) |
| 127 | + stage9(fit) |
| 128 | + stage10(fit) |
| 129 | + stage11(fit) |
| 130 | + fit.printResults() |
| 131 | + fit.saveResults("ni.dif.res") |
| 132 | + comp.saveFitArrays("ni.dif.fit") |
| 133 | + |
| 134 | + if 0: |
| 135 | + from pylab import plot, show |
| 136 | + x0,y0,u0 = comp.getDataArrays() |
| 137 | + x1,y1 = comp.getFitArrays() |
| 138 | + from RefinementAPI.utils import rebinArray |
| 139 | + y0i = rebinArray(y0, x0, x1) |
| 140 | + plot(x1, y0i, x1, y1) |
| 141 | + show() |
| 142 | + |
| 143 | +def stage1(fit): |
| 144 | + print "stage 1" |
| 145 | + fit.fixAll() |
| 146 | + fit.guessV("v_pscale") |
| 147 | + fit.refine() |
| 148 | + fit.printResults() |
| 149 | + return |
| 150 | + |
| 151 | +def stage2(fit): |
| 152 | + print "stage 2" |
| 153 | + fit.fixAll() |
| 154 | + fit.guessV("v_pscale") |
| 155 | + fit.guessV("v_zshift") |
| 156 | + fit.refine() |
| 157 | + fit.printResults() |
| 158 | + return |
| 159 | + |
| 160 | +def stage3(fit): |
| 161 | + print "stage 3" |
| 162 | + fit.fixAll() |
| 163 | + fit.guessV("v_pscale") |
| 164 | + fit.guessV("v_zshift") |
| 165 | + fit.guessV("v_biso") |
| 166 | + fit.refine() |
| 167 | + fit.printResults() |
| 168 | + return |
| 169 | + |
| 170 | +def stage3b(fit): |
| 171 | + print "stage 3b" |
| 172 | + fit.fixAll() |
| 173 | + fit.guessV("v_eta0") |
| 174 | + fit.refine() |
| 175 | + fit.printResults() |
| 176 | + return |
| 177 | + |
| 178 | +def stage4(fit): |
| 179 | + print "stage 4" |
| 180 | + fit.fixAll() |
| 181 | + fit.guessV("v_eta0") |
| 182 | + fit.guessV("v_pscale") |
| 183 | + fit.guessV("v_zshift") |
| 184 | + fit.guessV("v_biso") |
| 185 | + fit.refine() |
| 186 | + fit.printResults() |
| 187 | + return |
| 188 | + |
| 189 | +def stage5(fit): |
| 190 | + print "stage 5" |
| 191 | + fit.fixAll() |
| 192 | + fit.guessV("v_pscale") |
| 193 | + fit.guessV("v_eta0") |
| 194 | + fit.guessV("v_zshift") |
| 195 | + fit.guessV("v_biso") |
| 196 | + fit.guessV("v_V") |
| 197 | + fit.refine() |
| 198 | + fit.printResults() |
| 199 | + return |
| 200 | + |
| 201 | +def stage6(fit): |
| 202 | + print "stage 6" |
| 203 | + fit.fixAll() |
| 204 | + fit.guessV("v_eta0") |
| 205 | + fit.guessV("v_pscale") |
| 206 | + fit.guessV("v_zshift") |
| 207 | + fit.guessV("v_biso") |
| 208 | + fit.guessV("v_W") |
| 209 | + fit.refine() |
| 210 | + fit.printResults() |
| 211 | + return |
| 212 | + |
| 213 | +def stage7(fit): |
| 214 | + print "stage 7" |
| 215 | + fit.fixAll() |
| 216 | + fit.guessV("v_eta0") |
| 217 | + fit.guessV("v_pscale") |
| 218 | + fit.guessV("v_zshift") |
| 219 | + fit.guessV("v_biso") |
| 220 | + fit.guessV("v_X") |
| 221 | + fit.refine() |
| 222 | + fit.printResults() |
| 223 | + return |
| 224 | + |
| 225 | +def stage8(fit): |
| 226 | + print "stage 8" |
| 227 | + fit.fixAll() |
| 228 | + fit.guessV("v_eta0") |
| 229 | + fit.guessV("v_pscale") |
| 230 | + fit.guessV("v_zshift") |
| 231 | + fit.guessV("v_biso") |
| 232 | + fit.guessV("v_W") |
| 233 | + fit.guessV("v_X") |
| 234 | + fit.refine() |
| 235 | + fit.printResults() |
| 236 | + return |
| 237 | + |
| 238 | +def stage9(fit): |
| 239 | + print "stage 9" |
| 240 | + fit.fixAll() |
| 241 | + fit.guessV("v_eta0") |
| 242 | + fit.guessV("v_pscale") |
| 243 | + fit.guessV("v_zshift") |
| 244 | + fit.guessV("v_biso") |
| 245 | + #fit.guessV("v_U") |
| 246 | + fit.guessV("v_V") |
| 247 | + #fit.guessV("v_W") |
| 248 | + fit.guessV("v_X") |
| 249 | + fit.refine() |
| 250 | + fit.printResults() |
| 251 | + return |
| 252 | + |
| 253 | +def stage10(fit): |
| 254 | + print "stage 10" |
| 255 | + fit.fixAll() |
| 256 | + fit.guessV("v_eta0") |
| 257 | + fit.guessV("v_pscale") |
| 258 | + fit.guessV("v_zshift") |
| 259 | + fit.guessV("v_biso") |
| 260 | + #fit.guessV("v_U") |
| 261 | + fit.guessV("v_V") |
| 262 | + fit.guessV("v_W") |
| 263 | + fit.guessV("v_X") |
| 264 | + fit.refine() |
| 265 | + fit.printResults() |
| 266 | + return |
| 267 | + |
| 268 | +def stage11(fit): |
| 269 | + print "stage 11" |
| 270 | + fit.guessV("v_zshift") |
| 271 | + fit.guessV("v_pscale") |
| 272 | + fit.guessV("v_V") |
| 273 | + fit.guessV("v_W") |
| 274 | + fit.guessV("v_X") |
| 275 | + fit.guessV("v_eta0") |
| 276 | + fit.guessV("v_biso") |
| 277 | + fit.guessV("v_a") |
| 278 | + fit.refine() |
| 279 | + fit.printResults() |
| 280 | + return |
| 281 | + |
| 282 | +if __name__ == "__main__": |
| 283 | + fit = Fit() |
| 284 | + runfit(fit) |
0 commit comments