{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:05.486610Z", "iopub.status.busy": "2026-06-30T22:33:05.486406Z", "iopub.status.idle": "2026-06-30T22:33:05.490840Z", "shell.execute_reply": "2026-06-30T22:33:05.490080Z" }, "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: LBCO+Si, McStas\n", "\n", "This example demonstrates a Rietveld refinement of La0.5Ba0.5CoO3\n", "crystal structure with a small amount of Si phase using time-of-flight\n", "neutron powder diffraction data simulated with McStas." ] }, { "cell_type": "markdown", "id": "2", "metadata": {}, "source": [ "## πŸ› οΈ Import Library" ] }, { "cell_type": "code", "execution_count": 2, "id": "3", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:05.492392Z", "iopub.status.busy": "2026-06-30T22:33:05.492239Z", "iopub.status.idle": "2026-06-30T22:33:08.333241Z", "shell.execute_reply": "2026-06-30T22:33:08.332133Z" } }, "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 Structures\n", "\n", "This section shows how to add structures and modify their\n", "parameters.\n", "\n", "### Create Structure 1: LBCO" ] }, { "cell_type": "code", "execution_count": 3, "id": "5", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.334935Z", "iopub.status.busy": "2026-06-30T22:33:08.334662Z", "iopub.status.idle": "2026-06-30T22:33:08.339535Z", "shell.execute_reply": "2026-06-30T22:33:08.338595Z" } }, "outputs": [], "source": [ "structure_1 = StructureFactory.from_scratch(name='lbco')" ] }, { "cell_type": "markdown", "id": "6", "metadata": {}, "source": [ "#### Set Space Group" ] }, { "cell_type": "code", "execution_count": 4, "id": "7", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.341184Z", "iopub.status.busy": "2026-06-30T22:33:08.340963Z", "iopub.status.idle": "2026-06-30T22:33:08.344606Z", "shell.execute_reply": "2026-06-30T22:33:08.343737Z" } }, "outputs": [], "source": [ "structure_1.space_group.name_h_m = 'P m -3 m'\n", "structure_1.space_group.coord_system_code = '1'" ] }, { "cell_type": "markdown", "id": "8", "metadata": {}, "source": [ "#### Set Unit Cell" ] }, { "cell_type": "code", "execution_count": 5, "id": "9", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.346367Z", "iopub.status.busy": "2026-06-30T22:33:08.346135Z", "iopub.status.idle": "2026-06-30T22:33:08.349405Z", "shell.execute_reply": "2026-06-30T22:33:08.348634Z" } }, "outputs": [], "source": [ "structure_1.cell.length_a = 3.8909" ] }, { "cell_type": "markdown", "id": "10", "metadata": {}, "source": [ "#### Set Atom Sites" ] }, { "cell_type": "code", "execution_count": 6, "id": "11", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.351006Z", "iopub.status.busy": "2026-06-30T22:33:08.350843Z", "iopub.status.idle": "2026-06-30T22:33:08.357505Z", "shell.execute_reply": "2026-06-30T22:33:08.356643Z" } }, "outputs": [], "source": [ "structure_1.atom_sites.create(\n", " id='La',\n", " type_symbol='La',\n", " fract_x=0,\n", " fract_y=0,\n", " fract_z=0,\n", " adp_iso=0.2,\n", " occupancy=0.5,\n", ")\n", "structure_1.atom_sites.create(\n", " id='Ba',\n", " type_symbol='Ba',\n", " fract_x=0,\n", " fract_y=0,\n", " fract_z=0,\n", " adp_iso=0.2,\n", " occupancy=0.5,\n", ")\n", "structure_1.atom_sites.create(\n", " id='Co',\n", " type_symbol='Co',\n", " fract_x=0.5,\n", " fract_y=0.5,\n", " fract_z=0.5,\n", " adp_iso=0.2567,\n", ")\n", "structure_1.atom_sites.create(\n", " id='O',\n", " type_symbol='O',\n", " fract_x=0,\n", " fract_y=0.5,\n", " fract_z=0.5,\n", " adp_iso=1.4041,\n", ")" ] }, { "cell_type": "markdown", "id": "12", "metadata": {}, "source": [ "### Create Structure 2: Si" ] }, { "cell_type": "code", "execution_count": 7, "id": "13", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.359319Z", "iopub.status.busy": "2026-06-30T22:33:08.358958Z", "iopub.status.idle": "2026-06-30T22:33:08.363228Z", "shell.execute_reply": "2026-06-30T22:33:08.362498Z" } }, "outputs": [], "source": [ "structure_2 = StructureFactory.from_scratch(name='si')" ] }, { "cell_type": "markdown", "id": "14", "metadata": {}, "source": [ "#### Set Space Group" ] }, { "cell_type": "code", "execution_count": 8, "id": "15", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.365253Z", "iopub.status.busy": "2026-06-30T22:33:08.365034Z", "iopub.status.idle": "2026-06-30T22:33:08.368549Z", "shell.execute_reply": "2026-06-30T22:33:08.367677Z" } }, "outputs": [], "source": [ "structure_2.space_group.name_h_m = 'F d -3 m'\n", "structure_2.space_group.coord_system_code = '2'" ] }, { "cell_type": "markdown", "id": "16", "metadata": {}, "source": [ "#### Set Unit Cell" ] }, { "cell_type": "code", "execution_count": 9, "id": "17", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.370053Z", "iopub.status.busy": "2026-06-30T22:33:08.369888Z", "iopub.status.idle": "2026-06-30T22:33:08.372468Z", "shell.execute_reply": "2026-06-30T22:33:08.371977Z" } }, "outputs": [], "source": [ "structure_2.cell.length_a = 5.43146" ] }, { "cell_type": "markdown", "id": "18", "metadata": {}, "source": [ "#### Set Atom Sites" ] }, { "cell_type": "code", "execution_count": 10, "id": "19", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.374220Z", "iopub.status.busy": "2026-06-30T22:33:08.374047Z", "iopub.status.idle": "2026-06-30T22:33:08.378106Z", "shell.execute_reply": "2026-06-30T22:33:08.377257Z" } }, "outputs": [], "source": [ "structure_2.atom_sites.create(\n", " id='Si',\n", " type_symbol='Si',\n", " fract_x=0.0,\n", " fract_y=0.0,\n", " fract_z=0.0,\n", " adp_iso=0.0,\n", ")" ] }, { "cell_type": "markdown", "id": "20", "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": 11, "id": "21", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.379603Z", "iopub.status.busy": "2026-06-30T22:33:08.379455Z", "iopub.status.idle": "2026-06-30T22:33:08.527842Z", "shell.execute_reply": "2026-06-30T22:33:08.527078Z" } }, "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-lbco-si-mcstas'\u001b[0m: La0.5Ba0.5CoO3 + Si, McStas simulation\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "βœ… Data \u001b[32m'meas-lbco-si-mcstas'\u001b[0m downloaded to \u001b[32m'../../../data/meas-lbco-si-mcstas.xye'\u001b[0m\n" ] } ], "source": [ "data_path = download_data('meas-lbco-si-mcstas', destination='data')" ] }, { "cell_type": "markdown", "id": "22", "metadata": {}, "source": [ "### Create Experiment" ] }, { "cell_type": "code", "execution_count": 12, "id": "23", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.529671Z", "iopub.status.busy": "2026-06-30T22:33:08.529502Z", "iopub.status.idle": "2026-06-30T22:33:08.714589Z", "shell.execute_reply": "2026-06-30T22:33:08.713545Z" } }, "outputs": [], "source": [ "experiment = ExperimentFactory.from_data_path(\n", " name='mcstas',\n", " data_path=data_path,\n", " sample_form='powder',\n", " beam_mode='time-of-flight',\n", " radiation_probe='neutron',\n", " scattering_type='bragg',\n", ")" ] }, { "cell_type": "markdown", "id": "24", "metadata": {}, "source": [ "### Set Instrument" ] }, { "cell_type": "code", "execution_count": 13, "id": "25", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.716439Z", "iopub.status.busy": "2026-06-30T22:33:08.716204Z", "iopub.status.idle": "2026-06-30T22:33:08.719763Z", "shell.execute_reply": "2026-06-30T22:33:08.718996Z" } }, "outputs": [], "source": [ "experiment.instrument.setup_twotheta_bank = 94.90931761529106\n", "experiment.instrument.calib_d_to_tof_linear = 58724.76869981215" ] }, { "cell_type": "markdown", "id": "26", "metadata": {}, "source": [ "### Set Peak Profile" ] }, { "cell_type": "code", "execution_count": 14, "id": "27", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.721219Z", "iopub.status.busy": "2026-06-30T22:33:08.721047Z", "iopub.status.idle": "2026-06-30T22:33:08.724732Z", "shell.execute_reply": "2026-06-30T22:33:08.723916Z" } }, "outputs": [], "source": [ "experiment.peak.broad_gauss_sigma_0 = 45137\n", "experiment.peak.broad_gauss_sigma_1 = -52394\n", "experiment.peak.broad_gauss_sigma_2 = 22998\n", "experiment.peak.decay_beta_0 = 0.0055\n", "experiment.peak.decay_beta_1 = 0.0041\n", "experiment.peak.rise_alpha_0 = 0\n", "experiment.peak.rise_alpha_1 = 0.0097" ] }, { "cell_type": "markdown", "id": "28", "metadata": {}, "source": [ "### Set Background" ] }, { "cell_type": "markdown", "id": "29", "metadata": {}, "source": [ "Select the background type." ] }, { "cell_type": "code", "execution_count": 15, "id": "30", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.726491Z", "iopub.status.busy": "2026-06-30T22:33:08.726351Z", "iopub.status.idle": "2026-06-30T22:33:08.731319Z", "shell.execute_reply": "2026-06-30T22:33:08.730531Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mBackground type for experiment \u001b[0m\u001b[32m'mcstas'\u001b[0m\u001b[1;36m already set to\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "line-segment\n" ] } ], "source": [ "experiment.background.type = 'line-segment'" ] }, { "cell_type": "markdown", "id": "31", "metadata": {}, "source": [ "Add background points." ] }, { "cell_type": "code", "execution_count": 16, "id": "32", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.732834Z", "iopub.status.busy": "2026-06-30T22:33:08.732685Z", "iopub.status.idle": "2026-06-30T22:33:08.740024Z", "shell.execute_reply": "2026-06-30T22:33:08.739195Z" } }, "outputs": [], "source": [ "experiment.background.create(id='1', position=45000, intensity=0.2)\n", "experiment.background.create(id='2', position=50000, intensity=0.2)\n", "experiment.background.create(id='3', position=55000, intensity=0.2)\n", "experiment.background.create(id='4', position=65000, intensity=0.2)\n", "experiment.background.create(id='5', position=70000, intensity=0.2)\n", "experiment.background.create(id='6', position=75000, intensity=0.2)\n", "experiment.background.create(id='7', position=80000, intensity=0.2)\n", "experiment.background.create(id='8', position=85000, intensity=0.2)\n", "experiment.background.create(id='9', position=90000, intensity=0.2)\n", "experiment.background.create(id='10', position=95000, intensity=0.2)\n", "experiment.background.create(id='11', position=100000, intensity=0.2)\n", "experiment.background.create(id='12', position=105000, intensity=0.2)\n", "experiment.background.create(id='13', position=110000, intensity=0.2)" ] }, { "cell_type": "markdown", "id": "33", "metadata": {}, "source": [ "### Set Linked Structures" ] }, { "cell_type": "code", "execution_count": 17, "id": "34", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.741671Z", "iopub.status.busy": "2026-06-30T22:33:08.741452Z", "iopub.status.idle": "2026-06-30T22:33:08.745694Z", "shell.execute_reply": "2026-06-30T22:33:08.744966Z" } }, "outputs": [], "source": [ "experiment.linked_structures.create(structure_id='lbco', scale=4.0)\n", "experiment.linked_structures.create(structure_id='si', scale=0.2)" ] }, { "cell_type": "markdown", "id": "35", "metadata": {}, "source": [ "## πŸ“¦ Define Project\n", "\n", "The project object is used to manage structures, experiments, and\n", "analysis.\n", "\n", "### Create Project" ] }, { "cell_type": "code", "execution_count": 18, "id": "36", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.747180Z", "iopub.status.busy": "2026-06-30T22:33:08.747021Z", "iopub.status.idle": "2026-06-30T22:33:08.963966Z", "shell.execute_reply": "2026-06-30T22:33:08.963131Z" } }, "outputs": [], "source": [ "project = Project(name='lbco_si_mcstas')" ] }, { "cell_type": "markdown", "id": "37", "metadata": {}, "source": [ "### Add Structures" ] }, { "cell_type": "code", "execution_count": 19, "id": "38", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.965733Z", "iopub.status.busy": "2026-06-30T22:33:08.965551Z", "iopub.status.idle": "2026-06-30T22:33:08.968413Z", "shell.execute_reply": "2026-06-30T22:33:08.967757Z" } }, "outputs": [], "source": [ "project.structures.add(structure_1)\n", "project.structures.add(structure_2)" ] }, { "cell_type": "markdown", "id": "39", "metadata": {}, "source": [ "### Show Structures" ] }, { "cell_type": "code", "execution_count": 20, "id": "40", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.970544Z", "iopub.status.busy": "2026-06-30T22:33:08.970386Z", "iopub.status.idle": "2026-06-30T22:33:08.974994Z", "shell.execute_reply": "2026-06-30T22:33:08.974252Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mDefined structures 🧩\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1m[\u001b[0m\u001b[32m'lbco'\u001b[0m, \u001b[32m'si'\u001b[0m\u001b[1m]\u001b[0m\n" ] } ], "source": [ "project.structures.show_names()" ] }, { "cell_type": "markdown", "id": "41", "metadata": {}, "source": [ "### Add Experiments" ] }, { "cell_type": "code", "execution_count": 21, "id": "42", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.976329Z", "iopub.status.busy": "2026-06-30T22:33:08.976180Z", "iopub.status.idle": "2026-06-30T22:33:08.978883Z", "shell.execute_reply": "2026-06-30T22:33:08.978120Z" } }, "outputs": [], "source": [ "project.experiments.add(experiment)" ] }, { "cell_type": "markdown", "id": "43", "metadata": {}, "source": [ "### Display Structure" ] }, { "cell_type": "code", "execution_count": 22, "id": "44", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:08.980569Z", "iopub.status.busy": "2026-06-30T22:33:08.980422Z", "iopub.status.idle": "2026-06-30T22:33:09.686515Z", "shell.execute_reply": "2026-06-30T22:33:09.685737Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mStructure 🧩 \u001b[0m\u001b[32m'lbco'\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" }, { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mStructure 🧩 \u001b[0m\u001b[32m'si'\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='lbco')\n", "project.display.structure(struct_name='si')" ] }, { "cell_type": "markdown", "id": "45", "metadata": {}, "source": [ "### Set Excluded Regions\n", "\n", "Show measured data as loaded from the file." ] }, { "cell_type": "code", "execution_count": 23, "id": "46", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:09.688016Z", "iopub.status.busy": "2026-06-30T22:33:09.687856Z", "iopub.status.idle": "2026-06-30T22:33:10.138299Z", "shell.execute_reply": "2026-06-30T22:33:10.137488Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='mcstas')" ] }, { "cell_type": "markdown", "id": "47", "metadata": {}, "source": [ "Add excluded regions." ] }, { "cell_type": "code", "execution_count": 24, "id": "48", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:10.140463Z", "iopub.status.busy": "2026-06-30T22:33:10.140057Z", "iopub.status.idle": "2026-06-30T22:33:10.144644Z", "shell.execute_reply": "2026-06-30T22:33:10.143884Z" } }, "outputs": [], "source": [ "experiment.excluded_regions.create(id='1', start=0, end=40000)\n", "experiment.excluded_regions.create(id='2', start=108000, end=200000)" ] }, { "cell_type": "markdown", "id": "49", "metadata": {}, "source": [ "Show excluded regions." ] }, { "cell_type": "code", "execution_count": 25, "id": "50", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:10.146230Z", "iopub.status.busy": "2026-06-30T22:33:10.146058Z", "iopub.status.idle": "2026-06-30T22:33:10.152340Z", "shell.execute_reply": "2026-06-30T22:33:10.151803Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mExcluded regions\u001b[0m\n" ] }, { "data": { "text/html": [ "
startend
10.0000040000.00000
2108000.00000200000.00000
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "experiment.excluded_regions.show()" ] }, { "cell_type": "markdown", "id": "51", "metadata": {}, "source": [ "Show measured data after adding excluded regions." ] }, { "cell_type": "code", "execution_count": 26, "id": "52", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:10.154279Z", "iopub.status.busy": "2026-06-30T22:33:10.154130Z", "iopub.status.idle": "2026-06-30T22:33:10.548980Z", "shell.execute_reply": "2026-06-30T22:33:10.548254Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='mcstas')" ] }, { "cell_type": "markdown", "id": "53", "metadata": {}, "source": [ "Show experiment as text." ] }, { "cell_type": "code", "execution_count": 27, "id": "54", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:10.552028Z", "iopub.status.busy": "2026-06-30T22:33:10.551862Z", "iopub.status.idle": "2026-06-30T22:33:10.567525Z", "shell.execute_reply": "2026-06-30T22:33:10.566563Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mExperiment πŸ”¬ \u001b[0m\u001b[32m'mcstas'\u001b[0m\u001b[1;36m as text\u001b[0m\n" ] }, { "data": { "text/html": [ "
Edi
1data_mcstas
2
3_experiment_type.sample_form powder
4_experiment_type.beam_mode time-of-flight
5_experiment_type.radiation_probe neutron
6_experiment_type.scattering_type bragg
7
8_diffrn.ambient_temperature ?
9_diffrn.ambient_pressure ?
10_diffrn.ambient_magnetic_field ?
11_diffrn.ambient_electric_field ?
12
13_calculator.type cryspy
14
15_peak.rise_alpha_0 0.
16_peak.rise_alpha_1 0.0097
17_peak.decay_beta_0 0.0055
18_peak.decay_beta_1 0.0041
19_peak.broad_gauss_sigma_0 45137
20_peak.broad_gauss_sigma_1 -52394
21_peak.broad_gauss_sigma_2 22998
22_peak.broad_gauss_size_g 0.
23_peak.broad_gauss_strain_g 0.
24_peak.cutoff_fwhm 0.
25_peak.type tof-jorgensen
26
27_instrument.setup_twotheta_bank 94.90931762
28_instrument.calib_d_to_tof_offset 0.
29_instrument.calib_d_to_tof_linear 58724.76869981
30_instrument.calib_d_to_tof_quadratic 0.
31_instrument.calib_d_to_tof_reciprocal 0.
32
33_absorption.type none
34
35loop_
36_linked_structure.structure_id
37_linked_structure.scale
38lbco 4.
39si 0.2
40
41loop_
42_excluded_region.id
43_excluded_region.start
44_excluded_region.end
451 0. 40000
462 108000 200000
47
48_background.type line-segment
49
50loop_
51_background.id
52_background.position
53_background.intensity
541 45000 0.2
552 50000 0.2
563 55000 0.2
574 65000 0.2
585 70000 0.2
596 75000 0.2
607 80000 0.2
618 85000 0.2
629 90000 0.2
6310 95000 0.2
6411 100000 0.2
6512 105000 0.2
6613 110000 0.2
67
68loop_
69_data.time_of_flight
70_data.id
71_data.d_spacing
72_data.intensity_meas
73_data.intensity_meas_su
74_data.intensity_calc
75_data.intensity_bkg
76_data.calc_status
7741168.1286 1 0.70103518 0.21537107 0.02485114 0.21632254 0.2 incl
7841273.8536 2 0.70283552 0.26087313 0.03329888 0.24071375 0.2 incl
7941379.5785 3 0.70463587 0.30433686 0.03547088 0.27614644 0.2 incl
8041485.3035 4 0.70643622 0.47366708 0.04206284 0.30440757 0.2 incl
8141591.0285 5 0.70823657 0.6002652 0.04196648 0.30520219 0.2 incl
8241696.7534 6 0.71003691 0.60174483 0.03965186 0.27954292 0.2 incl
8341802.4784 7 0.71183726 0.50118258 0.03810349 0.24616907 0.2 incl
8441908.2034 8 0.71363761 0.37702264 0.03458906 0.22068129 0.2 incl
8542013.9284 9 0.71543795 0.27533183 0.03190951 0.20713221 0.2 incl
8642119.6533 10 0.7172383 0.26182311 0.02830043 0.20214356 0.2 incl
87...
88145835.8489 991 2.48337886 0.2240686 0.01131008 0.2 0.2 excl
89145941.5739 992 2.4851792 0.21377274 0.01070627 0.2 0.2 excl
90146047.2988 993 2.48697955 0.20927726 0.0108552 0.2 0.2 excl
91146153.0238 994 2.4887799 0.21839779 0.01091455 0.2 0.2 excl
92146258.7488 995 2.49058024 0.21613293 0.01104795 0.2 0.2 excl
93146364.4737 996 2.49238059 0.20571926 0.01109275 0.2 0.2 excl
94146470.1987 997 2.49418094 0.22615941 0.01142946 0.2 0.2 excl
95146575.9237 998 2.49598129 0.22113311 0.01151463 0.2 0.2 excl
96146681.6486 999 2.49778163 0.2086239 0.01097638 0.2 0.2 excl
97146787.3736 1000 2.49958198 0.20883912 0.01092893 0.2 0.2 excl
98
99loop_
100_refln.id
101_refln.structure_id
102_refln.d_spacing
103_refln.sin_theta_over_lambda
104_refln.index_h
105_refln.index_k
106_refln.index_l
107_refln.f_calc
108_refln.f_squared_calc
109_refln.time_of_flight
1101 lbco 1.74006338 0.28734586 2 1 0 0.10595474 0.01122641 102184.81943898
1112 lbco 1.58845327 0.31477161 2 1 1 0.39025607 0.1522998 93281.55106887
1123 lbco 1.37564089 0.36346695 2 2 0 2.33500019 5.45222587 80784.19293006
1134 lbco 1.29696667 0.38551492 2 2 1 0.06467317 0.00418262 76164.06751137
1145 lbco 1.29696667 0.38551492 3 0 0 0.06467317 0.00418262 76164.06751137
1156 lbco 1.23041061 0.40636841 3 1 0 0.42233682 0.17836839 72255.57875963
1167 lbco 1.17315049 0.42620278 3 1 1 1.7530811 3.07329336 68892.99121159
1178 lbco 1.12320608 0.44515429 2 2 2 2.19435299 4.81518503 65960.0173204
1189 lbco 1.0791415 0.46333127 3 2 0 0.02740221 0.00075088 63372.3347908
11910 lbco 1.03988677 0.48082158 3 2 1 0.45063705 0.20307375 61067.10981657
120...
12142 si 0.85878923 0.58221503 6 2 0 0. 0. 50432.19895265
12243 si 0.82828988 0.60365339 5 3 3 3.31928 11.01761972 48641.13190237
12344 si 0.8188234 0.61063228 6 2 2 6.63856 44.07047887 48085.21499475
12445 si 0.78396372 0.63778461 4 4 4 6.63856 44.07047887 46038.08831826
12546 si 0.76055653 0.65741333 5 5 1 3.31928 11.01761972 44663.50610299
12647 si 0.76055653 0.65741333 7 1 1 3.31928 11.01761972 44663.50610299
12748 si 0.75320798 0.66382727 6 4 0 0. 0. 44231.96452271
12849 si 0.72580937 0.68888612 6 4 2 0. 0. 42622.98752015
12950 si 0.70711586 0.7070977 7 3 1 3.31928 11.01761972 41525.21546552
13051 si 0.70711586 0.7070977 5 5 3 3.31928 11.01761972 41525.21546552
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.experiments['mcstas'].show_as_text()" ] }, { "cell_type": "markdown", "id": "55", "metadata": {}, "source": [ "## πŸš€ Perform Analysis\n", "\n", "This section outlines the analysis process, including how to configure\n", "calculation and fitting engines.\n", "\n", "### Set Free Parameters\n", "\n", "Set structure parameters to be optimized." ] }, { "cell_type": "code", "execution_count": 28, "id": "56", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:10.569617Z", "iopub.status.busy": "2026-06-30T22:33:10.569445Z", "iopub.status.idle": "2026-06-30T22:33:10.573210Z", "shell.execute_reply": "2026-06-30T22:33:10.572183Z" } }, "outputs": [], "source": [ "structure_1.cell.length_a.free = True\n", "structure_1.atom_sites['Co'].adp_iso.free = True\n", "structure_1.atom_sites['O'].adp_iso.free = True\n", "\n", "structure_2.cell.length_a.free = True" ] }, { "cell_type": "markdown", "id": "57", "metadata": {}, "source": [ "Set experiment parameters to be optimized." ] }, { "cell_type": "code", "execution_count": 29, "id": "58", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:10.574977Z", "iopub.status.busy": "2026-06-30T22:33:10.574731Z", "iopub.status.idle": "2026-06-30T22:33:10.581927Z", "shell.execute_reply": "2026-06-30T22:33:10.580988Z" } }, "outputs": [], "source": [ "experiment.linked_structures['lbco'].scale.free = True\n", "experiment.linked_structures['si'].scale.free = True\n", "\n", "experiment.peak.broad_gauss_sigma_0.free = True\n", "experiment.peak.broad_gauss_sigma_1.free = True\n", "experiment.peak.broad_gauss_sigma_2.free = True\n", "\n", "experiment.peak.rise_alpha_1.free = True\n", "experiment.peak.decay_beta_0.free = True\n", "experiment.peak.decay_beta_1.free = True\n", "\n", "for point in experiment.background:\n", " point.intensity.free = True" ] }, { "cell_type": "markdown", "id": "59", "metadata": {}, "source": [ "### Run Fitting" ] }, { "cell_type": "code", "execution_count": 30, "id": "60", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:10.583731Z", "iopub.status.busy": "2026-06-30T22:33:10.583562Z", "iopub.status.idle": "2026-06-30T22:33:21.066043Z", "shell.execute_reply": "2026-06-30T22:33:21.065322Z" } }, "outputs": [ { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function() {\n", " const button = document.getElementById('ed-fit-stop-5303ae0f3f9d4371bb5bb8c53cb7400c-button');\n", " const status = document.getElementById('ed-fit-stop-5303ae0f3f9d4371bb5bb8c53cb7400c-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'mcstas'\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.04480.81
2291.06283.0441.1% ↓
3572.2837.9286.6% ↓
4833.2228.7824.1% ↓
5843.2628.431.2% ↓
61094.1610.8162.0% ↓
71355.339.6410.8% ↓
81616.289.531.1% ↓
92439.829.53
" ], "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;36m9.53\u001b[0m at iteration \u001b[1;36m220\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "βœ… Fitting complete.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "βš™οΈ Settings used:\n" ] }, { "data": { "text/html": [ "
NameValueDescription
1max_iterations1000Maximum solver iterations.
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "πŸ“‹ Least-squares fit results:\n" ] }, { "data": { "text/html": [ "
MetricValue
1πŸ§ͺ Minimizerlmfit (leastsq)
2βœ… Overall statussuccess
3⏱️ Fitting time (seconds)9.82
4πŸ” Iterations240
5πŸ“ Goodness-of-fit (reduced χ²)9.53
6πŸ“ R-factor (Rf, %)5.81
7πŸ“ R-factor squared (RfΒ², %)5.35
8πŸ“ Weighted R-factor (wR, %)4.92
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "πŸ“ˆ Refined parameters:\n" ] }, { "data": { "text/html": [ "
datablockcategoryentryparameterunitsstartvalues.u.change
1lbcocelllength_aΓ…3.89093.89050.00020.01 % ↓
2lbcoatom_siteCoadp_isoΓ…Β²0.25670.23090.143510.05 % ↓
3lbcoatom_siteOadp_isoΓ…Β²1.40412.11790.047850.84 % ↑
4sicelllength_aΓ…5.43155.43580.00190.08 % ↑
5mcstaslinked_structurelbcoscale4.000028.94660.3453623.66 % ↑
6mcstaslinked_structuresiscale0.20000.03050.002684.77 % ↓
7mcstaspeakrise_alpha_1ΞΌs/Γ…0.00970.00980.00040.58 % ↑
8mcstaspeakdecay_beta_0ΞΌs0.00550.00550.00020.85 % ↑
9mcstaspeakdecay_beta_1ΞΌs/Γ…0.00410.00430.00054.31 % ↑
10mcstaspeakbroad_gauss_sigma_0ΞΌsΒ²45137.000039762.72174803.037411.91 % ↓
11mcstaspeakbroad_gauss_sigma_1ΞΌs/Γ…-52394.0000-43393.90856407.909117.18 % ↓
12mcstaspeakbroad_gauss_sigma_2ΞΌsΒ²/Γ…Β²22998.000019740.95962007.920714.16 % ↓
13mcstasbackground1intensity0.20000.25680.014028.38 % ↑
14mcstasbackground2intensity0.20000.25980.013729.91 % ↑
15mcstasbackground3intensity0.20000.26740.008133.69 % ↑
16mcstasbackground4intensity0.20000.26910.006234.57 % ↑
17mcstasbackground5intensity0.20000.24980.006124.88 % ↑
18mcstasbackground6intensity0.20000.24680.004723.40 % ↑
19mcstasbackground7intensity0.20000.24510.005722.57 % ↑
20mcstasbackground8intensity0.20000.24120.003620.60 % ↑
21mcstasbackground9intensity0.20000.22290.003511.47 % ↑
22mcstasbackground10intensity0.20000.25990.004329.93 % ↑
23mcstasbackground11intensity0.20000.22760.003713.78 % ↑
24mcstasbackground12intensity0.20000.22150.004510.75 % ↑
25mcstasbackground13intensity0.20000.22440.013412.21 % ↑
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
β€’ start = parameter value before refinement
β€’ value = refined value from least-squares minimization
β€’ s.u. = standard uncertainty (one sigma), from the covariance matrix
β€’ change = relative change from start, in %; ↑ = increase, ↓ = decrease
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n", "
\n", "
Loading plot…
\n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.analysis.fit()\n", "project.display.fit.results()\n", "project.display.fit.correlations()" ] }, { "cell_type": "markdown", "id": "61", "metadata": {}, "source": [ "### Display Pattern" ] }, { "cell_type": "code", "execution_count": 31, "id": "62", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:21.067817Z", "iopub.status.busy": "2026-06-30T22:33:21.067662Z", "iopub.status.idle": "2026-06-30T22:33:21.118307Z", "shell.execute_reply": "2026-06-30T22:33:21.117389Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='mcstas')" ] }, { "cell_type": "markdown", "id": "63", "metadata": {}, "source": [ "## πŸ’Ύ Save Project" ] }, { "cell_type": "code", "execution_count": 32, "id": "64", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:33:21.120072Z", "iopub.status.busy": "2026-06-30T22:33:21.119903Z", "iopub.status.idle": "2026-06-30T22:33:21.375921Z", "shell.execute_reply": "2026-06-30T22:33:21.374956Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mSaving project πŸ“¦ \u001b[0m\u001b[32m'lbco_si_mcstas'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/refine-lbco-si-mcstas'\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": [ "β”‚ └── πŸ“„ lbco.edi\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "β”‚ └── πŸ“„ si.edi\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "β”œβ”€β”€ πŸ“ experiments/\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "β”‚ └── πŸ“„ mcstas.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": [ " └── πŸ“„ lbco_si_mcstas.html\n" ] } ], "source": [ "project.save_as(dir_path='projects/refine-lbco-si-mcstas')" ] } ], "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 }