{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:49.718923Z", "iopub.status.busy": "2026-04-14T14:55:49.718738Z", "iopub.status.idle": "2026-04-14T14:55:49.722881Z", "shell.execute_reply": "2026-04-14T14:55:49.722072Z" }, "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.13.1" ] }, { "cell_type": "markdown", "id": "1", "metadata": {}, "source": [ "# Structure Refinement: Co2SiO4, D20 (T-scan)\n", "\n", "This example demonstrates a Rietveld refinement of the Co2SiO4 crystal\n", "structure using constant-wavelength neutron powder diffraction data\n", "from D20 at ILL. A sequential refinement is performed against a\n", "temperature scan using `fit_sequential`, which processes each data\n", "file independently without loading all datasets into memory at once." ] }, { "cell_type": "markdown", "id": "2", "metadata": {}, "source": [ "## Import Library" ] }, { "cell_type": "code", "execution_count": 2, "id": "3", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:49.724528Z", "iopub.status.busy": "2026-04-14T14:55:49.724325Z", "iopub.status.idle": "2026-04-14T14:55:52.258676Z", "shell.execute_reply": "2026-04-14T14:55:52.257717Z" } }, "outputs": [], "source": [ "import easydiffraction as ed" ] }, { "cell_type": "markdown", "id": "4", "metadata": {}, "source": [ "## Step 1: Define Project\n", "\n", "The project object manages structures, experiments, and analysis." ] }, { "cell_type": "code", "execution_count": 3, "id": "5", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:52.260431Z", "iopub.status.busy": "2026-04-14T14:55:52.260148Z", "iopub.status.idle": "2026-04-14T14:55:52.742727Z", "shell.execute_reply": "2026-04-14T14:55:52.741842Z" } }, "outputs": [ { "data": { "application/javascript": [ "\n", " (function() {\n", " var isDark = false;\n", "\n", " // Check JupyterLab theme\n", " if (document.body.classList.contains('jp-mod-dark') || \n", " document.body.classList.contains('theme-dark') ||\n", " document.body.classList.contains('vscode-dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check theme attribute\n", " var themeAttr = document.body.getAttribute('data-jp-theme-name');\n", " if (themeAttr && themeAttr.includes('dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check computed background color\n", " var notebookEl = document.querySelector('.jp-Notebook') || \n", " document.querySelector('.notebook_app') ||\n", " document.body;\n", " if (notebookEl) {\n", " var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n", " var rgb = bgColor.match(/\\d+/g);\n", " if (rgb && rgb.length >= 3) {\n", " var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n", " if (brightness < 128) {\n", " isDark = true;\n", " }\n", " }\n", " }\n", "\n", " // Store result\n", " if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n", " IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n", " }\n", " })();\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " if (typeof IPython !== 'undefined' && IPython.notebook) {\n", " IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n", " (document.body.classList.contains('theme-dark') || \n", " document.body.classList.contains('jp-mod-dark') ||\n", " (document.body.getAttribute('data-jp-theme-name') && \n", " document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n", " }\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project = ed.Project()" ] }, { "cell_type": "markdown", "id": "6", "metadata": {}, "source": [ "The project must be saved before running sequential fitting, so that\n", "results can be written to `analysis/results.csv`." ] }, { "cell_type": "code", "execution_count": 4, "id": "7", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:52.744403Z", "iopub.status.busy": "2026-04-14T14:55:52.744240Z", "iopub.status.idle": "2026-04-14T14:55:52.759626Z", "shell.execute_reply": "2026-04-14T14:55:52.758782Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;34mSaving project 📦 \u001b[0m\u001b[32m'untitled_project'\u001b[0m\u001b[1;34m to\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\u001b[35m/home/runner/work/diffraction-lib/diffraction-lib/docs/docs/tutorials/data/\u001b[0m\u001b[95mcosio_project\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "├── 📄 project.cif\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "├── 📁 structures/\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "├── 📁 experiments/\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "├── 📁 analysis/\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "│ └── 📄 analysis.cif\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "└── 📄 summary.cif\n" ] } ], "source": [ "project.save_as('data/cosio_project', temporary=False)" ] }, { "cell_type": "markdown", "id": "8", "metadata": {}, "source": [ "## Step 2: Define Crystal Structure\n", "\n", "This section shows how to add structures and modify their\n", "parameters.\n", "\n", "#### Create Structure" ] }, { "cell_type": "code", "execution_count": 5, "id": "9", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:52.761246Z", "iopub.status.busy": "2026-04-14T14:55:52.761053Z", "iopub.status.idle": "2026-04-14T14:55:52.764631Z", "shell.execute_reply": "2026-04-14T14:55:52.763821Z" } }, "outputs": [], "source": [ "project.structures.create(name='cosio')\n", "structure = project.structures['cosio']" ] }, { "cell_type": "markdown", "id": "10", "metadata": {}, "source": [ "#### Set Space Group" ] }, { "cell_type": "code", "execution_count": 6, "id": "11", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:52.766152Z", "iopub.status.busy": "2026-04-14T14:55:52.765976Z", "iopub.status.idle": "2026-04-14T14:55:52.769036Z", "shell.execute_reply": "2026-04-14T14:55:52.768185Z" } }, "outputs": [], "source": [ "structure.space_group.name_h_m = 'P n m a'\n", "structure.space_group.it_coordinate_system_code = 'abc'" ] }, { "cell_type": "markdown", "id": "12", "metadata": {}, "source": [ "#### Set Unit Cell" ] }, { "cell_type": "code", "execution_count": 7, "id": "13", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:52.770629Z", "iopub.status.busy": "2026-04-14T14:55:52.770429Z", "iopub.status.idle": "2026-04-14T14:55:52.774148Z", "shell.execute_reply": "2026-04-14T14:55:52.773238Z" } }, "outputs": [], "source": [ "structure.cell.length_a = 10.31\n", "structure.cell.length_b = 6.0\n", "structure.cell.length_c = 4.79" ] }, { "cell_type": "markdown", "id": "14", "metadata": {}, "source": [ "#### Set Atom Sites" ] }, { "cell_type": "code", "execution_count": 8, "id": "15", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:52.775663Z", "iopub.status.busy": "2026-04-14T14:55:52.775494Z", "iopub.status.idle": "2026-04-14T14:55:52.783899Z", "shell.execute_reply": "2026-04-14T14:55:52.783177Z" } }, "outputs": [], "source": [ "structure.atom_sites.create(\n", " label='Co1',\n", " type_symbol='Co',\n", " fract_x=0,\n", " fract_y=0,\n", " fract_z=0,\n", " wyckoff_letter='a',\n", " adp_iso=0.3,\n", ")\n", "structure.atom_sites.create(\n", " label='Co2',\n", " type_symbol='Co',\n", " fract_x=0.279,\n", " fract_y=0.25,\n", " fract_z=0.985,\n", " wyckoff_letter='c',\n", " adp_iso=0.3,\n", ")\n", "structure.atom_sites.create(\n", " label='Si',\n", " type_symbol='Si',\n", " fract_x=0.094,\n", " fract_y=0.25,\n", " fract_z=0.429,\n", " wyckoff_letter='c',\n", " adp_iso=0.34,\n", ")\n", "structure.atom_sites.create(\n", " label='O1',\n", " type_symbol='O',\n", " fract_x=0.091,\n", " fract_y=0.25,\n", " fract_z=0.771,\n", " wyckoff_letter='c',\n", " adp_iso=0.63,\n", ")\n", "structure.atom_sites.create(\n", " label='O2',\n", " type_symbol='O',\n", " fract_x=0.448,\n", " fract_y=0.25,\n", " fract_z=0.217,\n", " wyckoff_letter='c',\n", " adp_iso=0.59,\n", ")\n", "structure.atom_sites.create(\n", " label='O3',\n", " type_symbol='O',\n", " fract_x=0.164,\n", " fract_y=0.032,\n", " fract_z=0.28,\n", " wyckoff_letter='d',\n", " adp_iso=0.83,\n", ")" ] }, { "cell_type": "markdown", "id": "16", "metadata": {}, "source": [ "## Step 3: Define Template Experiment\n", "\n", "For sequential fitting, we create a single template experiment from\n", "the first data file. This template defines the instrument, peak\n", "profile, background, and linked phases that will be reused for every\n", "data file in the scan.\n", "\n", "#### Download Measured Data" ] }, { "cell_type": "code", "execution_count": 9, "id": "17", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:52.785631Z", "iopub.status.busy": "2026-04-14T14:55:52.785461Z", "iopub.status.idle": "2026-04-14T14:55:53.088723Z", "shell.execute_reply": "2026-04-14T14:55:53.087918Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;34mGetting data\u001b[0m\u001b[1;34m...\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Data #\u001b[1;36m27\u001b[0m: Co2SiO4, D20 \u001b[1m(\u001b[0mILL\u001b[1m)\u001b[0m, \u001b[1;36m23\u001b[0m files, T from ~60K to ~500K\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "✅ Data #\u001b[1;36m27\u001b[0m downloaded to \u001b[32m'data/ed-27.zip'\u001b[0m\n" ] } ], "source": [ "zip_path = ed.download_data(id=27, destination='data')" ] }, { "cell_type": "markdown", "id": "18", "metadata": {}, "source": [ "#### Extract Data Files" ] }, { "cell_type": "code", "execution_count": 10, "id": "19", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:53.090755Z", "iopub.status.busy": "2026-04-14T14:55:53.090551Z", "iopub.status.idle": "2026-04-14T14:55:53.103844Z", "shell.execute_reply": "2026-04-14T14:55:53.103042Z" } }, "outputs": [], "source": [ "data_dir = 'data/d20_scan'\n", "data_paths = ed.extract_data_paths_from_zip(zip_path, destination=data_dir)" ] }, { "cell_type": "markdown", "id": "20", "metadata": {}, "source": [ "#### Create Template Experiment from the First File" ] }, { "cell_type": "code", "execution_count": 11, "id": "21", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:53.105415Z", "iopub.status.busy": "2026-04-14T14:55:53.105221Z", "iopub.status.idle": "2026-04-14T14:55:53.275144Z", "shell.execute_reply": "2026-04-14T14:55:53.274313Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;34mData loaded successfully\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Experiment 🔬 \u001b[32m'd20'\u001b[0m. Number of data points: \u001b[1;36m1507\u001b[0m.\n" ] } ], "source": [ "project.experiments.add_from_data_path(\n", " name='d20',\n", " data_path=data_paths[0],\n", ")\n", "expt = project.experiments['d20']" ] }, { "cell_type": "markdown", "id": "22", "metadata": {}, "source": [ "#### Set Instrument" ] }, { "cell_type": "code", "execution_count": 12, "id": "23", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:53.276784Z", "iopub.status.busy": "2026-04-14T14:55:53.276614Z", "iopub.status.idle": "2026-04-14T14:55:53.279914Z", "shell.execute_reply": "2026-04-14T14:55:53.279127Z" } }, "outputs": [], "source": [ "expt.instrument.setup_wavelength = 1.87\n", "expt.instrument.calib_twotheta_offset = 0.29" ] }, { "cell_type": "markdown", "id": "24", "metadata": {}, "source": [ "#### Set Peak Profile" ] }, { "cell_type": "code", "execution_count": 13, "id": "25", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:53.281456Z", "iopub.status.busy": "2026-04-14T14:55:53.281297Z", "iopub.status.idle": "2026-04-14T14:55:53.284728Z", "shell.execute_reply": "2026-04-14T14:55:53.283914Z" } }, "outputs": [], "source": [ "expt.peak.broad_gauss_u = 0.24\n", "expt.peak.broad_gauss_v = -0.53\n", "expt.peak.broad_gauss_w = 0.38\n", "expt.peak.broad_lorentz_y = 0.02" ] }, { "cell_type": "markdown", "id": "26", "metadata": {}, "source": [ "#### Set Excluded Regions" ] }, { "cell_type": "code", "execution_count": 14, "id": "27", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:53.286428Z", "iopub.status.busy": "2026-04-14T14:55:53.286239Z", "iopub.status.idle": "2026-04-14T14:55:53.289917Z", "shell.execute_reply": "2026-04-14T14:55:53.289100Z" } }, "outputs": [], "source": [ "expt.excluded_regions.create(id='1', start=0, end=8)\n", "expt.excluded_regions.create(id='2', start=150, end=180)" ] }, { "cell_type": "markdown", "id": "28", "metadata": {}, "source": [ "#### Set Background" ] }, { "cell_type": "code", "execution_count": 15, "id": "29", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:53.291439Z", "iopub.status.busy": "2026-04-14T14:55:53.291262Z", "iopub.status.idle": "2026-04-14T14:55:53.299515Z", "shell.execute_reply": "2026-04-14T14:55:53.298454Z" } }, "outputs": [], "source": [ "expt.background.create(id='1', x=8, y=609)\n", "expt.background.create(id='2', x=9, y=581)\n", "expt.background.create(id='3', x=10, y=563)\n", "expt.background.create(id='4', x=11, y=540)\n", "expt.background.create(id='5', x=12, y=520)\n", "expt.background.create(id='6', x=15, y=507)\n", "expt.background.create(id='7', x=25, y=463)\n", "expt.background.create(id='8', x=30, y=434)\n", "expt.background.create(id='9', x=50, y=451)\n", "expt.background.create(id='10', x=70, y=431)\n", "expt.background.create(id='11', x=90, y=414)\n", "expt.background.create(id='12', x=110, y=361)\n", "expt.background.create(id='13', x=130, y=292)\n", "expt.background.create(id='14', x=150, y=241)" ] }, { "cell_type": "markdown", "id": "30", "metadata": {}, "source": [ "#### Set Linked Phases" ] }, { "cell_type": "code", "execution_count": 16, "id": "31", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:53.301033Z", "iopub.status.busy": "2026-04-14T14:55:53.300861Z", "iopub.status.idle": "2026-04-14T14:55:53.304196Z", "shell.execute_reply": "2026-04-14T14:55:53.303295Z" } }, "outputs": [], "source": [ "expt.linked_phases.create(id='cosio', scale=1.2)" ] }, { "cell_type": "markdown", "id": "32", "metadata": {}, "source": [ "## Step 4: Perform Analysis\n", "\n", "This section shows how to set free parameters, define constraints,\n", "and run the sequential refinement." ] }, { "cell_type": "markdown", "id": "33", "metadata": {}, "source": [ "#### Set Free Parameters" ] }, { "cell_type": "code", "execution_count": 17, "id": "34", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:53.305789Z", "iopub.status.busy": "2026-04-14T14:55:53.305598Z", "iopub.status.idle": "2026-04-14T14:55:53.312085Z", "shell.execute_reply": "2026-04-14T14:55:53.311134Z" } }, "outputs": [], "source": [ "structure.cell.length_a.free = True\n", "structure.cell.length_b.free = True\n", "structure.cell.length_c.free = True\n", "\n", "structure.atom_sites['Co2'].fract_x.free = True\n", "structure.atom_sites['Co2'].fract_z.free = True\n", "structure.atom_sites['Si'].fract_x.free = True\n", "structure.atom_sites['Si'].fract_z.free = True\n", "structure.atom_sites['O1'].fract_x.free = True\n", "structure.atom_sites['O1'].fract_z.free = True\n", "structure.atom_sites['O2'].fract_x.free = True\n", "structure.atom_sites['O2'].fract_z.free = True\n", "structure.atom_sites['O3'].fract_x.free = True\n", "structure.atom_sites['O3'].fract_y.free = True\n", "structure.atom_sites['O3'].fract_z.free = True\n", "\n", "structure.atom_sites['Co1'].adp_iso.free = True\n", "structure.atom_sites['Co2'].adp_iso.free = True\n", "structure.atom_sites['Si'].adp_iso.free = True\n", "structure.atom_sites['O1'].adp_iso.free = True\n", "structure.atom_sites['O2'].adp_iso.free = True\n", "structure.atom_sites['O3'].adp_iso.free = True" ] }, { "cell_type": "code", "execution_count": 18, "id": "35", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:53.313626Z", "iopub.status.busy": "2026-04-14T14:55:53.313441Z", "iopub.status.idle": "2026-04-14T14:55:53.318237Z", "shell.execute_reply": "2026-04-14T14:55:53.317428Z" } }, "outputs": [], "source": [ "expt.linked_phases['cosio'].scale.free = True\n", "\n", "expt.instrument.calib_twotheta_offset.free = True\n", "\n", "expt.peak.broad_gauss_u.free = True\n", "expt.peak.broad_gauss_v.free = True\n", "expt.peak.broad_gauss_w.free = True\n", "expt.peak.broad_lorentz_y.free = True\n", "\n", "for point in expt.background:\n", " point.y.free = True" ] }, { "cell_type": "markdown", "id": "36", "metadata": {}, "source": [ "#### Set Constraints\n", "\n", "Set aliases for parameters." ] }, { "cell_type": "code", "execution_count": 19, "id": "37", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:53.319706Z", "iopub.status.busy": "2026-04-14T14:55:53.319540Z", "iopub.status.idle": "2026-04-14T14:55:53.323053Z", "shell.execute_reply": "2026-04-14T14:55:53.322242Z" } }, "outputs": [], "source": [ "project.analysis.aliases.create(\n", " label='biso_Co1',\n", " param=structure.atom_sites['Co1'].adp_iso,\n", ")\n", "project.analysis.aliases.create(\n", " label='biso_Co2',\n", " param=structure.atom_sites['Co2'].adp_iso,\n", ")" ] }, { "cell_type": "markdown", "id": "38", "metadata": {}, "source": [ "Set constraints." ] }, { "cell_type": "code", "execution_count": 20, "id": "39", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:53.324501Z", "iopub.status.busy": "2026-04-14T14:55:53.324348Z", "iopub.status.idle": "2026-04-14T14:55:53.327293Z", "shell.execute_reply": "2026-04-14T14:55:53.326480Z" } }, "outputs": [], "source": [ "project.analysis.constraints.create(expression='biso_Co2 = biso_Co1')" ] }, { "cell_type": "markdown", "id": "40", "metadata": {}, "source": [ "#### Set Minimizer" ] }, { "cell_type": "code", "execution_count": 21, "id": "41", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:53.328795Z", "iopub.status.busy": "2026-04-14T14:55:53.328608Z", "iopub.status.idle": "2026-04-14T14:55:53.333871Z", "shell.execute_reply": "2026-04-14T14:55:53.333186Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;34mCurrent 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.current_minimizer = 'bumps (lm)'" ] }, { "cell_type": "markdown", "id": "42", "metadata": {}, "source": [ "#### Run Single Fitting\n", "\n", "This is the fitting of the first dataset to optimize the initial\n", "parameters for the sequential fitting. This step is optional but can\n", "help with convergence and speed of the sequential fitting, especially\n", "if the initial parameters are far from optimal." ] }, { "cell_type": "code", "execution_count": 22, "id": "43", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:55:53.335754Z", "iopub.status.busy": "2026-04-14T14:55:53.335579Z", "iopub.status.idle": "2026-04-14T14:56:14.864682Z", "shell.execute_reply": "2026-04-14T14:56:14.863768Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;34mStandard fitting\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "📋 Using experiment 🔬 \u001b[32m'd20'\u001b[0m for \u001b[32m'single'\u001b[0m fitting\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 \u001b[1m(\u001b[0mreduced χ²\u001b[1m)\u001b[0m change:\n" ] }, { "data": { "text/html": [ "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
 iterationχ²improvement [%]
1112.53
22011.865.4% ↓
3425.0357.6% ↓
4824.755.6% ↓
52844.74
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " (function() {\n", " var isDark = false;\n", "\n", " // Check JupyterLab theme\n", " if (document.body.classList.contains('jp-mod-dark') || \n", " document.body.classList.contains('theme-dark') ||\n", " document.body.classList.contains('vscode-dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check theme attribute\n", " var themeAttr = document.body.getAttribute('data-jp-theme-name');\n", " if (themeAttr && themeAttr.includes('dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check computed background color\n", " var notebookEl = document.querySelector('.jp-Notebook') || \n", " document.querySelector('.notebook_app') ||\n", " document.body;\n", " if (notebookEl) {\n", " var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n", " var rgb = bgColor.match(/\\d+/g);\n", " if (rgb && rgb.length >= 3) {\n", " var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n", " if (brightness < 128) {\n", " isDark = true;\n", " }\n", " }\n", " }\n", "\n", " // Store result\n", " if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n", " IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n", " }\n", " })();\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " if (typeof IPython !== 'undefined' && IPython.notebook) {\n", " IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n", " (document.body.classList.contains('theme-dark') || \n", " document.body.classList.contains('jp-mod-dark') ||\n", " (document.body.getAttribute('data-jp-theme-name') && \n", " document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n", " }\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " (function() {\n", " var isDark = false;\n", "\n", " // Check JupyterLab theme\n", " if (document.body.classList.contains('jp-mod-dark') || \n", " document.body.classList.contains('theme-dark') ||\n", " document.body.classList.contains('vscode-dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check theme attribute\n", " var themeAttr = document.body.getAttribute('data-jp-theme-name');\n", " if (themeAttr && themeAttr.includes('dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check computed background color\n", " var notebookEl = document.querySelector('.jp-Notebook') || \n", " document.querySelector('.notebook_app') ||\n", " document.body;\n", " if (notebookEl) {\n", " var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n", " var rgb = bgColor.match(/\\d+/g);\n", " if (rgb && rgb.length >= 3) {\n", " var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n", " if (brightness < 128) {\n", " isDark = true;\n", " }\n", " }\n", " }\n", "\n", " // Store result\n", " if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n", " IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n", " }\n", " })();\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " if (typeof IPython !== 'undefined' && IPython.notebook) {\n", " IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n", " (document.body.classList.contains('theme-dark') || \n", " document.body.classList.contains('jp-mod-dark') ||\n", " (document.body.getAttribute('data-jp-theme-name') && \n", " document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n", " }\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " (function() {\n", " var isDark = false;\n", "\n", " // Check JupyterLab theme\n", " if (document.body.classList.contains('jp-mod-dark') || \n", " document.body.classList.contains('theme-dark') ||\n", " document.body.classList.contains('vscode-dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check theme attribute\n", " var themeAttr = document.body.getAttribute('data-jp-theme-name');\n", " if (themeAttr && themeAttr.includes('dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check computed background color\n", " var notebookEl = document.querySelector('.jp-Notebook') || \n", " document.querySelector('.notebook_app') ||\n", " document.body;\n", " if (notebookEl) {\n", " var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n", " var rgb = bgColor.match(/\\d+/g);\n", " if (rgb && rgb.length >= 3) {\n", " var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n", " if (brightness < 128) {\n", " isDark = true;\n", " }\n", " }\n", " }\n", "\n", " // Store result\n", " if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n", " IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n", " }\n", " })();\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " if (typeof IPython !== 'undefined' && IPython.notebook) {\n", " IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n", " (document.body.classList.contains('theme-dark') || \n", " document.body.classList.contains('jp-mod-dark') ||\n", " (document.body.getAttribute('data-jp-theme-name') && \n", " document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n", " }\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " (function() {\n", " var isDark = false;\n", "\n", " // Check JupyterLab theme\n", " if (document.body.classList.contains('jp-mod-dark') || \n", " document.body.classList.contains('theme-dark') ||\n", " document.body.classList.contains('vscode-dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check theme attribute\n", " var themeAttr = document.body.getAttribute('data-jp-theme-name');\n", " if (themeAttr && themeAttr.includes('dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check computed background color\n", " var notebookEl = document.querySelector('.jp-Notebook') || \n", " document.querySelector('.notebook_app') ||\n", " document.body;\n", " if (notebookEl) {\n", " var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n", " var rgb = bgColor.match(/\\d+/g);\n", " if (rgb && rgb.length >= 3) {\n", " var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n", " if (brightness < 128) {\n", " isDark = true;\n", " }\n", " }\n", " }\n", "\n", " // Store result\n", " if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n", " IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n", " }\n", " })();\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " if (typeof IPython !== 'undefined' && IPython.notebook) {\n", " IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n", " (document.body.classList.contains('theme-dark') || \n", " document.body.classList.contains('jp-mod-dark') ||\n", " (document.body.getAttribute('data-jp-theme-name') && \n", " document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n", " }\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " (function() {\n", " var isDark = false;\n", "\n", " // Check JupyterLab theme\n", " if (document.body.classList.contains('jp-mod-dark') || \n", " document.body.classList.contains('theme-dark') ||\n", " document.body.classList.contains('vscode-dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check theme attribute\n", " var themeAttr = document.body.getAttribute('data-jp-theme-name');\n", " if (themeAttr && themeAttr.includes('dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check computed background color\n", " var notebookEl = document.querySelector('.jp-Notebook') || \n", " document.querySelector('.notebook_app') ||\n", " document.body;\n", " if (notebookEl) {\n", " var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n", " var rgb = bgColor.match(/\\d+/g);\n", " if (rgb && rgb.length >= 3) {\n", " var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n", " if (brightness < 128) {\n", " isDark = true;\n", " }\n", " }\n", " }\n", "\n", " // Store result\n", " if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n", " IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n", " }\n", " })();\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " if (typeof IPython !== 'undefined' && IPython.notebook) {\n", " IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n", " (document.body.classList.contains('theme-dark') || \n", " document.body.classList.contains('jp-mod-dark') ||\n", " (document.body.getAttribute('data-jp-theme-name') && \n", " document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n", " }\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " (function() {\n", " var isDark = false;\n", "\n", " // Check JupyterLab theme\n", " if (document.body.classList.contains('jp-mod-dark') || \n", " document.body.classList.contains('theme-dark') ||\n", " document.body.classList.contains('vscode-dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check theme attribute\n", " var themeAttr = document.body.getAttribute('data-jp-theme-name');\n", " if (themeAttr && themeAttr.includes('dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check computed background color\n", " var notebookEl = document.querySelector('.jp-Notebook') || \n", " document.querySelector('.notebook_app') ||\n", " document.body;\n", " if (notebookEl) {\n", " var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n", " var rgb = bgColor.match(/\\d+/g);\n", " if (rgb && rgb.length >= 3) {\n", " var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n", " if (brightness < 128) {\n", " isDark = true;\n", " }\n", " }\n", " }\n", "\n", " // Store result\n", " if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n", " IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n", " }\n", " })();\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " if (typeof IPython !== 'undefined' && IPython.notebook) {\n", " IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n", " (document.body.classList.contains('theme-dark') || \n", " document.body.classList.contains('jp-mod-dark') ||\n", " (document.body.getAttribute('data-jp-theme-name') && \n", " document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n", " }\n", " " ], "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;36m4.74\u001b[0m at iteration \u001b[1;36m248\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "✅ Fitting complete.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;34mSaving project 📦 \u001b[0m\u001b[32m'untitled_project'\u001b[0m\u001b[1;34m to\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\u001b[35m/home/runner/work/diffraction-lib/diffraction-lib/docs/docs/tutorials/data/\u001b[0m\u001b[95mcosio_project\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "├── 📄 project.cif\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "├── 📁 structures/\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "│ └── 📄 cosio.cif\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "├── 📁 experiments/\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "│ └── 📄 d20.cif\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "├── 📁 analysis/\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "│ └── 📄 analysis.cif\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "└── 📄 summary.cif\n" ] } ], "source": [ "project.analysis.fit()" ] }, { "cell_type": "markdown", "id": "44", "metadata": {}, "source": [ "#### Show parameter correlations" ] }, { "cell_type": "code", "execution_count": 23, "id": "45", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:56:14.866403Z", "iopub.status.busy": "2026-04-14T14:56:14.866203Z", "iopub.status.idle": "2026-04-14T14:56:15.336096Z", "shell.execute_reply": "2026-04-14T14:56:15.335176Z" } }, "outputs": [ { "data": { "application/javascript": [ "\n", " (function() {\n", " var isDark = false;\n", "\n", " // Check JupyterLab theme\n", " if (document.body.classList.contains('jp-mod-dark') || \n", " document.body.classList.contains('theme-dark') ||\n", " document.body.classList.contains('vscode-dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check theme attribute\n", " var themeAttr = document.body.getAttribute('data-jp-theme-name');\n", " if (themeAttr && themeAttr.includes('dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check computed background color\n", " var notebookEl = document.querySelector('.jp-Notebook') || \n", " document.querySelector('.notebook_app') ||\n", " document.body;\n", " if (notebookEl) {\n", " var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n", " var rgb = bgColor.match(/\\d+/g);\n", " if (rgb && rgb.length >= 3) {\n", " var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n", " if (brightness < 128) {\n", " isDark = true;\n", " }\n", " }\n", " }\n", "\n", " // Store result\n", " if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n", " IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n", " }\n", " })();\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " if (typeof IPython !== 'undefined' && IPython.notebook) {\n", " IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n", " (document.body.classList.contains('theme-dark') || \n", " document.body.classList.contains('jp-mod-dark') ||\n", " (document.body.getAttribute('data-jp-theme-name') && \n", " document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n", " }\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " (function() {\n", " var isDark = false;\n", "\n", " // Check JupyterLab theme\n", " if (document.body.classList.contains('jp-mod-dark') || \n", " document.body.classList.contains('theme-dark') ||\n", " document.body.classList.contains('vscode-dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check theme attribute\n", " var themeAttr = document.body.getAttribute('data-jp-theme-name');\n", " if (themeAttr && themeAttr.includes('dark')) {\n", " isDark = true;\n", " }\n", "\n", " // Check computed background color\n", " var notebookEl = document.querySelector('.jp-Notebook') || \n", " document.querySelector('.notebook_app') ||\n", " document.body;\n", " if (notebookEl) {\n", " var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n", " var rgb = bgColor.match(/\\d+/g);\n", " if (rgb && rgb.length >= 3) {\n", " var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n", " if (brightness < 128) {\n", " isDark = true;\n", " }\n", " }\n", " }\n", "\n", " // Store result\n", " if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n", " IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n", " }\n", " })();\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " if (typeof IPython !== 'undefined' && IPython.notebook) {\n", " IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n", " (document.body.classList.contains('theme-dark') || \n", " document.body.classList.contains('jp-mod-dark') ||\n", " (document.body.getAttribute('data-jp-theme-name') && \n", " document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n", " }\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.plotter.plot_param_correlations()" ] }, { "cell_type": "markdown", "id": "46", "metadata": {}, "source": [ "#### Compare measured and calculated patterns for the first fit." ] }, { "cell_type": "code", "execution_count": 24, "id": "47", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:56:15.337707Z", "iopub.status.busy": "2026-04-14T14:56:15.337538Z", "iopub.status.idle": "2026-04-14T14:56:15.704815Z", "shell.execute_reply": "2026-04-14T14:56:15.703811Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.plotter.plot_meas_vs_calc(expt_name='d20', show_residual=True)" ] }, { "cell_type": "markdown", "id": "48", "metadata": {}, "source": [ "#### Run Sequential Fitting\n", "\n", "Set output verbosity level to \"short\" to show only one-line status\n", "messages during the analysis process." ] }, { "cell_type": "code", "execution_count": 25, "id": "49", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:56:15.706483Z", "iopub.status.busy": "2026-04-14T14:56:15.706302Z", "iopub.status.idle": "2026-04-14T14:56:15.709337Z", "shell.execute_reply": "2026-04-14T14:56:15.708588Z" } }, "outputs": [], "source": [ "project.verbosity = 'short'" ] }, { "cell_type": "markdown", "id": "50", "metadata": { "lines_to_next_cell": 2 }, "source": [ "\n", "Define a callback that extracts the temperature from each data file." ] }, { "cell_type": "code", "execution_count": 26, "id": "51", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:56:15.711172Z", "iopub.status.busy": "2026-04-14T14:56:15.710980Z", "iopub.status.idle": "2026-04-14T14:56:15.714083Z", "shell.execute_reply": "2026-04-14T14:56:15.713360Z" } }, "outputs": [], "source": [ "def extract_diffrn(file_path):\n", " temperature = ed.extract_metadata(\n", " file_path=file_path,\n", " pattern=r'^TEMP\\s+([0-9.]+)',\n", " )\n", " return {'ambient_temperature': temperature}" ] }, { "cell_type": "markdown", "id": "52", "metadata": {}, "source": [ "Run the sequential fit over all data files in the scan directory." ] }, { "cell_type": "code", "execution_count": 27, "id": "53", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T14:56:15.716038Z", "iopub.status.busy": "2026-04-14T14:56:15.715832Z", "iopub.status.idle": "2026-04-14T15:02:01.279908Z", "shell.execute_reply": "2026-04-14T15:02:01.279170Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;34mSequential 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": [ "📋 \u001b[1;36m23\u001b[0m files in \u001b[1;36m6\u001b[0m chunks \u001b[1m(\u001b[0m\u001b[33mmax_workers\u001b[0m=\u001b[1;36m4\u001b[0m\u001b[1m)\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "📈 Goodness-of-fit \u001b[1m(\u001b[0mreduced χ²\u001b[1m)\u001b[0m:\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "✅ Chunk 1/6: 4 files, avg χ² = 4.54\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "✅ Chunk 2/6: 4 files, avg χ² = 4.68\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "✅ Chunk 3/6: 4 files, avg χ² = 4.64\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "✅ Chunk 4/6: 4 files, avg χ² = 4.70\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "✅ Chunk 5/6: 4 files, avg χ² = 4.75\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "✅ Chunk 6/6: 3 files, avg χ² = 4.72\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "✅ Sequential fitting complete: 23 files processed.\n", "📄 Results saved to: data/cosio_project/analysis/results.csv\n" ] } ], "source": [ "project.analysis.fit_sequential(\n", " data_dir=data_dir,\n", " extract_diffrn=extract_diffrn,\n", " max_workers='auto',\n", " reverse=True,\n", ")" ] }, { "cell_type": "markdown", "id": "54", "metadata": {}, "source": [ "#### Replay a Dataset\n", "\n", "Apply fitted parameters from the first CSV row and plot the result." ] }, { "cell_type": "code", "execution_count": 28, "id": "55", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T15:02:01.281692Z", "iopub.status.busy": "2026-04-14T15:02:01.281503Z", "iopub.status.idle": "2026-04-14T15:02:01.749351Z", "shell.execute_reply": "2026-04-14T15:02:01.748554Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.apply_params_from_csv(row_index=0)\n", "project.plotter.plot_meas_vs_calc(expt_name='d20', show_residual=True)" ] }, { "cell_type": "markdown", "id": "56", "metadata": {}, "source": [ "\n", "Apply fitted parameters from the last CSV row and plot the result." ] }, { "cell_type": "code", "execution_count": 29, "id": "57", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T15:02:01.751041Z", "iopub.status.busy": "2026-04-14T15:02:01.750879Z", "iopub.status.idle": "2026-04-14T15:02:02.256658Z", "shell.execute_reply": "2026-04-14T15:02:02.255784Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.apply_params_from_csv(row_index=-1)\n", "project.plotter.plot_meas_vs_calc(expt_name='d20', show_residual=True)" ] }, { "cell_type": "markdown", "id": "58", "metadata": {}, "source": [ "#### Plot Parameter Evolution\n", "\n", "Define the quantity to use as the x-axis in the following plots." ] }, { "cell_type": "code", "execution_count": 30, "id": "59", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T15:02:02.258395Z", "iopub.status.busy": "2026-04-14T15:02:02.258207Z", "iopub.status.idle": "2026-04-14T15:02:02.261037Z", "shell.execute_reply": "2026-04-14T15:02:02.260212Z" } }, "outputs": [], "source": [ "temperature = expt.diffrn.ambient_temperature" ] }, { "cell_type": "markdown", "id": "60", "metadata": {}, "source": [ "Plot unit cell parameters vs. temperature." ] }, { "cell_type": "code", "execution_count": 31, "id": "61", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T15:02:02.262565Z", "iopub.status.busy": "2026-04-14T15:02:02.262395Z", "iopub.status.idle": "2026-04-14T15:02:02.333862Z", "shell.execute_reply": "2026-04-14T15:02:02.333157Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.plotter.plot_param_series(structure.cell.length_a, versus=temperature)\n", "project.plotter.plot_param_series(structure.cell.length_b, versus=temperature)\n", "project.plotter.plot_param_series(structure.cell.length_c, versus=temperature)" ] }, { "cell_type": "markdown", "id": "62", "metadata": {}, "source": [ "Plot isotropic displacement parameters vs. temperature." ] }, { "cell_type": "code", "execution_count": 32, "id": "63", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T15:02:02.335404Z", "iopub.status.busy": "2026-04-14T15:02:02.335232Z", "iopub.status.idle": "2026-04-14T15:02:02.451769Z", "shell.execute_reply": "2026-04-14T15:02:02.451059Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.plotter.plot_param_series(structure.atom_sites['Co1'].adp_iso, versus=temperature)\n", "project.plotter.plot_param_series(structure.atom_sites['Si'].adp_iso, versus=temperature)\n", "project.plotter.plot_param_series(structure.atom_sites['O1'].adp_iso, versus=temperature)\n", "project.plotter.plot_param_series(structure.atom_sites['O2'].adp_iso, versus=temperature)\n", "project.plotter.plot_param_series(structure.atom_sites['O3'].adp_iso, versus=temperature)" ] }, { "cell_type": "markdown", "id": "64", "metadata": {}, "source": [ "Plot selected fractional coordinates vs. temperature." ] }, { "cell_type": "code", "execution_count": 33, "id": "65", "metadata": { "execution": { "iopub.execute_input": "2026-04-14T15:02:02.453361Z", "iopub.status.busy": "2026-04-14T15:02:02.453193Z", "iopub.status.idle": "2026-04-14T15:02:02.569119Z", "shell.execute_reply": "2026-04-14T15:02:02.568451Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.plotter.plot_param_series(structure.atom_sites['Co2'].fract_x, versus=temperature)\n", "project.plotter.plot_param_series(structure.atom_sites['Co2'].fract_z, versus=temperature)\n", "project.plotter.plot_param_series(structure.atom_sites['O1'].fract_z, versus=temperature)\n", "project.plotter.plot_param_series(structure.atom_sites['O2'].fract_z, versus=temperature)\n", "project.plotter.plot_param_series(structure.atom_sites['O3'].fract_z, versus=temperature)" ] } ], "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.4" } }, "nbformat": 4, "nbformat_minor": 5 }