{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "0",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:10.978206Z",
"iopub.status.busy": "2026-08-18T18:19:10.978046Z",
"iopub.status.idle": "2026-08-18T18:19:10.981925Z",
"shell.execute_reply": "2026-08-18T18:19:10.981222Z"
},
"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.20.1"
]
},
{
"cell_type": "markdown",
"id": "1",
"metadata": {},
"source": [
"# Structure Refinement: LaM(7)O3, P02.1 Synchrotron XRD\n",
"\n",
"This example refines the compositionally complex LaM(7)O3 perovskite,\n",
"with La on the A site and an equimolar mixture of Ti, Cr, Mn, Fe, Co,\n",
"Ni, and Cu on the B site. The low-temperature synchrotron X-ray powder\n",
"diffraction pattern was collected at the P02.1 beamline at PETRA III.\n",
"The workflow starts from approximate structural and profile parameters,\n",
"estimates the background from the measured pattern, and improves the\n",
"model in two fitting stages."
]
},
{
"cell_type": "markdown",
"id": "2",
"metadata": {},
"source": [
"## 🛠️ Import Library"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:10.983251Z",
"iopub.status.busy": "2026-08-18T18:19:10.983099Z",
"iopub.status.idle": "2026-08-18T18:19:13.702050Z",
"shell.execute_reply": "2026-08-18T18:19:13.701209Z"
}
},
"outputs": [],
"source": [
"import easydiffraction as edi"
]
},
{
"cell_type": "markdown",
"id": "4",
"metadata": {},
"source": [
"## 📦 Define Project\n",
"\n",
"The project manages the structures, experiments, analysis, and saved\n",
"results used throughout the tutorial.\n",
"\n",
"### Create Project"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:13.704440Z",
"iopub.status.busy": "2026-08-18T18:19:13.704161Z",
"iopub.status.idle": "2026-08-18T18:19:13.998530Z",
"shell.execute_reply": "2026-08-18T18:19:13.997616Z"
}
},
"outputs": [],
"source": [
"project = edi.Project(\n",
" name='lam7o3_p021',\n",
" description='LaM(7)O3 refinement using P02.1 synchrotron X-ray data.',\n",
")"
]
},
{
"cell_type": "markdown",
"id": "6",
"metadata": {},
"source": [
"### Save Initial Project\n",
"\n",
"Create the project directory before fitting so that analysis results\n",
"can be written as they are produced."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "7",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.000696Z",
"iopub.status.busy": "2026-08-18T18:19:14.000536Z",
"iopub.status.idle": "2026-08-18T18:19:14.051763Z",
"shell.execute_reply": "2026-08-18T18:19:14.050901Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mSaving project 📦 \u001b[0m\u001b[32m'lam7o3_p021'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/refine-lam7o3-p021'\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"├── 📄 project.edi\n",
"├── 📁 structures/\n",
"├── 📁 experiments/\n",
"├── 📁 analysis/\n",
"│ └── 📄 analysis.edi\n",
"└── 📁 reports/\n",
" └── 📄 lam7o3_p021.html\n"
]
}
],
"source": [
"project.save_as(dir_path='projects/refine-lam7o3-p021')"
]
},
{
"cell_type": "markdown",
"id": "8",
"metadata": {},
"source": [
"## 🧩 Define Structure\n",
"\n",
"The Pnma structure is initialized from approximate values rather than\n",
"the final refined values.\n",
"\n",
"### Create Structure\n",
"\n",
"Define the structure as an inline CIF. Empty uncertainty parentheses,\n",
"such as `5.5()`, mark a parameter as free without assigning an initial\n",
"standard uncertainty. Values without parentheses remain fixed."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "9",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.053499Z",
"iopub.status.busy": "2026-08-18T18:19:14.053257Z",
"iopub.status.idle": "2026-08-18T18:19:14.056664Z",
"shell.execute_reply": "2026-08-18T18:19:14.056007Z"
}
},
"outputs": [],
"source": [
"structure_cif = \"\"\"\n",
"data_lam7o3\n",
"\n",
"_cell.length_a 5.5()\n",
"_cell.length_b 7.7()\n",
"_cell.length_c 5.5()\n",
"_cell.angle_alpha 90.\n",
"_cell.angle_beta 90.\n",
"_cell.angle_gamma 90.\n",
"\n",
"_space_group.name_h_m \"P n m a\"\n",
"_space_group.coord_system_code abc\n",
"\n",
"loop_\n",
"_atom_site.id\n",
"_atom_site.type_symbol\n",
"_atom_site.fract_x\n",
"_atom_site.fract_y\n",
"_atom_site.fract_z\n",
"_atom_site.occupancy\n",
"_atom_site.adp_iso\n",
"_atom_site.adp_type\n",
"La La 0.48() 0.25 0.004() 1. 0.1() Biso\n",
"Ti Ti 0. 0. 0. 0.14286 0.1() Biso\n",
"Cr Cr 0. 0. 0. 0.14286 0.1 Biso\n",
"Mn Mn 0. 0. 0. 0.14286 0.1 Biso\n",
"Fe Fe 0. 0. 0. 0.14286 0.1 Biso\n",
"Co Co 0. 0. 0. 0.14286 0.1 Biso\n",
"Ni Ni 0. 0. 0. 0.14286 0.1 Biso\n",
"Cu Cu 0. 0. 0. 0.14286 0.1 Biso\n",
"O1 O 0.51() 0.25 0.57() 1. 0.1() Biso\n",
"O2 O 0.22() 0.03() 0.27() 1. 0.1 Biso\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "10",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.058494Z",
"iopub.status.busy": "2026-08-18T18:19:14.058310Z",
"iopub.status.idle": "2026-08-18T18:19:14.069654Z",
"shell.execute_reply": "2026-08-18T18:19:14.068784Z"
}
},
"outputs": [],
"source": [
"project.structures.add_from_cif_str(structure_cif)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "11",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.071117Z",
"iopub.status.busy": "2026-08-18T18:19:14.070959Z",
"iopub.status.idle": "2026-08-18T18:19:14.075590Z",
"shell.execute_reply": "2026-08-18T18:19:14.074559Z"
}
},
"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'lam7o3'\u001b[0m\u001b[1m]\u001b[0m\n"
]
}
],
"source": [
"project.structures.show_names()"
]
},
{
"cell_type": "markdown",
"id": "12",
"metadata": {},
"source": [
"Use a short alias to access the structure parameters below."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "13",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.077103Z",
"iopub.status.busy": "2026-08-18T18:19:14.076936Z",
"iopub.status.idle": "2026-08-18T18:19:14.079637Z",
"shell.execute_reply": "2026-08-18T18:19:14.078871Z"
}
},
"outputs": [],
"source": [
"structure = project.structures['lam7o3']"
]
},
{
"cell_type": "markdown",
"id": "14",
"metadata": {},
"source": [
"### Display Structure\n",
"\n",
"Inspect the structure as text and as an interactive crystal model."
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "15",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.081128Z",
"iopub.status.busy": "2026-08-18T18:19:14.080964Z",
"iopub.status.idle": "2026-08-18T18:19:14.207007Z",
"shell.execute_reply": "2026-08-18T18:19:14.206266Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mStructure 🧩 \u001b[0m\u001b[32m'lam7o3'\u001b[0m\u001b[1;36m as text\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"
| Edi |
|---|
| 1 | data_lam7o3 |
|---|
| 2 | |
|---|
| 3 | _cell.length_a 5.5() |
|---|
| 4 | _cell.length_b 7.7() |
|---|
| 5 | _cell.length_c 5.5() |
|---|
| 6 | _cell.angle_alpha 90. |
|---|
| 7 | _cell.angle_beta 90. |
|---|
| 8 | _cell.angle_gamma 90. |
|---|
| 9 | |
|---|
| 10 | _space_group.name_h_m "P n m a" |
|---|
| 11 | _space_group.coord_system_code abc |
|---|
| 12 | |
|---|
| 13 | _geom.min_bond_distance_cutoff 0. |
|---|
| 14 | _geom.bond_distance_inc 0.25 |
|---|
| 15 | |
|---|
| 16 | loop_ |
|---|
| 17 | _atom_site.id |
|---|
| 18 | _atom_site.type_symbol |
|---|
| 19 | _atom_site.fract_x |
|---|
| 20 | _atom_site.fract_y |
|---|
| 21 | _atom_site.fract_z |
|---|
| 22 | _atom_site.wyckoff_letter |
|---|
| 23 | _atom_site.multiplicity |
|---|
| 24 | _atom_site.occupancy |
|---|
| 25 | _atom_site.adp_iso |
|---|
| 26 | _atom_site.adp_type |
|---|
| 27 | La La 0.48() 0.25 0.004() c 4 1. 0.1() Biso |
|---|
| 28 | Ti Ti 0. 0. 0. a 4 0.14286 0.1() Biso |
|---|
| 29 | Cr Cr 0. 0. 0. a 4 0.14286 0.1 Biso |
|---|
| 30 | Mn Mn 0. 0. 0. a 4 0.14286 0.1 Biso |
|---|
| 31 | Fe Fe 0. 0. 0. a 4 0.14286 0.1 Biso |
|---|
| 32 | Co Co 0. 0. 0. a 4 0.14286 0.1 Biso |
|---|
| 33 | Ni Ni 0. 0. 0. a 4 0.14286 0.1 Biso |
|---|
| 34 | Cu Cu 0. 0. 0. a 4 0.14286 0.1 Biso |
|---|
| 35 | O1 O 0.51() 0.25 0.57() c 4 1. 0.1() Biso |
|---|
| 36 | O2 O 0.22() 0.03() 0.27() d 8 1. 0.1 Biso |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"structure.show_as_text()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "16",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.208803Z",
"iopub.status.busy": "2026-08-18T18:19:14.208629Z",
"iopub.status.idle": "2026-08-18T18:19:14.234390Z",
"shell.execute_reply": "2026-08-18T18:19:14.233449Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mStructure 🧩 \u001b[0m\u001b[32m'lam7o3'\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='lam7o3')"
]
},
{
"cell_type": "markdown",
"id": "17",
"metadata": {},
"source": [
"## 🔬 Define Experiment\n",
"\n",
"Load the measured pattern, configure the instrument and peak profile,\n",
"and link the structure to the experiment.\n",
"\n",
"### Download Data\n",
"\n",
"The first two columns contain 2-theta and intensity. When a third\n",
"column of standard uncertainties is absent, EasyDiffraction estimates\n",
"it from the square root of the intensity."
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "18",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.235822Z",
"iopub.status.busy": "2026-08-18T18:19:14.235668Z",
"iopub.status.idle": "2026-08-18T18:19:14.429996Z",
"shell.execute_reply": "2026-08-18T18:19:14.427124Z"
}
},
"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-hep7c-xray-synchrotron'\u001b[0m: La high-entropy perovskite \u001b[1m(\u001b[0m\u001b[1;36m7\u001b[0m B-cations\u001b[1m)\u001b[0m, synchrotron X-ray\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Data \u001b[32m'meas-hep7c-xray-synchrotron'\u001b[0m downloaded to \u001b[32m'../../../data/meas-hep7c-xray-synchrotron.dat'\u001b[0m\n"
]
}
],
"source": [
"data_path = edi.download_data('meas-hep7c-xray-synchrotron', destination='data')"
]
},
{
"cell_type": "markdown",
"id": "19",
"metadata": {},
"source": [
"### Create P02.1 Experiment"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "20",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.431947Z",
"iopub.status.busy": "2026-08-18T18:19:14.431583Z",
"iopub.status.idle": "2026-08-18T18:19:14.642116Z",
"shell.execute_reply": "2026-08-18T18:19:14.641229Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"⚠️ No uncertainty (sy) column provided. Defaulting to sqrt(y). \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mData loaded successfully\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Experiment 🔬 \u001b[32m'p021'\u001b[0m. Number of data points: \u001b[1;36m1459\u001b[0m.\n"
]
}
],
"source": [
"project.experiments.add_from_data_path(\n",
" name='p021',\n",
" data_path=data_path,\n",
" sample_form='powder',\n",
" beam_mode='constant wavelength',\n",
" radiation_probe='xray',\n",
")"
]
},
{
"cell_type": "markdown",
"id": "21",
"metadata": {},
"source": [
"Use a short alias to access the P02.1 experiment parameters below."
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "22",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.643739Z",
"iopub.status.busy": "2026-08-18T18:19:14.643567Z",
"iopub.status.idle": "2026-08-18T18:19:14.646411Z",
"shell.execute_reply": "2026-08-18T18:19:14.645585Z"
}
},
"outputs": [],
"source": [
"experiment = project.experiments['p021']"
]
},
{
"cell_type": "markdown",
"id": "23",
"metadata": {},
"source": [
"### Set Linked Structures\n",
"\n",
"Link the structural model to the measured pattern and use an\n",
"order-of-magnitude estimate for the scale factor."
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "24",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.647910Z",
"iopub.status.busy": "2026-08-18T18:19:14.647758Z",
"iopub.status.idle": "2026-08-18T18:19:14.650823Z",
"shell.execute_reply": "2026-08-18T18:19:14.650068Z"
}
},
"outputs": [],
"source": [
"experiment.linked_structures.create(\n",
" structure_id='lam7o3',\n",
" scale=0.000005,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "25",
"metadata": {},
"source": [
"### Set P02.1 Instrument Parameters\n",
"\n",
"Set the monochromatic X-ray wavelength reported for the P02.1\n",
"beamline measurement and initialize the unknown 2-theta zero shift at\n",
"zero."
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "26",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.652602Z",
"iopub.status.busy": "2026-08-18T18:19:14.652422Z",
"iopub.status.idle": "2026-08-18T18:19:14.655230Z",
"shell.execute_reply": "2026-08-18T18:19:14.654473Z"
}
},
"outputs": [],
"source": [
"experiment.instrument.setup_wavelength = 0.207109\n",
"experiment.instrument.calib_twotheta_offset = 0.0"
]
},
{
"cell_type": "markdown",
"id": "27",
"metadata": {},
"source": [
"### Set Peak Profile\n",
"\n",
"Select a pseudo-Voigt profile and provide approximate broadening\n",
"parameters. U, V, and W define the Gaussian contribution; X and Y\n",
"define the Lorentzian contribution."
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "28",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.656754Z",
"iopub.status.busy": "2026-08-18T18:19:14.656585Z",
"iopub.status.idle": "2026-08-18T18:19:14.663160Z",
"shell.execute_reply": "2026-08-18T18:19:14.662422Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mPeak types\u001b[0m\n"
]
},
{
"data": {
"text/html": [
" | | Type | Description |
|---|
| 1 | * | pseudo-voigt | CWL pseudo-Voigt profile |
|---|
| 2 | | pseudo-voigt + berar-baldinozzi asymmetry | CWL pseudo-Voigt profile with Berar-Baldinozzi asymmetry correction. |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"experiment.peak.show_supported()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "29",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.664915Z",
"iopub.status.busy": "2026-08-18T18:19:14.664752Z",
"iopub.status.idle": "2026-08-18T18:19:14.669424Z",
"shell.execute_reply": "2026-08-18T18:19:14.668736Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mPeak profile type for experiment \u001b[0m\u001b[32m'p021'\u001b[0m\u001b[1;36m changed to\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"pseudo-voigt\n"
]
}
],
"source": [
"experiment.peak.type = 'pseudo-voigt'"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "30",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.670844Z",
"iopub.status.busy": "2026-08-18T18:19:14.670686Z",
"iopub.status.idle": "2026-08-18T18:19:14.673839Z",
"shell.execute_reply": "2026-08-18T18:19:14.673118Z"
}
},
"outputs": [],
"source": [
"experiment.peak.broad_gauss_u = 0.04\n",
"experiment.peak.broad_gauss_v = -0.01\n",
"experiment.peak.broad_gauss_w = 0.001\n",
"experiment.peak.broad_lorentz_x = 0.1\n",
"experiment.peak.broad_lorentz_y = 0.0"
]
},
{
"cell_type": "markdown",
"id": "31",
"metadata": {},
"source": [
"### Set Excluded Regions\n",
"\n",
"Restrict the fit to the useful measured range from 2 to 15 degrees."
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "32",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.675257Z",
"iopub.status.busy": "2026-08-18T18:19:14.675097Z",
"iopub.status.idle": "2026-08-18T18:19:14.678342Z",
"shell.execute_reply": "2026-08-18T18:19:14.677638Z"
}
},
"outputs": [],
"source": [
"experiment.excluded_regions.create(id='1', start=0.0, end=2.0)\n",
"experiment.excluded_regions.create(id='2', start=15.0, end=20.0)"
]
},
{
"cell_type": "markdown",
"id": "33",
"metadata": {},
"source": [
"### Set Background\n",
"\n",
"Estimate initial background points from the measured pattern alone."
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "34",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.679984Z",
"iopub.status.busy": "2026-08-18T18:19:14.679825Z",
"iopub.status.idle": "2026-08-18T18:19:14.702091Z",
"shell.execute_reply": "2026-08-18T18:19:14.701328Z"
}
},
"outputs": [],
"source": [
"experiment.background.auto_estimate(use_model=False)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "35",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.704218Z",
"iopub.status.busy": "2026-08-18T18:19:14.704038Z",
"iopub.status.idle": "2026-08-18T18:19:14.710966Z",
"shell.execute_reply": "2026-08-18T18:19:14.710300Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mLine-segment background points\u001b[0m\n"
]
},
{
"data": {
"text/html": [
" | Position | Intensity |
|---|
| 1 | 2.00330 | 584.02820 |
|---|
| 2 | 3.19170 | 616.43436 |
|---|
| 3 | 3.49660 | 608.10597 |
|---|
| 4 | 3.72800 | 594.63226 |
|---|
| 5 | 3.95940 | 574.02994 |
|---|
| 6 | 4.94790 | 457.72470 |
|---|
| 7 | 5.17920 | 443.13978 |
|---|
| 8 | 5.46320 | 433.01395 |
|---|
| 9 | 6.02050 | 432.92677 |
|---|
| 10 | 6.97750 | 421.29697 |
|---|
| 11 | 7.75570 | 444.89668 |
|---|
| 12 | 8.61800 | 453.76679 |
|---|
| 13 | 11.28920 | 346.83990 |
|---|
| 14 | 11.93060 | 357.71449 |
|---|
| 15 | 14.73850 | 302.43079 |
|---|
| 16 | 14.99090 | 278.31547 |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"experiment.background.show()"
]
},
{
"cell_type": "markdown",
"id": "36",
"metadata": {},
"source": [
"### Inspect Experiment\n",
"\n",
"Display the configured experiment as text."
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "37",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:14.712974Z",
"iopub.status.busy": "2026-08-18T18:19:14.712797Z",
"iopub.status.idle": "2026-08-18T18:19:15.646557Z",
"shell.execute_reply": "2026-08-18T18:19:15.645790Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mExperiment 🔬 \u001b[0m\u001b[32m'p021'\u001b[0m\u001b[1;36m as text\u001b[0m\n"
]
},
{
"data": {
"text/html": [
" | Edi |
|---|
| 1 | data_p021 |
|---|
| 2 | |
|---|
| 3 | _experiment_type.sample_form powder |
|---|
| 4 | _experiment_type.beam_mode "constant wavelength" |
|---|
| 5 | _experiment_type.radiation_probe xray |
|---|
| 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.broad_gauss_u 0.04 |
|---|
| 16 | _peak.broad_gauss_v -0.01 |
|---|
| 17 | _peak.broad_gauss_w 0.001 |
|---|
| 18 | _peak.broad_lorentz_x 0.1 |
|---|
| 19 | _peak.broad_lorentz_y 0. |
|---|
| 20 | _peak.cutoff_fwhm 0. |
|---|
| 21 | _peak.type cwl-pseudo-voigt |
|---|
| 22 | |
|---|
| 23 | _instrument.setup_wavelength 0.207109 |
|---|
| 24 | _instrument.setup_wavelength_2 0. |
|---|
| 25 | _instrument.setup_wavelength_2_to_1_ratio 0. |
|---|
| 26 | _instrument.calib_twotheta_offset 0. |
|---|
| 27 | _instrument.calib_sample_displacement 0. |
|---|
| 28 | _instrument.calib_sample_transparency 0. |
|---|
| 29 | _instrument.setup_polarization_coefficient 0. |
|---|
| 30 | _instrument.setup_monochromator_twotheta 0. |
|---|
| 31 | |
|---|
| 32 | _absorption.type none |
|---|
| 33 | |
|---|
| 34 | loop_ |
|---|
| 35 | _linked_structure.structure_id |
|---|
| 36 | _linked_structure.scale |
|---|
| 37 | lam7o3 0.000005 |
|---|
| 38 | |
|---|
| 39 | loop_ |
|---|
| 40 | _excluded_region.id |
|---|
| 41 | _excluded_region.start |
|---|
| 42 | _excluded_region.end |
|---|
| 43 | 1 0. 2. |
|---|
| 44 | 2 15. 20. |
|---|
| 45 | |
|---|
| 46 | _background.type line-segment |
|---|
| 47 | |
|---|
| 48 | loop_ |
|---|
| 49 | _background.id |
|---|
| 50 | _background.position |
|---|
| 51 | _background.intensity |
|---|
| 52 | 1 2.0033 584.0282 |
|---|
| 53 | 2 3.1917 616.4343557 |
|---|
| 54 | 3 3.4966 608.10596651 |
|---|
| 55 | 4 3.728 594.63226302 |
|---|
| 56 | 5 3.9594 574.02993766 |
|---|
| 57 | 6 4.9479 457.7247 |
|---|
| 58 | 7 5.1792 443.13977867 |
|---|
| 59 | 8 5.4632 433.01395145 |
|---|
| 60 | 9 6.0205 432.92676858 |
|---|
| 61 | 10 6.9775 421.2969741 |
|---|
| 62 | 11 7.7557 444.89668148 |
|---|
| 63 | 12 8.618 453.76678528 |
|---|
| 64 | 13 11.2892 346.83989649 |
|---|
| 65 | 14 11.9306 357.71448643 |
|---|
| 66 | 15 14.7385 302.43079253 |
|---|
| 67 | 16 14.9909 278.31546798 |
|---|
| 68 | |
|---|
| 69 | loop_ |
|---|
| 70 | _data.two_theta |
|---|
| 71 | _data.id |
|---|
| 72 | _data.d_spacing |
|---|
| 73 | _data.intensity_meas |
|---|
| 74 | _data.intensity_meas_su |
|---|
| 75 | _data.intensity_calc |
|---|
| 76 | _data.intensity_bkg |
|---|
| 77 | _data.calc_status |
|---|
| 78 | 0.0053 1 0. 0. 1. 0. 0. excl |
|---|
| 79 | 0.0158 2 0. 0. 1. 0. 0. excl |
|---|
| 80 | 0.0263 3 0. 0. 1. 0. 0. excl |
|---|
| 81 | 0.0368 4 0. 0. 1. 0. 0. excl |
|---|
| 82 | 0.0473 5 0. 0. 1. 0. 0. excl |
|---|
| 83 | 0.0578 6 0. 0. 1. 0. 0. excl |
|---|
| 84 | 0.0684 7 0. 0. 1. 0. 0. excl |
|---|
| 85 | 0.0789 8 0. 0. 1. 0. 0. excl |
|---|
| 86 | 0.0894 9 0. 0. 1. 0. 0. excl |
|---|
| 87 | 0.0999 10 0. 0. 1. 0. 0. excl |
|---|
| 88 | ... |
|---|
| 89 | 15.2432 1450 0. 65.524826 8.09474064 0. 0. excl |
|---|
| 90 | 15.2538 1451 0. 43.702377 6.61077734 0. 0. excl |
|---|
| 91 | 15.2643 1452 0. 31.145777 5.58084017 0. 0. excl |
|---|
| 92 | 15.2748 1453 0. 20.166813 4.49074749 0. 0. excl |
|---|
| 93 | 15.2853 1454 0. 14.170188 3.76433102 0. 0. excl |
|---|
| 94 | 15.2958 1455 0. 7.3013401 2.7020992 0. 0. excl |
|---|
| 95 | 15.3063 1456 0. 12.101576 3.47873195 0. 0. excl |
|---|
| 96 | 15.3169 1457 0. 6.531918 2.55576173 0. 0. excl |
|---|
| 97 | 15.3274 1458 0. 3.1248069 1.76771234 0. 0. excl |
|---|
| 98 | 15.3379 1459 0. 3.6774037 1.91765578 0. 0. excl |
|---|
| 99 | |
|---|
| 100 | loop_ |
|---|
| 101 | _refln.id |
|---|
| 102 | _refln.structure_id |
|---|
| 103 | _refln.d_spacing |
|---|
| 104 | _refln.sin_theta_over_lambda |
|---|
| 105 | _refln.index_h |
|---|
| 106 | _refln.index_k |
|---|
| 107 | _refln.index_l |
|---|
| 108 | _refln.f_calc |
|---|
| 109 | _refln.f_squared_calc |
|---|
| 110 | _refln.two_theta |
|---|
| 111 | 1 lam7o3 7.7 0.06493506 0 1 0 0. 0. 1.54114667 |
|---|
| 112 | 2 lam7o3 5.5 0.09090909 0 0 1 0. 0. 2.15766778 |
|---|
| 113 | 3 lam7o3 5.5 0.09090909 1 0 0 0. 0. 2.15766778 |
|---|
| 114 | 4 lam7o3 4.47553409 0.11171851 0 1 1 3.59310475 12.91040172 2.65164569 |
|---|
| 115 | 5 lam7o3 4.47553409 0.11171851 1 1 0 0. 0. 2.65164569 |
|---|
| 116 | 6 lam7o3 3.8890873 0.12856487 1 0 1 84.40914375 7124.90354832 3.05158341 |
|---|
| 117 | 7 lam7o3 3.85 0.12987013 0 2 0 85.84489383 7369.34579669 3.08257218 |
|---|
| 118 | 8 lam7o3 3.47142809 0.14403294 1 1 1 24.66596148 608.40965573 3.4188328 |
|---|
| 119 | 9 lam7o3 3.15404289 0.1585267 1 2 0 0. 0. 3.76298134 |
|---|
| 120 | 10 lam7o3 3.15404289 0.1585267 0 2 1 0. 0. 3.76298134 |
|---|
| 121 | ... |
|---|
| 122 | 605 lam7o3 0.63080858 0.79263348 0 10 5 0. 0. 18.89705877 |
|---|
| 123 | 606 lam7o3 0.63072392 0.79273987 5 2 7 107.42119834 11539.3138528 18.89961836 |
|---|
| 124 | 607 lam7o3 0.63072392 0.79273987 7 2 5 90.76949065 8239.10043243 18.89961836 |
|---|
| 125 | 608 lam7o3 0.63021671 0.79337789 2 4 8 97.82362003 9569.46063649 18.91496894 |
|---|
| 126 | 609 lam7o3 0.63021671 0.79337789 8 4 2 76.04580662 5782.96470497 18.91496894 |
|---|
| 127 | 610 lam7o3 0.62937406 0.79444012 3 6 7 108.33293447 11736.02469019 18.94052659 |
|---|
| 128 | 611 lam7o3 0.62937406 0.79444012 7 6 3 78.37832345 6143.16158631 18.94052659 |
|---|
| 129 | 612 lam7o3 0.62845104 0.79560693 6 3 6 53.64286926 2877.55742291 18.9686017 |
|---|
| 130 | 613 lam7o3 0.62778229 0.79645445 8 5 0 76.32628817 5825.702266 18.98899484 |
|---|
| 131 | 614 lam7o3 0.62778229 0.79645445 0 5 8 0. 0. 18.98899484 |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"experiment.show_as_text()"
]
},
{
"cell_type": "markdown",
"id": "38",
"metadata": {},
"source": [
"## 🚀 Perform Analysis\n",
"\n",
"Select the refinement parameters, apply the shared-Biso constraints,\n",
"and improve the model in two fitting stages.\n",
"\n",
"### Set Free Parameters\n",
"\n",
"The independent cell lengths, selected fractional coordinates, and\n",
"three independent Biso values were marked free by `()` in the inline\n",
"CIF. They do not need to be selected again here."
]
},
{
"cell_type": "markdown",
"id": "39",
"metadata": {},
"source": [
"Refine the scale factor, zero shift, U/V/W/X profile terms, and active\n",
"background-point intensities."
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "40",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:15.648511Z",
"iopub.status.busy": "2026-08-18T18:19:15.648321Z",
"iopub.status.idle": "2026-08-18T18:19:15.652552Z",
"shell.execute_reply": "2026-08-18T18:19:15.651755Z"
}
},
"outputs": [],
"source": [
"experiment.linked_structures['lam7o3'].scale.free = True\n",
"\n",
"experiment.instrument.calib_twotheta_offset.free = True\n",
"\n",
"experiment.peak.broad_gauss_u.free = True\n",
"experiment.peak.broad_gauss_v.free = True\n",
"experiment.peak.broad_gauss_w.free = True\n",
"experiment.peak.broad_lorentz_x.free = True\n",
"\n",
"for point in experiment.background:\n",
" point.intensity.free = True"
]
},
{
"cell_type": "markdown",
"id": "41",
"metadata": {},
"source": [
"Display all parameters selected for refinement."
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "42",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:15.654047Z",
"iopub.status.busy": "2026-08-18T18:19:15.653894Z",
"iopub.status.idle": "2026-08-18T18:19:15.744781Z",
"shell.execute_reply": "2026-08-18T18:19:15.743966Z"
}
},
"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": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.parameters.free()"
]
},
{
"cell_type": "markdown",
"id": "43",
"metadata": {},
"source": [
"### Set Constraints\n",
"\n",
"Create aliases for the constrained Biso parameters. The seven\n",
"elements share one B site and therefore one Biso value; O1 and O2\n",
"are also modeled with one shared Biso value."
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "44",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:15.746751Z",
"iopub.status.busy": "2026-08-18T18:19:15.746568Z",
"iopub.status.idle": "2026-08-18T18:19:15.752567Z",
"shell.execute_reply": "2026-08-18T18:19:15.751783Z"
}
},
"outputs": [],
"source": [
"# B sites: Ti, Cr, Mn, Fe, Co, Ni, Cu\n",
"project.analysis.aliases.create(\n",
" id='biso_Ti',\n",
" param=structure.atom_sites['Ti'].adp_iso,\n",
")\n",
"project.analysis.aliases.create(\n",
" id='biso_Cr',\n",
" param=structure.atom_sites['Cr'].adp_iso,\n",
")\n",
"project.analysis.aliases.create(\n",
" id='biso_Mn',\n",
" param=structure.atom_sites['Mn'].adp_iso,\n",
")\n",
"project.analysis.aliases.create(\n",
" id='biso_Fe',\n",
" param=structure.atom_sites['Fe'].adp_iso,\n",
")\n",
"project.analysis.aliases.create(\n",
" id='biso_Co',\n",
" param=structure.atom_sites['Co'].adp_iso,\n",
")\n",
"project.analysis.aliases.create(\n",
" id='biso_Ni',\n",
" param=structure.atom_sites['Ni'].adp_iso,\n",
")\n",
"project.analysis.aliases.create(\n",
" id='biso_Cu',\n",
" param=structure.atom_sites['Cu'].adp_iso,\n",
")\n",
"\n",
"# O sites: O1, O2\n",
"project.analysis.aliases.create(\n",
" id='biso_O1',\n",
" param=structure.atom_sites['O1'].adp_iso,\n",
")\n",
"project.analysis.aliases.create(\n",
" id='biso_O2',\n",
" param=structure.atom_sites['O2'].adp_iso,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "45",
"metadata": {},
"source": [
"Apply the equality constraints using the aliases."
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "46",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:15.754842Z",
"iopub.status.busy": "2026-08-18T18:19:15.754658Z",
"iopub.status.idle": "2026-08-18T18:19:15.760764Z",
"shell.execute_reply": "2026-08-18T18:19:15.759716Z"
}
},
"outputs": [],
"source": [
"project.analysis.constraints.create(id='1', expression='biso_Cr = biso_Ti')\n",
"project.analysis.constraints.create(id='2', expression='biso_Mn = biso_Ti')\n",
"project.analysis.constraints.create(id='3', expression='biso_Fe = biso_Ti')\n",
"project.analysis.constraints.create(id='4', expression='biso_Co = biso_Ti')\n",
"project.analysis.constraints.create(id='5', expression='biso_Ni = biso_Ti')\n",
"project.analysis.constraints.create(id='6', expression='biso_Cu = biso_Ti')\n",
"\n",
"project.analysis.constraints.create(id='7', expression='biso_O2 = biso_O1')"
]
},
{
"cell_type": "markdown",
"id": "47",
"metadata": {},
"source": [
"Display the defined constraints."
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "48",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:15.762691Z",
"iopub.status.busy": "2026-08-18T18:19:15.762439Z",
"iopub.status.idle": "2026-08-18T18:19:15.770406Z",
"shell.execute_reply": "2026-08-18T18:19:15.769771Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mUser defined constraints\u001b[0m\n"
]
},
{
"data": {
"text/html": [
" | id | expression |
|---|
| 1 | 1 | biso_Cr = biso_Ti |
|---|
| 2 | 2 | biso_Mn = biso_Ti |
|---|
| 3 | 3 | biso_Fe = biso_Ti |
|---|
| 4 | 4 | biso_Co = biso_Ti |
|---|
| 5 | 5 | biso_Ni = biso_Ti |
|---|
| 6 | 6 | biso_Cu = biso_Ti |
|---|
| 7 | 7 | biso_O2 = biso_O1 |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Constraints enabled: \u001b[3;92mTrue\u001b[0m\n"
]
}
],
"source": [
"project.analysis.display.constraints()"
]
},
{
"cell_type": "markdown",
"id": "49",
"metadata": {},
"source": [
"### Fit Initial Model\n",
"\n",
"The first fit uses a background estimated directly from the measured\n",
"pattern.\n",
"\n",
"#### Display Pattern (Before Fit)\n",
"\n",
"Compare the measured pattern with the calculation from the starting\n",
"model before optimization."
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "50",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:15.772088Z",
"iopub.status.busy": "2026-08-18T18:19:15.771933Z",
"iopub.status.idle": "2026-08-18T18:19:15.899037Z",
"shell.execute_reply": "2026-08-18T18:19:15.898329Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='p021')"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "51",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:15.901950Z",
"iopub.status.busy": "2026-08-18T18:19:15.901767Z",
"iopub.status.idle": "2026-08-18T18:19:16.000647Z",
"shell.execute_reply": "2026-08-18T18:19:15.999971Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='p021', x_min=2.2, x_max=4.0)"
]
},
{
"cell_type": "markdown",
"id": "52",
"metadata": {},
"source": [
"#### Run Fitting"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "53",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:19:16.003031Z",
"iopub.status.busy": "2026-08-18T18:19:16.002857Z",
"iopub.status.idle": "2026-08-18T18:22:09.589706Z",
"shell.execute_reply": "2026-08-18T18:22:09.586977Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-1cc66c56ef2d4cf0be20bf9c49b689d3-button');\n",
" const status = document.getElementById('ed-fit-stop-1cc66c56ef2d4cf0be20bf9c49b689d3-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'p021'\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": [
" | iteration | time (s) | χ² | change / status |
|---|
| 1 | 1 | 0.21 | 276.18 | |
|---|
| 2 | 20 | 5.55 | 276.18 | |
|---|
| 3 | 39 | 10.67 | 46.46 | 83.2% ↓ |
|---|
| 4 | 57 | 15.93 | 46.46 | |
|---|
| 5 | 75 | 20.79 | 15.97 | 65.6% ↓ |
|---|
| 6 | 93 | 26.10 | 15.97 | |
|---|
| 7 | 111 | 31.06 | 3.89 | 75.7% ↓ |
|---|
| 8 | 130 | 36.43 | 3.89 | |
|---|
| 9 | 146 | 42.14 | 3.89 | |
|---|
| 10 | 149 | 43.16 | 1.71 | 55.9% ↓ |
|---|
| 11 | 161 | 48.41 | 1.71 | |
|---|
| 12 | 172 | 53.66 | 1.71 | |
|---|
| 13 | 184 | 58.73 | 1.71 | |
|---|
| 14 | 185 | 58.96 | 1.12 | 34.9% ↓ |
|---|
| 15 | 197 | 64.25 | 1.12 | |
|---|
| 16 | 208 | 69.28 | 1.12 | |
|---|
| 17 | 220 | 74.77 | 1.12 | |
|---|
| 18 | 221 | 75.18 | 0.88 | 20.9% ↓ |
|---|
| 19 | 232 | 80.26 | 0.88 | |
|---|
| 20 | 243 | 85.41 | 0.88 | |
|---|
| 21 | 254 | 90.59 | 0.88 | |
|---|
| 22 | 267 | 95.86 | 0.88 | |
|---|
| 23 | 278 | 101.07 | 0.88 | |
|---|
| 24 | 291 | 106.37 | 0.88 | |
|---|
| 25 | 302 | 111.53 | 0.88 | |
|---|
| 26 | 314 | 117.04 | 0.88 | |
|---|
| 27 | 326 | 122.14 | 0.88 | |
|---|
| 28 | 338 | 127.47 | 0.88 | |
|---|
| 29 | 350 | 132.67 | 0.88 | |
|---|
| 30 | 360 | 137.74 | 0.88 | |
|---|
| 31 | 371 | 142.92 | 0.88 | |
|---|
| 32 | 383 | 148.18 | 0.88 | |
|---|
| 33 | 394 | 153.34 | 0.88 | |
|---|
| 34 | 405 | 158.43 | 0.88 | |
|---|
| 35 | 417 | 163.82 | 0.88 | |
|---|
| 36 | 429 | 169.07 | 0.88 | |
|---|
| 37 | 438 | 173.49 | 0.88 | |
|---|
"
],
"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;36m0.88\u001b[0m at iteration \u001b[1;36m437\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Fitting complete.\n"
]
}
],
"source": [
"project.analysis.fit()"
]
},
{
"cell_type": "markdown",
"id": "54",
"metadata": {},
"source": [
"Display the initial fit summary and the strongest parameter\n",
"correlations."
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "55",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:22:09.591109Z",
"iopub.status.busy": "2026-08-18T18:22:09.590942Z",
"iopub.status.idle": "2026-08-18T18:22:10.846205Z",
"shell.execute_reply": "2026-08-18T18:22:10.845562Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"⚙️ Settings used:\n"
]
},
{
"data": {
"text/html": [
" | Name | Value | Description |
|---|
| 1 | max_iterations | 1000 | Maximum solver iterations. |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📋 Least-squares fit results:\n"
]
},
{
"data": {
"text/html": [
" | Metric | Value |
|---|
| 1 | 🧪 Minimizer | lmfit (leastsq) |
|---|
| 2 | ✅ Overall status | success |
|---|
| 3 | ⏱️ Fitting time (seconds) | 173.49 |
|---|
| 4 | 🔁 Iterations | 435 |
|---|
| 5 | 📏 Goodness-of-fit (reduced χ²) | 0.88 |
|---|
| 6 | 📏 R-factor (Rf, %) | 2.39 |
|---|
| 7 | 📏 R-factor squared (Rf², %) | 2.55 |
|---|
| 8 | 📏 Weighted R-factor (wR, %) | 1.91 |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📈 Refined parameters:\n"
]
},
{
"data": {
"text/html": [
" | datablock | category | entry | parameter | units | start | value | s.u. | change |
|---|
| 1 | lam7o3 | cell | | length_a | Å | 5.5000 | 5.4623 | 0.0002 | 0.69 % ↓ |
|---|
| 2 | lam7o3 | cell | | length_b | Å | 7.7000 | 7.7332 | 0.0004 | 0.43 % ↑ |
|---|
| 3 | lam7o3 | cell | | length_c | Å | 5.5000 | 5.4903 | 0.0002 | 0.18 % ↓ |
|---|
| 4 | lam7o3 | atom_site | La | fract_x | | 0.4800 | 0.4766 | 0.0002 | 0.72 % ↓ |
|---|
| 5 | lam7o3 | atom_site | La | fract_z | | 0.0040 | 0.0053 | 0.0006 | 31.47 % ↑ |
|---|
| 6 | lam7o3 | atom_site | La | adp_iso | Ų | 0.1000 | 0.5942 | 0.0216 | 494.21 % ↑ |
|---|
| 7 | lam7o3 | atom_site | Ti | adp_iso | Ų | 0.1000 | 0.3425 | 0.0291 | 242.51 % ↑ |
|---|
| 8 | lam7o3 | atom_site | O1 | fract_x | | 0.5100 | 0.5070 | 0.0021 | 0.58 % ↓ |
|---|
| 9 | lam7o3 | atom_site | O1 | fract_z | | 0.5700 | 0.5589 | 0.0035 | 1.96 % ↓ |
|---|
| 10 | lam7o3 | atom_site | O1 | adp_iso | Ų | 0.1000 | 0.5941 | 0.1573 | 494.11 % ↑ |
|---|
| 11 | lam7o3 | atom_site | O2 | fract_x | | 0.2200 | 0.2303 | 0.0033 | 4.68 % ↑ |
|---|
| 12 | lam7o3 | atom_site | O2 | fract_y | | 0.0300 | 0.0378 | 0.0020 | 25.89 % ↑ |
|---|
| 13 | lam7o3 | atom_site | O2 | fract_z | | 0.2700 | 0.2794 | 0.0029 | 3.47 % ↑ |
|---|
| 14 | p021 | linked_structure | lam7o3 | scale | | 0.0000 | 0.0000 | 0.0000 | 27.30 % ↓ |
|---|
| 15 | p021 | peak | | broad_gauss_u | deg² | 0.0400 | 0.0485 | 0.0174 | 21.19 % ↑ |
|---|
| 16 | p021 | peak | | broad_gauss_v | deg² | -0.0100 | -0.0066 | 0.0022 | 33.63 % ↓ |
|---|
| 17 | p021 | peak | | broad_gauss_w | deg² | 0.0010 | 0.0012 | 0.0001 | 18.94 % ↑ |
|---|
| 18 | p021 | peak | | broad_lorentz_x | deg | 0.1000 | 0.1637 | 0.0042 | 63.65 % ↑ |
|---|
| 19 | p021 | instrument | | twotheta_offset | deg | 0.0000 | -0.0004 | 0.0001 | N/A |
|---|
| 20 | p021 | background | 1 | intensity | | 584.0282 | 624.0578 | 4.4509 | 6.85 % ↑ |
|---|
| 21 | p021 | background | 2 | intensity | | 616.4344 | 988.2570 | 4.8160 | 60.32 % ↑ |
|---|
| 22 | p021 | background | 3 | intensity | | 608.1060 | 654.0695 | 6.6736 | 7.56 % ↑ |
|---|
| 23 | p021 | background | 4 | intensity | | 594.6323 | 626.9762 | 6.4339 | 5.44 % ↑ |
|---|
| 24 | p021 | background | 5 | intensity | | 574.0299 | 565.5692 | 4.4366 | 1.47 % ↓ |
|---|
| 25 | p021 | background | 6 | intensity | | 457.7247 | 449.1935 | 3.8087 | 1.86 % ↓ |
|---|
| 26 | p021 | background | 7 | intensity | | 443.1398 | 431.1709 | 5.7132 | 2.70 % ↓ |
|---|
| 27 | p021 | background | 8 | intensity | | 433.0140 | 423.0607 | 4.3495 | 2.30 % ↓ |
|---|
| 28 | p021 | background | 9 | intensity | | 432.9268 | 424.7706 | 3.6020 | 1.88 % ↓ |
|---|
| 29 | p021 | background | 10 | intensity | | 421.2970 | 406.9977 | 3.1857 | 3.39 % ↓ |
|---|
| 30 | p021 | background | 11 | intensity | | 444.8967 | 425.4509 | 3.2033 | 4.37 % ↓ |
|---|
| 31 | p021 | background | 12 | intensity | | 453.7668 | 462.3426 | 2.3750 | 1.89 % ↑ |
|---|
| 32 | p021 | background | 13 | intensity | | 346.8399 | 348.6887 | 2.3885 | 0.53 % ↑ |
|---|
| 33 | p021 | background | 14 | intensity | | 357.7145 | 349.4878 | 2.1675 | 2.30 % ↓ |
|---|
| 34 | p021 | background | 15 | intensity | | 302.4308 | 290.9154 | 2.2866 | 3.81 % ↓ |
|---|
| 35 | p021 | background | 16 | intensity | | 278.3155 | 258.7194 | 5.5684 | 7.04 % ↓ |
|---|
"
],
"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": 32,
"id": "56",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:22:10.848659Z",
"iopub.status.busy": "2026-08-18T18:22:10.847979Z",
"iopub.status.idle": "2026-08-18T18:22:10.881946Z",
"shell.execute_reply": "2026-08-18T18:22:10.881010Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.fit.correlations(max_parameters=5)"
]
},
{
"cell_type": "markdown",
"id": "57",
"metadata": {},
"source": [
"#### Display Pattern (After Initial Fit)\n",
"\n",
"Inspect the full fitted pattern and the nonuniform low-angle\n",
"background region."
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "58",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:22:10.883659Z",
"iopub.status.busy": "2026-08-18T18:22:10.883486Z",
"iopub.status.idle": "2026-08-18T18:22:10.973637Z",
"shell.execute_reply": "2026-08-18T18:22:10.972570Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='p021')"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "59",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:22:10.975839Z",
"iopub.status.busy": "2026-08-18T18:22:10.975150Z",
"iopub.status.idle": "2026-08-18T18:22:11.092323Z",
"shell.execute_reply": "2026-08-18T18:22:11.091835Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='p021', x_min=2.2, x_max=4.0)"
]
},
{
"cell_type": "markdown",
"id": "60",
"metadata": {},
"source": [
"### Improve Background Estimate\n",
"\n",
"With a fitted peak model available, repeat automatic estimation using\n",
"the calculated peak contribution. This replaces the original points\n",
"with a model-guided estimate. Replacement points are fixed by default,\n",
"so mark their intensities free again."
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "61",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:22:11.095098Z",
"iopub.status.busy": "2026-08-18T18:22:11.094414Z",
"iopub.status.idle": "2026-08-18T18:22:11.130623Z",
"shell.execute_reply": "2026-08-18T18:22:11.129505Z"
}
},
"outputs": [],
"source": [
"experiment.background.auto_estimate(use_model=True)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "62",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:22:11.132761Z",
"iopub.status.busy": "2026-08-18T18:22:11.132071Z",
"iopub.status.idle": "2026-08-18T18:22:11.142310Z",
"shell.execute_reply": "2026-08-18T18:22:11.141379Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mLine-segment background points\u001b[0m\n"
]
},
{
"data": {
"text/html": [
" | Position | Intensity |
|---|
| 1 | 2.00330 | 576.07930 |
|---|
| 2 | 2.17160 | 638.44269 |
|---|
| 3 | 2.23470 | 662.65186 |
|---|
| 4 | 2.29780 | 695.09265 |
|---|
| 5 | 2.40300 | 752.13934 |
|---|
| 6 | 2.75000 | 948.88708 |
|---|
| 7 | 2.79210 | 960.58868 |
|---|
| 8 | 2.83410 | 967.29542 |
|---|
| 9 | 2.87620 | 968.71605 |
|---|
| 10 | 2.91820 | 964.86104 |
|---|
| 11 | 2.97080 | 953.16247 |
|---|
| 12 | 3.14960 | 876.76893 |
|---|
| 13 | 3.32840 | 781.24539 |
|---|
| 14 | 3.49660 | 699.51489 |
|---|
| 15 | 3.64390 | 640.61808 |
|---|
| 16 | 3.72800 | 601.48366 |
|---|
| 17 | 3.81210 | 556.51417 |
|---|
| 18 | 4.03300 | 428.78047 |
|---|
| 19 | 4.08550 | 400.97938 |
|---|
| 20 | 4.14860 | 371.19048 |
|---|
| 21 | 4.21170 | 346.60070 |
|---|
| 22 | 4.26430 | 331.07531 |
|---|
| 23 | 4.43260 | 318.49330 |
|---|
| 24 | 4.50620 | 328.33475 |
|---|
| 25 | 4.77960 | 400.14924 |
|---|
| 26 | 4.94790 | 435.19050 |
|---|
| 27 | 5.02150 | 440.50098 |
|---|
| 28 | 5.46320 | 422.43300 |
|---|
| 29 | 5.82070 | 425.38983 |
|---|
| 30 | 6.08360 | 420.22464 |
|---|
| 31 | 6.43070 | 417.57909 |
|---|
| 32 | 6.78820 | 410.64869 |
|---|
| 33 | 7.40870 | 409.16031 |
|---|
| 34 | 7.75570 | 427.93405 |
|---|
| 35 | 7.86090 | 433.58138 |
|---|
| 36 | 8.17640 | 441.57902 |
|---|
| 37 | 8.33410 | 442.13621 |
|---|
| 38 | 8.97560 | 435.40766 |
|---|
| 39 | 9.97460 | 432.32693 |
|---|
| 40 | 10.38480 | 396.20254 |
|---|
| 41 | 10.85800 | 351.40050 |
|---|
| 42 | 11.69930 | 347.23352 |
|---|
| 43 | 11.85700 | 347.83931 |
|---|
| 44 | 12.53010 | 340.09138 |
|---|
| 45 | 14.24420 | 301.93226 |
|---|
| 46 | 14.99090 | 260.58927 |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"experiment.background.show()"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "63",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:22:11.144320Z",
"iopub.status.busy": "2026-08-18T18:22:11.143673Z",
"iopub.status.idle": "2026-08-18T18:22:11.149180Z",
"shell.execute_reply": "2026-08-18T18:22:11.148283Z"
}
},
"outputs": [],
"source": [
"for point in experiment.background:\n",
" point.intensity.free = True"
]
},
{
"cell_type": "markdown",
"id": "64",
"metadata": {},
"source": [
"#### Run Fitting"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "65",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:22:11.150807Z",
"iopub.status.busy": "2026-08-18T18:22:11.150644Z",
"iopub.status.idle": "2026-08-18T18:24:59.120945Z",
"shell.execute_reply": "2026-08-18T18:24:59.120479Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-a12c82e970ca46a1977d9c0e98ff0d60-button');\n",
" const status = document.getElementById('ed-fit-stop-a12c82e970ca46a1977d9c0e98ff0d60-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'p021'\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": [
" | iteration | time (s) | χ² | change / status |
|---|
| 1 | 1 | 0.70 | 2.77 | |
|---|
| 2 | 16 | 5.87 | 2.77 | |
|---|
| 3 | 27 | 11.07 | 2.77 | |
|---|
| 4 | 40 | 16.18 | 2.77 | |
|---|
| 5 | 58 | 21.45 | 2.77 | |
|---|
| 6 | 69 | 24.43 | 0.16 | 94.1% ↓ |
|---|
| 7 | 87 | 29.55 | 0.16 | |
|---|
| 8 | 106 | 34.60 | 0.16 | |
|---|
| 9 | 120 | 39.87 | 0.16 | |
|---|
| 10 | 132 | 45.45 | 0.16 | |
|---|
| 11 | 144 | 50.93 | 0.16 | |
|---|
| 12 | 156 | 56.18 | 0.16 | |
|---|
| 13 | 167 | 61.28 | 0.16 | |
|---|
| 14 | 179 | 66.43 | 0.16 | |
|---|
| 15 | 189 | 71.57 | 0.16 | |
|---|
| 16 | 202 | 77.12 | 0.16 | |
|---|
| 17 | 214 | 82.70 | 0.16 | |
|---|
| 18 | 226 | 88.39 | 0.16 | |
|---|
| 19 | 238 | 93.65 | 0.16 | |
|---|
| 20 | 251 | 99.51 | 0.16 | |
|---|
| 21 | 263 | 104.63 | 0.16 | |
|---|
| 22 | 275 | 110.10 | 0.16 | |
|---|
| 23 | 288 | 115.82 | 0.16 | |
|---|
| 24 | 300 | 121.44 | 0.16 | |
|---|
| 25 | 312 | 126.51 | 0.16 | |
|---|
| 26 | 324 | 131.85 | 0.16 | |
|---|
| 27 | 336 | 137.06 | 0.16 | |
|---|
| 28 | 348 | 142.16 | 0.16 | |
|---|
| 29 | 359 | 147.17 | 0.16 | |
|---|
| 30 | 371 | 152.23 | 0.16 | |
|---|
| 31 | 387 | 157.31 | 0.16 | |
|---|
| 32 | 400 | 167.86 | 0.16 | |
|---|
"
],
"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;36m0.16\u001b[0m at iteration \u001b[1;36m399\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Fitting complete.\n"
]
}
],
"source": [
"project.analysis.fit()"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "66",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:24:59.122932Z",
"iopub.status.busy": "2026-08-18T18:24:59.122763Z",
"iopub.status.idle": "2026-08-18T18:25:00.505278Z",
"shell.execute_reply": "2026-08-18T18:25:00.504502Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"⚙️ Settings used:\n"
]
},
{
"data": {
"text/html": [
" | Name | Value | Description |
|---|
| 1 | max_iterations | 1000 | Maximum solver iterations. |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📋 Least-squares fit results:\n"
]
},
{
"data": {
"text/html": [
" | Metric | Value |
|---|
| 1 | 🧪 Minimizer | lmfit (leastsq) |
|---|
| 2 | ✅ Overall status | success |
|---|
| 3 | ⏱️ Fitting time (seconds) | 167.86 |
|---|
| 4 | 🔁 Iterations | 397 |
|---|
| 5 | 📏 Goodness-of-fit (reduced χ²) | 0.16 |
|---|
| 6 | 📏 R-factor (Rf, %) | 1.01 |
|---|
| 7 | 📏 R-factor squared (Rf², %) | 1.61 |
|---|
| 8 | 📏 Weighted R-factor (wR, %) | 1.48 |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📈 Refined parameters:\n"
]
},
{
"data": {
"text/html": [
" | datablock | category | entry | parameter | units | start | value | s.u. | change |
|---|
| 1 | lam7o3 | cell | | length_a | Å | 5.4623 | 5.4622 | 0.0001 | 0.00 % ↓ |
|---|
| 2 | lam7o3 | cell | | length_b | Å | 7.7332 | 7.7331 | 0.0002 | 0.00 % ↓ |
|---|
| 3 | lam7o3 | cell | | length_c | Å | 5.4903 | 5.4902 | 0.0001 | 0.00 % ↓ |
|---|
| 4 | lam7o3 | atom_site | La | fract_x | | 0.4766 | 0.4767 | 0.0001 | 0.03 % ↑ |
|---|
| 5 | lam7o3 | atom_site | La | fract_z | | 0.0053 | 0.0045 | 0.0003 | 15.23 % ↓ |
|---|
| 6 | lam7o3 | atom_site | La | adp_iso | Ų | 0.5942 | 0.6260 | 0.0095 | 5.35 % ↑ |
|---|
| 7 | lam7o3 | atom_site | Ti | adp_iso | Ų | 0.3425 | 0.3376 | 0.0126 | 1.44 % ↓ |
|---|
| 8 | lam7o3 | atom_site | O1 | fract_x | | 0.5070 | 0.5083 | 0.0010 | 0.25 % ↑ |
|---|
| 9 | lam7o3 | atom_site | O1 | fract_z | | 0.5589 | 0.5708 | 0.0016 | 2.14 % ↑ |
|---|
| 10 | lam7o3 | atom_site | O1 | adp_iso | Ų | 0.5941 | 0.3583 | 0.0654 | 39.69 % ↓ |
|---|
| 11 | lam7o3 | atom_site | O2 | fract_x | | 0.2303 | 0.2218 | 0.0014 | 3.71 % ↓ |
|---|
| 12 | lam7o3 | atom_site | O2 | fract_y | | 0.0378 | 0.0340 | 0.0009 | 9.90 % ↓ |
|---|
| 13 | lam7o3 | atom_site | O2 | fract_z | | 0.2794 | 0.2748 | 0.0014 | 1.63 % ↓ |
|---|
| 14 | p021 | linked_structure | lam7o3 | scale | | 0.0000 | 0.0000 | 0.0000 | 0.49 % ↑ |
|---|
| 15 | p021 | peak | | broad_gauss_u | deg² | 0.0485 | 0.0513 | 0.0075 | 5.81 % ↑ |
|---|
| 16 | p021 | peak | | broad_gauss_v | deg² | -0.0066 | -0.0076 | 0.0010 | 15.15 % ↑ |
|---|
| 17 | p021 | peak | | broad_gauss_w | deg² | 0.0012 | 0.0012 | 0.0000 | 2.99 % ↑ |
|---|
| 18 | p021 | peak | | broad_lorentz_x | deg | 0.1637 | 0.1669 | 0.0025 | 2.00 % ↑ |
|---|
| 19 | p021 | instrument | | twotheta_offset | deg | -0.0004 | -0.0005 | 0.0001 | 25.23 % ↑ |
|---|
| 20 | p021 | background | 1 | intensity | | 576.0793 | 583.7057 | 4.4597 | 1.32 % ↑ |
|---|
| 21 | p021 | background | 2 | intensity | | 638.4427 | 637.0138 | 4.1454 | 0.22 % ↓ |
|---|
| 22 | p021 | background | 3 | intensity | | 662.6519 | 661.4446 | 5.3649 | 0.18 % ↓ |
|---|
| 23 | p021 | background | 4 | intensity | | 695.0927 | 691.5221 | 4.8034 | 0.51 % ↓ |
|---|
| 24 | p021 | background | 5 | intensity | | 752.1393 | 751.6693 | 3.3433 | 0.06 % ↓ |
|---|
| 25 | p021 | background | 6 | intensity | | 948.8871 | 967.4276 | 3.8652 | 1.95 % ↑ |
|---|
| 26 | p021 | background | 7 | intensity | | 960.5887 | 968.7470 | 7.8377 | 0.85 % ↑ |
|---|
| 27 | p021 | background | 8 | intensity | | 967.2954 | 981.1793 | 8.0417 | 1.44 % ↑ |
|---|
| 28 | p021 | background | 9 | intensity | | 968.7160 | 991.6844 | 8.0566 | 2.37 % ↑ |
|---|
| 29 | p021 | background | 10 | intensity | | 964.8610 | 978.2161 | 7.5124 | 1.38 % ↑ |
|---|
| 30 | p021 | background | 11 | intensity | | 953.1625 | 961.7701 | 5.2263 | 0.90 % ↑ |
|---|
| 31 | p021 | background | 12 | intensity | | 876.7689 | 877.8444 | 4.0526 | 0.12 % ↑ |
|---|
| 32 | p021 | background | 13 | intensity | | 781.2454 | 775.4285 | 3.7077 | 0.74 % ↓ |
|---|
| 33 | p021 | background | 14 | intensity | | 699.5149 | 689.0055 | 3.7740 | 1.50 % ↓ |
|---|
| 34 | p021 | background | 15 | intensity | | 640.6181 | 649.7581 | 4.0686 | 1.43 % ↑ |
|---|
| 35 | p021 | background | 16 | intensity | | 601.4837 | 615.5274 | 4.5230 | 2.33 % ↑ |
|---|
| 36 | p021 | background | 17 | intensity | | 556.5142 | 597.0830 | 3.4872 | 7.29 % ↑ |
|---|
| 37 | p021 | background | 18 | intensity | | 428.7805 | 551.2716 | 3.5847 | 28.57 % ↑ |
|---|
| 38 | p021 | background | 19 | intensity | | 400.9794 | 548.1756 | 5.2366 | 36.71 % ↑ |
|---|
| 39 | p021 | background | 20 | intensity | | 371.1905 | 583.1060 | 5.3080 | 57.09 % ↑ |
|---|
| 40 | p021 | background | 21 | intensity | | 346.6007 | 514.8713 | 5.4911 | 48.55 % ↑ |
|---|
| 41 | p021 | background | 22 | intensity | | 331.0753 | 523.4231 | 7.0097 | 58.10 % ↑ |
|---|
| 42 | p021 | background | 23 | intensity | | 318.4933 | 508.0645 | 4.9871 | 59.52 % ↑ |
|---|
| 43 | p021 | background | 24 | intensity | | 328.3347 | 497.3337 | 3.1594 | 51.47 % ↑ |
|---|
| 44 | p021 | background | 25 | intensity | | 400.1492 | 467.0731 | 2.6516 | 16.72 % ↑ |
|---|
| 45 | p021 | background | 26 | intensity | | 435.1905 | 452.4149 | 3.2856 | 3.96 % ↑ |
|---|
| 46 | p021 | background | 27 | intensity | | 440.5010 | 438.9108 | 2.5440 | 0.36 % ↓ |
|---|
| 47 | p021 | background | 28 | intensity | | 422.4330 | 420.9219 | 2.0607 | 0.36 % ↓ |
|---|
| 48 | p021 | background | 29 | intensity | | 425.3898 | 426.8501 | 2.1298 | 0.34 % ↑ |
|---|
| 49 | p021 | background | 30 | intensity | | 420.2246 | 418.4449 | 2.8849 | 0.42 % ↓ |
|---|
| 50 | p021 | background | 31 | intensity | | 417.5791 | 417.3651 | 2.0005 | 0.05 % ↓ |
|---|
| 51 | p021 | background | 32 | intensity | | 410.6487 | 411.7042 | 1.8668 | 0.26 % ↑ |
|---|
| 52 | p021 | background | 33 | intensity | | 409.1603 | 410.5187 | 2.0424 | 0.33 % ↑ |
|---|
| 53 | p021 | background | 34 | intensity | | 427.9340 | 431.2367 | 2.5606 | 0.77 % ↑ |
|---|
| 54 | p021 | background | 35 | intensity | | 433.5814 | 435.4782 | 2.5649 | 0.44 % ↑ |
|---|
| 55 | p021 | background | 36 | intensity | | 441.5790 | 441.4029 | 2.4132 | 0.04 % ↓ |
|---|
| 56 | p021 | background | 37 | intensity | | 442.1362 | 440.3573 | 1.9173 | 0.40 % ↓ |
|---|
| 57 | p021 | background | 38 | intensity | | 435.4077 | 436.7917 | 1.4636 | 0.32 % ↑ |
|---|
| 58 | p021 | background | 39 | intensity | | 432.3269 | 440.6909 | 1.6017 | 1.93 % ↑ |
|---|
| 59 | p021 | background | 40 | intensity | | 396.2025 | 399.2762 | 1.7705 | 0.78 % ↑ |
|---|
| 60 | p021 | background | 41 | intensity | | 351.4005 | 345.2537 | 1.4677 | 1.75 % ↓ |
|---|
| 61 | p021 | background | 42 | intensity | | 347.2335 | 344.8956 | 1.8053 | 0.67 % ↓ |
|---|
| 62 | p021 | background | 43 | intensity | | 347.8393 | 350.5874 | 1.6163 | 0.79 % ↑ |
|---|
| 63 | p021 | background | 44 | intensity | | 340.0914 | 339.5041 | 1.1339 | 0.17 % ↓ |
|---|
| 64 | p021 | background | 45 | intensity | | 301.9323 | 302.4185 | 1.0953 | 0.16 % ↑ |
|---|
| 65 | p021 | background | 46 | intensity | | 260.5893 | 273.9354 | 1.5148 | 5.12 % ↑ |
|---|
"
],
"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": 40,
"id": "67",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:25:00.506966Z",
"iopub.status.busy": "2026-08-18T18:25:00.506779Z",
"iopub.status.idle": "2026-08-18T18:25:00.541892Z",
"shell.execute_reply": "2026-08-18T18:25:00.541172Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.fit.correlations(max_parameters=5)"
]
},
{
"cell_type": "markdown",
"id": "68",
"metadata": {},
"source": [
"#### Display Pattern (After Final Fit)"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "69",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:25:00.543725Z",
"iopub.status.busy": "2026-08-18T18:25:00.543568Z",
"iopub.status.idle": "2026-08-18T18:25:00.700470Z",
"shell.execute_reply": "2026-08-18T18:25:00.699309Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='p021')"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "70",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:25:00.702060Z",
"iopub.status.busy": "2026-08-18T18:25:00.701880Z",
"iopub.status.idle": "2026-08-18T18:25:00.916667Z",
"shell.execute_reply": "2026-08-18T18:25:00.914301Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.pattern(expt_name='p021', x_min=2.2, x_max=4.0)"
]
},
{
"cell_type": "markdown",
"id": "71",
"metadata": {},
"source": [
"## 📊 Report\n",
"\n",
"The HTML report is written automatically when the project is saved.\n",
"PDF generation can be enabled before the final save when required."
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "72",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:25:00.919843Z",
"iopub.status.busy": "2026-08-18T18:25:00.919665Z",
"iopub.status.idle": "2026-08-18T18:25:00.923725Z",
"shell.execute_reply": "2026-08-18T18:25:00.922484Z"
}
},
"outputs": [],
"source": [
"# Enable PDF report generation before the last save (time consuming)\n",
"# project.report.pdf = True"
]
},
{
"cell_type": "markdown",
"id": "73",
"metadata": {},
"source": [
"## 💾 Save Project"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "74",
"metadata": {
"execution": {
"iopub.execute_input": "2026-08-18T18:25:00.927620Z",
"iopub.status.busy": "2026-08-18T18:25:00.927430Z",
"iopub.status.idle": "2026-08-18T18:25:01.453765Z",
"shell.execute_reply": "2026-08-18T18:25:01.451258Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mSaving project 📦 \u001b[0m\u001b[32m'lam7o3_p021'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/refine-lam7o3-p021'\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"├── 📄 project.edi\n",
"├── 📁 structures/\n",
"│ └── 📄 lam7o3.edi\n",
"├── 📁 experiments/\n",
"│ └── 📄 p021.edi\n",
"├── 📁 analysis/\n",
"│ └── 📄 analysis.edi\n",
"└── 📁 reports/\n",
" └── 📄 lam7o3_p021.html\n"
]
}
],
"source": [
"project.save()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "75",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}