Esempio n. 1
0
    def run(self, grid_points):
        if grid_points is None:
            (grid_points, grid_weights,
             grid_address) = get_ir_grid_points(self._iso._mesh,
                                                self._primitive)
        else:
            grid_weights = None
        iso_gamma = np.zeros(
            (len(self._sigmas), len(grid_points), len(
                self._iso._temps), len(self._iso._band_indices)),
            dtype="double")
        process = Progress_monitor(len(grid_points))
        for i, gp in enumerate(grid_points):
            process.progress_print(i)
            self._iso.set_grid_point(gp)
            if self._iso._phonon_done is None:
                self._iso._allocate_phonon()
            if self._log_level:
                print "------ Isotope scattering ------"
                print "Grid point: %d" % gp

            for j, sigma in enumerate(self._sigmas):
                self._iso.set_sigma(sigma)
                for k, temp in enumerate(self._temps):
                    self._iso.set_temperature(temp)
                    self._iso.run()
                    iso_gamma[j, i, k] = self._iso.get_gamma()

        for j, sigma in enumerate(self._sigmas):
            if sigma is not None:
                print "Mean isotope scattering rate at sigma=%f:" % sigma
                filename = "iso_gamma-m%d%d%d-s%.2f.hdf5" % (
                    tuple(self._iso._mesh) + (sigma, ))
            else:
                print "Mean isotope scattering rate using Tetrahedra method"
                filename = "iso_gamma-m%d%d%d.hdf5" % (tuple(self._iso._mesh))

            if grid_weights is not None:
                print "%20s %20s" % ("Temperature(K)", "Gamma (THz)")
                for k, temp in enumerate(self._iso._temps):
                    iso_ave = np.sum(np.dot(
                        grid_weights, iso_gamma[j, :,
                                                k])) / grid_weights.sum()
                    print "%20.2f %20.7e" % (temp, iso_ave)
                write_iso_scattering_to_hdf5(iso_gamma[j],
                                             mesh=self._iso._mesh,
                                             temperatures=self._iso._temps,
                                             sigma=sigma,
                                             filename=filename)
            else:  # Grid-point mode
                for k, temp in enumerate(self._iso._temps):
                    print "T=%.2f" % temp
                    for i, gp in enumerate(grid_points):
                        print "  Grid-point: %d" % gp
                        print "    %-20s %-20s" % ("Frequency (THz)",
                                                   "Gamma (THz)")
                        for l in np.arange(self._iso._frequencies.shape[-1]):
                            print "    %-20.4f %-20.4e" % (
                                self._iso._frequencies[gp, l], iso_gamma[j, i,
                                                                         k, l])
Esempio n. 2
0
    def get_matrix_contribution(self,
                                grid_points,
                                frequency_step=1.0,
                                sigmas=[0.1],
                                is_adaptive_sigma=False,
                                filename=None):
        mc = Collision(self._interaction,
                       sigmas=sigmas,
                       is_adaptive_sigma=is_adaptive_sigma,
                       frequencies=self._frequencies,
                       degeneracy=self._degeneracy,
                       write=write_scr,
                       read=read_scr,
                       cutoff_frequency=self._cutfr,
                       cutoff_lifetime=self._cutlt)
        is_sum = False
        if grid_points == None:
            is_sum = True
            if self._is_nosym:  # All grid points
                grid_points = np.arange(np.product(self._mesh))
            else:  # Automatic sampling
                (grid_points, grid_weights,
                 grid_address) = get_ir_grid_points(self._mesh,
                                                    self._primitive)
        matrix_contributions = []
        for gp in grid_points:
            print "# grid %d" % gp
            mc.set_grid_point(gp)
            mc.run_interaction()
            matrix_contributions_temp = []
            for sigma in sigmas:
                mc.set_sigma(sigma)
                max_freq = (np.amax(self._interaction.get_phonons()[0]) * 2 +
                            sigma * 4)
                fpoints = np.arange(0, max_freq + frequency_step / 2,
                                    frequency_step)
                mc.set_fpoints(fpoints)
                mc.run()
                matrix_contribution = mc.get_imag_self_energy()
                matrix_contributions_temp.append(matrix_contribution)
                if not is_sum:
                    write_matrix_contribution(gp,
                                              self._mesh,
                                              fpoints,
                                              matrix_contribution,
                                              sigma=sigma,
                                              filename=filename)
            matrix_contributions.append(matrix_contributions_temp)
        matrix_contributions = np.array(matrix_contributions)

        if is_sum:
            for i, sigma in enumerate(sigmas):
                write_matrix_contribution(None,
                                          self._mesh,
                                          fpoints,
                                          np.sum(matrix_contributions[:, i],
                                                 axis=0),
                                          sigma=sigma,
                                          filename=filename)
Esempio n. 3
0
    def get_linewidth_at_paths(self,
                               ise,
                               sigmas,
                               temperatures,
                               band_paths,
                               is_nu,
                               scattering_class=None,
                               filename=None):

        if self._is_nosym:
            grid_address, grid_mapping =get_grid_address([x + (x % 2 == 0) for x in self._mesh], is_return_map=True)
        else:
            grids, weights, grid_address, grid_mapping = get_ir_grid_points([x + (x % 2 == 0) for x in self._mesh],
                                                                            self._primitive,
                                                                            is_return_map=True)
        qpoints_address=grid_address / np.array(self._mesh, dtype=float)
        print "Paths in reciprocal reduced coordinates:"
        for sigma in sigmas:
            self._sigma = sigma
            lws_paths=[]
            distances=[]
            frequencies=[]
            new_paths = []
            for path in band_paths:
                print "[%5.2f %5.2f %5.2f] --> [%5.2f %5.2f %5.2f]" % (tuple(path[0]) + tuple(path[-1]))
                (new_path,
                 dists,
                freqs,
                lws)=self.path(path,
                              qpoints_address,
                              grid_mapping,
                              ise,
                              temperatures,
                              scattering_class)
                new_paths.append(new_path)
                distances.append(dists)
                frequencies.append(freqs)
                lws_paths.append(lws)
            self._distances=distances
            self._freqs_on_path=frequencies
            self._lws_on_path=lws_paths

            write_linewidth_band_csv(self._mesh,
                                     new_paths,
                                     distances=self._distances,
                                     lws=self._lws_on_path,
                                     band_indices=self._band_indices,
                                     temperatures=temperatures,
                                     frequencies=self._freqs_on_path,
                                     scattering_class=scattering_class,
                                     nu=is_nu,
                                     filename=(("-s%s"%sigma) if sigma is not None else ""))
            self.plot_lw()
Esempio n. 4
0
    def get_linewidth_at_paths(self,
                               ise,
                               sigmas,
                               temperatures,
                               band_paths,
                               is_nu,
                               scattering_class=None,
                               filename=None):

        if self._is_nosym:
            grid_address, grid_mapping = get_grid_address(
                [x + (x % 2 == 0) for x in self._mesh], is_return_map=True)
        else:
            grids, weights, grid_address, grid_mapping = get_ir_grid_points(
                [x + (x % 2 == 0) for x in self._mesh],
                self._primitive,
                is_return_map=True)
        qpoints_address = grid_address / np.array(self._mesh, dtype=float)
        print "Paths in reciprocal reduced coordinates:"
        for sigma in sigmas:
            self._sigma = sigma
            lws_paths = []
            distances = []
            frequencies = []
            new_paths = []
            for path in band_paths:
                print "[%5.2f %5.2f %5.2f] --> [%5.2f %5.2f %5.2f]" % (
                    tuple(path[0]) + tuple(path[-1]))
                (new_path, dists, freqs,
                 lws) = self.path(path, qpoints_address, grid_mapping, ise,
                                  temperatures, scattering_class)
                new_paths.append(new_path)
                distances.append(dists)
                frequencies.append(freqs)
                lws_paths.append(lws)
            self._distances = distances
            self._freqs_on_path = frequencies
            self._lws_on_path = lws_paths

            write_linewidth_band_csv(
                self._mesh,
                new_paths,
                distances=self._distances,
                lws=self._lws_on_path,
                band_indices=self._band_indices,
                temperatures=temperatures,
                frequencies=self._freqs_on_path,
                scattering_class=scattering_class,
                nu=is_nu,
                filename=(("-s%s" % sigma) if sigma is not None else ""))
            self.plot_lw()
Esempio n. 5
0
    def run(self, grid_points):
        if grid_points is None:
            (grid_points,grid_weights,grid_address)=get_ir_grid_points(self._iso._mesh,self._primitive)
        else:
            grid_weights = None
        iso_gamma=np.zeros((len(self._sigmas), len(grid_points), len(self._iso._temps), len(self._iso._band_indices)), dtype="double")
        process = Progress_monitor(len(grid_points))
        for i,gp in enumerate(grid_points):
            process.progress_print(i)
            self._iso.set_grid_point(gp)
            if self._iso._phonon_done is None:
                self._iso._allocate_phonon()
            if self._log_level:
                print "------ Isotope scattering ------"
                print "Grid point: %d" % gp

            for j, sigma in enumerate(self._sigmas):
                self._iso.set_sigma(sigma)
                for k, temp in enumerate(self._temps):
                    self._iso.set_temperature(temp)
                    self._iso.run()
                    iso_gamma[j,i,k]=self._iso.get_gamma()

        for j, sigma in enumerate(self._sigmas):
            if sigma is not None:
                print "Mean isotope scattering rate at sigma=%f:"%sigma
                filename = "iso_gamma-m%d%d%d-s%.2f.hdf5" %(tuple(self._iso._mesh)+(sigma,))
            else:
                print "Mean isotope scattering rate using Tetrahedra method"
                filename = "iso_gamma-m%d%d%d.hdf5" %(tuple(self._iso._mesh))

            if grid_weights is not None:
                print "%20s %20s" %("Temperature(K)", "Gamma (THz)")
                for k, temp in enumerate(self._iso._temps):
                    iso_ave = np.sum(np.dot(grid_weights, iso_gamma[j,:,k])) / grid_weights.sum()
                    print "%20.2f %20.7e" %(temp, iso_ave)
                write_iso_scattering_to_hdf5(iso_gamma[j],
                                             mesh=self._iso._mesh,
                                             temperatures=self._iso._temps,
                                             sigma=sigma,
                                             filename=filename)
            else: # Grid-point mode
                for k, temp in enumerate(self._iso._temps):
                    print "T=%.2f" %temp
                    for i,gp in enumerate(grid_points):
                        print "  Grid-point: %d" %gp
                        print  "    %-20s %-20s" %("Frequency (THz)", "Gamma (THz)")
                        for l in np.arange(self._iso._frequencies.shape[-1]):
                            print "    %-20.4f %-20.4e" %(self._iso._frequencies[gp, l], iso_gamma[j, i, k, l])
Esempio n. 6
0
    def set_grid_points(self):
        if self._is_nosym: # All grid points
            self._grid_points = np.arange(np.prod(self._mesh),
                                           dtype='intc')
            self._grid_weights = np.ones(len(self.grid_points), dtype='intc')

        else: # Automatic sampling
            (grid_points,
             grid_weights,
             grid_address) = get_ir_grid_points(
                self._mesh,
                self._primitive,
                mesh_shifts=[False, False, False])
            self._grid_points = grid_points
            self._grid_weights = grid_weights
Esempio n. 7
0
    def _get_ir_grid_points(self):
        if self._coarse_mesh_shifts is None:
            mesh_shifts = [False, False, False]
        else:
            mesh_shifts = self._coarse_mesh_shifts
        (coarse_grid_points, coarse_grid_weights,
         coarse_grid_address) = get_ir_grid_points(self._coarse_mesh,
                                                   self._primitive,
                                                   mesh_shifts=mesh_shifts)
        grid_points = from_coarse_to_dense_grid_points(
            self._mesh,
            self._mesh_divisors,
            coarse_grid_points,
            coarse_grid_address,
            coarse_mesh_shifts=self._coarse_mesh_shifts)
        grid_weights = coarse_grid_weights

        assert grid_weights.sum() == np.prod(self._mesh / self._mesh_divisors)

        return grid_points, grid_weights
Esempio n. 8
0
    def _get_ir_grid_points(self):
        if self._coarse_mesh_shifts is None:
            mesh_shifts = [False, False, False]
        else:
            mesh_shifts = self._coarse_mesh_shifts
        (coarse_grid_points, coarse_grid_weights, coarse_grid_address,
         _) = get_ir_grid_points(self._coarse_mesh,
                                 self._symmetry.get_pointgroup_operations(),
                                 mesh_shifts=mesh_shifts)
        grid_points = from_coarse_to_dense_grid_points(
            self._mesh,
            self._mesh_divisors,
            coarse_grid_points,
            coarse_grid_address,
            coarse_mesh_shifts=self._coarse_mesh_shifts)
        grid_weights = coarse_grid_weights

        assert grid_weights.sum() == np.prod(self._mesh // self._mesh_divisors)

        return grid_points, grid_weights
Esempio n. 9
0
    def _get_ir_grid_points(self):
        if self._coarse_mesh_shifts is None:
            mesh_shifts = [False, False, False]
        else:
            mesh_shifts = self._coarse_mesh_shifts
        (coarse_grid_points,
         coarse_grid_weights,
         coarse_grid_address, _) = get_ir_grid_points(
             self._coarse_mesh,
             self._symmetry.get_pointgroup_operations(),
             mesh_shifts=mesh_shifts)
        grid_points = from_coarse_to_dense_grid_points(
            self._mesh,
            self._mesh_divisors,
            coarse_grid_points,
            coarse_grid_address,
            coarse_mesh_shifts=self._coarse_mesh_shifts)
        grid_weights = coarse_grid_weights

        assert grid_weights.sum() == np.prod(self._mesh // self._mesh_divisors)

        return grid_points, grid_weights
Esempio n. 10
0
    def get_matrix_contribution(self,
                                grid_points,
                                frequency_step=1.0,
                                sigmas=[0.1],
                                is_adaptive_sigma=False,
                                filename=None):
        mc = Collision(self._interaction,
                            sigmas=sigmas,
                            is_adaptive_sigma=is_adaptive_sigma,
                            frequencies = self._frequencies,
                            degeneracy=self._degeneracy,
                            write=write_scr,
                            read=read_scr,
                            cutoff_frequency=self._cutfr,
                            cutoff_lifetime=self._cutlt)
        is_sum = False
        if grid_points == None:
            is_sum = True
            if self._is_nosym: # All grid points
                grid_points = np.arange(np.product(self._mesh))
            else: # Automatic sampling
                (grid_points,
                 grid_weights,
                 grid_address) = get_ir_grid_points(
                    self._mesh,
                    self._primitive)
        matrix_contributions = []
        for gp in grid_points:
            print "# grid %d" %gp
            mc.set_grid_point(gp)
            mc.run_interaction()
            matrix_contributions_temp = []
            for sigma in sigmas:
                mc.set_sigma(sigma)
                max_freq = (np.amax(self._interaction.get_phonons()[0]) * 2
                            + sigma * 4)
                fpoints = np.arange(0, max_freq + frequency_step / 2,
                                    frequency_step)
                mc.set_fpoints(fpoints)
                mc.run()
                matrix_contribution = mc.get_imag_self_energy()
                matrix_contributions_temp.append(matrix_contribution)
                if not is_sum:
                    write_matrix_contribution(
                                gp,
                                self._mesh,
                                fpoints,
                                matrix_contribution,
                                sigma=sigma,
                                filename=filename)
            matrix_contributions.append(matrix_contributions_temp)
        matrix_contributions = np.array(matrix_contributions)

        if is_sum:
            for i, sigma in enumerate(sigmas):
                write_matrix_contribution(
                                    None,
                                    self._mesh,
                                    fpoints,
                                    np.sum(matrix_contributions[:,i], axis=0),
                                    sigma=sigma,
                                    filename=filename)