{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "74abc5c8", "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 example demonstrates how to use the EasyDiffraction API in a\n", "simplified, user-friendly manner that closely follows the GUI workflow for a\n", "Rietveld refinement of La0.5Ba0.5CoO3 crystal structure using constant\n", "wavelength neutron powder diffraction data from HRPT at PSI.\n", "\n", "It is intended for users with minimal programming experience who want to\n", "learn how to perform standard crystal structure fitting using diffraction\n", "data. This script covers creating a project, adding sample models and\n", "experiments, performing analysis, and refining parameters.\n", "\n", "Only a single import of `easydiffraction` is required, and all operations are\n", "performed through high-level components of the `project` object, such as\n", "`project.sample_models`, `project.experiments`, and `project.analysis`.\n", "The `project` object is the main container for all information." ] }, { "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: Create a Project\n", "\n", "This section explains how to create a project and define its metadata." ] }, { "cell_type": "markdown", "id": "4", "metadata": {}, "source": [ "#### Create Project" ] }, { "cell_type": "code", "execution_count": null, "id": "5", "metadata": {}, "outputs": [], "source": [ "project = ed.Project(name='lbco_hrpt')" ] }, { "cell_type": "markdown", "id": "6", "metadata": {}, "source": [ "#### Set Project Metadata" ] }, { "cell_type": "code", "execution_count": null, "id": "7", "metadata": {}, "outputs": [], "source": [ "project.info.title = 'La0.5Ba0.5CoO3 at HRPT@PSI'\n", "project.info.description = \"\"\"This project demonstrates a standard\n", "refinement of La0.5Ba0.5CoO3, which crystallizes in a perovskite-type\n", "structure, using neutron powder diffraction data collected in constant\n", "wavelength mode at the HRPT diffractometer (PSI).\"\"\"" ] }, { "cell_type": "markdown", "id": "8", "metadata": {}, "source": [ "#### Show Project Metadata as CIF" ] }, { "cell_type": "code", "execution_count": null, "id": "9", "metadata": {}, "outputs": [], "source": [ "project.info.show_as_cif()" ] }, { "cell_type": "markdown", "id": "10", "metadata": {}, "source": [ "#### Save Project\n", "\n", "When saving the project for the first time, you need to specify the\n", "directory path. In the example below, the project is saved to a\n", "temporary location defined by the system." ] }, { "cell_type": "code", "execution_count": null, "id": "11", "metadata": {}, "outputs": [], "source": [ "project.save_as(dir_path='lbco_hrpt', temporary=True)" ] }, { "cell_type": "markdown", "id": "12", "metadata": {}, "source": [ "#### Set Up Data Plotter" ] }, { "cell_type": "markdown", "id": "13", "metadata": {}, "source": [ "Show supported plotting engines." ] }, { "cell_type": "code", "execution_count": null, "id": "14", "metadata": {}, "outputs": [], "source": [ "project.plotter.show_supported_engines()" ] }, { "cell_type": "markdown", "id": "15", "metadata": {}, "source": [ "Show current plotting configuration." ] }, { "cell_type": "code", "execution_count": null, "id": "16", "metadata": {}, "outputs": [], "source": [ "project.plotter.show_config()" ] }, { "cell_type": "markdown", "id": "17", "metadata": {}, "source": [ "Set plotting engine." ] }, { "cell_type": "code", "execution_count": null, "id": "18", "metadata": {}, "outputs": [], "source": [ "project.plotter.engine = 'plotly'" ] }, { "cell_type": "markdown", "id": "19", "metadata": {}, "source": [ "## Step 2: Define Sample Model\n", "\n", "This section shows how to add sample models and modify their parameters." ] }, { "cell_type": "markdown", "id": "20", "metadata": {}, "source": [ "#### Add Sample Model" ] }, { "cell_type": "code", "execution_count": null, "id": "21", "metadata": {}, "outputs": [], "source": [ "project.sample_models.add(name='lbco')" ] }, { "cell_type": "markdown", "id": "22", "metadata": {}, "source": [ "#### Show Defined Sample Models\n", "\n", "Show the names of the models added. These names are used to access the\n", "model using the syntax: `project.sample_models['model_name']`. All model\n", "parameters can be accessed via the `project` object." ] }, { "cell_type": "code", "execution_count": null, "id": "23", "metadata": {}, "outputs": [], "source": [ "project.sample_models.show_names()" ] }, { "cell_type": "markdown", "id": "24", "metadata": {}, "source": [ "#### Set Space Group\n", "\n", "Modify the default space group parameters." ] }, { "cell_type": "code", "execution_count": null, "id": "25", "metadata": {}, "outputs": [], "source": [ "project.sample_models['lbco'].space_group.name_h_m = 'P m -3 m'\n", "project.sample_models['lbco'].space_group.it_coordinate_system_code = '1'" ] }, { "cell_type": "markdown", "id": "26", "metadata": {}, "source": [ "#### Set Unit Cell\n", "\n", "Modify the default unit cell parameters." ] }, { "cell_type": "code", "execution_count": null, "id": "27", "metadata": {}, "outputs": [], "source": [ "project.sample_models['lbco'].cell.length_a = 3.88" ] }, { "cell_type": "markdown", "id": "28", "metadata": {}, "source": [ "#### Set Atom Sites\n", "\n", "Add atom sites to the sample model." ] }, { "cell_type": "code", "execution_count": null, "id": "29", "metadata": {}, "outputs": [], "source": [ "project.sample_models['lbco'].atom_sites.add(\n", " label='La',\n", " type_symbol='La',\n", " fract_x=0,\n", " fract_y=0,\n", " fract_z=0,\n", " wyckoff_letter='a',\n", " b_iso=0.5,\n", " occupancy=0.5,\n", ")\n", "project.sample_models['lbco'].atom_sites.add(\n", " label='Ba',\n", " type_symbol='Ba',\n", " fract_x=0,\n", " fract_y=0,\n", " fract_z=0,\n", " wyckoff_letter='a',\n", " b_iso=0.5,\n", " occupancy=0.5,\n", ")\n", "project.sample_models['lbco'].atom_sites.add(\n", " label='Co',\n", " type_symbol='Co',\n", " fract_x=0.5,\n", " fract_y=0.5,\n", " fract_z=0.5,\n", " wyckoff_letter='b',\n", " b_iso=0.5,\n", ")\n", "project.sample_models['lbco'].atom_sites.add(\n", " label='O',\n", " type_symbol='O',\n", " fract_x=0,\n", " fract_y=0.5,\n", " fract_z=0.5,\n", " wyckoff_letter='c',\n", " b_iso=0.5,\n", ")" ] }, { "cell_type": "markdown", "id": "30", "metadata": {}, "source": [ "#### Apply Symmetry Constraints" ] }, { "cell_type": "code", "execution_count": null, "id": "31", "metadata": {}, "outputs": [], "source": [ "project.sample_models['lbco'].apply_symmetry_constraints()" ] }, { "cell_type": "markdown", "id": "32", "metadata": {}, "source": [ "#### Show Sample Model as CIF" ] }, { "cell_type": "code", "execution_count": null, "id": "33", "metadata": {}, "outputs": [], "source": [ "project.sample_models['lbco'].show_as_cif()" ] }, { "cell_type": "markdown", "id": "34", "metadata": {}, "source": [ "#### Show Sample Model Structure" ] }, { "cell_type": "code", "execution_count": null, "id": "35", "metadata": {}, "outputs": [], "source": [ "project.sample_models['lbco'].show_structure()" ] }, { "cell_type": "markdown", "id": "36", "metadata": {}, "source": [ "#### Save Project State\n", "\n", "Save the project state after adding the sample model. This ensures\n", "that all changes are stored and can be accessed later. The project\n", "state is saved in the directory specified during project creation." ] }, { "cell_type": "code", "execution_count": null, "id": "37", "metadata": {}, "outputs": [], "source": [ "project.save()" ] }, { "cell_type": "markdown", "id": "38", "metadata": {}, "source": [ "## Step 3: Define Experiment\n", "\n", "This section shows how to add experiments, configure their parameters, and\n", "link the sample models defined in the previous step." ] }, { "cell_type": "markdown", "id": "39", "metadata": {}, "source": [ "#### Download Measured Data\n", "\n", "Download the data file from the EasyDiffraction repository on GitHub." ] }, { "cell_type": "code", "execution_count": null, "id": "40", "metadata": {}, "outputs": [], "source": [ "ed.download_from_repository('hrpt_lbco.xye', destination='data')" ] }, { "cell_type": "markdown", "id": "41", "metadata": {}, "source": [ "#### Add Diffraction Experiment" ] }, { "cell_type": "code", "execution_count": null, "id": "42", "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": "markdown", "id": "43", "metadata": {}, "source": [ "#### Show Defined Experiments" ] }, { "cell_type": "code", "execution_count": null, "id": "44", "metadata": {}, "outputs": [], "source": [ "project.experiments.show_names()" ] }, { "cell_type": "markdown", "id": "45", "metadata": {}, "source": [ "#### Show Measured Data" ] }, { "cell_type": "code", "execution_count": null, "id": "46", "metadata": {}, "outputs": [], "source": [ "project.plot_meas(expt_name='hrpt')" ] }, { "cell_type": "markdown", "id": "47", "metadata": {}, "source": [ "#### Set Instrument\n", "\n", "Modify the default instrument parameters." ] }, { "cell_type": "code", "execution_count": null, "id": "48", "metadata": {}, "outputs": [], "source": [ "project.experiments['hrpt'].instrument.setup_wavelength = 1.494\n", "project.experiments['hrpt'].instrument.calib_twotheta_offset = 0.6" ] }, { "cell_type": "markdown", "id": "49", "metadata": {}, "source": [ "#### Set Peak Profile\n", "\n", "Show supported peak profile types." ] }, { "cell_type": "code", "execution_count": null, "id": "50", "metadata": {}, "outputs": [], "source": [ "project.experiments['hrpt'].show_supported_peak_profile_types()" ] }, { "cell_type": "markdown", "id": "51", "metadata": {}, "source": [ "Show the current peak profile type." ] }, { "cell_type": "code", "execution_count": null, "id": "52", "metadata": {}, "outputs": [], "source": [ "project.experiments['hrpt'].show_current_peak_profile_type()" ] }, { "cell_type": "markdown", "id": "53", "metadata": {}, "source": [ "Select the desired peak profile type." ] }, { "cell_type": "code", "execution_count": null, "id": "54", "metadata": {}, "outputs": [], "source": [ "project.experiments['hrpt'].peak_profile_type = 'pseudo-voigt'" ] }, { "cell_type": "markdown", "id": "55", "metadata": {}, "source": [ "Modify default peak profile parameters." ] }, { "cell_type": "code", "execution_count": null, "id": "56", "metadata": {}, "outputs": [], "source": [ "project.experiments['hrpt'].peak.broad_gauss_u = 0.1\n", "project.experiments['hrpt'].peak.broad_gauss_v = -0.1\n", "project.experiments['hrpt'].peak.broad_gauss_w = 0.1\n", "project.experiments['hrpt'].peak.broad_lorentz_x = 0\n", "project.experiments['hrpt'].peak.broad_lorentz_y = 0.1" ] }, { "cell_type": "markdown", "id": "57", "metadata": {}, "source": [ "#### Set Background" ] }, { "cell_type": "markdown", "id": "58", "metadata": {}, "source": [ "Show supported background types." ] }, { "cell_type": "code", "execution_count": null, "id": "59", "metadata": {}, "outputs": [], "source": [ "project.experiments['hrpt'].show_supported_background_types()" ] }, { "cell_type": "markdown", "id": "60", "metadata": {}, "source": [ "Show current background type." ] }, { "cell_type": "code", "execution_count": null, "id": "61", "metadata": {}, "outputs": [], "source": [ "project.experiments['hrpt'].show_current_background_type()" ] }, { "cell_type": "markdown", "id": "62", "metadata": {}, "source": [ "Select the desired background type." ] }, { "cell_type": "code", "execution_count": null, "id": "63", "metadata": {}, "outputs": [], "source": [ "project.experiments['hrpt'].background_type = 'line-segment'" ] }, { "cell_type": "markdown", "id": "64", "metadata": {}, "source": [ "Add background points." ] }, { "cell_type": "code", "execution_count": null, "id": "65", "metadata": {}, "outputs": [], "source": [ "project.experiments['hrpt'].background.add(x=10, y=170)\n", "project.experiments['hrpt'].background.add(x=30, y=170)\n", "project.experiments['hrpt'].background.add(x=50, y=170)\n", "project.experiments['hrpt'].background.add(x=110, y=170)\n", "project.experiments['hrpt'].background.add(x=165, y=170)" ] }, { "cell_type": "markdown", "id": "66", "metadata": {}, "source": [ "Show current background points." ] }, { "cell_type": "code", "execution_count": null, "id": "67", "metadata": {}, "outputs": [], "source": [ "project.experiments['hrpt'].background.show()" ] }, { "cell_type": "markdown", "id": "68", "metadata": {}, "source": [ "#### Set Linked Phases\n", "\n", "Link the sample model defined in the previous step to the experiment." ] }, { "cell_type": "code", "execution_count": null, "id": "69", "metadata": {}, "outputs": [], "source": [ "project.experiments['hrpt'].linked_phases.add(id='lbco', scale=10.0)" ] }, { "cell_type": "markdown", "id": "70", "metadata": {}, "source": [ "#### Show Experiment as CIF" ] }, { "cell_type": "code", "execution_count": null, "id": "71", "metadata": {}, "outputs": [], "source": [ "project.experiments['hrpt'].show_as_cif()" ] }, { "cell_type": "markdown", "id": "72", "metadata": {}, "source": [ "#### Save Project State" ] }, { "cell_type": "code", "execution_count": null, "id": "73", "metadata": {}, "outputs": [], "source": [ "project.save()" ] }, { "cell_type": "markdown", "id": "74", "metadata": {}, "source": [ "## Step 4: Perform Analysis\n", "\n", "This section explains the analysis process, including how to set up\n", "calculation and fitting engines.\n", "\n", "#### Set Calculator\n", "\n", "Show supported calculation engines." ] }, { "cell_type": "code", "execution_count": null, "id": "75", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_supported_calculators()" ] }, { "cell_type": "markdown", "id": "76", "metadata": {}, "source": [ "Show current calculation engine." ] }, { "cell_type": "code", "execution_count": null, "id": "77", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_current_calculator()" ] }, { "cell_type": "markdown", "id": "78", "metadata": {}, "source": [ "Select the desired calculation engine." ] }, { "cell_type": "code", "execution_count": null, "id": "79", "metadata": {}, "outputs": [], "source": [ "project.analysis.current_calculator = 'cryspy'" ] }, { "cell_type": "markdown", "id": "80", "metadata": {}, "source": [ "#### Show Calculated Data" ] }, { "cell_type": "code", "execution_count": null, "id": "81", "metadata": {}, "outputs": [], "source": [ "project.plot_calc(expt_name='hrpt')" ] }, { "cell_type": "markdown", "id": "82", "metadata": {}, "source": [ "#### Plot Measured vs Calculated" ] }, { "cell_type": "code", "execution_count": null, "id": "83", "metadata": {}, "outputs": [], "source": [ "project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "84", "metadata": {}, "outputs": [], "source": [ "project.plot_meas_vs_calc(expt_name='hrpt', x_min=38, x_max=41, show_residual=True)" ] }, { "cell_type": "markdown", "id": "85", "metadata": {}, "source": [ "#### Show Parameters\n", "\n", "Show all parameters of the project." ] }, { "cell_type": "code", "execution_count": null, "id": "86", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_all_params()" ] }, { "cell_type": "markdown", "id": "87", "metadata": {}, "source": [ "Show all fittable parameters." ] }, { "cell_type": "code", "execution_count": null, "id": "88", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_fittable_params()" ] }, { "cell_type": "markdown", "id": "89", "metadata": {}, "source": [ "Show only free parameters." ] }, { "cell_type": "code", "execution_count": null, "id": "90", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_free_params()" ] }, { "cell_type": "markdown", "id": "91", "metadata": {}, "source": [ "Show how to access parameters in the code." ] }, { "cell_type": "code", "execution_count": null, "id": "92", "metadata": {}, "outputs": [], "source": [ "project.analysis.how_to_access_parameters()" ] }, { "cell_type": "markdown", "id": "93", "metadata": {}, "source": [ "#### Set Fit Mode\n", "\n", "Show supported fit modes." ] }, { "cell_type": "code", "execution_count": null, "id": "94", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_available_fit_modes()" ] }, { "cell_type": "markdown", "id": "95", "metadata": {}, "source": [ "Show current fit mode." ] }, { "cell_type": "code", "execution_count": null, "id": "96", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_current_fit_mode()" ] }, { "cell_type": "markdown", "id": "97", "metadata": {}, "source": [ "Select desired fit mode." ] }, { "cell_type": "code", "execution_count": null, "id": "98", "metadata": {}, "outputs": [], "source": [ "project.analysis.fit_mode = 'single'" ] }, { "cell_type": "markdown", "id": "99", "metadata": {}, "source": [ "#### Set Minimizer\n", "\n", "Show supported fitting engines." ] }, { "cell_type": "code", "execution_count": null, "id": "100", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_available_minimizers()" ] }, { "cell_type": "markdown", "id": "101", "metadata": {}, "source": [ "Show current fitting engine." ] }, { "cell_type": "code", "execution_count": null, "id": "102", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_current_minimizer()" ] }, { "cell_type": "markdown", "id": "103", "metadata": {}, "source": [ "Select desired fitting engine." ] }, { "cell_type": "code", "execution_count": null, "id": "104", "metadata": {}, "outputs": [], "source": [ "project.analysis.current_minimizer = 'lmfit (leastsq)'" ] }, { "cell_type": "markdown", "id": "105", "metadata": {}, "source": [ "### Perform Fit 1/5\n", "\n", "Set sample model parameters to be refined." ] }, { "cell_type": "code", "execution_count": null, "id": "106", "metadata": {}, "outputs": [], "source": [ "project.sample_models['lbco'].cell.length_a.free = True" ] }, { "cell_type": "markdown", "id": "107", "metadata": {}, "source": [ "Set experiment parameters to be refined." ] }, { "cell_type": "code", "execution_count": null, "id": "108", "metadata": {}, "outputs": [], "source": [ "project.experiments['hrpt'].linked_phases['lbco'].scale.free = True\n", "project.experiments['hrpt'].instrument.calib_twotheta_offset.free = True\n", "project.experiments['hrpt'].background['10'].y.free = True\n", "project.experiments['hrpt'].background['30'].y.free = True\n", "project.experiments['hrpt'].background['50'].y.free = True\n", "project.experiments['hrpt'].background['110'].y.free = True\n", "project.experiments['hrpt'].background['165'].y.free = True" ] }, { "cell_type": "markdown", "id": "109", "metadata": {}, "source": [ "Show free parameters after selection." ] }, { "cell_type": "code", "execution_count": null, "id": "110", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_free_params()" ] }, { "cell_type": "markdown", "id": "111", "metadata": {}, "source": [ "#### Run Fitting" ] }, { "cell_type": "code", "execution_count": null, "id": "112", "metadata": {}, "outputs": [], "source": [ "project.analysis.fit()" ] }, { "cell_type": "markdown", "id": "113", "metadata": {}, "source": [ "#### Plot Measured vs Calculated" ] }, { "cell_type": "code", "execution_count": null, "id": "114", "metadata": {}, "outputs": [], "source": [ "project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "115", "metadata": {}, "outputs": [], "source": [ "project.plot_meas_vs_calc(expt_name='hrpt', x_min=38, x_max=41, show_residual=True)" ] }, { "cell_type": "markdown", "id": "116", "metadata": {}, "source": [ "#### Save Project State" ] }, { "cell_type": "code", "execution_count": null, "id": "117", "metadata": {}, "outputs": [], "source": [ "project.save_as(dir_path='lbco_hrpt', temporary=True)" ] }, { "cell_type": "markdown", "id": "118", "metadata": {}, "source": [ "### Perform Fit 2/5\n", "\n", "Set more parameters to be refined." ] }, { "cell_type": "code", "execution_count": null, "id": "119", "metadata": {}, "outputs": [], "source": [ "project.experiments['hrpt'].peak.broad_gauss_u.free = True\n", "project.experiments['hrpt'].peak.broad_gauss_v.free = True\n", "project.experiments['hrpt'].peak.broad_gauss_w.free = True\n", "project.experiments['hrpt'].peak.broad_lorentz_y.free = True" ] }, { "cell_type": "markdown", "id": "120", "metadata": {}, "source": [ "Show free parameters after selection." ] }, { "cell_type": "code", "execution_count": null, "id": "121", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_free_params()" ] }, { "cell_type": "markdown", "id": "122", "metadata": {}, "source": [ "#### Run Fitting" ] }, { "cell_type": "code", "execution_count": null, "id": "123", "metadata": {}, "outputs": [], "source": [ "project.analysis.fit()" ] }, { "cell_type": "markdown", "id": "124", "metadata": {}, "source": [ "#### Plot Measured vs Calculated" ] }, { "cell_type": "code", "execution_count": null, "id": "125", "metadata": {}, "outputs": [], "source": [ "project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "126", "metadata": {}, "outputs": [], "source": [ "project.plot_meas_vs_calc(expt_name='hrpt', x_min=38, x_max=41, show_residual=True)" ] }, { "cell_type": "markdown", "id": "127", "metadata": {}, "source": [ "#### Save Project State" ] }, { "cell_type": "code", "execution_count": null, "id": "128", "metadata": {}, "outputs": [], "source": [ "project.save_as(dir_path='lbco_hrpt', temporary=True)" ] }, { "cell_type": "markdown", "id": "129", "metadata": {}, "source": [ "### Perform Fit 3/5\n", "\n", "Set more parameters to be refined." ] }, { "cell_type": "code", "execution_count": null, "id": "130", "metadata": {}, "outputs": [], "source": [ "project.sample_models['lbco'].atom_sites['La'].b_iso.free = True\n", "project.sample_models['lbco'].atom_sites['Ba'].b_iso.free = True\n", "project.sample_models['lbco'].atom_sites['Co'].b_iso.free = True\n", "project.sample_models['lbco'].atom_sites['O'].b_iso.free = True" ] }, { "cell_type": "markdown", "id": "131", "metadata": {}, "source": [ "Show free parameters after selection." ] }, { "cell_type": "code", "execution_count": null, "id": "132", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_free_params()" ] }, { "cell_type": "markdown", "id": "133", "metadata": {}, "source": [ "#### Run Fitting" ] }, { "cell_type": "code", "execution_count": null, "id": "134", "metadata": {}, "outputs": [], "source": [ "project.analysis.fit()" ] }, { "cell_type": "markdown", "id": "135", "metadata": {}, "source": [ "#### Plot Measured vs Calculated" ] }, { "cell_type": "code", "execution_count": null, "id": "136", "metadata": {}, "outputs": [], "source": [ "project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "137", "metadata": {}, "outputs": [], "source": [ "project.plot_meas_vs_calc(expt_name='hrpt', x_min=38, x_max=41, show_residual=True)" ] }, { "cell_type": "markdown", "id": "138", "metadata": {}, "source": [ "#### Save Project State" ] }, { "cell_type": "code", "execution_count": null, "id": "139", "metadata": {}, "outputs": [], "source": [ "project.save_as(dir_path='lbco_hrpt', temporary=True)" ] }, { "cell_type": "markdown", "id": "140", "metadata": {}, "source": [ "### Perform Fit 4/5\n", "\n", "#### Set Constraints\n", "\n", "Set aliases for parameters." ] }, { "cell_type": "code", "execution_count": null, "id": "141", "metadata": {}, "outputs": [], "source": [ "project.analysis.aliases.add(label='biso_La', param_uid=project.sample_models['lbco'].atom_sites['La'].b_iso.uid)\n", "project.analysis.aliases.add(label='biso_Ba', param_uid=project.sample_models['lbco'].atom_sites['Ba'].b_iso.uid)" ] }, { "cell_type": "markdown", "id": "142", "metadata": {}, "source": [ "Set constraints." ] }, { "cell_type": "code", "execution_count": null, "id": "143", "metadata": {}, "outputs": [], "source": [ "project.analysis.constraints.add(lhs_alias='biso_Ba', rhs_expr='biso_La')" ] }, { "cell_type": "markdown", "id": "144", "metadata": {}, "source": [ "Show defined constraints." ] }, { "cell_type": "code", "execution_count": null, "id": "145", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_constraints()" ] }, { "cell_type": "markdown", "id": "146", "metadata": {}, "source": [ "Show free parameters before applying constraints." ] }, { "cell_type": "code", "execution_count": null, "id": "147", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_free_params()" ] }, { "cell_type": "markdown", "id": "148", "metadata": {}, "source": [ "Apply constraints." ] }, { "cell_type": "code", "execution_count": null, "id": "149", "metadata": {}, "outputs": [], "source": [ "project.analysis.apply_constraints()" ] }, { "cell_type": "markdown", "id": "150", "metadata": {}, "source": [ "Show free parameters after applying constraints." ] }, { "cell_type": "code", "execution_count": null, "id": "151", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_free_params()" ] }, { "cell_type": "markdown", "id": "152", "metadata": {}, "source": [ "#### Run Fitting" ] }, { "cell_type": "code", "execution_count": null, "id": "153", "metadata": {}, "outputs": [], "source": [ "project.analysis.fit()" ] }, { "cell_type": "markdown", "id": "154", "metadata": {}, "source": [ "#### Plot Measured vs Calculated" ] }, { "cell_type": "code", "execution_count": null, "id": "155", "metadata": {}, "outputs": [], "source": [ "project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "156", "metadata": {}, "outputs": [], "source": [ "project.plot_meas_vs_calc(expt_name='hrpt', x_min=38, x_max=41, show_residual=True)" ] }, { "cell_type": "markdown", "id": "157", "metadata": {}, "source": [ "#### Save Project State" ] }, { "cell_type": "code", "execution_count": null, "id": "158", "metadata": {}, "outputs": [], "source": [ "project.save_as(dir_path='lbco_hrpt', temporary=True)" ] }, { "cell_type": "markdown", "id": "159", "metadata": {}, "source": [ "### Perform Fit 5/5\n", "\n", "#### Set Constraints\n", "\n", "Set more aliases for parameters." ] }, { "cell_type": "code", "execution_count": null, "id": "160", "metadata": {}, "outputs": [], "source": [ "project.analysis.aliases.add(\n", " label='occ_La',\n", " param_uid=project.sample_models['lbco'].atom_sites['La'].occupancy.uid,\n", ")\n", "project.analysis.aliases.add(\n", " label='occ_Ba',\n", " param_uid=project.sample_models['lbco'].atom_sites['Ba'].occupancy.uid,\n", ")" ] }, { "cell_type": "markdown", "id": "161", "metadata": {}, "source": [ "Set more constraints." ] }, { "cell_type": "code", "execution_count": null, "id": "162", "metadata": {}, "outputs": [], "source": [ "project.analysis.constraints.add(\n", " lhs_alias='occ_Ba',\n", " rhs_expr='1 - occ_La',\n", ")" ] }, { "cell_type": "markdown", "id": "163", "metadata": {}, "source": [ "Show defined constraints." ] }, { "cell_type": "code", "execution_count": null, "id": "164", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_constraints()" ] }, { "cell_type": "markdown", "id": "165", "metadata": {}, "source": [ "Apply constraints." ] }, { "cell_type": "code", "execution_count": null, "id": "166", "metadata": {}, "outputs": [], "source": [ "project.analysis.apply_constraints()" ] }, { "cell_type": "markdown", "id": "167", "metadata": {}, "source": [ "Set sample model parameters to be refined." ] }, { "cell_type": "code", "execution_count": null, "id": "168", "metadata": {}, "outputs": [], "source": [ "project.sample_models['lbco'].atom_sites['La'].occupancy.free = True" ] }, { "cell_type": "markdown", "id": "169", "metadata": {}, "source": [ "Show free parameters after selection." ] }, { "cell_type": "code", "execution_count": null, "id": "170", "metadata": {}, "outputs": [], "source": [ "project.analysis.show_free_params()" ] }, { "cell_type": "markdown", "id": "171", "metadata": {}, "source": [ "#### Run Fitting" ] }, { "cell_type": "code", "execution_count": null, "id": "172", "metadata": {}, "outputs": [], "source": [ "project.analysis.fit()" ] }, { "cell_type": "markdown", "id": "173", "metadata": {}, "source": [ "#### Plot Measured vs Calculated" ] }, { "cell_type": "code", "execution_count": null, "id": "174", "metadata": {}, "outputs": [], "source": [ "project.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "175", "metadata": {}, "outputs": [], "source": [ "project.plot_meas_vs_calc(expt_name='hrpt', x_min=38, x_max=41, show_residual=True)" ] }, { "cell_type": "markdown", "id": "176", "metadata": {}, "source": [ "#### Save Project State" ] }, { "cell_type": "code", "execution_count": null, "id": "177", "metadata": {}, "outputs": [], "source": [ "project.save_as(dir_path='lbco_hrpt', temporary=True)" ] }, { "cell_type": "markdown", "id": "178", "metadata": {}, "source": [ "## Step 5: Summary\n", "\n", "This final section shows how to review the results of the analysis." ] }, { "cell_type": "markdown", "id": "179", "metadata": {}, "source": [ "#### Show Project Summary" ] }, { "cell_type": "code", "execution_count": null, "id": "180", "metadata": {}, "outputs": [], "source": [ "project.summary.show_report()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }