{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:34.986126Z", "iopub.status.busy": "2026-06-30T22:36:34.985894Z", "iopub.status.idle": "2026-06-30T22:36:34.990219Z", "shell.execute_reply": "2026-06-30T22:36:34.989401Z" }, "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: Co2SiO4, D20\n", "\n", "This example demonstrates a Rietveld refinement of Co2SiO4 crystal\n", "structure using constant wavelength neutron powder diffraction data\n", "from D20 at ILL.\n", "\n", "It also shows different ways to set free parameters: standard\n", "one-by-one and batch setting." ] }, { "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:36:34.992122Z", "iopub.status.busy": "2026-06-30T22:36:34.991906Z", "iopub.status.idle": "2026-06-30T22:36:37.831856Z", "shell.execute_reply": "2026-06-30T22:36:37.830853Z" } }, "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 shows 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:36:37.833639Z", "iopub.status.busy": "2026-06-30T22:36:37.833358Z", "iopub.status.idle": "2026-06-30T22:36:37.838197Z", "shell.execute_reply": "2026-06-30T22:36:37.837380Z" } }, "outputs": [], "source": [ "structure = StructureFactory.from_scratch(name='cosio')" ] }, { "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:36:37.839580Z", "iopub.status.busy": "2026-06-30T22:36:37.839429Z", "iopub.status.idle": "2026-06-30T22:36:37.842593Z", "shell.execute_reply": "2026-06-30T22:36:37.841534Z" } }, "outputs": [], "source": [ "structure.space_group.name_h_m = 'P n m a'\n", "structure.space_group.coord_system_code = 'abc'" ] }, { "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:36:37.843945Z", "iopub.status.busy": "2026-06-30T22:36:37.843792Z", "iopub.status.idle": "2026-06-30T22:36:37.846657Z", "shell.execute_reply": "2026-06-30T22:36:37.845964Z" } }, "outputs": [], "source": [ "structure.cell.length_a = 10.3\n", "structure.cell.length_b = 6.0\n", "structure.cell.length_c = 4.8" ] }, { "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:36:37.848074Z", "iopub.status.busy": "2026-06-30T22:36:37.847916Z", "iopub.status.idle": "2026-06-30T22:36:37.856329Z", "shell.execute_reply": "2026-06-30T22:36:37.855631Z" } }, "outputs": [], "source": [ "structure.atom_sites.create(\n", " id='Co1',\n", " type_symbol='Co',\n", " fract_x=0,\n", " fract_y=0,\n", " fract_z=0,\n", " adp_iso=0.5,\n", ")\n", "structure.atom_sites.create(\n", " id='Co2',\n", " type_symbol='Co',\n", " fract_x=0.279,\n", " fract_y=0.25,\n", " fract_z=0.985,\n", " adp_iso=0.5,\n", ")\n", "structure.atom_sites.create(\n", " id='Si',\n", " type_symbol='Si',\n", " fract_x=0.094,\n", " fract_y=0.25,\n", " fract_z=0.429,\n", " adp_iso=0.5,\n", ")\n", "structure.atom_sites.create(\n", " id='O1',\n", " type_symbol='O',\n", " fract_x=0.091,\n", " fract_y=0.25,\n", " fract_z=0.771,\n", " adp_iso=0.5,\n", ")\n", "structure.atom_sites.create(\n", " id='O2',\n", " type_symbol='O',\n", " fract_x=0.448,\n", " fract_y=0.25,\n", " fract_z=0.217,\n", " adp_iso=0.5,\n", ")\n", "structure.atom_sites.create(\n", " id='O3',\n", " type_symbol='O',\n", " fract_x=0.164,\n", " fract_y=0.032,\n", " fract_z=0.28,\n", " adp_iso=0.5,\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:36:37.858069Z", "iopub.status.busy": "2026-06-30T22:36:37.857832Z", "iopub.status.idle": "2026-06-30T22:36:38.109856Z", "shell.execute_reply": "2026-06-30T22:36:38.108819Z" } }, "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-cosio-d20'\u001b[0m: Co2SiO4, D20 \u001b[1m(\u001b[0mILL\u001b[1m)\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "βœ… Data \u001b[32m'meas-cosio-d20'\u001b[0m downloaded to \u001b[32m'../../../data/meas-cosio-d20.xye'\u001b[0m\n" ] } ], "source": [ "data_path = download_data('meas-cosio-d20', destination='data')" ] }, { "cell_type": "markdown", "id": "14", "metadata": {}, "source": [ "### Create Experiment" ] }, { "cell_type": "code", "execution_count": 8, "id": "15", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:38.111579Z", "iopub.status.busy": "2026-06-30T22:36:38.111427Z", "iopub.status.idle": "2026-06-30T22:36:38.320334Z", "shell.execute_reply": "2026-06-30T22:36:38.319555Z" } }, "outputs": [], "source": [ "expt = ExperimentFactory.from_data_path(name='d20', data_path=data_path)" ] }, { "cell_type": "markdown", "id": "16", "metadata": {}, "source": [ "### Set Instrument" ] }, { "cell_type": "code", "execution_count": 9, "id": "17", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:38.321936Z", "iopub.status.busy": "2026-06-30T22:36:38.321773Z", "iopub.status.idle": "2026-06-30T22:36:38.324754Z", "shell.execute_reply": "2026-06-30T22:36:38.323932Z" } }, "outputs": [], "source": [ "expt.instrument.setup_wavelength = 1.87\n", "expt.instrument.calib_twotheta_offset = 0.1" ] }, { "cell_type": "markdown", "id": "18", "metadata": {}, "source": [ "### Set Peak Profile" ] }, { "cell_type": "code", "execution_count": 10, "id": "19", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:38.326219Z", "iopub.status.busy": "2026-06-30T22:36:38.326044Z", "iopub.status.idle": "2026-06-30T22:36:38.336153Z", "shell.execute_reply": "2026-06-30T22:36:38.335301Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mPeak types\u001b[0m\n" ] }, { "data": { "text/html": [ "
TypeDescription
1*pseudo-voigtCWL pseudo-Voigt profile
2pseudo-voigt + berar-baldinozzi asymmetryCWL pseudo-Voigt profile with Berar-Baldinozzi asymmetry correction.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "expt.peak.show_supported()" ] }, { "cell_type": "code", "execution_count": 11, "id": "20", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:38.337586Z", "iopub.status.busy": "2026-06-30T22:36:38.337420Z", "iopub.status.idle": "2026-06-30T22:36:38.343927Z", "shell.execute_reply": "2026-06-30T22:36:38.343122Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "⚠️ Switching peak profile type adds these settings with defaults: \n", " β€’ asym_beba_a0=0.0 \n", " β€’ asym_beba_a1=0.0 \n", " β€’ asym_beba_b0=0.0 \n", " β€’ asym_beba_b1=0.0 \n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mPeak profile type for experiment \u001b[0m\u001b[32m'd20'\u001b[0m\u001b[1;36m changed to\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "pseudo-voigt + berar-baldinozzi asymmetry\n" ] } ], "source": [ "expt.peak.type = 'pseudo-voigt + berar-baldinozzi asymmetry'" ] }, { "cell_type": "code", "execution_count": 12, "id": "21", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:38.345270Z", "iopub.status.busy": "2026-06-30T22:36:38.345122Z", "iopub.status.idle": "2026-06-30T22:36:38.348236Z", "shell.execute_reply": "2026-06-30T22:36:38.347396Z" } }, "outputs": [], "source": [ "expt.peak.broad_gauss_u = 0.3\n", "expt.peak.broad_gauss_v = -0.5\n", "expt.peak.broad_gauss_w = 0.4" ] }, { "cell_type": "code", "execution_count": 13, "id": "22", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:38.349796Z", "iopub.status.busy": "2026-06-30T22:36:38.349613Z", "iopub.status.idle": "2026-06-30T22:36:38.352392Z", "shell.execute_reply": "2026-06-30T22:36:38.351807Z" } }, "outputs": [], "source": [ "expt.peak.cutoff_fwhm = 8" ] }, { "cell_type": "markdown", "id": "23", "metadata": {}, "source": [ "### Set Background" ] }, { "cell_type": "code", "execution_count": 14, "id": "24", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:38.354127Z", "iopub.status.busy": "2026-06-30T22:36:38.353971Z", "iopub.status.idle": "2026-06-30T22:36:38.360603Z", "shell.execute_reply": "2026-06-30T22:36:38.359809Z" } }, "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" } ], "source": [ "expt.background.show_supported()" ] }, { "cell_type": "code", "execution_count": 15, "id": "25", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:38.362001Z", "iopub.status.busy": "2026-06-30T22:36:38.361862Z", "iopub.status.idle": "2026-06-30T22:36:38.369713Z", "shell.execute_reply": "2026-06-30T22:36:38.368848Z" } }, "outputs": [], "source": [ "expt.background.create(id='1', position=8, intensity=500)\n", "expt.background.create(id='2', position=9, intensity=500)\n", "expt.background.create(id='3', position=10, intensity=500)\n", "expt.background.create(id='4', position=11, intensity=500)\n", "expt.background.create(id='5', position=12, intensity=500)\n", "expt.background.create(id='6', position=15, intensity=500)\n", "expt.background.create(id='7', position=25, intensity=500)\n", "expt.background.create(id='8', position=30, intensity=500)\n", "expt.background.create(id='9', position=50, intensity=500)\n", "expt.background.create(id='10', position=70, intensity=500)\n", "expt.background.create(id='11', position=90, intensity=500)\n", "expt.background.create(id='12', position=110, intensity=500)\n", "expt.background.create(id='13', position=130, intensity=500)\n", "expt.background.create(id='14', position=150, intensity=500)" ] }, { "cell_type": "markdown", "id": "26", "metadata": {}, "source": [ "### Set Linked Structures" ] }, { "cell_type": "code", "execution_count": 16, "id": "27", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:38.371370Z", "iopub.status.busy": "2026-06-30T22:36:38.371188Z", "iopub.status.idle": "2026-06-30T22:36:38.374631Z", "shell.execute_reply": "2026-06-30T22:36:38.373683Z" } }, "outputs": [], "source": [ "expt.linked_structures.create(structure_id='cosio', scale=1.0)" ] }, { "cell_type": "markdown", "id": "28", "metadata": {}, "source": [ "## πŸ“¦ Define Project\n", "\n", "The project object is used to manage the structure, experiment, and\n", "analysis.\n", "\n", "### Create Project" ] }, { "cell_type": "code", "execution_count": 17, "id": "29", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:38.376009Z", "iopub.status.busy": "2026-06-30T22:36:38.375866Z", "iopub.status.idle": "2026-06-30T22:36:38.588811Z", "shell.execute_reply": "2026-06-30T22:36:38.587977Z" } }, "outputs": [], "source": [ "project = Project(name='cosio_d20')" ] }, { "cell_type": "code", "execution_count": 18, "id": "30", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:38.590452Z", "iopub.status.busy": "2026-06-30T22:36:38.590291Z", "iopub.status.idle": "2026-06-30T22:36:38.639627Z", "shell.execute_reply": "2026-06-30T22:36:38.638831Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mSaving project πŸ“¦ \u001b[0m\u001b[32m'cosio_d20'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/refine-cosio-d20'\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": [ "β”œβ”€β”€ πŸ“ experiments/\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": [ " └── πŸ“„ cosio_d20.html\n" ] } ], "source": [ "project.save_as(dir_path='projects/refine-cosio-d20')" ] }, { "cell_type": "markdown", "id": "31", "metadata": {}, "source": [ "### Add Structure" ] }, { "cell_type": "code", "execution_count": 19, "id": "32", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:38.641134Z", "iopub.status.busy": "2026-06-30T22:36:38.640968Z", "iopub.status.idle": "2026-06-30T22:36:38.643645Z", "shell.execute_reply": "2026-06-30T22:36:38.642901Z" } }, "outputs": [], "source": [ "project.structures.add(structure)" ] }, { "cell_type": "markdown", "id": "33", "metadata": {}, "source": [ "### Add Experiment" ] }, { "cell_type": "code", "execution_count": 20, "id": "34", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:38.645301Z", "iopub.status.busy": "2026-06-30T22:36:38.645166Z", "iopub.status.idle": "2026-06-30T22:36:38.647856Z", "shell.execute_reply": "2026-06-30T22:36:38.647063Z" } }, "outputs": [], "source": [ "project.experiments.add(expt)" ] }, { "cell_type": "markdown", "id": "35", "metadata": {}, "source": [ "## πŸš€ Perform Analysis\n", "\n", "This section shows the analysis process, including how to set up\n", "calculation and fitting engines.\n", "\n", "### Display Structure" ] }, { "cell_type": "code", "execution_count": 21, "id": "36", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:38.649212Z", "iopub.status.busy": "2026-06-30T22:36:38.649061Z", "iopub.status.idle": "2026-06-30T22:36:38.745404Z", "shell.execute_reply": "2026-06-30T22:36:38.744737Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mStructure 🧩 \u001b[0m\u001b[32m'cosio'\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='cosio')" ] }, { "cell_type": "markdown", "id": "37", "metadata": {}, "source": [ "### Display Pattern" ] }, { "cell_type": "code", "execution_count": 22, "id": "38", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:38.746938Z", "iopub.status.busy": "2026-06-30T22:36:38.746766Z", "iopub.status.idle": "2026-06-30T22:36:39.280492Z", "shell.execute_reply": "2026-06-30T22:36:39.279745Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='d20')" ] }, { "cell_type": "code", "execution_count": 23, "id": "39", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:39.284354Z", "iopub.status.busy": "2026-06-30T22:36:39.284190Z", "iopub.status.idle": "2026-06-30T22:36:39.332468Z", "shell.execute_reply": "2026-06-30T22:36:39.331794Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='d20', x_min=41, x_max=54)" ] }, { "cell_type": "markdown", "id": "40", "metadata": {}, "source": [ "### Set Free Parameters" ] }, { "cell_type": "code", "execution_count": 24, "id": "41", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:39.334118Z", "iopub.status.busy": "2026-06-30T22:36:39.333949Z", "iopub.status.idle": "2026-06-30T22:36:39.345913Z", "shell.execute_reply": "2026-06-30T22:36:39.345171Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "⚠️ Parameter 'cosio.atom_site.Co1.fract_x' is constrained by symmetry. Ignoring free=True. \n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "⚠️ Parameter 'cosio.atom_site.Co1.fract_y' is constrained by symmetry. Ignoring free=True. \n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "⚠️ Parameter 'cosio.atom_site.Co1.fract_z' is constrained by symmetry. Ignoring free=True. \n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "⚠️ Parameter 'cosio.atom_site.Co2.fract_y' is constrained by symmetry. Ignoring free=True. \n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "⚠️ Parameter 'cosio.atom_site.Si.fract_y' is constrained by symmetry. Ignoring free=True. \n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "⚠️ Parameter 'cosio.atom_site.O1.fract_y' is constrained by symmetry. Ignoring free=True. \n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "⚠️ Parameter 'cosio.atom_site.O2.fract_y' is constrained by symmetry. Ignoring free=True. \n" ] } ], "source": [ "structure.cell.length_a.free = True\n", "structure.cell.length_b.free = True\n", "structure.cell.length_c.free = True\n", "\n", "for atom_site in structure.atom_sites:\n", " for parameter in ('fract_x', 'fract_y', 'fract_z'):\n", " getattr(atom_site, parameter).free = True\n", "\n", "for atom_site in structure.atom_sites:\n", " atom_site.adp_iso.free = True\n", "\n", "for label in ('O1', 'O2', 'O3'):\n", " atom_site = structure.atom_sites[label]\n", " atom_site.occupancy.free = True" ] }, { "cell_type": "code", "execution_count": 25, "id": "42", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:39.347466Z", "iopub.status.busy": "2026-06-30T22:36:39.347304Z", "iopub.status.idle": "2026-06-30T22:36:39.351306Z", "shell.execute_reply": "2026-06-30T22:36:39.350596Z" } }, "outputs": [], "source": [ "expt.linked_structures['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", "expt.peak.asym_beba_b0.free = True\n", "\n", "for point in expt.background:\n", " point.intensity.free = True" ] }, { "cell_type": "markdown", "id": "43", "metadata": {}, "source": [ "Show free parameters after selection." ] }, { "cell_type": "code", "execution_count": 26, "id": "44", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:39.352732Z", "iopub.status.busy": "2026-06-30T22:36:39.352572Z", "iopub.status.idle": "2026-06-30T22:36:39.454130Z", "shell.execute_reply": "2026-06-30T22:36:39.453287Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mFree parameters for both structures \u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36m🧩 data blocks\u001b[0m\u001b[1;36m)\u001b[0m\u001b[1;36m and experiments \u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36mπŸ”¬ data blocks\u001b[0m\u001b[1;36m)\u001b[0m\n" ] }, { "data": { "text/html": [ "
datablockcategoryentryparametervalueuncertaintyminmaxunits
1cosiocelllength_a10.30000-infinfΓ…
2cosiocelllength_b6.00000-infinfΓ…
3cosiocelllength_c4.80000-infinfΓ…
4cosioatom_siteCo1adp_iso0.50000-infinfΓ…Β²
5cosioatom_siteCo2fract_x0.27900-infinf
6cosioatom_siteCo2fract_z0.98500-infinf
7cosioatom_siteCo2adp_iso0.50000-infinfΓ…Β²
8cosioatom_siteSifract_x0.09400-infinf
9cosioatom_siteSifract_z0.42900-infinf
10cosioatom_siteSiadp_iso0.50000-infinfΓ…Β²
11cosioatom_siteO1fract_x0.09100-infinf
12cosioatom_siteO1fract_z0.77100-infinf
13cosioatom_siteO1occupancy1.00000-infinf
14cosioatom_siteO1adp_iso0.50000-infinfΓ…Β²
15cosioatom_siteO2fract_x0.44800-infinf
16cosioatom_siteO2fract_z0.21700-infinf
17cosioatom_siteO2occupancy1.00000-infinf
18cosioatom_siteO2adp_iso0.50000-infinfΓ…Β²
19cosioatom_siteO3fract_x0.16400-infinf
20cosioatom_siteO3fract_y0.03200-infinf
21cosioatom_siteO3fract_z0.28000-infinf
22cosioatom_siteO3occupancy1.00000-infinf
23cosioatom_siteO3adp_iso0.50000-infinfΓ…Β²
24d20linked_structurecosioscale1.00000-infinf
25d20peakasym_beba_b00.00000-infinf
26d20peakbroad_gauss_u0.30000-infinfdegΒ²
27d20peakbroad_gauss_v-0.50000-infinfdegΒ²
28d20peakbroad_gauss_w0.40000-infinfdegΒ²
29d20peakbroad_lorentz_y0.00000-infinfdeg
30d20instrumenttwotheta_offset0.10000-infinfdeg
31d20background1intensity500.00000-infinf
32d20background2intensity500.00000-infinf
33d20background3intensity500.00000-infinf
34d20background4intensity500.00000-infinf
35d20background5intensity500.00000-infinf
36d20background6intensity500.00000-infinf
37d20background7intensity500.00000-infinf
38d20background8intensity500.00000-infinf
39d20background9intensity500.00000-infinf
40d20background10intensity500.00000-infinf
41d20background11intensity500.00000-infinf
42d20background12intensity500.00000-infinf
43d20background13intensity500.00000-infinf
44d20background14intensity500.00000-infinf
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.parameters.free()" ] }, { "cell_type": "markdown", "id": "45", "metadata": {}, "source": [ "### Set Constraints\n", "\n", "Set aliases for parameters." ] }, { "cell_type": "code", "execution_count": 27, "id": "46", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:39.455657Z", "iopub.status.busy": "2026-06-30T22:36:39.455500Z", "iopub.status.idle": "2026-06-30T22:36:39.459254Z", "shell.execute_reply": "2026-06-30T22:36:39.458490Z" } }, "outputs": [], "source": [ "project.analysis.aliases.create(\n", " id='biso_Co1',\n", " param=project.structures['cosio'].atom_sites['Co1'].adp_iso,\n", ")\n", "project.analysis.aliases.create(\n", " id='biso_Co2',\n", " param=project.structures['cosio'].atom_sites['Co2'].adp_iso,\n", ")" ] }, { "cell_type": "markdown", "id": "47", "metadata": {}, "source": [ "Set constraints." ] }, { "cell_type": "code", "execution_count": 28, "id": "48", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:39.460684Z", "iopub.status.busy": "2026-06-30T22:36:39.460531Z", "iopub.status.idle": "2026-06-30T22:36:39.463793Z", "shell.execute_reply": "2026-06-30T22:36:39.462953Z" }, "lines_to_next_cell": 2 }, "outputs": [], "source": [ "project.analysis.constraints.create(expression='biso_Co2 = biso_Co1')" ] }, { "cell_type": "markdown", "id": "49", "metadata": {}, "source": [ "### Run Fitting" ] }, { "cell_type": "code", "execution_count": 29, "id": "50", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:36:39.465337Z", "iopub.status.busy": "2026-06-30T22:36:39.465177Z", "iopub.status.idle": "2026-06-30T22:37:20.512899Z", "shell.execute_reply": "2026-06-30T22:37:20.512034Z" } }, "outputs": [ { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function() {\n", " const button = document.getElementById('ed-fit-stop-d1f77d81dcbe40bfb572035f20588d5c-button');\n", " const status = document.getElementById('ed-fit-stop-d1f77d81dcbe40bfb572035f20588d5c-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;36mStandard 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'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
110.07424.43
2473.3873.8182.6% ↓
3916.6339.8146.1% ↓
413610.1419.1951.8% ↓
518013.3412.7633.5% ↓
622416.547.6440.1% ↓
726819.724.6139.6% ↓
831222.984.385.0% ↓
937828.024.38
1044733.024.38
1151338.064.38
1253340.664.38
" ], "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.38\u001b[0m at iteration \u001b[1;36m516\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "βœ… Fitting complete.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mSaving project πŸ“¦ \u001b[0m\u001b[32m'cosio_d20'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/refine-cosio-d20'\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": [ "β”‚ └── πŸ“„ cosio.edi\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "β”œβ”€β”€ πŸ“ experiments/\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "β”‚ └── πŸ“„ d20.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": [ " └── πŸ“„ cosio_d20.html\n" ] } ], "source": [ "project.analysis.fit()" ] }, { "cell_type": "code", "execution_count": 30, "id": "51", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:37:20.514450Z", "iopub.status.busy": "2026-06-30T22:37:20.514296Z", "iopub.status.idle": "2026-06-30T22:37:20.899793Z", "shell.execute_reply": "2026-06-30T22:37:20.899014Z" } }, "outputs": [ { "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)40.66
4πŸ” Iterations530
5πŸ“ Goodness-of-fit (reduced χ²)4.38
6πŸ“ R-factor (Rf, %)2.99
7πŸ“ R-factor squared (RfΒ², %)4.32
8πŸ“ Weighted R-factor (wR, %)4.54
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "πŸ“ˆ Refined parameters:\n" ] }, { "data": { "text/html": [ "
datablockcategoryentryparameterunitsstartvalues.u.change
1cosiocelllength_aΓ…10.300010.30840.00030.08 % ↑
2cosiocelllength_bΓ…6.00006.00360.00020.06 % ↑
3cosiocelllength_cΓ…4.80004.78640.00010.28 % ↓
4cosioatom_siteCo1adp_isoΓ…Β²0.50000.67160.107934.33 % ↑
5cosioatom_siteCo2fract_x0.27900.27920.00070.07 % ↑
6cosioatom_siteCo2fract_z0.98500.98500.00140.00 % ↓
7cosioatom_siteSifract_x0.09400.09380.00040.26 % ↓
8cosioatom_siteSifract_z0.42900.42940.00080.08 % ↑
9cosioatom_siteSiadp_isoΓ…Β²0.50000.68640.088437.28 % ↑
10cosioatom_siteO1fract_x0.09100.09110.00030.14 % ↑
11cosioatom_siteO1fract_z0.77100.77150.00060.07 % ↑
12cosioatom_siteO1occupancy1.00000.91480.01368.52 % ↓
13cosioatom_siteO1adp_isoΓ…Β²0.50000.46620.07756.77 % ↓
14cosioatom_siteO2fract_x0.44800.44820.00030.04 % ↑
15cosioatom_siteO2fract_z0.21700.21710.00070.04 % ↑
16cosioatom_siteO2occupancy1.00000.95880.01354.12 % ↓
17cosioatom_siteO2adp_isoΓ…Β²0.50000.67130.079534.26 % ↑
18cosioatom_siteO3fract_x0.16400.16360.00020.23 % ↓
19cosioatom_siteO3fract_y0.03200.03150.00031.47 % ↓
20cosioatom_siteO3fract_z0.28000.28020.00050.07 % ↑
21cosioatom_siteO3occupancy1.00000.95480.01184.52 % ↓
22cosioatom_siteO3adp_isoΓ…Β²0.50000.84990.061469.99 % ↑
23d20linked_structurecosioscale1.00001.33070.028933.07 % ↑
24d20peakasym_beba_b00.0000-0.00870.0019N/A
25d20peakbroad_gauss_udegΒ²0.30000.24220.006619.26 % ↓
26d20peakbroad_gauss_vdegΒ²-0.5000-0.53090.01436.17 % ↑
27d20peakbroad_gauss_wdegΒ²0.40000.38840.00892.91 % ↓
28d20peakbroad_lorentz_ydeg0.00000.01340.0043N/A
29d20instrumenttwotheta_offsetdeg0.10000.27620.0033176.23 % ↑
30d20background1intensity500.0000609.322814.244221.86 % ↑
31d20background2intensity500.0000581.19159.528516.24 % ↑
32d20background3intensity500.0000563.37579.053112.68 % ↑
33d20background4intensity500.0000540.71758.59048.14 % ↑
34d20background5intensity500.0000520.15785.92564.03 % ↑
35d20background6intensity500.0000507.78043.41711.56 % ↑
36d20background7intensity500.0000463.03153.14187.39 % ↓
37d20background8intensity500.0000430.98932.426913.80 % ↓
38d20background9intensity500.0000451.80452.18319.64 % ↓
39d20background10intensity500.0000429.42751.978614.11 % ↓
40d20background11intensity500.0000414.14542.144817.17 % ↓
41d20background12intensity500.0000362.41732.013127.52 % ↓
42d20background13intensity500.0000293.14951.907541.37 % ↓
43d20background14intensity500.0000241.33622.895851.73 % ↓
" ], "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" } ], "source": [ "project.display.fit.results()" ] }, { "cell_type": "code", "execution_count": 31, "id": "52", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:37:20.901615Z", "iopub.status.busy": "2026-06-30T22:37:20.901457Z", "iopub.status.idle": "2026-06-30T22:37:20.930542Z", "shell.execute_reply": "2026-06-30T22:37:20.929712Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
Loading plot…
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.fit.correlations()" ] }, { "cell_type": "markdown", "id": "53", "metadata": {}, "source": [ "### Display Pattern" ] }, { "cell_type": "code", "execution_count": 32, "id": "54", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:37:20.932338Z", "iopub.status.busy": "2026-06-30T22:37:20.932185Z", "iopub.status.idle": "2026-06-30T22:37:21.005009Z", "shell.execute_reply": "2026-06-30T22:37:21.004119Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='d20')" ] }, { "cell_type": "code", "execution_count": 33, "id": "55", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:37:21.007813Z", "iopub.status.busy": "2026-06-30T22:37:21.007635Z", "iopub.status.idle": "2026-06-30T22:37:21.101871Z", "shell.execute_reply": "2026-06-30T22:37:21.100912Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='d20', x_min=42, x_max=52)" ] }, { "cell_type": "markdown", "id": "56", "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." ] } ], "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 }