Pylattice calculates powder x-ray diffraction spectra of crystalline materials. You define the crystal structure and the wavelength of light, and it does the rest. It's designed to easily mesh with python scripts and programs that need to calculate powder XRD spectra.
Pylattice only depends on numpy. If you want to plot the calculated spectra, you will need matplotlib as well.
Simply put the "lattice" folder somewhere on your pythonpath.
Pylattice has simple syntax and just tries to get the job done. Below is an example that calculates a powder XRD spectrum for NaCl:
from matplotlib import pyplot as p
from lattice import *
# Set up the crystal structure
lattice = FCC(5.63)
basis = Basis([('Cl',[0,0,0]),
('Na',[0.5,0.5,0.5])],
l_const=5.63)
crystal = lattice + basis
# Plot a simulated XRD with copper radiation
scattering_data = powder_XRD(crystal, 1.5405)
angles, values = spectrumify(scattering_data)
p.plot(angles, values)
# Add some more info to the plot
p.title(r'Simulated Powder XRD of NaCl, $\lambda = 1.5405$')
p.xlabel(r'$2\theta$')
p.ylabel(r'Scattering Intensity per Cubic Angstrom')
p.show()
- Define a lattice, either manually with Lattice or using one of the helper functions FCC,BCC,Cubic,or Hexagonal.
- Define a basis using Basis, providing a list of atoms and locations
- Define the crystal as the sum of the lattice and basis
-
powder_xrd(wavelength) returns a dictionary mapping angles to intensities. With the keyword argument "get_mults=True", it will also return a dictionary mapping angles to multiplicities
-
spectrumify turns the dictionary of scattering data into a fake scattering spectrum that can easily understood by humans.