{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:39.353614Z", "iopub.status.busy": "2026-06-30T22:28:39.353400Z", "iopub.status.idle": "2026-06-30T22:28:39.357813Z", "shell.execute_reply": "2026-06-30T22:28:39.356917Z" }, "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: Si, SEPD\n", "\n", "This example demonstrates a Rietveld refinement of Si crystal\n", "structure using time-of-flight neutron powder diffraction data from\n", "SEPD at Argonne.\n", "\n", "It also shows how to switch calculation engine and peak profile type." ] }, { "cell_type": "markdown", "id": "2", "metadata": {}, "source": [ "## πŸ› οΈ Import Library" ] }, { "cell_type": "code", "execution_count": 2, "id": "3", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:39.359423Z", "iopub.status.busy": "2026-06-30T22:28:39.359228Z", "iopub.status.idle": "2026-06-30T22:28:42.172828Z", "shell.execute_reply": "2026-06-30T22:28:42.171857Z" } }, "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:28:42.174686Z", "iopub.status.busy": "2026-06-30T22:28:42.174391Z", "iopub.status.idle": "2026-06-30T22:28:42.179277Z", "shell.execute_reply": "2026-06-30T22:28:42.178530Z" } }, "outputs": [], "source": [ "structure = StructureFactory.from_scratch(name='si')" ] }, { "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:28:42.180908Z", "iopub.status.busy": "2026-06-30T22:28:42.180699Z", "iopub.status.idle": "2026-06-30T22:28:42.184371Z", "shell.execute_reply": "2026-06-30T22:28:42.183432Z" } }, "outputs": [], "source": [ "structure.space_group.name_h_m = 'F d -3 m'\n", "structure.space_group.coord_system_code = '2'" ] }, { "cell_type": "markdown", "id": "8", "metadata": {}, "source": [ "### Set Unit Cell" ] }, { "cell_type": "code", "execution_count": 5, "id": "9", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:42.186180Z", "iopub.status.busy": "2026-06-30T22:28:42.185952Z", "iopub.status.idle": "2026-06-30T22:28:42.189264Z", "shell.execute_reply": "2026-06-30T22:28:42.188400Z" } }, "outputs": [], "source": [ "structure.cell.length_a = 5.431" ] }, { "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:28:42.190737Z", "iopub.status.busy": "2026-06-30T22:28:42.190585Z", "iopub.status.idle": "2026-06-30T22:28:42.195408Z", "shell.execute_reply": "2026-06-30T22:28:42.194645Z" } }, "outputs": [], "source": [ "structure.atom_sites.create(\n", " id='Si',\n", " type_symbol='Si',\n", " fract_x=0.125,\n", " fract_y=0.125,\n", " fract_z=0.125,\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\n", "parameters, 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:28:42.196799Z", "iopub.status.busy": "2026-06-30T22:28:42.196651Z", "iopub.status.idle": "2026-06-30T22:28:42.208165Z", "shell.execute_reply": "2026-06-30T22:28:42.207297Z" } }, "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-si-sepd'\u001b[0m: Si, SEPD \u001b[1m(\u001b[0mArgonne\u001b[1m)\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "βœ… Data \u001b[32m'meas-si-sepd'\u001b[0m already present at \u001b[32m'../../../data/meas-si-sepd.xye'\u001b[0m. Keeping existing.\n" ] } ], "source": [ "data_path = download_data('meas-si-sepd', 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:28:42.209794Z", "iopub.status.busy": "2026-06-30T22:28:42.209639Z", "iopub.status.idle": "2026-06-30T22:28:42.888496Z", "shell.execute_reply": "2026-06-30T22:28:42.887112Z" } }, "outputs": [], "source": [ "expt = ExperimentFactory.from_data_path(\n", " name='sepd',\n", " data_path=data_path,\n", " beam_mode='time-of-flight',\n", ")" ] }, { "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:28:42.890300Z", "iopub.status.busy": "2026-06-30T22:28:42.890109Z", "iopub.status.idle": "2026-06-30T22:28:42.893657Z", "shell.execute_reply": "2026-06-30T22:28:42.892862Z" } }, "outputs": [], "source": [ "expt.instrument.setup_twotheta_bank = 144.845\n", "expt.instrument.calib_d_to_tof_offset = -10.0\n", "expt.instrument.calib_d_to_tof_linear = 7476.91\n", "expt.instrument.calib_d_to_tof_quadratic = -1.54" ] }, { "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:28:42.895265Z", "iopub.status.busy": "2026-06-30T22:28:42.895082Z", "iopub.status.idle": "2026-06-30T22:28:42.903951Z", "shell.execute_reply": "2026-06-30T22:28:42.903246Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mPeak types\u001b[0m\n" ] }, { "data": { "text/html": [ "
TypeDescription
1pseudo-voigtTOF non-convoluted pseudo-Voigt profile
2*jorgensenTOF Jorgensen profile: back-to-back exponentials βŠ— Gaussian
3jorgensen-von-dreeleTOF Jorgensen-Von Dreele profile: back-to-back exponentials βŠ— pseudo-Voigt
4double-jorgensen-von-dreeleTOF Double-Jorgensen-Von Dreele profile: double back-to-back exponentials βŠ— pseudo-Voigt (Z-Rietveld type0m)
" ], "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:28:42.905742Z", "iopub.status.busy": "2026-06-30T22:28:42.905582Z", "iopub.status.idle": "2026-06-30T22:28:42.912754Z", "shell.execute_reply": "2026-06-30T22:28:42.911965Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "⚠️ Switching peak profile type adds these settings with defaults: \n", " β€’ broad_lorentz_gamma_0=0.0 \n", " β€’ broad_lorentz_gamma_1=0.0 \n", " β€’ broad_lorentz_gamma_2=0.0 \n", " β€’ broad_lorentz_size_l=0.0 \n", " β€’ broad_lorentz_strain_l=0.0 \n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mPeak profile type for experiment \u001b[0m\u001b[32m'sepd'\u001b[0m\u001b[1;36m changed to\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "jorgensen-von-dreele\n" ] } ], "source": [ "expt.peak.type = 'jorgensen-von-dreele'" ] }, { "cell_type": "code", "execution_count": 12, "id": "21", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:42.914435Z", "iopub.status.busy": "2026-06-30T22:28:42.914266Z", "iopub.status.idle": "2026-06-30T22:28:42.918196Z", "shell.execute_reply": "2026-06-30T22:28:42.917479Z" } }, "outputs": [], "source": [ "expt.peak.broad_gauss_sigma_0 = 3.0148\n", "expt.peak.broad_gauss_sigma_1 = 33.3451\n", "expt.peak.broad_gauss_sigma_2 = 0.0\n", "expt.peak.broad_lorentz_gamma_0 = 0.0\n", "expt.peak.broad_lorentz_gamma_1 = 2.5489\n", "expt.peak.broad_lorentz_gamma_2 = 0.0\n", "expt.peak.rise_alpha_0 = 0.0\n", "expt.peak.rise_alpha_1 = 0.5971\n", "expt.peak.decay_beta_0 = 0.0408\n", "expt.peak.decay_beta_1 = 0.0123" ] }, { "cell_type": "code", "execution_count": 13, "id": "22", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:42.919990Z", "iopub.status.busy": "2026-06-30T22:28:42.919836Z", "iopub.status.idle": "2026-06-30T22:28:42.922786Z", "shell.execute_reply": "2026-06-30T22:28:42.921955Z" } }, "outputs": [], "source": [ "expt.peak.cutoff_fwhm = 8.2" ] }, { "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:28:42.924441Z", "iopub.status.busy": "2026-06-30T22:28:42.924225Z", "iopub.status.idle": "2026-06-30T22:28:42.960727Z", "shell.execute_reply": "2026-06-30T22:28:42.959855Z" } }, "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:28:42.962418Z", "iopub.status.busy": "2026-06-30T22:28:42.962253Z", "iopub.status.idle": "2026-06-30T22:28:42.965597Z", "shell.execute_reply": "2026-06-30T22:28:42.964606Z" } }, "outputs": [], "source": [ "expt.linked_structures.create(structure_id='si', scale=600.0)" ] }, { "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:28:42.967158Z", "iopub.status.busy": "2026-06-30T22:28:42.966981Z", "iopub.status.idle": "2026-06-30T22:28:43.175961Z", "shell.execute_reply": "2026-06-30T22:28:43.175128Z" } }, "outputs": [], "source": [ "project = Project(name='si_sepd')" ] }, { "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:28:43.177600Z", "iopub.status.busy": "2026-06-30T22:28:43.177435Z", "iopub.status.idle": "2026-06-30T22:28:43.180265Z", "shell.execute_reply": "2026-06-30T22:28:43.179462Z" } }, "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:28:43.181810Z", "iopub.status.busy": "2026-06-30T22:28:43.181655Z", "iopub.status.idle": "2026-06-30T22:28:43.184674Z", "shell.execute_reply": "2026-06-30T22:28:43.183772Z" } }, "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", "### Display Structure" ] }, { "cell_type": "code", "execution_count": 19, "id": "34", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:43.186064Z", "iopub.status.busy": "2026-06-30T22:28:43.185924Z", "iopub.status.idle": "2026-06-30T22:28:43.458166Z", "shell.execute_reply": "2026-06-30T22:28:43.457370Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mStructure 🧩 \u001b[0m\u001b[32m'si'\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='si')" ] }, { "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:28:43.459947Z", "iopub.status.busy": "2026-06-30T22:28:43.459788Z", "iopub.status.idle": "2026-06-30T22:28:44.392754Z", "shell.execute_reply": "2026-06-30T22:28:44.391771Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='sepd')\n", "project.display.pattern(expt_name='sepd', x_min=23200, x_max=23700)" ] }, { "cell_type": "markdown", "id": "37", "metadata": {}, "source": [ "### Perform Fit 1/4\n", "\n", "Set parameters to be refined." ] }, { "cell_type": "code", "execution_count": 21, "id": "38", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:44.394449Z", "iopub.status.busy": "2026-06-30T22:28:44.394291Z", "iopub.status.idle": "2026-06-30T22:28:44.397215Z", "shell.execute_reply": "2026-06-30T22:28:44.396545Z" } }, "outputs": [], "source": [ "structure.cell.length_a.free = True\n", "\n", "expt.linked_structures['si'].scale.free = True\n", "expt.instrument.calib_d_to_tof_offset.free = True" ] }, { "cell_type": "markdown", "id": "39", "metadata": {}, "source": [ "Show free parameters after selection." ] }, { "cell_type": "code", "execution_count": 22, "id": "40", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:44.398894Z", "iopub.status.busy": "2026-06-30T22:28:44.398732Z", "iopub.status.idle": "2026-06-30T22:28:44.450848Z", "shell.execute_reply": "2026-06-30T22:28:44.449943Z" } }, "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": [ "
datablockcategoryentryparametervalueuncertaintyminmaxunits
1sicelllength_a5.43100-infinfΓ…
2sepdlinked_structuresiscale600.00000-infinf
3sepdinstrumentd_to_tof_offset-10.00000-infinfΞΌs
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.parameters.free()" ] }, { "cell_type": "markdown", "id": "41", "metadata": {}, "source": [ "#### Run Fitting" ] }, { "cell_type": "code", "execution_count": 23, "id": "42", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:44.452731Z", "iopub.status.busy": "2026-06-30T22:28:44.452557Z", "iopub.status.idle": "2026-06-30T22:28:44.457921Z", "shell.execute_reply": "2026-06-30T22:28:44.457103Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mCurrent minimizer changed to\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "bumps \u001b[1m(\u001b[0mlm\u001b[1m)\u001b[0m\n" ] } ], "source": [ "project.analysis.minimizer.type = 'bumps (lm)'" ] }, { "cell_type": "code", "execution_count": 24, "id": "43", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:44.459504Z", "iopub.status.busy": "2026-06-30T22:28:44.459293Z", "iopub.status.idle": "2026-06-30T22:28:57.089388Z", "shell.execute_reply": "2026-06-30T22:28:57.088486Z" } }, "outputs": [ { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function() {\n", " const button = document.getElementById('ed-fit-stop-c260fee14bad4c84849e134b899e71fd-button');\n", " const status = document.getElementById('ed-fit-stop-c260fee14bad4c84849e134b899e71fd-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'sepd'\u001b[0m for \u001b[32m'single'\u001b[0m fitting\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "πŸš€ Starting fit process with \u001b[32m'bumps \u001b[0m\u001b[32m(\u001b[0m\u001b[32mlm\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": [ "
iterationtime (s)χ²change / status
110.329.20
251.856.9224.7% ↓
3227.746.92
42811.676.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;36m6.92\u001b[0m at iteration \u001b[1;36m28\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "βœ… Fitting complete.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "βš™οΈ Settings used:\n" ] }, { "data": { "text/html": [ "
NameValueDescription
1max_iterations1000Maximum solver iterations.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "πŸ“‹ Least-squares fit results:\n" ] }, { "data": { "text/html": [ "
MetricValue
1πŸ§ͺ Minimizerbumps (lm)
2βœ… Overall statussuccess
3⏱️ Fitting time (seconds)11.67
4πŸ“ Goodness-of-fit (reduced χ²)6.92
5πŸ“ R-factor (Rf, %)11.59
6πŸ“ R-factor squared (RfΒ², %)6.24
7πŸ“ Weighted R-factor (wR, %)5.16
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "πŸ“ˆ Refined parameters:\n" ] }, { "data": { "text/html": [ "
datablockcategoryentryparameterunitsstartvalues.u.change
1sicelllength_aΓ…5.43105.43080.00010.00 % ↓
2sepdlinked_structuresiscale600.0000609.60451.59391.60 % ↑
3sepdinstrumentd_to_tof_offsetΞΌs-10.0000-8.27000.076017.30 % ↓
" ], "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.analysis.fit()\n", "project.display.fit.results()" ] }, { "cell_type": "markdown", "id": "44", "metadata": {}, "source": [ "#### Display Pattern" ] }, { "cell_type": "code", "execution_count": 25, "id": "45", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:57.091107Z", "iopub.status.busy": "2026-06-30T22:28:57.090949Z", "iopub.status.idle": "2026-06-30T22:28:57.165439Z", "shell.execute_reply": "2026-06-30T22:28:57.164250Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='sepd')" ] }, { "cell_type": "code", "execution_count": 26, "id": "46", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:57.173246Z", "iopub.status.busy": "2026-06-30T22:28:57.173024Z", "iopub.status.idle": "2026-06-30T22:28:57.231823Z", "shell.execute_reply": "2026-06-30T22:28:57.230925Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='sepd', x_min=23200, x_max=23700)" ] }, { "cell_type": "markdown", "id": "47", "metadata": {}, "source": [ "### Perform Fit 2/4\n", "\n", "Set more parameters to be refined." ] }, { "cell_type": "code", "execution_count": 27, "id": "48", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:57.233278Z", "iopub.status.busy": "2026-06-30T22:28:57.233111Z", "iopub.status.idle": "2026-06-30T22:28:57.236157Z", "shell.execute_reply": "2026-06-30T22:28:57.235521Z" } }, "outputs": [], "source": [ "for point in expt.background:\n", " point.intensity.free = True" ] }, { "cell_type": "markdown", "id": "49", "metadata": {}, "source": [ "Show free parameters after selection." ] }, { "cell_type": "code", "execution_count": 28, "id": "50", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:57.238193Z", "iopub.status.busy": "2026-06-30T22:28:57.238016Z", "iopub.status.idle": "2026-06-30T22:28:57.301838Z", "shell.execute_reply": "2026-06-30T22:28:57.300934Z" } }, "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": [ "
datablockcategoryentryparametervalueuncertaintyminmaxunits
1sicelllength_a5.430790.00006-infinfΓ…
2sepdlinked_structuresiscale609.604491.59390-infinf
3sepdinstrumentd_to_tof_offset-8.269960.07596-infinfΞΌs
4sepdbackground1intensity213.55062-infinf
5sepdbackground2intensity117.61669-infinf
6sepdbackground3intensity147.70005-infinf
7sepdbackground4intensity122.26237-infinf
8sepdbackground5intensity163.04903-infinf
9sepdbackground6intensity124.58762-infinf
10sepdbackground7intensity120.30738-infinf
11sepdbackground8intensity186.02117-infinf
12sepdbackground9intensity133.38534-infinf
13sepdbackground10intensity108.60000-infinf
14sepdbackground11intensity139.80000-infinf
15sepdbackground12intensity272.05501-infinf
16sepdbackground13intensity114.09603-infinf
17sepdbackground14intensity177.06320-infinf
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.parameters.free()" ] }, { "cell_type": "markdown", "id": "51", "metadata": {}, "source": [ "#### Run Fitting" ] }, { "cell_type": "code", "execution_count": 29, "id": "52", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:28:57.303471Z", "iopub.status.busy": "2026-06-30T22:28:57.303319Z", "iopub.status.idle": "2026-06-30T22:29:25.827332Z", "shell.execute_reply": "2026-06-30T22:29:25.826401Z" } }, "outputs": [ { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function() {\n", " const button = document.getElementById('ed-fit-stop-7b54dd20d99f41b9a37aeb2224378cbd-button');\n", " const status = document.getElementById('ed-fit-stop-7b54dd20d99f41b9a37aeb2224378cbd-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'sepd'\u001b[0m for \u001b[32m'single'\u001b[0m fitting\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "πŸš€ Starting fit process with \u001b[32m'bumps \u001b[0m\u001b[32m(\u001b[0m\u001b[32mlm\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": [ "
iterationtime (s)χ²change / status
110.326.93
2196.733.7146.5% ↓
33713.213.71
45827.553.71
" ], "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;36m3.71\u001b[0m at iteration \u001b[1;36m58\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "βœ… Fitting complete.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "βš™οΈ Settings used:\n" ] }, { "data": { "text/html": [ "
NameValueDescription
1max_iterations1000Maximum solver iterations.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "πŸ“‹ Least-squares fit results:\n" ] }, { "data": { "text/html": [ "
MetricValue
1πŸ§ͺ Minimizerbumps (lm)
2βœ… Overall statussuccess
3⏱️ Fitting time (seconds)27.55
4πŸ“ Goodness-of-fit (reduced χ²)3.71
5πŸ“ R-factor (Rf, %)8.29
6πŸ“ R-factor squared (RfΒ², %)4.19
7πŸ“ Weighted R-factor (wR, %)3.12
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "πŸ“ˆ Refined parameters:\n" ] }, { "data": { "text/html": [ "
datablockcategoryentryparameterunitsstartvalues.u.change
1sicelllength_aΓ…5.43085.43090.00000.00 % ↑
2sepdlinked_structuresiscale609.6045627.65841.20452.96 % ↑
3sepdinstrumentd_to_tof_offsetΞΌs-8.2700-8.44350.05412.10 % ↑
4sepdbackground1intensity213.5506203.78500.41104.57 % ↓
5sepdbackground2intensity117.6167103.74390.446611.79 % ↓
6sepdbackground3intensity147.7001125.11650.872615.29 % ↓
7sepdbackground4intensity122.2624119.81610.96512.00 % ↓
8sepdbackground5intensity163.0490127.47772.742621.82 % ↓
9sepdbackground6intensity124.5876123.15581.68051.15 % ↓
10sepdbackground7intensity120.3074121.72571.76461.18 % ↑
11sepdbackground8intensity186.0212140.36093.271824.55 % ↓
12sepdbackground9intensity133.3853135.10652.44051.29 % ↑
13sepdbackground10intensity108.6000129.94351.342519.65 % ↑
14sepdbackground11intensity139.8000143.23052.14132.45 % ↑
15sepdbackground12intensity272.0550175.44444.725735.51 % ↓
16sepdbackground13intensity114.0960166.49575.127445.93 % ↑
17sepdbackground14intensity177.0632203.966110.818715.19 % ↑
" ], "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.analysis.fit()\n", "project.display.fit.results()" ] }, { "cell_type": "markdown", "id": "53", "metadata": {}, "source": [ "#### Display Pattern" ] }, { "cell_type": "code", "execution_count": 30, "id": "54", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:29:25.829110Z", "iopub.status.busy": "2026-06-30T22:29:25.828849Z", "iopub.status.idle": "2026-06-30T22:29:25.909134Z", "shell.execute_reply": "2026-06-30T22:29:25.908291Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='sepd')" ] }, { "cell_type": "code", "execution_count": 31, "id": "55", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:29:25.916862Z", "iopub.status.busy": "2026-06-30T22:29:25.916668Z", "iopub.status.idle": "2026-06-30T22:29:25.978900Z", "shell.execute_reply": "2026-06-30T22:29:25.978009Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='sepd', x_min=23200, x_max=23700)" ] }, { "cell_type": "markdown", "id": "56", "metadata": {}, "source": [ "### Perform Fit 3/4\n", "\n", "Fix background points." ] }, { "cell_type": "code", "execution_count": 32, "id": "57", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:29:25.980589Z", "iopub.status.busy": "2026-06-30T22:29:25.980413Z", "iopub.status.idle": "2026-06-30T22:29:25.984321Z", "shell.execute_reply": "2026-06-30T22:29:25.983539Z" } }, "outputs": [], "source": [ "for point in expt.background:\n", " point.intensity.free = False" ] }, { "cell_type": "markdown", "id": "58", "metadata": {}, "source": [ "Set more parameters to be refined." ] }, { "cell_type": "code", "execution_count": 33, "id": "59", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:29:25.985986Z", "iopub.status.busy": "2026-06-30T22:29:25.985779Z", "iopub.status.idle": "2026-06-30T22:29:25.989301Z", "shell.execute_reply": "2026-06-30T22:29:25.988555Z" } }, "outputs": [], "source": [ "expt.peak.broad_gauss_sigma_0.free = True\n", "expt.peak.broad_gauss_sigma_1.free = True\n", "expt.peak.broad_lorentz_gamma_1.free = True" ] }, { "cell_type": "markdown", "id": "60", "metadata": {}, "source": [ "Show free parameters after selection." ] }, { "cell_type": "code", "execution_count": 34, "id": "61", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:29:25.990785Z", "iopub.status.busy": "2026-06-30T22:29:25.990640Z", "iopub.status.idle": "2026-06-30T22:29:26.037670Z", "shell.execute_reply": "2026-06-30T22:29:26.036953Z" } }, "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": [ "
datablockcategoryentryparametervalueuncertaintyminmaxunits
1sicelllength_a5.430930.00004-infinfΓ…
2sepdlinked_structuresiscale627.658411.20447-infinf
3sepdpeakbroad_lorentz_gamma_12.54890-infinfΞΌs/Γ…
4sepdpeakbroad_gauss_sigma_03.01480-infinfΞΌsΒ²
5sepdpeakbroad_gauss_sigma_133.34510-infinfΞΌs/Γ…
6sepdinstrumentd_to_tof_offset-8.443470.05410-infinfΞΌs
" ], "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": 35, "id": "63", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:29:26.039569Z", "iopub.status.busy": "2026-06-30T22:29:26.039391Z", "iopub.status.idle": "2026-06-30T22:29:46.941322Z", "shell.execute_reply": "2026-06-30T22:29:46.940083Z" } }, "outputs": [ { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function() {\n", " const button = document.getElementById('ed-fit-stop-5d86258f88c94150a98805e39d5c32ef-button');\n", " const status = document.getElementById('ed-fit-stop-5d86258f88c94150a98805e39d5c32ef-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'sepd'\u001b[0m for \u001b[32m'single'\u001b[0m fitting\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "πŸš€ Starting fit process with \u001b[32m'bumps \u001b[0m\u001b[32m(\u001b[0m\u001b[32mlm\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": [ "
iterationtime (s)χ²change / status
110.333.70
283.663.632.1% ↓
32210.903.62
43119.813.62
" ], "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;36m3.62\u001b[0m at iteration \u001b[1;36m31\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "βœ… Fitting complete.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "βš™οΈ Settings used:\n" ] }, { "data": { "text/html": [ "
NameValueDescription
1max_iterations1000Maximum solver iterations.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "πŸ“‹ Least-squares fit results:\n" ] }, { "data": { "text/html": [ "
MetricValue
1πŸ§ͺ Minimizerbumps (lm)
2βœ… Overall statussuccess
3⏱️ Fitting time (seconds)19.81
4πŸ“ Goodness-of-fit (reduced χ²)3.62
5πŸ“ R-factor (Rf, %)8.32
6πŸ“ R-factor squared (RfΒ², %)4.23
7πŸ“ Weighted R-factor (wR, %)3.08
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "πŸ“ˆ Refined parameters:\n" ] }, { "data": { "text/html": [ "
datablockcategoryentryparameterunitsstartvalues.u.change
1sicelllength_aΓ…5.43095.43090.00000.00 % ↓
2sepdlinked_structuresiscale627.6584627.01441.25250.10 % ↓
3sepdpeakbroad_lorentz_gamma_1ΞΌs/Γ…2.54892.24300.073412.00 % ↓
4sepdpeakbroad_gauss_sigma_0ΞΌsΒ²3.01486.31370.3700109.42 % ↑
5sepdpeakbroad_gauss_sigma_1ΞΌs/Γ…33.345132.70720.68201.91 % ↓
6sepdinstrumentd_to_tof_offsetΞΌs-8.4435-8.40250.05680.49 % ↓
" ], "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.analysis.fit()\n", "project.display.fit.results()" ] }, { "cell_type": "markdown", "id": "64", "metadata": {}, "source": [ "#### Display Pattern" ] }, { "cell_type": "code", "execution_count": 36, "id": "65", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:29:46.943122Z", "iopub.status.busy": "2026-06-30T22:29:46.942900Z", "iopub.status.idle": "2026-06-30T22:29:47.077322Z", "shell.execute_reply": "2026-06-30T22:29:47.076368Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='sepd')" ] }, { "cell_type": "code", "execution_count": 37, "id": "66", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:29:47.087910Z", "iopub.status.busy": "2026-06-30T22:29:47.087621Z", "iopub.status.idle": "2026-06-30T22:29:47.185435Z", "shell.execute_reply": "2026-06-30T22:29:47.184110Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='sepd', x_min=23200, x_max=23700)" ] }, { "cell_type": "markdown", "id": "67", "metadata": {}, "source": [ "### Perform Fit 4/4\n", "\n", "Set more parameters to be refined." ] }, { "cell_type": "code", "execution_count": 38, "id": "68", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:29:47.187442Z", "iopub.status.busy": "2026-06-30T22:29:47.187151Z", "iopub.status.idle": "2026-06-30T22:29:47.193254Z", "shell.execute_reply": "2026-06-30T22:29:47.192037Z" } }, "outputs": [], "source": [ "structure.atom_sites['Si'].adp_iso.free = True\n", "\n", "expt.peak.decay_beta_0.free = True\n", "expt.peak.decay_beta_1.free = True" ] }, { "cell_type": "markdown", "id": "69", "metadata": {}, "source": [ "Show free parameters after selection." ] }, { "cell_type": "code", "execution_count": 39, "id": "70", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:29:47.195087Z", "iopub.status.busy": "2026-06-30T22:29:47.194884Z", "iopub.status.idle": "2026-06-30T22:29:47.256773Z", "shell.execute_reply": "2026-06-30T22:29:47.255318Z" } }, "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": [ "
datablockcategoryentryparametervalueuncertaintyminmaxunits
1sicelllength_a5.430900.00004-infinfΓ…
2siatom_siteSiadp_iso0.50000-infinfΓ…Β²
3sepdlinked_structuresiscale627.014441.25251-infinf
4sepdpeakdecay_beta_00.04080-infinfΞΌs
5sepdpeakdecay_beta_10.01230-infinfΞΌs/Γ…
6sepdpeakbroad_lorentz_gamma_12.242970.07343-infinfΞΌs/Γ…
7sepdpeakbroad_gauss_sigma_06.313730.37001-infinfΞΌsΒ²
8sepdpeakbroad_gauss_sigma_132.707190.68203-infinfΞΌs/Γ…
9sepdinstrumentd_to_tof_offset-8.402490.05683-infinfΞΌs
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.parameters.free()" ] }, { "cell_type": "markdown", "id": "71", "metadata": {}, "source": [ "#### Run Fitting" ] }, { "cell_type": "code", "execution_count": 40, "id": "72", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:29:47.259306Z", "iopub.status.busy": "2026-06-30T22:29:47.259019Z", "iopub.status.idle": "2026-06-30T22:30:08.934596Z", "shell.execute_reply": "2026-06-30T22:30:08.934121Z" } }, "outputs": [ { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function() {\n", " const button = document.getElementById('ed-fit-stop-8d4fc30779f643569f072d72249aa563-button');\n", " const status = document.getElementById('ed-fit-stop-8d4fc30779f643569f072d72249aa563-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'sepd'\u001b[0m for \u001b[32m'single'\u001b[0m fitting\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "πŸš€ Starting fit process with \u001b[32m'bumps \u001b[0m\u001b[32m(\u001b[0m\u001b[32mlm\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": [ "
iterationtime (s)χ²change / status
110.513.63
2219.253.60
33820.513.60
" ], "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;36m3.60\u001b[0m at iteration \u001b[1;36m21\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "βœ… Fitting complete.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "βš™οΈ Settings used:\n" ] }, { "data": { "text/html": [ "
NameValueDescription
1max_iterations1000Maximum solver iterations.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "πŸ“‹ Least-squares fit results:\n" ] }, { "data": { "text/html": [ "
MetricValue
1πŸ§ͺ Minimizerbumps (lm)
2βœ… Overall statussuccess
3⏱️ Fitting time (seconds)20.51
4πŸ“ Goodness-of-fit (reduced χ²)3.60
5πŸ“ R-factor (Rf, %)8.20
6πŸ“ R-factor squared (RfΒ², %)4.08
7πŸ“ Weighted R-factor (wR, %)2.89
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "πŸ“ˆ Refined parameters:\n" ] }, { "data": { "text/html": [ "
datablockcategoryentryparameterunitsstartvalues.u.change
1sicelllength_aΓ…5.43095.43090.00010.00 % ↓
2siatom_siteSiadp_isoΓ…Β²0.50000.52230.00364.45 % ↑
3sepdlinked_structuresiscale627.0144634.19591.71291.15 % ↑
4sepdpeakdecay_beta_0ΞΌs0.04080.04060.00020.43 % ↓
5sepdpeakdecay_beta_1ΞΌs/Γ…0.01230.01240.00020.87 % ↑
6sepdpeakbroad_lorentz_gamma_1ΞΌs/Γ…2.24302.21240.07991.36 % ↓
7sepdpeakbroad_gauss_sigma_0ΞΌsΒ²6.31375.56490.429111.86 % ↓
8sepdpeakbroad_gauss_sigma_1ΞΌs/Γ…32.707233.20390.70021.52 % ↑
9sepdinstrumentd_to_tof_offsetΞΌs-8.4025-8.40560.08100.04 % ↑
" ], "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.analysis.fit()\n", "project.display.fit.results()" ] }, { "cell_type": "markdown", "id": "73", "metadata": {}, "source": [ "#### Display Correlations" ] }, { "cell_type": "code", "execution_count": 41, "id": "74", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:08.939017Z", "iopub.status.busy": "2026-06-30T22:30:08.938830Z", "iopub.status.idle": "2026-06-30T22:30:08.993920Z", "shell.execute_reply": "2026-06-30T22:30:08.993156Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
Loading plot…
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.fit.correlations()" ] }, { "cell_type": "markdown", "id": "75", "metadata": {}, "source": [ "#### Display Pattern" ] }, { "cell_type": "code", "execution_count": 42, "id": "76", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:08.995549Z", "iopub.status.busy": "2026-06-30T22:30:08.995393Z", "iopub.status.idle": "2026-06-30T22:30:09.070583Z", "shell.execute_reply": "2026-06-30T22:30:09.067676Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='sepd')" ] }, { "cell_type": "code", "execution_count": 43, "id": "77", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:09.076178Z", "iopub.status.busy": "2026-06-30T22:30:09.075944Z", "iopub.status.idle": "2026-06-30T22:30:09.142652Z", "shell.execute_reply": "2026-06-30T22:30:09.141664Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='sepd', x_min=23200, x_max=23700)" ] }, { "cell_type": "code", "execution_count": 44, "id": "78", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:09.151742Z", "iopub.status.busy": "2026-06-30T22:30:09.151495Z", "iopub.status.idle": "2026-06-30T22:30:09.285603Z", "shell.execute_reply": "2026-06-30T22:30:09.284931Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='sepd', x='d_spacing')" ] }, { "cell_type": "markdown", "id": "79", "metadata": {}, "source": [ "## πŸ’Ύ Save Project" ] }, { "cell_type": "code", "execution_count": 45, "id": "80", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:30:09.298563Z", "iopub.status.busy": "2026-06-30T22:30:09.298368Z", "iopub.status.idle": "2026-06-30T22:30:09.881395Z", "shell.execute_reply": "2026-06-30T22:30:09.880650Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mSaving project πŸ“¦ \u001b[0m\u001b[32m'si_sepd'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/refine-si-sepd'\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": [ "β”‚ └── πŸ“„ si.edi\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "β”œβ”€β”€ πŸ“ experiments/\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "β”‚ └── πŸ“„ sepd.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": [ " └── πŸ“„ si_sepd.html\n" ] } ], "source": [ "project.save_as(dir_path='projects/refine-si-sepd')" ] } ], "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 }