Esempio 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;
}
Esempio 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;
}
Esempio 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;
}