Tutorial 1: Introduction to the ListOfAtoms class

A hydrogen molecule

Say you want to do a calculation of a hydrogen molecule in a cubic box of size 4.0 Å with periodic boundary conditions. Here is what you have to do:

from somewhere import Calculator
from ASE import ListOfAtoms, Atom

a = 4.0
d = 0.71
h2 = ListOfAtoms([Atom('H', (0, 0, 0)),
                  Atom('H', (0, 0, d))],
                 cell=(a, a, a), periodic=True)

h2.SetCalculator(Calculator())

e2 = h2.GetPotentialEnergy()
print e2

Executing the above script would print out the total energy of the hydrogen molecule in eV.

The length and energy units used by default are Å and eV respectively. If other units are desired, this can be changed like this:

from ASE.Units import units
units.SetUnits('Bohr', 'Hartree')

The possible length units are: 'Ang', 'Bohr' and 'nm', and the possible energy units are: 'eV', 'Hartree', 'kJ/mol/Nav' and 'kcal/mol/Nav'.

The ListOfAtoms class

The class ListOfAtoms is a container for atom objects. It is a subclass of the python builtin list - so you can use all of the list methods. Here are some uses of some list methods (append, extend, insert, pop, reverse and sort):

from ASE import ListOfAtoms, Atom

a = 4.01
d = a / 2**0.5
slab = ListOfAtoms([Atom('Al', (0, 0, 0)),
                    Atom('Al', (d, 0, 0)),
                    Atom('Al', (0, d, 0)),
                    Atom('Al', (d, d, 0))],
                   cell=(2*d, 2*d, 10.0),
                   periodic=(True, True, False))
alkali = Atom('Na', (d / 2, d / 2, 2.1))
slab.append(alkali)
slab.pop()
slab.insert(0, alkali)
molecule = [Atom('H', (1.5*d, 1.5*d, 1.5)),
            Atom('H', (1.5*d, 1.5*d, 2.21))]
slab.extend(molecule)
slab.sort()
slab.reverse()

This will build up a 2x2 Al(100) one layer slab with a sodium atom and a hydrogen molecule adsorbed. The append followed by a pop does nothing - only present for demonstration purpose. The sort method will sort the atoms acording to atomic numbers, and after reversing the list, the atoms should be in this order: Al, Al, Al, Al, Na, H, H. If you have VMD installed, you can take a look at it:

>>> from ASE.Visualization.VMD import VMD
>>> VMD(slab.Repeat((2, 2, 1)))
Al-slab with stuff adsorbed

One layer (2x2) Al(100) slab with a sodium atom and a hydrogen molecule adsorbed (repeated four times).

ase2: ASE_Tutorial_1 (last edited 2010-10-20 09:11:15 by localhost)