Structure Refinement: LBCO, HRPT¶
This minimalistic example is designed to show how Rietveld refinement of a crystal structure can be performed when both the sample model and experiment are defined using CIF files.
For this example, constant-wavelength neutron powder diffraction data for La0.5Ba0.5CoO3 from HRPT at PSI is used.
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
Step 1: Define Project¶
# Create minimal project without name and description
project = ed.Project()
Step 2: Define Sample Model¶
# Download CIF file from repository
model_path = ed.download_data(id=1, destination='data')
Getting data...
Data #1: La0.5Ba0.5CoO3 (crystal structure)
✅ Data #1 downloaded to 'data/ed-1.cif'
project.sample_models.add(cif_path=model_path)
Step 3: Define Experiment¶
# Download CIF file from repository
expt_path = ed.download_data(id=2, destination='data')
Getting data...
Data #2: La0.5Ba0.5CoO3, HRPT (PSI), 300 K
✅ Data #2 downloaded to 'data/ed-2.cif'
project.experiments.add(cif_path=expt_path)
Step 4: Perform Analysis¶
# Start refinement. All parameters, which have standard uncertainties
# in the input CIF files, are refined by default.
project.analysis.fit()
Using experiment 🔬 'hrpt' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit (reduced χ²) change:
| iteration | χ² | improvement [%] | |
|---|---|---|---|
| 1 | 1 | 165.50 | |
| 2 | 28 | 33.67 | 79.7% ↓ |
| 3 | 45 | 10.85 | 67.8% ↓ |
| 4 | 63 | 6.43 | 40.7% ↓ |
| 5 | 81 | 3.33 | 48.2% ↓ |
| 6 | 98 | 2.23 | 33.2% ↓ |
| 7 | 116 | 1.91 | 14.5% ↓ |
| 8 | 133 | 1.50 | 21.1% ↓ |
| 9 | 150 | 1.45 | 3.6% ↓ |
| 10 | 167 | 1.34 | 7.7% ↓ |
| 11 | 185 | 1.29 | 3.4% ↓ |
| 12 | 276 | 1.29 |
🏆 Best goodness-of-fit (reduced χ²) is 1.29 at iteration 261
✅ Fitting complete.
Fit results
✅ Success: True
⏱️ Fitting time: 16.55 seconds
📏 Goodness-of-fit (reduced χ²): 1.29
📏 R-factor (Rf): 5.64%
📏 R-factor squared (Rf²): 5.29%
📏 Weighted R-factor (wR): 4.45%
📈 Fitted parameters:
| datablock | category | entry | parameter | start | fitted | uncertainty | units | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | lbco | cell | length_a | 3.8800 | 3.8909 | 0.0000 | Å | 0.28 % ↑ | |
| 2 | lbco | atom_site | La | b_iso | 0.5000 | 0.5051 | 6011.6004 | Ų | 1.02 % ↑ |
| 3 | lbco | atom_site | Ba | b_iso | 0.5000 | 0.5052 | 9770.5350 | Ų | 1.04 % ↑ |
| 4 | lbco | atom_site | Co | b_iso | 0.5000 | 0.2371 | 0.0611 | Ų | 52.59 % ↓ |
| 5 | lbco | atom_site | O | b_iso | 0.5000 | 1.3935 | 0.0168 | Ų | 178.70 % ↑ |
| 6 | hrpt | linked_phases | lbco | scale | 10.0000 | 9.1349 | 0.0643 | 8.65 % ↓ | |
| 7 | hrpt | peak | broad_gauss_u | 0.1000 | 0.0816 | 0.0031 | deg² | 18.44 % ↓ | |
| 8 | hrpt | peak | broad_gauss_v | -0.1000 | -0.1159 | 0.0067 | deg² | 15.90 % ↑ | |
| 9 | hrpt | peak | broad_gauss_w | 0.1000 | 0.1204 | 0.0033 | deg² | 20.45 % ↑ | |
| 10 | hrpt | peak | broad_lorentz_y | 0.1000 | 0.0844 | 0.0021 | deg | 15.57 % ↓ | |
| 11 | hrpt | instrument | twotheta_offset | 0.6000 | 0.6226 | 0.0010 | deg | 3.76 % ↑ | |
| 12 | hrpt | background | 1 | y | 170.0000 | 168.4242 | 1.3977 | 0.93 % ↓ | |
| 13 | hrpt | background | 2 | y | 170.0000 | 164.3715 | 1.0025 | 3.31 % ↓ | |
| 14 | hrpt | background | 3 | y | 170.0000 | 166.8870 | 0.7391 | 1.83 % ↓ | |
| 15 | hrpt | background | 4 | y | 170.0000 | 175.3977 | 0.6586 | 3.18 % ↑ | |
| 16 | hrpt | background | 5 | y | 170.0000 | 174.3027 | 0.9113 | 2.53 % ↑ |
project.experiments.show_names()
Defined experiments 🔬
['hrpt']
project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
Step 5: Show Project Summary¶
project.summary.show_report()
PROJECT INFO ━━━━━━━━━━━━
Title
Untitled Project
CRYSTALLOGRAPHIC DATA ━━━━━━━━━━━━━━━━━━━━━
Phase datablock
🧩 lbco
Space group
P m -3 m
Cell parameters
| Parameter | Value | |
|---|---|---|
| 1 | a | 3.89087 |
| 2 | b | 3.89087 |
| 3 | c | 3.89087 |
| 4 | alpha | 90.00000 |
| 5 | beta | 90.00000 |
| 6 | gamma | 90.00000 |
Atom sites
| label | type | x | y | z | occ | Biso | |
|---|---|---|---|---|---|---|---|
| 1 | La | La | 0.00000 | 0.00000 | 0.00000 | 0.50000 | 0.50512 |
| 2 | Ba | Ba | 0.00000 | 0.00000 | 0.00000 | 0.50000 | 0.50518 |
| 3 | Co | Co | 0.50000 | 0.50000 | 0.50000 | 1.00000 | 0.23706 |
| 4 | O | O | 0.00000 | 0.50000 | 0.50000 | 1.00000 | 1.39351 |
EXPERIMENTS ━━━━━━━━━━━
Experiment datablock
🔬 hrpt
Experiment type
powder, neutron, constant wavelength
Wavelength
1.49400
2θ offset
0.62258
Profile type
PeakProfileTypeEnum.PSEUDO_VOIGT
Peak broadening (Gaussian)
| Parameter | Value | |
|---|---|---|
| 1 | U | 0.08156 |
| 2 | V | -0.11590 |
| 3 | W | 0.12045 |
Peak broadening (Lorentzian)
| Parameter | Value | |
|---|---|---|
| 1 | X | 0.00000 |
| 2 | Y | 0.08443 |
FITTING ━━━━━━━
Calculation engine
cryspy
Minimization engine
lmfit (leastsq)
Fit quality
| metric | value | |
|---|---|---|
| 1 | Goodness-of-fit (reduced χ²) | 1.29 |