Making and manipulating structures with ASE

For preparing and manipulating crystal structures we will be using the ASE Python library. The documentation is rather accessible and even includes a refresher of Python basics. You can read it here, in preparation for the first lab: Here we will learn various functionalities of ASE, particularly how to make crystal structures, generate supercells, remove an atom to form a vacancy, and change an atom’s position.

ASE Atoms object holds all the information about our structure and has methods for manipulating it. Once we finish with the structurem, we will export it to a simple Python dictionary that is then used to generate the LAMMPS data and input files.

First we will create a crystal structure of Na metal. For this we will import the necessary spacegroup tools, so that we don't have to manually set up the cell and coordinates.

In [ ]:
from ase.spacegroup import crystal

In [ ]:
a = 4.5
Na_unitcell = crystal('Na', [(0,0,0)], spacegroup=229, cellpar=[a, a, a, 90, 90, 90])

In [ ]:

Now we verify that our structure indeed has atoms in the right places

In [ ]:

In [ ]:

We can make a supercell of this structure by rescaling the cell. Here we use NumPy's matrix capability.

In [ ]:
import numpy
multiplier = numpy.identity(3) * 2

In [ ]:
from import make_supercell
Na_supercell = make_supercell(Na_unitcell, multiplier)
We now have a structure with 16 atoms.

It is possible to change the position of the first atom directly like this:

In [ ]:
Na_supercell.positions[0] = (0.5, 0.5, 0.5)

Similarly, we can change the type of the first atom by reassigning the atomic number

In [ ]:
Na_supercell.numbers[0] = 3

Or we can remove an atom altogether to form a vacancy. We simply use the pop() method of Python lists.

In [ ]:

Now let's write the structure to a file so was can visualize what we've done to it. Crystallographic Information File (CIF) format is the most common for periodic structures today, and is understood by most structure visualizers and converters.

In [ ]:
from import write
write('sc.struct', Na_supercell)

We cans use VESTA to look at the result, or the ASE built-in viewer like so:

In [ ]:

To generate a surface slab supercell we can use ASE builder like so, and write it to a file

In [ ]:
from import bcc100
slab = bcc100('Na', size=(2,4,3), vacuum = 10.0)
write('slab.struct', slab)

You can look at the structure in VESTA and also get the atomic positions and cell information

In [ ]:

In [ ]:

In [ ]:

In the lab you will need to perform numerical sweeps of several parameters. You can use Numpy

In [ ]:
x = numpy.linspace(-5,5,10)
y = x*x

To plot the results, you can use Matplotlib

In [ ]:
import matplotlib.pyplot as plt

In [ ]: