Skip to content

ASE (Atomic Simulation Environment)

ASE is a Python package we use for manipulating atomic structures. Documentation can be found here. This page provides a basic review for using ASE and ASE GUI.

Reading/Writing Files

Read files in Python with:

from ase.io import read

structure = read('atoms_file.cif')  # creates atoms object named 'structure'

Write new files with:

structure.write('new_file.traj')
# or alternatively:
from ase.io import write

write('new_file.traj', structure)

Adding or Deleting Atoms/Molecules/Slabs

You can combine two atoms objects using the + operator:

combined_atoms = atoms1 + atoms2
Note: combined_atoms will have the unit cell shape of atoms1, so order of addition matters!

For example, you can add a hydrogen atom using:

from ase import Atom

h_atom = Atom('H', (1, 1, 1))  # Creates an H atom at the (1, 1, 1) position
structure_with_hydrogen = structure + h_atom

You can create a molecule using:

from ase.build import molecule

ch3oh = molecule('CH3OH')
Note: Only some simple molecules work with molecule(). See the documentation for the full list.

You can build a metal surface slab using:

from ase.build import surface

s1 = surface('Au', (2, 1, 1), 9)  # makes a gold surface along the [2 1 1] plane with 9 layers
s1.center(vacuum=10, axis=2)  # centers the slab in the unit cell with 10 Å of vacuum along the z-axis

Moving/Rotating Atoms

Move a set of atoms using:

atoms.translate([x, y, z])  # where x, y, z are distances in Angstroms

Rotate a set of atoms using:

atoms.rotate(90, 'z')  # rotates atoms 90 degrees around z-axis
atoms.rotate(90, (0, 0, 1))  # rotates atoms 90 degrees around (0, 0, 1) vector
atoms.rotate('x', 'y')  # rotates the x-axis into the y-axis
atoms.rotate((1, 0, 0), (0, 1, 0))  # rotates the (1, 0, 0) axis into the (0, 1, 0) axis

Neighbors

Obtain the indices of the neighbors of a particular atom using:

from ase.neighborlist import NeighborList, natural_cutoffs

nl = NeighborList(natural_cutoffs(atoms), self_interaction=False, bothways=True)
nl.update(atoms)  # rerun this line anytime atoms in structure move
neighbors = nl.get_neighbors(atom_index)[0]  # list of neighbor indices around the atom at atom_index

Constraints

Constrain the positions of atoms using:

from ase.constraints import FixAtoms
index_list = [1, 2, 3, 99]  # list of atom indices you want to constrain
c = FixAtoms(indices=index_list)
atoms.set_constraint(c)
This will prevent the atoms at the specified indices from moving in any simulation.

Constrain bond lengths between pairs of atoms using:

from ase.constraints import FixBondLengths
c = FixBondLengths([[0, 1], [0, 2]])
atoms.set_constraint(c)
This will prevent the distance between atom 0 and atom 1, as well as the distance between atom 0 and atom 2, from changing.

ASE GUI

ASE GUI is used to visualize and manipulate atoms. It can even be used to visualize atoms on an HPC, but this is slow.

To use ASE GUI, navigate to the file you want to view on the command line, then type:

ase gui filename.cif

Useful Commands

  • Two-finger click and drag (or mouse drag): rotate the atoms object
  • Ctrl + B: toggle between bond view and atom view (bond view is more useful)
  • Ctrl + W: wrap atoms to the cell
  • Ctrl + M: move selected atoms using arrow keys (viewing direction affects arrow key behavior)
  • Ctrl + R: rotate selected atoms using arrow keys (viewing direction affects arrow key behavior)
  • R: open the tab to repeat unit cell
  • Click an atom: display atom properties

ASE Converter

You can convert between any supported file formats using:

ase convert structure.xyz structure.cif