Ejemplo n.º 1
0
/* Return 0 if failed */
static int trim_cell(Cell * primitive_cell,
                     int * mapping_table,
                     SPGCONST Cell * cell,
                     const double symprec)
{
    int i, index_prim_atom;
    VecDBL * position;
    int **overlap_table;

    position = NULL;
    overlap_table = NULL;

    if ((overlap_table = allocate_overlap_table(cell->size)) == NULL) {
        goto err;
    }

    if ((position = get_positions_primitive(cell, primitive_cell->lattice))
            == NULL) {
        free_overlap_table(overlap_table, cell->size);
        goto err;
    }

    if (! get_overlap_table(overlap_table,
                            primitive_cell,
                            position,
                            cell->types,
                            symprec)) {
        goto err_with_free;
    }

    index_prim_atom = 0;
    for (i = 0; i < cell->size; i++) {
        if (overlap_table[i][0] == i) {
            mapping_table[i] = index_prim_atom;
            index_prim_atom++;
        } else {
            mapping_table[i] = mapping_table[overlap_table[i][0]];
        }
    }

    if (! set_primitive_positions(primitive_cell,
                                  position,
                                  cell,
                                  overlap_table)) {
        goto err_with_free;
    }

    mat_free_VecDBL(position);
    free_overlap_table(overlap_table, cell->size);
    return 1;

err_with_free:
    mat_free_VecDBL(position);
    free_overlap_table(overlap_table, cell->size);
err:
    return 0;
}
Ejemplo n.º 2
0
static int trim_cell( Cell * primitive,
		      int * mapping_table,
		      SPGCONST Cell * cell,
		      const double symprec )
{
  int ratio, i, count;
  VecDBL * position;
  int **overlap_table;

  overlap_table = allocate_overlap_table( cell->size );
  ratio = cell->size / primitive->size;

  /* Get reduced positions of atoms in original cell with respect to */
  /* primitive lattice */
  position = get_positions_primitive( cell, primitive->lattice );

  /* Create overlapping table */
  if ( ! get_overlap_table( overlap_table,
			    cell->size,
			    primitive,
			    position,
			    symprec ) ) { goto err; }

  /* cell to primitive cell mapping table */
  count = 0;
  for ( i = 0; i < cell->size; i++ ) {
    if ( overlap_table[i][0] == i ) {
      mapping_table[i] = count;
      count++;
    } else {
      mapping_table[i] = mapping_table[ overlap_table[i][0] ];
    }
  }

  /* Copy positions. Positions of overlapped atoms are averaged. */
  if ( ! set_primitive_positions( primitive,
				  position,
				  cell,
				  overlap_table ) )
    { goto err; }

  debug_print("Trimed position\n");
  debug_print_vectors_with_label( primitive->position,
				  primitive->types,
				  primitive->size );
  
  mat_free_VecDBL( position );
  free_overlap_table( overlap_table, cell->size );
  return 1;

 err:
  mat_free_VecDBL( position );
  free_overlap_table( overlap_table, cell->size );
  return 0;
}
Ejemplo n.º 3
0
static int trim_cell(Cell * primitive_cell,
		     int * mapping_table,
		     SPGCONST Cell * cell,
		     const double symprec)
{
  int i, index_prim_atom;
  VecDBL * position;
  int **overlap_table;

  overlap_table = allocate_overlap_table(cell->size);

  /* Get reduced positions of atoms in original cell with respect to */
  /* primitive lattice */
  position = get_positions_primitive(cell, primitive_cell->lattice);

  /* Create overlapping table */
  if (! get_overlap_table(overlap_table,
			  cell->size,
			  primitive_cell,
			  position,
			  symprec)) {goto err;}

  /* Create original cell to primitive cell mapping table */
  index_prim_atom = 0;
  for (i = 0; i < cell->size; i++) {
    if (overlap_table[i][0] == i) {
      mapping_table[i] = index_prim_atom;
      index_prim_atom++;
    } else {
      mapping_table[i] = mapping_table[overlap_table[i][0]];
    }
  }

  /* Copy positions. Positions of overlapped atoms are averaged. */
  if (! set_primitive_positions(primitive_cell,
				position,
				cell,
				overlap_table)) {goto err;}

  mat_free_VecDBL(position);
  free_overlap_table(overlap_table, cell->size);
  return 1;

 err:
  mat_free_VecDBL(position);
  free_overlap_table(overlap_table, cell->size);
  return 0;
}
Ejemplo n.º 4
0
/* Return NULL if failed */
static Cell * trim_cell(int * mapping_table,
                        SPGCONST double trimmed_lattice[3][3],
                        const Cell * cell,
                        const double symprec)
{
  int i, index_atom, ratio;
  Cell *trimmed_cell;
  VecDBL * position;
  int *overlap_table;

  position = NULL;
  overlap_table = NULL;
  trimmed_cell = NULL;

  ratio = abs(mat_Nint(mat_get_determinant_d3(cell->lattice) /
                       mat_get_determinant_d3(trimmed_lattice)));

  /* Check if cell->size is dividable by ratio */
  if ((cell->size / ratio) * ratio != cell->size) {
    return NULL;
  }

  if ((trimmed_cell = cel_alloc_cell(cell->size / ratio)) == NULL) {
    return NULL;
  }

  if ((position = translate_atoms_in_trimmed_lattice(cell,
                                                     trimmed_lattice))
      == NULL) {
    cel_free_cell(trimmed_cell);
    trimmed_cell = NULL;
    goto err;
  }

  mat_copy_matrix_d3(trimmed_cell->lattice, trimmed_lattice);

  if ((overlap_table = get_overlap_table(position,
                                         cell->size,
                                         cell->types,
                                         trimmed_cell,
                                         symprec)) == NULL) {
    mat_free_VecDBL(position);
    position = NULL;
    cel_free_cell(trimmed_cell);
    trimmed_cell = NULL;
    goto err;
  }

  index_atom = 0;
  for (i = 0; i < cell->size; i++) {
    if (overlap_table[i] == i) {
      mapping_table[i] = index_atom;
      trimmed_cell->types[index_atom] = cell->types[i];
      index_atom++;
    } else {
      mapping_table[i] = mapping_table[overlap_table[i]];
    }
  }

  set_positions(trimmed_cell,
                position,
                mapping_table,
                overlap_table);

  mat_free_VecDBL(position);
  position = NULL;
  free(overlap_table);

  return trimmed_cell;

 err:
  return NULL;
}