Example #1
0
def find_structure_symmetry(structure,
                            method='spglib',
                            symprec=1e-5,
                            angle_tolerance=-1.0):
    """
    Return the rotatiosn and translations which are possessed by the structure.
    
    Examples::

        >>> from qmpy.io import read
        >>> from qmpy.analysis.symmetry import find_structure_symmetry
        >>> structure = read('POSCAR')
        >>> find_structure_symmetry(structure)
    
    """
    # Get number of symmetry operations and allocate symmetry operations
    multi = 48 * len(structure)
    rotation = np.zeros((multi, 3, 3), dtype='intc')
    translation = np.zeros((multi, 3))

    cell = structure.cell.T.copy()
    coords = structure.site_coords.copy()
    numbers = np.array(structure.site_ids, dtype='intc')

    # Get symmetry operations
    magmoms = structure.magmoms
    if not any(magmoms):
        num_sym = spg.symmetry(rotation, translation, cell, coords, numbers,
                               symprec, angle_tolerance)
    else:
        num_sym = spg.symmetry_with_collinear_spin(rotation, translation, cell,
                                                   coords, numbers, magmoms,
                                                   symprec, angle_tolerance)

    return rotation[:num_sym], translation[:num_sym]
Example #2
0
def get_symmetry(bulk, symprec=1e-5, angle_tolerance=-1.0):
    """
    Return symmetry operations as hash.
    Hash key 'rotations' gives the numpy integer array
    of the rotation matrices for scaled positions
    Hash key 'translations' gives the numpy double array
    of the translation vectors in scaled positions
    """

    # 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()

    # Get number of symmetry operations and allocate symmetry operations
    # multi = spg.multiplicity(cell, positions, numbers, symprec)
    multi = 48 * bulk.get_number_of_atoms()
    rotation = np.zeros((multi, 3, 3), dtype='intc')
    translation = np.zeros((multi, 3))

    # Get symmetry operations
    magmoms = bulk.get_magnetic_moments()
    if magmoms == None:
        num_sym = spg.symmetry(rotation, translation, lattice, positions,
                               numbers, symprec, angle_tolerance)
    else:
        num_sym = spg.symmetry_with_collinear_spin(rotation, translation,
                                                   lattice, positions, numbers,
                                                   magmoms, symprec,
                                                   angle_tolerance)

    return {
        'rotations': rotation[:num_sym].copy(),
        'translations': translation[:num_sym].copy()
    }
Example #3
0
def get_symmetry(bulk, symprec=1e-5, angle_tolerance=-1.0):
    """
    Return symmetry operations as hash.
    Hash key 'rotations' gives the numpy integer array
    of the rotation matrices for scaled positions
    Hash key 'translations' gives the numpy double array
    of the translation vectors in scaled positions
    """

    # 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')
    positions = np.array([
        np.dot(atom.pos, np.linalg.inv(np.transpose(bulk.cell)))
        for atom in bulk
    ],
                         dtype='double',
                         order='C')
    lattice = np.array(bulk.cell * bulk.scale, dtype='double', order='C')
    numbers = np.array(
        [periodic_table.symbols.index(atom.type) + 1 for atom in bulk],
        dtype='intc')

    # Get number of symmetry operations and allocate symmetry operations
    # multi = spg.multiplicity(cell, positions, numbers, symprec)
    #    multi = 48 * bulk.get_number_of_atoms()
    multi = 48 * len(bulk)
    rotation = np.zeros((multi, 3, 3), dtype='intc')
    translation = np.zeros((multi, 3), dtype='double')

    # Get symmetry operations
    #    if use_magmoms:
    #        magmoms = bulk.get_magnetic_moments()
    #        num_sym = spg.symmetry_with_collinear_spin(rotation,
    #                                                   translation,
    #                                                   lattice,
    #                                                   positions,
    #                                                   numbers,
    #                                                   magmoms,
    #                                                   symprec,
    #                                                   angle_tolerance)
    #    else:
    #        num_sym = spg.symmetry(rotation,
    #                               translation,
    #                               lattice,
    #                               positions,
    #                               numbers,
    #                               symprec,
    #                               angle_tolerance)

    num_sym = spg.symmetry(rotation, translation, lattice, positions, numbers,
                           symprec, angle_tolerance)

    return {
        'rotations': np.array(rotation[:num_sym], dtype='intc', order='C'),
        'translations': np.array(translation[:num_sym],
                                 dtype='double',
                                 order='C')
    }
Example #4
0
def get_symmetry(bulk, use_magmoms=False, symprec=1e-5, angle_tolerance=-1.0):
    """
    Return symmetry operations as hash.
    Hash key 'rotations' gives the numpy integer array
    of the rotation matrices for scaled positions
    Hash key 'translations' gives the numpy double array
    of the translation vectors in scaled positions
    """

    # 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')

    # Get number of symmetry operations and allocate symmetry operations
    # multi = spg.multiplicity(cell, positions, numbers, symprec)
    multi = 48 * bulk.get_number_of_atoms()
    rotation = np.zeros((multi, 3, 3), dtype='intc')
    translation = np.zeros((multi, 3), dtype='double')

    # Get symmetry operations
    if use_magmoms:
        magmoms = bulk.get_magnetic_moments()
        equivalent_atoms = np.zeros(len(magmoms), dtype='intc')
        num_sym = spg.symmetry_with_collinear_spin(rotation,
                                                   translation,
                                                   equivalent_atoms,
                                                   lattice,
                                                   positions,
                                                   numbers,
                                                   magmoms,
                                                   symprec,
                                                   angle_tolerance)
        return ({'rotations': np.array(rotation[:num_sym],
                                       dtype='intc', order='C'),
                 'translations': np.array(translation[:num_sym],
                                          dtype='double', order='C')},
                equivalent_atoms)
    else:
        num_sym = spg.symmetry(rotation,
                               translation,
                               lattice,
                               positions,
                               numbers,
                               symprec,
                               angle_tolerance)

        return {'rotations': np.array(rotation[:num_sym],
                                      dtype='intc', order='C'),
                'translations': np.array(translation[:num_sym],
                                         dtype='double', order='C')}
Example #5
0
def get_symmetry(bulk, use_magmoms=False, symprec=1e-5, angle_tolerance=-1.0):
    """
    Return symmetry operations as hash.
    Hash key 'rotations' gives the numpy integer array
    of the rotation matrices for scaled positions
    Hash key 'translations' gives the numpy double array
    of the translation vectors in scaled positions
    """

    # 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')

    # Get number of symmetry operations and allocate symmetry operations
    # multi = spg.multiplicity(cell, positions, numbers, symprec)
    multi = 48 * bulk.get_number_of_atoms()
    rotation = np.zeros((multi, 3, 3), dtype='intc')
    translation = np.zeros((multi, 3), dtype='double')

    # Get symmetry operations
    if use_magmoms:
        magmoms = bulk.get_magnetic_moments()
        equivalent_atoms = np.zeros(len(magmoms), dtype='intc')
        num_sym = spg.symmetry_with_collinear_spin(rotation, translation,
                                                   equivalent_atoms, lattice,
                                                   positions, numbers, magmoms,
                                                   symprec, angle_tolerance)
        return ({
            'rotations':
            np.array(rotation[:num_sym], dtype='intc', order='C'),
            'translations':
            np.array(translation[:num_sym], dtype='double', order='C')
        }, equivalent_atoms)
    else:
        num_sym = spg.symmetry(rotation, translation, lattice, positions,
                               numbers, symprec, angle_tolerance)

        return {
            'rotations':
            np.array(rotation[:num_sym], dtype='intc', order='C'),
            'translations':
            np.array(translation[:num_sym], dtype='double', order='C')
        }
Example #6
0
    def get_symmetry(self):
        """
        Return symmetry operations as hash.
        Hash key 'rotations' gives the numpy integer array
        of the rotation matrices for scaled positions
        Hash key 'translations' gives the numpy float64 array
        of the translation vectors in scaled positions
        """

        # Get number of symmetry operations and allocate symmetry operations
        # multi = spg.multiplicity(cell, positions, numbers, symprec)
        multi = 48 * self._structure.num_sites
        rotation = np.zeros((multi, 3, 3), dtype=int)
        translation = np.zeros((multi, 3))

        num_sym = spg.symmetry(rotation, translation, self._lattice.transpose().copy(),
                                   self._positions, self._numbers, self._symprec, self._angle_tol)
        return (rotation[:num_sym], translation[:num_sym])
def find_structure_symmetry(structure, method='spglib',
        symprec=1e-5, angle_tolerance=-1.0):
    """
    Return the rotatiosn and translations which are possessed by the structure.
    
    Examples::

        >>> from qmpy.io import read
        >>> from qmpy.analysis.symmetry import find_structure_symmetry
        >>> structure = read('POSCAR')
        >>> find_structure_symmetry(structure)
    
    """
    # Get number of symmetry operations and allocate symmetry operations
    multi = 48 * len(structure)
    rotation = np.zeros((multi, 3, 3), dtype='intc')
    translation = np.zeros((multi, 3))

    cell = structure.cell.T.copy()
    coords = structure.site_coords.copy()
    numbers = np.array(structure.site_ids, dtype='intc')
  
    # Get symmetry operations
    magmoms = structure.magmoms
    if not any(magmoms):
        num_sym = spg.symmetry(rotation,
                               translation,
                               cell,
                               coords,
                               numbers,
                               symprec,
                               angle_tolerance)
    else:
        num_sym = spg.symmetry_with_collinear_spin(rotation,
                                                   translation,
                                                   cell,
                                                   coords,
                                                   numbers,
                                                   magmoms,
                                                   symprec,
                                                   angle_tolerance)
  
    return rotation[:num_sym], translation[:num_sym]
Example #8
0
def get_symmetry(bulk, symprec=1e-5, angle_tolerance=-1.0):
    """
    Return symmetry operations as hash.
    Hash key 'rotations' gives the numpy integer array
    of the rotation matrices for scaled positions
    Hash key 'translations' gives the numpy double array
    of the translation vectors in scaled positions
    """

    # 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()
  
    # Get number of symmetry operations and allocate symmetry operations
    # multi = spg.multiplicity(cell, positions, numbers, symprec)
    multi = 48 * bulk.get_number_of_atoms()
    rotation = np.zeros((multi, 3, 3), dtype='intc')
    translation = np.zeros((multi, 3))
  
    # Get symmetry operations
    magmoms = bulk.get_magnetic_moments()
    if magmoms == None:
        num_sym = spg.symmetry(rotation,
                               translation,
                               lattice,
                               positions,
                               numbers,
                               symprec,
                               angle_tolerance)
    else:
        num_sym = spg.symmetry_with_collinear_spin(rotation,
                                                   translation,
                                                   lattice,
                                                   positions,
                                                   numbers,
                                                   magmoms,
                                                   symprec,
                                                   angle_tolerance)
  
    return {'rotations': rotation[:num_sym].copy(),
            'translations': translation[:num_sym].copy()}