# Using the spacegroup subpackage¶

The most evident usage of the spacegroup subpackage is to set up an initial unit of a bulk structure. For this you only need to supply the unique atoms and their scaled positions, space group and lattice parameters.

## Examples of setting up bulk structures¶

We start by showing some examples of how to set up some common or interesting bulk structures using ase.lattice.spacegroup.crystal(). This function takes a lot of arguments, of which the most important are:

symbols : string | sequence of strings
Either a string formula or sequence of element symbols. E.g. ‘NaCl’ and (‘Na’, ‘Cl’) are equivalent.
basis : list of scaled coordinates
Coordinates of the non-equivalent sites in units of the lattice vectors.
spacegroup : int | string | Spacegroup instance
Space group given either as its number in International Tables or as its Hermann-Mauguin (or international) symbol.
setting : 1 | 2
Space group setting.
cellpar : [a, b, c, alpha, beta, gamma]
Cell parameters with angles in degree. Is not used when cell is given.

### Aluminium (fcc)¶

from ase.lattice.spacegroup import crystal

a = 4.05
al = crystal('Al', [(0,0,0)], spacegroup=225, cellpar=[a, a, a, 90, 90, 90])


The spacegroup argument can also be entered with its Hermann-Mauguin symbol, e.g. spacegroup=225 is equivalent to spacegroup=’F m -3 m’.

### Iron (bcc)¶

from ase.lattice.spacegroup import crystal

a = 2.87
fe = crystal('Fe', [(0,0,0)], spacegroup=229, cellpar=[a, a, a, 90, 90, 90])


### Magnesium (hcp)¶

from ase.lattice.spacegroup import crystal

a = 3.21
c = 5.21
mg = crystal('Mg', [(1./3., 2./3., 3./4.)], spacegroup=194,
cellpar=[a, a, c, 90, 90, 120])


### Diamond¶

from ase.lattice.spacegroup import crystal

a = 3.57
diamond = crystal('C', [(0,0,0)], spacegroup=227, cellpar=[a, a, a, 90, 90, 90])


### Sodium chloride¶

from ase.lattice.spacegroup import crystal

a = 5.64
nacl = crystal(['Na', 'Cl'], [(0, 0, 0), (0.5, 0.5, 0.5)], spacegroup=225,
cellpar=[a, a, a, 90, 90, 90])


### Rutile¶

from ase.lattice.spacegroup import crystal

a = 4.6
c = 2.95
rutile =crystal(['Ti', 'O'], basis=[(0, 0, 0), (0.3, 0.3, 0.0)],
spacegroup=136, cellpar=[a, a, c, 90, 90, 90])


### CoSb3 skutterudite¶

Skutterudites are quite interesting structures with 32 atoms in the unit cell.

from ase.lattice.spacegroup import crystal

a = 9.04
skutterudite = crystal(('Co', 'Sb'),
basis=[(0.25, 0.25, 0.25), (0.0, 0.335, 0.158)],
spacegroup=204,
cellpar=[a, a, a, 90, 90, 90])


Often this structure is visualised with the Cobalt atoms on the corners. This can easily be accomplished with ASE using ase.utils.geometry.cut(). Below is the origo argument used to put the Cobalt atom on the corners and extend to include all corner and edge atoms, even those belonging to neighbouring unit cells.

import ase.io as io
from ase.lattice.spacegroup import crystal
import ase.utils.geometry as geometry

a = 9.04
skutterudite = crystal(('Co', 'Sb'),
basis=[(0.25, 0.25, 0.25), (0.0, 0.335, 0.158)],
spacegroup=204,
cellpar=[a, a, a, 90, 90, 90])

# Create a new atoms instance with Co at origo including all atoms on the
# surface of the unit cell
cosb3 = geometry.cut(skutterudite, origo=(0.25, 0.25, 0.25), extend=1.01)

# Define the atomic bonds to show
bondatoms = []
symbols = cosb3.get_chemical_symbols()
for i in range(len(cosb3)):
for j in range(i):
if (symbols[i] == symbols[j] == 'Co' and
cosb3.get_distance(i, j) < 4.53):
bondatoms.append((i, j))
elif (symbols[i] == symbols[j] == 'Sb' and
cosb3.get_distance(i, j) < 2.99):
bondatoms.append((i, j))

# Create nice-looking image using povray
io.write('spacegroup-cosb3.pov', cosb3,
transparent=False,
display=False,
run_povray=True,
camera_type='perspective',
canvas_width=320,
rotation='90y',
bondlinewidth=0.07,
bondatoms=bondatoms)


## The Spacegroup class¶

The ase.lattice.spacegroup.Spacegroup class is used internally by the ase.lattice.spacegroup.crystal() function, but might sometimes also be useful if you want to know e.g. the symmetry operations of a given space group. Instances of the ase.lattice.spacegroup.Spacegroup class are immutable objects holding space group information, such as symmetry operations.

Let us e.g. consider the fcc structure. To print information about the space group, do

>>> from ase.lattice.spacegroup import Spacegroup
>>> sg = Spacegroup(225)
>>> print(sg)
225   F m -3 m
setting 1
centrosymmetric 1
primitive vectors
0.0000000000  0.5000000000  0.5000000000
0.5000000000  0.0000000000  0.5000000000
0.5000000000  0.5000000000  0.0000000000
reciprocal vectors
-1   1   1
1  -1   1
1   1  -1
4 subtranslations
0.0000000000  0.0000000000  0.0000000000
0.0000000000  0.5000000000  0.5000000000
0.5000000000  0.0000000000  0.5000000000
0.5000000000  0.5000000000  0.0000000000
24 symmetry operations (rot+trans)
1  0  0     0  1  0     0  0  1    0.0000000000  0.0000000000  0.0000000000
-1  0  0     0 -1  0     0  0  1    0.0000000000  0.0000000000  0.0000000000
-1  0  0     0  1  0     0  0 -1    0.0000000000  0.0000000000  0.0000000000
1  0  0     0 -1  0     0  0 -1    0.0000000000  0.0000000000  0.0000000000
0  0  1     1  0  0     0  1  0    0.0000000000  0.0000000000  0.0000000000
0  0  1    -1  0  0     0 -1  0    0.0000000000  0.0000000000  0.0000000000
0  0 -1    -1  0  0     0  1  0    0.0000000000  0.0000000000  0.0000000000
0  0 -1     1  0  0     0 -1  0    0.0000000000  0.0000000000  0.0000000000
0  1  0     0  0  1     1  0  0    0.0000000000  0.0000000000  0.0000000000
0 -1  0     0  0  1    -1  0  0    0.0000000000  0.0000000000  0.0000000000
0  1  0     0  0 -1    -1  0  0    0.0000000000  0.0000000000  0.0000000000
0 -1  0     0  0 -1     1  0  0    0.0000000000  0.0000000000  0.0000000000
0  1  0     1  0  0     0  0 -1    0.0000000000  0.0000000000  0.0000000000
0 -1  0    -1  0  0     0  0 -1    0.0000000000  0.0000000000  0.0000000000
0  1  0    -1  0  0     0  0  1    0.0000000000  0.0000000000  0.0000000000
0 -1  0     1  0  0     0  0  1    0.0000000000  0.0000000000  0.0000000000
1  0  0     0  0  1     0 -1  0    0.0000000000  0.0000000000  0.0000000000
-1  0  0     0  0  1     0  1  0    0.0000000000  0.0000000000  0.0000000000
-1  0  0     0  0 -1     0 -1  0    0.0000000000  0.0000000000  0.0000000000
1  0  0     0  0 -1     0  1  0    0.0000000000  0.0000000000  0.0000000000
0  0  1     0  1  0    -1  0  0    0.0000000000  0.0000000000  0.0000000000
0  0  1     0 -1  0     1  0  0    0.0000000000  0.0000000000  0.0000000000
0  0 -1     0  1  0     1  0  0    0.0000000000  0.0000000000  0.0000000000
0  0 -1     0 -1  0    -1  0  0    0.0000000000  0.0000000000  0.0000000000


Or, if you want to figure out what sites in the unit cell are equivalent to (0, 0, 0.5), simply do

>>> sites,kinds = sg.equivalent_sites([(0, 0, 0.5)])
>>> sites
array([[ 0. ,  0. ,  0.5],
[ 0.5,  0. ,  0. ],
[ 0. ,  0.5,  0. ],
[ 0.5,  0.5,  0.5]])
>>> kinds
[0, 0, 0, 0]


where sites will be an array containing the scaled positions of the four symmetry-equivalent sites.