Pair Distribution Function: NaCl, XRD¶
This example demonstrates a pair distribution function (PDF) analysis of NaCl, based on data collected from an X-ray powder diffraction experiment.
The dataset is taken from: https://github.com/diffpy/add2019-diffpy-cmi/tree/master
Import Library¶
In [2]:
Copied!
import easydiffraction as ed
import easydiffraction as ed
Create Project¶
In [3]:
Copied!
project = ed.Project()
project = ed.Project()
Set Plotting Engine¶
In [4]:
Copied!
# Keep the auto-selected engine. Alternatively, you can uncomment the
# line below to explicitly set the engine to the required one.
# project.plotter.engine = 'plotly'
# Keep the auto-selected engine. Alternatively, you can uncomment the
# line below to explicitly set the engine to the required one.
# project.plotter.engine = 'plotly'
In [5]:
Copied!
# Set global plot range for plots
project.plotter.x_min = 2.0
project.plotter.x_max = 30.0
# Set global plot range for plots
project.plotter.x_min = 2.0
project.plotter.x_max = 30.0
Add Sample Model¶
In [6]:
Copied!
project.sample_models.add(name='nacl')
project.sample_models.add(name='nacl')
In [7]:
Copied!
project.sample_models['nacl'].space_group.name_h_m = 'F m -3 m'
project.sample_models['nacl'].space_group.it_coordinate_system_code = '1'
project.sample_models['nacl'].cell.length_a = 5.62
project.sample_models['nacl'].atom_sites.add(
label='Na',
type_symbol='Na',
fract_x=0,
fract_y=0,
fract_z=0,
wyckoff_letter='a',
b_iso=1.0,
)
project.sample_models['nacl'].atom_sites.add(
label='Cl',
type_symbol='Cl',
fract_x=0.5,
fract_y=0.5,
fract_z=0.5,
wyckoff_letter='b',
b_iso=1.0,
)
project.sample_models['nacl'].space_group.name_h_m = 'F m -3 m'
project.sample_models['nacl'].space_group.it_coordinate_system_code = '1'
project.sample_models['nacl'].cell.length_a = 5.62
project.sample_models['nacl'].atom_sites.add(
label='Na',
type_symbol='Na',
fract_x=0,
fract_y=0,
fract_z=0,
wyckoff_letter='a',
b_iso=1.0,
)
project.sample_models['nacl'].atom_sites.add(
label='Cl',
type_symbol='Cl',
fract_x=0.5,
fract_y=0.5,
fract_z=0.5,
wyckoff_letter='b',
b_iso=1.0,
)
Add Experiment¶
In [8]:
Copied!
data_path = ed.download_data(id=4, destination='data')
data_path = ed.download_data(id=4, destination='data')
Getting data...
Data #4: NaCl.gr
✅ Data #4 downloaded to 'data/ed-4.gr'
In [9]:
Copied!
project.experiments.add(
name='xray_pdf',
data_path=data_path,
sample_form='powder',
beam_mode='constant wavelength',
radiation_probe='xray',
scattering_type='total',
)
project.experiments.add(
name='xray_pdf',
data_path=data_path,
sample_form='powder',
beam_mode='constant wavelength',
radiation_probe='xray',
scattering_type='total',
)
Warning: No uncertainty (sy) column provided. Defaulting to 0.03.
Data loaded successfully
Experiment 🔬 'xray_pdf'. Number of data points: 5000
In [10]:
Copied!
project.experiments['xray_pdf'].show_supported_peak_profile_types()
project.experiments['xray_pdf'].show_supported_peak_profile_types()
Supported peak profile types
| Peak profile type | Description | |
|---|---|---|
| 1 | gaussian-damped-sinc | Gaussian-damped sinc profile for pair distribution function (PDF) analysis. |
In [11]:
Copied!
project.experiments['xray_pdf'].show_current_peak_profile_type()
project.experiments['xray_pdf'].show_current_peak_profile_type()
Current peak profile type
PeakProfileTypeEnum.GAUSSIAN_DAMPED_SINC
In [12]:
Copied!
project.experiments['xray_pdf'].peak_profile_type = 'gaussian-damped-sinc'
project.experiments['xray_pdf'].peak_profile_type = 'gaussian-damped-sinc'
Peak profile type for experiment 'xray_pdf' changed to
gaussian-damped-sinc
In [13]:
Copied!
project.experiments['xray_pdf'].peak.damp_q = 0.03
project.experiments['xray_pdf'].peak.broad_q = 0
project.experiments['xray_pdf'].peak.cutoff_q = 21
project.experiments['xray_pdf'].peak.sharp_delta_1 = 0
project.experiments['xray_pdf'].peak.sharp_delta_2 = 5
project.experiments['xray_pdf'].peak.damp_particle_diameter = 0
project.experiments['xray_pdf'].peak.damp_q = 0.03
project.experiments['xray_pdf'].peak.broad_q = 0
project.experiments['xray_pdf'].peak.cutoff_q = 21
project.experiments['xray_pdf'].peak.sharp_delta_1 = 0
project.experiments['xray_pdf'].peak.sharp_delta_2 = 5
project.experiments['xray_pdf'].peak.damp_particle_diameter = 0
In [14]:
Copied!
project.experiments['xray_pdf'].linked_phases.add(id='nacl', scale=0.5)
project.experiments['xray_pdf'].linked_phases.add(id='nacl', scale=0.5)
Select Fitting Parameters¶
In [15]:
Copied!
project.sample_models['nacl'].cell.length_a.free = True
project.sample_models['nacl'].atom_sites['Na'].b_iso.free = True
project.sample_models['nacl'].atom_sites['Cl'].b_iso.free = True
project.sample_models['nacl'].cell.length_a.free = True
project.sample_models['nacl'].atom_sites['Na'].b_iso.free = True
project.sample_models['nacl'].atom_sites['Cl'].b_iso.free = True
In [16]:
Copied!
project.experiments['xray_pdf'].linked_phases['nacl'].scale.free = True
project.experiments['xray_pdf'].peak.damp_q.free = True
project.experiments['xray_pdf'].peak.sharp_delta_2.free = True
project.experiments['xray_pdf'].linked_phases['nacl'].scale.free = True
project.experiments['xray_pdf'].peak.damp_q.free = True
project.experiments['xray_pdf'].peak.sharp_delta_2.free = True
Run Fitting¶
In [17]:
Copied!
project.analysis.current_calculator = 'pdffit'
project.analysis.fit()
project.analysis.current_calculator = 'pdffit'
project.analysis.fit()
Current calculator changed to
pdffit
Using experiment 🔬 'xray_pdf' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit (reduced χ²) change:
| iteration | χ² | improvement [%] | |
|---|---|---|---|
| 1 | 1 | 163.09 | |
| 2 | 10 | 19.59 | 88.0% ↓ |
| 3 | 17 | 10.95 | 44.1% ↓ |
| 4 | 24 | 10.69 | 2.3% ↓ |
| 5 | 46 | 10.69 |
🏆 Best goodness-of-fit (reduced χ²) is 10.69 at iteration 45
✅ Fitting complete.
Fit results
✅ Success: True
⏱️ Fitting time: 10.17 seconds
📏 Goodness-of-fit (reduced χ²): 10.69
📏 R-factor (Rf): 34.82%
📏 R-factor squared (Rf²): 30.63%
📏 Weighted R-factor (wR): 30.63%
📈 Fitted parameters:
| datablock | category | entry | parameter | start | fitted | uncertainty | units | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | nacl | cell | length_a | 5.6200 | 5.6175 | N/A | Å | 0.04 % ↓ | |
| 2 | nacl | atom_site | Na | b_iso | 1.0000 | 1.0000 | N/A | Ų | 0.00 % ↓ |
| 3 | nacl | atom_site | Cl | b_iso | 1.0000 | 1.0000 | N/A | Ų | 0.00 % ↓ |
| 4 | xray_pdf | linked_phases | nacl | scale | 0.5000 | 0.4469 | N/A | 10.61 % ↓ | |
| 5 | xray_pdf | peak | damp_q | 0.0300 | 0.0625 | N/A | Å⁻¹ | 108.42 % ↑ | |
| 6 | xray_pdf | peak | sharp_delta_2 | 5.0000 | 4.3628 | N/A | Ų | 12.74 % ↓ |
Plot Measured vs Calculated¶
In [18]:
Copied!
project.plot_meas_vs_calc(expt_name='xray_pdf')
project.plot_meas_vs_calc(expt_name='xray_pdf')