{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "0",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:38.865962Z",
"iopub.status.busy": "2026-06-30T22:33:38.865536Z",
"iopub.status.idle": "2026-06-30T22:33:38.872607Z",
"shell.execute_reply": "2026-06-30T22:33:38.870998Z"
},
"tags": [
"hide-in-docs"
]
},
"outputs": [],
"source": [
"# Check whether easydiffraction is installed; install it if needed.\n",
"# Required for remote environments such as Google Colab.\n",
"import importlib.util\n",
"\n",
"if importlib.util.find_spec('easydiffraction') is None:\n",
" %pip install easydiffraction==0.19.1"
]
},
{
"cell_type": "markdown",
"id": "1",
"metadata": {},
"source": [
"# Structure Refinement: NCAF, WISH\n",
"\n",
"This example demonstrates a Rietveld refinement of Na2Ca3Al2F14\n",
"crystal structure using time-of-flight neutron powder diffraction data\n",
"from WISH at ISIS.\n",
"\n",
"Two datasets from detector banks 5+6 and 4+7 are used for joint\n",
"fitting."
]
},
{
"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:33:38.875194Z",
"iopub.status.busy": "2026-06-30T22:33:38.874776Z",
"iopub.status.idle": "2026-06-30T22:33:41.679162Z",
"shell.execute_reply": "2026-06-30T22:33:41.678272Z"
}
},
"outputs": [],
"source": [
"from easydiffraction import ExperimentFactory\n",
"from easydiffraction import Project\n",
"from easydiffraction import StructureFactory\n",
"from easydiffraction import download_data"
]
},
{
"cell_type": "markdown",
"id": "4",
"metadata": {},
"source": [
"## 🧩 Define Structure\n",
"\n",
"This section covers how to add structures and modify their\n",
"parameters.\n",
"\n",
"### Create Structure"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:41.681140Z",
"iopub.status.busy": "2026-06-30T22:33:41.680740Z",
"iopub.status.idle": "2026-06-30T22:33:41.687407Z",
"shell.execute_reply": "2026-06-30T22:33:41.686306Z"
}
},
"outputs": [],
"source": [
"structure = StructureFactory.from_scratch(name='ncaf')"
]
},
{
"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:33:41.689029Z",
"iopub.status.busy": "2026-06-30T22:33:41.688805Z",
"iopub.status.idle": "2026-06-30T22:33:41.692414Z",
"shell.execute_reply": "2026-06-30T22:33:41.691522Z"
}
},
"outputs": [],
"source": [
"structure.space_group.name_h_m = 'I 21 3'\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:33:41.694065Z",
"iopub.status.busy": "2026-06-30T22:33:41.693823Z",
"iopub.status.idle": "2026-06-30T22:33:41.697210Z",
"shell.execute_reply": "2026-06-30T22:33:41.696338Z"
}
},
"outputs": [],
"source": [
"structure.cell.length_a = 10.250256"
]
},
{
"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:33:41.698669Z",
"iopub.status.busy": "2026-06-30T22:33:41.698519Z",
"iopub.status.idle": "2026-06-30T22:33:41.706777Z",
"shell.execute_reply": "2026-06-30T22:33:41.705925Z"
}
},
"outputs": [],
"source": [
"structure.atom_sites.create(\n",
" id='Ca',\n",
" type_symbol='Ca',\n",
" fract_x=0.4663,\n",
" fract_y=0.0,\n",
" fract_z=0.25,\n",
" adp_iso=0.92,\n",
")\n",
"structure.atom_sites.create(\n",
" id='Al',\n",
" type_symbol='Al',\n",
" fract_x=0.2521,\n",
" fract_y=0.2521,\n",
" fract_z=0.2521,\n",
" adp_iso=0.73,\n",
")\n",
"structure.atom_sites.create(\n",
" id='Na',\n",
" type_symbol='Na',\n",
" fract_x=0.0851,\n",
" fract_y=0.0851,\n",
" fract_z=0.0851,\n",
" adp_iso=2.08,\n",
")\n",
"structure.atom_sites.create(\n",
" id='F1',\n",
" type_symbol='F',\n",
" fract_x=0.1377,\n",
" fract_y=0.3054,\n",
" fract_z=0.1195,\n",
" adp_iso=0.90,\n",
")\n",
"structure.atom_sites.create(\n",
" id='F2',\n",
" type_symbol='F',\n",
" fract_x=0.3625,\n",
" fract_y=0.3633,\n",
" fract_z=0.1867,\n",
" adp_iso=1.37,\n",
")\n",
"structure.atom_sites.create(\n",
" id='F3',\n",
" type_symbol='F',\n",
" fract_x=0.4612,\n",
" fract_y=0.4612,\n",
" fract_z=0.4612,\n",
" adp_iso=0.88,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "12",
"metadata": {},
"source": [
"## 🔬 Define Experiment\n",
"\n",
"This section shows how to add experiments, configure their parameters,\n",
"and link the structures defined in the previous step.\n",
"\n",
"### Download Data"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "13",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:41.708544Z",
"iopub.status.busy": "2026-06-30T22:33:41.708404Z",
"iopub.status.idle": "2026-06-30T22:33:41.896076Z",
"shell.execute_reply": "2026-06-30T22:33:41.895235Z"
}
},
"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-ncaf-wish-b56'\u001b[0m: NCAF, WISH \u001b[1m(\u001b[0mISIS\u001b[1m)\u001b[0m, Detector banks \u001b[1;36m5\u001b[0m & \u001b[1;36m6\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Data \u001b[32m'meas-ncaf-wish-b56'\u001b[0m downloaded to \u001b[32m'../../../data/meas-ncaf-wish-b56.xys'\u001b[0m\n"
]
}
],
"source": [
"data_path56 = download_data('meas-ncaf-wish-b56', destination='data')"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "14",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:41.897884Z",
"iopub.status.busy": "2026-06-30T22:33:41.897703Z",
"iopub.status.idle": "2026-06-30T22:33:42.088647Z",
"shell.execute_reply": "2026-06-30T22:33:42.087835Z"
}
},
"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-ncaf-wish-b47'\u001b[0m: NCAF, WISH \u001b[1m(\u001b[0mISIS\u001b[1m)\u001b[0m, Detector banks \u001b[1;36m4\u001b[0m & \u001b[1;36m7\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Data \u001b[32m'meas-ncaf-wish-b47'\u001b[0m downloaded to \u001b[32m'../../../data/meas-ncaf-wish-b47.xys'\u001b[0m\n"
]
}
],
"source": [
"data_path47 = download_data('meas-ncaf-wish-b47', destination='data')"
]
},
{
"cell_type": "markdown",
"id": "15",
"metadata": {},
"source": [
"### Create Experiment"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "16",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:42.090798Z",
"iopub.status.busy": "2026-06-30T22:33:42.090564Z",
"iopub.status.idle": "2026-06-30T22:33:42.664276Z",
"shell.execute_reply": "2026-06-30T22:33:42.663286Z"
}
},
"outputs": [],
"source": [
"expt56 = ExperimentFactory.from_data_path(\n",
" name='wish_5_6',\n",
" data_path=data_path56,\n",
" beam_mode='time-of-flight',\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "17",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:42.666044Z",
"iopub.status.busy": "2026-06-30T22:33:42.665860Z",
"iopub.status.idle": "2026-06-30T22:33:43.150945Z",
"shell.execute_reply": "2026-06-30T22:33:43.149939Z"
}
},
"outputs": [],
"source": [
"expt47 = ExperimentFactory.from_data_path(\n",
" name='wish_4_7',\n",
" data_path=data_path47,\n",
" beam_mode='time-of-flight',\n",
")"
]
},
{
"cell_type": "markdown",
"id": "18",
"metadata": {},
"source": [
"### Set Instrument"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "19",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.152844Z",
"iopub.status.busy": "2026-06-30T22:33:43.152540Z",
"iopub.status.idle": "2026-06-30T22:33:43.157031Z",
"shell.execute_reply": "2026-06-30T22:33:43.155903Z"
}
},
"outputs": [],
"source": [
"expt56.instrument.setup_twotheta_bank = 152.827\n",
"expt56.instrument.calib_d_to_tof_offset = -13.5\n",
"expt56.instrument.calib_d_to_tof_linear = 20773.0\n",
"expt56.instrument.calib_d_to_tof_quadratic = -1.08308"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "20",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.158614Z",
"iopub.status.busy": "2026-06-30T22:33:43.158450Z",
"iopub.status.idle": "2026-06-30T22:33:43.161560Z",
"shell.execute_reply": "2026-06-30T22:33:43.160899Z"
}
},
"outputs": [],
"source": [
"expt47.instrument.setup_twotheta_bank = 121.660\n",
"expt47.instrument.calib_d_to_tof_offset = -15.0\n",
"expt47.instrument.calib_d_to_tof_linear = 18660.0\n",
"expt47.instrument.calib_d_to_tof_quadratic = -0.47488"
]
},
{
"cell_type": "markdown",
"id": "21",
"metadata": {},
"source": [
"### Set Peak Profile"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "22",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.163426Z",
"iopub.status.busy": "2026-06-30T22:33:43.163199Z",
"iopub.status.idle": "2026-06-30T22:33:43.177199Z",
"shell.execute_reply": "2026-06-30T22:33:43.176232Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mPeak types\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"
| | Type | Description |
|---|
| 1 | | pseudo-voigt | TOF non-convoluted pseudo-Voigt profile |
|---|
| 2 | * | jorgensen | TOF Jorgensen profile: back-to-back exponentials ⊗ Gaussian |
|---|
| 3 | | jorgensen-von-dreele | TOF Jorgensen-Von Dreele profile: back-to-back exponentials ⊗ pseudo-Voigt |
|---|
| 4 | | double-jorgensen-von-dreele | TOF Double-Jorgensen-Von Dreele profile: double back-to-back exponentials ⊗ pseudo-Voigt (Z-Rietveld type0m) |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"expt56.peak.show_supported()\n",
"expt56.peak.broad_gauss_sigma_0 = 0.0\n",
"expt56.peak.broad_gauss_sigma_1 = 0.0\n",
"expt56.peak.broad_gauss_sigma_2 = 15.5\n",
"expt56.peak.decay_beta_0 = 0.007\n",
"expt56.peak.decay_beta_1 = 0.01\n",
"expt56.peak.rise_alpha_0 = -0.0094\n",
"expt56.peak.rise_alpha_1 = 0.1\n",
"expt56.peak.cutoff_fwhm = 20"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "23",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.178677Z",
"iopub.status.busy": "2026-06-30T22:33:43.178526Z",
"iopub.status.idle": "2026-06-30T22:33:43.182266Z",
"shell.execute_reply": "2026-06-30T22:33:43.181495Z"
}
},
"outputs": [],
"source": [
"expt47.peak.broad_gauss_sigma_0 = 0.0\n",
"expt47.peak.broad_gauss_sigma_1 = 29.8\n",
"expt47.peak.broad_gauss_sigma_2 = 18.0\n",
"expt47.peak.decay_beta_0 = 0.006\n",
"expt47.peak.decay_beta_1 = 0.015\n",
"expt47.peak.rise_alpha_0 = -0.0115\n",
"expt47.peak.rise_alpha_1 = 0.1\n",
"expt47.peak.cutoff_fwhm = 20"
]
},
{
"cell_type": "markdown",
"id": "24",
"metadata": {},
"source": [
"### Set Background"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "25",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.183813Z",
"iopub.status.busy": "2026-06-30T22:33:43.183667Z",
"iopub.status.idle": "2026-06-30T22:33:43.200373Z",
"shell.execute_reply": "2026-06-30T22:33:43.199030Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mBackground types\u001b[0m\n"
]
},
{
"data": {
"text/html": [
" | | Type | Description |
|---|
| 1 | | chebyshev | Chebyshev polynomial background |
|---|
| 2 | * | line-segment | Linear interpolation between points |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mBackground type for experiment \u001b[0m\u001b[32m'wish_5_6'\u001b[0m\u001b[1;36m already set to\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"line-segment\n"
]
}
],
"source": [
"expt56.background.show_supported()\n",
"expt56.background.type = 'line-segment'\n",
"for idx, (x, y) in enumerate(\n",
" [\n",
" (9162, 465),\n",
" (11136, 593),\n",
" (13313, 497),\n",
" (14906, 546),\n",
" (16454, 533),\n",
" (17352, 496),\n",
" (18743, 428),\n",
" (20179, 452),\n",
" (21368, 397),\n",
" (22176, 468),\n",
" (22827, 477),\n",
" (24644, 380),\n",
" (26439, 381),\n",
" (28257, 378),\n",
" (31196, 343),\n",
" (34034, 328),\n",
" (37265, 310),\n",
" (41214, 323),\n",
" (44827, 283),\n",
" (49830, 273),\n",
" (52905, 257),\n",
" (58204, 260),\n",
" (62916, 261),\n",
" (70186, 262),\n",
" (74204, 262),\n",
" (82103, 268),\n",
" (91958, 268),\n",
" (102712, 262),\n",
" ],\n",
" start=1,\n",
"):\n",
" expt56.background.create(id=str(idx), position=x, intensity=y)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "26",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.202122Z",
"iopub.status.busy": "2026-06-30T22:33:43.201860Z",
"iopub.status.idle": "2026-06-30T22:33:43.215471Z",
"shell.execute_reply": "2026-06-30T22:33:43.214749Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mBackground type for experiment \u001b[0m\u001b[32m'wish_4_7'\u001b[0m\u001b[1;36m already set to\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"line-segment\n"
]
}
],
"source": [
"expt47.background.type = 'line-segment'\n",
"for idx, (x, y) in enumerate(\n",
" [\n",
" (9090, 488),\n",
" (10672, 566),\n",
" (12287, 494),\n",
" (14037, 559),\n",
" (15451, 529),\n",
" (16764, 445),\n",
" (18076, 460),\n",
" (19456, 413),\n",
" (20466, 511),\n",
" (21880, 396),\n",
" (23798, 391),\n",
" (25447, 385),\n",
" (28073, 349),\n",
" (30058, 332),\n",
" (32583, 309),\n",
" (34804, 355),\n",
" (37160, 318),\n",
" (40324, 290),\n",
" (46895, 260),\n",
" (50631, 256),\n",
" (54602, 246),\n",
" (58439, 264),\n",
" (66520, 250),\n",
" (75002, 258),\n",
" (83649, 257),\n",
" (92770, 255),\n",
" (101524, 260),\n",
" ],\n",
" start=1,\n",
"):\n",
" expt47.background.create(id=str(idx), position=x, intensity=y)"
]
},
{
"cell_type": "markdown",
"id": "27",
"metadata": {},
"source": [
"### Set Linked Structures"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "28",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.217509Z",
"iopub.status.busy": "2026-06-30T22:33:43.217350Z",
"iopub.status.idle": "2026-06-30T22:33:43.220715Z",
"shell.execute_reply": "2026-06-30T22:33:43.219626Z"
}
},
"outputs": [],
"source": [
"expt56.linked_structures.create(structure_id='ncaf', scale=78.0)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "29",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.222138Z",
"iopub.status.busy": "2026-06-30T22:33:43.221989Z",
"iopub.status.idle": "2026-06-30T22:33:43.224985Z",
"shell.execute_reply": "2026-06-30T22:33:43.224213Z"
}
},
"outputs": [],
"source": [
"expt47.linked_structures.create(structure_id='ncaf', scale=37.0)"
]
},
{
"cell_type": "markdown",
"id": "30",
"metadata": {},
"source": [
"### Set Excluded Regions"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "31",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.226424Z",
"iopub.status.busy": "2026-06-30T22:33:43.226287Z",
"iopub.status.idle": "2026-06-30T22:33:43.229975Z",
"shell.execute_reply": "2026-06-30T22:33:43.228810Z"
}
},
"outputs": [],
"source": [
"expt56.excluded_regions.create(id='1', start=0, end=10010)\n",
"expt56.excluded_regions.create(id='2', start=100010, end=200000)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "32",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.231434Z",
"iopub.status.busy": "2026-06-30T22:33:43.231285Z",
"iopub.status.idle": "2026-06-30T22:33:43.234487Z",
"shell.execute_reply": "2026-06-30T22:33:43.233723Z"
}
},
"outputs": [],
"source": [
"expt47.excluded_regions.create(id='1', start=0, end=10006)\n",
"expt47.excluded_regions.create(id='2', start=100004, end=200000)"
]
},
{
"cell_type": "markdown",
"id": "33",
"metadata": {},
"source": [
"## 📦 Define Project\n",
"\n",
"The project object is used to manage the structure, experiments,\n",
"and analysis\n",
"\n",
"### Create Project"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "34",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.235965Z",
"iopub.status.busy": "2026-06-30T22:33:43.235818Z",
"iopub.status.idle": "2026-06-30T22:33:43.452928Z",
"shell.execute_reply": "2026-06-30T22:33:43.452002Z"
}
},
"outputs": [],
"source": [
"project = Project(name='ncaf_wish')"
]
},
{
"cell_type": "markdown",
"id": "35",
"metadata": {},
"source": [
"### Add Structure"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "36",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.454661Z",
"iopub.status.busy": "2026-06-30T22:33:43.454451Z",
"iopub.status.idle": "2026-06-30T22:33:43.457737Z",
"shell.execute_reply": "2026-06-30T22:33:43.456804Z"
}
},
"outputs": [],
"source": [
"project.structures.add(structure)"
]
},
{
"cell_type": "markdown",
"id": "37",
"metadata": {},
"source": [
"### Add Experiment"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "38",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.459280Z",
"iopub.status.busy": "2026-06-30T22:33:43.459065Z",
"iopub.status.idle": "2026-06-30T22:33:43.462152Z",
"shell.execute_reply": "2026-06-30T22:33:43.461399Z"
}
},
"outputs": [],
"source": [
"project.experiments.add(expt56)\n",
"project.experiments.add(expt47)"
]
},
{
"cell_type": "markdown",
"id": "39",
"metadata": {},
"source": [
"## 🚀 Perform Analysis\n",
"\n",
"This section shows the analysis process, including how to set up\n",
"calculation and fitting engines.\n",
"\n",
"### Set Fit Mode"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "40",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.463647Z",
"iopub.status.busy": "2026-06-30T22:33:43.463492Z",
"iopub.status.idle": "2026-06-30T22:33:43.472226Z",
"shell.execute_reply": "2026-06-30T22:33:43.471476Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mFitting Mode types\u001b[0m\n"
]
},
{
"data": {
"text/html": [
" | | Type | Description |
|---|
| 1 | | joint | Fit several experiments together with shared parameters. |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"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.show_supported()\n",
"project.analysis.fitting_mode.type = 'joint'"
]
},
{
"cell_type": "markdown",
"id": "41",
"metadata": {},
"source": [
"### Set Free Parameters"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "42",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.473812Z",
"iopub.status.busy": "2026-06-30T22:33:43.473656Z",
"iopub.status.idle": "2026-06-30T22:33:43.477430Z",
"shell.execute_reply": "2026-06-30T22:33:43.476303Z"
}
},
"outputs": [],
"source": [
"structure.atom_sites['Ca'].adp_iso.free = True\n",
"structure.atom_sites['Al'].adp_iso.free = True\n",
"structure.atom_sites['Na'].adp_iso.free = True\n",
"structure.atom_sites['F1'].adp_iso.free = True\n",
"structure.atom_sites['F2'].adp_iso.free = True\n",
"structure.atom_sites['F3'].adp_iso.free = True"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "43",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.479221Z",
"iopub.status.busy": "2026-06-30T22:33:43.478956Z",
"iopub.status.idle": "2026-06-30T22:33:43.485652Z",
"shell.execute_reply": "2026-06-30T22:33:43.484515Z"
}
},
"outputs": [],
"source": [
"expt56.linked_structures['ncaf'].scale.free = True\n",
"expt56.instrument.calib_d_to_tof_offset.free = True\n",
"expt56.instrument.calib_d_to_tof_linear.free = True\n",
"expt56.peak.broad_gauss_sigma_2.free = True\n",
"expt56.peak.decay_beta_0.free = True\n",
"expt56.peak.decay_beta_1.free = True\n",
"expt56.peak.rise_alpha_1.free = True\n",
"\n",
"expt47.linked_structures['ncaf'].scale.free = True\n",
"expt47.instrument.calib_d_to_tof_linear.free = True\n",
"expt47.instrument.calib_d_to_tof_offset.free = True\n",
"expt47.peak.broad_gauss_sigma_2.free = True\n",
"expt47.peak.decay_beta_0.free = True\n",
"expt47.peak.decay_beta_1.free = True\n",
"expt47.peak.rise_alpha_1.free = True"
]
},
{
"cell_type": "markdown",
"id": "44",
"metadata": {},
"source": [
"### Display Structure"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "45",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.487337Z",
"iopub.status.busy": "2026-06-30T22:33:43.487125Z",
"iopub.status.idle": "2026-06-30T22:33:43.662644Z",
"shell.execute_reply": "2026-06-30T22:33:43.661952Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mStructure 🧩 \u001b[0m\u001b[32m'ncaf'\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='ncaf')"
]
},
{
"cell_type": "markdown",
"id": "46",
"metadata": {},
"source": [
"### Display Pattern"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "47",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:43.664948Z",
"iopub.status.busy": "2026-06-30T22:33:43.664785Z",
"iopub.status.idle": "2026-06-30T22:33:44.761531Z",
"shell.execute_reply": "2026-06-30T22:33:44.760433Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='wish_5_6')"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "48",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:44.768693Z",
"iopub.status.busy": "2026-06-30T22:33:44.768505Z",
"iopub.status.idle": "2026-06-30T22:33:45.763488Z",
"shell.execute_reply": "2026-06-30T22:33:45.761931Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='wish_4_7')"
]
},
{
"cell_type": "markdown",
"id": "49",
"metadata": {},
"source": [
"### Run Fitting"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "50",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:33:45.769404Z",
"iopub.status.busy": "2026-06-30T22:33:45.769214Z",
"iopub.status.idle": "2026-06-30T22:36:16.576493Z",
"shell.execute_reply": "2026-06-30T22:36:16.575819Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-de4c905579cc43e7895b37548ffecd0b-button');\n",
" const status = document.getElementById('ed-fit-stop-de4c905579cc43e7895b37548ffecd0b-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'wish_5_6'\u001b[0m\u001b[1;36m, \u001b[0m\u001b[32m'wish_4_7'\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'lmfit \u001b[0m\u001b[32m(\u001b[0m\u001b[32mleastsq\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 | 1.23 | 21.64 | |
|---|
| 2 | 6 | 7.10 | 21.64 | |
|---|
| 3 | 11 | 13.02 | 21.64 | |
|---|
| 4 | 16 | 19.05 | 21.35 | 1.3% ↓ |
|---|
| 5 | 21 | 24.93 | 21.64 | |
|---|
| 6 | 24 | 28.17 | 15.59 | 27.0% ↓ |
|---|
| 7 | 29 | 34.31 | 15.59 | |
|---|
| 8 | 34 | 40.10 | 15.59 | |
|---|
| 9 | 39 | 45.89 | 15.59 | |
|---|
| 10 | 44 | 51.66 | 15.58 | |
|---|
| 11 | 49 | 57.43 | 15.49 | |
|---|
| 12 | 54 | 63.23 | 15.49 | |
|---|
| 13 | 59 | 69.00 | 15.49 | |
|---|
| 14 | 64 | 74.74 | 15.49 | |
|---|
| 15 | 68 | 79.80 | 15.49 | |
|---|
| 16 | 73 | 85.79 | 15.49 | |
|---|
| 17 | 77 | 91.21 | 15.49 | |
|---|
| 18 | 80 | 97.10 | 15.49 | |
|---|
| 19 | 83 | 102.64 | 15.49 | |
|---|
| 20 | 86 | 108.68 | 15.50 | |
|---|
| 21 | 89 | 114.23 | 15.49 | |
|---|
| 22 | 92 | 120.19 | 15.49 | |
|---|
| 23 | 95 | 125.67 | 15.49 | |
|---|
| 24 | 98 | 131.72 | 15.49 | |
|---|
| 25 | 101 | 137.30 | 15.49 | |
|---|
| 26 | 104 | 142.44 | 15.49 | |
|---|
| 27 | 109 | 149.13 | 15.49 | |
|---|
"
],
"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;36m15.49\u001b[0m at iteration \u001b[1;36m104\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 | lmfit (leastsq) |
|---|
| 2 | ✅ Overall status | success |
|---|
| 3 | ⏱️ Fitting time (seconds) | 149.13 |
|---|
| 4 | 🔁 Iterations | 106 |
|---|
| 5 | 📏 Goodness-of-fit (reduced χ²) | 15.49 |
|---|
| 6 | 📏 R-factor (Rf, %) | 6.98 |
|---|
| 7 | 📏 R-factor squared (Rf², %) | 8.05 |
|---|
| 8 | 📏 Weighted R-factor (wR, %) | 9.15 |
|---|
"
],
"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 | ncaf | atom_site | Ca | adp_iso | Ų | 0.9200 | 0.9340 | 0.0448 | 1.52 % ↑ |
|---|
| 2 | ncaf | atom_site | Al | adp_iso | Ų | 0.7300 | 0.7330 | 0.0569 | 0.41 % ↑ |
|---|
| 3 | ncaf | atom_site | Na | adp_iso | Ų | 2.0800 | 2.0474 | 0.1082 | 1.57 % ↓ |
|---|
| 4 | ncaf | atom_site | F1 | adp_iso | Ų | 0.9000 | 0.9389 | 0.0373 | 4.32 % ↑ |
|---|
| 5 | ncaf | atom_site | F2 | adp_iso | Ų | 1.3700 | 1.3442 | 0.0408 | 1.88 % ↓ |
|---|
| 6 | ncaf | atom_site | F3 | adp_iso | Ų | 0.8800 | 0.8481 | 0.0551 | 3.62 % ↓ |
|---|
| 7 | wish_5_6 | linked_structure | ncaf | scale | | 78.0000 | 77.7040 | 0.2489 | 0.38 % ↓ |
|---|
| 8 | wish_5_6 | peak | | rise_alpha_1 | μs/Å | 0.1000 | 0.1094 | 0.0012 | 9.43 % ↑ |
|---|
| 9 | wish_5_6 | peak | | decay_beta_0 | μs | 0.0070 | 0.0067 | 0.0000 | 4.54 % ↓ |
|---|
| 10 | wish_5_6 | peak | | decay_beta_1 | μs/Å | 0.0100 | 0.0101 | 0.0002 | 1.46 % ↑ |
|---|
| 11 | wish_5_6 | peak | | broad_gauss_sigma_2 | μs²/Ų | 15.5000 | 15.6544 | 0.7398 | 1.00 % ↑ |
|---|
| 12 | wish_5_6 | instrument | | d_to_tof_offset | μs | -13.5000 | -13.6259 | 0.4257 | 0.93 % ↑ |
|---|
| 13 | wish_5_6 | instrument | | d_to_tof_linear | μs/Å | 20773.0000 | 20773.0394 | 0.3051 | 0.00 % ↑ |
|---|
| 14 | wish_4_7 | linked_structure | ncaf | scale | | 37.0000 | 37.0734 | 0.1134 | 0.20 % ↑ |
|---|
| 15 | wish_4_7 | peak | | rise_alpha_1 | μs/Å | 0.1000 | 0.1222 | 0.0018 | 22.15 % ↑ |
|---|
| 16 | wish_4_7 | peak | | decay_beta_0 | μs | 0.0060 | 0.0065 | 0.0000 | 7.52 % ↑ |
|---|
| 17 | wish_4_7 | peak | | decay_beta_1 | μs/Å | 0.0150 | 0.0148 | 0.0003 | 1.38 % ↓ |
|---|
| 18 | wish_4_7 | peak | | broad_gauss_sigma_2 | μs²/Ų | 18.0000 | 18.2610 | 0.8685 | 1.45 % ↑ |
|---|
| 19 | wish_4_7 | instrument | | d_to_tof_offset | μs | -15.0000 | -14.9767 | 0.5084 | 0.16 % ↓ |
|---|
| 20 | wish_4_7 | instrument | | d_to_tof_linear | μs/Å | 18660.0000 | 18660.1025 | 0.3625 | 0.00 % ↑ |
|---|
"
],
"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": "51",
"metadata": {},
"source": [
"### Display Pattern"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "52",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:36:16.578101Z",
"iopub.status.busy": "2026-06-30T22:36:16.577932Z",
"iopub.status.idle": "2026-06-30T22:36:16.659086Z",
"shell.execute_reply": "2026-06-30T22:36:16.658055Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='wish_5_6')"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "53",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:36:16.666629Z",
"iopub.status.busy": "2026-06-30T22:36:16.666452Z",
"iopub.status.idle": "2026-06-30T22:36:17.133935Z",
"shell.execute_reply": "2026-06-30T22:36:17.132927Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='wish_4_7')"
]
},
{
"cell_type": "markdown",
"id": "54",
"metadata": {},
"source": [
"## 📊 Report\n",
"\n",
"The HTML report is written automatically when the project is saved;\n",
"enable `project.report.pdf` as well for a PDF version."
]
},
{
"cell_type": "markdown",
"id": "55",
"metadata": {},
"source": [
"## 💾 Save Project"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "56",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:36:17.140144Z",
"iopub.status.busy": "2026-06-30T22:36:17.139959Z",
"iopub.status.idle": "2026-06-30T22:36:18.506963Z",
"shell.execute_reply": "2026-06-30T22:36:18.506190Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mSaving project 📦 \u001b[0m\u001b[32m'ncaf_wish'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/refine-ncaf-wish'\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": [
"│ └── 📄 ncaf.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"├── 📁 experiments/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"│ └── 📄 wish_5_6.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"│ └── 📄 wish_4_7.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": [
" └── 📄 ncaf_wish.html\n"
]
}
],
"source": [
"project.save_as(dir_path='projects/refine-ncaf-wish')"
]
}
],
"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
}