Skip to content

A powder XRD simulation tool made for kicks, giggles, and to force me to learn the maths

Notifications You must be signed in to change notification settings

allevitan/pylattice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pylattice

What it Does

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.

Dependencies

Pylattice only depends on numpy. If you want to plot the calculated spectra, you will need matplotlib as well.

Installation

Simply put the "lattice" folder somewhere on your pythonpath.

Basic Use

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()

Defining a Crystal

  • 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

Calculating the Spectrum

  • 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.

About

A powder XRD simulation tool made for kicks, giggles, and to force me to learn the maths

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages