How to use the spglib.refine_cell function in spglib

To help you get started, we’ve selected a few spglib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aiidateam / aiida-core / aiida / orm / nodes / data / structure.py View on Github external
def ase_refine_cell(aseatoms, **kwargs):
    """
    Detect the symmetry of the structure, remove symmetric atoms and
    refine unit cell.

    :param aseatoms: an ase.atoms.Atoms instance
    :param symprec: symmetry precision, used by spglib
    :return newase: refined cell with reduced set of atoms
    :return symmetry: a dictionary describing the symmetry space group
    """
    from spglib import refine_cell, get_symmetry_dataset
    from ase.atoms import Atoms
    cell, positions, numbers = refine_cell(aseatoms, **kwargs)

    refined_atoms = Atoms(numbers, scaled_positions=positions, cell=cell, pbc=True)

    sym_dataset = get_symmetry_dataset(refined_atoms, **kwargs)

    unique_numbers = []
    unique_positions = []

    for i in set(sym_dataset['equivalent_atoms']):
        unique_numbers.append(refined_atoms.numbers[i])
        unique_positions.append(refined_atoms.get_scaled_positions()[i])

    unique_atoms = Atoms(unique_numbers, scaled_positions=unique_positions, cell=cell, pbc=True)

    return unique_atoms, {
        'hm': sym_dataset['international'],
github pyiron / pyiron / pyiron / atomistics / structure / atoms.py View on Github external
def refine_cell(self, symprec=1e-5, angle_tolerance=-1.0):
        """
        
        Args:
            symprec: 
            angle_tolerance: 

        Returns:

        https://atztogo.github.io/spglib/python-spglib.html
        """
        lattice = np.array(self.get_cell().T, dtype='double', order='C')
        positions = np.array(self.get_scaled_positions(), dtype='double', order='C')
        numbers = np.array(self.get_atomic_numbers(), dtype='intc')
        cell, coords, el = spglib.refine_cell(cell=(lattice, positions, numbers),
                                              symprec=symprec,
                                              angle_tolerance=angle_tolerance)

        return Atoms(symbols=list(self.get_chemical_symbols()),
                     positions=coords,
                     cell=cell)
github MaterialsDiscovery / PyChemia / pychemia / crystal / symmetry.py View on Github external
>>> fcc = pychemia.Structure(symbols=['Au'],
        ...       cell=[[0, b+1E-5, b-1E-5], [b+1E-5, 0, b-1E-5], [b+1E-5, b-1E-5, 0]], periodicity=True)
        >>> symm = pychemia.crystal.CrystalSymmetry(fcc)
        >>> symm.number()
        2
        >>> symm.symbol() == u'P-1'
        True
        >>> fcc2 = symm.refine_cell(symprec=1E-3)
        >>> symm2 = pychemia.crystal.CrystalSymmetry(fcc2)
        >>> symm2.number()
        225
        >>> symm2.symbol() == u'Fm-3m'
        True

        """
        new_spglib_cell = spg.refine_cell(self.spglib_cell, symprec=symprec)
        return self.get_new_structure(new_spglib_cell)
github atztogo / spglib / python / examples / example.py View on Github external
print('')
print("[get_symmetry_dataset] ['rotations'], ['translations']")
print("  Symmetry operations of Rutile unitcell are:")
for i, (rot,trans) in enumerate(zip(dataset['rotations'],
                                    dataset['translations'])):
    print("  --------------- %4d ---------------" % (i + 1))
    print("  rotation:")
    for x in rot:
        print("     [%2d %2d %2d]" % (x[0], x[1], x[2]))
    print("  translation:")
    print("     (%8.5f %8.5f %8.5f)" % (trans[0], trans[1], trans[2]))
print('')

print("[refine_cell]")
print(" Refine distorted rutile structure")
lattice, positions, numbers = spglib.refine_cell(rutile_dist, symprec=1e-1)
show_cell(lattice, positions, numbers)
print('')

print("[find_primitive]")
print(" Fine primitive distorted silicon structure")
lattice, positions, numbers = spglib.find_primitive(silicon_dist, symprec=1e-1)
show_cell(lattice, positions, numbers)
print('')

print("[standardize_cell]")
print(" Standardize distorted rutile structure:")
print(" (to_primitive=0 and no_idealize=0)")
lattice, positions, numbers = spglib.standardize_cell(rutile_dist,
                                                      to_primitive=0,
                                                      no_idealize=0,
                                                      symprec=1e-1)
github pyiron / pyiron / pyiron / atomistics / structure / atoms.py View on Github external
def refine_cell(self, symprec=1e-5, angle_tolerance=-1.0):
        """
        
        Args:
            symprec: 
            angle_tolerance: 

        Returns:

        https://atztogo.github.io/spglib/python-spglib.html
        """
        lattice = np.array(self.get_cell().T, dtype='double', order='C')
        positions = np.array(self.get_scaled_positions(), dtype='double', order='C')
        numbers = np.array(self.get_atomic_numbers(), dtype='intc')
        cell, coords, el = spglib.refine_cell(cell=(lattice, positions, numbers),
                                              symprec=symprec,
                                              angle_tolerance=angle_tolerance)

        return Atoms(symbols=list(self.get_chemical_symbols()),
                     positions=coords,
                     cell=cell)
github materialsproject / pymatgen / pymatgen / symmetry / analyzer.py View on Github external
def get_refined_structure(self):
        """
        Get the refined structure based on detected symmetry. The refined
        structure is a *conventional* cell setting with atoms moved to the
        expected symmetry positions.

        Returns:
            Refined structure.
        """
        # Atomic positions have to be specified by scaled positions for spglib.
        lattice, scaled_positions, numbers \
            = spglib.refine_cell(self._cell, self._symprec, self._angle_tol)

        species = [self._unique_species[i - 1] for i in numbers]
        s = Structure(lattice, species, scaled_positions)
        return s.get_sorted_structure()