{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:04.187108Z", "iopub.status.busy": "2026-06-30T22:27:04.186895Z", "iopub.status.idle": "2026-06-30T22:27:04.191428Z", "shell.execute_reply": "2026-06-30T22:27:04.190372Z" }, "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": [ "# Calculation Without Data: LBCO, CWL\n", "\n", "This example shows how to **calculate and plot a diffraction pattern\n", "without any measured data**. Everything the calculation needs β€” the\n", "crystal structure, the instrument, the peak profile, and the\n", "background β€” is defined in code, and the pattern is computed over a\n", "calculation range instead of over loaded data points.\n", "\n", "This is useful to preview what a candidate structure should look like,\n", "to teach, or to generate a synthetic pattern before any measurement\n", "exists. No data file is downloaded or loaded.\n", "\n", "For this example, a constant-wavelength neutron powder experiment for\n", "La0.5Ba0.5CoO3 is used." ] }, { "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:27:04.192953Z", "iopub.status.busy": "2026-06-30T22:27:04.192806Z", "iopub.status.idle": "2026-06-30T22:27:07.078988Z", "shell.execute_reply": "2026-06-30T22:27:07.078088Z" } }, "outputs": [], "source": [ "import easydiffraction as edi" ] }, { "cell_type": "markdown", "id": "4", "metadata": {}, "source": [ "## πŸ“¦ Define Project" ] }, { "cell_type": "code", "execution_count": 3, "id": "5", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:07.080915Z", "iopub.status.busy": "2026-06-30T22:27:07.080623Z", "iopub.status.idle": "2026-06-30T22:27:07.575025Z", "shell.execute_reply": "2026-06-30T22:27:07.573951Z" } }, "outputs": [], "source": [ "project = edi.Project(name='lbco_simulation')" ] }, { "cell_type": "markdown", "id": "6", "metadata": {}, "source": [ "## 🧩 Define Structure" ] }, { "cell_type": "markdown", "id": "7", "metadata": {}, "source": [ "### Download CIF file" ] }, { "cell_type": "code", "execution_count": 4, "id": "8", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:07.576791Z", "iopub.status.busy": "2026-06-30T22:27:07.576595Z", "iopub.status.idle": "2026-06-30T22:27:08.035155Z", "shell.execute_reply": "2026-06-30T22:27:08.034215Z" } }, "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'struct-lbco'\u001b[0m: La0.5Ba0.5CoO3 \u001b[1m(\u001b[0mcrystal structure\u001b[1m)\u001b[0m\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "βœ… Data \u001b[32m'struct-lbco'\u001b[0m downloaded to \u001b[32m'../../../data/struct-lbco.cif'\u001b[0m\n" ] } ], "source": [ "structure_path = edi.download_data('struct-lbco', destination='data')" ] }, { "cell_type": "markdown", "id": "9", "metadata": {}, "source": [ "### Add Structure from CIF" ] }, { "cell_type": "code", "execution_count": 5, "id": "10", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:08.036867Z", "iopub.status.busy": "2026-06-30T22:27:08.036709Z", "iopub.status.idle": "2026-06-30T22:27:08.048568Z", "shell.execute_reply": "2026-06-30T22:27:08.047761Z" } }, "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[1m]\u001b[0m\n" ] } ], "source": [ "project.structures.add_from_cif_path(structure_path)\n", "project.structures.show_names()\n", "\n", "structure = project.structures['lbco']" ] }, { "cell_type": "markdown", "id": "11", "metadata": {}, "source": [ "### Plot Structure" ] }, { "cell_type": "code", "execution_count": 6, "id": "12", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:08.050198Z", "iopub.status.busy": "2026-06-30T22:27:08.050034Z", "iopub.status.idle": "2026-06-30T22:27:08.100983Z", "shell.execute_reply": "2026-06-30T22:27:08.100016Z" } }, "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" } ], "source": [ "project.display.structure(struct_name='lbco')" ] }, { "cell_type": "markdown", "id": "13", "metadata": {}, "source": [ "## πŸ”¬ Define Experiment\n", "\n", "### Create Experiment Without Data\n", "\n", "Instead of loading a measured data file, the 'virtual' experiment is created\n", "directly from its type. With no measured scan present, the pattern is\n", "later computed over the `data_range` defined below." ] }, { "cell_type": "code", "execution_count": 7, "id": "14", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:08.102748Z", "iopub.status.busy": "2026-06-30T22:27:08.102516Z", "iopub.status.idle": "2026-06-30T22:27:08.162224Z", "shell.execute_reply": "2026-06-30T22:27:08.160937Z" } }, "outputs": [], "source": [ "project.experiments.create(\n", " name='sim',\n", " sample_form='powder',\n", " beam_mode='constant wavelength',\n", " radiation_probe='neutron',\n", ")" ] }, { "cell_type": "code", "execution_count": 8, "id": "15", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:08.169849Z", "iopub.status.busy": "2026-06-30T22:27:08.169631Z", "iopub.status.idle": "2026-06-30T22:27:08.173346Z", "shell.execute_reply": "2026-06-30T22:27:08.172390Z" } }, "outputs": [], "source": [ "experiment = project.experiments['sim']" ] }, { "cell_type": "markdown", "id": "16", "metadata": {}, "source": [ "### Set Instrument" ] }, { "cell_type": "code", "execution_count": 9, "id": "17", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:08.175004Z", "iopub.status.busy": "2026-06-30T22:27:08.174829Z", "iopub.status.idle": "2026-06-30T22:27:08.180201Z", "shell.execute_reply": "2026-06-30T22:27:08.179497Z" } }, "outputs": [], "source": [ "experiment.instrument.setup_wavelength = 1.494" ] }, { "cell_type": "markdown", "id": "18", "metadata": {}, "source": [ "### Set Peak Profile" ] }, { "cell_type": "code", "execution_count": 10, "id": "19", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:08.185958Z", "iopub.status.busy": "2026-06-30T22:27:08.185772Z", "iopub.status.idle": "2026-06-30T22:27:08.194126Z", "shell.execute_reply": "2026-06-30T22:27:08.189946Z" } }, "outputs": [], "source": [ "experiment.peak.broad_gauss_u = 0.1\n", "experiment.peak.broad_gauss_v = -0.1\n", "experiment.peak.broad_gauss_w = 0.1\n", "experiment.peak.broad_lorentz_y = 0.1" ] }, { "cell_type": "markdown", "id": "20", "metadata": {}, "source": [ "### Set Background" ] }, { "cell_type": "code", "execution_count": 11, "id": "21", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:08.199474Z", "iopub.status.busy": "2026-06-30T22:27:08.199280Z", "iopub.status.idle": "2026-06-30T22:27:08.205516Z", "shell.execute_reply": "2026-06-30T22:27:08.204595Z" } }, "outputs": [], "source": [ "experiment.background.create(id='1', position=10, intensity=20)\n", "experiment.background.create(id='2', position=160, intensity=20)" ] }, { "cell_type": "markdown", "id": "22", "metadata": {}, "source": [ "### Set Calculation Range\n", "\n", "With no measured data, the x-grid to calculate on comes from the\n", "`data_range` category. It already holds a sensible default window\n", "derived from the instrument, so the experiment is calculable without\n", "any setup. Here we change the default window as an example." ] }, { "cell_type": "code", "execution_count": 12, "id": "23", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:08.210875Z", "iopub.status.busy": "2026-06-30T22:27:08.210676Z", "iopub.status.idle": "2026-06-30T22:27:08.215794Z", "shell.execute_reply": "2026-06-30T22:27:08.215079Z" } }, "outputs": [], "source": [ "experiment.data_range.two_theta_min = 10.0\n", "experiment.data_range.two_theta_max = 160.0\n", "experiment.data_range.two_theta_inc = 0.05" ] }, { "cell_type": "markdown", "id": "24", "metadata": {}, "source": [ "### Set Linked Structures" ] }, { "cell_type": "code", "execution_count": 13, "id": "25", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:08.217354Z", "iopub.status.busy": "2026-06-30T22:27:08.217196Z", "iopub.status.idle": "2026-06-30T22:27:08.220292Z", "shell.execute_reply": "2026-06-30T22:27:08.219551Z" } }, "outputs": [], "source": [ "experiment.linked_structures.create(structure_id='lbco', scale=10.0)" ] }, { "cell_type": "markdown", "id": "26", "metadata": {}, "source": [ "## πŸš€ Perform Calculation\n", "\n", "### Display Pattern\n", "\n", "Plotting the pattern computes the calculated curve over the\n", "`data_range` grid and shows a two-panel view: the calculated curve\n", "with its background on the main panel, plus a Bragg-peaks row. There\n", "is no measured curve or residual, because there is no measurement." ] }, { "cell_type": "code", "execution_count": 14, "id": "27", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:08.221616Z", "iopub.status.busy": "2026-06-30T22:27:08.221472Z", "iopub.status.idle": "2026-06-30T22:27:08.941205Z", "shell.execute_reply": "2026-06-30T22:27:08.940498Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='sim')" ] }, { "cell_type": "code", "execution_count": 15, "id": "28", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:08.943355Z", "iopub.status.busy": "2026-06-30T22:27:08.943186Z", "iopub.status.idle": "2026-06-30T22:27:08.987018Z", "shell.execute_reply": "2026-06-30T22:27:08.986134Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='sim', x_min=30, x_max=60)" ] }, { "cell_type": "markdown", "id": "29", "metadata": {}, "source": [ "### Modify Parameters and Recalculate" ] }, { "cell_type": "code", "execution_count": 16, "id": "30", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:08.988579Z", "iopub.status.busy": "2026-06-30T22:27:08.988420Z", "iopub.status.idle": "2026-06-30T22:27:08.991779Z", "shell.execute_reply": "2026-06-30T22:27:08.990921Z" } }, "outputs": [], "source": [ "structure.cell.length_a = 3.6\n", "structure.atom_sites['O'].adp_iso = 1.2\n", "experiment.peak.broad_lorentz_y = 0.9" ] }, { "cell_type": "code", "execution_count": 17, "id": "31", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:08.993193Z", "iopub.status.busy": "2026-06-30T22:27:08.993025Z", "iopub.status.idle": "2026-06-30T22:27:09.263038Z", "shell.execute_reply": "2026-06-30T22:27:09.262041Z" } }, "outputs": [], "source": [ "project.analysis.calculate()" ] }, { "cell_type": "code", "execution_count": 18, "id": "32", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:09.264808Z", "iopub.status.busy": "2026-06-30T22:27:09.264655Z", "iopub.status.idle": "2026-06-30T22:27:09.307781Z", "shell.execute_reply": "2026-06-30T22:27:09.306968Z" } }, "outputs": [ { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "project.display.pattern(expt_name='sim', x_min=30, x_max=60)" ] }, { "cell_type": "markdown", "id": "33", "metadata": {}, "source": [ "## πŸ’Ύ Save Project" ] }, { "cell_type": "code", "execution_count": 19, "id": "34", "metadata": { "execution": { "iopub.execute_input": "2026-06-30T22:27:09.309366Z", "iopub.status.busy": "2026-06-30T22:27:09.309176Z", "iopub.status.idle": "2026-06-30T22:27:09.492032Z", "shell.execute_reply": "2026-06-30T22:27:09.491248Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;36mSaving project πŸ“¦ \u001b[0m\u001b[32m'lbco_simulation'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/simulate-lbco-cwl'\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": [ "β”œβ”€β”€ πŸ“ experiments/\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "β”‚ └── πŸ“„ sim.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_simulation.html\n" ] } ], "source": [ "project.save_as(dir_path='projects/simulate-lbco-cwl')" ] } ], "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 }