Exemplo n.º 1
0
/* If primitive could not be found, primitive->size = -1 is returned. */
static Cell * get_primitive( int * mapping_table,
			     SPGCONST Cell * cell,
			     const VecDBL * pure_trans,
			     const double symprec )
{
  int multi;
  double prim_lattice[3][3];
  Cell * primitive;

  /* Primitive lattice vectors are searched. */
  /* To be consistent, sometimes tolerance is decreased iteratively. */
  /* The descreased tolerance is stored in 'static double tolerance'. */
  multi = get_primitive_lattice_vectors_iterative( prim_lattice,
						   cell,
						   pure_trans,
						   symprec );
  if ( ! multi  ) {
    goto not_found;
  }

  primitive = cel_alloc_cell( cell->size / multi );

  if ( ! lat_smallest_lattice_vector( primitive->lattice,
				      prim_lattice,
				      symprec ) ) {
    cel_free_cell( primitive );
    goto not_found;
  }

  /* Fit atoms into new primitive cell */
  if ( ! trim_cell( primitive, mapping_table, cell, symprec ) ) {
    cel_free_cell( primitive );
    goto not_found;
  }

  debug_print("Original cell lattice.\n");
  debug_print_matrix_d3(cell->lattice);
  debug_print("Found primitive lattice after choosing least axes.\n");
  debug_print_matrix_d3(primitive->lattice);
  debug_print("Number of atoms in primitive cell: %d\n", primitive->size);
  debug_print("Volume: original %f --> primitive %f\n",
	      mat_get_determinant_d3(cell->lattice),
	      mat_get_determinant_d3(primitive->lattice));

  /* found */
  return primitive;

 not_found:
  primitive = cel_alloc_cell( -1 );
  warning_print("spglib: Primitive cell could not found ");
  warning_print("(line %d, %s).\n", __LINE__, __FILE__);
  return primitive;
}
Exemplo n.º 2
0
/* Return NULL if failed */
static Cell * get_primitive_cell(int * mapping_table,
                                 SPGCONST Cell * cell,
                                 const VecDBL * pure_trans,
                                 const double symprec)
{
    int multi;
    double prim_lattice[3][3];
    Cell * primitive_cell;

    debug_print("get_primitive:\n");

    primitive_cell = NULL;

    /* Primitive lattice vectors are searched. */
    /* To be consistent, sometimes tolerance is decreased iteratively. */
    /* The descreased tolerance is stored in 'static double tolerance'. */
    multi = get_primitive_lattice_vectors_iterative(prim_lattice,
            cell,
            pure_trans,
            symprec);
    if (! multi) {
        goto not_found;
    }

    if ((primitive_cell = cel_alloc_cell(cell->size / multi)) == NULL) {
        goto not_found;
    }

    if (! lat_smallest_lattice_vector(primitive_cell->lattice,
                                      prim_lattice,
                                      symprec)) {
        cel_free_cell(primitive_cell);
        primitive_cell = NULL;
        goto not_found;
    }

    /* Fit atoms into new primitive cell */
    if (! trim_cell(primitive_cell, mapping_table, cell, symprec)) {
        cel_free_cell(primitive_cell);
        primitive_cell = NULL;
        goto not_found;
    }

    /* found */
    return primitive_cell;

not_found:
    warning_print("spglib: Primitive cell could not be found ");
    warning_print("(line %d, %s).\n", __LINE__, __FILE__);
    return NULL;
}