Created
May 17, 2024 08:28
-
-
Save crystalfp/b613861dbe600e79b2d45bc24faef5e4 to your computer and use it in GitHub Desktop.
Example spg_standardize_cell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include "spglib.h" | |
static void sub_spg_standardize_cell(double lattice[3][3], double position[][3], | |
int types[], int const num_atom, | |
double const symprec, | |
int const to_primitive, | |
int const no_idealize) { | |
double lat[3][3], pos[4 * 4][3]; | |
int typ[4 * 4]; | |
for (int i = 0; i < 3; i++) { | |
lat[i][0] = lattice[i][0]; | |
lat[i][1] = lattice[i][1]; | |
lat[i][2] = lattice[i][2]; | |
} | |
for (int i = 0; i < num_atom; i++) { | |
pos[i][0] = position[i][0]; | |
pos[i][1] = position[i][1]; | |
pos[i][2] = position[i][2]; | |
typ[i] = types[i]; | |
} | |
/* lattice, position, and types are overwritten. */ | |
int num_primitive_atom = spg_standardize_cell( | |
lat, pos, typ, num_atom, to_primitive, no_idealize, symprec); | |
printf("VASP POSCAR format: "); | |
if (to_primitive == 0) { | |
printf("to_primitive=0 and "); | |
} else { | |
printf("to_primitive=1 and "); | |
} | |
if (no_idealize == 0) { | |
printf("no_idealize=0\n"); | |
} else { | |
printf("no_idealize=1\n"); | |
} | |
printf("1.0\n"); | |
for (int i = 0; i < 3; i++) { | |
printf("%f %f %f\n", lat[0][i], lat[1][i], lat[2][i]); | |
} | |
printf("%d\n", num_primitive_atom); | |
printf("Direct\n"); | |
for (int i = 0; i < num_primitive_atom; i++) { | |
printf("%f %f %f\n", pos[i][0], pos[i][1], pos[i][2]); | |
} | |
} | |
static void example_spg_standardize_cell_BCC(void) { | |
double lattice[3][3] = {{2.51, 0, 0}, {-1.255, 2.17372, 0},{4.09644e-16, 7.09525e-16, 6.69}}; | |
double position[][3] = { | |
{-2.46519e-32, 2.46519e-32, 0.5}, | |
{0.3333, 0.6667, 0}, | |
{0, 0, 0}, | |
{0.6667, 0.3333, 0.5}}; | |
int types[] = {5, 5, 7, 7}; | |
int num_atom = 4; | |
double symprec = 1e-5; | |
/* lattice, position, and types are overwritten. */ | |
printf("*** Example of spg_standardize_cell (BCC unitcell) ***:\n"); | |
printf("------------------------------------------------------\n"); | |
for (int j = 0; j < 2; j++) { | |
for (int k = 0; k < 2; k++) { | |
sub_spg_standardize_cell(lattice, position, types, num_atom, | |
symprec, j, k); | |
printf("------------------------------------------------------\n"); | |
} | |
} | |
} | |
int main(int argc, char* argv[]) { | |
printf("%d.%d.%d\n", spg_get_major_version(), spg_get_minor_version(), spg_get_micro_version()); | |
example_spg_standardize_cell_BCC(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment