This is document for Pyspglib for ASE (Atomic Simulation Environment). Pyspglib is the python module to use spglib library.
The C sources of spglib and interface for the python C/API are compiled. The development environment for python and gcc are required before starting to build.
Go to the python/ase directory
Type the command:
% python setup.py install --home=<my-directory>
The <my-directory> is possibly current directory, ..
Import spglib:
from pyspglib import spglib
Call the methods with ASE Atoms object.
The tolerance is given in Cartesian coordinates.
spacegroup = get_spacegroup(atoms, symprec=1e-5)
atoms is the object of ASE Atoms class. symprec is the float variable, which is used as tolerance in symmetry search.
International space group symbol and the number are obtained as a string.
symmetry = get_symmetry(atoms, symprec=1e-5)
atoms is the object of ASE Atoms class. symprec is the float variable, which is used as tolerance in symmetry search.
Symmetry operations are obtained as a dictionary. The key rotation contains a numpy array of integer, which is “number of symmetry operations” x “3x3 matrices”. The key translation contains a numpy array of float, which is “number of symmetry operations” x “vectors”. The orders of the rotation matrices and the translation vectors correspond with each other, e.g. , the second symmetry operation is organized by the second rotation matrix and second translation vector in the respective arrays. The operations are applied for the fractional coordinates (not for Cartesian coordinates).
The rotation matrix and translation vector are used as follows:
new_vector[3x1] = rotation[3x3] * vector[3x1] + translation[3x1]
The three values in the vector are given for the a, b, and c axes, respectively.
lattice, scaled_positions, numbers = refine_cell(atoms, symprec=1e-5)
atoms is the object of ASE Atoms class. symprec is the float variable, which is used as tolerance in symmetry search.
Bravais lattice (3x3 numpy array), atomic scaled positions (a numpy array of [number_of_atoms,3]), and atomic numbers (a 1D numpy array) that are symmetrized following space group type are returned.
lattice, scaled_positions, numbers = find_primitive(atoms, symprec=1e-5)
atoms is the object of ASE Atoms class. symprec is the float variable, which is used as tolerance in symmetry search.
When a primitive cell is found, lattice parameters (3x3 numpy array), scaled positions (a numpy array of [number_of_atoms,3]), and atomic numbers (a 1D numpy array) is returned. When no primitive cell is found, (None, None, None) is returned.
mapping, grid = get_ir_reciprocal_mesh( mesh, atoms, is_shift=[0,0,0] )
Irreducible k-points are obtained from a sampling mesh of k-points. mesh is given by three integers by array and specifies mesh numbers along reciprocal primitive axis. atoms is an Atoms object of ASE. is_shift is given by the three integers by array. When is_shift is set for each reciprocal primitive axis, the mesh is shifted along the axis in half of adjacent mesh points irrespective of the mesh numbers. When the value is not 0, is_shift is set.
mapping and grid are returned. grid gives the mesh points in fractional coordinates in reciprocal space. mapping gives mapping to the irreducible k-point indices that are obtained by
np.unique( mapping )
Here np is the imported numpy module. The grid point is accessed by grid[ index ].
For example, the irreducible k-points in fractional coordinates are obtained by
ir_grid = []
mapping, grid = get_ir_reciprocal_mesh( [ 8, 8, 8 ], atoms, [ 1, 1, 1 ] )
for i in np.unique( mapping ):
ir_grid.append( grid[ i ] )
#!/usr/bin/evn python
import sys
from ase import *
from pyspglib import spglib
import numpy as np
silicon = Atoms( symbols='Si8',
cell=[(4,0,0),
(0,4,0),
(0,0,4)],
scaled_positions=[(0, 0, 0),
(0, 0.5, 0.5),
(0.5, 0, 0.5),
(0.5, 0.5, 0),
(0.25, 0.25, 0.25),
(0.25, 0.75, 0.75),
(0.75, 0.25, 0.75),
(0.75, 0.75, 0.25)],
pbc=True)
silicon_prim = Atoms( symbols='Si2',
cell=[(0,2,2),
(2,0,2),
(2,2,0)],
scaled_positions=[(0, 0, 0),
(0.25, 0.25, 0.25)],
pbc=True)
rutile = Atoms( symbols='Si2O4',
cell=[ (4,0,0),
(0,4,0),
(0,0,3) ],
scaled_positions=[(0, 0, 0),
(0.5, 0.5, 0.5),
(0.3, 0.3, 0.0),
(0.7, 0.7, 0.0),
(0.2, 0.8, 0.5),
(0.8, 0.2, 0.5)],
pbc=True )
# For VASP case
# import ase.io.vasp as vasp
# bulk = vasp.read_vasp(sys.argv[1])
print "[get_spacegroup]"
print " Spacegroup of Silicon is ", spglib.get_spacegroup(silicon)
print ""
print "[get_spacegroup]"
print " Spacegroup of Rutile is ", spglib.get_spacegroup(rutile)
print ""
print "[get_symmetry]"
print " Symmetry operations of Rutile unitcell are:"
print ""
symmetry = spglib.get_symmetry(rutile)
for i in range(symmetry['rotation'].shape[0]):
print " --------------- %4d ---------------" % (i+1)
rot = symmetry['rotation'][i]
trans = symmetry['translation'][i]
print " rotation:"
for x in rot:
print " [%2d %2d %2d]" % (x[0], x[1], x[2])
print " translation:"
print " (%8.5f %8.5f %8.5f)" % (trans[0], trans[1], trans[2])
print ""
symmetry = spglib.get_symmetry(silicon)
print "[get_symmetry]"
print " Number of symmetry operations of silicon convensional"
print " unit cell is ", len( symmetry['rotation'] ), "(192)."
print ""
mapping, grid = spglib.get_ir_reciprocal_mesh( [ 11, 11, 11 ],
silicon_prim,
is_shift=[ 0, 0, 0 ] )
num_ir_kpt = len( np.unique( mapping ) )
print "[get_ir_reciprocal_mesh]"
print " Number of irreducible k-points of primitive silicon with"
print " 11x11x11 Monkhorst-Pack mesh is ", num_ir_kpt, "(56)."
print ""
mapping, grid = spglib.get_ir_reciprocal_mesh( [ 8, 8, 8 ],
rutile,
is_shift=[ 1, 1, 1 ] )
num_ir_kpt = len( np.unique( mapping ) )
print "[get_ir_reciprocal_mesh]"
print " Number of irreducible k-points of Rutile with"
print " 8x8x8 Monkhorst-Pack mesh is ", num_ir_kpt, "(40)."
print ""
mesh = np.array([8,8,8])
kpoints = []
for i in range(mesh[0]):
for j in range(mesh[1]):
for k in range(mesh[2]):
kpoints.append([float(i)/mesh[0],
float(j)/mesh[1],
float(k)/mesh[2]])
kpoints = np.array(kpoints) + 0.5/mesh
kpoints = kpoints - 1 * ( kpoints > 0.5 )
mapping = spglib.get_ir_kpoints( kpoints, rutile )
num_ir_kpt = len( np.unique( mapping ) )
print "[get_ir_kpoints]"
print " Number of irreducible k-points of Rutile with"
print " 8x8x8 Monkhorst-Pack mesh is ", num_ir_kpt, "(40)."
print ""