[ase-users] Find space group
Atz Togo
atz.togo at gmail.com
Sat Jan 24 11:21:55 CET 2009
Dear ASE users,
I made the small code to find space group for ASE Atoms class. I send
this e-mail because I wonder if some developer may be interested in
space group or crysta symmetry search.
The following example code requires the spglib library
(http://spglib.sourceforge.net/) that I made. The usage of an example
code is like this.
% python example_ase.py
Fd -3 m (227)
The codes and makefile are written below, and are found in svn
repository of spglib, too.
---------python example (example_ase.py)--------------
#!/usr/bin/evn python
from ase import *
import _spglib as spg
bulk = Atoms(symbols='Si8',
cell=[(4,0,0),
(0,4,0),
(0,0,4)],
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)
spg.get_spacegroup(bulk.numbers.size, bulk.cell, bulk.positions,
array(bulk.numbers, dtype=int32), 1e-5)
------------------------------
--------c-wrapper-----------
#include <Python.h>
#include <stdio.h>
#include <numpy/arrayobject.h>
#include <spglib.h>
static PyObject * get_spacegroup(PyObject *self, PyObject *args);
static PyMethodDef functions[] = {
{"get_spacegroup", get_spacegroup, METH_VARARGS, "Space group finder"},
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC init_spglib(void)
{
PyObject* m = Py_InitModule3("_spglib", functions,
"C-extension for spglib\n\n...\n");
}
static PyObject *get_spacegroup(PyObject *self, PyObject *args)
{
int i, j;
int size;
double symprec;
char symbol[21];
PyArrayObject* lattice;
PyArrayObject* position;
PyArrayObject* atom_type;
if (!PyArg_ParseTuple(args, "iOOOd", &size, &lattice, &position,
&atom_type, &symprec))
return NULL;
double* lat = (double*)lattice->data;
double* pos = (double*)position->data;
int* typat = (int*)atom_type->data;
i = spg_get_international(symbol, lat, pos, typat, size, symprec);
printf("%s (%d)\n", symbol, i);
Py_RETURN_NONE;
}
--------------------------
-------makefile-----------
CC = gcc
PYINC = /usr/include/python2.5
NUMPYINC = /usr/lib/python2.5/site-packages/numpy/core/include
_spglib.so: example.c
$(CC) example.c -g -I$(PYINC) -I$(NUMPYINC) -I$(SPGLIBINC)
-L$(SPGLIB) -lsymspg -fpic -shared -o _spglib.so
clean:
rm -f _spglib.so core
-------------------------------
Best regards,
--
Atsushi Togo
Department of Materials Science and Engineering
Kyoto University
Yoshida-Honmachi, Sakyo-ku, Kyoto 606-8501, Japan
E-mail: atz.togo at gmail.com
E-mail: atz.togo at gmail.com
More information about the ase-users
mailing list