{
"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": [
""
],
"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": [
""
],
"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": [
""
],
"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": [
" | iteration | time (s) | ΟΒ² | change / status |
|---|
| 1 | 1 | 0.60 | 988.58 | |
|---|
| 2 | 12 | 7.31 | 135.11 | 86.3% β |
|---|
| 3 | 23 | 14.14 | 59.07 | 56.3% β |
|---|
| 4 | 34 | 20.71 | 54.00 | 8.6% β |
|---|
| 5 | 45 | 27.19 | 53.03 | 1.8% β |
|---|
| 6 | 56 | 33.61 | 53.00 | |
|---|
| 7 | 69 | 41.14 | 53.00 | |
|---|
| 8 | 82 | 55.68 | 53.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": [
" | Name | Value | Description |
|---|
| 1 | max_iterations | 1000 | Maximum solver iterations. |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Least-squares fit results:\n"
]
},
{
"data": {
"text/html": [
" | Metric | Value |
|---|
| 1 | π§ͺ Minimizer | bumps (lm) |
|---|
| 2 | β
Overall status | success |
|---|
| 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": [
" | datablock | category | entry | parameter | units | start | value | s.u. | change |
|---|
| 1 | si | cell | | length_a | Γ
| 5.4200 | 5.4306 | 0.0001 | 0.20 % β |
|---|
| 2 | sepd | linked_structure | si | scale | | 634.3132 | 634.2327 | 3.9384 | 0.01 % β |
|---|
| 3 | sepd | peak | | broad_lorentz_gamma_1 | ΞΌs/Γ
| 2.2100 | 2.2337 | 0.2271 | 1.07 % β |
|---|
| 4 | sepd | peak | | broad_gauss_sigma_1 | ΞΌs/Γ
| 33.1900 | 32.6348 | 1.8571 | 1.67 % β |
|---|
| 5 | sepd | instrument | | d_to_tof_offset | ΞΌs | -8.4000 | -8.0616 | 0.1768 | 4.03 % β |
|---|
| 6 | nomad | linked_structure | si | scale | | 1.6000 | 1.5668 | 0.0026 | 2.08 % β |
|---|
| 7 | nomad | peak | | damp_q | Γ
β»ΒΉ | 0.0200 | 0.0235 | 0.0001 | 17.67 % β |
|---|
| 8 | nomad | peak | | broad_q | Γ
β»Β² | 0.0300 | 0.0276 | 0.0001 | 8.14 % β |
|---|
| 9 | nomad | peak | | sharp_delta_1 | Γ
| 0.4000 | 0.3848 | 0.0340 | 3.80 % β |
|---|
| 10 | nomad | peak | | sharp_delta_2 | Γ
Β² | 3.0000 | 3.0514 | 0.0849 | 1.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",
""
],
"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": [
""
],
"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": [
""
],
"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
}