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, ..
To run this example, you need to copy _spglib.so and spglib.py to a current directory or the directory where the $PYTHONPATH is set.
#!/usr/bin/evn python
import sys
from ase import *
import spglib as spg
import numpy as npy
def create_uniform_kpoints(mesh):
"""Create k-point vector from uniform mesh.
The k-points are able to be on the boundary.
"""
kpts = np.zeros((np.prod(mesh), 3), dtype=float)
num_kpts = 0
for i in range(mesh[0]):
k_a = 1.0/mesh[0] * i
k_a = k_a - 1 * (k_a > 0.5 + 0.5 / mesh[0])
for j in range(mesh[1]):
k_b = 1.0/mesh[1] * j
k_b = k_b - 1 * (k_b > 0.5 + 0.5 / mesh[1])
for k in range(mesh[2]):
k_c = 1.0/mesh[2] * k
k_c = k_c - 1 * (k_c > 0.5 + 0.5 / mesh[2])
kpts[num_kpts] = [k_a, k_b, k_c]
num_kpts += 1
return kpts
Si = 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)
SiO2 = 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 "Spacegroup of Si is ", spg.get_spacegroup(Si)
print ""
print "Spacegroup of SiO2 is ", spg.get_spacegroup(SiO2)
print ""
print "Symmetry operations of SiO2 unitcell is:"
print ""
symmetry = spg.get_symmetry(SiO2)
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])
kpoint = create_uniform_kpoints((3,3,3))
print kpoint.shape[0]
print kpoint
symmetry = spg.get_symmetry(Si)
print "Number of operations of Si is ", symmetry['rotation'].shape[0]
num_kpt = spg.get_ir_kpoint(kpoint, SiO2)
print "Number of point group of SiO2 is ", num_kpt
for i in range(num_kpt):
print kpoint[i]
print "Number of point group of Si is ", spg.get_ir_kpoint(kpoint, Si)
Import spglib:
import spglib
Call the methods with ASE Atoms object.
get_spacegroup(atoms, precision=1e-5)
atoms is the object of ASE Atoms class. precision is the float variable, which is used as tolerance in symmetry search. The unit is about fractional coordinates.
International space group symbol and the number are obtained as a string.
get_symmetry(Atoms, precition=1e-5)
atoms is the object of ASE Atoms class. precision is the float variable, which is used as tolerance in symmetry search. The unit is about fractional coordinates.
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.