def find_primitive(structure, symprec=1e-4, angle_tolerance=-1.0):
    """
    A primitive cell in the input cell is searched and returned
    as an object of Atoms class.
    If no primitive cell is found, (None, None, None) is returned.
    """
    cell = structure.cell.T.copy()
    coords = np.array(structure.site_coords.copy(), dtype='double')
    comps = structure.site_compositions
    numbers = [ comps.index(c) for c in comps ]
    numbers = np.array(numbers*4, dtype='intc')

    num_atom_prim = spg.primitive(cell,
                                  coords,
                                  numbers,
                                  symprec,
                                  angle_tolerance)

    coords = wrap(coords)
    comps = [ comps[i] for i in numbers ]
    if num_atom_prim > 0:
        structure.cell = cell.T
        structure.set_nsites(num_atom_prim)
        structure.site_coords = coords[:num_atom_prim]
        structure.site_compositions = comps[:num_atom_prim]
        return structure
    else:
        return structure
Exemple #2
0
def find_primitive(structure, symprec=1e-4, angle_tolerance=-1.0):
    """
    A primitive cell in the input cell is searched and returned
    as an object of Atoms class.
    If no primitive cell is found, (None, None, None) is returned.
    """
    cell = structure.cell.T.copy()
    coords = np.array(structure.site_coords.copy(), dtype='double')
    comps = structure.site_compositions
    numbers = [comps.index(c) for c in comps]
    numbers = np.array(numbers * 4, dtype='intc')

    num_atom_prim = spg.primitive(cell, coords, numbers, symprec,
                                  angle_tolerance)

    coords = wrap(coords)
    comps = [comps[i] for i in numbers]
    if num_atom_prim > 0:
        structure.cell = cell.T
        structure.set_nsites(num_atom_prim)
        structure.site_coords = coords[:num_atom_prim]
        structure.site_compositions = comps[:num_atom_prim]
        return structure
    else:
        return structure
Exemple #3
0
def find_primitive(bulk, symprec=1e-5, angle_tolerance=-1.0):
    """
    A primitive cell in the input cell is searched and returned
    as an object of Atoms class.
    If no primitive cell is found, (None, None, None) is returned.
    """

    # Atomic positions have to be specified by scaled positions for spglib.
    positions = bulk.get_scaled_positions().copy()
    lattice = bulk.get_cell().T.copy()
    numbers = np.intc(bulk.get_atomic_numbers()).copy()

    # lattice is transposed with respect to the definition of Atoms class
    num_atom_prim = spg.primitive(lattice, positions, numbers, symprec,
                                  angle_tolerance)
    if num_atom_prim > 0:
        return (lattice.T.copy(), positions[:num_atom_prim].copy(),
                numbers[:num_atom_prim].copy())
    else:
        return None, None, None
Exemple #4
0
    def find_primitive(self):
        """
        A primitive cell in the input cell is searched and returned
        as an Structure object.
        If no primitive cell is found, (None, None, None) is returned.
        """

        # Atomic positions have to be specified by scaled positions for spglib.
        positions = self._positions.copy()
        lattice = self._lattice.T.copy()
        numbers = self._numbers.copy()
        # lattice is transposed with respect to the definition of Atoms class
        num_atom_prim = spg.primitive(lattice, positions, numbers, self._symprec, self._angle_tol)
        zs = numbers[:num_atom_prim]
        species = [self._unique_species[i - 1] for i in zs]

        if num_atom_prim > 0:
            return Structure(lattice.T, species, positions[:num_atom_prim])
        else:
            #Not sure if we should return None or just return the full structure.
            return None
Exemple #5
0
def find_primitive(bulk, symprec=1e-5, angle_tolerance=-1.0):
    """
    A primitive cell in the input cell is searched and returned
    as an object of Atoms class.
    If no primitive cell is found, (None, None, None) is returned.
    """

    # Atomic positions have to be specified by scaled positions for spglib.
    positions = np.array(bulk.get_scaled_positions(), dtype='double', order='C')
    lattice = np.array(bulk.get_cell().T, dtype='double', order='C')
    numbers = np.array(bulk.get_atomic_numbers(), dtype='intc')

    # lattice is transposed with respect to the definition of Atoms class
    num_atom_prim = spg.primitive(lattice,
                                  positions,
                                  numbers,
                                  symprec,
                                  angle_tolerance)
    if num_atom_prim > 0:
        return (np.array(lattice.T, dtype='double', order='C'),
                np.array(positions[:num_atom_prim], dtype='double', order='C'),
                np.array(numbers[:num_atom_prim], dtype='intc'))
    else:
        return None, None, None