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: https://wiki.fysik.dtu.dk/ase/python.html. 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 [ ]:
print('hello')
Now we verify that our structure indeed has atoms in the right places
In [ ]:
Na_unitcell.positions
In [ ]:
Na_unitcell.get_chemical_symbols()
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
print(multiplier)
In [ ]:
from ase.build import make_supercell
Na_supercell = make_supercell(Na_unitcell, multiplier)
Na_supercell.positions
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 [ ]:
print(Na_supercell.numbers)
Na_supercell.numbers[0] = 3
Na_supercell.get_chemical_symbols()
Or we can remove an atom altogether to form a vacancy. We simply use the pop() method of Python lists.
In [ ]:
Na_supercell.pop(15)
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 ase.io 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 [ ]:
Na_supercell.edit()
To generate a surface slab supercell we can use ASE builder like so, and write it to a file
In [ ]:
from ase.build 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 [ ]:
slab.positions
In [ ]:
slab.cell
In [ ]:
slab.edit()
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
print(x)
To plot the results, you can use Matplotlib
In [ ]:
import matplotlib.pyplot as plt
plt.plot(x,y)
plt.show()
In [ ]: