{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "0",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:54.472344Z",
"iopub.status.busy": "2026-06-30T22:28:54.472131Z",
"iopub.status.idle": "2026-06-30T22:28:54.476614Z",
"shell.execute_reply": "2026-06-30T22:28:54.475647Z"
},
"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 minimalistic example is designed to show how Rietveld refinement\n",
"can be performed when both the crystal structure and experiment are\n",
"defined directly in code. Only the experimentally measured data is\n",
"loaded from an external file. It also shows how to switch calculation\n",
"engine.\n",
"\n",
"For this example, constant-wavelength neutron powder diffraction data\n",
"for La0.5Ba0.5CoO3 from HRPT at PSI is used.\n",
"\n",
"It does not contain any advanced features or options, and includes no\n",
"comments or explanations β these can be found in the other tutorials.\n",
"Default values are used for all parameters if not specified. Only\n",
"essential and self-explanatory code is provided.\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 simple\n",
"refinement. It is also useful for those who want to see what a\n",
"refinement might look like in code. For a more detailed explanation of\n",
"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:28:54.478165Z",
"iopub.status.busy": "2026-06-30T22:28:54.477984Z",
"iopub.status.idle": "2026-06-30T22:28:57.382189Z",
"shell.execute_reply": "2026-06-30T22:28:57.381274Z"
}
},
"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:28:57.384144Z",
"iopub.status.busy": "2026-06-30T22:28:57.383812Z",
"iopub.status.idle": "2026-06-30T22:28:57.599964Z",
"shell.execute_reply": "2026-06-30T22:28:57.598963Z"
}
},
"outputs": [],
"source": [
"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:28:57.601503Z",
"iopub.status.busy": "2026-06-30T22:28:57.601345Z",
"iopub.status.idle": "2026-06-30T22:28:57.604510Z",
"shell.execute_reply": "2026-06-30T22:28:57.603761Z"
}
},
"outputs": [],
"source": [
"project.structures.create(name='lbco')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:57.606259Z",
"iopub.status.busy": "2026-06-30T22:28:57.605943Z",
"iopub.status.idle": "2026-06-30T22:28:57.608747Z",
"shell.execute_reply": "2026-06-30T22:28:57.608164Z"
}
},
"outputs": [],
"source": [
"structure = project.structures['lbco']"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "9",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:57.610354Z",
"iopub.status.busy": "2026-06-30T22:28:57.610188Z",
"iopub.status.idle": "2026-06-30T22:28:57.613647Z",
"shell.execute_reply": "2026-06-30T22:28:57.612964Z"
}
},
"outputs": [],
"source": [
"structure.space_group.name_h_m = 'P m -3 m'\n",
"structure.space_group.coord_system_code = '1'"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "10",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:57.615268Z",
"iopub.status.busy": "2026-06-30T22:28:57.615024Z",
"iopub.status.idle": "2026-06-30T22:28:57.617960Z",
"shell.execute_reply": "2026-06-30T22:28:57.617307Z"
}
},
"outputs": [],
"source": [
"structure.cell.length_a = 3.88"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "11",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:57.619320Z",
"iopub.status.busy": "2026-06-30T22:28:57.619179Z",
"iopub.status.idle": "2026-06-30T22:28:57.625991Z",
"shell.execute_reply": "2026-06-30T22:28:57.625013Z"
}
},
"outputs": [],
"source": [
"structure.atom_sites.create(\n",
" id='La',\n",
" type_symbol='La',\n",
" fract_x=0,\n",
" fract_y=0,\n",
" fract_z=0,\n",
" adp_iso=0.5,\n",
" occupancy=0.5,\n",
")\n",
"structure.atom_sites.create(\n",
" id='Ba',\n",
" type_symbol='Ba',\n",
" fract_x=0,\n",
" fract_y=0,\n",
" fract_z=0,\n",
" adp_iso=0.5,\n",
" occupancy=0.5,\n",
")\n",
"structure.atom_sites.create(\n",
" id='Co',\n",
" type_symbol='Co',\n",
" fract_x=0.5,\n",
" fract_y=0.5,\n",
" fract_z=0.5,\n",
" adp_iso=0.5,\n",
")\n",
"structure.atom_sites.create(\n",
" id='O',\n",
" type_symbol='O',\n",
" fract_x=0,\n",
" fract_y=0.5,\n",
" fract_z=0.5,\n",
" adp_iso=0.5,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "12",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:57.627471Z",
"iopub.status.busy": "2026-06-30T22:28:57.627319Z",
"iopub.status.idle": "2026-06-30T22:28:58.042016Z",
"shell.execute_reply": "2026-06-30T22:28:58.041143Z"
}
},
"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": [
"project.display.structure(struct_name='lbco')"
]
},
{
"cell_type": "markdown",
"id": "13",
"metadata": {},
"source": [
"## π¬ Define Experiment"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "14",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:58.044007Z",
"iopub.status.busy": "2026-06-30T22:28:58.043825Z",
"iopub.status.idle": "2026-06-30T22:28:58.221940Z",
"shell.execute_reply": "2026-06-30T22:28:58.221149Z"
}
},
"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'meas-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'meas-lbco-hrpt'\u001b[0m downloaded to \u001b[32m'../../../data/meas-lbco-hrpt.xye'\u001b[0m\n"
]
}
],
"source": [
"data_path = edi.download_data('meas-lbco-hrpt', destination='data')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "15",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:58.223858Z",
"iopub.status.busy": "2026-06-30T22:28:58.223680Z",
"iopub.status.idle": "2026-06-30T22:28:58.734290Z",
"shell.execute_reply": "2026-06-30T22:28:58.733286Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mData loaded successfully\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Experiment π¬ \u001b[32m'hrpt'\u001b[0m. Number of data points: \u001b[1;36m3098\u001b[0m.\n"
]
}
],
"source": [
"project.experiments.add_from_data_path(\n",
" name='hrpt',\n",
" data_path=data_path,\n",
" sample_form='powder',\n",
" beam_mode='constant wavelength',\n",
" radiation_probe='neutron',\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "16",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:58.738160Z",
"iopub.status.busy": "2026-06-30T22:28:58.737884Z",
"iopub.status.idle": "2026-06-30T22:28:58.741975Z",
"shell.execute_reply": "2026-06-30T22:28:58.741125Z"
}
},
"outputs": [],
"source": [
"experiment = project.experiments['hrpt']"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "17",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:58.743716Z",
"iopub.status.busy": "2026-06-30T22:28:58.743529Z",
"iopub.status.idle": "2026-06-30T22:28:58.746727Z",
"shell.execute_reply": "2026-06-30T22:28:58.745893Z"
}
},
"outputs": [],
"source": [
"experiment.instrument.setup_wavelength = 1.494\n",
"experiment.instrument.calib_twotheta_offset = 0.6"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "18",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:58.748509Z",
"iopub.status.busy": "2026-06-30T22:28:58.748256Z",
"iopub.status.idle": "2026-06-30T22:28:58.752624Z",
"shell.execute_reply": "2026-06-30T22:28:58.751837Z"
}
},
"outputs": [],
"source": [
"experiment.peak.broad_gauss_u = 0.1\n",
"experiment.peak.broad_gauss_v = -0.1\n",
"experiment.peak.broad_gauss_w = 0.1\n",
"experiment.peak.broad_lorentz_y = 0.1"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "19",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:58.754188Z",
"iopub.status.busy": "2026-06-30T22:28:58.754012Z",
"iopub.status.idle": "2026-06-30T22:28:58.757599Z",
"shell.execute_reply": "2026-06-30T22:28:58.756819Z"
}
},
"outputs": [],
"source": [
"experiment.excluded_regions.create(id='1', start=0, end=5)\n",
"experiment.excluded_regions.create(id='2', start=165, end=180)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "20",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:58.759266Z",
"iopub.status.busy": "2026-06-30T22:28:58.759084Z",
"iopub.status.idle": "2026-06-30T22:28:58.772990Z",
"shell.execute_reply": "2026-06-30T22:28:58.772022Z"
}
},
"outputs": [],
"source": [
"experiment.background.auto_estimate()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "21",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:58.774677Z",
"iopub.status.busy": "2026-06-30T22:28:58.774513Z",
"iopub.status.idle": "2026-06-30T22:28:58.778004Z",
"shell.execute_reply": "2026-06-30T22:28:58.777133Z"
}
},
"outputs": [],
"source": [
"experiment.linked_structures.create(structure_id='lbco', scale=10.0)"
]
},
{
"cell_type": "markdown",
"id": "22",
"metadata": {},
"source": [
"## π Perform Analysis"
]
},
{
"cell_type": "markdown",
"id": "23",
"metadata": {},
"source": [
"### Without Constraints"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "24",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:58.779572Z",
"iopub.status.busy": "2026-06-30T22:28:58.779406Z",
"iopub.status.idle": "2026-06-30T22:28:58.782956Z",
"shell.execute_reply": "2026-06-30T22:28:58.782201Z"
}
},
"outputs": [],
"source": [
"structure.cell.length_a.free = True\n",
"\n",
"structure.atom_sites['La'].adp_iso.free = True\n",
"structure.atom_sites['Ba'].adp_iso.free = True\n",
"structure.atom_sites['Co'].adp_iso.free = True\n",
"structure.atom_sites['O'].adp_iso.free = True"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "25",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:58.784802Z",
"iopub.status.busy": "2026-06-30T22:28:58.784636Z",
"iopub.status.idle": "2026-06-30T22:28:58.788975Z",
"shell.execute_reply": "2026-06-30T22:28:58.788038Z"
}
},
"outputs": [],
"source": [
"experiment.instrument.calib_twotheta_offset.free = True\n",
"\n",
"experiment.peak.broad_gauss_u.free = True\n",
"experiment.peak.broad_gauss_v.free = True\n",
"experiment.peak.broad_gauss_w.free = True\n",
"experiment.peak.broad_lorentz_y.free = True\n",
"\n",
"for point in experiment.background:\n",
" point.intensity.free = True\n",
"\n",
"experiment.linked_structures['lbco'].scale.free = True"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "26",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:28:58.790797Z",
"iopub.status.busy": "2026-06-30T22:28:58.790636Z",
"iopub.status.idle": "2026-06-30T22:29:08.194842Z",
"shell.execute_reply": "2026-06-30T22:29:08.193907Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-8a9413e9ce004761a7872fa1f9b34939-button');\n",
" const status = document.getElementById('ed-fit-stop-8a9413e9ce004761a7872fa1f9b34939-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.30 | 164.50 | |
|---|
| 2 | 28 | 1.30 | 31.70 | 80.7% β |
|---|
| 3 | 45 | 1.92 | 10.78 | 66.0% β |
|---|
| 4 | 63 | 2.77 | 7.96 | 26.2% β |
|---|
| 5 | 80 | 3.40 | 3.06 | 61.6% β |
|---|
| 6 | 98 | 4.09 | 2.04 | 33.1% β |
|---|
| 7 | 115 | 4.72 | 1.29 | 36.6% β |
|---|
| 8 | 133 | 5.36 | 1.27 | 2.2% β |
|---|
| 9 | 240 | 9.35 | 1.27 | |
|---|
"
],
"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.27\u001b[0m at iteration \u001b[1;36m239\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β
Fitting complete.\n"
]
}
],
"source": [
"project.analysis.fit()"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "27",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:29:08.196590Z",
"iopub.status.busy": "2026-06-30T22:29:08.196431Z",
"iopub.status.idle": "2026-06-30T22:29:08.730871Z",
"shell.execute_reply": "2026-06-30T22:29:08.729952Z"
}
},
"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) | 9.35 |
|---|
| 4 | π Iterations | 237 |
|---|
| 5 | π Goodness-of-fit (reduced ΟΒ²) | 1.27 |
|---|
| 6 | π R-factor (Rf, %) | 5.60 |
|---|
| 7 | π R-factor squared (RfΒ², %) | 5.23 |
|---|
| 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.4871 | 130.9297 | 2.59 % β |
|---|
| 3 | lbco | atom_site | Ba | adp_iso | Γ
Β² | 0.5000 | 0.4872 | 212.9911 | 2.57 % β |
|---|
| 4 | lbco | atom_site | Co | adp_iso | Γ
Β² | 0.5000 | 0.2619 | 0.0613 | 47.61 % β |
|---|
| 5 | lbco | atom_site | O | adp_iso | Γ
Β² | 0.5000 | 1.4090 | 0.0167 | 181.80 % β |
|---|
| 6 | hrpt | linked_structure | lbco | scale | | 10.0000 | 9.1342 | 0.0633 | 8.66 % β |
|---|
| 7 | hrpt | peak | | broad_gauss_u | degΒ² | 0.1000 | 0.0812 | 0.0031 | 18.80 % β |
|---|
| 8 | hrpt | peak | | broad_gauss_v | degΒ² | -0.1000 | -0.1146 | 0.0066 | 14.62 % β |
|---|
| 9 | hrpt | peak | | broad_gauss_w | degΒ² | 0.1000 | 0.1205 | 0.0032 | 20.52 % β |
|---|
| 10 | hrpt | peak | | broad_lorentz_y | deg | 0.1000 | 0.0833 | 0.0021 | 16.66 % β |
|---|
| 11 | hrpt | instrument | | twotheta_offset | deg | 0.6000 | 0.6225 | 0.0010 | 3.75 % β |
|---|
| 12 | hrpt | background | 1 | intensity | | 167.0000 | 165.9356 | 0.8946 | 0.64 % β |
|---|
| 13 | hrpt | background | 2 | intensity | | 153.0000 | 167.5696 | 0.6934 | 9.52 % β |
|---|
| 14 | hrpt | background | 3 | intensity | | 164.4003 | 172.8384 | 0.7185 | 5.13 % β |
|---|
| 15 | hrpt | background | 4 | intensity | | 158.0000 | 181.0572 | 0.8783 | 14.59 % β |
|---|
| 16 | hrpt | background | 5 | intensity | | 109.0000 | 167.3818 | 1.2467 | 53.56 % β |
|---|
"
],
"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": [
"project.display.fit.results()"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "28",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:29:08.732590Z",
"iopub.status.busy": "2026-06-30T22:29:08.732409Z",
"iopub.status.idle": "2026-06-30T22:29:08.774780Z",
"shell.execute_reply": "2026-06-30T22:29:08.773933Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.fit.correlations()"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "29",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:29:08.776344Z",
"iopub.status.busy": "2026-06-30T22:29:08.776182Z",
"iopub.status.idle": "2026-06-30T22:29:08.842802Z",
"shell.execute_reply": "2026-06-30T22:29:08.842043Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='hrpt')"
]
},
{
"cell_type": "markdown",
"id": "30",
"metadata": {},
"source": [
"### With Constraints"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "31",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:29:08.849828Z",
"iopub.status.busy": "2026-06-30T22:29:08.849644Z",
"iopub.status.idle": "2026-06-30T22:29:08.855394Z",
"shell.execute_reply": "2026-06-30T22:29:08.854175Z"
}
},
"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": 25,
"id": "32",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:29:08.857049Z",
"iopub.status.busy": "2026-06-30T22:29:08.856887Z",
"iopub.status.idle": "2026-06-30T22:29:08.867350Z",
"shell.execute_reply": "2026-06-30T22:29:08.866600Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mMinimizer types\u001b[0m\n"
]
},
{
"data": {
"text/html": [
" | | Type | Description |
|---|
| 1 | | bumps | BUMPS library using the default Levenberg-Marquardt method |
|---|
| 2 | | bumps (amoeba) | BUMPS library with Nelder-Mead simplex method |
|---|
| 3 | | bumps (de) | BUMPS library with differential evolution method |
|---|
| 4 | | bumps (dream) | BUMPS library with DREAM Bayesian sampling |
|---|
| 5 | | bumps (lm) | BUMPS library with Levenberg-Marquardt method |
|---|
| 6 | | dfols | DFO-LS library for derivative-free least-squares optimization |
|---|
| 7 | | emcee | emcee affine-invariant ensemble Bayesian sampling |
|---|
| 8 | | lmfit | LMFIT library using the default Levenberg-Marquardt method |
|---|
| 9 | | lmfit (least_squares) | LMFIT library with SciPy's trust region reflective algorithm |
|---|
| 10 | * | lmfit (leastsq) | LMFIT library with Levenberg-Marquardt least squares method |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mCurrent minimizer changed to\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"lmfit\n"
]
}
],
"source": [
"project.analysis.minimizer.show_supported()\n",
"project.analysis.minimizer.type = 'lmfit'"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "33",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:29:08.869037Z",
"iopub.status.busy": "2026-06-30T22:29:08.868863Z",
"iopub.status.idle": "2026-06-30T22:29:09.704805Z",
"shell.execute_reply": "2026-06-30T22:29:09.704019Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-469009b9ca084c9793c556d4da36761d-button');\n",
" const status = document.getElementById('ed-fit-stop-469009b9ca084c9793c556d4da36761d-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.27 | |
|---|
| 2 | 20 | 0.78 | 1.27 | |
|---|
"
],
"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.27\u001b[0m at iteration \u001b[1;36m19\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β
Fitting complete.\n"
]
}
],
"source": [
"project.analysis.fit()"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "34",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:29:09.706324Z",
"iopub.status.busy": "2026-06-30T22:29:09.706167Z",
"iopub.status.idle": "2026-06-30T22:29:10.038711Z",
"shell.execute_reply": "2026-06-30T22:29:10.037892Z"
}
},
"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 |
|---|
| 2 | β
Overall status | success |
|---|
| 3 | β±οΈ Fitting time (seconds) | 0.78 |
|---|
| 4 | π Iterations | 17 |
|---|
| 5 | π Goodness-of-fit (reduced ΟΒ²) | 1.27 |
|---|
| 6 | π R-factor (Rf, %) | 5.60 |
|---|
| 7 | π R-factor squared (RfΒ², %) | 5.23 |
|---|
| 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.4871 | 0.4871 | 0.0275 | 0.01 % β |
|---|
| 3 | lbco | atom_site | Co | adp_iso | Γ
Β² | 0.2619 | 0.2619 | 0.0568 | 0.00 % β |
|---|
| 4 | lbco | atom_site | O | adp_iso | Γ
Β² | 1.4090 | 1.4090 | 0.0160 | 0.00 % β |
|---|
| 5 | hrpt | linked_structure | lbco | scale | | 9.1342 | 9.1342 | 0.0532 | 0.00 % β |
|---|
| 6 | hrpt | peak | | broad_gauss_u | degΒ² | 0.0812 | 0.0812 | 0.0031 | 0.00 % β |
|---|
| 7 | hrpt | peak | | broad_gauss_v | degΒ² | -0.1146 | -0.1146 | 0.0066 | 0.00 % β |
|---|
| 8 | hrpt | peak | | broad_gauss_w | degΒ² | 0.1205 | 0.1205 | 0.0032 | 0.00 % β |
|---|
| 9 | hrpt | peak | | broad_lorentz_y | deg | 0.0833 | 0.0833 | 0.0021 | 0.00 % β |
|---|
| 10 | hrpt | instrument | | twotheta_offset | deg | 0.6225 | 0.6225 | 0.0010 | 0.00 % β |
|---|
| 11 | hrpt | background | 1 | intensity | | 165.9356 | 165.9356 | 0.8942 | 0.00 % β |
|---|
| 12 | hrpt | background | 2 | intensity | | 167.5696 | 167.5696 | 0.6927 | 0.00 % β |
|---|
| 13 | hrpt | background | 3 | intensity | | 172.8384 | 172.8384 | 0.7123 | 0.00 % β |
|---|
| 14 | hrpt | background | 4 | intensity | | 181.0572 | 181.0572 | 0.8781 | 0.00 % β |
|---|
| 15 | hrpt | background | 5 | intensity | | 167.3818 | 167.3818 | 1.2311 | 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": [
"project.display.fit.results()"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "35",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:29:10.040346Z",
"iopub.status.busy": "2026-06-30T22:29:10.040177Z",
"iopub.status.idle": "2026-06-30T22:29:10.063443Z",
"shell.execute_reply": "2026-06-30T22:29:10.062717Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.fit.correlations()"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "36",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:29:10.065157Z",
"iopub.status.busy": "2026-06-30T22:29:10.064965Z",
"iopub.status.idle": "2026-06-30T22:29:10.133672Z",
"shell.execute_reply": "2026-06-30T22:29:10.132608Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='hrpt')"
]
},
{
"cell_type": "markdown",
"id": "37",
"metadata": {},
"source": [
"### Switch Calculator"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "38",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:29:10.137665Z",
"iopub.status.busy": "2026-06-30T22:29:10.137458Z",
"iopub.status.idle": "2026-06-30T22:29:10.144579Z",
"shell.execute_reply": "2026-06-30T22:29:10.143901Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mCalculator types\u001b[0m\n"
]
},
{
"data": {
"text/html": [
" | | Type | Description |
|---|
| 1 | | crysfml | CrysFML library for crystallographic calculations |
|---|
| 2 | * | cryspy | CrysPy library for crystallographic calculations |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"experiment.calculator.show_supported()"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "39",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:29:10.146454Z",
"iopub.status.busy": "2026-06-30T22:29:10.146267Z",
"iopub.status.idle": "2026-06-30T22:29:10.151646Z",
"shell.execute_reply": "2026-06-30T22:29:10.150969Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mCalculator for experiment \u001b[0m\u001b[32m'hrpt'\u001b[0m\u001b[1;36m changed to\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"crysfml\n"
]
}
],
"source": [
"experiment.calculator.type = 'crysfml'"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "40",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:29:10.153109Z",
"iopub.status.busy": "2026-06-30T22:29:10.152928Z",
"iopub.status.idle": "2026-06-30T22:29:12.478060Z",
"shell.execute_reply": "2026-06-30T22:29:12.477202Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-d951d4a1195c4cceb12c5f5edc84aadb-button');\n",
" const status = document.getElementById('ed-fit-stop-d951d4a1195c4cceb12c5f5edc84aadb-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.27 | |
|---|
| 2 | 60 | 2.28 | 1.26 | |
|---|
"
],
"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.26\u001b[0m at iteration \u001b[1;36m40\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β
Fitting complete.\n"
]
}
],
"source": [
"project.analysis.fit()"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "41",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:29:12.479634Z",
"iopub.status.busy": "2026-06-30T22:29:12.479426Z",
"iopub.status.idle": "2026-06-30T22:29:12.563286Z",
"shell.execute_reply": "2026-06-30T22:29:12.562789Z"
}
},
"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 |
|---|
| 2 | β
Overall status | success |
|---|
| 3 | β±οΈ Fitting time (seconds) | 2.28 |
|---|
| 4 | π Iterations | 57 |
|---|
| 5 | π Goodness-of-fit (reduced ΟΒ²) | 1.26 |
|---|
| 6 | π R-factor (Rf, %) | 5.57 |
|---|
| 7 | π R-factor squared (RfΒ², %) | 5.22 |
|---|
| 8 | π Weighted R-factor (wR, %) | 4.39 |
|---|
"
],
"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.8908 | 0.0000 | 0.00 % β |
|---|
| 2 | lbco | atom_site | La | adp_iso | Γ
Β² | 0.4871 | 0.4765 | 0.0227 | 2.17 % β |
|---|
| 3 | lbco | atom_site | Co | adp_iso | Γ
Β² | 0.2619 | 0.2873 | 0.0481 | 9.68 % β |
|---|
| 4 | lbco | atom_site | O | adp_iso | Γ
Β² | 1.4090 | 1.4120 | 0.0155 | 0.21 % β |
|---|
| 5 | hrpt | linked_structure | lbco | scale | | 9.1342 | 9.1280 | 0.0508 | 0.07 % β |
|---|
| 6 | hrpt | peak | | broad_gauss_u | degΒ² | 0.0812 | 0.0837 | 0.0020 | 3.06 % β |
|---|
| 7 | hrpt | peak | | broad_gauss_v | degΒ² | -0.1146 | -0.1198 | 0.0037 | 4.55 % β |
|---|
| 8 | hrpt | peak | | broad_gauss_w | degΒ² | 0.1205 | 0.1230 | 0.0027 | 2.03 % β |
|---|
| 9 | hrpt | peak | | broad_lorentz_y | deg | 0.0833 | 0.0827 | 0.0020 | 0.74 % β |
|---|
| 10 | hrpt | instrument | | twotheta_offset | deg | 0.6225 | 0.6199 | 0.0009 | 0.41 % β |
|---|
| 11 | hrpt | background | 1 | intensity | | 165.9356 | 166.8983 | 0.8922 | 0.58 % β |
|---|
| 12 | hrpt | background | 2 | intensity | | 167.5696 | 167.7980 | 0.6849 | 0.14 % β |
|---|
| 13 | hrpt | background | 3 | intensity | | 172.8384 | 172.7761 | 0.7101 | 0.04 % β |
|---|
| 14 | hrpt | background | 4 | intensity | | 181.0572 | 181.1597 | 0.8672 | 0.06 % β |
|---|
| 15 | hrpt | background | 5 | intensity | | 167.3818 | 162.7919 | 1.2358 | 2.74 % β |
|---|
"
],
"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": [
"project.display.fit.results()"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "42",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:29:12.565076Z",
"iopub.status.busy": "2026-06-30T22:29:12.564898Z",
"iopub.status.idle": "2026-06-30T22:29:12.588528Z",
"shell.execute_reply": "2026-06-30T22:29:12.587761Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.fit.correlations()"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "43",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:29:12.590369Z",
"iopub.status.busy": "2026-06-30T22:29:12.590178Z",
"iopub.status.idle": "2026-06-30T22:29:12.653168Z",
"shell.execute_reply": "2026-06-30T22:29:12.652395Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='hrpt')"
]
},
{
"cell_type": "markdown",
"id": "44",
"metadata": {},
"source": [
"## πΎ Save Project"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "45",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:29:12.658603Z",
"iopub.status.busy": "2026-06-30T22:29:12.658424Z",
"iopub.status.idle": "2026-06-30T22:29:12.986662Z",
"shell.execute_reply": "2026-06-30T22:29:12.985858Z"
}
},
"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-data'\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-data')"
]
}
],
"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
}