{ "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": [ "
TypeDescription
1pseudo-voigtTOF non-convoluted pseudo-Voigt profile
2*jorgensenTOF Jorgensen profile: back-to-back exponentials ⊗ Gaussian
3jorgensen-von-dreeleTOF Jorgensen-Von Dreele profile: back-to-back exponentials ⊗ pseudo-Voigt
4double-jorgensen-von-dreeleTOF Double-Jorgensen-Von Dreele profile: double back-to-back exponentials ⊗ pseudo-Voigt (Z-Rietveld type0m)
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "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": [ "
TypeDescription
1chebyshevChebyshev polynomial background
2*line-segmentLinear 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": [ "
TypeDescription
1jointFit 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": [ "
Loading plot…
" ], "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": [ "
Loading plot…
" ], "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": [ "
iterationtime (s)χ²change / status
111.2321.64
267.1021.64
31113.0221.64
41619.0521.351.3% ↓
52124.9321.64
62428.1715.5927.0% ↓
72934.3115.59
83440.1015.59
93945.8915.59
104451.6615.58
114957.4315.49
125463.2315.49
135969.0015.49
146474.7415.49
156879.8015.49
167385.7915.49
177791.2115.49
188097.1015.49
1983102.6415.49
2086108.6815.50
2189114.2315.49
2292120.1915.49
2395125.6715.49
2498131.7215.49
25101137.3015.49
26104142.4415.49
27109149.1315.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": [ "
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🧪 Minimizerlmfit (leastsq)
2✅ Overall statussuccess
3⏱️ Fitting time (seconds)149.13
4🔁 Iterations106
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": [ "
datablockcategoryentryparameterunitsstartvalues.u.change
1ncafatom_siteCaadp_isoŲ0.92000.93400.04481.52 % ↑
2ncafatom_siteAladp_isoŲ0.73000.73300.05690.41 % ↑
3ncafatom_siteNaadp_isoŲ2.08002.04740.10821.57 % ↓
4ncafatom_siteF1adp_isoŲ0.90000.93890.03734.32 % ↑
5ncafatom_siteF2adp_isoŲ1.37001.34420.04081.88 % ↓
6ncafatom_siteF3adp_isoŲ0.88000.84810.05513.62 % ↓
7wish_5_6linked_structurencafscale78.000077.70400.24890.38 % ↓
8wish_5_6peakrise_alpha_1μs/Å0.10000.10940.00129.43 % ↑
9wish_5_6peakdecay_beta_0μs0.00700.00670.00004.54 % ↓
10wish_5_6peakdecay_beta_1μs/Å0.01000.01010.00021.46 % ↑
11wish_5_6peakbroad_gauss_sigma_2μs²/Ų15.500015.65440.73981.00 % ↑
12wish_5_6instrumentd_to_tof_offsetμs-13.5000-13.62590.42570.93 % ↑
13wish_5_6instrumentd_to_tof_linearμs/Å20773.000020773.03940.30510.00 % ↑
14wish_4_7linked_structurencafscale37.000037.07340.11340.20 % ↑
15wish_4_7peakrise_alpha_1μs/Å0.10000.12220.001822.15 % ↑
16wish_4_7peakdecay_beta_0μs0.00600.00650.00007.52 % ↑
17wish_4_7peakdecay_beta_1μs/Å0.01500.01480.00031.38 % ↓
18wish_4_7peakbroad_gauss_sigma_2μs²/Ų18.000018.26100.86851.45 % ↑
19wish_4_7instrumentd_to_tof_offsetμs-15.0000-14.97670.50840.16 % ↓
20wish_4_7instrumentd_to_tof_linearμs/Å18660.000018660.10250.36250.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", "
\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": "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": [ "
Loading plot…
" ], "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": [ "
Loading plot…
" ], "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 }