{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "0",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:24.625829Z",
"iopub.status.busy": "2026-08-18T18:28:24.625632Z",
"iopub.status.idle": "2026-08-18T18:28:24.629711Z",
"shell.execute_reply": "2026-08-18T18:28:24.629002Z"
},
"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.20.1"
]
},
{
"cell_type": "markdown",
"id": "1",
"metadata": {},
"source": [
"# Structure Refinement: HS, HRPT\n",
"\n",
"This example demonstrates a Rietveld refinement of HS crystal\n",
"structure using constant wavelength neutron powder diffraction data\n",
"from HRPT at PSI."
]
},
{
"cell_type": "markdown",
"id": "2",
"metadata": {},
"source": [
"## 🛠️ Import Library"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:24.631187Z",
"iopub.status.busy": "2026-08-18T18:28:24.631025Z",
"iopub.status.idle": "2026-08-18T18:28:27.622985Z",
"shell.execute_reply": "2026-08-18T18:28:27.622113Z"
}
},
"outputs": [],
"source": [
"from easydiffraction import ExperimentFactory\n",
"from easydiffraction import Project\n",
"from easydiffraction import StructureFactory\n",
"from easydiffraction import download_data"
]
},
{
"cell_type": "markdown",
"id": "4",
"metadata": {},
"source": [
"## 🧩 Define Structure\n",
"\n",
"This section shows how to add structures and modify their\n",
"parameters.\n",
"\n",
"### Create Structure"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:27.625509Z",
"iopub.status.busy": "2026-08-18T18:28:27.625159Z",
"iopub.status.idle": "2026-08-18T18:28:27.630778Z",
"shell.execute_reply": "2026-08-18T18:28:27.630085Z"
}
},
"outputs": [],
"source": [
"structure = StructureFactory.from_scratch(name='hs')"
]
},
{
"cell_type": "markdown",
"id": "6",
"metadata": {},
"source": [
"### Set Space Group"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "7",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:27.632445Z",
"iopub.status.busy": "2026-08-18T18:28:27.632298Z",
"iopub.status.idle": "2026-08-18T18:28:27.635402Z",
"shell.execute_reply": "2026-08-18T18:28:27.634874Z"
}
},
"outputs": [],
"source": [
"structure.space_group.name_h_m = 'R -3 m'\n",
"structure.space_group.coord_system_code = 'h'"
]
},
{
"cell_type": "markdown",
"id": "8",
"metadata": {
"lines_to_next_cell": 2
},
"source": [
"### Set Unit Cell"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "9",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:27.637091Z",
"iopub.status.busy": "2026-08-18T18:28:27.636936Z",
"iopub.status.idle": "2026-08-18T18:28:27.639574Z",
"shell.execute_reply": "2026-08-18T18:28:27.638929Z"
}
},
"outputs": [],
"source": [
"structure.cell.length_a = 6.85\n",
"structure.cell.length_c = 14.1"
]
},
{
"cell_type": "markdown",
"id": "10",
"metadata": {},
"source": [
"### Set Atom Sites"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "11",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:27.641214Z",
"iopub.status.busy": "2026-08-18T18:28:27.641045Z",
"iopub.status.idle": "2026-08-18T18:28:27.648147Z",
"shell.execute_reply": "2026-08-18T18:28:27.647479Z"
}
},
"outputs": [],
"source": [
"structure.atom_sites.create(\n",
" id='Zn',\n",
" type_symbol='Zn',\n",
" fract_x=0,\n",
" fract_y=0,\n",
" fract_z=0.5,\n",
" adp_iso=0.5,\n",
")\n",
"structure.atom_sites.create(\n",
" id='Cu',\n",
" type_symbol='Cu',\n",
" fract_x=0.5,\n",
" fract_y=0,\n",
" fract_z=0,\n",
" adp_iso=0.5,\n",
")\n",
"structure.atom_sites.create(\n",
" id='O',\n",
" type_symbol='O',\n",
" fract_x=0.21,\n",
" fract_y=-0.21,\n",
" fract_z=0.06,\n",
" adp_iso=0.5,\n",
")\n",
"structure.atom_sites.create(\n",
" id='Cl',\n",
" type_symbol='Cl',\n",
" fract_x=0,\n",
" fract_y=0,\n",
" fract_z=0.197,\n",
" adp_iso=0.5,\n",
")\n",
"structure.atom_sites.create(\n",
" id='H',\n",
" type_symbol='2H',\n",
" fract_x=0.13,\n",
" fract_y=-0.13,\n",
" fract_z=0.08,\n",
" adp_iso=0.5,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "12",
"metadata": {},
"source": [
"## 🔬 Define Experiment\n",
"\n",
"This section shows how to add experiments, configure their parameters,\n",
"and link the structures defined in the previous step.\n",
"\n",
"### Download Data"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "13",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:27.649780Z",
"iopub.status.busy": "2026-08-18T18:28:27.649618Z",
"iopub.status.idle": "2026-08-18T18:28:27.851770Z",
"shell.execute_reply": "2026-08-18T18:28:27.848252Z"
}
},
"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-hs-hrpt'\u001b[0m: HS, HRPT \u001b[1m(\u001b[0mPSI\u001b[1m)\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Data \u001b[32m'meas-hs-hrpt'\u001b[0m downloaded to \u001b[32m'../../../data/meas-hs-hrpt.xye'\u001b[0m\n"
]
}
],
"source": [
"data_path = download_data('meas-hs-hrpt', destination='data')"
]
},
{
"cell_type": "markdown",
"id": "14",
"metadata": {},
"source": [
"### Create Experiment"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "15",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:27.853827Z",
"iopub.status.busy": "2026-08-18T18:28:27.853532Z",
"iopub.status.idle": "2026-08-18T18:28:28.381330Z",
"shell.execute_reply": "2026-08-18T18:28:28.380372Z"
}
},
"outputs": [],
"source": [
"expt = ExperimentFactory.from_data_path(name='hrpt', data_path=data_path)"
]
},
{
"cell_type": "markdown",
"id": "16",
"metadata": {},
"source": [
"### Set Instrument"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "17",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:28.383381Z",
"iopub.status.busy": "2026-08-18T18:28:28.383214Z",
"iopub.status.idle": "2026-08-18T18:28:28.386166Z",
"shell.execute_reply": "2026-08-18T18:28:28.385493Z"
}
},
"outputs": [],
"source": [
"expt.instrument.setup_wavelength = 1.89\n",
"expt.instrument.calib_twotheta_offset = 0.0"
]
},
{
"cell_type": "markdown",
"id": "18",
"metadata": {},
"source": [
"### Set Peak Profile"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "19",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:28.387794Z",
"iopub.status.busy": "2026-08-18T18:28:28.387641Z",
"iopub.status.idle": "2026-08-18T18:28:28.396577Z",
"shell.execute_reply": "2026-08-18T18:28:28.395885Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mPeak types\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"
| | Type | Description |
|---|
| 1 | * | pseudo-voigt | CWL pseudo-Voigt profile |
|---|
| 2 | | pseudo-voigt + berar-baldinozzi asymmetry | CWL pseudo-Voigt profile with Berar-Baldinozzi asymmetry correction. |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"expt.peak.show_supported()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "20",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:28.398209Z",
"iopub.status.busy": "2026-08-18T18:28:28.398052Z",
"iopub.status.idle": "2026-08-18T18:28:28.404279Z",
"shell.execute_reply": "2026-08-18T18:28:28.403602Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"⚠️ Switching peak profile type adds these settings with defaults: \n",
" • asym_beba_a0=0.0 \n",
" • asym_beba_a1=0.0 \n",
" • asym_beba_b0=0.0 \n",
" • asym_beba_b1=0.0 \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mPeak profile type for experiment \u001b[0m\u001b[32m'hrpt'\u001b[0m\u001b[1;36m changed to\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"pseudo-voigt + berar-baldinozzi asymmetry\n"
]
}
],
"source": [
"expt.peak.type = 'pseudo-voigt + berar-baldinozzi asymmetry'"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "21",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:28.405988Z",
"iopub.status.busy": "2026-08-18T18:28:28.405828Z",
"iopub.status.idle": "2026-08-18T18:28:28.409053Z",
"shell.execute_reply": "2026-08-18T18:28:28.408433Z"
}
},
"outputs": [],
"source": [
"expt.peak.broad_gauss_u = 0.1\n",
"expt.peak.broad_gauss_v = -0.2\n",
"expt.peak.broad_gauss_w = 0.2\n",
"expt.peak.broad_lorentz_y = 0"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "22",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:28.410757Z",
"iopub.status.busy": "2026-08-18T18:28:28.410601Z",
"iopub.status.idle": "2026-08-18T18:28:28.413092Z",
"shell.execute_reply": "2026-08-18T18:28:28.412441Z"
}
},
"outputs": [],
"source": [
"expt.peak.cutoff_fwhm = 8"
]
},
{
"cell_type": "markdown",
"id": "23",
"metadata": {},
"source": [
"### Set Background"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "24",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:28.414751Z",
"iopub.status.busy": "2026-08-18T18:28:28.414596Z",
"iopub.status.idle": "2026-08-18T18:28:28.442553Z",
"shell.execute_reply": "2026-08-18T18:28:28.441826Z"
}
},
"outputs": [],
"source": [
"expt.background.auto_estimate()"
]
},
{
"cell_type": "markdown",
"id": "25",
"metadata": {},
"source": [
"### Set Linked Structures"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "26",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:28.444326Z",
"iopub.status.busy": "2026-08-18T18:28:28.444167Z",
"iopub.status.idle": "2026-08-18T18:28:28.446754Z",
"shell.execute_reply": "2026-08-18T18:28:28.446158Z"
}
},
"outputs": [],
"source": [
"expt.linked_structures.create(structure_id='hs', scale=0.5)"
]
},
{
"cell_type": "markdown",
"id": "27",
"metadata": {},
"source": [
"## 📦 Define Project\n",
"\n",
"The project object is used to manage the structure, experiment, and\n",
"analysis.\n",
"\n",
"### Create Project"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "28",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:28.448403Z",
"iopub.status.busy": "2026-08-18T18:28:28.448248Z",
"iopub.status.idle": "2026-08-18T18:28:28.742763Z",
"shell.execute_reply": "2026-08-18T18:28:28.742291Z"
}
},
"outputs": [],
"source": [
"project = Project(name='hs_hrpt')"
]
},
{
"cell_type": "markdown",
"id": "29",
"metadata": {},
"source": [
"### Add Structure"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "30",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:28.747914Z",
"iopub.status.busy": "2026-08-18T18:28:28.747737Z",
"iopub.status.idle": "2026-08-18T18:28:28.752382Z",
"shell.execute_reply": "2026-08-18T18:28:28.751586Z"
}
},
"outputs": [],
"source": [
"project.structures.add(structure)"
]
},
{
"cell_type": "markdown",
"id": "31",
"metadata": {},
"source": [
"### Add Experiment"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "32",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:28.753959Z",
"iopub.status.busy": "2026-08-18T18:28:28.753787Z",
"iopub.status.idle": "2026-08-18T18:28:28.757677Z",
"shell.execute_reply": "2026-08-18T18:28:28.757217Z"
}
},
"outputs": [],
"source": [
"project.experiments.add(expt)"
]
},
{
"cell_type": "markdown",
"id": "33",
"metadata": {},
"source": [
"## 🚀 Perform Analysis\n",
"\n",
"This section shows the analysis process, including how to set up\n",
"calculation and fitting engines.\n",
"\n",
"\n",
"### Display Structure"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "34",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:28.759653Z",
"iopub.status.busy": "2026-08-18T18:28:28.759483Z",
"iopub.status.idle": "2026-08-18T18:28:29.158374Z",
"shell.execute_reply": "2026-08-18T18:28:29.157825Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mStructure 🧩 \u001b[0m\u001b[32m'hs'\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='hs')"
]
},
{
"cell_type": "markdown",
"id": "35",
"metadata": {},
"source": [
"### Display Pattern"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "36",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:29.160032Z",
"iopub.status.busy": "2026-08-18T18:28:29.159863Z",
"iopub.status.idle": "2026-08-18T18:28:29.620863Z",
"shell.execute_reply": "2026-08-18T18:28:29.617857Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='hrpt')"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "37",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:29.625013Z",
"iopub.status.busy": "2026-08-18T18:28:29.624847Z",
"iopub.status.idle": "2026-08-18T18:28:29.673725Z",
"shell.execute_reply": "2026-08-18T18:28:29.672845Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)"
]
},
{
"cell_type": "markdown",
"id": "38",
"metadata": {},
"source": [
"### Perform Fit 1/4\n",
"\n",
"Set parameters to be refined."
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "39",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:29.675322Z",
"iopub.status.busy": "2026-08-18T18:28:29.675136Z",
"iopub.status.idle": "2026-08-18T18:28:29.678655Z",
"shell.execute_reply": "2026-08-18T18:28:29.677997Z"
}
},
"outputs": [],
"source": [
"structure.cell.length_a.free = True\n",
"structure.cell.length_c.free = True\n",
"\n",
"expt.linked_structures['hs'].scale.free = True\n",
"expt.instrument.calib_twotheta_offset.free = True"
]
},
{
"cell_type": "markdown",
"id": "40",
"metadata": {},
"source": [
"Show free parameters after selection."
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "41",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:29.680291Z",
"iopub.status.busy": "2026-08-18T18:28:29.680122Z",
"iopub.status.idle": "2026-08-18T18:28:29.779681Z",
"shell.execute_reply": "2026-08-18T18:28:29.779209Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mFree parameters for both structures \u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36m🧩 data blocks\u001b[0m\u001b[1;36m)\u001b[0m\u001b[1;36m and experiments \u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36m🔬 data blocks\u001b[0m\u001b[1;36m)\u001b[0m\n"
]
},
{
"data": {
"text/html": [
" | datablock | category | entry | parameter | value | uncertainty | min | max | units |
|---|
| 1 | hs | cell | | length_a | 6.85000 | | -inf | inf | Å |
|---|
| 2 | hs | cell | | length_c | 14.10000 | | -inf | inf | Å |
|---|
| 3 | hrpt | linked_structure | hs | scale | 0.50000 | | -inf | inf | |
|---|
| 4 | hrpt | instrument | | twotheta_offset | 0.00000 | | -inf | inf | deg |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.parameters.free()"
]
},
{
"cell_type": "markdown",
"id": "42",
"metadata": {},
"source": [
"#### Run Fitting"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "43",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:29.782883Z",
"iopub.status.busy": "2026-08-18T18:28:29.782704Z",
"iopub.status.idle": "2026-08-18T18:28:36.471528Z",
"shell.execute_reply": "2026-08-18T18:28:36.470947Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-e2b5aaefd3f145208381e07ab453d8c0-button');\n",
" const status = document.getElementById('ed-fit-stop-e2b5aaefd3f145208381e07ab453d8c0-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.05 | 210.23 | |
|---|
| 2 | 8 | 0.44 | 60.12 | 71.4% ↓ |
|---|
| 3 | 13 | 0.96 | 55.45 | 7.8% ↓ |
|---|
| 4 | 18 | 1.21 | 51.96 | 6.3% ↓ |
|---|
| 5 | 23 | 1.48 | 49.78 | 4.2% ↓ |
|---|
| 6 | 28 | 1.73 | 48.53 | 2.5% ↓ |
|---|
| 7 | 33 | 1.97 | 47.85 | 1.4% ↓ |
|---|
| 8 | 43 | 2.69 | 47.31 | 1.1% ↓ |
|---|
| 9 | 110 | 6.61 | 47.11 | |
|---|
"
],
"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;36m47.11\u001b[0m at iteration \u001b[1;36m80\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Fitting complete.\n"
]
}
],
"source": [
"project.analysis.fit()"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "44",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:36.474693Z",
"iopub.status.busy": "2026-08-18T18:28:36.474346Z",
"iopub.status.idle": "2026-08-18T18:28:36.893874Z",
"shell.execute_reply": "2026-08-18T18:28:36.893305Z"
}
},
"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) | 6.61 |
|---|
| 4 | 🔁 Iterations | 107 |
|---|
| 5 | 📏 Goodness-of-fit (reduced χ²) | 47.11 |
|---|
| 6 | 📏 R-factor (Rf, %) | 17.69 |
|---|
| 7 | 📏 R-factor squared (Rf², %) | 30.23 |
|---|
| 8 | 📏 Weighted R-factor (wR, %) | 31.10 |
|---|
"
],
"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 | hs | cell | | length_a | Å | 6.8500 | 6.8622 | 0.0003 | 0.18 % ↑ |
|---|
| 2 | hs | cell | | length_c | Å | 14.1000 | 14.1363 | 0.0008 | 0.26 % ↑ |
|---|
| 3 | hrpt | linked_structure | hs | scale | | 0.5000 | 0.2442 | 0.0029 | 51.16 % ↓ |
|---|
| 4 | hrpt | instrument | | twotheta_offset | deg | 0.0000 | 0.1258 | 0.0051 | N/A |
|---|
"
],
"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": "markdown",
"id": "45",
"metadata": {},
"source": [
"#### Display Pattern"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "46",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:36.897840Z",
"iopub.status.busy": "2026-08-18T18:28:36.897676Z",
"iopub.status.idle": "2026-08-18T18:28:36.963501Z",
"shell.execute_reply": "2026-08-18T18:28:36.962865Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='hrpt')"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "47",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:36.968031Z",
"iopub.status.busy": "2026-08-18T18:28:36.967855Z",
"iopub.status.idle": "2026-08-18T18:28:37.019009Z",
"shell.execute_reply": "2026-08-18T18:28:37.018171Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)"
]
},
{
"cell_type": "markdown",
"id": "48",
"metadata": {},
"source": [
"### Perform Fit 2/4\n",
"\n",
"Set more parameters to be refined."
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "49",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:37.020514Z",
"iopub.status.busy": "2026-08-18T18:28:37.020341Z",
"iopub.status.idle": "2026-08-18T18:28:37.023969Z",
"shell.execute_reply": "2026-08-18T18:28:37.023243Z"
}
},
"outputs": [],
"source": [
"expt.peak.broad_gauss_u.free = True\n",
"expt.peak.broad_gauss_v.free = True\n",
"expt.peak.broad_gauss_w.free = True\n",
"expt.peak.broad_lorentz_y.free = True\n",
"\n",
"for point in expt.background:\n",
" point.intensity.free = True"
]
},
{
"cell_type": "markdown",
"id": "50",
"metadata": {},
"source": [
"Show free parameters after selection."
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "51",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:37.025571Z",
"iopub.status.busy": "2026-08-18T18:28:37.025389Z",
"iopub.status.idle": "2026-08-18T18:28:37.108437Z",
"shell.execute_reply": "2026-08-18T18:28:37.107711Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mFree parameters for both structures \u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36m🧩 data blocks\u001b[0m\u001b[1;36m)\u001b[0m\u001b[1;36m and experiments \u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36m🔬 data blocks\u001b[0m\u001b[1;36m)\u001b[0m\n"
]
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.parameters.free()"
]
},
{
"cell_type": "markdown",
"id": "52",
"metadata": {},
"source": [
"#### Run Fitting"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "53",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:37.110219Z",
"iopub.status.busy": "2026-08-18T18:28:37.110063Z",
"iopub.status.idle": "2026-08-18T18:28:51.164753Z",
"shell.execute_reply": "2026-08-18T18:28:51.164081Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-62836cdaf8444d54931306ce7dfae104-button');\n",
" const status = document.getElementById('ed-fit-stop-62836cdaf8444d54931306ce7dfae104-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.05 | 47.35 | |
|---|
| 2 | 24 | 1.43 | 16.05 | 66.1% ↓ |
|---|
| 3 | 46 | 2.79 | 14.94 | 6.9% ↓ |
|---|
| 4 | 67 | 4.27 | 13.01 | 12.9% ↓ |
|---|
| 5 | 148 | 9.43 | 12.92 | |
|---|
| 6 | 224 | 13.97 | 12.92 | |
|---|
"
],
"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;36m12.92\u001b[0m at iteration \u001b[1;36m202\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Fitting complete.\n"
]
}
],
"source": [
"project.analysis.fit()"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "54",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:51.166932Z",
"iopub.status.busy": "2026-08-18T18:28:51.166770Z",
"iopub.status.idle": "2026-08-18T18:28:51.585631Z",
"shell.execute_reply": "2026-08-18T18:28:51.584956Z"
}
},
"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) | 13.97 |
|---|
| 4 | 🔁 Iterations | 221 |
|---|
| 5 | 📏 Goodness-of-fit (reduced χ²) | 12.92 |
|---|
| 6 | 📏 R-factor (Rf, %) | 9.89 |
|---|
| 7 | 📏 R-factor squared (Rf², %) | 13.86 |
|---|
| 8 | 📏 Weighted R-factor (wR, %) | 13.80 |
|---|
"
],
"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 | hs | cell | | length_a | Å | 6.8622 | 6.8626 | 0.0003 | 0.01 % ↑ |
|---|
| 2 | hs | cell | | length_c | Å | 14.1363 | 14.1392 | 0.0009 | 0.02 % ↑ |
|---|
| 3 | hrpt | linked_structure | hs | scale | | 0.2442 | 0.4162 | 0.0040 | 70.42 % ↑ |
|---|
| 4 | hrpt | peak | | broad_gauss_u | deg² | 0.1000 | 0.3458 | 0.0267 | 245.76 % ↑ |
|---|
| 5 | hrpt | peak | | broad_gauss_v | deg² | -0.2000 | -0.2479 | 0.0493 | 23.94 % ↑ |
|---|
| 6 | hrpt | peak | | broad_gauss_w | deg² | 0.2000 | 0.2127 | 0.0211 | 6.34 % ↑ |
|---|
| 7 | hrpt | peak | | broad_lorentz_y | deg | 0.0000 | 0.1574 | 0.0106 | N/A |
|---|
| 8 | hrpt | instrument | | twotheta_offset | deg | 0.1258 | 0.1272 | 0.0040 | 1.14 % ↑ |
|---|
| 9 | hrpt | background | 1 | intensity | | 645.0000 | 673.1075 | 20.0334 | 4.36 % ↑ |
|---|
| 10 | hrpt | background | 2 | intensity | | 460.0000 | 454.9251 | 6.2694 | 1.10 % ↓ |
|---|
| 11 | hrpt | background | 3 | intensity | | 451.0000 | 436.5423 | 6.1275 | 3.21 % ↓ |
|---|
| 12 | hrpt | background | 4 | intensity | | 616.7518 | 562.0722 | 13.6510 | 8.87 % ↓ |
|---|
| 13 | hrpt | background | 5 | intensity | | 451.0000 | 472.8034 | 7.6853 | 4.83 % ↑ |
|---|
| 14 | hrpt | background | 6 | intensity | | 522.4892 | 495.6934 | 5.4898 | 5.13 % ↓ |
|---|
| 15 | hrpt | background | 7 | intensity | | 497.0172 | 404.5708 | 5.2875 | 18.60 % ↓ |
|---|
| 16 | hrpt | background | 8 | intensity | | 613.1533 | 440.4542 | 10.4755 | 28.17 % ↓ |
|---|
| 17 | hrpt | background | 9 | intensity | | 657.1372 | 394.8575 | 11.4790 | 39.91 % ↓ |
|---|
| 18 | hrpt | background | 10 | intensity | | 573.0000 | 538.7733 | 8.9774 | 5.97 % ↓ |
|---|
| 19 | hrpt | background | 11 | intensity | | 514.0000 | 456.0360 | 8.4105 | 11.28 % ↓ |
|---|
| 20 | hrpt | background | 12 | intensity | | 538.1731 | 552.2311 | 14.7053 | 2.61 % ↑ |
|---|
"
],
"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": "markdown",
"id": "55",
"metadata": {},
"source": [
"#### Display Pattern"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "56",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:51.587552Z",
"iopub.status.busy": "2026-08-18T18:28:51.587369Z",
"iopub.status.idle": "2026-08-18T18:28:51.642921Z",
"shell.execute_reply": "2026-08-18T18:28:51.642250Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='hrpt')"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "57",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:51.647367Z",
"iopub.status.busy": "2026-08-18T18:28:51.647192Z",
"iopub.status.idle": "2026-08-18T18:28:51.697182Z",
"shell.execute_reply": "2026-08-18T18:28:51.696329Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)"
]
},
{
"cell_type": "markdown",
"id": "58",
"metadata": {},
"source": [
"### Perform Fit 3/4\n",
"\n",
"Set more parameters to be refined."
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "59",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:51.699138Z",
"iopub.status.busy": "2026-08-18T18:28:51.698905Z",
"iopub.status.idle": "2026-08-18T18:28:51.702903Z",
"shell.execute_reply": "2026-08-18T18:28:51.702173Z"
}
},
"outputs": [],
"source": [
"structure.atom_sites['O'].fract_x.free = True\n",
"structure.atom_sites['O'].fract_z.free = True\n",
"structure.atom_sites['Cl'].fract_z.free = True\n",
"structure.atom_sites['H'].fract_x.free = True\n",
"structure.atom_sites['H'].fract_z.free = True"
]
},
{
"cell_type": "markdown",
"id": "60",
"metadata": {},
"source": [
"Show free parameters after selection."
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "61",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:51.704436Z",
"iopub.status.busy": "2026-08-18T18:28:51.704267Z",
"iopub.status.idle": "2026-08-18T18:28:51.791039Z",
"shell.execute_reply": "2026-08-18T18:28:51.790250Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mFree parameters for both structures \u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36m🧩 data blocks\u001b[0m\u001b[1;36m)\u001b[0m\u001b[1;36m and experiments \u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36m🔬 data blocks\u001b[0m\u001b[1;36m)\u001b[0m\n"
]
},
{
"data": {
"text/html": [
" | datablock | category | entry | parameter | value | uncertainty | min | max | units |
|---|
| 1 | hs | cell | | length_a | 6.86260 | 0.00035 | -inf | inf | Å |
|---|
| 2 | hs | cell | | length_c | 14.13920 | 0.00093 | -inf | inf | Å |
|---|
| 3 | hs | atom_site | O | fract_x | 0.21000 | | -inf | inf | |
|---|
| 4 | hs | atom_site | O | fract_z | 0.06000 | | -inf | inf | |
|---|
| 5 | hs | atom_site | Cl | fract_z | 0.19700 | | -inf | inf | |
|---|
| 6 | hs | atom_site | H | fract_x | 0.13000 | | -inf | inf | |
|---|
| 7 | hs | atom_site | H | fract_z | 0.08000 | | -inf | inf | |
|---|
| 8 | hrpt | linked_structure | hs | scale | 0.41619 | 0.00400 | -inf | inf | |
|---|
| 9 | hrpt | peak | | broad_gauss_u | 0.34576 | 0.02672 | -inf | inf | deg² |
|---|
| 10 | hrpt | peak | | broad_gauss_v | -0.24788 | 0.04934 | -inf | inf | deg² |
|---|
| 11 | hrpt | peak | | broad_gauss_w | 0.21267 | 0.02110 | -inf | inf | deg² |
|---|
| 12 | hrpt | peak | | broad_lorentz_y | 0.15740 | 0.01058 | -inf | inf | deg |
|---|
| 13 | hrpt | instrument | | twotheta_offset | 0.12718 | 0.00396 | -inf | inf | deg |
|---|
| 14 | hrpt | background | 1 | intensity | 673.10753 | 20.03337 | -inf | inf | |
|---|
| 15 | hrpt | background | 2 | intensity | 454.92508 | 6.26943 | -inf | inf | |
|---|
| 16 | hrpt | background | 3 | intensity | 436.54232 | 6.12751 | -inf | inf | |
|---|
| 17 | hrpt | background | 4 | intensity | 562.07220 | 13.65100 | -inf | inf | |
|---|
| 18 | hrpt | background | 5 | intensity | 472.80337 | 7.68533 | -inf | inf | |
|---|
| 19 | hrpt | background | 6 | intensity | 495.69338 | 5.48976 | -inf | inf | |
|---|
| 20 | hrpt | background | 7 | intensity | 404.57081 | 5.28747 | -inf | inf | |
|---|
| 21 | hrpt | background | 8 | intensity | 440.45421 | 10.47549 | -inf | inf | |
|---|
| 22 | hrpt | background | 9 | intensity | 394.85751 | 11.47903 | -inf | inf | |
|---|
| 23 | hrpt | background | 10 | intensity | 538.77335 | 8.97740 | -inf | inf | |
|---|
| 24 | hrpt | background | 11 | intensity | 456.03599 | 8.41055 | -inf | inf | |
|---|
| 25 | hrpt | background | 12 | intensity | 552.23109 | 14.70527 | -inf | inf | |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.parameters.free()"
]
},
{
"cell_type": "markdown",
"id": "62",
"metadata": {},
"source": [
"#### Run Fitting"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "63",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:28:51.792864Z",
"iopub.status.busy": "2026-08-18T18:28:51.792705Z",
"iopub.status.idle": "2026-08-18T18:29:07.022958Z",
"shell.execute_reply": "2026-08-18T18:29:07.021971Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-c47b4a3a3b3b4a77b5656036a6fed0dd-button');\n",
" const status = document.getElementById('ed-fit-stop-c47b4a3a3b3b4a77b5656036a6fed0dd-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.06 | 12.94 | |
|---|
| 2 | 29 | 1.66 | 5.20 | 59.8% ↓ |
|---|
| 3 | 55 | 3.15 | 4.95 | 4.7% ↓ |
|---|
| 4 | 137 | 8.16 | 4.95 | |
|---|
| 5 | 217 | 13.23 | 4.95 | |
|---|
| 6 | 246 | 15.15 | 4.95 | |
|---|
"
],
"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;36m4.95\u001b[0m at iteration \u001b[1;36m178\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Fitting complete.\n"
]
}
],
"source": [
"project.analysis.fit()"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "64",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:29:07.024578Z",
"iopub.status.busy": "2026-08-18T18:29:07.024387Z",
"iopub.status.idle": "2026-08-18T18:29:07.504919Z",
"shell.execute_reply": "2026-08-18T18:29:07.504308Z"
}
},
"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) | 15.15 |
|---|
| 4 | 🔁 Iterations | 243 |
|---|
| 5 | 📏 Goodness-of-fit (reduced χ²) | 4.95 |
|---|
| 6 | 📏 R-factor (Rf, %) | 6.43 |
|---|
| 7 | 📏 R-factor squared (Rf², %) | 8.76 |
|---|
| 8 | 📏 Weighted R-factor (wR, %) | 8.89 |
|---|
"
],
"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 | hs | cell | | length_a | Å | 6.8626 | 6.8620 | 0.0002 | 0.01 % ↓ |
|---|
| 2 | hs | cell | | length_c | Å | 14.1392 | 14.1348 | 0.0005 | 0.03 % ↓ |
|---|
| 3 | hs | atom_site | O | fract_x | | 0.2100 | 0.2059 | 0.0002 | 1.94 % ↓ |
|---|
| 4 | hs | atom_site | O | fract_z | | 0.0600 | 0.0629 | 0.0002 | 4.75 % ↑ |
|---|
| 5 | hs | atom_site | Cl | fract_z | | 0.1970 | 0.1974 | 0.0002 | 0.20 % ↑ |
|---|
| 6 | hs | atom_site | H | fract_x | | 0.1300 | 0.1339 | 0.0002 | 3.01 % ↑ |
|---|
| 7 | hs | atom_site | H | fract_z | | 0.0800 | 0.0871 | 0.0001 | 8.89 % ↑ |
|---|
| 8 | hrpt | linked_structure | hs | scale | | 0.4162 | 0.3950 | 0.0023 | 5.09 % ↓ |
|---|
| 9 | hrpt | peak | | broad_gauss_u | deg² | 0.3458 | 0.3572 | 0.0140 | 3.30 % ↑ |
|---|
| 10 | hrpt | peak | | broad_gauss_v | deg² | -0.2479 | -0.3818 | 0.0268 | 54.01 % ↑ |
|---|
| 11 | hrpt | peak | | broad_gauss_w | deg² | 0.2127 | 0.2825 | 0.0125 | 32.86 % ↑ |
|---|
| 12 | hrpt | peak | | broad_lorentz_y | deg | 0.1574 | 0.1390 | 0.0062 | 11.68 % ↓ |
|---|
| 13 | hrpt | instrument | | twotheta_offset | deg | 0.1272 | 0.1148 | 0.0024 | 9.71 % ↓ |
|---|
| 14 | hrpt | background | 1 | intensity | | 673.1075 | 672.1313 | 12.3974 | 0.15 % ↓ |
|---|
| 15 | hrpt | background | 2 | intensity | | 454.9251 | 456.2819 | 3.8836 | 0.30 % ↑ |
|---|
| 16 | hrpt | background | 3 | intensity | | 436.5423 | 448.0780 | 3.7964 | 2.64 % ↑ |
|---|
| 17 | hrpt | background | 4 | intensity | | 562.0722 | 564.3133 | 8.4295 | 0.40 % ↑ |
|---|
| 18 | hrpt | background | 5 | intensity | | 472.8034 | 464.7443 | 4.7938 | 1.70 % ↓ |
|---|
| 19 | hrpt | background | 6 | intensity | | 495.6934 | 517.8974 | 3.3679 | 4.48 % ↑ |
|---|
| 20 | hrpt | background | 7 | intensity | | 404.5708 | 449.9013 | 3.2316 | 11.20 % ↑ |
|---|
| 21 | hrpt | background | 8 | intensity | | 440.4542 | 473.3742 | 6.7661 | 7.47 % ↑ |
|---|
| 22 | hrpt | background | 9 | intensity | | 394.8575 | 477.2343 | 8.0578 | 20.86 % ↑ |
|---|
| 23 | hrpt | background | 10 | intensity | | 538.7733 | 454.9376 | 6.0965 | 15.56 % ↓ |
|---|
| 24 | hrpt | background | 11 | intensity | | 456.0360 | 405.1224 | 5.6028 | 11.16 % ↓ |
|---|
| 25 | hrpt | background | 12 | intensity | | 552.2311 | 589.7398 | 9.2059 | 6.79 % ↑ |
|---|
"
],
"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": "markdown",
"id": "65",
"metadata": {},
"source": [
"#### Display Pattern"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "66",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:29:07.506714Z",
"iopub.status.busy": "2026-08-18T18:29:07.506551Z",
"iopub.status.idle": "2026-08-18T18:29:07.571292Z",
"shell.execute_reply": "2026-08-18T18:29:07.570882Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='hrpt')"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "67",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:29:07.581902Z",
"iopub.status.busy": "2026-08-18T18:29:07.581718Z",
"iopub.status.idle": "2026-08-18T18:29:07.643275Z",
"shell.execute_reply": "2026-08-18T18:29:07.642604Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)"
]
},
{
"cell_type": "markdown",
"id": "68",
"metadata": {},
"source": [
"### Perform Fit 4/4\n",
"\n",
"Set more parameters to be refined."
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "69",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:29:07.644738Z",
"iopub.status.busy": "2026-08-18T18:29:07.644567Z",
"iopub.status.idle": "2026-08-18T18:29:07.648294Z",
"shell.execute_reply": "2026-08-18T18:29:07.647654Z"
}
},
"outputs": [],
"source": [
"structure.atom_sites['Zn'].adp_iso.free = True\n",
"structure.atom_sites['Cu'].adp_iso.free = True\n",
"structure.atom_sites['O'].adp_iso.free = True\n",
"structure.atom_sites['Cl'].adp_iso.free = True\n",
"structure.atom_sites['H'].adp_iso.free = True\n",
"\n",
"expt.peak.asym_beba_a0.free = True\n",
"expt.peak.asym_beba_b0.free = True\n",
"expt.peak.asym_beba_a1.free = True\n",
"expt.peak.asym_beba_b1.free = True"
]
},
{
"cell_type": "markdown",
"id": "70",
"metadata": {},
"source": [
"Show free parameters after selection."
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "71",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:29:07.650041Z",
"iopub.status.busy": "2026-08-18T18:29:07.649862Z",
"iopub.status.idle": "2026-08-18T18:29:07.769508Z",
"shell.execute_reply": "2026-08-18T18:29:07.765200Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mFree parameters for both structures \u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36m🧩 data blocks\u001b[0m\u001b[1;36m)\u001b[0m\u001b[1;36m and experiments \u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36m🔬 data blocks\u001b[0m\u001b[1;36m)\u001b[0m\n"
]
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.parameters.free()"
]
},
{
"cell_type": "markdown",
"id": "72",
"metadata": {},
"source": [
"#### Run Fitting"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "73",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:29:07.771196Z",
"iopub.status.busy": "2026-08-18T18:29:07.771012Z",
"iopub.status.idle": "2026-08-18T18:29:33.582305Z",
"shell.execute_reply": "2026-08-18T18:29:33.581217Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-585777c990724acbb4a62206435da996-button');\n",
" const status = document.getElementById('ed-fit-stop-585777c990724acbb4a62206435da996-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.06 | 4.96 | |
|---|
| 2 | 38 | 2.67 | 2.15 | 56.6% ↓ |
|---|
| 3 | 73 | 4.90 | 1.95 | 9.1% ↓ |
|---|
| 4 | 149 | 10.25 | 1.95 | |
|---|
| 5 | 232 | 15.27 | 1.95 | |
|---|
| 6 | 312 | 20.29 | 1.95 | |
|---|
| 7 | 395 | 25.71 | 1.95 | |
|---|
"
],
"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.95\u001b[0m at iteration \u001b[1;36m373\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Fitting complete.\n"
]
}
],
"source": [
"project.analysis.fit()"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "74",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:29:33.584036Z",
"iopub.status.busy": "2026-08-18T18:29:33.583846Z",
"iopub.status.idle": "2026-08-18T18:29:34.041562Z",
"shell.execute_reply": "2026-08-18T18:29:34.040396Z"
}
},
"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) | 25.71 |
|---|
| 4 | 🔁 Iterations | 392 |
|---|
| 5 | 📏 Goodness-of-fit (reduced χ²) | 1.95 |
|---|
| 6 | 📏 R-factor (Rf, %) | 3.99 |
|---|
| 7 | 📏 R-factor squared (Rf², %) | 4.64 |
|---|
| 8 | 📏 Weighted R-factor (wR, %) | 4.14 |
|---|
"
],
"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 | hs | cell | | length_a | Å | 6.8620 | 6.8640 | 0.0004 | 0.03 % ↑ |
|---|
| 2 | hs | cell | | length_c | Å | 14.1348 | 14.1418 | 0.0010 | 0.05 % ↑ |
|---|
| 3 | hs | atom_site | Zn | adp_iso | Ų | 0.5000 | 0.1618 | 0.0609 | 67.65 % ↓ |
|---|
| 4 | hs | atom_site | Cu | adp_iso | Ų | 0.5000 | 1.4873 | 0.0380 | 197.46 % ↑ |
|---|
| 5 | hs | atom_site | O | fract_x | | 0.2059 | 0.2063 | 0.0002 | 0.16 % ↑ |
|---|
| 6 | hs | atom_site | O | fract_z | | 0.0629 | 0.0611 | 0.0001 | 2.85 % ↓ |
|---|
| 7 | hs | atom_site | O | adp_iso | Ų | 0.5000 | 1.0782 | 0.0377 | 115.64 % ↑ |
|---|
| 8 | hs | atom_site | Cl | fract_z | | 0.1974 | 0.1967 | 0.0001 | 0.34 % ↓ |
|---|
| 9 | hs | atom_site | Cl | adp_iso | Ų | 0.5000 | 1.4329 | 0.0380 | 186.58 % ↑ |
|---|
| 10 | hs | atom_site | H | fract_x | | 0.1339 | 0.1324 | 0.0002 | 1.15 % ↓ |
|---|
| 11 | hs | atom_site | H | fract_z | | 0.0871 | 0.0898 | 0.0001 | 3.12 % ↑ |
|---|
| 12 | hs | atom_site | H | adp_iso | Ų | 0.5000 | 2.4445 | 0.0430 | 388.90 % ↑ |
|---|
| 13 | hrpt | linked_structure | hs | scale | | 0.3950 | 0.5110 | 0.0026 | 29.37 % ↑ |
|---|
| 14 | hrpt | peak | | asym_beba_a0 | | 0.0000 | -0.1969 | 0.0258 | N/A |
|---|
| 15 | hrpt | peak | | asym_beba_b0 | | 0.0000 | -0.0474 | 0.0041 | N/A |
|---|
| 16 | hrpt | peak | | asym_beba_a1 | | 0.0000 | 0.1179 | 0.0591 | N/A |
|---|
| 17 | hrpt | peak | | asym_beba_b1 | | 0.0000 | 0.0553 | 0.0093 | N/A |
|---|
| 18 | hrpt | peak | | broad_gauss_u | deg² | 0.3572 | 0.2304 | 0.0075 | 35.50 % ↓ |
|---|
| 19 | hrpt | peak | | broad_gauss_v | deg² | -0.3818 | -0.2884 | 0.0113 | 24.45 % ↓ |
|---|
| 20 | hrpt | peak | | broad_gauss_w | deg² | 0.2825 | 0.2722 | 0.0032 | 3.65 % ↓ |
|---|
| 21 | hrpt | peak | | broad_lorentz_y | deg | 0.1390 | 0.1528 | 0.0031 | 9.90 % ↑ |
|---|
| 22 | hrpt | instrument | | twotheta_offset | deg | 0.1148 | 0.1461 | 0.0071 | 27.24 % ↑ |
|---|
| 23 | hrpt | background | 1 | intensity | | 672.1313 | 672.1970 | 7.7886 | 0.01 % ↑ |
|---|
| 24 | hrpt | background | 2 | intensity | | 456.2819 | 456.1904 | 2.4427 | 0.02 % ↓ |
|---|
| 25 | hrpt | background | 3 | intensity | | 448.0780 | 444.7383 | 2.3898 | 0.75 % ↓ |
|---|
| 26 | hrpt | background | 4 | intensity | | 564.3133 | 472.7138 | 5.6219 | 16.23 % ↓ |
|---|
| 27 | hrpt | background | 5 | intensity | | 464.7443 | 460.8542 | 3.0171 | 0.84 % ↓ |
|---|
| 28 | hrpt | background | 6 | intensity | | 517.8974 | 494.4704 | 2.0904 | 4.52 % ↓ |
|---|
| 29 | hrpt | background | 7 | intensity | | 449.9013 | 492.3397 | 2.0718 | 9.43 % ↑ |
|---|
| 30 | hrpt | background | 8 | intensity | | 473.3742 | 533.2086 | 4.4152 | 12.64 % ↑ |
|---|
| 31 | hrpt | background | 9 | intensity | | 477.2343 | 525.1618 | 5.2338 | 10.04 % ↑ |
|---|
| 32 | hrpt | background | 10 | intensity | | 454.9376 | 526.7387 | 3.9282 | 15.78 % ↑ |
|---|
| 33 | hrpt | background | 11 | intensity | | 405.1224 | 492.4487 | 3.6512 | 21.56 % ↑ |
|---|
| 34 | hrpt | background | 12 | intensity | | 589.7398 | 507.1961 | 6.6711 | 14.00 % ↓ |
|---|
"
],
"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": 44,
"id": "75",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:29:34.043076Z",
"iopub.status.busy": "2026-08-18T18:29:34.042907Z",
"iopub.status.idle": "2026-08-18T18:29:34.349304Z",
"shell.execute_reply": "2026-08-18T18:29:34.348310Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.fit.correlations()"
]
},
{
"cell_type": "markdown",
"id": "76",
"metadata": {},
"source": [
"#### Display Pattern"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "77",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:29:34.350896Z",
"iopub.status.busy": "2026-08-18T18:29:34.350719Z",
"iopub.status.idle": "2026-08-18T18:29:34.409990Z",
"shell.execute_reply": "2026-08-18T18:29:34.409103Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='hrpt')"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "78",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:29:34.413572Z",
"iopub.status.busy": "2026-08-18T18:29:34.413332Z",
"iopub.status.idle": "2026-08-18T18:29:34.466866Z",
"shell.execute_reply": "2026-08-18T18:29:34.466207Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='hrpt', x_min=48, x_max=51)"
]
},
{
"cell_type": "markdown",
"id": "79",
"metadata": {},
"source": [
"## 📊 Report\n",
"\n",
"The HTML report is written automatically when the project is saved;\n",
"enable `project.report.pdf` as well for a PDF version."
]
},
{
"cell_type": "markdown",
"id": "80",
"metadata": {},
"source": [
"## 💾 Save Project"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "81",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:29:34.468445Z",
"iopub.status.busy": "2026-08-18T18:29:34.468287Z",
"iopub.status.idle": "2026-08-18T18:29:34.805685Z",
"shell.execute_reply": "2026-08-18T18:29:34.804852Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mSaving project 📦 \u001b[0m\u001b[32m'hs_hrpt'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/refine-hs-hrpt'\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"├── 📄 project.edi\n",
"├── 📁 structures/\n",
"│ └── 📄 hs.edi\n",
"├── 📁 experiments/\n",
"│ └── 📄 hrpt.edi\n",
"├── 📁 analysis/\n",
"│ └── 📄 analysis.edi\n",
"└── 📁 reports/\n",
" └── 📄 hs_hrpt.html\n"
]
}
],
"source": [
"project.save_as(dir_path='projects/refine-hs-hrpt')"
]
}
],
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}