{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:35:00.269428Z", "iopub.status.busy": "2026-08-18T18:35:00.269268Z", "iopub.status.idle": "2026-08-18T18:35:00.273146Z", "shell.execute_reply": "2026-08-18T18:35:00.272421Z" }, "tags": [ "hide-in-docs" ] }, "outputs": [], "source": [ "# Check whether easydiffraction is installed; install it if needed.\n", "# Required for remote environments such as Google Colab.\n", "import importlib.util\n", "\n", "if importlib.util.find_spec('easydiffraction') is None:\n", " %pip install easydiffraction==0.20.1" ] }, { "cell_type": "markdown", "id": "1", "metadata": {}, "source": [ "# Structure Refinement: 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-08-18T18:35:00.274855Z", "iopub.status.busy": "2026-08-18T18:35:00.274703Z", "iopub.status.idle": "2026-08-18T18:35:02.967447Z", "shell.execute_reply": "2026-08-18T18:35:02.966542Z" } }, "outputs": [], "source": [ "from easydiffraction import ExperimentFactory\n", "from easydiffraction import Project\n", "from easydiffraction import StructureFactory\n", "from easydiffraction import download_data" ] }, { "cell_type": "markdown", "id": "4", "metadata": {}, "source": [ "## 🧩 Define Structure\n", "\n", "This section shows how to add structures and modify their\n", "parameters.\n", "\n", "### Create Structure" ] }, { "cell_type": "code", "execution_count": 3, "id": "5", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:35:02.969413Z", "iopub.status.busy": "2026-08-18T18:35:02.969057Z", "iopub.status.idle": "2026-08-18T18:35:02.975509Z", "shell.execute_reply": "2026-08-18T18:35:02.974673Z" } }, "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-08-18T18:35:02.977098Z", "iopub.status.busy": "2026-08-18T18:35:02.976895Z", "iopub.status.idle": "2026-08-18T18:35:02.980708Z", "shell.execute_reply": "2026-08-18T18:35:02.979919Z" } }, "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-08-18T18:35:02.982202Z", "iopub.status.busy": "2026-08-18T18:35:02.982038Z", "iopub.status.idle": "2026-08-18T18:35:02.985078Z", "shell.execute_reply": "2026-08-18T18:35:02.984125Z" } }, "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-08-18T18:35:02.986693Z", "iopub.status.busy": "2026-08-18T18:35:02.986474Z", "iopub.status.idle": "2026-08-18T18:35:02.991122Z", "shell.execute_reply": "2026-08-18T18:35:02.990319Z" } }, "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-08-18T18:35:02.992942Z", "iopub.status.busy": "2026-08-18T18:35:02.992734Z", "iopub.status.idle": "2026-08-18T18:35:03.005911Z", "shell.execute_reply": "2026-08-18T18:35:03.005228Z" } }, "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-08-18T18:35:03.007605Z", "iopub.status.busy": "2026-08-18T18:35:03.007416Z", "iopub.status.idle": "2026-08-18T18:35:03.693563Z", "shell.execute_reply": "2026-08-18T18:35:03.692682Z" } }, "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-08-18T18:35:03.695578Z", "iopub.status.busy": "2026-08-18T18:35:03.695384Z", "iopub.status.idle": "2026-08-18T18:35:03.698825Z", "shell.execute_reply": "2026-08-18T18:35:03.698010Z" } }, "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-08-18T18:35:03.700242Z", "iopub.status.busy": "2026-08-18T18:35:03.700094Z", "iopub.status.idle": "2026-08-18T18:35:03.708766Z", "shell.execute_reply": "2026-08-18T18:35:03.707875Z" } }, "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-08-18T18:35:03.710300Z", "iopub.status.busy": "2026-08-18T18:35:03.710146Z", "iopub.status.idle": "2026-08-18T18:35:03.716706Z", "shell.execute_reply": "2026-08-18T18:35:03.715910Z" } }, "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=0.0 \n", " β€’ broad_lorentz_strain=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-08-18T18:35:03.718281Z", "iopub.status.busy": "2026-08-18T18:35:03.718114Z", "iopub.status.idle": "2026-08-18T18:35:03.722006Z", "shell.execute_reply": "2026-08-18T18:35:03.721185Z" } }, "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-08-18T18:35:03.723541Z", "iopub.status.busy": "2026-08-18T18:35:03.723323Z", "iopub.status.idle": "2026-08-18T18:35:03.726616Z", "shell.execute_reply": "2026-08-18T18:35:03.725899Z" } }, "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-08-18T18:35:03.728114Z", "iopub.status.busy": "2026-08-18T18:35:03.727926Z", "iopub.status.idle": "2026-08-18T18:35:03.774593Z", "shell.execute_reply": "2026-08-18T18:35:03.773479Z" } }, "outputs": [], "source": [ "expt.background.auto_estimate()" ] }, { "cell_type": "markdown", "id": "25", "metadata": {}, "source": [ "### Set Linked Structures" ] }, { "cell_type": "code", "execution_count": 15, "id": "26", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:35:03.776215Z", "iopub.status.busy": "2026-08-18T18:35:03.776057Z", "iopub.status.idle": "2026-08-18T18:35:03.779599Z", "shell.execute_reply": "2026-08-18T18:35:03.778817Z" } }, "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-08-18T18:35:03.781128Z", "iopub.status.busy": "2026-08-18T18:35:03.780930Z", "iopub.status.idle": "2026-08-18T18:35:04.074757Z", "shell.execute_reply": "2026-08-18T18:35:04.073897Z" } }, "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-08-18T18:35:04.076363Z", "iopub.status.busy": "2026-08-18T18:35:04.076204Z", "iopub.status.idle": "2026-08-18T18:35:04.079084Z", "shell.execute_reply": "2026-08-18T18:35:04.078411Z" } }, "outputs": [], "source": [ "project.structures.add(structure)" ] }, { "cell_type": "markdown", "id": "31", "metadata": {}, "source": [ "### Add Experiment" ] }, { "cell_type": "code", "execution_count": 18, "id": "32", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:35:04.080760Z", "iopub.status.busy": "2026-08-18T18:35:04.080610Z", "iopub.status.idle": "2026-08-18T18:35:04.083147Z", "shell.execute_reply": "2026-08-18T18:35:04.082435Z" } }, "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-08-18T18:35:04.084768Z", "iopub.status.busy": "2026-08-18T18:35:04.084618Z", "iopub.status.idle": "2026-08-18T18:35:04.339030Z", "shell.execute_reply": "2026-08-18T18:35:04.338211Z" } }, "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-08-18T18:35:04.340740Z", "iopub.status.busy": "2026-08-18T18:35:04.340542Z", "iopub.status.idle": "2026-08-18T18:35:05.353714Z", "shell.execute_reply": "2026-08-18T18:35:05.352626Z" } }, "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-08-18T18:35:05.355471Z", "iopub.status.busy": "2026-08-18T18:35:05.355266Z", "iopub.status.idle": "2026-08-18T18:35:05.358628Z", "shell.execute_reply": "2026-08-18T18:35:05.357882Z" } }, "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-08-18T18:35:05.360230Z", "iopub.status.busy": "2026-08-18T18:35:05.360058Z", "iopub.status.idle": "2026-08-18T18:35:05.411163Z", "shell.execute_reply": "2026-08-18T18:35:05.410337Z" } }, "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-08-18T18:35:05.412999Z", "iopub.status.busy": "2026-08-18T18:35:05.412821Z", "iopub.status.idle": "2026-08-18T18:35:05.418146Z", "shell.execute_reply": "2026-08-18T18:35:05.417331Z" } }, "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-08-18T18:35:05.419737Z", "iopub.status.busy": "2026-08-18T18:35:05.419566Z", "iopub.status.idle": "2026-08-18T18:35:16.116377Z", "shell.execute_reply": "2026-08-18T18:35:16.115661Z" } }, "outputs": [ { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function() {\n", " const button = document.getElementById('ed-fit-stop-3a8252891a1e44d4ac4e4c14196b5d57-button');\n", " const status = document.getElementById('ed-fit-stop-3a8252891a1e44d4ac4e4c14196b5d57-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.2783.59
251.637.3191.3% ↓
392.736.915.4% ↓
4249.756.91
" ], "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.91\u001b[0m at iteration \u001b[1;36m16\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)9.75
4πŸ“ Goodness-of-fit (reduced χ²)6.91
5πŸ“ R-factor (Rf, %)11.58
6πŸ“ R-factor squared (RfΒ², %)6.18
7πŸ“ Weighted R-factor (wR, %)5.09
" ], "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.0000368.20370.962638.63 % ↓
3sepdinstrumentd_to_tof_offsetΞΌs-10.0000-8.31290.075916.87 % ↓
" ], "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-08-18T18:35:16.117834Z", "iopub.status.busy": "2026-08-18T18:35:16.117659Z", "iopub.status.idle": "2026-08-18T18:35:16.188880Z", "shell.execute_reply": "2026-08-18T18:35:16.188081Z" } }, "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-08-18T18:35:16.195492Z", "iopub.status.busy": "2026-08-18T18:35:16.195304Z", "iopub.status.idle": "2026-08-18T18:35:16.249529Z", "shell.execute_reply": "2026-08-18T18:35:16.248847Z" } }, "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-08-18T18:35:16.251102Z", "iopub.status.busy": "2026-08-18T18:35:16.250937Z", "iopub.status.idle": "2026-08-18T18:35:16.254149Z", "shell.execute_reply": "2026-08-18T18:35:16.253469Z" } }, "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-08-18T18:35:16.255672Z", "iopub.status.busy": "2026-08-18T18:35:16.255494Z", "iopub.status.idle": "2026-08-18T18:35:16.315379Z", "shell.execute_reply": "2026-08-18T18:35:16.314700Z" } }, "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.430820.00006-infinfΓ…
2sepdlinked_structuresiscale368.203740.96260-infinf
3sepdinstrumentd_to_tof_offset-8.312940.07593-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-08-18T18:35:16.317041Z", "iopub.status.busy": "2026-08-18T18:35:16.316869Z", "iopub.status.idle": "2026-08-18T18:35:47.354976Z", "shell.execute_reply": "2026-08-18T18:35:47.354227Z" } }, "outputs": [ { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function() {\n", " const button = document.getElementById('ed-fit-stop-3fb810b3e59445c8808a24024298d3f4-button');\n", " const status = document.getElementById('ed-fit-stop-3fb810b3e59445c8808a24024298d3f4-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.276.93
2195.963.7146.5% ↓
34112.583.71
46230.053.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;36m62\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)30.05
4πŸ“ Goodness-of-fit (reduced χ²)3.71
5πŸ“ R-factor (Rf, %)8.29
6πŸ“ R-factor squared (RfΒ², %)4.20
7πŸ“ Weighted R-factor (wR, %)3.13
" ], "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_structuresiscale368.2037379.10340.72752.96 % ↑
3sepdinstrumentd_to_tof_offsetΞΌs-8.3129-8.43740.05411.50 % ↑
4sepdbackground1intensity213.5506203.78620.41104.57 % ↓
5sepdbackground2intensity117.6167103.74280.446611.80 % ↓
6sepdbackground3intensity147.7001125.11440.872615.29 % ↓
7sepdbackground4intensity122.2624119.81860.96512.00 % ↓
8sepdbackground5intensity163.0490127.47252.742521.82 % ↓
9sepdbackground6intensity124.5876123.15761.68051.15 % ↓
10sepdbackground7intensity120.3074121.72701.76461.18 % ↑
11sepdbackground8intensity186.0212140.35353.271824.55 % ↓
12sepdbackground9intensity133.3853135.11112.44041.29 % ↑
13sepdbackground10intensity108.6000129.94321.342419.65 % ↑
14sepdbackground11intensity139.8000143.23012.14122.45 % ↑
15sepdbackground12intensity272.0550175.44194.725635.51 % ↓
16sepdbackground13intensity114.0960166.50135.127345.93 % ↑
17sepdbackground14intensity177.0632203.961010.818615.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-08-18T18:35:47.356865Z", "iopub.status.busy": "2026-08-18T18:35:47.356576Z", "iopub.status.idle": "2026-08-18T18:35:47.425657Z", "shell.execute_reply": "2026-08-18T18:35:47.424956Z" } }, "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-08-18T18:35:47.432655Z", "iopub.status.busy": "2026-08-18T18:35:47.432476Z", "iopub.status.idle": "2026-08-18T18:35:47.488678Z", "shell.execute_reply": "2026-08-18T18:35:47.487979Z" } }, "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-08-18T18:35:47.490292Z", "iopub.status.busy": "2026-08-18T18:35:47.490119Z", "iopub.status.idle": "2026-08-18T18:35:47.493256Z", "shell.execute_reply": "2026-08-18T18:35:47.492647Z" } }, "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-08-18T18:35:47.494819Z", "iopub.status.busy": "2026-08-18T18:35:47.494661Z", "iopub.status.idle": "2026-08-18T18:35:47.497353Z", "shell.execute_reply": "2026-08-18T18:35:47.496766Z" } }, "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-08-18T18:35:47.498811Z", "iopub.status.busy": "2026-08-18T18:35:47.498660Z", "iopub.status.idle": "2026-08-18T18:35:47.543243Z", "shell.execute_reply": "2026-08-18T18:35:47.542585Z" } }, "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.430920.00004-infinfΓ…
2sepdlinked_structuresiscale379.103440.72748-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.437370.05407-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-08-18T18:35:47.544980Z", "iopub.status.busy": "2026-08-18T18:35:47.544806Z", "iopub.status.idle": "2026-08-18T18:36:00.219326Z", "shell.execute_reply": "2026-08-18T18:36:00.218644Z" } }, "outputs": [ { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function() {\n", " const button = document.getElementById('ed-fit-stop-a379769fb9114726a8e2e4334f8d02b5-button');\n", " const status = document.getElementById('ed-fit-stop-a379769fb9114726a8e2e4334f8d02b5-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.273.70
282.513.632.1% ↓
32512.053.63
" ], "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.63\u001b[0m at iteration \u001b[1;36m25\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)12.05
4πŸ“ Goodness-of-fit (reduced χ²)3.63
5πŸ“ R-factor (Rf, %)8.33
6πŸ“ R-factor squared (RfΒ², %)4.27
7πŸ“ Weighted R-factor (wR, %)3.14
" ], "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_structuresiscale379.1034378.74250.75650.10 % ↓
3sepdpeakbroad_lorentz_gamma_1ΞΌs/Γ…2.54892.25950.071111.35 % ↓
4sepdpeakbroad_gauss_sigma_0ΞΌsΒ²3.01486.13900.2002103.63 % ↑
5sepdpeakbroad_gauss_sigma_1ΞΌs/Γ…33.345132.71430.67781.89 % ↓
6sepdinstrumentd_to_tof_offsetΞΌs-8.4374-8.37410.05670.75 % ↓
" ], "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-08-18T18:36:00.220846Z", "iopub.status.busy": "2026-08-18T18:36:00.220679Z", "iopub.status.idle": "2026-08-18T18:36:00.290953Z", "shell.execute_reply": "2026-08-18T18:36:00.290170Z" } }, "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-08-18T18:36:00.297885Z", "iopub.status.busy": "2026-08-18T18:36:00.297707Z", "iopub.status.idle": "2026-08-18T18:36:00.352256Z", "shell.execute_reply": "2026-08-18T18:36:00.351535Z" } }, "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-08-18T18:36:00.353789Z", "iopub.status.busy": "2026-08-18T18:36:00.353619Z", "iopub.status.idle": "2026-08-18T18:36:00.356707Z", "shell.execute_reply": "2026-08-18T18:36:00.356012Z" } }, "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-08-18T18:36:00.358215Z", "iopub.status.busy": "2026-08-18T18:36:00.358068Z", "iopub.status.idle": "2026-08-18T18:36:00.403339Z", "shell.execute_reply": "2026-08-18T18:36:00.402678Z" } }, "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.430880.00004-infinfΓ…
2siatom_siteSiadp_iso0.50000-infinfΓ…Β²
3sepdlinked_structuresiscale378.742500.75653-infinf
4sepdpeakdecay_beta_00.04080-infinfΞΌs
5sepdpeakdecay_beta_10.01230-infinfΞΌs/Γ…
6sepdpeakbroad_lorentz_gamma_12.259520.07107-infinfΞΌs/Γ…
7sepdpeakbroad_gauss_sigma_06.139030.20017-infinfΞΌsΒ²
8sepdpeakbroad_gauss_sigma_132.714300.67783-infinfΞΌs/Γ…
9sepdinstrumentd_to_tof_offset-8.374100.05668-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-08-18T18:36:00.404971Z", "iopub.status.busy": "2026-08-18T18:36:00.404821Z", "iopub.status.idle": "2026-08-18T18:36:19.306936Z", "shell.execute_reply": "2026-08-18T18:36:19.306170Z" } }, "outputs": [ { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function() {\n", " const button = document.getElementById('ed-fit-stop-f5b1782e077240daa6db2f7373ca0410-button');\n", " const status = document.getElementById('ed-fit-stop-f5b1782e077240daa6db2f7373ca0410-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.553.63
2216.723.60
33818.263.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)18.26
4πŸ“ Goodness-of-fit (reduced χ²)3.60
5πŸ“ R-factor (Rf, %)8.21
6πŸ“ R-factor squared (RfΒ², %)4.12
7πŸ“ Weighted R-factor (wR, %)2.93
" ], "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.52220.00364.44 % ↑
3sepdlinked_structuresiscale378.7425383.08521.03461.15 % ↑
4sepdpeakdecay_beta_0ΞΌs0.04080.04060.00020.45 % ↓
5sepdpeakdecay_beta_1ΞΌs/Γ…0.01230.01240.00020.94 % ↑
6sepdpeakbroad_lorentz_gamma_1ΞΌs/Γ…2.25952.22640.07981.47 % ↓
7sepdpeakbroad_gauss_sigma_0ΞΌsΒ²6.13905.64390.42998.06 % ↓
8sepdpeakbroad_gauss_sigma_1ΞΌs/Γ…32.714333.00530.69940.89 % ↑
9sepdinstrumentd_to_tof_offsetΞΌs-8.3741-8.40080.08070.32 % ↑
" ], "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-08-18T18:36:19.308415Z", "iopub.status.busy": "2026-08-18T18:36:19.308250Z", "iopub.status.idle": "2026-08-18T18:36:19.332614Z", "shell.execute_reply": "2026-08-18T18:36:19.331951Z" } }, "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-08-18T18:36:19.334225Z", "iopub.status.busy": "2026-08-18T18:36:19.334075Z", "iopub.status.idle": "2026-08-18T18:36:19.404128Z", "shell.execute_reply": "2026-08-18T18:36:19.403376Z" } }, "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-08-18T18:36:19.410966Z", "iopub.status.busy": "2026-08-18T18:36:19.410801Z", "iopub.status.idle": "2026-08-18T18:36:19.466903Z", "shell.execute_reply": "2026-08-18T18:36:19.466121Z" } }, "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-08-18T18:36:19.468553Z", "iopub.status.busy": "2026-08-18T18:36:19.468375Z", "iopub.status.idle": "2026-08-18T18:36:19.535676Z", "shell.execute_reply": "2026-08-18T18:36:19.534900Z" } }, "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-08-18T18:36:19.542405Z", "iopub.status.busy": "2026-08-18T18:36:19.542237Z", "iopub.status.idle": "2026-08-18T18:36:20.021573Z", "shell.execute_reply": "2026-08-18T18:36:20.020699Z" } }, "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", "β”œβ”€β”€ πŸ“ structures/\n", "β”‚ └── πŸ“„ si.edi\n", "β”œβ”€β”€ πŸ“ experiments/\n", "β”‚ └── πŸ“„ sepd.edi\n", "β”œβ”€β”€ πŸ“ analysis/\n", "β”‚ └── πŸ“„ analysis.edi\n", "└── πŸ“ reports/\n", " └── πŸ“„ 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.6" } }, "nbformat": 4, "nbformat_minor": 5 }