def test_get_hall_number_from_symmetry(self):
     for fname in self._filenames:
         cell = read_vasp(fname)
         if 'distorted' in fname:
             dataset = get_symmetry_dataset(cell, symprec=1e-1)
             hall_number = get_hall_number_from_symmetry(
                 dataset['rotations'],
                 dataset['translations'],
                 symprec=1e-1)
             if hall_number != dataset['hall_number']:
                 print("%d != %d in %s" %
                       (hall_number, dataset['hall_number'], fname))
                 ref_cell = (dataset['std_lattice'],
                             dataset['std_positions'], dataset['std_types'])
                 dataset = get_symmetry_dataset(ref_cell, symprec=1e-5)
                 hall_number = get_hall_number_from_symmetry(
                     dataset['rotations'],
                     dataset['translations'],
                     symprec=1e-5)
                 print("Using refinced cell: %d, %d in %s" %
                       (hall_number, dataset['hall_number'], fname))
         else:
             dataset = get_symmetry_dataset(cell, symprec=1e-5)
             hall_number = get_hall_number_from_symmetry(
                 dataset['rotations'],
                 dataset['translations'],
                 symprec=1e-5)
         self.assertEqual(
             hall_number,
             dataset['hall_number'],
             msg=("%d != %d in %s" %
                  (hall_number, dataset['hall_number'], fname)))
 def test_get_hall_number_from_symmetry(self):
     for fname in self._filenames:
         cell = read_vasp(fname)
         if 'distorted' in fname:
             dataset = get_symmetry_dataset(cell, symprec=1e-1)
             hall_number = get_hall_number_from_symmetry(
                 dataset['rotations'],
                 dataset['translations'],
                 symprec=1e-1)
             if hall_number != dataset['hall_number']:
                 print("%d != %d in %s" %
                       (hall_number, dataset['hall_number'], fname))
                 ref_cell = (dataset['std_lattice'],
                             dataset['std_positions'],
                             dataset['std_types'])
                 dataset = get_symmetry_dataset(ref_cell, symprec=1e-5)
                 hall_number = get_hall_number_from_symmetry(
                     dataset['rotations'],
                     dataset['translations'],
                     symprec=1e-5)
                 print("Using refinced cell: %d, %d in %s" %
                       (hall_number, dataset['hall_number'], fname))
         else:
             dataset = get_symmetry_dataset(cell, symprec=1e-5)
             hall_number = get_hall_number_from_symmetry(
                 dataset['rotations'],
                 dataset['translations'],
                 symprec=1e-5)
         self.assertEqual(
             hall_number, dataset['hall_number'],
             msg=("%d != %d in %s" %
                  (hall_number, dataset['hall_number'], fname)))
示例#3
0
def get_hall_number_from_symmetry(operations,
                                  basis="fractional",
                                  lattice=None,
                                  symprec=1e-5):
    """obtain the Hall number from the symmetry operations

    Parameters
    ----------
    operations: list
        Nx12 flattened list of symmetry operations
    basis: str
        "fractional" or "cartesian"

    Returns
    -------
    int

    """
    if basis == "cartesian":
        operations = operations_cart_to_frac(operations, lattice)
    elif basis != "fractional":
        raise ValueError("basis should be cartesian or fractional")
    rotations = [[o[0:3], o[3:6], o[6:9]] for o in operations]
    translations = [o[9:12] for o in operations]
    return spglib.get_hall_number_from_symmetry(rotations,
                                                translations,
                                                symprec=symprec)
示例#4
0
    def get_spglib_hall_number(self, symprec=1e-5):
        """
        Uses spglib.get_hall_number_from_symmetry to determine the hall number
        based on the symmetry operations. Useful when the space group number
        is not available, but the symmetries are (e.g. the DDB file)

        Args:
            symprec: distance tolerance in fractional coordinates (not the standard
                in cartesian coordinates). See spglib docs for more details.

        Returns:
            int: the hall number.
        """
        return spglib.get_hall_number_from_symmetry(self.symrel, self.tnons, symprec=symprec)
示例#5
0
    def get_iso(self, symprec):

        DG = self.matrices

        mat_list = [mat.rotation_matrix for mat in DG]
        vec_list = [mat.translation_vector for mat in DG]

        h_number = spglib.get_hall_number_from_symmetry(np.around(
            mat_list, decimals=4), np.around(vec_list, decimals=6), symprec = symprec)
        sg_type_data=spglib.get_spacegroup_type(h_number)
        iso_sg=sg_type_data['international_short']
        iso_sg_num=sg_type_data['number']

        return iso_sg, iso_sg_num
示例#6
0
def get_iso(path, iv):

    DG = path.get_DG()

    outputfile = open(iv.image_dir + "/../results/output.out", "a")

    h_number = spglib.get_hall_number_from_symmetry(np.around(DG[0][:],
                                                              decimals=4),
                                                    np.around(DG[1][:],
                                                              decimals=6),
                                                    symprec=iv.gentol)
    sg_type_data = spglib.get_spacegroup_type(h_number)
    iso_sg = sg_type_data['international_short']
    iso_sg_num = sg_type_data['number']

    return iso_sg, iso_sg_num
示例#7
0
    def read(self, file):
        """Read and parse fort.34 file"""
        if isinstance(file, str):
            with open(file) as f:
                data = f.read()
        else:
            data = file.read()
        parsed_data = _parse_string(f34_parser(), data)
        self.dimensionality, self.centring, self.crystal_type = parsed_data['header']
        if self.dimensionality != 3:
            raise NotImplementedError('Structure with dimensionality < 3 currently not supported')

        # primitive cell vectors and basis positions in cartesian coordinates
        abc = np.array(parsed_data['abc'].asList()).reshape((3, 3))
        positions = np.array([d[1:] for d in parsed_data['geometry']])

        # convert positions to fractional
        positions = np.dot(np.linalg.inv(abc).T, positions.T).T
        atomic_numbers = [d[0] for d in parsed_data['geometry']]

        # convert to conventional cell
        cell = (abc, positions, atomic_numbers)
        cell = spglib.standardize_cell(cell, to_primitive=False, no_idealize=False)
        self.abc, self.positions, atomic_numbers = cell

        # ECPs
        self.atomic_numbers = [num if num < 201 else num - 200 for num in atomic_numbers]

        # get symmetry operations
        self.n_symops = parsed_data['n_symops']
        self.symops = np.array(parsed_data['symops'].asList()).reshape(self.n_symops * 4, 3)
        rotations = np.zeros((self.n_symops, 3, 3))
        for i in range(3):
            rotations[:, i] = self.symops[i::4]

        # convert symmetry operations from cartesian to fractional
        rotations = np.dot(np.dot(np.linalg.inv(abc.T), rotations), abc.T)

        # have to round rotations matrix as it is used to find symmetry group
        rotations = np.round(np.swapaxes(rotations, 0, 1), 9)
        translations = np.dot(self.symops[3::4], np.linalg.inv(abc))
        hall = spglib.get_hall_number_from_symmetry(rotations, translations)
        self.space_group = int(spglib.get_spacegroup_type(hall)['number'])
        # we have conventional cell now
        return self