{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "4c44715c", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:24.986946Z", "iopub.status.busy": "2026-01-06T13:53:24.986566Z", "iopub.status.idle": "2026-01-06T13:53:24.997320Z", "shell.execute_reply": "2026-01-06T13:53:24.996722Z" }, "tags": [ "hide-in-docs" ] }, "outputs": [], "source": [ "# Check if the easydiffraction library is installed.\n", "# If not, install it with the 'visualization' extras.\n", "# Needed when running remotely (e.g. Colab) where the lib is absent.\n", "import builtins\n", "import importlib.util\n", "\n", "if (hasattr(builtins, '__IPYTHON__') and\n", " importlib.util.find_spec('easydiffraction') is None):\n", " !pip install 'easydiffraction[visualization]==0.10.1'" ] }, { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# Pair Distribution Function: NaCl, XRD\n", "\n", "This example demonstrates a pair distribution function (PDF) analysis\n", "of NaCl, based on data collected from an X-ray powder diffraction\n", "experiment.\n", "\n", "The dataset is taken from:\n", "https://github.com/diffpy/add2019-diffpy-cmi/tree/master" ] }, { "cell_type": "markdown", "id": "1", "metadata": {}, "source": [ "## Import Library" ] }, { "cell_type": "code", "execution_count": 2, "id": "2", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:24.998975Z", "iopub.status.busy": "2026-01-06T13:53:24.998862Z", "iopub.status.idle": "2026-01-06T13:53:28.658189Z", "shell.execute_reply": "2026-01-06T13:53:28.657519Z" } }, "outputs": [], "source": [ "import easydiffraction as ed" ] }, { "cell_type": "markdown", "id": "3", "metadata": {}, "source": [ "## Create Project" ] }, { "cell_type": "code", "execution_count": 3, "id": "4", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:28.660481Z", "iopub.status.busy": "2026-01-06T13:53:28.660281Z", "iopub.status.idle": "2026-01-06T13:53:28.862267Z", "shell.execute_reply": "2026-01-06T13:53:28.857543Z" } }, "outputs": [], "source": [ "project = ed.Project()" ] }, { "cell_type": "markdown", "id": "5", "metadata": {}, "source": [ "## Set Plotting Engine" ] }, { "cell_type": "code", "execution_count": 4, "id": "6", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:28.869703Z", "iopub.status.busy": "2026-01-06T13:53:28.866872Z", "iopub.status.idle": "2026-01-06T13:53:28.879283Z", "shell.execute_reply": "2026-01-06T13:53:28.876657Z" } }, "outputs": [], "source": [ "# Keep the auto-selected engine. Alternatively, you can uncomment the\n", "# line below to explicitly set the engine to the required one.\n", "# project.plotter.engine = 'plotly'" ] }, { "cell_type": "code", "execution_count": 5, "id": "7", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:28.887868Z", "iopub.status.busy": "2026-01-06T13:53:28.886859Z", "iopub.status.idle": "2026-01-06T13:53:28.897851Z", "shell.execute_reply": "2026-01-06T13:53:28.894230Z" } }, "outputs": [], "source": [ "# Set global plot range for plots\n", "project.plotter.x_min = 2.0\n", "project.plotter.x_max = 30.0" ] }, { "cell_type": "markdown", "id": "8", "metadata": {}, "source": [ "## Add Sample Model" ] }, { "cell_type": "code", "execution_count": 6, "id": "9", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:28.902037Z", "iopub.status.busy": "2026-01-06T13:53:28.901808Z", "iopub.status.idle": "2026-01-06T13:53:28.914239Z", "shell.execute_reply": "2026-01-06T13:53:28.912633Z" } }, "outputs": [], "source": [ "project.sample_models.add(name='nacl')" ] }, { "cell_type": "code", "execution_count": 7, "id": "10", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:28.920858Z", "iopub.status.busy": "2026-01-06T13:53:28.919800Z", "iopub.status.idle": "2026-01-06T13:53:28.941249Z", "shell.execute_reply": "2026-01-06T13:53:28.939492Z" } }, "outputs": [], "source": [ "project.sample_models['nacl'].space_group.name_h_m = 'F m -3 m'\n", "project.sample_models['nacl'].space_group.it_coordinate_system_code = '1'\n", "project.sample_models['nacl'].cell.length_a = 5.62\n", "project.sample_models['nacl'].atom_sites.add(\n", " label='Na',\n", " type_symbol='Na',\n", " fract_x=0,\n", " fract_y=0,\n", " fract_z=0,\n", " wyckoff_letter='a',\n", " b_iso=1.0,\n", ")\n", "project.sample_models['nacl'].atom_sites.add(\n", " label='Cl',\n", " type_symbol='Cl',\n", " fract_x=0.5,\n", " fract_y=0.5,\n", " fract_z=0.5,\n", " wyckoff_letter='b',\n", " b_iso=1.0,\n", ")" ] }, { "cell_type": "markdown", "id": "11", "metadata": {}, "source": [ "## Add Experiment" ] }, { "cell_type": "code", "execution_count": 8, "id": "12", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:28.946630Z", "iopub.status.busy": "2026-01-06T13:53:28.945782Z", "iopub.status.idle": "2026-01-06T13:53:29.120917Z", "shell.execute_reply": "2026-01-06T13:53:29.119602Z" } }, "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;36m4\u001b[0m: NaCl.gr\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "โœ… Data #\u001b[1;36m4\u001b[0m downloaded to \u001b[32m'data/ed-4.gr'\u001b[0m\n" ] } ], "source": [ "data_path = ed.download_data(id=4, destination='data')" ] }, { "cell_type": "code", "execution_count": 9, "id": "13", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:29.127370Z", "iopub.status.busy": "2026-01-06T13:53:29.126477Z", "iopub.status.idle": "2026-01-06T13:53:29.916165Z", "shell.execute_reply": "2026-01-06T13:53:29.915556Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Warning: No uncertainty (sy) column provided. Defaulting to 0.03.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;34mData loaded successfully\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Experiment ๐Ÿ”ฌ \u001b[32m'xray_pdf'\u001b[0m. Number of data points: \u001b[1;36m5000\u001b[0m\n" ] } ], "source": [ "project.experiments.add(\n", " name='xray_pdf',\n", " data_path=data_path,\n", " sample_form='powder',\n", " beam_mode='constant wavelength',\n", " radiation_probe='xray',\n", " scattering_type='total',\n", ")" ] }, { "cell_type": "code", "execution_count": 10, "id": "14", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:29.918475Z", "iopub.status.busy": "2026-01-06T13:53:29.918333Z", "iopub.status.idle": "2026-01-06T13:53:30.533326Z", "shell.execute_reply": "2026-01-06T13:53:30.532930Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;34mSupported peak profile types\u001b[0m\n" ] }, { "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", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
 Peak profile typeDescription
1gaussian-damped-sincGaussian-damped sinc profile for pair distribution function (PDF) analysis.
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.experiments['xray_pdf'].show_supported_peak_profile_types()" ] }, { "cell_type": "code", "execution_count": 11, "id": "15", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:30.535300Z", "iopub.status.busy": "2026-01-06T13:53:30.535095Z", "iopub.status.idle": "2026-01-06T13:53:30.539225Z", "shell.execute_reply": "2026-01-06T13:53:30.538727Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;34mCurrent peak profile type\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "PeakProfileTypeEnum.GAUSSIAN_DAMPED_SINC\n" ] } ], "source": [ "project.experiments['xray_pdf'].show_current_peak_profile_type()" ] }, { "cell_type": "code", "execution_count": 12, "id": "16", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:30.541245Z", "iopub.status.busy": "2026-01-06T13:53:30.541138Z", "iopub.status.idle": "2026-01-06T13:53:30.548035Z", "shell.execute_reply": "2026-01-06T13:53:30.546105Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;34mPeak profile type for experiment \u001b[0m\u001b[32m'xray_pdf'\u001b[0m\u001b[1;34m changed to\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "gaussian-damped-sinc\n" ] } ], "source": [ "project.experiments['xray_pdf'].peak_profile_type = 'gaussian-damped-sinc'" ] }, { "cell_type": "code", "execution_count": 13, "id": "17", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:30.551223Z", "iopub.status.busy": "2026-01-06T13:53:30.549575Z", "iopub.status.idle": "2026-01-06T13:53:30.558553Z", "shell.execute_reply": "2026-01-06T13:53:30.557869Z" } }, "outputs": [], "source": [ "project.experiments['xray_pdf'].peak.damp_q = 0.03\n", "project.experiments['xray_pdf'].peak.broad_q = 0\n", "project.experiments['xray_pdf'].peak.cutoff_q = 21\n", "project.experiments['xray_pdf'].peak.sharp_delta_1 = 0\n", "project.experiments['xray_pdf'].peak.sharp_delta_2 = 5\n", "project.experiments['xray_pdf'].peak.damp_particle_diameter = 0" ] }, { "cell_type": "code", "execution_count": 14, "id": "18", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:30.560173Z", "iopub.status.busy": "2026-01-06T13:53:30.560068Z", "iopub.status.idle": "2026-01-06T13:53:30.564007Z", "shell.execute_reply": "2026-01-06T13:53:30.563009Z" } }, "outputs": [], "source": [ "project.experiments['xray_pdf'].linked_phases.add(id='nacl', scale=0.5)" ] }, { "cell_type": "markdown", "id": "19", "metadata": {}, "source": [ "## Select Fitting Parameters" ] }, { "cell_type": "code", "execution_count": 15, "id": "20", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:30.566596Z", "iopub.status.busy": "2026-01-06T13:53:30.565514Z", "iopub.status.idle": "2026-01-06T13:53:30.569502Z", "shell.execute_reply": "2026-01-06T13:53:30.568310Z" } }, "outputs": [], "source": [ "project.sample_models['nacl'].cell.length_a.free = True\n", "project.sample_models['nacl'].atom_sites['Na'].b_iso.free = True\n", "project.sample_models['nacl'].atom_sites['Cl'].b_iso.free = True" ] }, { "cell_type": "code", "execution_count": 16, "id": "21", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:30.571073Z", "iopub.status.busy": "2026-01-06T13:53:30.570964Z", "iopub.status.idle": "2026-01-06T13:53:30.577166Z", "shell.execute_reply": "2026-01-06T13:53:30.574402Z" } }, "outputs": [], "source": [ "project.experiments['xray_pdf'].linked_phases['nacl'].scale.free = True\n", "project.experiments['xray_pdf'].peak.damp_q.free = True\n", "project.experiments['xray_pdf'].peak.sharp_delta_2.free = True" ] }, { "cell_type": "markdown", "id": "22", "metadata": {}, "source": [ "## Run Fitting" ] }, { "cell_type": "code", "execution_count": 17, "id": "23", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:30.580444Z", "iopub.status.busy": "2026-01-06T13:53:30.579526Z", "iopub.status.idle": "2026-01-06T13:53:38.525567Z", "shell.execute_reply": "2026-01-06T13:53:38.525171Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;34mCurrent calculator changed to\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "pdffit\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;34mUsing experiment ๐Ÿ”ฌ \u001b[0m\u001b[32m'xray_pdf'\u001b[0m\u001b[1;34m for \u001b[0m\u001b[32m'single'\u001b[0m\u001b[1;34m 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 \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 [%]
11163.09
21019.5988.0% โ†“
31710.9544.1% โ†“
42410.692.3% โ†“
54610.69
\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;36m10.69\u001b[0m at iteration \u001b[1;36m45\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "โœ… Fitting complete.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;34mFit results\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "โœ… Success: \u001b[3;92mTrue\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "โฑ๏ธ Fitting time: \u001b[1;36m6.71\u001b[0m seconds\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "๐Ÿ“ Goodness-of-fit \u001b[1m(\u001b[0mreduced ฯ‡ยฒ\u001b[1m)\u001b[0m: \u001b[1;36m10.69\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "๐Ÿ“ R-factor \u001b[1m(\u001b[0mRf\u001b[1m)\u001b[0m: \u001b[1;36m34.82\u001b[0m%\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "๐Ÿ“ R-factor squared \u001b[1m(\u001b[0mRfยฒ\u001b[1m)\u001b[0m: \u001b[1;36m30.63\u001b[0m%\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "๐Ÿ“ Weighted R-factor \u001b[1m(\u001b[0mwR\u001b[1m)\u001b[0m: \u001b[1;36m30.63\u001b[0m%\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "๐Ÿ“ˆ Fitted parameters:\n" ] }, { "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", "\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", " \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", " \n", " \n", " \n", " \n", " \n", "
 datablockcategoryentryparameterstartfitteduncertaintyunitschange
1naclcelllength_a5.62005.6175N/Aร…0.04 % โ†“
2naclatom_siteNab_iso1.00001.0000N/Aร…ยฒ0.00 % โ†“
3naclatom_siteClb_iso1.00001.0000N/Aร…ยฒ0.00 % โ†“
4xray_pdflinked_phasesnaclscale0.50000.4469N/A10.61 % โ†“
5xray_pdfpeakdamp_q0.03000.0625N/Aร…โปยน108.42 % โ†‘
6xray_pdfpeaksharp_delta_25.00004.3628N/Aร…ยฒ12.74 % โ†“
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.analysis.current_calculator = 'pdffit'\n", "project.analysis.fit()\n", "project.analysis.show_fit_results()" ] }, { "cell_type": "markdown", "id": "24", "metadata": {}, "source": [ "## Plot Measured vs Calculated" ] }, { "cell_type": "code", "execution_count": 18, "id": "25", "metadata": { "execution": { "iopub.execute_input": "2026-01-06T13:53:38.527597Z", "iopub.status.busy": "2026-01-06T13:53:38.527466Z", "iopub.status.idle": "2026-01-06T13:53:38.699740Z", "shell.execute_reply": "2026-01-06T13:53:38.699285Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.plot_meas_vs_calc(expt_name='xray_pdf')" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.11" } }, "nbformat": 4, "nbformat_minor": 5 }