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 Sample Model¶
In [6]:
Copied!
project.sample_models.add(name='si')
project.sample_models.add(name='si')
In [7]:
Copied!
sample_model = project.sample_models['si']
sample_model.space_group.name_h_m.value = 'F d -3 m'
sample_model.space_group.it_coordinate_system_code = '1'
sample_model.cell.length_a = 5.43146
sample_model.atom_sites.add(
label='Si',
type_symbol='Si',
fract_x=0,
fract_y=0,
fract_z=0,
wyckoff_letter='a',
b_iso=0.5,
)
sample_model = project.sample_models['si']
sample_model.space_group.name_h_m.value = 'F d -3 m'
sample_model.space_group.it_coordinate_system_code = '1'
sample_model.cell.length_a = 5.43146
sample_model.atom_sites.add(
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(
name='nomad',
data_path=data_path,
sample_form='powder',
beam_mode='time-of-flight',
radiation_probe='neutron',
scattering_type='total',
)
project.experiments.add(
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.add(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.add(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.sample_models['si'].cell.length_a.free = True
project.sample_models['si'].atom_sites['Si'].b_iso.free = True
experiment.linked_phases['si'].scale.free = True
project.sample_models['si'].cell.length_a.free = True
project.sample_models['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.current_calculator = 'pdffit'
project.analysis.fit()
project.analysis.current_calculator = 'pdffit'
project.analysis.fit()
Current calculator changed to
pdffit
Using experiment 🔬 'nomad' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit (reduced χ²) change:
| iteration | χ² | improvement [%] | |
|---|---|---|---|
| 1 | 1 | 3103.72 | |
| 2 | 11 | 270.15 | 91.3% ↓ |
| 3 | 19 | 239.11 | 11.5% ↓ |
| 4 | 52 | 239.01 |
🏆 Best goodness-of-fit (reduced χ²) is 239.01 at iteration 51
✅ Fitting complete.
Fit results
✅ Success: True
⏱️ Fitting time: 9.88 seconds
📏 Goodness-of-fit (reduced χ²): 239.01
📏 R-factor (Rf): 9.88%
📏 R-factor squared (Rf²): 9.82%
📏 Weighted R-factor (wR): 9.82%
📈 Fitted parameters:
| datablock | category | entry | parameter | start | fitted | uncertainty | units | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | si | cell | length_a | 5.4315 | 5.4315 | N/A | Å | 0.00 % ↓ | |
| 2 | si | atom_site | Si | b_iso | 0.5000 | 0.5000 | N/A | Ų | 0.00 % ↓ |
| 3 | nomad | linked_phases | si | scale | 1.0000 | 1.2501 | N/A | 25.01 % ↑ | |
| 4 | nomad | peak | damp_q | 0.0200 | 0.0233 | N/A | Å⁻¹ | 16.62 % ↑ | |
| 5 | nomad | peak | broad_q | 0.0300 | 0.0290 | N/A | Å⁻² | 3.46 % ↓ | |
| 6 | nomad | peak | sharp_delta_1 | 0.0000 | 0.0078 | N/A | Å | N/A | |
| 7 | nomad | peak | sharp_delta_2 | 4.0000 | 3.8877 | N/A | Ų | 2.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)