The Atom object#

ASE defines a python class called Atom to setup and handle atoms in electronic structure and molecular simulations. From a python script, atoms can be created like this:

>>> from ase import Atom
>>> a1 = Atom('Si', (0, 0, 0))
>>> a2 = Atom('H', (1.3, 0, 0), mass=2)
>>> a3 = Atom(14, position=(0, 0, 0))  # same as a1
class ase.atom.Atom(symbol='X', position=(0, 0, 0), tag=None, momentum=None, mass=None, magmom=None, charge=None, atoms=None, index=None)[source]#

Class for representing a single atom.

Parameters:
  • symbol (str or int) – Can be a chemical symbol (str) or an atomic number (int).

  • position (sequence of 3 floats) – Atomic position.

  • tag (int) – Special purpose tag.

  • momentum (sequence of 3 floats) – Momentum for atom.

  • mass (float) – Atomic mass in atomic units.

  • magmom (float or 3 floats) – Magnetic moment.

  • charge (float) – Atomic charge.

Examples

The first argument to the constructor of an Atom object is the chemical symbol, and the second argument is the position in Å units (see units). The position can be any numerical sequence of length three. The properties of an atom can also be set using keywords like it is done in the a, b, and c examples below.

>>> from ase import Atom
>>> a = Atom('O', charge=-2)
>>> b = Atom(8, charge=-2)
>>> c = Atom('H', (1, 2, 3), magmom=1)
>>> print(a.charge, a.position)
-2 [ 0.  0.  0.]
>>> c.x = 0.0
>>> c.position
array([ 0.,  2.,  3.])
>>> b.symbol
'O'
>>> c.tag = 42
>>> c.number
1
>>> c.symbol = 'Li'
>>> c.number
3

If the atom object belongs to an Atoms object, then assigning values to the atom attributes will change the corresponding arrays of the atoms object:

>>> from ase import Atoms
>>> OH = Atoms('OH')
>>> OH[0].charge = -1
>>> OH.get_initial_charges()
array([-1.,  0.])

Another example:

>>> from ase.build import bulk
>>> bulk = bulk('Ni', 'fcc', a=3.5)
>>> for atom in bulk:
...     if atom.symbol == 'Ni':
...         atom.magmom = 0.7  # set initial magnetic moment

The different properties of an atom can be obtained and changed via attributes (position, number, tag, momentum, mass, magmom, charge, x, y, z):

>>> from ase import Atom
>>> a.position = [1, 0, 0]
>>> a.position
[1, 0, 0]
>>> a.z = 2.5
>>> a.position
[1, 0, 2.5]
>>> a.magmom = 1.0
>>> bulk[0].magmom = 2.0

That last line will set the initial magnetic moment that some calculators use (similar to the set_initial_magnetic_moments() method).

Note

The position and momentum attributes refer to mutable objects, so in some cases, you may want to use a.position.copy() in order to avoid changing the position of a by accident.

Getting an Atom from an Atoms object#

Indexing an Atoms object returns an Atom object still remembering that it belongs to the collective Atoms:

>>> from ase.build import molecule
>>> atoms = molecule('CH4')
>>> atoms.get_positions()
array([[ 0.      ,  0.      ,  0.      ],
       [ 0.629118,  0.629118,  0.629118],
       [-0.629118, -0.629118,  0.629118],
       [ 0.629118, -0.629118, -0.629118],
       [-0.629118,  0.629118, -0.629118]])
>>> a = atoms[2]
>>> a
Atom('H', [-0.629118, -0.629118, 0.629118], index=2)

Modifying an Atom object will also change the atoms object:

>>> a.x = 0
>>> atoms.get_positions()
array([[ 0.      ,  0.      ,  0.      ],
       [ 0.629118,  0.629118,  0.629118],
       [ 0.      , -0.629118,  0.629118],
       [ 0.629118, -0.629118, -0.629118],
       [-0.629118,  0.629118, -0.629118]])

Building an Atoms object from Atom objects#

It is also possible to create an Atoms object from Atom objects:

>>> from ase.atoms import Atoms
>>> a1 = Atom('H', (0, 0, 0), mass=2)
>>> a2 = Atom('H', (0.74, 0, 0), mass=2)
>>> h2=Atoms([a1, a2])
>>> h2.get_center_of_mass()
array([0.37, 0.  , 0.  ])

See also

ase:

More information about how to use collections of atoms.

ase.calculators:

Information about how to calculate forces and energies of atoms.

Tips and tricks :

General tips for using ase.