{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "2659804d", "metadata": { "tags": [ "hide-in-docs" ] }, "outputs": [], "source": [ "# Check if the easydiffraction library is installed.\n", "# If not, install it including the 'visualization' extras.\n", "# This is needed, e.g., when running this as a notebook via Google Colab or\n", "# Jupyter Notebook in an environment where the library is not pre-installed.\n", "import builtins\n", "import importlib.util\n", "\n", "if hasattr(builtins, '__IPYTHON__'):\n", " if importlib.util.find_spec('easydiffraction') is None:\n", " !pip install 'easydiffraction[visualization]'\n" ] }, { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# Structure Refinement: LBCO, HRPT\n", "\n", "This minimalistic example is designed to be as compact as possible for a\n", "Rietveld refinement of a crystal structure using constant-wavelength neutron\n", "powder diffraction data for La0.5Ba0.5CoO3 from HRPT at PSI.\n", "\n", "It does not contain any advanced features or options, and includes no\n", "comments or explanations—these can be found in the other tutorials.\n", "Default values are used for all parameters if not specified. Only essential\n", "and self-explanatory code is provided.\n", "\n", "The example is intended for users who are already familiar with the\n", "EasyDiffraction library and want to quickly get started with a simple\n", "refinement. It is also useful for those who want to see what a refinement\n", "might look like in code. For a more detailed explanation of the code, please\n", "refer to the other tutorials." ] }, { "cell_type": "markdown", "id": "1", "metadata": {}, "source": [ "## Import Library" ] }, { "cell_type": "code", "execution_count": null, "id": "2", "metadata": {}, "outputs": [], "source": [ "import easydiffraction as ed" ] }, { "cell_type": "markdown", "id": "3", "metadata": {}, "source": [ "## Step 1: Define Project" ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "project = ed.Project()" ] }, { "cell_type": "markdown", "id": "5", "metadata": {}, "source": [ "## Step 2: Define Sample Model" ] }, { "cell_type": "code", "execution_count": null, "id": "6", "metadata": {}, "outputs": [], "source": [ "project.sample_models.add(name='lbco')" ] }, { "cell_type": "code", "execution_count": null, "id": "7", "metadata": {}, "outputs": [], "source": [ "sample_model = project.sample_models['lbco']" ] }, { "cell_type": "code", "execution_count": null, "id": "8", "metadata": {}, "outputs": [], "source": [ "sample_model.space_group.name_h_m = 'P m -3 m'\n", "sample_model.space_group.it_coordinate_system_code = '1'" ] }, { "cell_type": "code", "execution_count": null, "id": "9", "metadata": {}, "outputs": [], "source": [ "sample_model.cell.length_a = 3.88" ] }, { "cell_type": "code", "execution_count": null, "id": "10", "metadata": {}, "outputs": [], "source": [ "sample_model.atom_sites.add('La', 'La', 0, 0, 0, b_iso=0.5, occupancy=0.5)\n", "sample_model.atom_sites.add('Ba', 'Ba', 0, 0, 0, b_iso=0.5, occupancy=0.5)\n", "sample_model.atom_sites.add('Co', 'Co', 0.5, 0.5, 0.5, b_iso=0.5)\n", "sample_model.atom_sites.add('O', 'O', 0, 0.5, 0.5, b_iso=0.5)" ] }, { "cell_type": "markdown", "id": "11", "metadata": {}, "source": [ "## Step 3: Define Experiment" ] }, { "cell_type": "code", "execution_count": null, "id": "12", "metadata": {}, "outputs": [], "source": [ "ed.download_from_repository('hrpt_lbco.xye', destination='data')" ] }, { "cell_type": "code", "execution_count": null, "id": "13", "metadata": {}, "outputs": [], "source": [ "project.experiments.add(\n", " name='hrpt',\n", " sample_form='powder',\n", " beam_mode='constant wavelength',\n", " radiation_probe='neutron',\n", " data_path='data/hrpt_lbco.xye',\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "14", "metadata": {}, "outputs": [], "source": [ "experiment = project.experiments['hrpt']" ] }, { "cell_type": "code", "execution_count": null, "id": "15", "metadata": {}, "outputs": [], "source": [ "experiment.instrument.setup_wavelength = 1.494\n", "experiment.instrument.calib_twotheta_offset = 0.6" ] }, { "cell_type": "code", "execution_count": null, "id": "16", "metadata": {}, "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": "code", "execution_count": null, "id": "17", "metadata": {}, "outputs": [], "source": [ "experiment.background.add(x=10, y=170)\n", "experiment.background.add(x=30, y=170)\n", "experiment.background.add(x=50, y=170)\n", "experiment.background.add(x=110, y=170)\n", "experiment.background.add(x=165, y=170)" ] }, { "cell_type": "code", "execution_count": null, "id": "18", "metadata": {}, "outputs": [], "source": [ "experiment.excluded_regions.add(minimum=0, maximum=5)\n", "experiment.excluded_regions.add(minimum=165, maximum=180)" ] }, { "cell_type": "code", "execution_count": null, "id": "19", "metadata": {}, "outputs": [], "source": [ "experiment.linked_phases.add(id='lbco', scale=10.0)" ] }, { "cell_type": "markdown", "id": "20", "metadata": {}, "source": [ "## Step 4: Perform Analysis" ] }, { "cell_type": "code", "execution_count": null, "id": "21", "metadata": {}, "outputs": [], "source": [ "sample_model.cell.length_a.free = True\n", "\n", "sample_model.atom_sites['La'].b_iso.free = True\n", "sample_model.atom_sites['Ba'].b_iso.free = True\n", "sample_model.atom_sites['Co'].b_iso.free = True\n", "sample_model.atom_sites['O'].b_iso.free = True" ] }, { "cell_type": "code", "execution_count": null, "id": "22", "metadata": {}, "outputs": [], "source": [ "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_y.free = True\n", "\n", "experiment.background['10'].y.free = True\n", "experiment.background['30'].y.free = True\n", "experiment.background['50'].y.free = True\n", "experiment.background['110'].y.free = True\n", "experiment.background['165'].y.free = True\n", "\n", "experiment.linked_phases['lbco'].scale.free = True" ] }, { "cell_type": "code", "execution_count": null, "id": "23", "metadata": {}, "outputs": [], "source": [ "project.analysis.fit()" ] }, { "cell_type": "code", "execution_count": null, "id": "24", "metadata": {}, "outputs": [], "source": [ "project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }