{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "0",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:27:42.733208Z",
"iopub.status.busy": "2026-06-30T22:27:42.732990Z",
"iopub.status.idle": "2026-06-30T22:27:42.737637Z",
"shell.execute_reply": "2026-06-30T22:27:42.736873Z"
},
"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: 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-06-30T22:27:42.739202Z",
"iopub.status.busy": "2026-06-30T22:27:42.739031Z",
"iopub.status.idle": "2026-06-30T22:27:45.722907Z",
"shell.execute_reply": "2026-06-30T22:27:45.721876Z"
}
},
"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-06-30T22:27:45.724648Z",
"iopub.status.busy": "2026-06-30T22:27:45.724375Z",
"iopub.status.idle": "2026-06-30T22:27:45.729217Z",
"shell.execute_reply": "2026-06-30T22:27:45.728448Z"
}
},
"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-06-30T22:27:45.730955Z",
"iopub.status.busy": "2026-06-30T22:27:45.730804Z",
"iopub.status.idle": "2026-06-30T22:27:45.733554Z",
"shell.execute_reply": "2026-06-30T22:27:45.732857Z"
}
},
"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-06-30T22:27:45.735281Z",
"iopub.status.busy": "2026-06-30T22:27:45.735122Z",
"iopub.status.idle": "2026-06-30T22:27:45.738381Z",
"shell.execute_reply": "2026-06-30T22:27:45.737730Z"
}
},
"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-06-30T22:27:45.739990Z",
"iopub.status.busy": "2026-06-30T22:27:45.739828Z",
"iopub.status.idle": "2026-06-30T22:27:45.747118Z",
"shell.execute_reply": "2026-06-30T22:27:45.746398Z"
}
},
"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-06-30T22:27:45.748485Z",
"iopub.status.busy": "2026-06-30T22:27:45.748333Z",
"iopub.status.idle": "2026-06-30T22:27:45.907807Z",
"shell.execute_reply": "2026-06-30T22:27:45.906875Z"
}
},
"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-06-30T22:27:45.909508Z",
"iopub.status.busy": "2026-06-30T22:27:45.909344Z",
"iopub.status.idle": "2026-06-30T22:27:46.418078Z",
"shell.execute_reply": "2026-06-30T22:27:46.417198Z"
}
},
"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-06-30T22:27:46.419731Z",
"iopub.status.busy": "2026-06-30T22:27:46.419555Z",
"iopub.status.idle": "2026-06-30T22:27:46.422659Z",
"shell.execute_reply": "2026-06-30T22:27:46.421855Z"
}
},
"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-06-30T22:27:46.424309Z",
"iopub.status.busy": "2026-06-30T22:27:46.424130Z",
"iopub.status.idle": "2026-06-30T22:27:46.434527Z",
"shell.execute_reply": "2026-06-30T22:27:46.433662Z"
}
},
"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-06-30T22:27:46.435992Z",
"iopub.status.busy": "2026-06-30T22:27:46.435820Z",
"iopub.status.idle": "2026-06-30T22:27:46.442890Z",
"shell.execute_reply": "2026-06-30T22:27:46.441876Z"
}
},
"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-06-30T22:27:46.444466Z",
"iopub.status.busy": "2026-06-30T22:27:46.444289Z",
"iopub.status.idle": "2026-06-30T22:27:46.447624Z",
"shell.execute_reply": "2026-06-30T22:27:46.446861Z"
}
},
"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-06-30T22:27:46.449484Z",
"iopub.status.busy": "2026-06-30T22:27:46.449313Z",
"iopub.status.idle": "2026-06-30T22:27:46.452066Z",
"shell.execute_reply": "2026-06-30T22:27:46.451473Z"
}
},
"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-06-30T22:27:46.453887Z",
"iopub.status.busy": "2026-06-30T22:27:46.453710Z",
"iopub.status.idle": "2026-06-30T22:27:46.475627Z",
"shell.execute_reply": "2026-06-30T22:27:46.474872Z"
}
},
"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-06-30T22:27:46.477730Z",
"iopub.status.busy": "2026-06-30T22:27:46.477537Z",
"iopub.status.idle": "2026-06-30T22:27:46.481238Z",
"shell.execute_reply": "2026-06-30T22:27:46.480516Z"
}
},
"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-06-30T22:27:46.482855Z",
"iopub.status.busy": "2026-06-30T22:27:46.482678Z",
"iopub.status.idle": "2026-06-30T22:27:46.734088Z",
"shell.execute_reply": "2026-06-30T22:27:46.733217Z"
}
},
"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-06-30T22:27:46.735943Z",
"iopub.status.busy": "2026-06-30T22:27:46.735556Z",
"iopub.status.idle": "2026-06-30T22:27:46.738932Z",
"shell.execute_reply": "2026-06-30T22:27:46.738103Z"
}
},
"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-06-30T22:27:46.740437Z",
"iopub.status.busy": "2026-06-30T22:27:46.740279Z",
"iopub.status.idle": "2026-06-30T22:27:46.742978Z",
"shell.execute_reply": "2026-06-30T22:27:46.742224Z"
}
},
"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-06-30T22:27:46.744488Z",
"iopub.status.busy": "2026-06-30T22:27:46.744339Z",
"iopub.status.idle": "2026-06-30T22:27:47.071227Z",
"shell.execute_reply": "2026-06-30T22:27:47.070319Z"
}
},
"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-06-30T22:27:47.073192Z",
"iopub.status.busy": "2026-06-30T22:27:47.072981Z",
"iopub.status.idle": "2026-06-30T22:27:47.558479Z",
"shell.execute_reply": "2026-06-30T22:27:47.556353Z"
}
},
"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-06-30T22:27:47.562896Z",
"iopub.status.busy": "2026-06-30T22:27:47.562706Z",
"iopub.status.idle": "2026-06-30T22:27:47.615291Z",
"shell.execute_reply": "2026-06-30T22:27:47.614388Z"
}
},
"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-06-30T22:27:47.617124Z",
"iopub.status.busy": "2026-06-30T22:27:47.616929Z",
"iopub.status.idle": "2026-06-30T22:27:47.620893Z",
"shell.execute_reply": "2026-06-30T22:27:47.619891Z"
}
},
"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-06-30T22:27:47.622456Z",
"iopub.status.busy": "2026-06-30T22:27:47.622280Z",
"iopub.status.idle": "2026-06-30T22:27:47.733998Z",
"shell.execute_reply": "2026-06-30T22:27:47.732185Z"
}
},
"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-06-30T22:27:47.735607Z",
"iopub.status.busy": "2026-06-30T22:27:47.735414Z",
"iopub.status.idle": "2026-06-30T22:27:54.497789Z",
"shell.execute_reply": "2026-06-30T22:27:54.496749Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-9ce22983b34142b5835ce63316d9bd51-button');\n",
" const status = document.getElementById('ed-fit-stop-9ce22983b34142b5835ce63316d9bd51-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.38 | 60.12 | 71.4% ↓ |
|---|
| 3 | 13 | 0.85 | 55.45 | 7.8% ↓ |
|---|
| 4 | 18 | 1.12 | 51.96 | 6.3% ↓ |
|---|
| 5 | 23 | 1.36 | 49.78 | 4.2% ↓ |
|---|
| 6 | 28 | 1.60 | 48.53 | 2.5% ↓ |
|---|
| 7 | 33 | 2.09 | 47.85 | 1.4% ↓ |
|---|
| 8 | 43 | 2.60 | 47.31 | 1.1% ↓ |
|---|
| 9 | 110 | 6.68 | 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-06-30T22:27:54.499799Z",
"iopub.status.busy": "2026-06-30T22:27:54.499492Z",
"iopub.status.idle": "2026-06-30T22:27:54.966848Z",
"shell.execute_reply": "2026-06-30T22:27:54.965987Z"
}
},
"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.68 |
|---|
| 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-06-30T22:27:54.968507Z",
"iopub.status.busy": "2026-06-30T22:27:54.968323Z",
"iopub.status.idle": "2026-06-30T22:27:55.035567Z",
"shell.execute_reply": "2026-06-30T22:27:55.034533Z"
}
},
"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-06-30T22:27:55.040218Z",
"iopub.status.busy": "2026-06-30T22:27:55.040022Z",
"iopub.status.idle": "2026-06-30T22:27:55.092906Z",
"shell.execute_reply": "2026-06-30T22:27:55.092075Z"
}
},
"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-06-30T22:27:55.094769Z",
"iopub.status.busy": "2026-06-30T22:27:55.094596Z",
"iopub.status.idle": "2026-06-30T22:27:55.098698Z",
"shell.execute_reply": "2026-06-30T22:27:55.097596Z"
}
},
"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-06-30T22:27:55.100499Z",
"iopub.status.busy": "2026-06-30T22:27:55.100282Z",
"iopub.status.idle": "2026-06-30T22:27:55.200522Z",
"shell.execute_reply": "2026-06-30T22:27:55.199293Z"
}
},
"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-06-30T22:27:55.202062Z",
"iopub.status.busy": "2026-06-30T22:27:55.201896Z",
"iopub.status.idle": "2026-06-30T22:28:09.410859Z",
"shell.execute_reply": "2026-06-30T22:28:09.409909Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-4a91be41e8794ff4a8ecbfececd249b2-button');\n",
" const status = document.getElementById('ed-fit-stop-4a91be41e8794ff4a8ecbfececd249b2-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 | 47.35 | |
|---|
| 2 | 24 | 1.46 | 16.05 | 66.1% ↓ |
|---|
| 3 | 46 | 2.85 | 14.94 | 6.9% ↓ |
|---|
| 4 | 67 | 4.18 | 13.01 | 12.9% ↓ |
|---|
| 5 | 148 | 9.36 | 12.92 | |
|---|
| 6 | 224 | 14.13 | 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-06-30T22:28:09.412639Z",
"iopub.status.busy": "2026-06-30T22:28:09.412483Z",
"iopub.status.idle": "2026-06-30T22:28:09.870600Z",
"shell.execute_reply": "2026-06-30T22:28:09.869982Z"
}
},
"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) | 14.13 |
|---|
| 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-06-30T22:28:09.872439Z",
"iopub.status.busy": "2026-06-30T22:28:09.872254Z",
"iopub.status.idle": "2026-06-30T22:28:09.933624Z",
"shell.execute_reply": "2026-06-30T22:28:09.932798Z"
}
},
"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-06-30T22:28:09.936706Z",
"iopub.status.busy": "2026-06-30T22:28:09.936530Z",
"iopub.status.idle": "2026-06-30T22:28:09.988879Z",
"shell.execute_reply": "2026-06-30T22:28:09.988021Z"
}
},
"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-06-30T22:28:09.990549Z",
"iopub.status.busy": "2026-06-30T22:28:09.990369Z",
"iopub.status.idle": "2026-06-30T22:28:09.993567Z",
"shell.execute_reply": "2026-06-30T22:28:09.992901Z"
}
},
"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-06-30T22:28:09.995105Z",
"iopub.status.busy": "2026-06-30T22:28:09.994924Z",
"iopub.status.idle": "2026-06-30T22:28:10.093478Z",
"shell.execute_reply": "2026-06-30T22:28:10.092679Z"
}
},
"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-06-30T22:28:10.095497Z",
"iopub.status.busy": "2026-06-30T22:28:10.095342Z",
"iopub.status.idle": "2026-06-30T22:28:25.704682Z",
"shell.execute_reply": "2026-06-30T22:28:25.703553Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-8719f06718dd41b5940d7bfb72cf559b-button');\n",
" const status = document.getElementById('ed-fit-stop-8719f06718dd41b5940d7bfb72cf559b-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.07 | 12.94 | |
|---|
| 2 | 29 | 1.78 | 5.20 | 59.8% ↓ |
|---|
| 3 | 55 | 3.34 | 4.95 | 4.7% ↓ |
|---|
| 4 | 133 | 8.34 | 4.95 | |
|---|
| 5 | 217 | 13.37 | 4.95 | |
|---|
| 6 | 246 | 15.52 | 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-06-30T22:28:25.706471Z",
"iopub.status.busy": "2026-06-30T22:28:25.706238Z",
"iopub.status.idle": "2026-06-30T22:28:26.189390Z",
"shell.execute_reply": "2026-06-30T22:28:26.188577Z"
}
},
"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.52 |
|---|
| 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-06-30T22:28:26.190941Z",
"iopub.status.busy": "2026-06-30T22:28:26.190786Z",
"iopub.status.idle": "2026-06-30T22:28:26.253639Z",
"shell.execute_reply": "2026-06-30T22:28:26.252903Z"
}
},
"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-06-30T22:28:26.256323Z",
"iopub.status.busy": "2026-06-30T22:28:26.256160Z",
"iopub.status.idle": "2026-06-30T22:28:26.309262Z",
"shell.execute_reply": "2026-06-30T22:28:26.308146Z"
}
},
"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-06-30T22:28:26.311005Z",
"iopub.status.busy": "2026-06-30T22:28:26.310828Z",
"iopub.status.idle": "2026-06-30T22:28:26.315977Z",
"shell.execute_reply": "2026-06-30T22:28:26.315083Z"
}
},
"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-06-30T22:28:26.318040Z",
"iopub.status.busy": "2026-06-30T22:28:26.317287Z",
"iopub.status.idle": "2026-06-30T22:28:26.439420Z",
"shell.execute_reply": "2026-06-30T22:28:26.438667Z"
}
},
"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-06-30T22:28:26.441000Z",
"iopub.status.busy": "2026-06-30T22:28:26.440815Z",
"iopub.status.idle": "2026-06-30T22:28:51.202303Z",
"shell.execute_reply": "2026-06-30T22:28:51.201554Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-d8c038898c2e4342af075dd26f9e4dae-button');\n",
" const status = document.getElementById('ed-fit-stop-d8c038898c2e4342af075dd26f9e4dae-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.44 | 2.15 | 56.6% ↓ |
|---|
| 3 | 73 | 4.42 | 1.95 | 9.1% ↓ |
|---|
| 4 | 153 | 9.44 | 1.95 | |
|---|
| 5 | 236 | 14.48 | 1.95 | |
|---|
| 6 | 317 | 19.50 | 1.95 | |
|---|
| 7 | 395 | 24.66 | 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-06-30T22:28:51.204123Z",
"iopub.status.busy": "2026-06-30T22:28:51.203942Z",
"iopub.status.idle": "2026-06-30T22:28:51.652781Z",
"shell.execute_reply": "2026-06-30T22:28:51.652021Z"
}
},
"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) | 24.66 |
|---|
| 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-06-30T22:28:51.654831Z",
"iopub.status.busy": "2026-06-30T22:28:51.654656Z",
"iopub.status.idle": "2026-06-30T22:28:51.683468Z",
"shell.execute_reply": "2026-06-30T22:28:51.682225Z"
}
},
"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-06-30T22:28:51.685927Z",
"iopub.status.busy": "2026-06-30T22:28:51.685738Z",
"iopub.status.idle": "2026-06-30T22:28:51.746759Z",
"shell.execute_reply": "2026-06-30T22:28:51.745924Z"
}
},
"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-06-30T22:28:51.751530Z",
"iopub.status.busy": "2026-06-30T22:28:51.751337Z",
"iopub.status.idle": "2026-06-30T22:28:52.060357Z",
"shell.execute_reply": "2026-06-30T22:28:52.059426Z"
}
},
"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-06-30T22:28:52.062357Z",
"iopub.status.busy": "2026-06-30T22:28:52.062160Z",
"iopub.status.idle": "2026-06-30T22:28:52.423637Z",
"shell.execute_reply": "2026-06-30T22:28:52.422403Z"
}
},
"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"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"├── 📁 structures/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"│ └── 📄 hs.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": [
" └── 📄 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.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}