{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Creation of a new calibrant\n", "\n", "In this tutorial we will see how to create a new calibrant. For this example we will use one of the componant of mostpaintings: hydrocerussite.\n", "\n", "The cell parameter are definied in this document:\n", "http://rruff.geo.arizona.edu/AMS/AMC_text_files/11987_amc.txt\n", "\n", "The first step is to record the cell parameters and provide them to pyFAI to define the cell." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "pyFAI version 0.21.0-dev0\n" ] } ], "source": [ "import pyFAI\n", "print(\"pyFAI version\",pyFAI.version)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from pyFAI.calibrant import Cell\n", "hydroc_hex = Cell.hexagonal(5.24656, 23.7023)\n", "\n", "#This is an alternative representation, where extinction rules are already definied ... but that's cheating\n", "hydroc_rho = Cell.hexagonal(5.24656, 23.7023, lattice_type=\"R\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Chromium oxide has a crystal structure de Corrundom which is R-3m (space group 166). \n", "The selection rules are rather complicated and are available in:\n", "http://img.chem.ucl.ac.uk/sgp/large/166bz2.gif\n", "\n", "We will setup a function corresponding to the selection rules. It returns True if the reflection is active and False otherwise.\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def reflection_condition_166(h,k,l):\n", " \"\"\"from http://img.chem.ucl.ac.uk/sgp/large/166bz2.htm\"\"\"\n", " if h == 0 and k == 0:\n", " # 00l: 3n\n", " return l%3 == 0\n", " elif h == 0 and l == 0:\n", " # 0k0: k=3n\n", " return k%3 == 0\n", " elif k == 0 and l == 0:\n", " # h00: h=3n\n", " return h%3 == 0\n", " elif h == k:\n", " # hhl: l=3n\n", " return l%3 == 0\n", " elif l == 0:\n", " # hk0: h-k = 3n\n", " return (h-k)%3 == 0\n", " elif k == 0:\n", " # h0l: h-l = 3n\n", " return ((h - l)%3 == 0)\n", " elif h == 0:\n", " # 0kl: h+l = 3n\n", " return ((k + l)%3 == 0)\n", " else:\n", " # -h + k + l = 3n\n", " return (-h + k + l) % 3 == 0" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# Use the actual selection rule, not the short version:\n", "#cro.selection_rules.append(lambda h, k, l: ((-h + k + l) % 3 == 0))\n", "hydroc_hex.selection_rules.append(reflection_condition_166)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1.0266221843304677 (-5, 2, -4)\n", "1.041379200056494 (-5, 2, -1)\n", "1.0383768889418905 (-5, 2, 2)\n", "1.0180635197137227 (-5, 2, 5)\n", "1.0243550169740998 (-4, 0, -10)\n", "1.0769301354851748 (-4, 0, -7)\n", "1.1156006392090894 (-4, 0, -4)\n", "1.1346113609835977 (-4, 0, -1)\n", "1.1307314697456305 (-4, 0, 2)\n", "1.1046428683561866 (-4, 0, 5)\n", "1.0606335361782178 (-4, 0, 8)\n", "1.0048382352168421 (-4, 0, 11)\n", "1.0108862622799024 (-4, 1, -14)\n", "1.0878062403916176 (-4, 1, -11)\n", "1.159644632464954 (-4, 1, -8)\n", "1.2178844207065906 (-4, 1, -5)\n", "1.253118378087609 (-4, 1, -2)\n", "1.2584056108912545 (-4, 1, 1)\n", "1.2326168700716238 (-4, 1, 4)\n", "1.181041351041593 (-4, 1, 7)\n", "1.1126931506543154 (-4, 1, 10)\n", "1.0366630158144405 (-4, 1, 13)\n", "1.0092469779433046 (-4, 2, -15)\n", "1.092664697681165 (-4, 2, -12)\n", "1.1740842047275695 (-4, 2, -9)\n", "1.2448173722310034 (-4, 2, -6)\n", "1.2939303559673565 (-4, 2, -3)\n", "1.31164 (-4, 2, 0)\n", "1.0934060528214278 (-3, 0, -15)\n", "1.2018877636145413 (-3, 0, -12)\n", "1.3129229346319629 (-3, 0, -9)\n", "1.4141780482376238 (-3, 0, -6)\n", "1.4874675189454527 (-3, 0, -3)\n", "1.514551414159762 (-3, 0, 0)\n", "1.0093047350823812 (-3, 1, -19)\n", "1.1217224559690626 (-3, 1, -16)\n", "1.250109533018166 (-3, 1, -13)\n", "1.390676494928023 (-3, 1, -10)\n", "1.531610287507519 (-3, 1, -7)\n", "1.6494634269378436 (-3, 1, -4)\n", "1.7128498231506335 (-3, 1, -1)\n", "1.6995880549128863 (-3, 1, 2)\n", "1.6146506455916174 (-3, 1, 5)\n", "1.4857868793904678 (-3, 1, 8)\n", "1.342980080706968 (-3, 1, 11)\n", "1.2056528430004532 (-3, 1, 14)\n", "1.082434063677994 (-3, 1, 17)\n", "1.050740297907581 (-2, 0, -20)\n", "1.1883121496530844 (-2, 0, -17)\n", "1.3575224987307548 (-2, 0, -14)\n", "1.5633915700007044 (-2, 0, -11)\n", "1.802831645421812 (-2, 0, -8)\n", "2.0487100339481996 (-2, 0, -5)\n", "2.2312012784181787 (-2, 0, -2)\n", "2.261462939491261 (-2, 0, 1)\n", "2.1212670723564355 (-2, 0, 4)\n", "1.886546490429041 (-2, 0, 7)\n", "1.6401090792321418 (-2, 0, 10)\n", "1.4219518829625697 (-2, 0, 13)\n", "1.2408892402308387 (-2, 0, 16)\n", "1.0934794981533718 (-2, 0, 19)\n", "1.0367882138457822 (-2, 1, -21)\n", "1.1768503528666374 (-2, 1, -18)\n", "1.3535602541146567 (-2, 1, -15)\n", "1.5779182216667438 (-2, 1, -12)\n", "1.8585730984088402 (-2, 1, -9)\n", "2.18532939536233 (-2, 1, -6)\n", "2.489634744462007 (-2, 1, -3)\n", "2.62328 (-2, 1, 0)\n", "1.0483099442247654 (-1, 0, -22)\n", "1.2029724002981195 (-1, 0, -19)\n", "1.4084264950302066 (-1, 0, -16)\n", "1.6921038638926156 (-1, 0, -13)\n", "2.101480595815162 (-1, 0, -10)\n", "2.7150449974615096 (-1, 0, -7)\n", "3.605663290843624 (-1, 0, -4)\n", "4.4624025568363574 (-1, 0, -1)\n", "4.242534144712871 (-1, 0, 2)\n", "3.2802181584642836 (-1, 0, 5)\n", "2.4817784804616774 (-1, 0, 8)\n", "1.9469190372141116 (-1, 0, 11)\n", "1.5864672589095954 (-1, 0, 14)\n", "1.3329101904058698 (-1, 0, 17)\n", "1.1467492153761274 (-1, 0, 20)\n", "1.0050092747909034 (-1, 0, 23)\n", "1.1286809523809527 (0, 0, -21)\n", "1.3167944444444448 (0, 0, -18)\n", "1.580153333333334 (0, 0, -15)\n", "1.9751916666666673 (0, 0, -12)\n", "2.6335888888888896 (0, 0, -9)\n", "3.9503833333333347 (0, 0, -6)\n", "7.900766666666669 (0, 0, -3)\n" ] } ], "source": [ "for reflex in hydroc_hex.d_spacing(1).values():\n", " print(reflex[0], reflex[1])" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "length is the same: True\n", "Content is the same: True\n" ] } ], "source": [ "print(\"length is the same: \", len(hydroc_hex.d_spacing(1)) == len(hydroc_rho.d_spacing(1)))\n", "ds_hex=list(hydroc_hex.d_spacing(1).keys())\n", "ds_hex.sort()\n", "ds_rho=list(hydroc_rho.d_spacing(1).keys())\n", "ds_rho.sort()\n", "print(\"Content is the same:\", ds_hex == ds_rho)\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "hydroc_rho.save(\"hydrocerussite\", \"basic lead carbonate (R-3m)\", dmin=1, doi=\"https://doi.org/10.1107/S0108270102006844\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Conclusion\n", "This is an advanced tutorial, most user won't have to define their own calibrant. You can also contact the developers to get your own calibrant integrated into pyFAI which makes things easier for you and other users." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.9.1+" } }, "nbformat": 4, "nbformat_minor": 2 }