Structure Refinement: HS, HRPT¶
This example demonstrates a Rietveld refinement of HS crystal structure using constant wavelength neutron powder diffraction data from HRPT at PSI.
Import Library¶
In [2]:
Copied!
from easydiffraction import ExperimentFactory
from easydiffraction import Project
from easydiffraction import SampleModelFactory
from easydiffraction import download_from_repository
from easydiffraction import ExperimentFactory
from easydiffraction import Project
from easydiffraction import SampleModelFactory
from easydiffraction import download_from_repository
In [3]:
Copied!
model = SampleModelFactory.create(name='hs')
model = SampleModelFactory.create(name='hs')
Set Space Group¶
In [4]:
Copied!
model.space_group.name_h_m = 'R -3 m'
model.space_group.it_coordinate_system_code = 'h'
model.space_group.name_h_m = 'R -3 m'
model.space_group.it_coordinate_system_code = 'h'
Set Unit Cell¶
In [5]:
Copied!
model.cell.length_a = 6.9
model.cell.length_c = 14.1
model.cell.length_a = 6.9
model.cell.length_c = 14.1
Set Atom Sites¶
In [6]:
Copied!
model.atom_sites.add_from_args(
    label='Zn',
    type_symbol='Zn',
    fract_x=0,
    fract_y=0,
    fract_z=0.5,
    wyckoff_letter='b',
    b_iso=0.5,
)
model.atom_sites.add_from_args(
    label='Cu',
    type_symbol='Cu',
    fract_x=0.5,
    fract_y=0,
    fract_z=0,
    wyckoff_letter='e',
    b_iso=0.5,
)
model.atom_sites.add_from_args(
    label='O',
    type_symbol='O',
    fract_x=0.21,
    fract_y=-0.21,
    fract_z=0.06,
    wyckoff_letter='h',
    b_iso=0.5,
)
model.atom_sites.add_from_args(
    label='Cl',
    type_symbol='Cl',
    fract_x=0,
    fract_y=0,
    fract_z=0.197,
    wyckoff_letter='c',
    b_iso=0.5,
)
model.atom_sites.add_from_args(
    label='H',
    type_symbol='2H',
    fract_x=0.13,
    fract_y=-0.13,
    fract_z=0.08,
    wyckoff_letter='h',
    b_iso=0.5,
)
model.atom_sites.add_from_args(
    label='Zn',
    type_symbol='Zn',
    fract_x=0,
    fract_y=0,
    fract_z=0.5,
    wyckoff_letter='b',
    b_iso=0.5,
)
model.atom_sites.add_from_args(
    label='Cu',
    type_symbol='Cu',
    fract_x=0.5,
    fract_y=0,
    fract_z=0,
    wyckoff_letter='e',
    b_iso=0.5,
)
model.atom_sites.add_from_args(
    label='O',
    type_symbol='O',
    fract_x=0.21,
    fract_y=-0.21,
    fract_z=0.06,
    wyckoff_letter='h',
    b_iso=0.5,
)
model.atom_sites.add_from_args(
    label='Cl',
    type_symbol='Cl',
    fract_x=0,
    fract_y=0,
    fract_z=0.197,
    wyckoff_letter='c',
    b_iso=0.5,
)
model.atom_sites.add_from_args(
    label='H',
    type_symbol='2H',
    fract_x=0.13,
    fract_y=-0.13,
    fract_z=0.08,
    wyckoff_letter='h',
    b_iso=0.5,
)
Symmetry constraints¶
Show CIF output before applying symmetry constraints.
In [7]:
Copied!
model.show_as_cif()
model.show_as_cif()
Sample model 🧩 'hs' as cif
| CIF | |
|---|---|
| 1 | data_hs | 
| 2 | |
| 3 | _cell.length_a 6.9 | 
| 4 | _cell.length_b 10.0 | 
| 5 | _cell.length_c 14.1 | 
| 6 | _cell.angle_alpha 90.0 | 
| 7 | _cell.angle_beta 90.0 | 
| 8 | _cell.angle_gamma 90.0 | 
| 9 | |
| 10 | _space_group.name_H-M_alt "R -3 m" | 
| 11 | _space_group.IT_coordinate_system_code h | 
| 12 | |
| 13 | loop_ | 
| 14 | _atom_site.label | 
| 15 | _atom_site.type_symbol | 
| 16 | _atom_site.fract_x | 
| 17 | _atom_site.fract_y | 
| 18 | _atom_site.fract_z | 
| 19 | _atom_site.Wyckoff_letter | 
| 20 | _atom_site.occupancy | 
| 21 | _atom_site.B_iso_or_equiv | 
| 22 | _atom_site.adp_type | 
| 23 | Zn Zn 0 0 0.5 b 1.0 0.5 Biso | 
| 24 | Cu Cu 0.5 0 0 e 1.0 0.5 Biso | 
| 25 | O O 0.21 -0.21 0.06 h 1.0 0.5 Biso | 
| 26 | Cl Cl 0 0 0.197 c 1.0 0.5 Biso | 
| 27 | H 2H 0.13 -0.13 0.08 h 1.0 0.5 Biso | 
Apply symmetry constraints.
In [8]:
Copied!
model.apply_symmetry_constraints()
model.apply_symmetry_constraints()
Show CIF output after applying symmetry constraints.
In [9]:
Copied!
model.show_as_cif()
model.show_as_cif()
Sample model 🧩 'hs' as cif
| CIF | |
|---|---|
| 1 | data_hs | 
| 2 | |
| 3 | _cell.length_a 6.9 | 
| 4 | _cell.length_b 6.9 | 
| 5 | _cell.length_c 14.1 | 
| 6 | _cell.angle_alpha 90.0 | 
| 7 | _cell.angle_beta 90.0 | 
| 8 | _cell.angle_gamma 120.0 | 
| 9 | |
| 10 | _space_group.name_H-M_alt "R -3 m" | 
| 11 | _space_group.IT_coordinate_system_code h | 
| 12 | |
| 13 | loop_ | 
| 14 | _atom_site.label | 
| 15 | _atom_site.type_symbol | 
| 16 | _atom_site.fract_x | 
| 17 | _atom_site.fract_y | 
| 18 | _atom_site.fract_z | 
| 19 | _atom_site.Wyckoff_letter | 
| 20 | _atom_site.occupancy | 
| 21 | _atom_site.B_iso_or_equiv | 
| 22 | _atom_site.adp_type | 
| 23 | Zn Zn 0.0 0.0 0.5 b 1.0 0.5 Biso | 
| 24 | Cu Cu 0.5 0.0 0.0 e 1.0 0.5 Biso | 
| 25 | O O 0.21 -0.21 0.06 h 1.0 0.5 Biso | 
| 26 | Cl Cl 0.0 0.0 0.197 c 1.0 0.5 Biso | 
| 27 | H 2H 0.13 -0.13 0.08 h 1.0 0.5 Biso | 
In [10]:
Copied!
download_from_repository('hrpt_hs.xye', destination='data')
download_from_repository('hrpt_hs.xye', destination='data')
Downloading...
File 'hrpt_hs.xye' from 'easyscience/diffraction-lib'
Create Experiment¶
In [11]:
Copied!
expt = ExperimentFactory.create(name='hrpt', data_path='data/hrpt_hs.xye')
expt = ExperimentFactory.create(name='hrpt', data_path='data/hrpt_hs.xye')
Data loaded successfully
Experiment 🔬 'hrpt'. Number of data points: 3220
Set Instrument¶
In [12]:
Copied!
expt.instrument.setup_wavelength = 1.89
expt.instrument.calib_twotheta_offset = 0.0
expt.instrument.setup_wavelength = 1.89
expt.instrument.calib_twotheta_offset = 0.0
Set Peak Profile¶
In [13]:
Copied!
expt.peak.broad_gauss_u = 0.1
expt.peak.broad_gauss_v = -0.2
expt.peak.broad_gauss_w = 0.2
expt.peak.broad_lorentz_x = 0.0
expt.peak.broad_lorentz_y = 0
expt.peak.broad_gauss_u = 0.1
expt.peak.broad_gauss_v = -0.2
expt.peak.broad_gauss_w = 0.2
expt.peak.broad_lorentz_x = 0.0
expt.peak.broad_lorentz_y = 0
Set Background¶
In [14]:
Copied!
expt.background.add_from_args(x=4.4196, y=500)
expt.background.add_from_args(x=6.6207, y=500)
expt.background.add_from_args(x=10.4918, y=500)
expt.background.add_from_args(x=15.4634, y=500)
expt.background.add_from_args(x=45.6041, y=500)
expt.background.add_from_args(x=74.6844, y=500)
expt.background.add_from_args(x=103.4187, y=500)
expt.background.add_from_args(x=121.6311, y=500)
expt.background.add_from_args(x=159.4116, y=500)
expt.background.add_from_args(x=4.4196, y=500)
expt.background.add_from_args(x=6.6207, y=500)
expt.background.add_from_args(x=10.4918, y=500)
expt.background.add_from_args(x=15.4634, y=500)
expt.background.add_from_args(x=45.6041, y=500)
expt.background.add_from_args(x=74.6844, y=500)
expt.background.add_from_args(x=103.4187, y=500)
expt.background.add_from_args(x=121.6311, y=500)
expt.background.add_from_args(x=159.4116, y=500)
Set Linked Phases¶
In [15]:
Copied!
expt.linked_phases.add_from_args(id='hs', scale=0.5)
expt.linked_phases.add_from_args(id='hs', scale=0.5)
In [16]:
Copied!
project = Project()
project = Project()
Set Plotting Engine¶
In [17]:
Copied!
project.plotter.engine = 'plotly'
project.plotter.engine = 'plotly'
Add Sample Model¶
In [18]:
Copied!
project.sample_models.add(model)
project.sample_models.add(model)
Add Experiment¶
In [19]:
Copied!
project.experiments.add(expt)
project.experiments.add(expt)
In [20]:
Copied!
project.analysis.current_calculator = 'cryspy'
project.analysis.current_calculator = 'cryspy'
Current calculator changed to
cryspy
Set Minimizer¶
In [21]:
Copied!
project.analysis.current_minimizer = 'lmfit (leastsq)'
project.analysis.current_minimizer = 'lmfit (leastsq)'
Current minimizer changed to
lmfit (leastsq)
Plot Measured vs Calculated¶
In [22]:
Copied!
project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
In [23]:
Copied!
project.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
project.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
Perform Fit 1/5¶
Set parameters to be refined.
In [24]:
Copied!
model.cell.length_a.free = True
model.cell.length_c.free = True
expt.linked_phases['hs'].scale.free = True
expt.instrument.calib_twotheta_offset.free = True
model.cell.length_a.free = True
model.cell.length_c.free = True
expt.linked_phases['hs'].scale.free = True
expt.instrument.calib_twotheta_offset.free = True
Show free parameters after selection.
In [25]:
Copied!
project.analysis.show_free_params()
project.analysis.show_free_params()
Free parameters for both sample models (🧩 data blocks) and experiments (🔬 data blocks)
| datablock | category | entry | parameter | value | uncertainty | min | max | units | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | 6.90000 | -inf | inf | Å | ||
| 2 | hs | cell | length_c | 14.10000 | -inf | inf | Å | ||
| 3 | hrpt | linked_phases | hs | scale | 0.50000 | -inf | inf | ||
| 4 | hrpt | instrument | twotheta_offset | 0.00000 | -inf | inf | deg | 
Run Fitting¶
In [26]:
Copied!
project.analysis.fit()
project.analysis.fit()
Using experiment 🔬 'hrpt' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit (reduced χ²) change:
| iteration | χ² | improvement [%] | |
|---|---|---|---|
| 1 | 1 | 576.50 | |
| 2 | 8 | 122.02 | 78.8% ↓ | 
| 3 | 13 | 115.19 | 5.6% ↓ | 
| 4 | 18 | 109.86 | 4.6% ↓ | 
| 5 | 23 | 106.68 | 2.9% ↓ | 
| 6 | 28 | 104.60 | 2.0% ↓ | 
| 7 | 33 | 102.87 | 1.7% ↓ | 
| 8 | 38 | 101.13 | 1.7% ↓ | 
| 9 | 43 | 99.20 | 1.9% ↓ | 
| 10 | 48 | 96.86 | 2.4% ↓ | 
| 11 | 53 | 93.93 | 3.0% ↓ | 
| 12 | 58 | 90.34 | 3.8% ↓ | 
| 13 | 63 | 86.20 | 4.6% ↓ | 
| 14 | 68 | 81.66 | 5.3% ↓ | 
| 15 | 73 | 76.78 | 6.0% ↓ | 
| 16 | 78 | 71.71 | 6.6% ↓ | 
| 17 | 83 | 66.82 | 6.8% ↓ | 
| 18 | 88 | 62.48 | 6.5% ↓ | 
| 19 | 93 | 58.99 | 5.6% ↓ | 
| 20 | 98 | 56.41 | 4.4% ↓ | 
| 21 | 103 | 54.64 | 3.1% ↓ | 
| 22 | 108 | 53.49 | 2.1% ↓ | 
| 23 | 113 | 52.76 | 1.4% ↓ | 
| 24 | 123 | 52.02 | 1.4% ↓ | 
| 25 | 304 | 51.57 | 
🏆 Best goodness-of-fit (reduced χ²) is 51.57 at iteration 303
✅ Fitting complete.
Fit results
✅ Success: True
⏱️ Fitting time: 16.50 seconds
📏 Goodness-of-fit (reduced χ²): 51.57
📏 R-factor (Rf): 19.70%
📏 R-factor squared (Rf²): 30.20%
📏 Weighted R-factor (wR): 30.35%
📈 Fitted parameters:
| datablock | category | entry | parameter | start | fitted | uncertainty | units | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | None | length_a | 6.9000 | 6.8623 | 0.0003 | Å | 0.55 % ↓ | 
| 2 | hs | cell | None | length_c | 14.1000 | 14.1365 | 0.0008 | Å | 0.26 % ↑ | 
| 3 | hrpt | linked_phases | hs | scale | 0.5000 | 0.2548 | 0.0030 | 49.04 % ↓ | |
| 4 | hrpt | instrument | None | twotheta_offset | 0.0000 | 0.1271 | 0.0051 | deg | N/A | 
Plot Measured vs Calculated¶
In [27]:
Copied!
project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
In [28]:
Copied!
project.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
project.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
Perform Fit 2/5¶
Set more parameters to be refined.
In [29]:
Copied!
expt.peak.broad_gauss_u.free = True
expt.peak.broad_gauss_v.free = True
expt.peak.broad_gauss_w.free = True
expt.peak.broad_lorentz_x.free = True
for point in expt.background:
    point.y.free = True
expt.peak.broad_gauss_u.free = True
expt.peak.broad_gauss_v.free = True
expt.peak.broad_gauss_w.free = True
expt.peak.broad_lorentz_x.free = True
for point in expt.background:
    point.y.free = True
Show free parameters after selection.
In [30]:
Copied!
project.analysis.show_free_params()
project.analysis.show_free_params()
Free parameters for both sample models (🧩 data blocks) and experiments (🔬 data blocks)
| datablock | category | entry | parameter | value | uncertainty | min | max | units | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | 6.86229 | 0.00029 | -inf | inf | Å | |
| 2 | hs | cell | length_c | 14.13651 | 0.00084 | -inf | inf | Å | |
| 3 | hrpt | peak | broad_gauss_u | 0.10000 | -inf | inf | deg² | ||
| 4 | hrpt | peak | broad_gauss_v | -0.20000 | -inf | inf | deg² | ||
| 5 | hrpt | peak | broad_gauss_w | 0.20000 | -inf | inf | deg² | ||
| 6 | hrpt | peak | broad_lorentz_x | 0.00000 | -inf | inf | deg | ||
| 7 | hrpt | linked_phases | hs | scale | 0.25480 | 0.00305 | -inf | inf | |
| 8 | hrpt | instrument | twotheta_offset | 0.12712 | 0.00515 | -inf | inf | deg | |
| 9 | hrpt | background | 4.4196 | y | 500.00000 | -inf | inf | ||
| 10 | hrpt | background | 6.6207 | y | 500.00000 | -inf | inf | ||
| 11 | hrpt | background | 10.4918 | y | 500.00000 | -inf | inf | ||
| 12 | hrpt | background | 15.4634 | y | 500.00000 | -inf | inf | ||
| 13 | hrpt | background | 45.6041 | y | 500.00000 | -inf | inf | ||
| 14 | hrpt | background | 74.6844 | y | 500.00000 | -inf | inf | ||
| 15 | hrpt | background | 103.4187 | y | 500.00000 | -inf | inf | ||
| 16 | hrpt | background | 121.6311 | y | 500.00000 | -inf | inf | ||
| 17 | hrpt | background | 159.4116 | y | 500.00000 | -inf | inf | 
Run Fitting¶
In [31]:
Copied!
project.analysis.fit()
project.analysis.fit()
Using experiment 🔬 'hrpt' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit (reduced χ²) change:
| iteration | χ² | improvement [%] | |
|---|---|---|---|
| 1 | 1 | 51.78 | |
| 2 | 21 | 13.07 | 74.8% ↓ | 
| 3 | 40 | 12.66 | 3.2% ↓ | 
| 4 | 58 | 12.49 | 1.3% ↓ | 
| 5 | 340 | 12.41 | 
🏆 Best goodness-of-fit (reduced χ²) is 12.41 at iteration 339
✅ Fitting complete.
Fit results
✅ Success: True
⏱️ Fitting time: 13.50 seconds
📏 Goodness-of-fit (reduced χ²): 12.41
📏 R-factor (Rf): 9.62%
📏 R-factor squared (Rf²): 12.83%
📏 Weighted R-factor (wR): 12.21%
📈 Fitted parameters:
| datablock | category | entry | parameter | start | fitted | uncertainty | units | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | None | length_a | 6.8623 | 6.8628 | 0.0003 | Å | 0.01 % ↑ | 
| 2 | hs | cell | None | length_c | 14.1365 | 14.1389 | 0.0009 | Å | 0.02 % ↑ | 
| 3 | hrpt | peak | None | broad_gauss_u | 0.1000 | 0.1042 | 0.0451 | deg² | 4.18 % ↑ | 
| 4 | hrpt | peak | None | broad_gauss_v | -0.2000 | -0.4977 | 0.0619 | deg² | 148.83 % ↑ | 
| 5 | hrpt | peak | None | broad_gauss_w | 0.2000 | 0.3592 | 0.0227 | deg² | 79.60 % ↑ | 
| 6 | hrpt | peak | None | broad_lorentz_x | 0.0000 | 0.5042 | 0.0075 | deg | N/A | 
| 7 | hrpt | linked_phases | hs | scale | 0.2548 | 0.4570 | 0.0032 | 79.37 % ↑ | |
| 8 | hrpt | instrument | None | twotheta_offset | 0.1271 | 0.1289 | 0.0038 | deg | 1.39 % ↑ | 
| 9 | hrpt | background | 4.4196 | y | 500.0000 | 645.4830 | 23.7674 | 29.10 % ↑ | |
| 10 | hrpt | background | 6.6207 | y | 500.0000 | 520.8595 | 13.6088 | 4.17 % ↑ | |
| 11 | hrpt | background | 10.4918 | y | 500.0000 | 455.0036 | 10.4220 | 9.00 % ↓ | |
| 12 | hrpt | background | 15.4634 | y | 500.0000 | 428.8639 | 5.4019 | 14.23 % ↓ | |
| 13 | hrpt | background | 45.6041 | y | 500.0000 | 453.5008 | 5.2135 | 9.30 % ↓ | |
| 14 | hrpt | background | 74.6844 | y | 500.0000 | 446.7592 | 5.4686 | 10.65 % ↓ | |
| 15 | hrpt | background | 103.4187 | y | 500.0000 | 411.5620 | 5.4490 | 17.69 % ↓ | |
| 16 | hrpt | background | 121.6311 | y | 500.0000 | 364.3828 | 5.6634 | 27.12 % ↓ | |
| 17 | hrpt | background | 159.4116 | y | 500.0000 | 469.2837 | 5.4987 | 6.14 % ↓ | 
Plot Measured vs Calculated¶
In [32]:
Copied!
project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
In [33]:
Copied!
project.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
project.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
Perform Fit 3/5¶
Set more parameters to be refined.
In [34]:
Copied!
model.atom_sites['O'].fract_x.free = True
model.atom_sites['O'].fract_z.free = True
model.atom_sites['Cl'].fract_z.free = True
model.atom_sites['H'].fract_x.free = True
model.atom_sites['H'].fract_z.free = True
model.atom_sites['O'].fract_x.free = True
model.atom_sites['O'].fract_z.free = True
model.atom_sites['Cl'].fract_z.free = True
model.atom_sites['H'].fract_x.free = True
model.atom_sites['H'].fract_z.free = True
Show free parameters after selection.
In [35]:
Copied!
project.analysis.show_free_params()
project.analysis.show_free_params()
Free parameters for both sample models (🧩 data blocks) and experiments (🔬 data blocks)
| datablock | category | entry | parameter | value | uncertainty | min | max | units | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | 6.86276 | 0.00033 | -inf | inf | Å | |
| 2 | hs | cell | length_c | 14.13889 | 0.00088 | -inf | inf | Å | |
| 3 | hs | atom_site | O | fract_x | 0.21000 | -inf | inf | ||
| 4 | hs | atom_site | O | fract_z | 0.06000 | -inf | inf | ||
| 5 | hs | atom_site | Cl | fract_z | 0.19700 | -inf | inf | ||
| 6 | hs | atom_site | H | fract_x | 0.13000 | -inf | inf | ||
| 7 | hs | atom_site | H | fract_z | 0.08000 | -inf | inf | ||
| 8 | hrpt | peak | broad_gauss_u | 0.10418 | 0.04510 | -inf | inf | deg² | |
| 9 | hrpt | peak | broad_gauss_v | -0.49766 | 0.06188 | -inf | inf | deg² | |
| 10 | hrpt | peak | broad_gauss_w | 0.35919 | 0.02266 | -inf | inf | deg² | |
| 11 | hrpt | peak | broad_lorentz_x | 0.50419 | 0.00753 | -inf | inf | deg | |
| 12 | hrpt | linked_phases | hs | scale | 0.45704 | 0.00318 | -inf | inf | |
| 13 | hrpt | instrument | twotheta_offset | 0.12889 | 0.00379 | -inf | inf | deg | |
| 14 | hrpt | background | 4.4196 | y | 645.48303 | 23.76745 | -inf | inf | |
| 15 | hrpt | background | 6.6207 | y | 520.85952 | 13.60879 | -inf | inf | |
| 16 | hrpt | background | 10.4918 | y | 455.00355 | 10.42197 | -inf | inf | |
| 17 | hrpt | background | 15.4634 | y | 428.86390 | 5.40186 | -inf | inf | |
| 18 | hrpt | background | 45.6041 | y | 453.50084 | 5.21353 | -inf | inf | |
| 19 | hrpt | background | 74.6844 | y | 446.75916 | 5.46856 | -inf | inf | |
| 20 | hrpt | background | 103.4187 | y | 411.56202 | 5.44902 | -inf | inf | |
| 21 | hrpt | background | 121.6311 | y | 364.38279 | 5.66340 | -inf | inf | |
| 22 | hrpt | background | 159.4116 | y | 469.28374 | 5.49874 | -inf | inf | 
Run Fitting¶
In [36]:
Copied!
project.analysis.fit()
project.analysis.fit()
Using experiment 🔬 'hrpt' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit (reduced χ²) change:
| iteration | χ² | improvement [%] | |
|---|---|---|---|
| 1 | 1 | 12.43 | |
| 2 | 26 | 5.11 | 58.9% ↓ | 
| 3 | 49 | 4.40 | 13.9% ↓ | 
| 4 | 72 | 4.35 | 1.3% ↓ | 
| 5 | 188 | 4.34 | 
🏆 Best goodness-of-fit (reduced χ²) is 4.34 at iteration 187
✅ Fitting complete.
Fit results
✅ Success: True
⏱️ Fitting time: 7.80 seconds
📏 Goodness-of-fit (reduced χ²): 4.34
📏 R-factor (Rf): 6.01%
📏 R-factor squared (Rf²): 7.74%
📏 Weighted R-factor (wR): 7.51%
📈 Fitted parameters:
| datablock | category | entry | parameter | start | fitted | uncertainty | units | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | None | length_a | 6.8628 | 6.8621 | 0.0002 | Å | 0.01 % ↓ | 
| 2 | hs | cell | None | length_c | 14.1389 | 14.1356 | 0.0005 | Å | 0.02 % ↓ | 
| 3 | hs | atom_site | O | fract_x | 0.2100 | 0.2059 | 0.0002 | 1.96 % ↓ | |
| 4 | hs | atom_site | O | fract_z | 0.0600 | 0.0625 | 0.0002 | 4.14 % ↑ | |
| 5 | hs | atom_site | Cl | fract_z | 0.1970 | 0.1977 | 0.0002 | 0.36 % ↑ | |
| 6 | hs | atom_site | H | fract_x | 0.1300 | 0.1330 | 0.0002 | 2.33 % ↑ | |
| 7 | hs | atom_site | H | fract_z | 0.0800 | 0.0877 | 0.0001 | 9.59 % ↑ | |
| 8 | hrpt | peak | None | broad_gauss_u | 0.1042 | 0.1789 | 0.0119 | deg² | 71.71 % ↑ | 
| 9 | hrpt | peak | None | broad_gauss_v | -0.4977 | -0.3964 | 0.0222 | deg² | 20.35 % ↓ | 
| 10 | hrpt | peak | None | broad_gauss_w | 0.3592 | 0.3272 | 0.0100 | deg² | 8.92 % ↓ | 
| 11 | hrpt | peak | None | broad_lorentz_x | 0.5042 | 0.3601 | 0.0089 | deg | 28.57 % ↓ | 
| 12 | hrpt | linked_phases | hs | scale | 0.4570 | 0.4176 | 0.0021 | 8.63 % ↓ | |
| 13 | hrpt | instrument | None | twotheta_offset | 0.1289 | 0.1167 | 0.0021 | deg | 9.43 % ↓ | 
| 14 | hrpt | background | 4.4196 | y | 645.4830 | 647.4024 | 14.0610 | 0.30 % ↑ | |
| 15 | hrpt | background | 6.6207 | y | 520.8595 | 523.4725 | 8.0510 | 0.50 % ↑ | |
| 16 | hrpt | background | 10.4918 | y | 455.0036 | 453.7545 | 6.1678 | 0.27 % ↓ | |
| 17 | hrpt | background | 15.4634 | y | 428.8639 | 437.9479 | 3.2221 | 2.12 % ↑ | |
| 18 | hrpt | background | 45.6041 | y | 453.5008 | 477.4863 | 3.2261 | 5.29 % ↑ | |
| 19 | hrpt | background | 74.6844 | y | 446.7592 | 485.0177 | 3.4007 | 8.56 % ↑ | |
| 20 | hrpt | background | 103.4187 | y | 411.5620 | 452.4338 | 3.2894 | 9.93 % ↑ | |
| 21 | hrpt | background | 121.6311 | y | 364.3828 | 435.3732 | 3.5007 | 19.48 % ↑ | |
| 22 | hrpt | background | 159.4116 | y | 469.2837 | 427.3883 | 3.6274 | 8.93 % ↓ | 
Plot Measured vs Calculated¶
In [37]:
Copied!
project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
In [38]:
Copied!
project.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
project.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
Perform Fit 4/5¶
Set more parameters to be refined.
In [39]:
Copied!
model.atom_sites['Zn'].b_iso.free = True
model.atom_sites['Cu'].b_iso.free = True
model.atom_sites['O'].b_iso.free = True
model.atom_sites['Cl'].b_iso.free = True
model.atom_sites['H'].b_iso.free = True
model.atom_sites['Zn'].b_iso.free = True
model.atom_sites['Cu'].b_iso.free = True
model.atom_sites['O'].b_iso.free = True
model.atom_sites['Cl'].b_iso.free = True
model.atom_sites['H'].b_iso.free = True
Show free parameters after selection.
In [40]:
Copied!
project.analysis.show_free_params()
project.analysis.show_free_params()
Free parameters for both sample models (🧩 data blocks) and experiments (🔬 data blocks)
| datablock | category | entry | parameter | value | uncertainty | min | max | units | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | 6.86205 | 0.00020 | -inf | inf | Å | |
| 2 | hs | cell | length_c | 14.13560 | 0.00049 | -inf | inf | Å | |
| 3 | hs | atom_site | Zn | b_iso | 0.50000 | -inf | inf | Ų | |
| 4 | hs | atom_site | Cu | b_iso | 0.50000 | -inf | inf | Ų | |
| 5 | hs | atom_site | O | fract_x | 0.20589 | 0.00022 | -inf | inf | |
| 6 | hs | atom_site | O | fract_z | 0.06248 | 0.00016 | -inf | inf | |
| 7 | hs | atom_site | O | b_iso | 0.50000 | -inf | inf | Ų | |
| 8 | hs | atom_site | Cl | fract_z | 0.19771 | 0.00016 | -inf | inf | |
| 9 | hs | atom_site | Cl | b_iso | 0.50000 | -inf | inf | Ų | |
| 10 | hs | atom_site | H | fract_x | 0.13303 | 0.00017 | -inf | inf | |
| 11 | hs | atom_site | H | fract_z | 0.08767 | 0.00012 | -inf | inf | |
| 12 | hs | atom_site | H | b_iso | 0.50000 | -inf | inf | Ų | |
| 13 | hrpt | peak | broad_gauss_u | 0.17888 | 0.01187 | -inf | inf | deg² | |
| 14 | hrpt | peak | broad_gauss_v | -0.39638 | 0.02219 | -inf | inf | deg² | |
| 15 | hrpt | peak | broad_gauss_w | 0.32715 | 0.00999 | -inf | inf | deg² | |
| 16 | hrpt | peak | broad_lorentz_x | 0.36012 | 0.00888 | -inf | inf | deg | |
| 17 | hrpt | linked_phases | hs | scale | 0.41758 | 0.00208 | -inf | inf | |
| 18 | hrpt | instrument | twotheta_offset | 0.11674 | 0.00215 | -inf | inf | deg | |
| 19 | hrpt | background | 4.4196 | y | 647.40242 | 14.06098 | -inf | inf | |
| 20 | hrpt | background | 6.6207 | y | 523.47254 | 8.05103 | -inf | inf | |
| 21 | hrpt | background | 10.4918 | y | 453.75449 | 6.16778 | -inf | inf | |
| 22 | hrpt | background | 15.4634 | y | 437.94787 | 3.22213 | -inf | inf | |
| 23 | hrpt | background | 45.6041 | y | 477.48627 | 3.22612 | -inf | inf | |
| 24 | hrpt | background | 74.6844 | y | 485.01766 | 3.40075 | -inf | inf | |
| 25 | hrpt | background | 103.4187 | y | 452.43379 | 3.28943 | -inf | inf | |
| 26 | hrpt | background | 121.6311 | y | 435.37321 | 3.50066 | -inf | inf | |
| 27 | hrpt | background | 159.4116 | y | 427.38825 | 3.62743 | -inf | inf | 
Run Fitting¶
In [41]:
Copied!
project.analysis.fit()
project.analysis.fit()
Using experiment 🔬 'hrpt' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit (reduced χ²) change:
| iteration | χ² | improvement [%] | |
|---|---|---|---|
| 1 | 1 | 4.35 | |
| 2 | 31 | 2.30 | 47.1% ↓ | 
| 3 | 59 | 2.11 | 8.3% ↓ | 
| 4 | 144 | 2.11 | 
🏆 Best goodness-of-fit (reduced χ²) is 2.11 at iteration 118
✅ Fitting complete.
Fit results
✅ Success: True
⏱️ Fitting time: 6.75 seconds
📏 Goodness-of-fit (reduced χ²): 2.11
📏 R-factor (Rf): 4.17%
📏 R-factor squared (Rf²): 5.05%
📏 Weighted R-factor (wR): 4.73%
📈 Fitted parameters:
| datablock | category | entry | parameter | start | fitted | uncertainty | units | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | None | length_a | 6.8621 | 6.8615 | 0.0001 | Å | 0.01 % ↓ | 
| 2 | hs | cell | None | length_c | 14.1356 | 14.1360 | 0.0004 | Å | 0.00 % ↑ | 
| 3 | hs | atom_site | Zn | b_iso | 0.5000 | 0.0855 | 0.0630 | Ų | 82.91 % ↓ | 
| 4 | hs | atom_site | Cu | b_iso | 0.5000 | 1.1937 | 0.0399 | Ų | 138.74 % ↑ | 
| 5 | hs | atom_site | O | fract_x | 0.2059 | 0.2060 | 0.0002 | 0.06 % ↑ | |
| 6 | hs | atom_site | O | fract_z | 0.0625 | 0.0609 | 0.0001 | 2.53 % ↓ | |
| 7 | hs | atom_site | O | b_iso | 0.5000 | 0.7001 | 0.0360 | Ų | 40.02 % ↑ | 
| 8 | hs | atom_site | Cl | fract_z | 0.1977 | 0.1968 | 0.0001 | 0.49 % ↓ | |
| 9 | hs | atom_site | Cl | b_iso | 0.5000 | 1.1129 | 0.0385 | Ų | 122.58 % ↑ | 
| 10 | hs | atom_site | H | fract_x | 0.1330 | 0.1322 | 0.0002 | 0.62 % ↓ | |
| 11 | hs | atom_site | H | fract_z | 0.0877 | 0.0900 | 0.0001 | 2.63 % ↑ | |
| 12 | hs | atom_site | H | b_iso | 0.5000 | 2.3404 | 0.0401 | Ų | 368.08 % ↑ | 
| 13 | hrpt | peak | None | broad_gauss_u | 0.1789 | 0.1579 | 0.0076 | deg² | 11.70 % ↓ | 
| 14 | hrpt | peak | None | broad_gauss_v | -0.3964 | -0.3571 | 0.0147 | deg² | 9.91 % ↓ | 
| 15 | hrpt | peak | None | broad_gauss_w | 0.3272 | 0.3498 | 0.0067 | deg² | 6.92 % ↑ | 
| 16 | hrpt | peak | None | broad_lorentz_x | 0.3601 | 0.2927 | 0.0065 | deg | 18.73 % ↓ | 
| 17 | hrpt | linked_phases | hs | scale | 0.4176 | 0.4918 | 0.0022 | 17.76 % ↑ | |
| 18 | hrpt | instrument | None | twotheta_offset | 0.1167 | 0.1137 | 0.0015 | deg | 2.62 % ↓ | 
| 19 | hrpt | background | 4.4196 | y | 647.4024 | 648.4125 | 9.7968 | 0.16 % ↑ | |
| 20 | hrpt | background | 6.6207 | y | 523.4725 | 523.7880 | 5.6095 | 0.06 % ↑ | |
| 21 | hrpt | background | 10.4918 | y | 453.7545 | 454.9375 | 4.2976 | 0.26 % ↑ | |
| 22 | hrpt | background | 15.4634 | y | 437.9479 | 435.9131 | 2.2512 | 0.46 % ↓ | |
| 23 | hrpt | background | 45.6041 | y | 477.4863 | 472.9718 | 2.2759 | 0.95 % ↓ | |
| 24 | hrpt | background | 74.6844 | y | 485.0177 | 486.6064 | 2.4356 | 0.33 % ↑ | |
| 25 | hrpt | background | 103.4187 | y | 452.4338 | 472.4095 | 2.3483 | 4.42 % ↑ | |
| 26 | hrpt | background | 121.6311 | y | 435.3732 | 496.7338 | 2.6211 | 14.09 % ↑ | |
| 27 | hrpt | background | 159.4116 | y | 427.3883 | 473.1457 | 2.9361 | 10.71 % ↑ | 
Plot Measured vs Calculated¶
In [42]:
Copied!
project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
In [43]:
Copied!
project.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
project.plot_meas_vs_calc(expt_name='hrpt', x_min=48, x_max=51, show_residual=True)
Summary¶
This final section shows how to review the results of the analysis.
Show Project Summary¶
In [44]:
Copied!
project.summary.show_report()
project.summary.show_report()
PROJECT INFO ━━━━━━━━━━━━
Title
Untitled Project
CRYSTALLOGRAPHIC DATA ━━━━━━━━━━━━━━━━━━━━━
Phase datablock
🧩 hs
Space group
R -3 m
Cell parameters
| Parameter | Value | |
|---|---|---|
| 1 | a | 6.86149 | 
| 2 | b | 6.86149 | 
| 3 | c | 14.13604 | 
| 4 | alpha | 90.00000 | 
| 5 | beta | 90.00000 | 
| 6 | gamma | 120.00000 | 
Atom sites
| label | type | x | y | z | occ | Biso | |
|---|---|---|---|---|---|---|---|
| 1 | Zn | Zn | 0.00000 | 0.00000 | 0.50000 | 1.00000 | 0.08546 | 
| 2 | Cu | Cu | 0.50000 | 0.00000 | 0.00000 | 1.00000 | 1.19372 | 
| 3 | O | O | 0.20601 | -0.20601 | 0.06090 | 1.00000 | 0.70009 | 
| 4 | Cl | Cl | 0.00000 | 0.00000 | 0.19675 | 1.00000 | 1.11288 | 
| 5 | H | 2H | 0.13220 | -0.13220 | 0.08998 | 1.00000 | 2.34039 | 
EXPERIMENTS ━━━━━━━━━━━
Experiment datablock
🔬 hrpt
Experiment type
SampleFormEnum.POWDER, RadiationProbeEnum.NEUTRON, BeamModeEnum.CONSTANT_WAVELENGTH
Wavelength
1.89000
2θ offset
0.11368
Profile type
PeakProfileTypeEnum.PSEUDO_VOIGT
Peak broadening (Gaussian)
| Parameter | Value | |
|---|---|---|
| 1 | U | 0.15795 | 
| 2 | V | -0.35708 | 
| 3 | W | 0.34978 | 
Peak broadening (Lorentzian)
| Parameter | Value | |
|---|---|---|
| 1 | X | 0.29266 | 
| 2 | Y | 0.00000 | 
FITTING ━━━━━━━
Calculation engine
cryspy
Minimization engine
lmfit (leastsq)
Fit quality
| metric | value | |
|---|---|---|
| 1 | Goodness-of-fit (reduced χ²) | 2.11 |