Example #1
0
    def set_grid_point(self, grid_point, stores_triplets_map=False):
        reciprocal_lattice = np.linalg.inv(self._primitive.get_cell())
        if not self._is_mesh_symmetry:
            (triplets_at_q, weights_at_q, grid_address, bz_map,
             triplets_map_at_q, ir_map_at_q) = get_nosym_triplets_at_q(
                 grid_point,
                 self._mesh,
                 reciprocal_lattice,
                 stores_triplets_map=stores_triplets_map)
        else:
            (triplets_at_q, weights_at_q, grid_address, bz_map,
             triplets_map_at_q, ir_map_at_q) = get_triplets_at_q(
                 grid_point,
                 self._mesh,
                 self._symmetry.get_pointgroup_operations(),
                 reciprocal_lattice,
                 stores_triplets_map=stores_triplets_map)

        # Special treatment of symmetry is applied when q_direction is used.
        if self._nac_q_direction is not None:
            if (grid_address[grid_point] == 0).all():
                rotations = []
                for r in self._symmetry.get_pointgroup_operations():
                    dq = self._nac_q_direction
                    dq /= np.linalg.norm(dq)
                    diff = np.dot(dq, r) - dq
                    if (abs(diff) < 1e-5).all():
                        rotations.append(r)
                (triplets_at_q, weights_at_q, grid_address, bz_map,
                 triplets_map_at_q, ir_map_at_q) = get_triplets_at_q(
                     grid_point,
                     self._mesh,
                     np.array(rotations, dtype='intc', order='C'),
                     reciprocal_lattice,
                     is_time_reversal=False,
                     stores_triplets_map=stores_triplets_map)

        for triplet in triplets_at_q:
            sum_q = (grid_address[triplet]).sum(axis=0)
            if (sum_q % self._mesh != 0).any():
                print("============= Warning ==================")
                print("%s" % triplet)
                for tp in triplet:
                    print("%s %s" %
                          (grid_address[tp],
                           np.linalg.norm(
                               np.dot(
                                   reciprocal_lattice, grid_address[tp] /
                                   self._mesh.astype('double')))))
                print("%s" % sum_q)
                print("============= Warning ==================")

        self._grid_point = grid_point
        self._triplets_at_q = triplets_at_q
        self._weights_at_q = weights_at_q
        self._triplets_map_at_q = triplets_map_at_q
        self._grid_address = grid_address
        self._bz_map = bz_map
        self._ir_map_at_q = ir_map_at_q
        self.set_phonons(self._triplets_at_q.ravel())
Example #2
0
 def _set_triplets(self):
     if not self._is_mesh_symmetry:
         if self._log_level:
             print("Triplets at q without considering symmetry")
             sys.stdout.flush()
         
         (self._triplets_at_q,
          self._weights_at_q,
          self._grid_address,
          self._bz_map,
          map_triplets,
          map_q) = get_nosym_triplets_at_q(
              self._grid_point,
              self._mesh,
              self._reciprocal_lattice,
              with_bz_map=True)
     else:
         (self._triplets_at_q,
          self._weights_at_q,
          self._grid_address,
          self._bz_map,
          map_triplets,
          map_q) = get_triplets_at_q(
              self._grid_point,
              self._mesh,
              self._symmetry.get_pointgroup_operations(),
              self._reciprocal_lattice)
Example #3
0
    def _set_triplets(self):
        if not self._is_mesh_symmetry:
            if self._log_level:
                print("Triplets at q without considering symmetry")
                sys.stdout.flush()

            (self._triplets_at_q, self._weights_at_q, _,
             _) = get_nosym_triplets_at_q(self._grid_point, self._bz_grid)
        else:
            (self._triplets_at_q, self._weights_at_q, _,
             _) = get_triplets_at_q(self._grid_point, self._bz_grid)
Example #4
0
def test_get_triplets_at_q_type1(si_pbesol_111):
    """Test triplets under type1 grid."""
    pcell = si_pbesol_111.primitive
    psym = si_pbesol_111.primitive_symmetry
    grid_point = 1
    mesh = [4, 4, 4]

    bz_grid = BZGrid(
        mesh,
        lattice=pcell.cell,
        symmetry_dataset=psym.dataset,
        store_dense_gp_map=False,
    )
    triplets, weights = get_triplets_at_q(grid_point, bz_grid)[:2]
    triplets_ref = [
        1,
        0,
        3,
        1,
        1,
        2,
        1,
        4,
        15,
        1,
        5,
        14,
        1,
        6,
        13,
        1,
        7,
        12,
        1,
        65,
        11,
        1,
        9,
        10,
        1,
        24,
        59,
        1,
        26,
        88,
    ]
    weights_ref = [2, 2, 6, 6, 6, 6, 6, 6, 12, 12]
    # print("".join(["%d, " % i for i in triplets.ravel()]))
    # print("".join(["%d, " % i for i in weights]))
    _show_triplets_info(mesh, bz_grid, triplets, np.linalg.inv(pcell.cell))

    np.testing.assert_equal(triplets.ravel(), triplets_ref)
    np.testing.assert_equal(weights, weights_ref)
Example #5
0
    def set_grid_point(self, grid_point, stores_triplets_map=False):
        reciprocal_lattice = np.linalg.inv(self._primitive.get_cell())
        if not self._is_mesh_symmetry:
            (triplets_at_q, weights_at_q, grid_address, bz_map,
             triplets_map_at_q, ir_map_at_q) = get_nosym_triplets_at_q(
                 grid_point,
                 self._mesh,
                 reciprocal_lattice,
                 stores_triplets_map=stores_triplets_map)
        else:
            (triplets_at_q, weights_at_q, grid_address, bz_map,
             triplets_map_at_q, ir_map_at_q) = get_triplets_at_q(
                 grid_point,
                 self._mesh,
                 self._symmetry.get_pointgroup_operations(),
                 reciprocal_lattice,
                 stores_triplets_map=stores_triplets_map)

        for triplet in triplets_at_q:
            sum_q = (grid_address[triplet]).sum(axis=0)
            if (sum_q % self._mesh != 0).any():
                print("============= Warning ==================")
                print("%s" % triplet)
                for tp in triplet:
                    print("%s %s" %
                          (grid_address[tp],
                           np.linalg.norm(
                               np.dot(
                                   reciprocal_lattice, grid_address[tp] /
                                   self._mesh.astype('double')))))
                print("%s" % sum_q)
                print("============= Warning ==================")

        self._grid_point = grid_point
        self._triplets_at_q = triplets_at_q
        self._weights_at_q = weights_at_q
        self._triplets_map_at_q = triplets_map_at_q
        self._grid_address = grid_address
        self._bz_map = bz_map
        self._ir_map_at_q = ir_map_at_q
        self.set_phonons(self._triplets_at_q.ravel())
Example #6
0
    def set_grid_point(self, grid_point, store_triplets_map=False):
        """Set grid point and prepare grid point triplets."""
        if not self._is_mesh_symmetry:
            (
                triplets_at_q,
                weights_at_q,
                triplets_map_at_q,
                ir_map_at_q,
            ) = get_nosym_triplets_at_q(grid_point, self._bz_grid)
        else:
            # Special treatment of symmetry is applied when q_direction is used
            # at Gamma point = (0 0 0).
            if (self._bz_grid.addresses[grid_point]
                    == 0).all() and self._nac_q_direction is not None:
                rotations = []
                for i, r in enumerate(self._bz_grid.reciprocal_operations):
                    dq = self._nac_q_direction
                    dq /= np.linalg.norm(dq)
                    diff = np.dot(r, dq) - dq
                    if (abs(diff) < 1e-5).all():
                        rotations.append(self._bz_grid.rotations[i])
                (
                    triplets_at_q,
                    weights_at_q,
                    triplets_map_at_q,
                    ir_map_at_q,
                ) = get_triplets_at_q(
                    grid_point,
                    self._bz_grid,
                    reciprocal_rotations=rotations,
                    is_time_reversal=False,
                )
            else:
                (
                    triplets_at_q,
                    weights_at_q,
                    triplets_map_at_q,
                    ir_map_at_q,
                ) = get_triplets_at_q(grid_point, self._bz_grid)

            # Re-calculate phonon at Gamma-point when q-direction is given.
            if (self._bz_grid.addresses[grid_point] == 0).all():
                self.run_phonon_solver_at_gamma(is_nac=True)
            elif self._done_nac_at_gamma:
                if self._nac_q_direction is None:
                    self.run_phonon_solver_at_gamma()
                else:
                    msg = (
                        "Phonons at Gamma has been calcualted with NAC, "
                        "but ph-ph interaction is expected to calculate at "
                        "non-Gamma point. Setting Interaction.nac_q_direction = "
                        "None, can avoid raising this exception to re-run phonon "
                        "calculation at Gamma without NAC.")
                    raise RuntimeError(msg)

        reciprocal_lattice = np.linalg.inv(self._primitive.cell)
        for triplet in triplets_at_q:
            sum_q = (self._bz_grid.addresses[triplet]).sum(axis=0)
            if (sum_q % self.mesh_numbers != 0).any():
                print("============= Warning ==================")
                print("%s" % triplet)
                for tp in triplet:
                    print("%s %s" % (
                        self._bz_grid.addresses[tp],
                        np.linalg.norm(
                            np.dot(
                                reciprocal_lattice,
                                self._bz_grid.addresses[tp] /
                                self.mesh_numbers.astype("double"),
                            )),
                    ))
                print("%s" % sum_q)
                print("============= Warning ==================")

        self._triplets_at_q = triplets_at_q
        self._weights_at_q = weights_at_q

        if store_triplets_map:
            self._triplets_map_at_q = triplets_map_at_q
            self._ir_map_at_q = ir_map_at_q
Example #7
0
def _get_number_of_triplets(bz_grid, grid_point, swappable=True):
    triplets_at_q = get_triplets_at_q(grid_point, bz_grid,
                                      swappable=swappable)[0]
    return len(triplets_at_q)