{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:25.463868Z", "iopub.status.busy": "2026-06-30T22:27:25.463704Z", "iopub.status.idle": "2026-06-30T22:27:25.468346Z", "shell.execute_reply": "2026-06-30T22:27:25.467549Z" }, "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": [ "# 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-06-30T22:27:25.470122Z", "iopub.status.busy": "2026-06-30T22:27:25.469955Z", "iopub.status.idle": "2026-06-30T22:27:28.387775Z", "shell.execute_reply": "2026-06-30T22:27:28.386879Z" } }, "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-06-30T22:27:28.389582Z", "iopub.status.busy": "2026-06-30T22:27:28.389295Z", "iopub.status.idle": "2026-06-30T22:27:28.394279Z", "shell.execute_reply": "2026-06-30T22:27:28.393453Z" } }, "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:27:28.396185Z", "iopub.status.busy": "2026-06-30T22:27:28.396007Z", "iopub.status.idle": "2026-06-30T22:27:28.399321Z", "shell.execute_reply": "2026-06-30T22:27:28.398514Z" } }, "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-06-30T22:27:28.401036Z", "iopub.status.busy": "2026-06-30T22:27:28.400864Z", "iopub.status.idle": "2026-06-30T22:27:28.403755Z", "shell.execute_reply": "2026-06-30T22:27:28.402952Z" } }, "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-06-30T22:27:28.405234Z", "iopub.status.busy": "2026-06-30T22:27:28.405047Z", "iopub.status.idle": "2026-06-30T22:27:28.409258Z", "shell.execute_reply": "2026-06-30T22:27:28.408442Z" } }, "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-06-30T22:27:28.410999Z", "iopub.status.busy": "2026-06-30T22:27:28.410858Z", "iopub.status.idle": "2026-06-30T22:27:28.586008Z", "shell.execute_reply": "2026-06-30T22:27:28.585244Z" } }, "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-06-30T22:27:28.587990Z", "iopub.status.busy": "2026-06-30T22:27:28.587767Z", "iopub.status.idle": "2026-06-30T22:27:29.294080Z", "shell.execute_reply": "2026-06-30T22:27:29.293186Z" } }, "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-06-30T22:27:29.295744Z", "iopub.status.busy": "2026-06-30T22:27:29.295566Z", "iopub.status.idle": "2026-06-30T22:27:29.299053Z", "shell.execute_reply": "2026-06-30T22:27:29.298218Z" } }, "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-06-30T22:27:29.300664Z", "iopub.status.busy": "2026-06-30T22:27:29.300496Z", "iopub.status.idle": "2026-06-30T22:27:29.308174Z", "shell.execute_reply": "2026-06-30T22:27:29.307496Z" } }, "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": [ "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-06-30T22:27:29.309830Z", "iopub.status.busy": "2026-06-30T22:27:29.309663Z", "iopub.status.idle": "2026-06-30T22:27:29.316395Z", "shell.execute_reply": "2026-06-30T22:27:29.315534Z" } }, "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-06-30T22:27:29.317846Z", "iopub.status.busy": "2026-06-30T22:27:29.317683Z", "iopub.status.idle": "2026-06-30T22:27:29.320870Z", "shell.execute_reply": "2026-06-30T22:27:29.320012Z" } }, "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-06-30T22:27:29.322288Z", "iopub.status.busy": "2026-06-30T22:27:29.322130Z", "iopub.status.idle": "2026-06-30T22:27:29.475119Z", "shell.execute_reply": "2026-06-30T22:27:29.474308Z" } }, "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 downloaded to \u001b[32m'../../../data/meas-si-pdf-nomad.gr'\u001b[0m\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-06-30T22:27:29.476861Z", "iopub.status.busy": "2026-06-30T22:27:29.476680Z", "iopub.status.idle": "2026-06-30T22:27:30.042376Z", "shell.execute_reply": "2026-06-30T22:27:30.041668Z" } }, "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-06-30T22:27:30.044544Z", "iopub.status.busy": "2026-06-30T22:27:30.044373Z", "iopub.status.idle": "2026-06-30T22:27:30.047816Z", "shell.execute_reply": "2026-06-30T22:27:30.047119Z" } }, "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-06-30T22:27:30.049545Z", "iopub.status.busy": "2026-06-30T22:27:30.049395Z", "iopub.status.idle": "2026-06-30T22:27:30.052499Z", "shell.execute_reply": "2026-06-30T22:27:30.051740Z" } }, "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-06-30T22:27:30.054036Z", "iopub.status.busy": "2026-06-30T22:27:30.053877Z", "iopub.status.idle": "2026-06-30T22:27:30.270482Z", "shell.execute_reply": "2026-06-30T22:27:30.269251Z" } }, "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-06-30T22:27:30.272072Z", "iopub.status.busy": "2026-06-30T22:27:30.271919Z", "iopub.status.idle": "2026-06-30T22:27:30.274718Z", "shell.execute_reply": "2026-06-30T22:27:30.273958Z" } }, "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-06-30T22:27:30.276213Z", "iopub.status.busy": "2026-06-30T22:27:30.276039Z", "iopub.status.idle": "2026-06-30T22:27:30.279022Z", "shell.execute_reply": "2026-06-30T22:27:30.277966Z" } }, "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-06-30T22:27:30.280475Z", "iopub.status.busy": "2026-06-30T22:27:30.280343Z", "iopub.status.idle": "2026-06-30T22:27:30.285913Z", "shell.execute_reply": "2026-06-30T22:27:30.285118Z" } }, "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-06-30T22:27:30.287899Z", "iopub.status.busy": "2026-06-30T22:27:30.287675Z", "iopub.status.idle": "2026-06-30T22:27:30.588495Z", "shell.execute_reply": "2026-06-30T22:27:30.587577Z" } }, "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-06-30T22:27:30.590248Z", "iopub.status.busy": "2026-06-30T22:27:30.590052Z", "iopub.status.idle": "2026-06-30T22:27:31.562185Z", "shell.execute_reply": "2026-06-30T22:27:31.561446Z" } }, "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-06-30T22:27:31.571007Z", "iopub.status.busy": "2026-06-30T22:27:31.570825Z", "iopub.status.idle": "2026-06-30T22:27:31.875806Z", "shell.execute_reply": "2026-06-30T22:27:31.875055Z" } }, "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-06-30T22:27:31.878531Z", "iopub.status.busy": "2026-06-30T22:27:31.878355Z", "iopub.status.idle": "2026-06-30T22:27:31.881200Z", "shell.execute_reply": "2026-06-30T22:27:31.880571Z" } }, "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-06-30T22:27:31.883195Z", "iopub.status.busy": "2026-06-30T22:27:31.883023Z", "iopub.status.idle": "2026-06-30T22:27:31.886282Z", "shell.execute_reply": "2026-06-30T22:27:31.885439Z" } }, "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-06-30T22:27:31.888127Z", "iopub.status.busy": "2026-06-30T22:27:31.887967Z", "iopub.status.idle": "2026-06-30T22:27:31.892164Z", "shell.execute_reply": "2026-06-30T22:27:31.891234Z" } }, "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-06-30T22:27:31.893784Z", "iopub.status.busy": "2026-06-30T22:27:31.893565Z", "iopub.status.idle": "2026-06-30T22:27:31.970772Z", "shell.execute_reply": "2026-06-30T22:27:31.969574Z" } }, "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-06-30T22:27:31.972485Z", "iopub.status.busy": "2026-06-30T22:27:31.972302Z", "iopub.status.idle": "2026-06-30T22:27:31.977776Z", "shell.execute_reply": "2026-06-30T22:27:31.977087Z" } }, "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-06-30T22:27:31.979639Z", "iopub.status.busy": "2026-06-30T22:27:31.979466Z", "iopub.status.idle": "2026-06-30T22:28:28.972896Z", "shell.execute_reply": "2026-06-30T22:28:28.971948Z" } }, "outputs": [ { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function() {\n", " const button = document.getElementById('ed-fit-stop-93e05085bf9d4879bd8d68214fa95eb0-button');\n", " const status = document.getElementById('ed-fit-stop-93e05085bf9d4879bd8d68214fa95eb0-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.60988.58
2127.31135.1186.3% ↓
32314.1459.0756.3% ↓
43420.7154.008.6% ↓
54527.1953.031.8% ↓
65633.6153.00
76941.1453.00
88255.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;36m69\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)55.68
4πŸ“ Goodness-of-fit (reduced χ²)53.00
5πŸ“ R-factor (Rf, %)8.64
6πŸ“ R-factor squared (RfΒ², %)5.05
7πŸ“ Weighted R-factor (wR, %)4.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.42005.43060.00010.20 % ↑
2sepdlinked_structuresiscale634.3132634.23273.93840.01 % ↓
3sepdpeakbroad_lorentz_gamma_1ΞΌs/Γ…2.21002.23370.22711.07 % ↑
4sepdpeakbroad_gauss_sigma_1ΞΌs/Γ…33.190032.63481.85711.67 % ↓
5sepdinstrumentd_to_tof_offsetΞΌs-8.4000-8.06160.17684.03 % ↓
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.38480.03403.80 % ↓
10nomadpeaksharp_delta_2Γ…Β²3.00003.05140.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-06-30T22:28:28.974504Z", "iopub.status.busy": "2026-06-30T22:28:28.974339Z", "iopub.status.idle": "2026-06-30T22:28:29.050972Z", "shell.execute_reply": "2026-06-30T22:28:29.049957Z" } }, "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-06-30T22:28:29.060075Z", "iopub.status.busy": "2026-06-30T22:28:29.059891Z", "iopub.status.idle": "2026-06-30T22:28:29.100343Z", "shell.execute_reply": "2026-06-30T22:28:29.099338Z" } }, "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-06-30T22:28:29.102216Z", "iopub.status.busy": "2026-06-30T22:28:29.102035Z", "iopub.status.idle": "2026-06-30T22:28:29.882147Z", "shell.execute_reply": "2026-06-30T22:28:29.881246Z" } }, "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" ] }, { "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": [ "β”‚ └── πŸ“„ nomad.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_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.5" } }, "nbformat": 4, "nbformat_minor": 5 }