{
"nbformat": 4,
"nbformat_minor": 5,
"metadata": {
"jupytext": {
"main_language": "python",
"notebook_metadata_filter": "-all",
"cell_metadata_filter": "-all",
"text_representation": {
"extension": ".py",
"format_name": "percent"
}
}
},
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"tags": [
"hide-in-docs"
],
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.220138Z",
"iopub.execute_input": "2026-11-10T22:14:23.220292Z",
"shell.execute_reply": "2026-11-10T22:14:23.223288Z",
"iopub.status.idle": "2026-11-10T22:14:23.223795Z"
}
},
"outputs": [],
"source": "# Check whether easydiffraction is installed; install it if needed.\n# Required for remote environments such as Google Colab.\nimport importlib.util\n\nif importlib.util.find_spec('easydiffraction') is None:\n %pip install easydiffraction==2026.11.0 --extra-index-url https://enhantica.github.io/edi-download/pypi/simple/\n",
"id": "0"
},
{
"id": "1",
"cell_type": "markdown",
"source": "# Rietveld fit: herbertsmithite, HRPT\n\nFit herbertsmithite, ZnCu₃(OD)₆Cl₂, a deuterated kagome antiferromagnet, to constant-wavelength\nneutron powder data from HRPT at PSI, with a pseudo-Voigt profile and Bérar-Baldinozzi\nasymmetry.\n\nThe project is the catalogue case `pd-neut-cwl_hs-hrpt`, the one the command line and the app's\nExamples open.",
"metadata": {}
},
{
"cell_type": "markdown",
"metadata": {},
"source": "
Fitting
Single pd neut cwl Bragg
Crystal structure",
"id": "2"
},
{
"id": "3",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.224974Z",
"iopub.execute_input": "2026-11-10T22:14:23.225109Z",
"shell.execute_reply": "2026-11-10T22:14:23.234359Z",
"iopub.status.idle": "2026-11-10T22:14:23.234761Z"
}
},
"execution_count": 2,
"source": "import easydiffraction as edi",
"outputs": []
},
{
"id": "4",
"cell_type": "markdown",
"source": "## Load the project",
"metadata": {}
},
{
"id": "5",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.235870Z",
"iopub.execute_input": "2026-11-10T22:14:23.236007Z",
"shell.execute_reply": "2026-11-10T22:14:23.490847Z",
"iopub.status.idle": "2026-11-10T22:14:23.491217Z"
}
},
"execution_count": 3,
"source": "project_path = edi.download_data('pd-neut-cwl_hs-hrpt', destination='data')\nproject = edi.Project.load(project_path)\nstructure = project.structures['hs']\nexperiment = project.experiments['hrpt']",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "Data 'pd-neut-cwl_hs-hrpt' is at data/pd-neut-cwl_hs-hrpt-dc870810b0b3/pd-neut-cwl_hs-hrpt\n"
}
]
},
{
"id": "6",
"cell_type": "markdown",
"source": "The project marks what its fit frees. The fit below frees it in stages, so start with all of it\nfixed.",
"metadata": {}
},
{
"id": "7",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.492308Z",
"iopub.execute_input": "2026-11-10T22:14:23.492427Z",
"shell.execute_reply": "2026-11-10T22:14:23.529541Z",
"iopub.status.idle": "2026-11-10T22:14:23.529905Z"
}
},
"execution_count": 4,
"source": "for parameter in project.free_parameters:\n parameter.free = False",
"outputs": []
},
{
"id": "8",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.530993Z",
"iopub.execute_input": "2026-11-10T22:14:23.531131Z",
"iopub.status.idle": "2026-11-10T22:14:23.569272Z",
"shell.execute_reply": "2026-11-10T22:14:23.568744Z"
}
},
"execution_count": 5,
"source": "project.display.pattern('hrpt')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<377,542 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "9",
"cell_type": "markdown",
"source": "## Perform the analysis\n\nThe fit follows diffraction-lib's four cycles for this case.",
"metadata": {}
},
{
"id": "10",
"cell_type": "markdown",
"source": "### Cell, scale and 2θ zero\n\nThe cell lengths, the scale and the zero shift put the peaks in place and at the right height.",
"metadata": {}
},
{
"id": "11",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.572501Z",
"iopub.execute_input": "2026-11-10T22:14:23.572639Z",
"shell.execute_reply": "2026-11-10T22:14:23.579249Z",
"iopub.status.idle": "2026-11-10T22:14:23.579640Z"
}
},
"execution_count": 6,
"source": "structure.cell.length_a.free = True\nstructure.cell.length_c.free = True\nexperiment.linked_structures['hs'].scale.free = True\nexperiment.instrument.calib_twotheta_offset.free = True",
"outputs": []
},
{
"id": "12",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.580755Z",
"iopub.execute_input": "2026-11-10T22:14:23.580879Z",
"iopub.status.idle": "2026-11-10T22:14:23.599178Z",
"shell.execute_reply": "2026-11-10T22:14:23.598738Z"
}
},
"execution_count": 7,
"source": "project.display.parameters.free()",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<77,987 characters>, height=208)",
"text/html": ""
}
}
]
},
{
"id": "13",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.600439Z",
"iopub.execute_input": "2026-11-10T22:14:23.600585Z",
"iopub.status.idle": "2026-11-10T22:14:23.674405Z",
"shell.execute_reply": "2026-11-10T22:14:23.673996Z"
}
},
"execution_count": 8,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-cwl_hs-hrpt, 3220 pts fitted / 3220 loaded, 4 free\n iter time (s) Rwp (%) reduced χ² change\n 39.94 121.13\n 1 0.002 27.45 57.20 52.8% ↓\n 2 0.004 26.38 52.82 7.6% ↓\n 3 0.005 25.56 49.61 6.1% ↓\n 4 0.008 25.02 47.54 4.2% ↓\n 5 0.009 24.70 46.30 2.6% ↓\n 6 0.011 24.51 45.59 1.5% ↓\n 7 0.013 24.40 45.19 0.9% ↓\n 8 0.015 24.34 44.97 0.5% ↓\n 9 0.017 24.30 44.84 0.3% ↓\n 10 0.018 24.28 44.77 0.2% ↓\n 11 0.020 24.27 44.73 0.1% ↓\n 12 0.022 24.27 44.71 \n 13 0.024 24.26 44.70 \n 14 0.025 24.26 44.69 \n 15 0.027 24.26 44.69 \n 16 0.029 24.26 44.69 \n 17 0.031 24.26 44.68 \n 18 0.033 24.26 44.68 \n 19 0.035 24.26 44.68 \n done · converged · 19 iters · reduced χ² 44.68 · Rwp 24.26 % · 0.04 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<80,908 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "14",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.675555Z",
"iopub.execute_input": "2026-11-10T22:14:23.675722Z",
"iopub.status.idle": "2026-11-10T22:14:23.709394Z",
"shell.execute_reply": "2026-11-10T22:14:23.708945Z"
}
},
"execution_count": 9,
"source": "project.display.pattern('hrpt')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<377,171 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "15",
"cell_type": "markdown",
"source": "### Background\n\nThe estimated points are a starting point; fit them now that the peaks are in place.",
"metadata": {}
},
{
"id": "16",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.712965Z",
"iopub.execute_input": "2026-11-10T22:14:23.713105Z",
"shell.execute_reply": "2026-11-10T22:14:23.727300Z",
"iopub.status.idle": "2026-11-10T22:14:23.727679Z"
}
},
"execution_count": 10,
"source": "for point in experiment.background:\n point.intensity.free = True",
"outputs": []
},
{
"id": "17",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.728755Z",
"iopub.execute_input": "2026-11-10T22:14:23.728887Z",
"iopub.status.idle": "2026-11-10T22:14:23.778978Z",
"shell.execute_reply": "2026-11-10T22:14:23.778504Z"
}
},
"execution_count": 11,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-cwl_hs-hrpt, 3220 pts fitted / 3220 loaded, 14 free\n iter time (s) Rwp (%) reduced χ² change\n 24.26 44.82\n 1 0.003 21.75 36.02 19.6% ↓\n 2 0.005 21.75 36.02 \n 3 0.007 21.75 36.02 \n 4 0.011 21.75 36.02 \n done · converged · 4 iters · reduced χ² 36.02 · Rwp 21.75 % · 0.01 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<90,901 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "18",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.780238Z",
"iopub.execute_input": "2026-11-10T22:14:23.780382Z",
"iopub.status.idle": "2026-11-10T22:14:23.814370Z",
"shell.execute_reply": "2026-11-10T22:14:23.813882Z"
}
},
"execution_count": 12,
"source": "project.display.pattern('hrpt')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<414,826 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "19",
"cell_type": "markdown",
"source": "### Peak widths\n\nThe Gaussian widths and the mixing η₀, with the background staying free. diffraction-lib frees\nthe Lorentzian Y where this profile has η₀.",
"metadata": {}
},
{
"id": "20",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.818775Z",
"iopub.execute_input": "2026-11-10T22:14:23.818896Z",
"shell.execute_reply": "2026-11-10T22:14:23.825965Z",
"iopub.status.idle": "2026-11-10T22:14:23.826374Z"
}
},
"execution_count": 13,
"source": "experiment.peak.broad_gauss_u.free = True\nexperiment.peak.broad_gauss_v.free = True\nexperiment.peak.broad_gauss_w.free = True\nexperiment.peak.mixing_eta_0.free = True",
"outputs": []
},
{
"id": "21",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.827446Z",
"iopub.execute_input": "2026-11-10T22:14:23.827568Z",
"shell.execute_reply": "2026-11-10T22:14:23.893653Z",
"iopub.status.idle": "2026-11-10T22:14:23.894122Z"
}
},
"execution_count": 14,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-cwl_hs-hrpt, 3220 pts fitted / 3220 loaded, 18 free\n iter time (s) Rwp (%) reduced χ² change\n 21.75 36.07\n 1 0.003 16.60 21.01 41.8% ↓\n 2 0.006 14.23 15.45 26.5% ↓\n 3 0.008 13.53 13.96 9.6% ↓\n 4 0.011 13.45 13.79 1.2% ↓\n 5 0.014 13.44 13.77 0.1% ↓\n 6 0.017 13.44 13.77 \n 7 0.020 13.44 13.77 \n 8 0.023 13.44 13.77 \n 9 0.027 13.44 13.77 \n done · converged · 9 iters · reduced χ² 13.77 · Rwp 13.44 % · 0.03 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<95,277 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "22",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.895152Z",
"iopub.execute_input": "2026-11-10T22:14:23.895283Z",
"iopub.status.idle": "2026-11-10T22:14:23.931006Z",
"shell.execute_reply": "2026-11-10T22:14:23.930305Z"
}
},
"execution_count": 15,
"source": "project.display.pattern('hrpt')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<414,543 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "23",
"cell_type": "markdown",
"source": "### Atom positions\n\nThe coordinates the symmetry leaves free: O and H in x and z, Cl in z.",
"metadata": {}
},
{
"id": "24",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.934907Z",
"iopub.execute_input": "2026-11-10T22:14:23.935056Z",
"iopub.status.idle": "2026-11-10T22:14:23.962097Z",
"shell.execute_reply": "2026-11-10T22:14:23.961457Z"
}
},
"execution_count": 16,
"source": "for site in structure.atom_sites:\n for coordinate in (site.fract_x, site.fract_y, site.fract_z):\n coordinate.free = not coordinate.symmetry_constrained",
"outputs": []
},
{
"id": "25",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:23.963434Z",
"iopub.execute_input": "2026-11-10T22:14:23.963578Z",
"shell.execute_reply": "2026-11-10T22:14:24.037593Z",
"iopub.status.idle": "2026-11-10T22:14:24.038122Z"
}
},
"execution_count": 17,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-cwl_hs-hrpt, 3220 pts fitted / 3220 loaded, 23 free\n iter time (s) Rwp (%) reduced χ² change\n 13.44 13.79\n 1 0.007 8.42 5.41 60.7% ↓\n 2 0.012 8.21 5.15 4.8% ↓\n 3 0.017 8.21 5.15 0.1% ↓\n 4 0.021 8.21 5.15 \n 5 0.029 8.21 5.15 \n done · converged · 5 iters · reduced χ² 5.15 · Rwp 8.21 % · 0.03 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<100,519 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "26",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:24.039374Z",
"iopub.execute_input": "2026-11-10T22:14:24.039500Z",
"iopub.status.idle": "2026-11-10T22:14:24.075029Z",
"shell.execute_reply": "2026-11-10T22:14:24.074588Z"
}
},
"execution_count": 18,
"source": "project.display.pattern('hrpt')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<414,515 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "27",
"cell_type": "markdown",
"source": "### Displacements\n\nEvery site's displacement.",
"metadata": {}
},
{
"id": "28",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:24.079175Z",
"iopub.execute_input": "2026-11-10T22:14:24.079308Z",
"shell.execute_reply": "2026-11-10T22:14:24.086467Z",
"iopub.status.idle": "2026-11-10T22:14:24.086829Z"
}
},
"execution_count": 19,
"source": "for site in structure.atom_sites:\n site.adp_iso.free = True",
"outputs": []
},
{
"id": "29",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:24.087898Z",
"iopub.execute_input": "2026-11-10T22:14:24.088016Z",
"shell.execute_reply": "2026-11-10T22:14:24.149362Z",
"iopub.status.idle": "2026-11-10T22:14:24.149751Z"
}
},
"execution_count": 20,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-cwl_hs-hrpt, 3220 pts fitted / 3220 loaded, 28 free\n iter time (s) Rwp (%) reduced χ² change\n 8.21 5.16\n 1 0.006 5.71 2.50 51.5% ↓\n 2 0.010 5.45 2.27 9.1% ↓\n 3 0.014 5.45 2.27 \n 4 0.020 5.45 2.27 \n done · converged · 4 iters · reduced χ² 2.27 · Rwp 5.45 % · 0.02 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<105,771 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "30",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:24.150854Z",
"iopub.execute_input": "2026-11-10T22:14:24.150983Z",
"iopub.status.idle": "2026-11-10T22:14:24.183999Z",
"shell.execute_reply": "2026-11-10T22:14:24.183156Z"
}
},
"execution_count": 21,
"source": "project.display.pattern('hrpt')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<414,694 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "31",
"cell_type": "markdown",
"source": "### Asymmetry\n\nLast, the four Bérar-Baldinozzi asymmetry terms.",
"metadata": {}
},
{
"id": "32",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:24.187849Z",
"iopub.execute_input": "2026-11-10T22:14:24.187978Z",
"shell.execute_reply": "2026-11-10T22:14:24.194661Z",
"iopub.status.idle": "2026-11-10T22:14:24.195045Z"
}
},
"execution_count": 22,
"source": "experiment.peak.asym_beba_a0.free = True\nexperiment.peak.asym_beba_b0.free = True\nexperiment.peak.asym_beba_a1.free = True\nexperiment.peak.asym_beba_b1.free = True",
"outputs": []
},
{
"id": "33",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:24.195974Z",
"iopub.execute_input": "2026-11-10T22:14:24.196085Z",
"shell.execute_reply": "2026-11-10T22:14:24.264062Z",
"iopub.status.idle": "2026-11-10T22:14:24.264536Z"
}
},
"execution_count": 23,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-cwl_hs-hrpt, 3220 pts fitted / 3220 loaded, 32 free\n iter time (s) Rwp (%) reduced χ² change\n 5.45 2.27\n 1 0.006 5.31 2.16 4.9% ↓\n 2 0.011 5.30 2.15 0.4% ↓\n 3 0.015 5.30 2.15 \n 4 0.020 5.30 2.15 \n 5 0.026 5.30 2.15 \n done · converged · 5 iters · reduced χ² 2.15 · Rwp 5.30 % · 0.03 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<109,819 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "34",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:24.265667Z",
"iopub.execute_input": "2026-11-10T22:14:24.265797Z",
"iopub.status.idle": "2026-11-10T22:14:24.300142Z",
"shell.execute_reply": "2026-11-10T22:14:24.299577Z"
}
},
"execution_count": 24,
"source": "project.display.pattern('hrpt')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<414,742 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "35",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:24.303970Z",
"iopub.execute_input": "2026-11-10T22:14:24.304092Z",
"iopub.status.idle": "2026-11-10T22:14:24.325861Z",
"shell.execute_reply": "2026-11-10T22:14:24.325409Z"
}
},
"execution_count": 25,
"source": "project.display.fit.correlations()",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<77,003 characters>, height=560)",
"text/html": ""
}
}
]
},
{
"id": "36",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:24.327125Z",
"iopub.execute_input": "2026-11-10T22:14:24.327262Z",
"iopub.status.idle": "2026-11-10T22:14:24.350989Z",
"shell.execute_reply": "2026-11-10T22:14:24.350531Z"
}
},
"execution_count": 26,
"source": "project.display.structure('hs')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<260,639 characters>, height=660)",
"text/html": ""
}
}
]
},
{
"id": "37",
"cell_type": "markdown",
"source": "## Save the project",
"metadata": {}
},
{
"id": "38",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-10T22:14:24.353178Z",
"iopub.execute_input": "2026-11-10T22:14:24.353291Z",
"shell.execute_reply": "2026-11-10T22:14:24.542936Z",
"iopub.status.idle": "2026-11-10T22:14:24.543312Z"
}
},
"execution_count": 27,
"source": "project.save_as('pd-neut-cwl_hs-hrpt')\nproject.report.save_html('pd-neut-cwl_hs-hrpt.html')",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "Saving project to 'pd-neut-cwl_hs-hrpt'\nSaving report to 'pd-neut-cwl_hs-hrpt.html'\n"
}
]
}
]
}