Pair Distribution Function: Si, NPD¶
This example demonstrates a pair distribution function (PDF) analysis of Si, based on data collected from a time-of-flight neutron powder diffraction experiment at NOMAD at SNS.
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_max = 40
# Set global plot range for plots
project.plotter.x_max = 40
Add Structure¶
In [6]:
Copied!
project.structures.create(name='si')
project.structures.create(name='si')
In [7]:
Copied!
structure = project.structures['si']
structure.space_group.name_h_m.value = 'F d -3 m'
structure.space_group.it_coordinate_system_code = '1'
structure.cell.length_a = 5.43146
structure.atom_sites.create(
label='Si',
type_symbol='Si',
fract_x=0,
fract_y=0,
fract_z=0,
wyckoff_letter='a',
b_iso=0.5,
)
structure = project.structures['si']
structure.space_group.name_h_m.value = 'F d -3 m'
structure.space_group.it_coordinate_system_code = '1'
structure.cell.length_a = 5.43146
structure.atom_sites.create(
label='Si',
type_symbol='Si',
fract_x=0,
fract_y=0,
fract_z=0,
wyckoff_letter='a',
b_iso=0.5,
)
Add Experiment¶
In [8]:
Copied!
data_path = ed.download_data(id=5, destination='data')
data_path = ed.download_data(id=5, destination='data')
Getting data...
Data #5: NOM_9999_Si_640g_PAC_50_ff_ftfrgr_up-to-50.gr
✅ Data #5 downloaded to 'data/ed-5.gr'
In [9]:
Copied!
project.experiments.add_from_data_path(
name='nomad',
data_path=data_path,
sample_form='powder',
beam_mode='time-of-flight',
radiation_probe='neutron',
scattering_type='total',
)
project.experiments.add_from_data_path(
name='nomad',
data_path=data_path,
sample_form='powder',
beam_mode='time-of-flight',
radiation_probe='neutron',
scattering_type='total',
)
Warning: No uncertainty (sy) column provided. Defaulting to 0.03.
Data loaded successfully
Experiment 🔬 'nomad'. Number of data points: 5033.
In [10]:
Copied!
experiment = project.experiments['nomad']
experiment.linked_phases.create(id='si', scale=1.0)
experiment.peak.damp_q = 0.02
experiment.peak.broad_q = 0.03
experiment.peak.cutoff_q = 35.0
experiment.peak.sharp_delta_1 = 0.0
experiment.peak.sharp_delta_2 = 4.0
experiment.peak.damp_particle_diameter = 0
experiment = project.experiments['nomad']
experiment.linked_phases.create(id='si', scale=1.0)
experiment.peak.damp_q = 0.02
experiment.peak.broad_q = 0.03
experiment.peak.cutoff_q = 35.0
experiment.peak.sharp_delta_1 = 0.0
experiment.peak.sharp_delta_2 = 4.0
experiment.peak.damp_particle_diameter = 0
Select Fitting Parameters¶
In [11]:
Copied!
project.structures['si'].cell.length_a.free = True
project.structures['si'].atom_sites['Si'].b_iso.free = True
experiment.linked_phases['si'].scale.free = True
project.structures['si'].cell.length_a.free = True
project.structures['si'].atom_sites['Si'].b_iso.free = True
experiment.linked_phases['si'].scale.free = True
In [12]:
Copied!
experiment.peak.damp_q.free = True
experiment.peak.broad_q.free = True
experiment.peak.sharp_delta_1.free = True
experiment.peak.sharp_delta_2.free = True
experiment.peak.damp_q.free = True
experiment.peak.broad_q.free = True
experiment.peak.sharp_delta_1.free = True
experiment.peak.sharp_delta_2.free = True
Run Fitting¶
In [13]:
Copied!
project.analysis.fit()
project.analysis.show_fit_results()
project.analysis.fit()
project.analysis.show_fit_results()
Using experiment 🔬 'nomad' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit (reduced χ²) change:
| iteration | χ² | improvement [%] | |
|---|---|---|---|
| 1 | 1 | 3102.63 | |
| 2 | 11 | 2177.55 | 29.8% ↓ |
| 3 | 19 | 345.28 | 84.1% ↓ |
| 4 | 27 | 180.23 | 47.8% ↓ |
| 5 | 35 | 170.60 | 5.3% ↓ |
| 6 | 68 | 170.54 |
🏆 Best goodness-of-fit (reduced χ²) is 170.54 at iteration 67
✅ Fitting complete.
Fit results
✅ Success: True
⏱️ Fitting time: 16.42 seconds
📏 Goodness-of-fit (reduced χ²): 170.54
📏 R-factor (Rf): 8.40%
📏 R-factor squared (Rf²): 8.30%
📏 Weighted R-factor (wR): 8.30%
📈 Fitted parameters:
| datablock | category | entry | parameter | start | fitted | uncertainty | units | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | si | cell | length_a | 5.4315 | 5.4306 | 0.0000 | Å | 0.02 % ↓ | |
| 2 | si | atom_site | Si | b_iso | 0.5000 | 0.7170 | 0.0055 | Ų | 43.40 % ↑ |
| 3 | nomad | linked_phases | si | scale | 1.0000 | 1.2728 | 0.0014 | 27.28 % ↑ | |
| 4 | nomad | peak | damp_q | 0.0200 | 0.0251 | 0.0001 | Å⁻¹ | 25.66 % ↑ | |
| 5 | nomad | peak | broad_q | 0.0300 | 0.0183 | 0.0003 | Å⁻² | 39.10 % ↓ | |
| 6 | nomad | peak | sharp_delta_1 | 0.0000 | 2.5400 | 0.0529 | Å | N/A | |
| 7 | nomad | peak | sharp_delta_2 | 4.0000 | -1.7525 | 0.1244 | Ų | 143.81 % ↓ |
Plot Measured vs Calculated¶
In [14]:
Copied!
project.plot_meas_vs_calc(expt_name='nomad', show_residual=False)
project.plot_meas_vs_calc(expt_name='nomad', show_residual=False)