Example #1
0
    def test_get_stabilized_reciprocal_mesh(self):
        for i in range(len(self.cells)):
            ir_rec_mesh = get_stabilized_reciprocal_mesh(
                self.meshes[i], self.rotations[i], is_dense=False)
            (mapping_table, grid_address) = ir_rec_mesh
            data = np.loadtxt(StringIO(result_ir_rec_mesh[i]), dtype='intc')
            np.testing.assert_equal(data[:, 0], mapping_table)
            np.testing.assert_equal(data[:, 1:4], grid_address)

            ir_rec_mesh = get_stabilized_reciprocal_mesh(
                self.meshes[i], self.rotations[i], is_dense=True)
            (mapping_table, grid_address) = ir_rec_mesh
            np.testing.assert_equal(data[:, 0], mapping_table)
            np.testing.assert_equal(data[:, 1:4], grid_address)
Example #2
0
    def _set_ir_qpoints(self, rotations, is_time_reversal=True):
        grid_mapping_table, grid_address = get_stabilized_reciprocal_mesh(
            self._mesh,
            rotations,
            is_shift=self._is_shift,
            is_time_reversal=is_time_reversal,
            is_dense=True)

        shift = np.array(self._is_shift, dtype='intc') * 0.5

        if self._fit_in_BZ:
            grid_address, _ = relocate_BZ_grid_address(grid_address,
                                                       self._mesh,
                                                       self._rec_lat,
                                                       is_shift=self._is_shift,
                                                       is_dense=True)
            self._grid_address = grid_address[:np.prod(self._mesh)]
        else:
            self._grid_address = grid_address

        (self._ir_grid_points,
         self._ir_weights) = extract_ir_grid_points(grid_mapping_table)

        self._ir_qpoints = np.array(
            (self._grid_address[self._ir_grid_points] + shift) / self._mesh,
            dtype='double',
            order='C')
        self._grid_mapping_table = grid_mapping_table
Example #3
0
    def test_get_stabilized_reciprocal_mesh(self):
        for i in range(len(self.cells)):
            ir_rec_mesh = get_stabilized_reciprocal_mesh(self.meshes[i],
                                                         self.rotations[i],
                                                         is_dense=False)
            (mapping_table, grid_address) = ir_rec_mesh
            data = np.loadtxt(StringIO(result_ir_rec_mesh[i]), dtype='intc')
            np.testing.assert_equal(data[:, 0], mapping_table)
            np.testing.assert_equal(data[:, 1:4], grid_address)

            ir_rec_mesh = get_stabilized_reciprocal_mesh(self.meshes[i],
                                                         self.rotations[i],
                                                         is_dense=True)
            (mapping_table, grid_address) = ir_rec_mesh
            np.testing.assert_equal(data[:, 0], mapping_table)
            np.testing.assert_equal(data[:, 1:4], grid_address)
Example #4
0
    def _testBrillouinZone(self, direct_lat, mesh, is_shift):
        _, grid_address = get_stabilized_reciprocal_mesh(mesh,
                                                         rotations=[
                                                             np.eye(
                                                                 3,
                                                                 dtype='intc'),
                                                         ],
                                                         is_shift=is_shift)
        rec_lat = np.linalg.inv(direct_lat)
        bz_grid_address, bz_map = relocate_BZ_grid_address(grid_address,
                                                           mesh,
                                                           rec_lat,
                                                           is_shift=is_shift)

        qpoints = (grid_address + np.array(is_shift) / 2.0) / mesh
        bz = BrillouinZone(rec_lat)
        bz.run(qpoints)
        sv_all = bz.shortest_qpoints  # including BZ boundary duplicates
        sv = [v[0] for v in sv_all]
        bz_qpoints = (bz_grid_address + np.array(is_shift) / 2.0) / mesh
        d2_this = (np.dot(sv, rec_lat.T)**2).sum(axis=1)
        d2_spglib = (np.dot(bz_qpoints[:np.prod(mesh)],
                            rec_lat.T)**2).sum(axis=1)
        diff = d2_this - d2_spglib
        diff -= np.rint(diff)

        # Following both of two tests are necessary.
        # Check equivalence of vectors by lattice translation
        np.testing.assert_allclose(diff, 0, atol=1e-8)
        # Check being in same (hopefull first) Brillouin zone by their lengths
        np.testing.assert_allclose(d2_this, d2_spglib, atol=1e-8)
Example #5
0
def get_grid_address(mesh):
    grid_mapping_table, grid_address = spglib.get_stabilized_reciprocal_mesh(
        mesh, [[[1, 0, 0], [0, 1, 0], [0, 0, 1]]],
        is_time_reversal=False,
        is_dense=True)

    return grid_address
Example #6
0
 def test_get_stabilized_reciprocal_mesh(self):
     for fname in self._filenames:
         cell = read_vasp("./data/%s" % fname)
         rotations = get_symmetry_from_database(513)['rotations']
         ir_rec_mesh = get_stabilized_reciprocal_mesh(self._mesh, rotations)
         (mapping_table, grid_address) = ir_rec_mesh
         data = np.loadtxt(StringIO(result_ir_rec_mesh), dtype='intc')
         self.assertTrue((data[:, 0] == mapping_table).all())
         self.assertTrue((data[:, 1:4] == grid_address).all())
Example #7
0
def get_ir_grid_points(mesh, rotations, mesh_shifts=None):
    if mesh_shifts is None:
        mesh_shifts = [False, False, False]
    grid_mapping_table, grid_address = spglib.get_stabilized_reciprocal_mesh(
        mesh, rotations, is_shift=np.where(mesh_shifts, 1, 0), is_dense=True)
    (ir_grid_points,
     ir_grid_weights) = extract_ir_grid_points(grid_mapping_table)

    return ir_grid_points, ir_grid_weights, grid_address, grid_mapping_table
 def test_get_stabilized_reciprocal_mesh(self):
     file_and_mesh = (["cubic/POSCAR-217", [4, 4, 4]],
                      ["hexagonal/POSCAR-182", [4, 4, 2]])
     i = 0
     for fname, mesh in file_and_mesh:
         cell = read_vasp("./data/%s" % fname)
         rotations = get_symmetry_dataset(cell)['rotations']
         ir_rec_mesh = get_stabilized_reciprocal_mesh(mesh, rotations)
         (mapping_table, grid_address) = ir_rec_mesh
         data = np.loadtxt(StringIO(result_ir_rec_mesh[i]), dtype='intc')
         np.testing.assert_equal(data[:, 0], mapping_table)
         np.testing.assert_equal(data[:, 1:4], grid_address)
         i += 1
Example #9
0
    def setUp(self):
        identity = np.eye(3, dtype='intc')
        file_and_mesh = (
            [os.path.join(data_dir, "data", "cubic", "POSCAR-217"), [4, 4, 4]],
            [os.path.join(data_dir, "data", "hexagonal", "POSCAR-182"),
             [4, 4, 2]])

        self.meshes = []
        self.cells = []
        self.rotations = []
        self.grid_addresses = []
        for i, (fname, mesh) in enumerate(file_and_mesh):
            self.meshes.append(mesh)
            self.cells.append(read_vasp(fname))
            self.rotations.append(
                get_symmetry_dataset(self.cells[i])['rotations'])
            _, ga = get_stabilized_reciprocal_mesh(mesh, [identity, ])
            self.grid_addresses.append(ga)
Example #10
0
    def _set_ir_qpoints(self, rotations, is_time_reversal=True):
        grid_mapping_table, grid_address = get_stabilized_reciprocal_mesh(
            self._mesh,
            rotations,
            is_shift=self._is_shift,
            is_time_reversal=is_time_reversal,
            is_dense=True,
        )
        # uintp to int_
        grid_mapping_table = np.array(grid_mapping_table, dtype="int_")

        # Currently 'intc', but will be 'int_' in next major version.
        if int(__version__.split(".")[0]) < 3:
            dtype = "intc"
        else:
            dtype = "int_"

        if self._fit_in_BZ:
            grid_address, _ = relocate_BZ_grid_address(
                grid_address,
                self._mesh,
                self._rec_lat,
                is_shift=self._is_shift,
                is_dense=True,
            )
            self._grid_address = np.array(grid_address[:np.prod(self._mesh)],
                                          dtype=dtype,
                                          order="C")
        else:
            self._grid_address = np.array(grid_address, dtype=dtype, order="C")

        (self._ir_grid_points,
         self._ir_weights) = extract_ir_grid_points(grid_mapping_table)

        shift = np.array(self._is_shift) * 0.5
        self._ir_qpoints = np.array(
            (self._grid_address[self._ir_grid_points] + shift) / self._mesh,
            dtype="double",
            order="C",
        )

        self._grid_mapping_table = grid_mapping_table
Example #11
0
    def setUp(self):
        identity = np.eye(3, dtype='intc')
        file_and_mesh = ([
            os.path.join(data_dir, "data", "cubic", "POSCAR-217"), [4, 4, 4]
        ], [
            os.path.join(data_dir, "data", "hexagonal", "POSCAR-182"),
            [4, 4, 2]
        ])

        self.meshes = []
        self.cells = []
        self.rotations = []
        self.grid_addresses = []
        for i, (fname, mesh) in enumerate(file_and_mesh):
            self.meshes.append(mesh)
            self.cells.append(read_vasp(fname))
            self.rotations.append(
                get_symmetry_dataset(self.cells[i])['rotations'])
            _, ga = get_stabilized_reciprocal_mesh(mesh, [
                identity,
            ])
            self.grid_addresses.append(ga)