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