{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "cb7ab0e6", "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": [ "# Pair Distribution Function: Si, NPD\n", "\n", "This example demonstrates a pair distribution function (PDF) analysis of Si,\n", "based on data collected from a time-of-flight neutron powder diffraction\n", "experiment at NOMAD at SNS." ] }, { "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": [ "## Create Project" ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "project = ed.Project()" ] }, { "cell_type": "markdown", "id": "5", "metadata": {}, "source": [ "## Set Plotting Engine" ] }, { "cell_type": "code", "execution_count": null, "id": "6", "metadata": {}, "outputs": [], "source": [ "project.plotter.engine = 'plotly'\n", "project.plotter.x_max = 40" ] }, { "cell_type": "markdown", "id": "7", "metadata": {}, "source": [ "## Add Sample Model" ] }, { "cell_type": "code", "execution_count": null, "id": "8", "metadata": {}, "outputs": [], "source": [ "project.sample_models.add(name='si')" ] }, { "cell_type": "code", "execution_count": null, "id": "9", "metadata": {}, "outputs": [], "source": [ "sample_model = project.sample_models['si']\n", "sample_model.space_group.name_h_m.value = 'F d -3 m'\n", "sample_model.space_group.it_coordinate_system_code = '1'\n", "sample_model.cell.length_a = 5.43146\n", "sample_model.atom_sites.add(label='Si', type_symbol='Si', fract_x=0, fract_y=0, fract_z=0, wyckoff_letter='a', b_iso=0.5)" ] }, { "cell_type": "markdown", "id": "10", "metadata": {}, "source": [ "## Add Experiment" ] }, { "cell_type": "code", "execution_count": null, "id": "11", "metadata": {}, "outputs": [], "source": [ "ed.download_from_repository('NOM_9999_Si_640g_PAC_50_ff_ftfrgr_up-to-50.gr', destination='data')" ] }, { "cell_type": "code", "execution_count": null, "id": "12", "metadata": {}, "outputs": [], "source": [ "project.experiments.add(\n", " name='nomad',\n", " sample_form='powder',\n", " beam_mode='time-of-flight',\n", " radiation_probe='neutron',\n", " scattering_type='total',\n", " data_path='data/NOM_9999_Si_640g_PAC_50_ff_ftfrgr_up-to-50.gr',\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "13", "metadata": {}, "outputs": [], "source": [ "experiment = project.experiments['nomad']\n", "experiment.linked_phases.add(id='si', scale=1.0)\n", "experiment.peak.damp_q = 0.02\n", "experiment.peak.broad_q = 0.03\n", "experiment.peak.cutoff_q = 35.0\n", "experiment.peak.sharp_delta_1 = 0.0\n", "experiment.peak.sharp_delta_2 = 4.0\n", "experiment.peak.damp_particle_diameter = 0" ] }, { "cell_type": "markdown", "id": "14", "metadata": {}, "source": [ "## Select Fitting Parameters" ] }, { "cell_type": "code", "execution_count": null, "id": "15", "metadata": {}, "outputs": [], "source": [ "project.sample_models['si'].cell.length_a.free = True\n", "project.sample_models['si'].atom_sites['Si'].b_iso.free = True\n", "experiment.linked_phases['si'].scale.free = True" ] }, { "cell_type": "code", "execution_count": null, "id": "16", "metadata": {}, "outputs": [], "source": [ "experiment.peak.damp_q.free = True\n", "experiment.peak.broad_q.free = True\n", "experiment.peak.sharp_delta_1.free = True\n", "experiment.peak.sharp_delta_2.free = True" ] }, { "cell_type": "markdown", "id": "17", "metadata": {}, "source": [ "## Run Fitting" ] }, { "cell_type": "code", "execution_count": null, "id": "18", "metadata": {}, "outputs": [], "source": [ "project.analysis.current_calculator = 'pdffit'\n", "project.analysis.fit()" ] }, { "cell_type": "markdown", "id": "19", "metadata": {}, "source": [ "## Plot Measured vs Calculated" ] }, { "cell_type": "code", "execution_count": null, "id": "20", "metadata": {}, "outputs": [], "source": [ "project.plot_meas_vs_calc(expt_name='nomad', show_residual=False)" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }