From c7de2716036def87a7d9cf133d1abda3b7a27627 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Tue, 17 Oct 2023 18:26:32 +0900 Subject: [PATCH 1/2] Minor simplification of trim_cell --- src/cell.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/cell.c b/src/cell.c index e76d4ae14..d5f2dab39 100644 --- a/src/cell.c +++ b/src/cell.c @@ -54,15 +54,15 @@ static void set_positions_and_tensors(Cell *trimmed_cell, const int *mapping_table, const int *overlap_table); static VecDBL *translate_atoms_in_trimmed_lattice(const Cell *cell, - const double prim_lat[3][3]); + const int tmat_p_i[3][3]); static int *get_overlap_table(const VecDBL *position, const int cell_size, const int *cell_types, const Cell *trimmed_cell, const double symprec); // @brief Allocate Cell. NULL is returned if failed // @param size number of atoms -// @param tensor_rank rank of site tensors for magnetic symmetry. Set -1 if not -// used. +// @param tensor_rank rank of site tensors for magnetic symmetry. Set -1 if +// not used. Cell *cel_alloc_cell(const int size, const SiteTensorType tensor_rank) { Cell *cell; @@ -131,7 +131,8 @@ void cel_free_cell(Cell *cell) { cell->types = NULL; } if ((cell->tensor_rank != NOSPIN) && (cell->tensors != NULL)) { - // When cell->tensor_rank==NOSPIN, cell->tensors is already NULL. + // When cell->tensor_rank==NOSPIN, cell->tensors is already + // NULL. free(cell->tensors); cell->tensors = NULL; } @@ -378,8 +379,8 @@ static Cell *trim_cell(int *mapping_table, const double trimmed_lattice[3][3], goto err; } - if ((position = translate_atoms_in_trimmed_lattice( - cell, trimmed_lattice)) == NULL) { + if ((position = translate_atoms_in_trimmed_lattice(cell, tmp_mat_int)) == + NULL) { warning_print("spglib: translate_atoms_in_trimmed_lattice failed.\n"); warning_print(" (line %d, %s).\n", __LINE__, __FILE__); cel_free_cell(trimmed_cell); @@ -502,10 +503,9 @@ static void set_positions_and_tensors(Cell *trimmed_cell, } /* Return NULL if failed */ -static VecDBL *translate_atoms_in_trimmed_lattice( - const Cell *cell, const double trimmed_lattice[3][3]) { +static VecDBL *translate_atoms_in_trimmed_lattice(const Cell *cell, + const int tmat_p_i[3][3]) { int i, j; - double tmp_matrix[3][3], axis_inv[3][3]; VecDBL *position; position = NULL; @@ -514,13 +514,10 @@ static VecDBL *translate_atoms_in_trimmed_lattice( return NULL; } - mat_inverse_matrix_d3(tmp_matrix, trimmed_lattice, 0); - mat_multiply_matrix_d3(axis_inv, tmp_matrix, cell->lattice); - /* Send atoms into the trimmed cell */ for (i = 0; i < cell->size; i++) { - mat_multiply_matrix_vector_d3(position->vec[i], axis_inv, - cell->position[i]); + mat_multiply_matrix_vector_id3(position->vec[i], tmat_p_i, + cell->position[i]); for (j = 0; j < 3; j++) { if (j != cell->aperiodic_axis) { position->vec[i][j] = mat_Dmod1(position->vec[i][j]); From 644f62805dc00987aafdc91002de9bb126449ace Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Tue, 17 Oct 2023 22:12:37 +0900 Subject: [PATCH 2/2] Add doxygen comments --- src/cell.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/cell.c b/src/cell.c index d5f2dab39..cec963c57 100644 --- a/src/cell.c +++ b/src/cell.c @@ -326,12 +326,14 @@ int cel_layer_any_overlap_with_same_type(const Cell *cell, return 0; } -/// @param[out] mapping_table array (cell->size, ), maps atom-`i` in cell to -/// non-overlapped atom-`mapping_table[i]` -/// @param[in] trimmed_lattice -/// @param[in] cell -/// @param[in] symprec -/// @return trimmed_cell +/// @param[out] mapping_table array (`cell->size`, ), maps atom-`i` in `cell` to +/// atom-`j` in smaller cell to be returned. +/// @param[in] trimmed_lattice basis vectors of smaller cell which are +/// commensure with basis vectors of larger cell. +/// @param[in] cell larger cell from which smaller cell having basis vectors of +/// `trimmed_lattice` is created. +/// @param[in] symprec tolerance parameter. +/// @return smaller cell having basis vectors of `trimmed_lattice`. Cell *cel_trim_cell(int *mapping_table, const double trimmed_lattice[3][3], const Cell *cell, const double symprec) { return trim_cell(mapping_table, trimmed_lattice, cell, symprec); @@ -528,7 +530,17 @@ static VecDBL *translate_atoms_in_trimmed_lattice(const Cell *cell, return position; } -/* Return NULL if failed */ +/// @brief Find translationally equivalent atoms in larger cell with respect to +/// lattice of smaller cell. +/// @param position array of positions of atoms in larger cells that are reduced +/// in smaller cells. +/// @param cell_size number of atoms in larger cell. +/// @param cell_types yypes of atoms in larger cell. +/// @param trimmed_cell basis vectors of smaller cell. +/// @param symprec tolerance parameter. +/// @return array (cell_size, ) If `position[i]` and `position[j]` with `i` <= +/// `j` are equivalent, `overlap_table[i]` = `overlap_table[j]` = `i`. Return +/// NULL if failed. static int *get_overlap_table(const VecDBL *position, const int cell_size, const int *cell_types, const Cell *trimmed_cell, const double symprec) {