{
"nbformat": 4,
"nbformat_minor": 5,
"metadata": {
"jupytext": {
"main_language": "python",
"notebook_metadata_filter": "-all",
"cell_metadata_filter": "-all",
"text_representation": {
"extension": ".py",
"format_name": "percent"
}
}
},
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"tags": [
"hide-in-docs"
],
"execution": {
"iopub.status.busy": "2026-11-12T16:09:36.888960Z",
"iopub.execute_input": "2026-11-12T16:09:36.889128Z",
"shell.execute_reply": "2026-11-12T16:09:36.891648Z",
"iopub.status.idle": "2026-11-12T16:09:36.892019Z"
}
},
"outputs": [],
"source": "# Check whether easydiffraction is installed; install it if needed.\n# Required for remote environments such as Google Colab.\nimport importlib.util\n\nif importlib.util.find_spec('easydiffraction') is None:\n %pip install easydiffraction==2026.11.13 --extra-index-url https://download.easydiffraction.org/pypi/simple/\n",
"id": "0"
},
{
"id": "1",
"cell_type": "markdown",
"source": "# Co₂SiO₄ on D20 at 2.3 K",
"metadata": {}
},
{
"cell_type": "markdown",
"metadata": {},
"source": "
",
"id": "2"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Fit the magnetic structure of the olivine Co₂SiO₄ to constant-wavelength neutron powder data\nfrom D20 at ILL, measured at 2.3 K, below its ordering temperature. The cobalt moments order with\nk = 0 in the magnetic space group Pnma.1: Co1 may point in any direction, Co2 only along b.\n\nThe project is the catalogue case `pd-neut-cwl_cosio-d20_2k`, the one the command line and the\napp's Examples open. Its two Co sites share one displacement, and the two FCJ asymmetry terms are\ntied, from the start.",
"id": "3"
},
{
"id": "4",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:36.893010Z",
"iopub.execute_input": "2026-11-12T16:09:36.893127Z",
"shell.execute_reply": "2026-11-12T16:09:36.901609Z",
"iopub.status.idle": "2026-11-12T16:09:36.901920Z"
}
},
"execution_count": 2,
"source": "import easydiffraction as edi",
"outputs": []
},
{
"id": "5",
"cell_type": "markdown",
"source": "## Load the project",
"metadata": {}
},
{
"id": "6",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:36.902902Z",
"iopub.execute_input": "2026-11-12T16:09:36.903023Z",
"shell.execute_reply": "2026-11-12T16:09:37.121592Z",
"iopub.status.idle": "2026-11-12T16:09:37.122007Z"
}
},
"execution_count": 3,
"source": "project_path = edi.download_data('pd-neut-cwl_cosio-d20_2k', destination='data')\nproject = edi.Project.load(project_path)\nstructure = project.structures['cosio']\nexperiment = project.experiments['d20']\nproject.display.constraints()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "Data 'pd-neut-cwl_cosio-d20_2k' is at data/pd-neut-cwl_cosio-d20_2k-84d4534215e5/pd-neut-cwl_cosio-d20_2k\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<78,814 characters>, height=264)",
"text/html": ""
}
}
]
},
{
"id": "7",
"cell_type": "markdown",
"source": "The project marks what its fit frees. The fit below frees it in stages, so start with all of it\nfixed.",
"metadata": {}
},
{
"id": "8",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.123067Z",
"iopub.execute_input": "2026-11-12T16:09:37.123185Z",
"shell.execute_reply": "2026-11-12T16:09:37.183490Z",
"iopub.status.idle": "2026-11-12T16:09:37.183838Z"
}
},
"execution_count": 4,
"source": "for parameter in project.free_parameters:\n parameter.free = False",
"outputs": []
},
{
"id": "9",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.184993Z",
"iopub.execute_input": "2026-11-12T16:09:37.185111Z",
"iopub.status.idle": "2026-11-12T16:09:37.210382Z",
"shell.execute_reply": "2026-11-12T16:09:37.209982Z"
}
},
"execution_count": 5,
"source": "project.display.pattern('d20')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<308,745 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "10",
"cell_type": "markdown",
"source": "## Perform the analysis\n\nEverything starts fixed, and five stages each free one more group, keeping the earlier ones free:\nthe scale, cell and moments, then the background, the atoms, the peak widths and last the peak\nasymmetry.\n\n### Scale, 2θ zero, cell and magnetic moments\n\nThe first stage frees the phase scale, the 2θ zero shift, the three cell lengths and the magnetic\nmodel: the moment components the magnetic space group allows (Co1 in any direction, Co2 only\nalong b) and the j2 term of the Co²⁺ form factor, which sets how the magnetic intensities fall\nwith angle.",
"metadata": {}
},
{
"id": "11",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.213599Z",
"iopub.execute_input": "2026-11-12T16:09:37.213730Z",
"iopub.status.idle": "2026-11-12T16:09:37.229732Z",
"shell.execute_reply": "2026-11-12T16:09:37.229349Z"
}
},
"execution_count": 6,
"source": "experiment.linked_structures['cosio'].scale.free = True\nexperiment.instrument.calib_twotheta_offset.free = True\nstructure.cell.length_a.free = True\nstructure.cell.length_b.free = True\nstructure.cell.length_c.free = True\nstructure.atom_site_moment['Co1'].crystalaxis_x.free = True\nstructure.atom_site_moment['Co1'].crystalaxis_y.free = True\nstructure.atom_site_moment['Co1'].crystalaxis_z.free = True\nstructure.atom_site_moment['Co2'].crystalaxis_y.free = True\nstructure.magnetic_form_factor['Co'].j2_coefficient.free = True",
"outputs": []
},
{
"id": "12",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.230775Z",
"iopub.execute_input": "2026-11-12T16:09:37.230916Z",
"iopub.status.idle": "2026-11-12T16:09:37.245449Z",
"shell.execute_reply": "2026-11-12T16:09:37.245075Z"
}
},
"execution_count": 7,
"source": "project.display.parameters.free()",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<84,988 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "13",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.246415Z",
"iopub.execute_input": "2026-11-12T16:09:37.246524Z",
"shell.execute_reply": "2026-11-12T16:09:37.317564Z",
"iopub.status.idle": "2026-11-12T16:09:37.317979Z"
}
},
"execution_count": 8,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-cwl_cosio-d20_2k, 1438 pts fitted / 1506 loaded, 10 free\n iter time (s) Rwp (%) reduced χ² change\n 11.38 35.86\n 1 0.024 5.97 9.88 72.5% ↓\n 2 0.028 5.97 9.88 \n 3 0.032 5.97 9.88 \n 4 0.037 5.97 9.88 \n done · converged · 4 iters · reduced χ² 9.88 · Rwp 5.97 % · 0.04 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<93,283 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "14",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.318979Z",
"iopub.execute_input": "2026-11-12T16:09:37.319095Z",
"iopub.status.idle": "2026-11-12T16:09:37.342664Z",
"shell.execute_reply": "2026-11-12T16:09:37.342272Z"
}
},
"execution_count": 9,
"source": "project.display.pattern('d20')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<309,619 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "15",
"cell_type": "markdown",
"source": "### Background\n\nThe second stage frees the sixteen background points, which follow the level between the peaks.",
"metadata": {}
},
{
"id": "16",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.345233Z",
"iopub.execute_input": "2026-11-12T16:09:37.345358Z",
"shell.execute_reply": "2026-11-12T16:09:37.367845Z",
"iopub.status.idle": "2026-11-12T16:09:37.368162Z"
}
},
"execution_count": 10,
"source": "for point in experiment.background:\n point.intensity.free = True",
"outputs": []
},
{
"id": "17",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.369172Z",
"iopub.execute_input": "2026-11-12T16:09:37.369297Z",
"iopub.status.idle": "2026-11-12T16:09:37.443047Z",
"shell.execute_reply": "2026-11-12T16:09:37.442673Z"
}
},
"execution_count": 11,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-cwl_cosio-d20_2k, 1438 pts fitted / 1506 loaded, 26 free\n iter time (s) Rwp (%) reduced χ² change\n 5.97 9.99\n 1 0.026 5.65 8.93 10.6% ↓\n 2 0.031 5.65 8.93 \n 3 0.037 5.65 8.93 \n done · converged · 3 iters · reduced χ² 8.93 · Rwp 5.65 % · 0.04 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<114,042 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "18",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.444357Z",
"iopub.execute_input": "2026-11-12T16:09:37.444480Z",
"iopub.status.idle": "2026-11-12T16:09:37.468418Z",
"shell.execute_reply": "2026-11-12T16:09:37.468028Z"
}
},
"execution_count": 12,
"source": "project.display.pattern('d20')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<309,449 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "19",
"cell_type": "markdown",
"source": "### Atomic displacements and positions\n\nThe third stage frees the atoms: each site's isotropic displacement (Co2's follows Co1's by the\nproject's constraint) and the coordinates the symmetry leaves free. Co1 sits on a centre of\nsymmetry, so it has none; the other sites lie on the mirror plane, except O3.",
"metadata": {}
},
{
"id": "20",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.471135Z",
"iopub.execute_input": "2026-11-12T16:09:37.471258Z",
"iopub.status.idle": "2026-11-12T16:09:37.516232Z",
"shell.execute_reply": "2026-11-12T16:09:37.515830Z"
}
},
"execution_count": 13,
"source": "for site in structure.atom_sites:\n site.adp_iso.free = not site.adp_iso.user_constrained\n for coordinate in (site.fract_x, site.fract_y, site.fract_z):\n coordinate.free = not coordinate.symmetry_constrained",
"outputs": []
},
{
"id": "21",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.517399Z",
"iopub.execute_input": "2026-11-12T16:09:37.517527Z",
"iopub.status.idle": "2026-11-12T16:09:37.604715Z",
"shell.execute_reply": "2026-11-12T16:09:37.604282Z"
}
},
"execution_count": 14,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-cwl_cosio-d20_2k, 1438 pts fitted / 1506 loaded, 42 free\n iter time (s) Rwp (%) reduced χ² change\n 5.65 9.03\n 1 0.026 5.60 8.87 1.8% ↓\n 2 0.031 5.59 8.87 \n 3 0.035 5.59 8.87 \n 4 0.039 5.59 8.86 \n 5 0.043 5.59 8.86 \n 6 0.048 5.59 8.86 \n done · converged · 6 iters · reduced χ² 8.86 · Rwp 5.59 % · 0.05 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<133,575 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "22",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.606084Z",
"iopub.execute_input": "2026-11-12T16:09:37.606199Z",
"iopub.status.idle": "2026-11-12T16:09:37.631509Z",
"shell.execute_reply": "2026-11-12T16:09:37.631113Z"
}
},
"execution_count": 15,
"source": "project.display.pattern('d20')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<309,601 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "23",
"cell_type": "markdown",
"source": "### Peak widths\n\nThe fourth stage frees the peak profile: the Gaussian widths U, V and W and the Lorentzian Y.",
"metadata": {}
},
{
"id": "24",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.634026Z",
"iopub.execute_input": "2026-11-12T16:09:37.634152Z",
"shell.execute_reply": "2026-11-12T16:09:37.641418Z",
"iopub.status.idle": "2026-11-12T16:09:37.641782Z"
}
},
"execution_count": 16,
"source": "experiment.peak.broad_gauss_u.free = True\nexperiment.peak.broad_gauss_v.free = True\nexperiment.peak.broad_gauss_w.free = True\nexperiment.peak.broad_lorentz_y.free = True",
"outputs": []
},
{
"id": "25",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.642845Z",
"iopub.execute_input": "2026-11-12T16:09:37.642967Z",
"iopub.status.idle": "2026-11-12T16:09:37.755251Z",
"shell.execute_reply": "2026-11-12T16:09:37.754954Z"
}
},
"execution_count": 17,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-cwl_cosio-d20_2k, 1438 pts fitted / 1506 loaded, 46 free\n iter time (s) Rwp (%) reduced χ² change\n 5.59 8.89\n 1 0.031 5.58 8.86 0.3% ↓\n 2 0.036 5.58 8.86 \n 3 0.041 5.58 8.86 \n 4 0.046 5.58 8.86 \n 5 0.051 5.58 8.86 \n 6 0.056 5.58 8.86 \n 7 0.061 5.58 8.86 \n 8 0.065 5.58 8.86 \n 9 0.071 5.58 8.86 \n done · converged · 9 iters · reduced χ² 8.86 · Rwp 5.58 % · 0.08 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<136,443 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "26",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.756888Z",
"iopub.execute_input": "2026-11-12T16:09:37.757013Z",
"iopub.status.idle": "2026-11-12T16:09:37.781521Z",
"shell.execute_reply": "2026-11-12T16:09:37.781176Z"
}
},
"execution_count": 18,
"source": "project.display.pattern('d20')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<309,654 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "27",
"cell_type": "markdown",
"source": "### Peak asymmetry\n\nThe last stage frees the asymmetry: the low-angle peaks lean towards low angle. One FCJ term is\nfreed; the other follows it by the project's constraint.",
"metadata": {}
},
{
"id": "28",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.784790Z",
"iopub.execute_input": "2026-11-12T16:09:37.784939Z",
"shell.execute_reply": "2026-11-12T16:09:37.788046Z",
"iopub.status.idle": "2026-11-12T16:09:37.788386Z"
}
},
"execution_count": 19,
"source": "experiment.peak.asym_fcj_1.free = True",
"outputs": []
},
{
"id": "29",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:37.789328Z",
"iopub.execute_input": "2026-11-12T16:09:37.789439Z",
"iopub.status.idle": "2026-11-12T16:09:38.158135Z",
"shell.execute_reply": "2026-11-12T16:09:38.157703Z"
}
},
"execution_count": 20,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-cwl_cosio-d20_2k, 1438 pts fitted / 1506 loaded, 47 free\n iter time (s) Rwp (%) reduced χ² change\n 5.58 8.87\n 1 0.185 5.51 8.62 2.8% ↓\n 2 0.191 5.44 8.41 2.4% ↓\n 3 0.197 5.36 8.16 3.0% ↓\n 4 0.202 5.21 7.71 5.5% ↓\n 5 0.208 5.06 7.28 5.6% ↓\n 6 0.214 4.74 6.39 12.1% ↓\n 7 0.220 4.72 6.33 1.0% ↓\n 8 0.226 4.70 6.27 1.0% ↓\n 9 0.234 4.69 6.26 0.1% ↓\n 10 0.241 4.69 6.26 \n 11 0.249 4.69 6.26 \n 12 0.257 4.69 6.26 \n 13 0.264 4.69 6.25 0.1% ↓\n 14 0.271 4.69 6.25 \n 15 0.279 4.69 6.25 \n 16 0.287 4.69 6.25 \n 17 0.295 4.69 6.25 \n 18 0.303 4.69 6.25 \n 19 0.311 4.69 6.25 \n 20 0.322 4.69 6.25 \n done · converged · 20 iters · reduced χ² 6.25 · Rwp 4.69 % · 0.33 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<142,630 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "30",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:38.159554Z",
"iopub.execute_input": "2026-11-12T16:09:38.159685Z",
"iopub.status.idle": "2026-11-12T16:09:38.185681Z",
"shell.execute_reply": "2026-11-12T16:09:38.185283Z"
}
},
"execution_count": 21,
"source": "project.display.pattern('d20')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<309,908 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "31",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:38.188552Z",
"iopub.execute_input": "2026-11-12T16:09:38.188679Z",
"iopub.status.idle": "2026-11-12T16:09:38.206354Z",
"shell.execute_reply": "2026-11-12T16:09:38.205991Z"
}
},
"execution_count": 22,
"source": "project.display.fit.correlations()",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<80,180 characters>, height=560)",
"text/html": ""
}
}
]
},
{
"id": "32",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:38.207432Z",
"iopub.execute_input": "2026-11-12T16:09:38.207560Z",
"iopub.status.idle": "2026-11-12T16:09:38.231956Z",
"shell.execute_reply": "2026-11-12T16:09:38.231589Z"
}
},
"execution_count": 23,
"source": "project.display.structure('cosio')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<340,630 characters>, height=660)",
"text/html": ""
}
}
]
},
{
"id": "33",
"cell_type": "markdown",
"source": "## Save the project",
"metadata": {}
},
{
"id": "34",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:09:38.235065Z",
"iopub.execute_input": "2026-11-12T16:09:38.235184Z",
"shell.execute_reply": "2026-11-12T16:09:38.400636Z",
"iopub.status.idle": "2026-11-12T16:09:38.401032Z"
}
},
"execution_count": 24,
"source": "project.save_as('pd-neut-cwl_cosio-d20_2k')\nproject.report.save_html('pd-neut-cwl_cosio-d20_2k.html')",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "Saving project to 'pd-neut-cwl_cosio-d20_2k'\nSaving report to 'pd-neut-cwl_cosio-d20_2k.html'\n"
}
]
}
]
}