#!/usr/bin/env python # coding: utf-8 # # Tutorial 3: PXRD module in PyXtal # Source code: https://github.com/qzhu2017/PyXtal # # Created by Qiang Zhu (2020/11/25) # # Last updated: 2022/08/11 # # An interactive webpage can be found at the following [link](https://vxrd.physics.unlv.edu) # # In[1]: # load the necessary libraries from pyxtal import pyxtal from pyxtal.XRD import Similarity from pkg_resources import resource_filename # In[2]: # specify the path of an experimental structure cif_nacl = resource_filename("pyxtal", "database/cifs/NaCl.cif") cif_aspirin = resource_filename("pyxtal", "database/cifs/aspirin.cif") # load the structure from pyxtal # if you load the atomic crystal #xtal1 = pyxtal() #xtal1.from_seed(seed = cif_nacl) # to load a molecular crystal, also needs to specify the molecule tag xtal1 = pyxtal(molecular=True) xtal1.from_seed(seed=cif_aspirin, molecules=['aspirin']) print(xtal1) # visualize the structure # xtal1.show() # In[3]: # compute the xrd project xrd = xtal1.get_XRD(thetas=[0, 35]) # you can easily access the diffraction information by hkl indices print(xrd) # In[4]: # plot XRD fig = xrd.plot_pxrd(fontsize=18, figsize=(16,6), show_hkl=False, xlim=[5,36], width=0.5, minimum_I=0.1) # In[5]: # plot XRD xrd.plotly_pxrd() # In[6]: # Now we randomly perturb the crystal xtal2 = xtal1.copy() xtal2.apply_perturbation(d_lat=0.02) xrd2 = xtal2.get_XRD(thetas=[0, 35]) # In[7]: # Compare the the PXRDs of two structures p1 = xrd.get_profile() p2 = xrd2.get_profile() s = Similarity(p1, p2, x_range=[0,35]) print(s) s.show()