static int test_spg_get_error_message(void) { double lattice[3][3] = {{4, 0, 0}, {0, 4, 0}, {0, 0, 4}}; double position[][3] = { {0, 0, 0}, {0.5, 0.5, 0.5}, {0.5, 0.5, 0.5} }; int types[] = {1, 1, 1}; int num_atom = 3, num_primitive_atom; double symprec = 1e-5; SpglibError error; /* lattice, position, and types are overwirtten. */ printf("*** Example of spg_get_error_message ***:\n"); num_primitive_atom = spg_find_primitive(lattice, position, types, num_atom, symprec); if (num_primitive_atom == 0) { printf("Primitive cell was not found.\n"); error = spg_get_error_code(); printf("%s\n", spg_get_error_message(error)); if (error == SPGLIB_SUCCESS) { return 1; } else { return 0; } } else { return 1; } }
static int test_spg_find_primitive_corundum(void) { double lattice[3][3] = {{4.8076344022756095, -2.4038172011378047, 0}, {0, 4.1635335244786962, 0}, {0, 0, 13.1172699198127543}}; double position[][3] = { {0.0000000000000000, 0.0000000000000000, 0.3521850942289043}, {0.6666666666666643, 0.3333333333333357, 0.6855184275622400}, {0.3333333333333357, 0.6666666666666643, 0.0188517608955686}, {0.0000000000000000, 0.0000000000000000, 0.6478149057711028}, {0.6666666666666643, 0.3333333333333357, 0.9811482391044314}, {0.3333333333333357, 0.6666666666666643, 0.3144815724377600}, {0.0000000000000000, 0.0000000000000000, 0.1478149057710957}, {0.6666666666666643, 0.3333333333333357, 0.4811482391044314}, {0.3333333333333357, 0.6666666666666643, 0.8144815724377600}, {0.0000000000000000, 0.0000000000000000, 0.8521850942288972}, {0.6666666666666643, 0.3333333333333357, 0.1855184275622400}, {0.3333333333333357, 0.6666666666666643, 0.5188517608955686}, {0.3061673906454899, 0.0000000000000000, 0.2500000000000000}, {0.9728340573121541, 0.3333333333333357, 0.5833333333333357}, {0.6395007239788255, 0.6666666666666643, 0.9166666666666643}, {0.6938326093545102, 0.0000000000000000, 0.7500000000000000}, {0.3604992760211744, 0.3333333333333357, 0.0833333333333357}, {0.0271659426878458, 0.6666666666666643, 0.4166666666666643}, {0.0000000000000000, 0.3061673906454899, 0.2500000000000000}, {0.6666666666666643, 0.6395007239788255, 0.5833333333333357}, {0.3333333333333357, 0.9728340573121541, 0.9166666666666643}, {0.0000000000000000, 0.6938326093545102, 0.7500000000000000}, {0.6666666666666643, 0.0271659426878458, 0.0833333333333357}, {0.3333333333333357, 0.3604992760211744, 0.4166666666666643}, {0.6938326093545102, 0.6938326093545102, 0.2500000000000000}, {0.3604992760211744, 0.0271659426878458, 0.5833333333333357}, {0.0271659426878458, 0.3604992760211744, 0.9166666666666643}, {0.3061673906454899, 0.3061673906454899, 0.7500000000000000}, {0.9728340573121541, 0.6395007239788255, 0.0833333333333357}, {0.6395007239788255, 0.9728340573121541, 0.4166666666666643}, }; int types[30]; int i, num_atom = 30, num_primitive_atom; double symprec = 1e-5; for (i = 0; i < 12; i++) { types[i] = 1; } for (i = 12; i < 30; i++) { types[i] = 2; } /* lattice, position, and types are overwirtten. */ printf("*** spg_find_primitive (Corundum) ***:\n"); num_primitive_atom = spg_find_primitive(lattice, position, types, num_atom, symprec); if (num_primitive_atom == 0) { printf("Primitive cell was not found.\n"); return 1; } else { show_cell(lattice, position, types, num_primitive_atom); return 0; } }
static PyObject * get_primitive(PyObject *self, PyObject *args) { int num_atom, num_atom_prim; double symprec; PyArrayObject* lattice_vectors; PyArrayObject* atomic_positions; PyArrayObject* atom_types; PyObject *array; double *p_lattice; double *p_positions; double lattice[3][3]; double (*positions)[3]; int *types_int; int *types; if (!PyArg_ParseTuple(args, "OOOd", &lattice_vectors, &atomic_positions, &atom_types, &symprec)) { return NULL; } p_lattice = (double(*))lattice_vectors->data; p_positions = (double(*))atomic_positions->data; types_int = (int*)atom_types->data; num_atom = atom_types->dimensions[0]; positions = (double(*)[3]) malloc(sizeof(double[3]) * num_atom); types = (int*) malloc(sizeof(int) * num_atom); set_spglib_cell(lattice, positions, types, num_atom, p_lattice, p_positions, types_int); num_atom_prim = spg_find_primitive(lattice, positions, types, num_atom, symprec); array = set_cell(num_atom_prim, lattice, positions, types); free(types); free(positions); return array; }
static int test_spg_find_primitive_BCC(void) { double lattice[3][3] = {{4, 0, 0}, {0, 4, 0}, {0, 0, 4}}; double position[][3] = { {0, 0, 0}, {0.5, 0.5, 0.5} }; int types[] = {1, 1}; int num_atom = 2, num_primitive_atom; double symprec = 1e-5; /* lattice, position, and types are overwirtten. */ printf("*** spg_find_primitive (BCC unitcell --> primitive) ***:\n"); num_primitive_atom = spg_find_primitive(lattice, position, types, num_atom, symprec); if (num_primitive_atom == 0) { printf("Primitive cell was not found.\n"); return 1; } else { show_cell(lattice, position, types, num_primitive_atom); return 0; } }