{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "0",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:31:42.447205Z",
"iopub.status.busy": "2026-06-30T22:31:42.446960Z",
"iopub.status.idle": "2026-06-30T22:31:42.453354Z",
"shell.execute_reply": "2026-06-30T22:31:42.452108Z"
},
"tags": [
"hide-in-docs"
]
},
"outputs": [],
"source": [
"# Check whether easydiffraction is installed; install it if needed.\n",
"# Required for remote environments such as Google Colab.\n",
"import importlib.util\n",
"\n",
"if importlib.util.find_spec('easydiffraction') is None:\n",
" %pip install easydiffraction==0.19.1"
]
},
{
"cell_type": "markdown",
"id": "1",
"metadata": {},
"source": [
"# Structure Refinement: LBCO, HRPT\n",
"\n",
"This basic example is designed to show how Rietveld refinement can be\n",
"performed when both the crystal structure and experiment parameters\n",
"are defined using CIF files.\n",
"\n",
"For this example, constant-wavelength neutron powder diffraction data\n",
"for La0.5Ba0.5CoO3 from HRPT at PSI is used.\n",
"\n",
"The example is intended for users who are already familiar with the\n",
"EasyDiffraction library and want to quickly get started with a basic\n",
"refinement.\n",
"\n",
"It is also useful for those who want to see how constraints can be\n",
"applied to highly correlated parameters. For a more detailed\n",
"explanation of the code, please refer to the other tutorials."
]
},
{
"cell_type": "markdown",
"id": "2",
"metadata": {},
"source": [
"## π οΈ Import Library"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:31:42.455852Z",
"iopub.status.busy": "2026-06-30T22:31:42.454888Z",
"iopub.status.idle": "2026-06-30T22:31:47.164008Z",
"shell.execute_reply": "2026-06-30T22:31:47.162447Z"
}
},
"outputs": [],
"source": [
"import easydiffraction as edi"
]
},
{
"cell_type": "markdown",
"id": "4",
"metadata": {},
"source": [
"## π¦ Define Project"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:31:47.166610Z",
"iopub.status.busy": "2026-06-30T22:31:47.166215Z",
"iopub.status.idle": "2026-06-30T22:31:47.534345Z",
"shell.execute_reply": "2026-06-30T22:31:47.532979Z"
}
},
"outputs": [],
"source": [
"# Create a minimal project with a short name\n",
"project = edi.Project(name='lbco_hrpt')"
]
},
{
"cell_type": "markdown",
"id": "6",
"metadata": {},
"source": [
"## π§© Define Structure"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "7",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:31:47.536760Z",
"iopub.status.busy": "2026-06-30T22:31:47.536529Z",
"iopub.status.idle": "2026-06-30T22:31:47.554801Z",
"shell.execute_reply": "2026-06-30T22:31:47.553466Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mGetting data\u001b[0m\u001b[1;36m...\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data \u001b[32m'struct-lbco'\u001b[0m: La0.5Ba0.5CoO3 \u001b[1m(\u001b[0mcrystal structure\u001b[1m)\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β
Data \u001b[32m'struct-lbco'\u001b[0m already present at \u001b[32m'../../../data/struct-lbco.cif'\u001b[0m. Keeping existing.\n"
]
}
],
"source": [
"# Download CIF file from repository\n",
"structure_path = edi.download_data('struct-lbco', destination='data')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:31:47.556732Z",
"iopub.status.busy": "2026-06-30T22:31:47.556511Z",
"iopub.status.idle": "2026-06-30T22:31:47.571865Z",
"shell.execute_reply": "2026-06-30T22:31:47.570601Z"
}
},
"outputs": [],
"source": [
"# Add structure from downloaded CIF\n",
"project.structures.add_from_cif_path(structure_path)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "9",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:31:47.573718Z",
"iopub.status.busy": "2026-06-30T22:31:47.573486Z",
"iopub.status.idle": "2026-06-30T22:31:47.656719Z",
"shell.execute_reply": "2026-06-30T22:31:47.655910Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mStructure π§© \u001b[0m\u001b[32m'lbco'\u001b[0m\u001b[1;36m \u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36mAtom view type: \u001b[0m\u001b[32m'covalent'\u001b[0m\u001b[1;36m)\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"
\n",
"
\n",
"
Loading plotβ¦
\n",
"
\n",
"
\n",
"
\n",
"
drag = rotate
wheel = zoom
right-drag = pan
\n",
"
\n",
"
\n",
"\n",
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Plot the crystal structure\n",
"project.display.structure(struct_name='lbco')"
]
},
{
"cell_type": "markdown",
"id": "10",
"metadata": {},
"source": [
"## π¬ Define Experiment"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "11",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:31:47.658944Z",
"iopub.status.busy": "2026-06-30T22:31:47.658707Z",
"iopub.status.idle": "2026-06-30T22:31:47.892676Z",
"shell.execute_reply": "2026-06-30T22:31:47.891535Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mGetting data\u001b[0m\u001b[1;36m...\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data \u001b[32m'expt-lbco-hrpt'\u001b[0m: La0.5Ba0.5CoO3, HRPT \u001b[1m(\u001b[0mPSI\u001b[1m)\u001b[0m, \u001b[1;36m300\u001b[0m K\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β
Data \u001b[32m'expt-lbco-hrpt'\u001b[0m downloaded to \u001b[32m'../../../data/expt-lbco-hrpt.edi'\u001b[0m\n"
]
}
],
"source": [
"# Download CIF file from repository\n",
"expt_path = edi.download_data('expt-lbco-hrpt', destination='data')"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "12",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:31:47.894719Z",
"iopub.status.busy": "2026-06-30T22:31:47.894492Z",
"iopub.status.idle": "2026-06-30T22:31:49.250197Z",
"shell.execute_reply": "2026-06-30T22:31:49.249637Z"
}
},
"outputs": [],
"source": [
"# Add experiment from downloaded CIF\n",
"project.experiments.add_from_cif_path(expt_path)"
]
},
{
"cell_type": "markdown",
"id": "13",
"metadata": {},
"source": [
"## π Perform Analysis"
]
},
{
"cell_type": "markdown",
"id": "14",
"metadata": {},
"source": [
"### Without Constraints"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "15",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:31:49.251903Z",
"iopub.status.busy": "2026-06-30T22:31:49.251737Z",
"iopub.status.idle": "2026-06-30T22:32:00.171989Z",
"shell.execute_reply": "2026-06-30T22:32:00.171337Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-26ea5891d97f4bc5877e007efbd12bee-button');\n",
" const status = document.getElementById('ed-fit-stop-26ea5891d97f4bc5877e007efbd12bee-status');\n",
" const kernelId = '';\n",
" if (!button) {\n",
" return;\n",
" }\n",
"\n",
" function setStatus(text) {\n",
" if (status) {\n",
" status.textContent = text;\n",
" }\n",
" }\n",
"\n",
" function pageConfig() {\n",
" const element = document.getElementById('jupyter-config-data');\n",
" if (!element || !element.textContent) {\n",
" return {};\n",
" }\n",
" try {\n",
" return JSON.parse(element.textContent);\n",
" } catch (error) {\n",
" return {};\n",
" }\n",
" }\n",
"\n",
" function baseUrl(config) {\n",
" const configured = config.baseUrl || config.base_url ||\n",
" (window.Jupyter && Jupyter.notebook && Jupyter.notebook.base_url);\n",
" if (configured) {\n",
" return configured.endsWith('/') ? configured : configured + '/';\n",
" }\n",
" const markers = ['/lab/', '/notebooks/', '/tree/'];\n",
" for (const marker of markers) {\n",
" const index = window.location.pathname.indexOf(marker);\n",
" if (index >= 0) {\n",
" return window.location.pathname.slice(0, index + 1);\n",
" }\n",
" }\n",
" return '/';\n",
" }\n",
"\n",
" function token(config) {\n",
" return config.token || new URLSearchParams(window.location.search).get('token') || '';\n",
" }\n",
"\n",
" function cookie(name) {\n",
" const prefix = name + '=';\n",
" for (const part of document.cookie.split(';')) {\n",
" const trimmed = part.trim();\n",
" if (trimmed.startsWith(prefix)) {\n",
" return decodeURIComponent(trimmed.slice(prefix.length));\n",
" }\n",
" }\n",
" return '';\n",
" }\n",
"\n",
" function notebookPath() {\n",
" const decoded = decodeURIComponent(window.location.pathname);\n",
" const markers = ['/lab/tree/', '/notebooks/', '/tree/'];\n",
" for (const marker of markers) {\n",
" const index = decoded.indexOf(marker);\n",
" if (index >= 0) {\n",
" return decoded.slice(index + marker.length);\n",
" }\n",
" }\n",
" return '';\n",
" }\n",
"\n",
" async function kernelFromSessions(config) {\n",
" const url = new URL(baseUrl(config) + 'api/sessions', window.location.origin);\n",
" const authToken = token(config);\n",
" if (authToken) {\n",
" url.searchParams.set('token', authToken);\n",
" }\n",
" const response = await fetch(url, {credentials: 'same-origin'});\n",
" if (!response.ok) {\n",
" return '';\n",
" }\n",
" const sessions = await response.json();\n",
" const path = notebookPath();\n",
" const session = sessions.find((item) => item.path === path) || sessions[0];\n",
" return session && session.kernel ? session.kernel.id : '';\n",
" }\n",
"\n",
" async function interruptKernel(config, resolvedKernelId) {\n",
" const url = new URL(\n",
" baseUrl(config) + 'api/kernels/' + resolvedKernelId + '/interrupt',\n",
" window.location.origin\n",
" );\n",
" const authToken = token(config);\n",
" if (authToken) {\n",
" url.searchParams.set('token', authToken);\n",
" }\n",
" const xsrfToken = cookie('_xsrf');\n",
" const headers = {};\n",
" if (xsrfToken) {\n",
" headers['X-XSRFToken'] = xsrfToken;\n",
" }\n",
" const response = await fetch(url, {\n",
" method: 'POST',\n",
" credentials: 'same-origin',\n",
" headers: headers\n",
" });\n",
" return response.ok;\n",
" }\n",
"\n",
" button.addEventListener('click', async function() {\n",
" button.disabled = true;\n",
" setStatus('Stopping...');\n",
" const config = pageConfig();\n",
" try {\n",
" const resolvedKernelId = kernelId || await kernelFromSessions(config);\n",
" if (!resolvedKernelId) {\n",
" throw new Error('Could not resolve the current kernel id.');\n",
" }\n",
" const interrupted = await interruptKernel(config, resolvedKernelId);\n",
" if (!interrupted) {\n",
" throw new Error('Jupyter Server rejected the interrupt request.');\n",
" }\n",
" setStatus('Interrupt sent...');\n",
" } catch (error) {\n",
" button.disabled = false;\n",
" setStatus('Use Kernel > Interrupt to stop this fit.');\n",
" }\n",
" });\n",
"})();\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mStandard fitting\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Using experiment π¬ \u001b[32m'hrpt'\u001b[0m for \u001b[32m'single'\u001b[0m fitting\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Starting fit process with \u001b[32m'lmfit \u001b[0m\u001b[32m(\u001b[0m\u001b[32mleastsq\u001b[0m\u001b[32m)\u001b[0m\u001b[32m'\u001b[0m\u001b[33m...\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Goodness-of-fit progress:\n"
]
},
{
"data": {
"text/html": [
" | iteration | time (s) | ΟΒ² | change / status |
|---|
| 1 | 1 | 0.28 | 165.50 | |
|---|
| 2 | 28 | 1.30 | 33.67 | 79.7% β |
|---|
| 3 | 45 | 1.95 | 10.85 | 67.8% β |
|---|
| 4 | 63 | 2.85 | 6.43 | 40.7% β |
|---|
| 5 | 81 | 3.51 | 3.33 | 48.2% β |
|---|
| 6 | 98 | 4.13 | 2.23 | 33.2% β |
|---|
| 7 | 116 | 4.80 | 1.91 | 14.5% β |
|---|
| 8 | 133 | 5.43 | 1.50 | 21.1% β |
|---|
| 9 | 150 | 6.07 | 1.45 | 3.6% β |
|---|
| 10 | 167 | 6.71 | 1.34 | 7.7% β |
|---|
| 11 | 185 | 7.40 | 1.29 | 3.4% β |
|---|
| 12 | 276 | 10.87 | 1.29 | |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Best goodness-of-fit \u001b[1m(\u001b[0mreduced ΟΒ²\u001b[1m)\u001b[0m is \u001b[1;36m1.29\u001b[0m at iteration \u001b[1;36m261\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β
Fitting complete.\n"
]
}
],
"source": [
"# Start refinement. All parameters, which have standard uncertainties\n",
"# in the input CIF files, are refined by default.\n",
"project.analysis.fit()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "16",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:32:00.173788Z",
"iopub.status.busy": "2026-06-30T22:32:00.173613Z",
"iopub.status.idle": "2026-06-30T22:32:00.746192Z",
"shell.execute_reply": "2026-06-30T22:32:00.745595Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"βοΈ Settings used:\n"
]
},
{
"data": {
"text/html": [
" | Name | Value | Description |
|---|
| 1 | max_iterations | 1000 | Maximum solver iterations. |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Least-squares fit results:\n"
]
},
{
"data": {
"text/html": [
" | Metric | Value |
|---|
| 1 | π§ͺ Minimizer | lmfit (leastsq) |
|---|
| 2 | β
Overall status | success |
|---|
| 3 | β±οΈ Fitting time (seconds) | 10.87 |
|---|
| 4 | π Iterations | 273 |
|---|
| 5 | π Goodness-of-fit (reduced ΟΒ²) | 1.29 |
|---|
| 6 | π R-factor (Rf, %) | 5.62 |
|---|
| 7 | π R-factor squared (RfΒ², %) | 5.25 |
|---|
| 8 | π Weighted R-factor (wR, %) | 4.40 |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Refined parameters:\n"
]
},
{
"data": {
"text/html": [
" | datablock | category | entry | parameter | units | start | value | s.u. | change |
|---|
| 1 | lbco | cell | | length_a | Γ
| 3.8800 | 3.8909 | 0.0000 | 0.28 % β |
|---|
| 2 | lbco | atom_site | La | adp_iso | Γ
Β² | 0.5000 | 0.5051 | 6011.5791 | 1.02 % β |
|---|
| 3 | lbco | atom_site | Ba | adp_iso | Γ
Β² | 0.5000 | 0.5052 | 9770.5004 | 1.04 % β |
|---|
| 4 | lbco | atom_site | Co | adp_iso | Γ
Β² | 0.5000 | 0.2371 | 0.0611 | 52.59 % β |
|---|
| 5 | lbco | atom_site | O | adp_iso | Γ
Β² | 0.5000 | 1.3935 | 0.0168 | 178.70 % β |
|---|
| 6 | hrpt | linked_structure | lbco | scale | | 10.0000 | 9.1349 | 0.0643 | 8.65 % β |
|---|
| 7 | hrpt | peak | | broad_gauss_u | degΒ² | 0.1000 | 0.0816 | 0.0031 | 18.44 % β |
|---|
| 8 | hrpt | peak | | broad_gauss_v | degΒ² | -0.1000 | -0.1159 | 0.0067 | 15.90 % β |
|---|
| 9 | hrpt | peak | | broad_gauss_w | degΒ² | 0.1000 | 0.1204 | 0.0033 | 20.45 % β |
|---|
| 10 | hrpt | peak | | broad_lorentz_y | deg | 0.1000 | 0.0844 | 0.0021 | 15.57 % β |
|---|
| 11 | hrpt | instrument | | twotheta_offset | deg | 0.6000 | 0.6226 | 0.0010 | 3.76 % β |
|---|
| 12 | hrpt | background | 1 | intensity | | 170.0000 | 168.4242 | 1.3977 | 0.93 % β |
|---|
| 13 | hrpt | background | 2 | intensity | | 170.0000 | 164.3715 | 1.0025 | 3.31 % β |
|---|
| 14 | hrpt | background | 3 | intensity | | 170.0000 | 166.8870 | 0.7391 | 1.83 % β |
|---|
| 15 | hrpt | background | 4 | intensity | | 170.0000 | 175.3977 | 0.6586 | 3.18 % β |
|---|
| 16 | hrpt | background | 5 | intensity | | 170.0000 | 174.3027 | 0.9113 | 2.53 % β |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
" β’ 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
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"β οΈ Red s.u.: exceeds the refined value (consider adding constraints)
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Show fit results summary\n",
"project.display.fit.results()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "17",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:32:00.748011Z",
"iopub.status.busy": "2026-06-30T22:32:00.747841Z",
"iopub.status.idle": "2026-06-30T22:32:00.789626Z",
"shell.execute_reply": "2026-06-30T22:32:00.789033Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Show parameter correlations\n",
"project.display.fit.correlations()"
]
},
{
"cell_type": "markdown",
"id": "18",
"metadata": {},
"source": [
"### With Constraints"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "19",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:32:00.791539Z",
"iopub.status.busy": "2026-06-30T22:32:00.791366Z",
"iopub.status.idle": "2026-06-30T22:32:00.796195Z",
"shell.execute_reply": "2026-06-30T22:32:00.795223Z"
}
},
"outputs": [],
"source": [
"# As can be seen from the parameter-correlation plot, the isotropic\n",
"# displacement parameters of La and Ba are highly correlated. Because\n",
"# La and Ba share the same mixed-occupancy site, their contributions to\n",
"# the neutron diffraction pattern are difficult to separate, especially\n",
"# since their coherent scattering lengths are not very different.\n",
"# Therefore, it is necessary to constrain them to be equal. First we\n",
"# define aliases and then use them to create a constraint.\n",
"project.analysis.aliases.create(\n",
" id='biso_La',\n",
" param=project.structures['lbco'].atom_sites['La'].adp_iso,\n",
")\n",
"project.analysis.aliases.create(\n",
" id='biso_Ba',\n",
" param=project.structures['lbco'].atom_sites['Ba'].adp_iso,\n",
")\n",
"project.analysis.constraints.create(expression='biso_Ba = biso_La')"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "20",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:32:00.797611Z",
"iopub.status.busy": "2026-06-30T22:32:00.797451Z",
"iopub.status.idle": "2026-06-30T22:32:01.665524Z",
"shell.execute_reply": "2026-06-30T22:32:01.664617Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-8380c81554994332993ce577ca4472b7-button');\n",
" const status = document.getElementById('ed-fit-stop-8380c81554994332993ce577ca4472b7-status');\n",
" const kernelId = '';\n",
" if (!button) {\n",
" return;\n",
" }\n",
"\n",
" function setStatus(text) {\n",
" if (status) {\n",
" status.textContent = text;\n",
" }\n",
" }\n",
"\n",
" function pageConfig() {\n",
" const element = document.getElementById('jupyter-config-data');\n",
" if (!element || !element.textContent) {\n",
" return {};\n",
" }\n",
" try {\n",
" return JSON.parse(element.textContent);\n",
" } catch (error) {\n",
" return {};\n",
" }\n",
" }\n",
"\n",
" function baseUrl(config) {\n",
" const configured = config.baseUrl || config.base_url ||\n",
" (window.Jupyter && Jupyter.notebook && Jupyter.notebook.base_url);\n",
" if (configured) {\n",
" return configured.endsWith('/') ? configured : configured + '/';\n",
" }\n",
" const markers = ['/lab/', '/notebooks/', '/tree/'];\n",
" for (const marker of markers) {\n",
" const index = window.location.pathname.indexOf(marker);\n",
" if (index >= 0) {\n",
" return window.location.pathname.slice(0, index + 1);\n",
" }\n",
" }\n",
" return '/';\n",
" }\n",
"\n",
" function token(config) {\n",
" return config.token || new URLSearchParams(window.location.search).get('token') || '';\n",
" }\n",
"\n",
" function cookie(name) {\n",
" const prefix = name + '=';\n",
" for (const part of document.cookie.split(';')) {\n",
" const trimmed = part.trim();\n",
" if (trimmed.startsWith(prefix)) {\n",
" return decodeURIComponent(trimmed.slice(prefix.length));\n",
" }\n",
" }\n",
" return '';\n",
" }\n",
"\n",
" function notebookPath() {\n",
" const decoded = decodeURIComponent(window.location.pathname);\n",
" const markers = ['/lab/tree/', '/notebooks/', '/tree/'];\n",
" for (const marker of markers) {\n",
" const index = decoded.indexOf(marker);\n",
" if (index >= 0) {\n",
" return decoded.slice(index + marker.length);\n",
" }\n",
" }\n",
" return '';\n",
" }\n",
"\n",
" async function kernelFromSessions(config) {\n",
" const url = new URL(baseUrl(config) + 'api/sessions', window.location.origin);\n",
" const authToken = token(config);\n",
" if (authToken) {\n",
" url.searchParams.set('token', authToken);\n",
" }\n",
" const response = await fetch(url, {credentials: 'same-origin'});\n",
" if (!response.ok) {\n",
" return '';\n",
" }\n",
" const sessions = await response.json();\n",
" const path = notebookPath();\n",
" const session = sessions.find((item) => item.path === path) || sessions[0];\n",
" return session && session.kernel ? session.kernel.id : '';\n",
" }\n",
"\n",
" async function interruptKernel(config, resolvedKernelId) {\n",
" const url = new URL(\n",
" baseUrl(config) + 'api/kernels/' + resolvedKernelId + '/interrupt',\n",
" window.location.origin\n",
" );\n",
" const authToken = token(config);\n",
" if (authToken) {\n",
" url.searchParams.set('token', authToken);\n",
" }\n",
" const xsrfToken = cookie('_xsrf');\n",
" const headers = {};\n",
" if (xsrfToken) {\n",
" headers['X-XSRFToken'] = xsrfToken;\n",
" }\n",
" const response = await fetch(url, {\n",
" method: 'POST',\n",
" credentials: 'same-origin',\n",
" headers: headers\n",
" });\n",
" return response.ok;\n",
" }\n",
"\n",
" button.addEventListener('click', async function() {\n",
" button.disabled = true;\n",
" setStatus('Stopping...');\n",
" const config = pageConfig();\n",
" try {\n",
" const resolvedKernelId = kernelId || await kernelFromSessions(config);\n",
" if (!resolvedKernelId) {\n",
" throw new Error('Could not resolve the current kernel id.');\n",
" }\n",
" const interrupted = await interruptKernel(config, resolvedKernelId);\n",
" if (!interrupted) {\n",
" throw new Error('Jupyter Server rejected the interrupt request.');\n",
" }\n",
" setStatus('Interrupt sent...');\n",
" } catch (error) {\n",
" button.disabled = false;\n",
" setStatus('Use Kernel > Interrupt to stop this fit.');\n",
" }\n",
" });\n",
"})();\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mStandard fitting\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Using experiment π¬ \u001b[32m'hrpt'\u001b[0m for \u001b[32m'single'\u001b[0m fitting\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Starting fit process with \u001b[32m'lmfit \u001b[0m\u001b[32m(\u001b[0m\u001b[32mleastsq\u001b[0m\u001b[32m)\u001b[0m\u001b[32m'\u001b[0m\u001b[33m...\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Goodness-of-fit progress:\n"
]
},
{
"data": {
"text/html": [
" | iteration | time (s) | ΟΒ² | change / status |
|---|
| 1 | 1 | 0.04 | 1.29 | |
|---|
| 2 | 20 | 0.81 | 1.29 | |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Best goodness-of-fit \u001b[1m(\u001b[0mreduced ΟΒ²\u001b[1m)\u001b[0m is \u001b[1;36m1.29\u001b[0m at iteration \u001b[1;36m19\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β
Fitting complete.\n"
]
}
],
"source": [
"# Start refinement. All parameters, which have standard uncertainties\n",
"# in the input CIF files, are refined by default.\n",
"project.analysis.fit()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "21",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:32:01.666976Z",
"iopub.status.busy": "2026-06-30T22:32:01.666802Z",
"iopub.status.idle": "2026-06-30T22:32:01.989172Z",
"shell.execute_reply": "2026-06-30T22:32:01.988511Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"βοΈ Settings used:\n"
]
},
{
"data": {
"text/html": [
" | Name | Value | Description |
|---|
| 1 | max_iterations | 1000 | Maximum solver iterations. |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Least-squares fit results:\n"
]
},
{
"data": {
"text/html": [
" | Metric | Value |
|---|
| 1 | π§ͺ Minimizer | lmfit (leastsq) |
|---|
| 2 | β
Overall status | success |
|---|
| 3 | β±οΈ Fitting time (seconds) | 0.81 |
|---|
| 4 | π Iterations | 17 |
|---|
| 5 | π Goodness-of-fit (reduced ΟΒ²) | 1.29 |
|---|
| 6 | π R-factor (Rf, %) | 5.62 |
|---|
| 7 | π R-factor squared (RfΒ², %) | 5.25 |
|---|
| 8 | π Weighted R-factor (wR, %) | 4.40 |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Refined parameters:\n"
]
},
{
"data": {
"text/html": [
" | datablock | category | entry | parameter | units | start | value | s.u. | change |
|---|
| 1 | lbco | cell | | length_a | Γ
| 3.8909 | 3.8909 | 0.0000 | 0.00 % β |
|---|
| 2 | lbco | atom_site | La | adp_iso | Γ
Β² | 0.5051 | 0.5051 | 0.0278 | 0.00 % β |
|---|
| 3 | lbco | atom_site | Co | adp_iso | Γ
Β² | 0.2371 | 0.2371 | 0.0564 | 0.00 % β |
|---|
| 4 | lbco | atom_site | O | adp_iso | Γ
Β² | 1.3935 | 1.3935 | 0.0160 | 0.00 % β |
|---|
| 5 | hrpt | linked_structure | lbco | scale | | 9.1349 | 9.1349 | 0.0538 | 0.00 % β |
|---|
| 6 | hrpt | peak | | broad_gauss_u | degΒ² | 0.0816 | 0.0816 | 0.0031 | 0.00 % β |
|---|
| 7 | hrpt | peak | | broad_gauss_v | degΒ² | -0.1159 | -0.1159 | 0.0066 | 0.01 % β |
|---|
| 8 | hrpt | peak | | broad_gauss_w | degΒ² | 0.1204 | 0.1204 | 0.0032 | 0.00 % β |
|---|
| 9 | hrpt | peak | | broad_lorentz_y | deg | 0.0844 | 0.0844 | 0.0021 | 0.00 % β |
|---|
| 10 | hrpt | instrument | | twotheta_offset | deg | 0.6226 | 0.6226 | 0.0010 | 0.00 % β |
|---|
| 11 | hrpt | background | 1 | intensity | | 168.4242 | 168.4242 | 1.3974 | 0.00 % β |
|---|
| 12 | hrpt | background | 2 | intensity | | 164.3715 | 164.3715 | 1.0023 | 0.00 % β |
|---|
| 13 | hrpt | background | 3 | intensity | | 166.8870 | 166.8871 | 0.7388 | 0.00 % β |
|---|
| 14 | hrpt | background | 4 | intensity | | 175.3977 | 175.3978 | 0.6490 | 0.00 % β |
|---|
| 15 | hrpt | background | 5 | intensity | | 174.3027 | 174.3026 | 0.8956 | 0.00 % β |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
" β’ 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
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Show fit results summary\n",
"project.display.fit.results()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "22",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:32:01.990558Z",
"iopub.status.busy": "2026-06-30T22:32:01.990409Z",
"iopub.status.idle": "2026-06-30T22:32:02.014031Z",
"shell.execute_reply": "2026-06-30T22:32:02.013197Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Show parameter correlations\n",
"project.display.fit.correlations()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "23",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:32:02.015670Z",
"iopub.status.busy": "2026-06-30T22:32:02.015497Z",
"iopub.status.idle": "2026-06-30T22:32:02.020248Z",
"shell.execute_reply": "2026-06-30T22:32:02.019455Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mDefined experiments π¬\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1m[\u001b[0m\u001b[32m'hrpt'\u001b[0m\u001b[1m]\u001b[0m\n"
]
}
],
"source": [
"# Show defined experiment names\n",
"project.experiments.show_names()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "24",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:32:02.021602Z",
"iopub.status.busy": "2026-06-30T22:32:02.021435Z",
"iopub.status.idle": "2026-06-30T22:32:02.103791Z",
"shell.execute_reply": "2026-06-30T22:32:02.103126Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Plot measured vs. calculated diffraction patterns\n",
"project.display.pattern(expt_name='hrpt')"
]
},
{
"cell_type": "markdown",
"id": "25",
"metadata": {},
"source": [
"## πΎ Save Project"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "26",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:32:02.108238Z",
"iopub.status.busy": "2026-06-30T22:32:02.108035Z",
"iopub.status.idle": "2026-06-30T22:32:02.453778Z",
"shell.execute_reply": "2026-06-30T22:32:02.452843Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mSaving project π¦ \u001b[0m\u001b[32m'lbco_hrpt'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/refine-lbco-hrpt-from-cif'\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π project.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π structures/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π lbco.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π experiments/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π hrpt.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π analysis/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π analysis.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π reports/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" βββ π lbco_hrpt.html\n"
]
}
],
"source": [
"project.save_as(dir_path='projects/refine-lbco-hrpt-from-cif')"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.14.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}