Creation of a new calibrant

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.

The cell parameter are definied in this document: http://rruff.geo.arizona.edu/AMS/AMC_text_files/11987_amc.txt

The first step is to record the cell parameters and provide them to pyFAI to define the cell.

[1]:
import pyFAI
print("pyFAI version",pyFAI.version)
pyFAI version 2023.9.0-dev0
[2]:
from pyFAI.calibrant import Cell
hydroc_hex = Cell.hexagonal(5.24656, 23.7023)

#This is an alternative representation, where extinction rules are already definied ... but that's cheating
hydroc_rho = Cell.hexagonal(5.24656, 23.7023, lattice_type="R")

Chromium oxide has a crystal structure de Corrundom which is R-3m (space group 166). The selection rules are rather complicated and are available in: http://img.chem.ucl.ac.uk/sgp/large/166bz2.gif

We will setup a function corresponding to the selection rules. It returns True if the reflection is active and False otherwise.

[3]:
def reflection_condition_166(h,k,l):
    """from http://img.chem.ucl.ac.uk/sgp/large/166bz2.htm"""
    if h == 0 and k == 0:
        # 00l: 3n
        return l%3 == 0
    elif h == 0 and l == 0:
        # 0k0: k=3n
        return k%3 == 0
    elif k == 0 and l == 0:
        # h00: h=3n
        return h%3 == 0
    elif h == k:
        # hhl: l=3n
        return l%3 == 0
    elif l == 0:
        # hk0: h-k = 3n
        return (h-k)%3 == 0
    elif k == 0:
        # h0l: h-l = 3n
        return ((h - l)%3 == 0)
    elif h == 0:
        # 0kl: h+l = 3n
        return ((k + l)%3 == 0)
    else:
        # -h + k + l = 3n
        return (-h + k + l) % 3 == 0
[4]:
# Use the actual selection rule, not the short version:
#cro.selection_rules.append(lambda h, k, l: ((-h + k + l) % 3 == 0))
hydroc_hex.selection_rules.append(reflection_condition_166)
[5]:
for reflex in hydroc_hex.d_spacing(1).values():
    print(reflex[0], reflex[1])
1.0266221843304677 (-5, 2, -4)
1.041379200056494 (-5, 2, -1)
1.0383768889418905 (-5, 2, 2)
1.0180635197137227 (-5, 2, 5)
1.0243550169740998 (-4, 0, -10)
1.0769301354851748 (-4, 0, -7)
1.1156006392090894 (-4, 0, -4)
1.1346113609835977 (-4, 0, -1)
1.1307314697456305 (-4, 0, 2)
1.1046428683561866 (-4, 0, 5)
1.0606335361782178 (-4, 0, 8)
1.0048382352168421 (-4, 0, 11)
1.0108862622799024 (-4, 1, -14)
1.0878062403916176 (-4, 1, -11)
1.159644632464954 (-4, 1, -8)
1.2178844207065906 (-4, 1, -5)
1.253118378087609 (-4, 1, -2)
1.2584056108912545 (-4, 1, 1)
1.2326168700716238 (-4, 1, 4)
1.181041351041593 (-4, 1, 7)
1.1126931506543154 (-4, 1, 10)
1.0366630158144405 (-4, 1, 13)
1.0092469779433046 (-4, 2, -15)
1.092664697681165 (-4, 2, -12)
1.1740842047275695 (-4, 2, -9)
1.2448173722310034 (-4, 2, -6)
1.2939303559673565 (-4, 2, -3)
1.31164 (-4, 2, 0)
1.0934060528214278 (-3, 0, -15)
1.2018877636145413 (-3, 0, -12)
1.3129229346319629 (-3, 0, -9)
1.4141780482376238 (-3, 0, -6)
1.4874675189454527 (-3, 0, -3)
1.514551414159762 (-3, 0, 0)
1.0093047350823812 (-3, 1, -19)
1.1217224559690626 (-3, 1, -16)
1.250109533018166 (-3, 1, -13)
1.390676494928023 (-3, 1, -10)
1.531610287507519 (-3, 1, -7)
1.6494634269378436 (-3, 1, -4)
1.7128498231506335 (-3, 1, -1)
1.6995880549128863 (-3, 1, 2)
1.6146506455916174 (-3, 1, 5)
1.4857868793904678 (-3, 1, 8)
1.342980080706968 (-3, 1, 11)
1.2056528430004532 (-3, 1, 14)
1.082434063677994 (-3, 1, 17)
1.050740297907581 (-2, 0, -20)
1.1883121496530844 (-2, 0, -17)
1.3575224987307548 (-2, 0, -14)
1.5633915700007044 (-2, 0, -11)
1.802831645421812 (-2, 0, -8)
2.0487100339481996 (-2, 0, -5)
2.2312012784181787 (-2, 0, -2)
2.261462939491261 (-2, 0, 1)
2.1212670723564355 (-2, 0, 4)
1.886546490429041 (-2, 0, 7)
1.6401090792321418 (-2, 0, 10)
1.4219518829625697 (-2, 0, 13)
1.2408892402308387 (-2, 0, 16)
1.0934794981533718 (-2, 0, 19)
1.0367882138457822 (-2, 1, -21)
1.1768503528666374 (-2, 1, -18)
1.3535602541146567 (-2, 1, -15)
1.5779182216667438 (-2, 1, -12)
1.8585730984088402 (-2, 1, -9)
2.18532939536233 (-2, 1, -6)
2.489634744462007 (-2, 1, -3)
2.62328 (-2, 1, 0)
1.0483099442247654 (-1, 0, -22)
1.2029724002981195 (-1, 0, -19)
1.4084264950302066 (-1, 0, -16)
1.6921038638926156 (-1, 0, -13)
2.101480595815162 (-1, 0, -10)
2.7150449974615096 (-1, 0, -7)
3.605663290843624 (-1, 0, -4)
4.4624025568363574 (-1, 0, -1)
4.242534144712871 (-1, 0, 2)
3.2802181584642836 (-1, 0, 5)
2.4817784804616774 (-1, 0, 8)
1.9469190372141116 (-1, 0, 11)
1.5864672589095954 (-1, 0, 14)
1.3329101904058698 (-1, 0, 17)
1.1467492153761274 (-1, 0, 20)
1.0050092747909034 (-1, 0, 23)
1.1286809523809527 (0, 0, -21)
1.3167944444444448 (0, 0, -18)
1.580153333333334 (0, 0, -15)
1.9751916666666673 (0, 0, -12)
2.6335888888888896 (0, 0, -9)
3.9503833333333347 (0, 0, -6)
7.900766666666669 (0, 0, -3)
[6]:
print("length is the same: ", len(hydroc_hex.d_spacing(1)) == len(hydroc_rho.d_spacing(1)))
ds_hex=list(hydroc_hex.d_spacing(1).keys())
ds_hex.sort()
ds_rho=list(hydroc_rho.d_spacing(1).keys())
ds_rho.sort()
print("Content is the same:", ds_hex == ds_rho)

length is the same:  True
Content is the same: True
[7]:
hydroc_rho.save("hydrocerussite", "basic lead carbonate (R-3m)", dmin=1, doi="https://doi.org/10.1107/S0108270102006844")

Conclusion

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.