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 StructureFactory
from easydiffraction import download_data
from easydiffraction import ExperimentFactory
from easydiffraction import Project
from easydiffraction import StructureFactory
from easydiffraction import download_data
In [3]:
Copied!
structure = StructureFactory.from_scratch(name='hs')
structure = StructureFactory.from_scratch(name='hs')
Set Space Group¶
In [4]:
Copied!
structure.space_group.name_h_m = 'R -3 m'
structure.space_group.coord_system_code = 'h'
structure.space_group.name_h_m = 'R -3 m'
structure.space_group.coord_system_code = 'h'
Set Unit Cell¶
In [5]:
Copied!
structure.cell.length_a = 6.85
structure.cell.length_c = 14.1
structure.cell.length_a = 6.85
structure.cell.length_c = 14.1
Set Atom Sites¶
In [6]:
Copied!
structure.atom_sites.create(
id='Zn',
type_symbol='Zn',
fract_x=0,
fract_y=0,
fract_z=0.5,
adp_iso=0.5,
)
structure.atom_sites.create(
id='Cu',
type_symbol='Cu',
fract_x=0.5,
fract_y=0,
fract_z=0,
adp_iso=0.5,
)
structure.atom_sites.create(
id='O',
type_symbol='O',
fract_x=0.21,
fract_y=-0.21,
fract_z=0.06,
adp_iso=0.5,
)
structure.atom_sites.create(
id='Cl',
type_symbol='Cl',
fract_x=0,
fract_y=0,
fract_z=0.197,
adp_iso=0.5,
)
structure.atom_sites.create(
id='H',
type_symbol='2H',
fract_x=0.13,
fract_y=-0.13,
fract_z=0.08,
adp_iso=0.5,
)
structure.atom_sites.create(
id='Zn',
type_symbol='Zn',
fract_x=0,
fract_y=0,
fract_z=0.5,
adp_iso=0.5,
)
structure.atom_sites.create(
id='Cu',
type_symbol='Cu',
fract_x=0.5,
fract_y=0,
fract_z=0,
adp_iso=0.5,
)
structure.atom_sites.create(
id='O',
type_symbol='O',
fract_x=0.21,
fract_y=-0.21,
fract_z=0.06,
adp_iso=0.5,
)
structure.atom_sites.create(
id='Cl',
type_symbol='Cl',
fract_x=0,
fract_y=0,
fract_z=0.197,
adp_iso=0.5,
)
structure.atom_sites.create(
id='H',
type_symbol='2H',
fract_x=0.13,
fract_y=-0.13,
fract_z=0.08,
adp_iso=0.5,
)
In [7]:
Copied!
data_path = download_data('meas-hs-hrpt', destination='data')
data_path = download_data('meas-hs-hrpt', destination='data')
Getting data...
Data 'meas-hs-hrpt': HS, HRPT (PSI)
✅ Data 'meas-hs-hrpt' downloaded to '../../../data/meas-hs-hrpt.xye'
Create Experiment¶
In [8]:
Copied!
expt = ExperimentFactory.from_data_path(name='hrpt', data_path=data_path)
expt = ExperimentFactory.from_data_path(name='hrpt', data_path=data_path)
Set Instrument¶
In [9]:
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 [10]:
Copied!
expt.peak.show_supported()
expt.peak.show_supported()
Peak types
| Type | Description | ||
|---|---|---|---|
| 1 | * | pseudo-voigt | CWL pseudo-Voigt profile |
| 2 | pseudo-voigt + berar-baldinozzi asymmetry | CWL pseudo-Voigt profile with Berar-Baldinozzi asymmetry correction. |
In [11]:
Copied!
expt.peak.type = 'pseudo-voigt + berar-baldinozzi asymmetry'
expt.peak.type = 'pseudo-voigt + berar-baldinozzi asymmetry'
⚠️ Switching peak profile type adds these settings with defaults: • asym_beba_a0=0.0 • asym_beba_a1=0.0 • asym_beba_b0=0.0 • asym_beba_b1=0.0
Peak profile type for experiment 'hrpt' changed to
pseudo-voigt + berar-baldinozzi asymmetry
In [12]:
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_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_y = 0
In [13]:
Copied!
expt.peak.cutoff_fwhm = 8
expt.peak.cutoff_fwhm = 8
Set Background¶
In [14]:
Copied!
expt.background.auto_estimate()
expt.background.auto_estimate()
Set Linked Structures¶
In [15]:
Copied!
expt.linked_structures.create(structure_id='hs', scale=0.5)
expt.linked_structures.create(structure_id='hs', scale=0.5)
In [16]:
Copied!
project = Project(name='hs_hrpt')
project = Project(name='hs_hrpt')
Add Structure¶
In [17]:
Copied!
project.structures.add(structure)
project.structures.add(structure)
Add Experiment¶
In [18]:
Copied!
project.experiments.add(expt)
project.experiments.add(expt)
In [19]:
Copied!
project.display.structure(struct_name='hs')
project.display.structure(struct_name='hs')
Structure 🧩 'hs' (Atom view type: 'covalent')
Loading plot…
drag = rotate
wheel = zoom
right-drag = pan
wheel = zoom
right-drag = pan
Display Pattern¶
In [20]:
Copied!
project.display.pattern(expt_name='hrpt')
project.display.pattern(expt_name='hrpt')
Loading plot…
In [21]:
Copied!
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
Loading plot…
Perform Fit 1/4¶
Set parameters to be refined.
In [22]:
Copied!
structure.cell.length_a.free = True
structure.cell.length_c.free = True
expt.linked_structures['hs'].scale.free = True
expt.instrument.calib_twotheta_offset.free = True
structure.cell.length_a.free = True
structure.cell.length_c.free = True
expt.linked_structures['hs'].scale.free = True
expt.instrument.calib_twotheta_offset.free = True
Show free parameters after selection.
In [23]:
Copied!
project.display.parameters.free()
project.display.parameters.free()
Free parameters for both structures (🧩 data blocks) and experiments (🔬 data blocks)
| datablock | category | entry | parameter | value | uncertainty | min | max | units | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | 6.85000 | -inf | inf | Å | ||
| 2 | hs | cell | length_c | 14.10000 | -inf | inf | Å | ||
| 3 | hrpt | linked_structure | hs | scale | 0.50000 | -inf | inf | ||
| 4 | hrpt | instrument | twotheta_offset | 0.00000 | -inf | inf | deg |
Run Fitting¶
In [24]:
Copied!
project.analysis.fit()
project.analysis.fit()
Standard fitting
📋 Using experiment 🔬 'hrpt' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit progress:
| iteration | time (s) | χ² | change / status | |
|---|---|---|---|---|
| 1 | 1 | 0.05 | 210.23 | |
| 2 | 8 | 0.41 | 60.12 | 71.4% ↓ |
| 3 | 13 | 0.88 | 55.45 | 7.8% ↓ |
| 4 | 18 | 1.12 | 51.96 | 6.3% ↓ |
| 5 | 23 | 1.37 | 49.78 | 4.2% ↓ |
| 6 | 28 | 1.62 | 48.53 | 2.5% ↓ |
| 7 | 33 | 2.10 | 47.85 | 1.4% ↓ |
| 8 | 43 | 2.61 | 47.31 | 1.1% ↓ |
| 9 | 110 | 6.71 | 47.11 |
🏆 Best goodness-of-fit (reduced χ²) is 47.11 at iteration 80
✅ Fitting complete.
In [25]:
Copied!
project.display.fit.results()
project.display.fit.results()
⚙️ Settings used:
| Name | Value | Description | |
|---|---|---|---|
| 1 | max_iterations | 1000 | Maximum solver iterations. |
📋 Least-squares fit results:
| Metric | Value | |
|---|---|---|
| 1 | 🧪 Minimizer | lmfit (leastsq) |
| 2 | ✅ Overall status | success |
| 3 | ⏱️ Fitting time (seconds) | 6.71 |
| 4 | 🔁 Iterations | 107 |
| 5 | 📏 Goodness-of-fit (reduced χ²) | 47.11 |
| 6 | 📏 R-factor (Rf, %) | 17.69 |
| 7 | 📏 R-factor squared (Rf², %) | 30.23 |
| 8 | 📏 Weighted R-factor (wR, %) | 31.10 |
📈 Refined parameters:
| datablock | category | entry | parameter | units | start | value | s.u. | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | Å | 6.8500 | 6.8622 | 0.0003 | 0.18 % ↑ | |
| 2 | hs | cell | length_c | Å | 14.1000 | 14.1363 | 0.0008 | 0.26 % ↑ | |
| 3 | hrpt | linked_structure | hs | scale | 0.5000 | 0.2442 | 0.0029 | 51.16 % ↓ | |
| 4 | hrpt | instrument | twotheta_offset | deg | 0.0000 | 0.1258 | 0.0051 | N/A |
• start = parameter value before refinement
• value = refined value from least-squares minimization
• s.u. = standard uncertainty (one sigma), from the covariance matrix
• change = relative change from start, in %; ↑ = increase, ↓ = decrease
• value = refined value from least-squares minimization
• s.u. = standard uncertainty (one sigma), from the covariance matrix
• change = relative change from start, in %; ↑ = increase, ↓ = decrease
Display Pattern¶
In [26]:
Copied!
project.display.pattern(expt_name='hrpt')
project.display.pattern(expt_name='hrpt')
Loading plot…
In [27]:
Copied!
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
Loading plot…
Perform Fit 2/4¶
Set more parameters to be refined.
In [28]:
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_y.free = True
for point in expt.background:
point.intensity.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_y.free = True
for point in expt.background:
point.intensity.free = True
Show free parameters after selection.
In [29]:
Copied!
project.display.parameters.free()
project.display.parameters.free()
Free parameters for both structures (🧩 data blocks) and experiments (🔬 data blocks)
| datablock | category | entry | parameter | value | uncertainty | min | max | units | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | 6.86216 | 0.00029 | -inf | inf | Å | |
| 2 | hs | cell | length_c | 14.13634 | 0.00084 | -inf | inf | Å | |
| 3 | hrpt | linked_structure | hs | scale | 0.24422 | 0.00291 | -inf | inf | |
| 4 | hrpt | peak | broad_gauss_u | 0.10000 | -inf | inf | deg² | ||
| 5 | hrpt | peak | broad_gauss_v | -0.20000 | -inf | inf | deg² | ||
| 6 | hrpt | peak | broad_gauss_w | 0.20000 | -inf | inf | deg² | ||
| 7 | hrpt | peak | broad_lorentz_y | 0.00000 | -inf | inf | deg | ||
| 8 | hrpt | instrument | twotheta_offset | 0.12575 | 0.00513 | -inf | inf | deg | |
| 9 | hrpt | background | 1 | intensity | 645.00000 | -inf | inf | ||
| 10 | hrpt | background | 2 | intensity | 460.00000 | -inf | inf | ||
| 11 | hrpt | background | 3 | intensity | 451.00000 | -inf | inf | ||
| 12 | hrpt | background | 4 | intensity | 616.75182 | -inf | inf | ||
| 13 | hrpt | background | 5 | intensity | 451.00000 | -inf | inf | ||
| 14 | hrpt | background | 6 | intensity | 522.48916 | -inf | inf | ||
| 15 | hrpt | background | 7 | intensity | 497.01720 | -inf | inf | ||
| 16 | hrpt | background | 8 | intensity | 613.15327 | -inf | inf | ||
| 17 | hrpt | background | 9 | intensity | 657.13723 | -inf | inf | ||
| 18 | hrpt | background | 10 | intensity | 573.00000 | -inf | inf | ||
| 19 | hrpt | background | 11 | intensity | 514.00000 | -inf | inf | ||
| 20 | hrpt | background | 12 | intensity | 538.17307 | -inf | inf |
Run Fitting¶
In [30]:
Copied!
project.analysis.fit()
project.analysis.fit()
Standard fitting
📋 Using experiment 🔬 'hrpt' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit progress:
| iteration | time (s) | χ² | change / status | |
|---|---|---|---|---|
| 1 | 1 | 0.05 | 47.35 | |
| 2 | 24 | 1.45 | 16.05 | 66.1% ↓ |
| 3 | 46 | 2.85 | 14.94 | 6.9% ↓ |
| 4 | 67 | 4.23 | 13.01 | 12.9% ↓ |
| 5 | 145 | 9.23 | 12.92 | |
| 6 | 219 | 14.25 | 12.92 | |
| 7 | 224 | 14.61 | 12.92 |
🏆 Best goodness-of-fit (reduced χ²) is 12.92 at iteration 202
✅ Fitting complete.
In [31]:
Copied!
project.display.fit.results()
project.display.fit.results()
⚙️ Settings used:
| Name | Value | Description | |
|---|---|---|---|
| 1 | max_iterations | 1000 | Maximum solver iterations. |
📋 Least-squares fit results:
| Metric | Value | |
|---|---|---|
| 1 | 🧪 Minimizer | lmfit (leastsq) |
| 2 | ✅ Overall status | success |
| 3 | ⏱️ Fitting time (seconds) | 14.61 |
| 4 | 🔁 Iterations | 221 |
| 5 | 📏 Goodness-of-fit (reduced χ²) | 12.92 |
| 6 | 📏 R-factor (Rf, %) | 9.89 |
| 7 | 📏 R-factor squared (Rf², %) | 13.86 |
| 8 | 📏 Weighted R-factor (wR, %) | 13.80 |
📈 Refined parameters:
| datablock | category | entry | parameter | units | start | value | s.u. | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | Å | 6.8622 | 6.8626 | 0.0003 | 0.01 % ↑ | |
| 2 | hs | cell | length_c | Å | 14.1363 | 14.1392 | 0.0009 | 0.02 % ↑ | |
| 3 | hrpt | linked_structure | hs | scale | 0.2442 | 0.4162 | 0.0040 | 70.42 % ↑ | |
| 4 | hrpt | peak | broad_gauss_u | deg² | 0.1000 | 0.3458 | 0.0267 | 245.76 % ↑ | |
| 5 | hrpt | peak | broad_gauss_v | deg² | -0.2000 | -0.2479 | 0.0493 | 23.94 % ↑ | |
| 6 | hrpt | peak | broad_gauss_w | deg² | 0.2000 | 0.2127 | 0.0211 | 6.34 % ↑ | |
| 7 | hrpt | peak | broad_lorentz_y | deg | 0.0000 | 0.1574 | 0.0106 | N/A | |
| 8 | hrpt | instrument | twotheta_offset | deg | 0.1258 | 0.1272 | 0.0040 | 1.14 % ↑ | |
| 9 | hrpt | background | 1 | intensity | 645.0000 | 673.1075 | 20.0334 | 4.36 % ↑ | |
| 10 | hrpt | background | 2 | intensity | 460.0000 | 454.9251 | 6.2694 | 1.10 % ↓ | |
| 11 | hrpt | background | 3 | intensity | 451.0000 | 436.5423 | 6.1275 | 3.21 % ↓ | |
| 12 | hrpt | background | 4 | intensity | 616.7518 | 562.0722 | 13.6510 | 8.87 % ↓ | |
| 13 | hrpt | background | 5 | intensity | 451.0000 | 472.8034 | 7.6853 | 4.83 % ↑ | |
| 14 | hrpt | background | 6 | intensity | 522.4892 | 495.6934 | 5.4898 | 5.13 % ↓ | |
| 15 | hrpt | background | 7 | intensity | 497.0172 | 404.5708 | 5.2875 | 18.60 % ↓ | |
| 16 | hrpt | background | 8 | intensity | 613.1533 | 440.4542 | 10.4755 | 28.17 % ↓ | |
| 17 | hrpt | background | 9 | intensity | 657.1372 | 394.8575 | 11.4790 | 39.91 % ↓ | |
| 18 | hrpt | background | 10 | intensity | 573.0000 | 538.7733 | 8.9774 | 5.97 % ↓ | |
| 19 | hrpt | background | 11 | intensity | 514.0000 | 456.0360 | 8.4105 | 11.28 % ↓ | |
| 20 | hrpt | background | 12 | intensity | 538.1731 | 552.2311 | 14.7053 | 2.61 % ↑ |
• start = parameter value before refinement
• value = refined value from least-squares minimization
• s.u. = standard uncertainty (one sigma), from the covariance matrix
• change = relative change from start, in %; ↑ = increase, ↓ = decrease
• value = refined value from least-squares minimization
• s.u. = standard uncertainty (one sigma), from the covariance matrix
• change = relative change from start, in %; ↑ = increase, ↓ = decrease
Display Pattern¶
In [32]:
Copied!
project.display.pattern(expt_name='hrpt')
project.display.pattern(expt_name='hrpt')
Loading plot…
In [33]:
Copied!
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
Loading plot…
Perform Fit 3/4¶
Set more parameters to be refined.
In [34]:
Copied!
structure.atom_sites['O'].fract_x.free = True
structure.atom_sites['O'].fract_z.free = True
structure.atom_sites['Cl'].fract_z.free = True
structure.atom_sites['H'].fract_x.free = True
structure.atom_sites['H'].fract_z.free = True
structure.atom_sites['O'].fract_x.free = True
structure.atom_sites['O'].fract_z.free = True
structure.atom_sites['Cl'].fract_z.free = True
structure.atom_sites['H'].fract_x.free = True
structure.atom_sites['H'].fract_z.free = True
Show free parameters after selection.
In [35]:
Copied!
project.display.parameters.free()
project.display.parameters.free()
Free parameters for both structures (🧩 data blocks) and experiments (🔬 data blocks)
| datablock | category | entry | parameter | value | uncertainty | min | max | units | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | 6.86260 | 0.00035 | -inf | inf | Å | |
| 2 | hs | cell | length_c | 14.13920 | 0.00093 | -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 | linked_structure | hs | scale | 0.41619 | 0.00400 | -inf | inf | |
| 9 | hrpt | peak | broad_gauss_u | 0.34576 | 0.02672 | -inf | inf | deg² | |
| 10 | hrpt | peak | broad_gauss_v | -0.24788 | 0.04934 | -inf | inf | deg² | |
| 11 | hrpt | peak | broad_gauss_w | 0.21267 | 0.02110 | -inf | inf | deg² | |
| 12 | hrpt | peak | broad_lorentz_y | 0.15740 | 0.01058 | -inf | inf | deg | |
| 13 | hrpt | instrument | twotheta_offset | 0.12718 | 0.00396 | -inf | inf | deg | |
| 14 | hrpt | background | 1 | intensity | 673.10753 | 20.03337 | -inf | inf | |
| 15 | hrpt | background | 2 | intensity | 454.92508 | 6.26943 | -inf | inf | |
| 16 | hrpt | background | 3 | intensity | 436.54232 | 6.12751 | -inf | inf | |
| 17 | hrpt | background | 4 | intensity | 562.07220 | 13.65100 | -inf | inf | |
| 18 | hrpt | background | 5 | intensity | 472.80337 | 7.68533 | -inf | inf | |
| 19 | hrpt | background | 6 | intensity | 495.69338 | 5.48976 | -inf | inf | |
| 20 | hrpt | background | 7 | intensity | 404.57081 | 5.28747 | -inf | inf | |
| 21 | hrpt | background | 8 | intensity | 440.45421 | 10.47549 | -inf | inf | |
| 22 | hrpt | background | 9 | intensity | 394.85751 | 11.47903 | -inf | inf | |
| 23 | hrpt | background | 10 | intensity | 538.77335 | 8.97740 | -inf | inf | |
| 24 | hrpt | background | 11 | intensity | 456.03599 | 8.41055 | -inf | inf | |
| 25 | hrpt | background | 12 | intensity | 552.23109 | 14.70527 | -inf | inf |
Run Fitting¶
In [36]:
Copied!
project.analysis.fit()
project.analysis.fit()
Standard fitting
📋 Using experiment 🔬 'hrpt' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit progress:
| iteration | time (s) | χ² | change / status | |
|---|---|---|---|---|
| 1 | 1 | 0.06 | 12.94 | |
| 2 | 29 | 1.82 | 5.20 | 59.8% ↓ |
| 3 | 55 | 3.40 | 4.95 | 4.7% ↓ |
| 4 | 131 | 8.41 | 4.95 | |
| 5 | 211 | 13.43 | 4.95 | |
| 6 | 246 | 15.93 | 4.95 |
🏆 Best goodness-of-fit (reduced χ²) is 4.95 at iteration 178
✅ Fitting complete.
In [37]:
Copied!
project.display.fit.results()
project.display.fit.results()
⚙️ Settings used:
| Name | Value | Description | |
|---|---|---|---|
| 1 | max_iterations | 1000 | Maximum solver iterations. |
📋 Least-squares fit results:
| Metric | Value | |
|---|---|---|
| 1 | 🧪 Minimizer | lmfit (leastsq) |
| 2 | ✅ Overall status | success |
| 3 | ⏱️ Fitting time (seconds) | 15.93 |
| 4 | 🔁 Iterations | 243 |
| 5 | 📏 Goodness-of-fit (reduced χ²) | 4.95 |
| 6 | 📏 R-factor (Rf, %) | 6.43 |
| 7 | 📏 R-factor squared (Rf², %) | 8.76 |
| 8 | 📏 Weighted R-factor (wR, %) | 8.89 |
📈 Refined parameters:
| datablock | category | entry | parameter | units | start | value | s.u. | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | Å | 6.8626 | 6.8620 | 0.0002 | 0.01 % ↓ | |
| 2 | hs | cell | length_c | Å | 14.1392 | 14.1348 | 0.0005 | 0.03 % ↓ | |
| 3 | hs | atom_site | O | fract_x | 0.2100 | 0.2059 | 0.0002 | 1.94 % ↓ | |
| 4 | hs | atom_site | O | fract_z | 0.0600 | 0.0629 | 0.0002 | 4.75 % ↑ | |
| 5 | hs | atom_site | Cl | fract_z | 0.1970 | 0.1974 | 0.0002 | 0.20 % ↑ | |
| 6 | hs | atom_site | H | fract_x | 0.1300 | 0.1339 | 0.0002 | 3.01 % ↑ | |
| 7 | hs | atom_site | H | fract_z | 0.0800 | 0.0871 | 0.0001 | 8.89 % ↑ | |
| 8 | hrpt | linked_structure | hs | scale | 0.4162 | 0.3950 | 0.0023 | 5.09 % ↓ | |
| 9 | hrpt | peak | broad_gauss_u | deg² | 0.3458 | 0.3572 | 0.0140 | 3.30 % ↑ | |
| 10 | hrpt | peak | broad_gauss_v | deg² | -0.2479 | -0.3818 | 0.0268 | 54.01 % ↑ | |
| 11 | hrpt | peak | broad_gauss_w | deg² | 0.2127 | 0.2825 | 0.0125 | 32.86 % ↑ | |
| 12 | hrpt | peak | broad_lorentz_y | deg | 0.1574 | 0.1390 | 0.0062 | 11.68 % ↓ | |
| 13 | hrpt | instrument | twotheta_offset | deg | 0.1272 | 0.1148 | 0.0024 | 9.71 % ↓ | |
| 14 | hrpt | background | 1 | intensity | 673.1075 | 672.1313 | 12.3974 | 0.15 % ↓ | |
| 15 | hrpt | background | 2 | intensity | 454.9251 | 456.2819 | 3.8836 | 0.30 % ↑ | |
| 16 | hrpt | background | 3 | intensity | 436.5423 | 448.0780 | 3.7964 | 2.64 % ↑ | |
| 17 | hrpt | background | 4 | intensity | 562.0722 | 564.3133 | 8.4295 | 0.40 % ↑ | |
| 18 | hrpt | background | 5 | intensity | 472.8034 | 464.7443 | 4.7938 | 1.70 % ↓ | |
| 19 | hrpt | background | 6 | intensity | 495.6934 | 517.8974 | 3.3679 | 4.48 % ↑ | |
| 20 | hrpt | background | 7 | intensity | 404.5708 | 449.9013 | 3.2316 | 11.20 % ↑ | |
| 21 | hrpt | background | 8 | intensity | 440.4542 | 473.3742 | 6.7661 | 7.47 % ↑ | |
| 22 | hrpt | background | 9 | intensity | 394.8575 | 477.2343 | 8.0578 | 20.86 % ↑ | |
| 23 | hrpt | background | 10 | intensity | 538.7733 | 454.9376 | 6.0965 | 15.56 % ↓ | |
| 24 | hrpt | background | 11 | intensity | 456.0360 | 405.1224 | 5.6028 | 11.16 % ↓ | |
| 25 | hrpt | background | 12 | intensity | 552.2311 | 589.7398 | 9.2059 | 6.79 % ↑ |
• start = parameter value before refinement
• value = refined value from least-squares minimization
• s.u. = standard uncertainty (one sigma), from the covariance matrix
• change = relative change from start, in %; ↑ = increase, ↓ = decrease
• value = refined value from least-squares minimization
• s.u. = standard uncertainty (one sigma), from the covariance matrix
• change = relative change from start, in %; ↑ = increase, ↓ = decrease
Display Pattern¶
In [38]:
Copied!
project.display.pattern(expt_name='hrpt')
project.display.pattern(expt_name='hrpt')
Loading plot…
In [39]:
Copied!
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
Loading plot…
Perform Fit 4/4¶
Set more parameters to be refined.
In [40]:
Copied!
structure.atom_sites['Zn'].adp_iso.free = True
structure.atom_sites['Cu'].adp_iso.free = True
structure.atom_sites['O'].adp_iso.free = True
structure.atom_sites['Cl'].adp_iso.free = True
structure.atom_sites['H'].adp_iso.free = True
expt.peak.asym_beba_a0.free = True
expt.peak.asym_beba_b0.free = True
expt.peak.asym_beba_a1.free = True
expt.peak.asym_beba_b1.free = True
structure.atom_sites['Zn'].adp_iso.free = True
structure.atom_sites['Cu'].adp_iso.free = True
structure.atom_sites['O'].adp_iso.free = True
structure.atom_sites['Cl'].adp_iso.free = True
structure.atom_sites['H'].adp_iso.free = True
expt.peak.asym_beba_a0.free = True
expt.peak.asym_beba_b0.free = True
expt.peak.asym_beba_a1.free = True
expt.peak.asym_beba_b1.free = True
Show free parameters after selection.
In [41]:
Copied!
project.display.parameters.free()
project.display.parameters.free()
Free parameters for both structures (🧩 data blocks) and experiments (🔬 data blocks)
| datablock | category | entry | parameter | value | uncertainty | min | max | units | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | 6.86203 | 0.00022 | -inf | inf | Å | |
| 2 | hs | cell | length_c | 14.13484 | 0.00053 | -inf | inf | Å | |
| 3 | hs | atom_site | Zn | adp_iso | 0.50000 | -inf | inf | Ų | |
| 4 | hs | atom_site | Cu | adp_iso | 0.50000 | -inf | inf | Ų | |
| 5 | hs | atom_site | O | fract_x | 0.20592 | 0.00024 | -inf | inf | |
| 6 | hs | atom_site | O | fract_z | 0.06285 | 0.00018 | -inf | inf | |
| 7 | hs | atom_site | O | adp_iso | 0.50000 | -inf | inf | Ų | |
| 8 | hs | atom_site | Cl | fract_z | 0.19739 | 0.00018 | -inf | inf | |
| 9 | hs | atom_site | Cl | adp_iso | 0.50000 | -inf | inf | Ų | |
| 10 | hs | atom_site | H | fract_x | 0.13391 | 0.00018 | -inf | inf | |
| 11 | hs | atom_site | H | fract_z | 0.08711 | 0.00013 | -inf | inf | |
| 12 | hs | atom_site | H | adp_iso | 0.50000 | -inf | inf | Ų | |
| 13 | hrpt | linked_structure | hs | scale | 0.39501 | 0.00234 | -inf | inf | |
| 14 | hrpt | peak | asym_beba_a0 | 0.00000 | -inf | inf | |||
| 15 | hrpt | peak | asym_beba_b0 | 0.00000 | -inf | inf | |||
| 16 | hrpt | peak | asym_beba_a1 | 0.00000 | -inf | inf | |||
| 17 | hrpt | peak | asym_beba_b1 | 0.00000 | -inf | inf | |||
| 18 | hrpt | peak | broad_gauss_u | 0.35717 | 0.01404 | -inf | inf | deg² | |
| 19 | hrpt | peak | broad_gauss_v | -0.38176 | 0.02676 | -inf | inf | deg² | |
| 20 | hrpt | peak | broad_gauss_w | 0.28255 | 0.01248 | -inf | inf | deg² | |
| 21 | hrpt | peak | broad_lorentz_y | 0.13901 | 0.00615 | -inf | inf | deg | |
| 22 | hrpt | instrument | twotheta_offset | 0.11483 | 0.00237 | -inf | inf | deg | |
| 23 | hrpt | background | 1 | intensity | 672.13128 | 12.39736 | -inf | inf | |
| 24 | hrpt | background | 2 | intensity | 456.28194 | 3.88358 | -inf | inf | |
| 25 | hrpt | background | 3 | intensity | 448.07805 | 3.79639 | -inf | inf | |
| 26 | hrpt | background | 4 | intensity | 564.31327 | 8.42947 | -inf | inf | |
| 27 | hrpt | background | 5 | intensity | 464.74432 | 4.79375 | -inf | inf | |
| 28 | hrpt | background | 6 | intensity | 517.89737 | 3.36789 | -inf | inf | |
| 29 | hrpt | background | 7 | intensity | 449.90125 | 3.23156 | -inf | inf | |
| 30 | hrpt | background | 8 | intensity | 473.37425 | 6.76608 | -inf | inf | |
| 31 | hrpt | background | 9 | intensity | 477.23431 | 8.05784 | -inf | inf | |
| 32 | hrpt | background | 10 | intensity | 454.93762 | 6.09645 | -inf | inf | |
| 33 | hrpt | background | 11 | intensity | 405.12239 | 5.60281 | -inf | inf | |
| 34 | hrpt | background | 12 | intensity | 589.73981 | 9.20593 | -inf | inf |
Run Fitting¶
In [42]:
Copied!
project.analysis.fit()
project.analysis.fit()
Standard fitting
📋 Using experiment 🔬 'hrpt' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit progress:
| iteration | time (s) | χ² | change / status | |
|---|---|---|---|---|
| 1 | 1 | 0.06 | 4.96 | |
| 2 | 38 | 2.71 | 2.15 | 56.6% ↓ |
| 3 | 73 | 4.92 | 1.95 | 9.1% ↓ |
| 4 | 150 | 10.22 | 1.95 | |
| 5 | 227 | 15.25 | 1.95 | |
| 6 | 304 | 20.26 | 1.95 | |
| 7 | 380 | 25.57 | 1.95 | |
| 8 | 395 | 26.93 | 1.95 |
🏆 Best goodness-of-fit (reduced χ²) is 1.95 at iteration 373
✅ Fitting complete.
In [43]:
Copied!
project.display.fit.results()
project.display.fit.results()
⚙️ Settings used:
| Name | Value | Description | |
|---|---|---|---|
| 1 | max_iterations | 1000 | Maximum solver iterations. |
📋 Least-squares fit results:
| Metric | Value | |
|---|---|---|
| 1 | 🧪 Minimizer | lmfit (leastsq) |
| 2 | ✅ Overall status | success |
| 3 | ⏱️ Fitting time (seconds) | 26.93 |
| 4 | 🔁 Iterations | 392 |
| 5 | 📏 Goodness-of-fit (reduced χ²) | 1.95 |
| 6 | 📏 R-factor (Rf, %) | 3.99 |
| 7 | 📏 R-factor squared (Rf², %) | 4.64 |
| 8 | 📏 Weighted R-factor (wR, %) | 4.14 |
📈 Refined parameters:
| datablock | category | entry | parameter | units | start | value | s.u. | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | hs | cell | length_a | Å | 6.8620 | 6.8640 | 0.0004 | 0.03 % ↑ | |
| 2 | hs | cell | length_c | Å | 14.1348 | 14.1418 | 0.0010 | 0.05 % ↑ | |
| 3 | hs | atom_site | Zn | adp_iso | Ų | 0.5000 | 0.1618 | 0.0609 | 67.65 % ↓ |
| 4 | hs | atom_site | Cu | adp_iso | Ų | 0.5000 | 1.4873 | 0.0380 | 197.46 % ↑ |
| 5 | hs | atom_site | O | fract_x | 0.2059 | 0.2063 | 0.0002 | 0.16 % ↑ | |
| 6 | hs | atom_site | O | fract_z | 0.0629 | 0.0611 | 0.0001 | 2.85 % ↓ | |
| 7 | hs | atom_site | O | adp_iso | Ų | 0.5000 | 1.0782 | 0.0377 | 115.64 % ↑ |
| 8 | hs | atom_site | Cl | fract_z | 0.1974 | 0.1967 | 0.0001 | 0.34 % ↓ | |
| 9 | hs | atom_site | Cl | adp_iso | Ų | 0.5000 | 1.4329 | 0.0380 | 186.58 % ↑ |
| 10 | hs | atom_site | H | fract_x | 0.1339 | 0.1324 | 0.0002 | 1.15 % ↓ | |
| 11 | hs | atom_site | H | fract_z | 0.0871 | 0.0898 | 0.0001 | 3.12 % ↑ | |
| 12 | hs | atom_site | H | adp_iso | Ų | 0.5000 | 2.4445 | 0.0430 | 388.90 % ↑ |
| 13 | hrpt | linked_structure | hs | scale | 0.3950 | 0.5110 | 0.0026 | 29.37 % ↑ | |
| 14 | hrpt | peak | asym_beba_a0 | 0.0000 | -0.1969 | 0.0258 | N/A | ||
| 15 | hrpt | peak | asym_beba_b0 | 0.0000 | -0.0474 | 0.0041 | N/A | ||
| 16 | hrpt | peak | asym_beba_a1 | 0.0000 | 0.1179 | 0.0591 | N/A | ||
| 17 | hrpt | peak | asym_beba_b1 | 0.0000 | 0.0553 | 0.0093 | N/A | ||
| 18 | hrpt | peak | broad_gauss_u | deg² | 0.3572 | 0.2304 | 0.0075 | 35.50 % ↓ | |
| 19 | hrpt | peak | broad_gauss_v | deg² | -0.3818 | -0.2884 | 0.0113 | 24.45 % ↓ | |
| 20 | hrpt | peak | broad_gauss_w | deg² | 0.2825 | 0.2722 | 0.0032 | 3.65 % ↓ | |
| 21 | hrpt | peak | broad_lorentz_y | deg | 0.1390 | 0.1528 | 0.0031 | 9.90 % ↑ | |
| 22 | hrpt | instrument | twotheta_offset | deg | 0.1148 | 0.1461 | 0.0071 | 27.24 % ↑ | |
| 23 | hrpt | background | 1 | intensity | 672.1313 | 672.1970 | 7.7886 | 0.01 % ↑ | |
| 24 | hrpt | background | 2 | intensity | 456.2819 | 456.1904 | 2.4427 | 0.02 % ↓ | |
| 25 | hrpt | background | 3 | intensity | 448.0780 | 444.7383 | 2.3898 | 0.75 % ↓ | |
| 26 | hrpt | background | 4 | intensity | 564.3133 | 472.7138 | 5.6219 | 16.23 % ↓ | |
| 27 | hrpt | background | 5 | intensity | 464.7443 | 460.8542 | 3.0171 | 0.84 % ↓ | |
| 28 | hrpt | background | 6 | intensity | 517.8974 | 494.4704 | 2.0904 | 4.52 % ↓ | |
| 29 | hrpt | background | 7 | intensity | 449.9013 | 492.3397 | 2.0718 | 9.43 % ↑ | |
| 30 | hrpt | background | 8 | intensity | 473.3742 | 533.2086 | 4.4152 | 12.64 % ↑ | |
| 31 | hrpt | background | 9 | intensity | 477.2343 | 525.1618 | 5.2338 | 10.04 % ↑ | |
| 32 | hrpt | background | 10 | intensity | 454.9376 | 526.7387 | 3.9282 | 15.78 % ↑ | |
| 33 | hrpt | background | 11 | intensity | 405.1224 | 492.4487 | 3.6512 | 21.56 % ↑ | |
| 34 | hrpt | background | 12 | intensity | 589.7398 | 507.1961 | 6.6711 | 14.00 % ↓ |
• start = parameter value before refinement
• value = refined value from least-squares minimization
• s.u. = standard uncertainty (one sigma), from the covariance matrix
• change = relative change from start, in %; ↑ = increase, ↓ = decrease
• value = refined value from least-squares minimization
• s.u. = standard uncertainty (one sigma), from the covariance matrix
• change = relative change from start, in %; ↑ = increase, ↓ = decrease
In [44]:
Copied!
project.display.fit.correlations()
project.display.fit.correlations()
Loading plot…
Display Pattern¶
In [45]:
Copied!
project.display.pattern(expt_name='hrpt')
project.display.pattern(expt_name='hrpt')
Loading plot…
In [46]:
Copied!
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)
Loading plot…
📊 Report¶
The HTML report is written automatically when the project is saved;
enable project.report.pdf as well for a PDF version.
💾 Save Project¶
In [47]:
Copied!
project.save_as(dir_path='projects/refine-hs-hrpt')
project.save_as(dir_path='projects/refine-hs-hrpt')
Saving project 📦 'hs_hrpt' to '../../../projects/refine-hs-hrpt'
├── 📄 project.edi
├── 📁 structures/
│ └── 📄 hs.edi
├── 📁 experiments/
│ └── 📄 hrpt.edi
├── 📁 analysis/
│ └── 📄 analysis.edi
└── 📁 reports/
└── 📄 hs_hrpt.html