{ "cells": [ { "cell_type": "markdown", "id": "26bea4e7", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "# CrysFML: Neutrons vs X-rays" ] }, { "cell_type": "code", "execution_count": null, "id": "9ecc4733", "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "# Misc\n", "import sys, os\n", "import numpy as np\n", "\n", "# CrysFML\n", "import CFML_api\n", "\n", "# Vizualization\n", "import py3Dmol\n", "from bokeh.io import show, output_notebook\n", "from bokeh.plotting import figure" ] }, { "cell_type": "code", "execution_count": null, "id": "d76d50fc", "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "output_notebook()\n", "FIGURE_WIDTH = 700\n", "FIGURE_HEIGHT = 300" ] }, { "cell_type": "code", "execution_count": null, "id": "9bc7ab53", "metadata": {}, "outputs": [], "source": [ "def diffraction_pattern_xy(space_group, cell, atom_list, job_info):\n", " reflection_list = CFML_api.ReflectionList(cell, space_group, \n", " True, \n", " job_info)\n", " reflection_list.compute_structure_factors(space_group, \n", " atom_list, \n", " job_info)\n", " diffraction_pattern = CFML_api.DiffractionPattern(job_info,\n", " reflection_list, \n", " cell.reciprocal_cell_vol)\n", " return diffraction_pattern.x, diffraction_pattern.ycalc" ] }, { "cell_type": "code", "execution_count": null, "id": "dff61a69", "metadata": {}, "outputs": [], "source": [ "def set_default_parameters(job_info):\n", " job_info.range_2theta = (10.0, 155.45)\n", " job_info.theta_step = 0.05\n", " job_info.lambdas = (1.9122, 1.9122)\n", " job_info.lambda_ratio = 1.0\n", " job_info.u_resolution = 0.1421\n", " job_info.v_resolution = -0.4181\n", " job_info.w_resolution = 0.3864\n", " job_info.x_resolution = 0.0\n", " job_info.y_resolution = 0.0904" ] }, { "cell_type": "markdown", "id": "7e5916ec", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "## Define model" ] }, { "cell_type": "markdown", "id": "45dbea02", "metadata": {}, "source": [ "### Create space group object" ] }, { "cell_type": "code", "execution_count": null, "id": "85719689", "metadata": {}, "outputs": [], "source": [ "space_group = CFML_api.SpaceGroup('P n m a')\n", "#space_group.print_description()" ] }, { "cell_type": "markdown", "id": "7318fe30", "metadata": {}, "source": [ "### Create unit cell object" ] }, { "cell_type": "code", "execution_count": null, "id": "3331332e", "metadata": {}, "outputs": [], "source": [ "lengths = np.asarray([8.477,5.396,6.957], dtype='float32')\n", "angles = np.asarray([90,90,90], dtype='float32')\n", "unit_cell = CFML_api.Cell(lengths, angles)\n", "#unit_cell.print_description()" ] }, { "cell_type": "markdown", "id": "f7abc667", "metadata": {}, "source": [ "### Create list of atoms" ] }, { "cell_type": "code", "execution_count": null, "id": "990fd6f8", "metadata": {}, "outputs": [], "source": [ "cif_str = '''\n", "loop_\n", " _atom_site_label\n", " _atom_site_type_symbol\n", " _atom_site_occupancy\n", " _atom_site_fract_x\n", " _atom_site_fract_y\n", " _atom_site_fract_z\n", " _atom_site_adp_type\n", " _atom_site_U_iso_or_equiv\n", " Pb Pb 1.0 0.1880 0.25 0.1668 Uiso 0.0169\n", " S S 1.0 0.0650 0.25 0.6850 Uiso 0.0025\n", " O1 O 1.0 0.9080 0.25 0.5950 Uiso 0.0246\n", " O2 O 1.0 0.1935 0.25 0.5432 Uiso 0.0180\n", " O3 O 1.0 0.0814 0.0274 0.8085 Uiso 0.0165\n", "'''\n", "atom_list = CFML_api.AtomList(cif_str.split('\\n'))\n", "atom_list.set_mult_occ_cif(space_group)\n", "#atom_list.print_description()" ] }, { "cell_type": "markdown", "id": "e85b2978", "metadata": {}, "source": [ "### Create job definition object" ] }, { "cell_type": "code", "execution_count": null, "id": "9651c148", "metadata": {}, "outputs": [], "source": [ "cfl_str = '''\n", "Title SrTiO3\n", "'''\n", "job_info = CFML_api.JobInfo(cfl_str.split('\\n'))\n", "job_info.print_description()" ] }, { "cell_type": "markdown", "id": "8d2a501f", "metadata": {}, "source": [ "### Modify job definition object" ] }, { "cell_type": "code", "execution_count": null, "id": "a54b8c2b", "metadata": {}, "outputs": [], "source": [ "job_info.pattern_type = \"NEUT_2THE\"\n", "set_default_parameters(job_info)\n", "job_info.print_description()" ] }, { "cell_type": "markdown", "id": "205efba2", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "## Calculate neutron powder diffraction pattern" ] }, { "cell_type": "markdown", "id": "0d389b01", "metadata": {}, "source": [ "### Plot calculated pattern" ] }, { "cell_type": "code", "execution_count": null, "id": "ff08fbf0", "metadata": {}, "outputs": [], "source": [ "x_data, y_data_neutrons = diffraction_pattern_xy(space_group, unit_cell, atom_list, job_info)\n", "fig = figure(width=FIGURE_WIDTH, height=FIGURE_HEIGHT)\n", "fig.line(x_data, y_data_neutrons, legend_label='Neutrons', color='orangered', line_width=2)\n", "show(fig)" ] }, { "cell_type": "markdown", "id": "d978e86e", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "## Calculate X-rays powder diffraction pattern" ] }, { "cell_type": "markdown", "id": "db8ee522", "metadata": {}, "source": [ "### Modify job definition object" ] }, { "cell_type": "code", "execution_count": null, "id": "ecf85ccb", "metadata": {}, "outputs": [], "source": [ "job_info.pattern_type = \"XRAY_2THE\"\n", "job_info.print_description()" ] }, { "cell_type": "markdown", "id": "158b54b2", "metadata": {}, "source": [ "### Plot calculated pattern" ] }, { "cell_type": "code", "execution_count": null, "id": "aa77c718", "metadata": {}, "outputs": [], "source": [ "x_data, y_data_xrays = diffraction_pattern_xy(space_group, unit_cell, atom_list, job_info)\n", "fig = figure(width=FIGURE_WIDTH, height=FIGURE_HEIGHT)\n", "fig.line(x_data, y_data_xrays, legend_label='Xrays / 500', color='olivedrab', line_width=2)\n", "show(fig)" ] }, { "cell_type": "markdown", "id": "95daab9b", "metadata": {}, "source": [ "## Compare neutron and X-ray diffraction patterns" ] }, { "cell_type": "code", "execution_count": null, "id": "025aca32", "metadata": { "scrolled": true }, "outputs": [], "source": [ "fig = figure(width=FIGURE_WIDTH, height=FIGURE_HEIGHT)\n", "fig.line(x_data, y_data_neutrons, legend_label='Neutrons', color='orangered', line_width=2)\n", "fig.line(x_data, y_data_xrays/500, legend_label='Xrays / 500', color='olivedrab', line_width=2)\n", "show(fig)" ] }, { "cell_type": "code", "execution_count": null, "id": "af159bae", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "df7c1875", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "69b47af8", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "## Calculate neutron powder diffraction pattern (2nd iteration)" ] }, { "cell_type": "markdown", "id": "e33be893", "metadata": {}, "source": [ "### Modify job definition object" ] }, { "cell_type": "code", "execution_count": null, "id": "f43e3142", "metadata": {}, "outputs": [], "source": [ "job_info.pattern_type = \"NEUT_2THE\"\n", "job_info.print_description()" ] }, { "cell_type": "markdown", "id": "b272c615", "metadata": {}, "source": [ "### Plot calculated pattern" ] }, { "cell_type": "code", "execution_count": null, "id": "d7cc713a", "metadata": {}, "outputs": [], "source": [ "x_data, y_data_neutrons2 = diffraction_pattern_xy(space_group, unit_cell, atom_list, job_info)\n", "fig = figure(width=FIGURE_WIDTH, height=FIGURE_HEIGHT)\n", "fig.line(x_data, y_data_neutrons2, legend_label='Neutrons II', color='orange', line_width=2)\n", "show(fig)" ] }, { "cell_type": "markdown", "id": "1d3c134c", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "## Calculate X-rays powder diffraction pattern (2nd iteration)" ] }, { "cell_type": "markdown", "id": "bae6b31b", "metadata": {}, "source": [ "### Modify job definition object" ] }, { "cell_type": "code", "execution_count": null, "id": "5ddffc65", "metadata": {}, "outputs": [], "source": [ "job_info.pattern_type = \"XRAY_2THE\"\n", "job_info.print_description()" ] }, { "cell_type": "markdown", "id": "cee16bcb", "metadata": {}, "source": [ "### Plot calculated pattern" ] }, { "cell_type": "code", "execution_count": null, "id": "78bdcb17", "metadata": {}, "outputs": [], "source": [ "x_data, y_data_xrays2 = diffraction_pattern_xy(space_group, unit_cell, atom_list, job_info)\n", "fig = figure(width=FIGURE_WIDTH, height=FIGURE_HEIGHT)\n", "fig.line(x_data, y_data_xrays2, legend_label='Xrays II / 500', color='darkgreen', line_width=2)\n", "show(fig)" ] }, { "cell_type": "markdown", "id": "f29f98df", "metadata": {}, "source": [ "## Compare neutron and X-ray diffraction patterns (2nd iteration)" ] }, { "cell_type": "code", "execution_count": null, "id": "67364db3", "metadata": { "scrolled": true }, "outputs": [], "source": [ "fig = figure(width=FIGURE_WIDTH, height=FIGURE_HEIGHT)\n", "fig.line(x_data, y_data_neutrons2, legend_label='Neutrons II', color='orange', line_width=2)\n", "fig.line(x_data, y_data_xrays2/500, legend_label='Xrays II / 500', color='darkgreen', line_width=2)\n", "show(fig)" ] }, { "cell_type": "markdown", "id": "7dc8b39f", "metadata": {}, "source": [ "## Compare neutron and X-ray diffraction patterns (all iterations)" ] }, { "cell_type": "code", "execution_count": null, "id": "ec9a1630", "metadata": { "scrolled": true }, "outputs": [], "source": [ "fig = figure(width=FIGURE_WIDTH, height=FIGURE_HEIGHT)\n", "fig.line(x_data, y_data_neutrons, legend_label='Neutrons', color='orangered', line_width=2)\n", "fig.line(x_data, y_data_xrays/500, legend_label='Xrays / 500', color='olivedrab', line_width=2)\n", "fig.line(x_data, y_data_neutrons2, legend_label='Neutrons II', color='orange', line_width=2)\n", "fig.line(x_data, y_data_xrays2/500, legend_label='Xrays II / 500', color='darkgreen', line_width=2)\n", "show(fig)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "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.8.10" } }, "nbformat": 4, "nbformat_minor": 5 }