Esempio n. 1
0
    def __init__(self,
                 qpoint,
                 distance,
                 dynamical_matrix,
                 unitcell_ideal,
                 primitive_matrix_ideal,
                 factor=VaspToTHz,
                 star="none",
                 mode="eigenvector",
                 verbose=False):

        self._qpoint = qpoint
        self._distance = distance

        self._factor = factor

        self._eigenstates = Eigenstates(
            dynamical_matrix,
            unitcell_ideal,
            primitive_matrix_ideal,
            mode=mode,
            star=star,
            verbose=verbose)

        with h5py.File('point.hdf5', 'w') as f:
            self._hdf5_file = f
            self.run()
Esempio n. 2
0
    def __init__(self,
                 paths,
                 dynamical_matrix,
                 unitcell_ideal,
                 primitive_matrix_ideal,
                 is_eigenvectors=False,
                 is_band_connection=False,
                 group_velocity=None,
                 factor=VaspToTHz,
                 star="none",
                 mode="eigenvector",
                 verbose=False):
        """

        Args:
            dynamical_matrix:
                Dynamical matrix for the (disordered) supercell.
            primitive_ideal_wrt_unitcell:
                Primitive cell w.r.t. the unitcell (not the supercell).
        """
        # ._dynamical_matrix must be assigned for calculating DOS
        # using the tetrahedron method.
        self._dynamical_matrix = dynamical_matrix

        # self._cell is used for write_yaml and _shift_point.
        # This must correspond to the "ideal" primitive cell.
        primitive_ideal_wrt_unitcell = (get_primitive(unitcell_ideal,
                                                      primitive_matrix_ideal))
        self._cell = primitive_ideal_wrt_unitcell

        self._factor = factor
        self._is_eigenvectors = is_eigenvectors
        self._is_band_connection = is_band_connection
        if is_band_connection:
            self._is_eigenvectors = True
        self._group_velocity = group_velocity

        self._paths = [np.array(path) for path in paths]
        self._distances = []
        self._distance = 0.
        self._special_point = [0.]
        self._eigenvalues = None
        self._eigenvectors = None
        self._frequencies = None

        self._star = star
        self._mode = mode

        self._eigenstates = Eigenstates(dynamical_matrix,
                                        unitcell_ideal,
                                        primitive_matrix_ideal,
                                        mode=mode,
                                        star=star,
                                        verbose=verbose)

        with h5py.File('band.hdf5', 'w') as f:
            self._hdf5_file = f
            self._write_hdf5_header()
            self._set_band(verbose=verbose)
Esempio n. 3
0
    def __init__(self,
                 qpoint,
                 distance,
                 dynamical_matrix,
                 unitcell_ideal,
                 primitive_matrix_ideal,
                 density_extractor,
                 factor=VaspToTHz,
                 star="none",
                 mode="eigenvector",
                 verbose=False):

        self._qpoint = qpoint
        self._distance = distance

        self._factor = factor

        self._eigenstates = Eigenstates(dynamical_matrix,
                                        unitcell_ideal,
                                        primitive_matrix_ideal,
                                        mode=mode,
                                        star=star,
                                        verbose=verbose)

        # self._density_extractor = density_extractor

        # fn_sf_atoms = "spectral_functions_atoms.dat"
        # fn_sf_irs   = "spectral_functions_irs.dat"
        # with open(fn_sf_atoms, "w") as fatoms, open(fn_sf_irs, "w") as firs:
        #     self._file_sf_atoms = fatoms
        #     self._file_sf_irs   = firs

        #     self.run()

        with h5py.File('point.hdf5', 'w') as f:
            self._hdf5_file = f
            self.run()
Esempio n. 4
0
    def __init__(self,
                 dynamical_matrix,
                 unitcell_ideal,
                 primitive_matrix_ideal,
                 mesh,
                 shift=None,
                 is_time_reversal=True,
                 is_mesh_symmetry=True,
                 is_eigenvectors=False,
                 is_gamma_center=False,
                 star="none",
                 group_velocity=None,
                 rotations=None, # Point group operations in real space
                 factor=VaspToTHz,
                 use_lapack_solver=False,
                 mode="eigenvector"):

        self._mesh = np.array(mesh, dtype='intc')
        self._is_eigenvectors = is_eigenvectors
        self._factor = factor

        primitive_ideal_wrt_unitcell = (
            get_primitive(unitcell_ideal, primitive_matrix_ideal))
        self._cell = primitive_ideal_wrt_unitcell

        # ._dynamical_matrix must be assigned for calculating DOS
        # using the tetrahedron method.
        # In the "DOS", this is used to get "primitive".
        # In the "TetrahedronMesh", this is used just as the "Atoms".
        # Currently, we must not use the tetrahedron method,
        # because now we do not give the primitive but the unitcell for the
        # self._dynamical_matrix.
        self._dynamical_matrix = dynamical_matrix
        self._use_lapack_solver = use_lapack_solver

        self._gp = GridPoints(self._mesh,
                              np.linalg.inv(self._cell.get_cell()),
                              q_mesh_shift=shift,
                              is_gamma_center=is_gamma_center,
                              is_time_reversal=is_time_reversal,
                              rotations=rotations,
                              is_mesh_symmetry=is_mesh_symmetry)

        self._qpoints = self._gp.get_ir_qpoints()
        self._weights = self._gp.get_ir_grid_weights()

        self._star = star

        self._eigenstates_unfolding = Eigenstates(
            dynamical_matrix,
            unitcell_ideal,
            primitive_matrix_ideal,
            mode=mode,
            star=star,
            verbose=False)

        self._frequencies = None
        self._eigenvalues = None
        self._eigenvectors = None
        self._set_phonon()

        self._group_velocities = None
        if group_velocity is not None:
            self._set_group_velocities(group_velocity)
Esempio n. 5
0
class MeshUnfolding(Mesh):
    def __init__(self,
                 dynamical_matrix,
                 unitcell_ideal,
                 primitive_matrix_ideal,
                 mesh,
                 shift=None,
                 is_time_reversal=True,
                 is_mesh_symmetry=True,
                 is_eigenvectors=False,
                 is_gamma_center=False,
                 star="none",
                 group_velocity=None,
                 rotations=None, # Point group operations in real space
                 factor=VaspToTHz,
                 use_lapack_solver=False,
                 mode="eigenvector"):

        self._mesh = np.array(mesh, dtype='intc')
        self._is_eigenvectors = is_eigenvectors
        self._factor = factor

        primitive_ideal_wrt_unitcell = (
            get_primitive(unitcell_ideal, primitive_matrix_ideal))
        self._cell = primitive_ideal_wrt_unitcell

        # ._dynamical_matrix must be assigned for calculating DOS
        # using the tetrahedron method.
        # In the "DOS", this is used to get "primitive".
        # In the "TetrahedronMesh", this is used just as the "Atoms".
        # Currently, we must not use the tetrahedron method,
        # because now we do not give the primitive but the unitcell for the
        # self._dynamical_matrix.
        self._dynamical_matrix = dynamical_matrix
        self._use_lapack_solver = use_lapack_solver

        self._gp = GridPoints(self._mesh,
                              np.linalg.inv(self._cell.get_cell()),
                              q_mesh_shift=shift,
                              is_gamma_center=is_gamma_center,
                              is_time_reversal=is_time_reversal,
                              rotations=rotations,
                              is_mesh_symmetry=is_mesh_symmetry)

        self._qpoints = self._gp.get_ir_qpoints()
        self._weights = self._gp.get_ir_grid_weights()

        self._star = star

        self._eigenstates_unfolding = Eigenstates(
            dynamical_matrix,
            unitcell_ideal,
            primitive_matrix_ideal,
            mode=mode,
            star=star,
            verbose=False)

        self._frequencies = None
        self._eigenvalues = None
        self._eigenvectors = None
        self._set_phonon()

        self._group_velocities = None
        if group_velocity is not None:
            self._set_group_velocities(group_velocity)

    def get_pr_weights(self):
        return self._pr_weights

    def write_yaml(self):
        w = open('mesh.yaml', 'w')
        eigenvalues = self._eigenvalues
        natom = self._cell.get_number_of_atoms()
        lattice = np.linalg.inv(self._cell.get_cell()) # column vectors
        w.write("mesh: [ %5d, %5d, %5d ]\n" % tuple(self._mesh))
        w.write("nqpoint: %-7d\n" % self._qpoints.shape[0])
        w.write("natom:   %-7d\n" % natom)
        w.write("reciprocal_lattice:\n")
        for vec, axis in zip(lattice.T, ('a*', 'b*', 'c*')):
            w.write("- [ %12.8f, %12.8f, %12.8f ] # %2s\n" %
                    (tuple(vec) + (axis,)))
        w.write("phonon:\n")

        for i, q in enumerate(self._qpoints):
            w.write("- q-position: [ %12.7f, %12.7f, %12.7f ]\n" % tuple(q))
            w.write("  weight: %-5d\n" % self._weights[i])
            w.write("  band:\n")

            for j, freq in enumerate(self._frequencies[i]):
                w.write("  - # %d\n" % (j + 1))
                w.write("    frequency:  %15.10f\n" % freq)
                w.write("    pr_weight:  %15.10f\n" % self._pr_weights[i, j])

                if self._group_velocities is not None:
                    w.write("    group_velocity: ")
                    w.write("[ %13.7f, %13.7f, %13.7f ]\n" %
                            tuple(self._group_velocities[i, j]))

                if self._is_eigenvectors:
                    w.write("    eigenvector:\n")
                    for k in range(natom):
                        w.write("    - # atom %d\n" % (k+1))
                        for l in (0,1,2):
                            w.write("      - [ %17.14f, %17.14f ]\n" %
                                    (self._eigenvectors[i,k*3+l,j].real,
                                     self._eigenvectors[i,k*3+l,j].imag))
            w.write("\n")

    def _set_phonon(self):
        # For the unfolding method.
        # num_band = self._cell.get_number_of_atoms() * 3
        cell = self._dynamical_matrix.get_primitive()
        num_band = cell.get_number_of_atoms() * 3
        num_qpoints = len(self._qpoints)

        self._eigenvalues = np.zeros((num_qpoints, num_band), dtype='double')
        self._frequencies = np.zeros_like(self._eigenvalues)
        # TODO(ikeda): the folling is very bad if we turn on is_star
        self._pr_weights  = np.zeros_like(self._eigenvalues)
        if self._is_eigenvectors or self._use_lapack_solver:
            self._eigenvectors = np.zeros(
                (num_qpoints, num_band, num_band,), dtype='complex128')

        if self._use_lapack_solver:
            print("ERROR: _use_lapack_solver is not considered for this script.")
            raise ValueError
        else:
            for i, q in enumerate(self._qpoints):
                eigvals, eigvecs, self._pr_weights[i], nstar = (
                    self._eigenstates_unfolding.extract_eigenstates(q)
                )
                self._eigenvalues[i] = eigvals.real
                if self._is_eigenvectors:
                    self._eigenvectors[i] = eigvecs
            self._frequencies = np.array(np.sqrt(abs(self._eigenvalues)) *
                                         np.sign(self._eigenvalues),
                                         dtype='double',
                                         order='C') * self._factor