|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | + |
| 4 | +"""Perform simple refinement of Ni structure to the experimental x-ray PDF. |
| 5 | +Save fitted curve, refined structure and results summary. |
| 6 | +""" |
| 7 | + |
| 8 | +import matplotlib.pyplot as plt |
| 9 | +import numpy |
| 10 | + |
| 11 | +from diffpy.pdffit2 import PdfFit |
| 12 | + |
| 13 | +# Create new PDF calculator object. |
| 14 | +pf = PdfFit() |
| 15 | + |
| 16 | +# Load data ------------------------------------------------------------------ |
| 17 | + |
| 18 | +# Load experimental x-ray PDF data |
| 19 | +qmax = 30.0 # Q-cutoff used in PDF calculation in 1/A |
| 20 | +qdamp = 0.01 # instrument Q-resolution factor, responsible for PDF decay |
| 21 | +pf.read_data("Ni-xray.gr", "X", qmax, qdamp) |
| 22 | + |
| 23 | +# Load nickel structure, must be in PDFFIT or DISCUS format |
| 24 | +pf.read_struct("Ni.stru") |
| 25 | + |
| 26 | +# Configure Refinement ------------------------------------------------------- |
| 27 | + |
| 28 | +# Refine lattice parameters a, b, c. |
| 29 | +# Make them all equal to parameter @1. |
| 30 | +pf.constrain(pf.lat(1), "@1") |
| 31 | +pf.constrain(pf.lat(2), "@1") |
| 32 | +pf.constrain(pf.lat(3), "@1") |
| 33 | +# set initial value of parameter @1 |
| 34 | +pf.setpar(1, pf.lat(1)) |
| 35 | + |
| 36 | +# Refine phase scale factor. Right side can have formulas. |
| 37 | +pf.constrain("pscale", "@20 * 2") |
| 38 | +pf.setpar(20, pf.getvar(pf.pscale) / 2.0) |
| 39 | + |
| 40 | +# Refine PDF damping due to instrument Q-resolution. |
| 41 | +# Left side can be also passed as a reference to PdfFit object |
| 42 | +pf.constrain(pf.qdamp, "@21") |
| 43 | +pf.setpar(21, 0.03) |
| 44 | + |
| 45 | +# Refine sharpening factor for correlated motion of close atoms. |
| 46 | +pf.constrain(pf.delta2, 22) |
| 47 | +pf.setpar(22, 0.0003) |
| 48 | + |
| 49 | +# Set all temperature factors isotropic and equal to @4 |
| 50 | +for idx in range(1, 5): |
| 51 | + pf.constrain(pf.u11(idx), "@4") |
| 52 | + pf.constrain(pf.u22(idx), "@4") |
| 53 | + pf.constrain(pf.u33(idx), "@4") |
| 54 | +pf.setpar(4, pf.u11(1)) |
| 55 | + |
| 56 | +# Refine --------------------------------------------------------------------- |
| 57 | + |
| 58 | +pf.pdfrange(1, 1.5, 19.99) |
| 59 | +pf.refine() |
| 60 | + |
| 61 | +# Save results --------------------------------------------------------------- |
| 62 | + |
| 63 | +pf.save_pdf(1, "Ni_refinement.fgr") |
| 64 | +pf.save_struct(1, "Ni_refinement.rstr") |
| 65 | +pf.save_res("Ni_refinement.res") |
| 66 | + |
| 67 | +# Plot results --------------------------------------------------------------- |
| 68 | + |
| 69 | +# obtain data from PdfFit calculator object |
| 70 | +r = pf.getR() |
| 71 | +Gobs = pf.getpdf_obs() |
| 72 | +Gfit = pf.getpdf_fit() |
| 73 | + |
| 74 | +# calculate difference curve |
| 75 | +Gdiff = numpy.array(Gobs) - numpy.array(Gfit) |
| 76 | +Gdiff_baseline = -10 |
| 77 | + |
| 78 | +plt.plot(r, Gobs, "ko") |
| 79 | +plt.plot(r, Gfit, "b-") |
| 80 | +plt.plot(r, Gdiff + Gdiff_baseline, "r-") |
| 81 | + |
| 82 | +plt.xlabel("r (Å)") |
| 83 | +plt.ylabel("G (Å$^{-2}$)") |
| 84 | +plt.title("Fit of nickel to x-ray experimental PDF") |
| 85 | + |
| 86 | +# display plot window, this must be the last command in the script |
| 87 | +plt.show() |
0 commit comments