How to use the spglib.get_spacegroup 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 pyiron / pyiron / pyiron / atomistics / structure / atoms.py View on Github external
def get_spacegroup(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(), dtype='double', order='C')
        positions = np.array(self.get_scaled_positions(), dtype='double', order='C')
        numbers = np.array(self.get_atomic_numbers(), dtype='intc')
        space_group = spglib.get_spacegroup(cell=(lattice, positions, numbers),
                                            symprec=symprec,
                                            angle_tolerance=angle_tolerance).split()
        if len(space_group) == 1:
            return {"Number": ast.literal_eval(space_group[0])}
        else:
            return {"InternationalTableSymbol": space_group[0],
                    "Number": ast.literal_eval(space_group[1])}
github elcorto / pwtools / pwtools / symmetry.py View on Github external
`angle_tolerance` last time I checked

    Returns
    -------
    spg_num, spg_sym
    spg_num : int
        space group number
    spg_sym : str
        space group symbol

    Notes
    -----
    The used function ``spglib.get_spacegroup()`` returns a string, which we
    split into `spg_num` and `spg_sym`.
    """
    ret = spglib.get_spacegroup(struct.get_spglib(), **kwds)
    spl = ret.split()
    spg_sym = spl[0]
    spg_num = spl[1]
    spg_num = spg_num.replace('(','').replace(')','')
    spg_num = int(spg_num)
    return spg_num,spg_sym
github pyiron / pyiron / pyiron / atomistics / structure / atoms.py View on Github external
def get_spacegroup(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(), dtype='double', order='C')
        positions = np.array(self.get_scaled_positions(), dtype='double', order='C')
        numbers = np.array(self.get_atomic_numbers(), dtype='intc')
        space_group = spglib.get_spacegroup(cell=(lattice, positions, numbers),
                                            symprec=symprec,
                                            angle_tolerance=angle_tolerance).split()
        if len(space_group) == 1:
            return {"Number": ast.literal_eval(space_group[0])}
        else:
            return {"InternationalTableSymbol": space_group[0],
                    "Number": ast.literal_eval(space_group[1])}
github chuanxun / StructurePrototypeAnalysisPackage / spap / spap.py View on Github external
ccf_range = r_cut_off + extend_r
    r_vector = np.linspace(0.0, ccf_range, int(ccf_range / ccf_step) + 2)
    space_g_l = []
    for structure in structure_list:
        if pbc == [True, True, True] or pbc == [True, True, False]:
            structure.conventional_cell = standardize_cell(
                (structure.cell, structure.get_scaled_positions(wrap=True), structure.numbers), symprec=symprec)
            if structure.conventional_cell == None:
                structure.conventional_cell = structure
                structure.space_group = 'NULL(0)'
                space_g_l.append(1)
            else:
                structure.conventional_cell = Atoms(cell=structure.conventional_cell[0],
                                                    scaled_positions=structure.conventional_cell[1],
                                                    numbers=structure.conventional_cell[2], pbc=pbc)
                structure.space_group = get_spacegroup(
                    (structure.cell, structure.get_scaled_positions(wrap=True), structure.numbers),
                    symprec=symprec).replace(' ', '')
                space_g_l.append(int(get_spg_n(structure.space_group)))
        elif pbc == [False, False, False]:
            structure.conventional_cell = structure
            structure.space_group = 'P1(1)'
            space_g_l.append(1)
        structure.conventional_cell.n_atom = len(structure.conventional_cell.numbers)
    if l_cif or l_poscar:
        if os.path.exists(dir_name):
            for root, dirs, files in os.walk(dir_name, topdown=False):
                for name in files:
                    os.remove(os.path.join(root, name))
                for name in dirs:
                    os.rmdir(os.path.join(root, name))
        else:
github JohnKendrick / PDielec / PDielec / UnitCell.py View on Github external
def find_symmetry(self):
        """Find the space group symmetry of the unit cell"""
        from spglib import get_spacegroup
        cell = ( self.lattice, self.fractional_coordinates, self.atomic_nos )
        self.spacegroup = get_spacegroup(cell, symmprec=1e-5)
        print("Symmetry space group is", self.spacegroup)
github atztogo / spglib / python / examples / example.py View on Github external
# For VASP case
# import vasp
# bulk = vasp.read_vasp(sys.argv[1])

print("[get_spacegroup]")
print("  Spacegroup of Silicon is %s." % spglib.get_spacegroup(silicon))
print('')
print("[get_spacegroup]")
print("  Spacegroup of Silicon (ASE Atoms-like format) is %s." %
      spglib.get_spacegroup(silicon_ase))
print('')
print("[get_spacegroup]")
print("  Spacegroup of Rutile is %s." % spglib.get_spacegroup(rutile))
print('')
print("[get_spacegroup]")
print("  Spacegroup of MgB2 is %s." % spglib.get_spacegroup(MgB2))
print('')
print("[get_symmetry]")
print("  Symmetry operations of Rutile unitcell are:")
print('')
symmetry = spglib.get_symmetry(rutile)
show_symmetry(symmetry)
print('')
print("[get_symmetry]")
print("  Symmetry operations of MgB2 are:")
print('')
symmetry = spglib.get_symmetry(MgB2)
show_symmetry(symmetry)
print('')
print("[get_pointgroup]")
print("  Pointgroup of Rutile is %s." %
      spglib.get_pointgroup(symmetry['rotations'])[0])
github chuanxun / StructurePrototypeAnalysisPackage / SPAP.py View on Github external
total_struc += 1

    print('Analyzing symmetry')
    space_g_l = []
    for structure in structure_list:
        structure.conventional_cell = standardize_cell(
            (structure.cell, structure.get_scaled_positions(wrap=True), structure.numbers), symprec=symprec)
        if structure.conventional_cell == None:
            structure.conventional_cell = structure
            structure.space_group = 'NULL(0)'
            space_g_l.append(0)
        else:
            structure.conventional_cell = Atoms(cell=structure.conventional_cell[0],
                                                scaled_positions=structure.conventional_cell[1],
                                                numbers=structure.conventional_cell[2], pbc=True)
            structure.space_group = get_spacegroup(
                (structure.cell, structure.get_scaled_positions(wrap=True), structure.numbers),
                symprec=symprec).replace(' ', '')
            space_g_l.append(int(get_spg_n(structure.space_group)))
        structure.conventional_cell.n_atom = len(structure.conventional_cell.numbers)
    if l_cif or l_poscar:
        if os.path.exists(dir_name):
            for root, dirs, files in os.walk(dir_name, topdown=False):
                for name in files:
                    os.remove(os.path.join(root, name))
                for name in dirs:
                    os.rmdir(os.path.join(root, name))
        else:
            os.mkdir(dir_name)
        for root, dirs, files in os.walk('./', topdown=True):
            for name in dirs:
                if name[:4] == 'dir_' and name != dir_name:
github atztogo / spglib / python / examples / example.py View on Github external
[(0, 0, 0),
         (1.0/3, 2.0/3, 0.5),
         (2.0/3, 1.0/3, 0.5)],
        [12, 5, 5])

a = [3., 0., 0.]
b = [-3.66666667, 3.68178701, 0.]
c = [-0.66666667, -1.3429469, 1.32364995]
niggli_lattice = np.array([a, b, c])

# For VASP case
# import vasp
# bulk = vasp.read_vasp(sys.argv[1])

print("[get_spacegroup]")
print("  Spacegroup of Silicon is %s." % spglib.get_spacegroup(silicon))
print('')
print("[get_spacegroup]")
print("  Spacegroup of Silicon (ASE Atoms-like format) is %s." %
      spglib.get_spacegroup(silicon_ase))
print('')
print("[get_spacegroup]")
print("  Spacegroup of Rutile is %s." % spglib.get_spacegroup(rutile))
print('')
print("[get_spacegroup]")
print("  Spacegroup of MgB2 is %s." % spglib.get_spacegroup(MgB2))
print('')
print("[get_symmetry]")
print("  Symmetry operations of Rutile unitcell are:")
print('')
symmetry = spglib.get_symmetry(rutile)
show_symmetry(symmetry)