Structure Refinement: LBCO, HRPT¶
This minimalistic example is designed to be as compact as possible for a Rietveld refinement of a crystal structure using constant-wavelength neutron powder diffraction data for La0.5Ba0.5CoO3 from HRPT at PSI.
It does not contain any advanced features or options, and includes no comments or explanations—these can be found in the other tutorials. Default values are used for all parameters if not specified. Only essential and self-explanatory code is provided.
The example is intended for users who are already familiar with the EasyDiffraction library and want to quickly get started with a simple refinement. It is also useful for those who want to see what a refinement might look like in code. For a more detailed explanation of the code, please refer to the other tutorials.
Import Library¶
import easydiffraction as ed
⚠️ 'pycrysfml' module not found. This calculation engine will not be available. ✅ 'cryspy' calculation engine is successfully imported. ✅ 'pdffit' calculation engine is successfully imported.
Step 1: Define Project¶
project = ed.Project()
Step 2: Define Sample Model¶
project.sample_models.add(name='lbco')
sample_model = project.sample_models['lbco']
sample_model.space_group.name_h_m = 'P m -3 m'
sample_model.space_group.it_coordinate_system_code = '1'
sample_model.cell.length_a = 3.88
sample_model.atom_sites.add('La', 'La', 0, 0, 0, b_iso=0.5, occupancy=0.5)
sample_model.atom_sites.add('Ba', 'Ba', 0, 0, 0, b_iso=0.5, occupancy=0.5)
sample_model.atom_sites.add('Co', 'Co', 0.5, 0.5, 0.5, b_iso=0.5)
sample_model.atom_sites.add('O', 'O', 0, 0.5, 0.5, b_iso=0.5)
Step 3: Define Experiment¶
ed.download_from_repository('hrpt_lbco.xye', destination='data')
⚠️ Warning
File 'data/hrpt_lbco.xye' already exists and will not be overwritten.
project.experiments.add(
name='hrpt',
sample_form='powder',
beam_mode='constant wavelength',
radiation_probe='neutron',
data_path='data/hrpt_lbco.xye',
)
Loading measured data from ASCII file /Users/runner/work/diffraction-lib/diffraction-lib/docs/tutorials/data/hrpt_lbco.xye Data loaded successfully Experiment 🔬 'hrpt'. Number of data points: 3098
experiment = project.experiments['hrpt']
experiment.instrument.setup_wavelength = 1.494
experiment.instrument.calib_twotheta_offset = 0.6
experiment.peak.broad_gauss_u = 0.1
experiment.peak.broad_gauss_v = -0.1
experiment.peak.broad_gauss_w = 0.1
experiment.peak.broad_lorentz_y = 0.1
experiment.background.add(x=10, y=170)
experiment.background.add(x=30, y=170)
experiment.background.add(x=50, y=170)
experiment.background.add(x=110, y=170)
experiment.background.add(x=165, y=170)
experiment.excluded_regions.add(minimum=0, maximum=5)
experiment.excluded_regions.add(minimum=165, maximum=180)
experiment.linked_phases.add(id='lbco', scale=10.0)
Step 4: Perform Analysis¶
sample_model.cell.length_a.free = True
sample_model.atom_sites['La'].b_iso.free = True
sample_model.atom_sites['Ba'].b_iso.free = True
sample_model.atom_sites['Co'].b_iso.free = True
sample_model.atom_sites['O'].b_iso.free = True
experiment.instrument.calib_twotheta_offset.free = True
experiment.peak.broad_gauss_u.free = True
experiment.peak.broad_gauss_v.free = True
experiment.peak.broad_gauss_w.free = True
experiment.peak.broad_lorentz_y.free = True
experiment.background['10'].y.free = True
experiment.background['30'].y.free = True
experiment.background['50'].y.free = True
experiment.background['110'].y.free = True
experiment.background['165'].y.free = True
experiment.linked_phases['lbco'].scale.free = True
project.analysis.fit()
Using experiment 🔬 'hrpt' for 'single' fitting 🚀 Starting fit process with 'lmfit (leastsq)'... 📈 Goodness-of-fit (reduced χ²) change:
iteration | χ² | improvement [%] |
---|---|---|
1 |
165.02 |
|
28 |
33.58 |
79.7% ↓ |
45 |
10.82 |
67.8% ↓ |
63 |
6.49 |
40.0% ↓ |
81 |
3.35 |
48.4% ↓ |
98 |
2.24 |
33.1% ↓ |
116 |
1.91 |
14.7% ↓ |
133 |
1.50 |
21.3% ↓ |
150 |
1.45 |
3.6% ↓ |
167 |
1.34 |
7.8% ↓ |
185 |
1.29 |
3.4% ↓ |
276 |
1.29 |
🏆 Best goodness-of-fit (reduced χ²) is 1.29 at iteration 275
✅ Fitting complete.
Fit results
✅ Success: True
⏱️ Fitting time: 2.07 seconds
📏 Goodness-of-fit (reduced χ²): 1.29
📏 R-factor (Rf): 5.63%
📏 R-factor squared (Rf²): 5.27%
📏 Weighted R-factor (wR): 4.41%
📈 Fitted parameters:
datablock | category | entry | parameter | start | fitted | uncertainty | units | change | |
---|---|---|---|---|---|---|---|---|---|
1 | lbco |
atom_sites |
La |
b_iso |
0.5000 |
0.5052 |
3231.6242 |
Ų |
1.04 % ↑ |
2 | lbco |
atom_sites |
Ba |
b_iso |
0.5000 |
0.5049 |
5252.3879 |
Ų |
0.97 % ↑ |
3 | lbco |
atom_sites |
Co |
b_iso |
0.5000 |
0.2370 |
0.0611 |
Ų |
52.60 % ↓ |
4 | lbco |
atom_sites |
O |
b_iso |
0.5000 |
1.3935 |
0.0167 |
Ų |
178.71 % ↑ |
5 | lbco |
cell |
length_a |
3.8800 |
3.8909 |
0.0000 |
Å |
0.28 % ↑ |
|
6 | hrpt |
background |
10 |
y |
170.0000 |
168.5585 |
1.3671 |
0.85 % ↓ |
|
7 | hrpt |
background |
30 |
y |
170.0000 |
164.3357 |
0.9992 |
3.33 % ↓ |
|
8 | hrpt |
background |
50 |
y |
170.0000 |
166.8881 |
0.7388 |
1.83 % ↓ |
|
9 | hrpt |
background |
110 |
y |
170.0000 |
175.4006 |
0.6578 |
3.18 % ↑ |
|
10 | hrpt |
background |
165 |
y |
170.0000 |
174.2813 |
0.9105 |
2.52 % ↑ |
|
11 | hrpt |
instrument |
twotheta_offset |
0.6000 |
0.6226 |
0.0010 |
deg |
3.76 % ↑ |
|
12 | hrpt |
linked_phases |
lbco |
scale |
10.0000 |
9.1351 |
0.0642 |
8.65 % ↓ |
|
13 | hrpt |
peak |
broad_gauss_u |
0.1000 |
0.0816 |
0.0031 |
deg² |
18.43 % ↓ |
|
14 | hrpt |
peak |
broad_gauss_v |
-0.1000 |
-0.1159 |
0.0067 |
deg² |
15.93 % ↑ |
|
15 | hrpt |
peak |
broad_gauss_w |
0.1000 |
0.1204 |
0.0033 |
deg² |
20.45 % ↑ |
|
16 | hrpt |
peak |
broad_lorentz_y |
0.1000 |
0.0844 |
0.0021 |
deg |
15.55 % ↓ |
project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)