{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:34.084931Z", "iopub.status.busy": "2026-08-18T18:25:34.084766Z", "iopub.status.idle": "2026-08-18T18:25:34.089107Z", "shell.execute_reply": "2026-08-18T18:25:34.088238Z" }, "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": [ "# Joint Refinement: Si, Bragg + PDF\n", "\n", "This example demonstrates a joint refinement of the Si crystal\n", "structure combining Bragg diffraction and pair distribution function\n", "(PDF) analysis. The Bragg experiment uses time-of-flight neutron\n", "powder diffraction data from SEPD at Argonne, while the PDF\n", "experiment uses data from NOMAD at SNS. A single shared Si structure\n", "is refined simultaneously against both datasets." ] }, { "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:25:34.090659Z", "iopub.status.busy": "2026-08-18T18:25:34.090489Z", "iopub.status.idle": "2026-08-18T18:25:37.702987Z", "shell.execute_reply": "2026-08-18T18:25:37.702465Z" } }, "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", "A single Si structure is shared between the Bragg and PDF\n", "experiments. Structural parameters refined against both datasets\n", "simultaneously.\n", "\n", "### Create Structure" ] }, { "cell_type": "code", "execution_count": 3, "id": "5", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:37.706184Z", "iopub.status.busy": "2026-08-18T18:25:37.705717Z", "iopub.status.idle": "2026-08-18T18:25:37.710915Z", "shell.execute_reply": "2026-08-18T18:25:37.710489Z" } }, "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:25:37.713057Z", "iopub.status.busy": "2026-08-18T18:25:37.712699Z", "iopub.status.idle": "2026-08-18T18:25:37.715916Z", "shell.execute_reply": "2026-08-18T18:25:37.715347Z" } }, "outputs": [], "source": [ "structure.space_group.name_h_m = 'F d -3 m'\n", "structure.space_group.coord_system_code = '1'" ] }, { "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:25:37.717783Z", "iopub.status.busy": "2026-08-18T18:25:37.717618Z", "iopub.status.idle": "2026-08-18T18:25:37.720367Z", "shell.execute_reply": "2026-08-18T18:25:37.719683Z" } }, "outputs": [], "source": [ "structure.cell.length_a = 5.42" ] }, { "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:25:37.721762Z", "iopub.status.busy": "2026-08-18T18:25:37.721596Z", "iopub.status.idle": "2026-08-18T18:25:37.726096Z", "shell.execute_reply": "2026-08-18T18:25:37.725103Z" } }, "outputs": [], "source": [ "structure.atom_sites.create(\n", " id='Si',\n", " type_symbol='Si',\n", " fract_x=0,\n", " fract_y=0,\n", " fract_z=0,\n", " adp_iso=0.5223,\n", ")" ] }, { "cell_type": "markdown", "id": "12", "metadata": {}, "source": [ "## πŸ”¬ Define Experiments\n", "\n", "Two experiments are defined: one for Bragg diffraction and one for\n", "PDF analysis. Both are linked to the same Si structure.\n", "\n", "### Experiment 1: Bragg (SEPD, TOF)\n", "\n", "#### Download Data" ] }, { "cell_type": "code", "execution_count": 7, "id": "13", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:37.728102Z", "iopub.status.busy": "2026-08-18T18:25:37.727448Z", "iopub.status.idle": "2026-08-18T18:25:37.859353Z", "shell.execute_reply": "2026-08-18T18:25:37.858270Z" } }, "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 downloaded to \u001b[32m'../../../data/meas-si-sepd.xye'\u001b[0m\n" ] } ], "source": [ "bragg_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:25:37.861051Z", "iopub.status.busy": "2026-08-18T18:25:37.860745Z", "iopub.status.idle": "2026-08-18T18:25:38.634469Z", "shell.execute_reply": "2026-08-18T18:25:38.633628Z" } }, "outputs": [], "source": [ "bragg_expt = ExperimentFactory.from_data_path(\n", " name='sepd', data_path=bragg_data_path, 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:25:38.636620Z", "iopub.status.busy": "2026-08-18T18:25:38.636427Z", "iopub.status.idle": "2026-08-18T18:25:38.639773Z", "shell.execute_reply": "2026-08-18T18:25:38.638988Z" } }, "outputs": [], "source": [ "bragg_expt.instrument.setup_twotheta_bank = 144.845\n", "bragg_expt.instrument.calib_d_to_tof_offset = -8.4\n", "bragg_expt.instrument.calib_d_to_tof_linear = 7476.91\n", "bragg_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:25:38.641172Z", "iopub.status.busy": "2026-08-18T18:25:38.641005Z", "iopub.status.idle": "2026-08-18T18:25:38.648881Z", "shell.execute_reply": "2026-08-18T18:25:38.648190Z" } }, "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": [ "bragg_expt.peak.type = 'jorgensen-von-dreele'\n", "bragg_expt.peak.broad_gauss_sigma_0 = 5.61\n", "bragg_expt.peak.broad_gauss_sigma_1 = 33.19\n", "bragg_expt.peak.broad_lorentz_gamma_1 = 2.21\n", "bragg_expt.peak.decay_beta_0 = 0.0406\n", "bragg_expt.peak.decay_beta_1 = 0.0124\n", "bragg_expt.peak.rise_alpha_1 = 0.5971\n", "bragg_expt.peak.cutoff_fwhm = 8.2" ] }, { "cell_type": "markdown", "id": "20", "metadata": {}, "source": [ "#### Set Background" ] }, { "cell_type": "code", "execution_count": 11, "id": "21", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:38.650598Z", "iopub.status.busy": "2026-08-18T18:25:38.650405Z", "iopub.status.idle": "2026-08-18T18:25:38.656933Z", "shell.execute_reply": "2026-08-18T18:25:38.656241Z" } }, "outputs": [], "source": [ "for idx, (x, y) in enumerate(\n", " [\n", " (2000.0, 203.79),\n", " (9035.0, 103.74),\n", " (9335.0, 125.12),\n", " (11915.0, 119.81),\n", " (12315.0, 127.52),\n", " (12695.0, 123.16),\n", " (13745.0, 121.72),\n", " (14410.0, 140.39),\n", " (14875.0, 135.11),\n", " (15660.0, 129.95),\n", " (23075.0, 143.23),\n", " (23515.0, 175.48),\n", " (28100.0, 166.48),\n", " (29995.0, 203.98),\n", " ],\n", " start=1,\n", "):\n", " bragg_expt.background.create(id=str(idx), position=x, intensity=y)" ] }, { "cell_type": "markdown", "id": "22", "metadata": {}, "source": [ "#### Set Linked Structures" ] }, { "cell_type": "code", "execution_count": 12, "id": "23", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:38.658595Z", "iopub.status.busy": "2026-08-18T18:25:38.658407Z", "iopub.status.idle": "2026-08-18T18:25:38.661988Z", "shell.execute_reply": "2026-08-18T18:25:38.661131Z" } }, "outputs": [], "source": [ "bragg_expt.linked_structures.create(structure_id='si', scale=634.3132)" ] }, { "cell_type": "markdown", "id": "24", "metadata": {}, "source": [ "### Experiment 2: PDF (NOMAD, TOF)\n", "\n", "#### Download Data" ] }, { "cell_type": "code", "execution_count": 13, "id": "25", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:38.663441Z", "iopub.status.busy": "2026-08-18T18:25:38.663279Z", "iopub.status.idle": "2026-08-18T18:25:38.670608Z", "shell.execute_reply": "2026-08-18T18:25:38.669960Z" } }, "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-pdf-nomad'\u001b[0m: Si, NOMAD \u001b[1m(\u001b[0mSNS\u001b[1m)\u001b[0m, PDF\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "βœ… Data \u001b[32m'meas-si-pdf-nomad'\u001b[0m already present at \u001b[32m'../../../data/meas-si-pdf-nomad.gr'\u001b[0m. Keeping existing.\n" ] } ], "source": [ "pdf_data_path = download_data('meas-si-pdf-nomad', destination='data')" ] }, { "cell_type": "markdown", "id": "26", "metadata": {}, "source": [ "#### Create Experiment" ] }, { "cell_type": "code", "execution_count": 14, "id": "27", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:38.672307Z", "iopub.status.busy": "2026-08-18T18:25:38.672157Z", "iopub.status.idle": "2026-08-18T18:25:39.302952Z", "shell.execute_reply": "2026-08-18T18:25:39.302223Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "⚠️ No uncertainty (sy) column provided. Defaulting to 0.03. \n" ] } ], "source": [ "pdf_expt = ExperimentFactory.from_data_path(\n", " name='nomad',\n", " data_path=pdf_data_path,\n", " beam_mode='time-of-flight',\n", " scattering_type='total',\n", ")" ] }, { "cell_type": "markdown", "id": "28", "metadata": {}, "source": [ "#### Set Peak Profile (PDF Parameters)" ] }, { "cell_type": "code", "execution_count": 15, "id": "29", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:39.307027Z", "iopub.status.busy": "2026-08-18T18:25:39.306855Z", "iopub.status.idle": "2026-08-18T18:25:39.314536Z", "shell.execute_reply": "2026-08-18T18:25:39.313763Z" } }, "outputs": [], "source": [ "pdf_expt.peak.damp_q = 0.02\n", "pdf_expt.peak.broad_q = 0.03\n", "pdf_expt.peak.cutoff_q = 35.0\n", "pdf_expt.peak.sharp_delta_1 = 0.4\n", "pdf_expt.peak.sharp_delta_2 = 3.0\n", "pdf_expt.peak.damp_particle_diameter = 0" ] }, { "cell_type": "markdown", "id": "30", "metadata": {}, "source": [ "#### Set Linked Structures" ] }, { "cell_type": "code", "execution_count": 16, "id": "31", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:39.316336Z", "iopub.status.busy": "2026-08-18T18:25:39.316183Z", "iopub.status.idle": "2026-08-18T18:25:39.322663Z", "shell.execute_reply": "2026-08-18T18:25:39.319231Z" } }, "outputs": [], "source": [ "pdf_expt.linked_structures.create(structure_id='si', scale=1.6)" ] }, { "cell_type": "markdown", "id": "32", "metadata": {}, "source": [ "## πŸ“¦ Define Project\n", "\n", "The project object manages the shared structure, both experiments,\n", "and the analysis.\n", "\n", "### Create Project" ] }, { "cell_type": "code", "execution_count": 17, "id": "33", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:39.324259Z", "iopub.status.busy": "2026-08-18T18:25:39.324107Z", "iopub.status.idle": "2026-08-18T18:25:39.706615Z", "shell.execute_reply": "2026-08-18T18:25:39.705229Z" } }, "outputs": [], "source": [ "project = Project(name='si_bragg_pdf')" ] }, { "cell_type": "markdown", "id": "34", "metadata": {}, "source": [ "### Add Structure" ] }, { "cell_type": "code", "execution_count": 18, "id": "35", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:39.708290Z", "iopub.status.busy": "2026-08-18T18:25:39.708124Z", "iopub.status.idle": "2026-08-18T18:25:39.713894Z", "shell.execute_reply": "2026-08-18T18:25:39.713230Z" } }, "outputs": [], "source": [ "project.structures.add(structure)" ] }, { "cell_type": "markdown", "id": "36", "metadata": {}, "source": [ "### Add Experiments" ] }, { "cell_type": "code", "execution_count": 19, "id": "37", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:39.715541Z", "iopub.status.busy": "2026-08-18T18:25:39.715368Z", "iopub.status.idle": "2026-08-18T18:25:39.721754Z", "shell.execute_reply": "2026-08-18T18:25:39.719529Z" } }, "outputs": [], "source": [ "project.experiments.add(bragg_expt)\n", "project.experiments.add(pdf_expt)" ] }, { "cell_type": "markdown", "id": "38", "metadata": {}, "source": [ "## πŸš€ Perform Analysis\n", "\n", "This section shows the joint analysis process. The calculator is\n", "auto-resolved per experiment: CrysPy for Bragg, PDFfit for PDF.\n", "\n", "### Set Fit Mode and Weights" ] }, { "cell_type": "code", "execution_count": 20, "id": "39", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:39.723335Z", "iopub.status.busy": "2026-08-18T18:25:39.723180Z", "iopub.status.idle": "2026-08-18T18:25:39.733850Z", "shell.execute_reply": "2026-08-18T18:25:39.731379Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mFitting mode changed to\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "joint\n" ] } ], "source": [ "project.analysis.fitting_mode.type = 'joint'\n", "project.analysis.joint_fit.create(experiment_id='sepd', weight=0.75)\n", "project.analysis.joint_fit.create(experiment_id='nomad', weight=0.25)" ] }, { "cell_type": "markdown", "id": "40", "metadata": {}, "source": [ "### Display Structure" ] }, { "cell_type": "code", "execution_count": 21, "id": "41", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:39.735570Z", "iopub.status.busy": "2026-08-18T18:25:39.735371Z", "iopub.status.idle": "2026-08-18T18:25:40.055126Z", "shell.execute_reply": "2026-08-18T18:25:40.054289Z" } }, "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": "42", "metadata": {}, "source": [ "### Display Pattern (Before Fit)" ] }, { "cell_type": "code", "execution_count": 22, "id": "43", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:40.056721Z", "iopub.status.busy": "2026-08-18T18:25:40.056549Z", "iopub.status.idle": "2026-08-18T18:25:41.131156Z", "shell.execute_reply": "2026-08-18T18:25:41.130699Z" } }, "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": 23, "id": "44", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:41.152099Z", "iopub.status.busy": "2026-08-18T18:25:41.151719Z", "iopub.status.idle": "2026-08-18T18:25:41.499851Z", "shell.execute_reply": "2026-08-18T18:25:41.494481Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='nomad')" ] }, { "cell_type": "markdown", "id": "45", "metadata": {}, "source": [ "### Set Free Parameters\n", "\n", "Shared structural parameters are refined against both datasets\n", "simultaneously." ] }, { "cell_type": "code", "execution_count": 24, "id": "46", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:41.501746Z", "iopub.status.busy": "2026-08-18T18:25:41.501564Z", "iopub.status.idle": "2026-08-18T18:25:41.506755Z", "shell.execute_reply": "2026-08-18T18:25:41.505315Z" } }, "outputs": [], "source": [ "structure.cell.length_a.free = True" ] }, { "cell_type": "markdown", "id": "47", "metadata": {}, "source": [ "Bragg experiment parameters." ] }, { "cell_type": "code", "execution_count": 25, "id": "48", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:41.508218Z", "iopub.status.busy": "2026-08-18T18:25:41.508049Z", "iopub.status.idle": "2026-08-18T18:25:41.511126Z", "shell.execute_reply": "2026-08-18T18:25:41.510552Z" } }, "outputs": [], "source": [ "bragg_expt.linked_structures['si'].scale.free = True\n", "bragg_expt.instrument.calib_d_to_tof_offset.free = True\n", "bragg_expt.peak.broad_gauss_sigma_1.free = True\n", "bragg_expt.peak.broad_lorentz_gamma_1.free = True" ] }, { "cell_type": "markdown", "id": "49", "metadata": {}, "source": [ "PDF experiment parameters." ] }, { "cell_type": "code", "execution_count": 26, "id": "50", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:41.514046Z", "iopub.status.busy": "2026-08-18T18:25:41.513886Z", "iopub.status.idle": "2026-08-18T18:25:41.517115Z", "shell.execute_reply": "2026-08-18T18:25:41.516419Z" } }, "outputs": [], "source": [ "pdf_expt.linked_structures['si'].scale.free = True\n", "pdf_expt.peak.damp_q.free = True\n", "pdf_expt.peak.broad_q.free = True\n", "pdf_expt.peak.sharp_delta_1.free = True\n", "pdf_expt.peak.sharp_delta_2.free = True" ] }, { "cell_type": "markdown", "id": "51", "metadata": {}, "source": [ "### Display Free Parameters" ] }, { "cell_type": "code", "execution_count": 27, "id": "52", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:41.518397Z", "iopub.status.busy": "2026-08-18T18:25:41.518240Z", "iopub.status.idle": "2026-08-18T18:25:41.588031Z", "shell.execute_reply": "2026-08-18T18:25:41.586950Z" } }, "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.42000-infinfΓ…
2sepdlinked_structuresiscale634.31320-infinf
3sepdpeakbroad_lorentz_gamma_12.21000-infinfΞΌs/Γ…
4sepdpeakbroad_gauss_sigma_133.19000-infinfΞΌs/Γ…
5sepdinstrumentd_to_tof_offset-8.40000-infinfΞΌs
6nomadlinked_structuresiscale1.60000-infinf
7nomadpeakdamp_q0.02000-infinfÅ⁻¹
8nomadpeakbroad_q0.03000-infinfÅ⁻²
9nomadpeaksharp_delta_10.40000-infinfΓ…
10nomadpeaksharp_delta_23.00000-infinfΓ…Β²
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.parameters.free()" ] }, { "cell_type": "markdown", "id": "53", "metadata": {}, "source": [ "### Run Fitting" ] }, { "cell_type": "code", "execution_count": 28, "id": "54", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:41.589617Z", "iopub.status.busy": "2026-08-18T18:25:41.589426Z", "iopub.status.idle": "2026-08-18T18:25:41.595516Z", "shell.execute_reply": "2026-08-18T18:25:41.594815Z" } }, "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": 29, "id": "55", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:25:41.597162Z", "iopub.status.busy": "2026-08-18T18:25:41.597009Z", "iopub.status.idle": "2026-08-18T18:26:42.214889Z", "shell.execute_reply": "2026-08-18T18:26:42.214200Z" } }, "outputs": [ { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function() {\n", " const button = document.getElementById('ed-fit-stop-aac12eb037a642d4a75d3723fd00e5a9-button');\n", " const status = document.getElementById('ed-fit-stop-aac12eb037a642d4a75d3723fd00e5a9-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;36mUsing all experiments πŸ”¬ \u001b[0m\u001b[1;36m[\u001b[0m\u001b[32m'sepd'\u001b[0m\u001b[1;36m, \u001b[0m\u001b[32m'nomad'\u001b[0m\u001b[1;36m]\u001b[0m\u001b[1;36m for \u001b[0m\u001b[32m'joint'\u001b[0m\u001b[1;36m fitting\u001b[0m\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.511627.28
2127.46226.6686.1% ↓
32314.7366.3670.7% ↓
43420.8554.7117.6% ↓
54526.6853.053.0% ↓
65632.7153.00
77040.7053.00
88359.6853.00
" ], "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;36m53.00\u001b[0m at iteration \u001b[1;36m70\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)59.68
4πŸ“ Goodness-of-fit (reduced χ²)53.00
5πŸ“ R-factor (Rf, %)8.64
6πŸ“ R-factor squared (RfΒ², %)5.06
7πŸ“ Weighted R-factor (wR, %)4.17
" ], "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.42005.43060.00000.20 % ↑
2sepdlinked_structuresiscale634.3132383.09492.343639.60 % ↓
3sepdpeakbroad_lorentz_gamma_1ΞΌs/Γ…2.21002.23940.20821.33 % ↑
4sepdpeakbroad_gauss_sigma_1ΞΌs/Γ…33.190032.59821.81461.78 % ↓
5sepdinstrumentd_to_tof_offsetΞΌs-8.4000-8.06070.08874.04 % ↓
6nomadlinked_structuresiscale1.60001.56680.00262.08 % ↓
7nomadpeakdamp_qÅ⁻¹0.02000.02350.000117.67 % ↑
8nomadpeakbroad_qÅ⁻²0.03000.02760.00018.14 % ↓
9nomadpeaksharp_delta_1Γ…0.40000.38490.03403.78 % ↓
10nomadpeaksharp_delta_2Γ…Β²3.00003.05130.08491.71 % ↑
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
β€’ start = parameter value before refinement
β€’ value = refined value from least-squares minimization
β€’ s.u. = standard uncertainty (one sigma), from the covariance matrix
β€’ change = relative change from start, in %; ↑ = increase, ↓ = decrease
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n", "
\n", "
Loading plot…
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.analysis.fit()\n", "project.display.fit.results()\n", "project.display.fit.correlations()" ] }, { "cell_type": "markdown", "id": "56", "metadata": {}, "source": [ "### Display Pattern (After Fit)" ] }, { "cell_type": "code", "execution_count": 30, "id": "57", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:26:42.216856Z", "iopub.status.busy": "2026-08-18T18:26:42.216685Z", "iopub.status.idle": "2026-08-18T18:26:42.294075Z", "shell.execute_reply": "2026-08-18T18:26:42.293180Z" } }, "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": "58", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:26:42.302424Z", "iopub.status.busy": "2026-08-18T18:26:42.302187Z", "iopub.status.idle": "2026-08-18T18:26:42.346562Z", "shell.execute_reply": "2026-08-18T18:26:42.345725Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='nomad')" ] }, { "cell_type": "markdown", "id": "59", "metadata": {}, "source": [ "## πŸ’Ύ Save Project" ] }, { "cell_type": "code", "execution_count": 32, "id": "60", "metadata": { "execution": { "iopub.execute_input": "2026-08-18T18:26:42.348077Z", "iopub.status.busy": "2026-08-18T18:26:42.347897Z", "iopub.status.idle": "2026-08-18T18:26:43.104236Z", "shell.execute_reply": "2026-08-18T18:26:43.103262Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mSaving project πŸ“¦ \u001b[0m\u001b[32m'si_bragg_pdf'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/joint-si-bragg-pdf'\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "β”œβ”€β”€ πŸ“„ project.edi\n", "β”œβ”€β”€ πŸ“ structures/\n", "β”‚ └── πŸ“„ si.edi\n", "β”œβ”€β”€ πŸ“ experiments/\n", "β”‚ └── πŸ“„ sepd.edi\n", "β”‚ └── πŸ“„ nomad.edi\n", "β”œβ”€β”€ πŸ“ analysis/\n", "β”‚ └── πŸ“„ analysis.edi\n", "└── πŸ“ reports/\n", " └── πŸ“„ si_bragg_pdf.html\n" ] } ], "source": [ "project.save_as(dir_path='projects/joint-si-bragg-pdf')" ] } ], "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 }