static PyObject * get_pointgroup(PyObject *self, PyObject *args) { PyArrayObject* rotations; if (! PyArg_ParseTuple(args, "O", &rotations)) { return NULL; } int i, j; int trans_mat[3][3]; char symbol[6]; PyObject* array, * mat, * vec; SPGCONST int(*rot)[3][3] = (int(*)[3][3])PyArray_DATA(rotations); const int num_rot = PyArray_DIMS(rotations)[0]; const int ptg_num = spg_get_pointgroup(symbol, trans_mat, rot, num_rot); /* Transformation matrix */ mat = PyList_New(3); for (i = 0; i < 3; i++) { vec = PyList_New(3); for (j = 0; j < 3; j++) { PyList_SetItem(vec, j, PyLong_FromLong((long)trans_mat[i][j])); } PyList_SetItem(mat, i, vec); } array = PyList_New(3); PyList_SetItem(array, 0, PYUNICODE_FROMSTRING(symbol)); PyList_SetItem(array, 1, PyLong_FromLong((long) ptg_num)); PyList_SetItem(array, 2, mat); return array; }
static PyObject * get_pointgroup(PyObject *self, PyObject *args) { PyArrayObject* rotations; if (! PyArg_ParseTuple(args, "O", &rotations)) { return NULL; } long *rot_long = (long*)rotations->data; int i, j, k; int trans_mat[3][3]; char symbol[6]; PyObject* array, * mat, * vec; const int num_rot = rotations->dimensions[0]; int rot[num_rot][3][3]; for (i = 0; i < num_rot; i++) { for (j = 0; j < 3; j++) { for (k = 0; k < 3; k++) { rot[i][j][k] = (int) rot_long[ i*9 + j*3 + k ]; } } } const int ptg_num = spg_get_pointgroup(symbol, trans_mat, rot, num_rot); /* Transformation matrix */ mat = PyList_New(3); for (i = 0; i < 3; i++) { vec = PyList_New(3); for (j = 0; j < 3; j++) { PyList_SetItem(vec, j, PyInt_FromLong((long)trans_mat[i][j])); } PyList_SetItem(mat, i, vec); } array = PyList_New(3); PyList_SetItem(array, 0, PyString_FromString(symbol)); PyList_SetItem(array, 1, PyInt_FromLong((long) ptg_num)); PyList_SetItem(array, 2, mat); return array; }
static int show_spg_dataset(double lattice[3][3], const double origin_shift[3], double position[][3], const int num_atom, const int types[]) { SpglibDataset *dataset; char ptsymbol[6]; int pt_trans_mat[3][3]; int i, j; const char *wl = "abcdefghijklmnopqrstuvwxyz"; for ( i = 0; i < num_atom; i++ ) { for ( j = 0; j < 3; j++ ) { position[i][j] += origin_shift[j]; } } dataset = spg_get_dataset(lattice, position, types, num_atom, 1e-5); if (dataset == NULL) { return 1; } printf("International: %s (%d)\n", dataset->international_symbol, dataset->spacegroup_number ); printf("Hall symbol: %s\n", dataset->hall_symbol ); if (spg_get_pointgroup(ptsymbol, pt_trans_mat, dataset->rotations, dataset->n_operations)) { printf("Point group: %s\n", ptsymbol); printf("Transformation matrix:\n"); for ( i = 0; i < 3; i++ ) { printf("%f %f %f\n", dataset->transformation_matrix[i][0], dataset->transformation_matrix[i][1], dataset->transformation_matrix[i][2]); } printf("Wyckoff letters:\n"); for ( i = 0; i < dataset->n_atoms; i++ ) { printf("%c ", wl[dataset->wyckoffs[i]]); } printf("\n"); printf("Equivalent atoms:\n"); for (i = 0; i < dataset->n_atoms; i++) { printf("%d ", dataset->equivalent_atoms[i]); } printf("\n"); for (i = 0; i < dataset->n_operations; i++) { printf("--- %d ---\n", i + 1); for (j = 0; j < 3; j++) { printf("%2d %2d %2d\n", dataset->rotations[i][j][0], dataset->rotations[i][j][1], dataset->rotations[i][j][2]); } printf("%f %f %f\n", dataset->translations[i][0], dataset->translations[i][1], dataset->translations[i][2]); } spg_free_dataset(dataset); return 0; } else { spg_free_dataset(dataset); return 1; } }