Esempio n. 1
0
File: run.py Progetto: gmp007/amset
    def run(self,
            directory: Union[str, Path] = '.',
            prefix: Optional[str] = None,
            return_usage_stats: bool = False):
        mem_usage, (amset_data,
                    usage_stats) = memory_usage(partial(self._run_wrapper,
                                                        directory=directory,
                                                        prefix=prefix),
                                                max_usage=True,
                                                retval=True,
                                                interval=.1,
                                                include_children=False,
                                                multiprocess=True)

        log_banner("END")

        logger.info("Timing and memory usage:")
        timing_info = [
            "{} time: {:.4f} s".format(name, t)
            for name, t in usage_stats.items()
        ]
        log_list(timing_info + ["max memory: {:.1f} MB".format(mem_usage[0])])

        now = datetime.datetime.now()
        logger.info("amset exiting on {} at {}".format(
            now.strftime("%d %b %Y"), now.strftime("%H:%M")))

        if return_usage_stats:
            usage_stats["max memory"] = mem_usage[0]
            return amset_data, usage_stats

        else:
            return amset_data
Esempio n. 2
0
def _log_settings(runner: AmsetRunner):
    log_banner("SETTINGS")

    logger.info("Run parameters:")
    run_params = [
        "doping: {}".format(", ".join(map("{:g}".format, runner.doping))),
        "temperatures: {}".format(", ".join(map(str, runner.temperatures))),
        "interpolation_factor: {}".format(runner.interpolation_factor),
        "scattering_type: {}".format(runner.scattering_type),
        "soc: {}".format(runner.soc)
    ]

    if runner.user_bandgap:
        run_params.append("bandgap: {}".format(runner.user_bandgap))

    if runner.scissor:
        run_params.append("scissor: {}".format(runner.scissor))

    log_list(run_params)

    logger.info("Performance parameters:")
    log_list([
        "{}: {}".format(k, v)
        for k, v in runner.performance_parameters.items()
    ])

    logger.info("Output parameters:")
    log_list(
        ["{}: {}".format(k, v) for k, v in runner.output_parameters.items()])

    logger.info("Material properties:")
    log_list([
        "{}: {}".format(k, v) for k, v in runner.material_properties.items()
        if v is not None
    ])
Esempio n. 3
0
File: run.py Progetto: gmp007/amset
def _log_band_structure_information(band_structure: BandStructure):
    log_banner("BAND STRUCTURE")

    logger.info("Input band structure information:")
    log_list([
        "# bands: {}".format(band_structure.nb_bands),
        "# k-points: {}".format(len(band_structure.kpoints)),
        "Fermi level: {:.3f} eV".format(band_structure.efermi),
        "spin polarized: {}".format(band_structure.is_spin_polarized),
        "metallic: {}".format(band_structure.is_metal())
    ])

    if band_structure.is_metal():
        return

    logger.info("Band gap:")
    band_gap_info = []

    bg_data = band_structure.get_band_gap()
    if not bg_data['direct']:
        band_gap_info.append('indirect band gap: {:.3f} eV'.format(
            bg_data['energy']))

    direct_data = band_structure.get_direct_band_gap_dict()
    direct_bg = min((spin_data['value'] for spin_data in direct_data.values()))
    band_gap_info.append('direct band gap: {:.3f} eV'.format(direct_bg))

    direct_kpoint = []
    for spin, spin_data in direct_data.items():
        direct_kindex = spin_data['kpoint_index']
        direct_kpoint.append(
            _kpt_str.format(
                k=band_structure.kpoints[direct_kindex].frac_coords))

    band_gap_info.append("direct k-point: {}".format(", ".join(direct_kpoint)))
    log_list(band_gap_info)

    vbm_data = band_structure.get_vbm()
    cbm_data = band_structure.get_cbm()

    logger.info('Valence band maximum:')
    _log_band_edge_information(band_structure, vbm_data)

    logger.info('Conduction band minimum:')
    _log_band_edge_information(band_structure, cbm_data)
Esempio n. 4
0
File: run.py Progetto: gmp007/amset
def _log_structure_information(structure: Structure, symprec):
    log_banner("STRUCTURE")
    logger.info("Structure information:")

    formula = structure.composition.get_reduced_formula_and_factor(
        iupac_ordering=True)[0]

    if not symprec:
        symprec = 0.01

    sga = SpacegroupAnalyzer(structure, symprec=symprec)
    log_list([
        "formula: {}".format(unicodeify(formula)),
        "# sites: {}".format(structure.num_sites), "space group: {}".format(
            unicodeify_spacegroup(sga.get_space_group_symbol()))
    ])

    logger.info("Lattice:")
    log_list([
        "a, b, c [Å]: {:.2f}, {:.2f}, {:.2f}".format(*structure.lattice.abc),
        "α, β, γ [°]: {:.0f}, {:.0f}, {:.0f}".format(*structure.lattice.angles)
    ])
Esempio n. 5
0
File: run.py Progetto: gmp007/amset
    def _run_wrapper(self,
                     directory: Union[str, Path] = '.',
                     prefix: Optional[str] = None):
        tt = time.perf_counter()
        _log_amset_intro()
        _log_settings(self)
        _log_structure_information(self._band_structure.structure,
                                   self.performance_parameters["symprec"])
        _log_band_structure_information(self._band_structure)

        log_banner("INTERPOLATION")
        t0 = time.perf_counter()

        interpolater = Interpolater(
            self._band_structure,
            num_electrons=self._num_electrons,
            interpolation_factor=self.
            interpolation_parameters["interpolation_factor"],
            soc=self.soc,
            interpolate_projections=True)

        if self.interpolation_parameters["kpoints"]:
            amset_data = interpolater.get_amset_data_from_kpoints(
                self.interpolation_parameters["kpoints"],
                energy_cutoff=self.performance_parameters["energy_cutoff"],
                scissor=self.scissor,
                bandgap=self.user_bandgap,
                symprec=self.performance_parameters["symprec"])
        else:
            amset_data = interpolater.get_amset_data(
                energy_cutoff=self.performance_parameters["energy_cutoff"],
                scissor=self.scissor,
                bandgap=self.user_bandgap,
                symprec=self.performance_parameters["symprec"],
                nworkers=self.performance_parameters["nworkers"])

        timing = {"interpolation": time.perf_counter() - t0}

        if (self.material_properties["pop_frequency"] and
            ("POP" in self.scattering_type or self.scattering_type == "auto")):
            # convert from THz to angular frequency in Hz
            pop_frequency = self.material_properties[
                "pop_frequency"] * 1e12 * 2 * np.pi

            # use the phonon energy to pad the fermi dirac cutoffs, this is because
            # pop scattering from a kpoints, k, to kpoints with energies above and below
            # k. We therefore need k-points above and below to be within the cut-offs
            # otherwise scattering cannot occur
            cutoff_pad = pop_frequency * hbar * units.eV
        else:
            cutoff_pad = 0

        log_banner("DOS")
        amset_data.calculate_dos(
            estep=self.performance_parameters["dos_estep"])
        amset_data.set_doping_and_temperatures(self.doping, self.temperatures)
        amset_data.calculate_fd_cutoffs(self.performance_parameters["fd_tol"],
                                        cutoff_pad=cutoff_pad)

        if self.interpolation_parameters["fine_mesh_de"]:
            log_banner("DENSIFICATION")

            inv_screening_length_sq = None
            if (self.interpolation_parameters["use_imp_minimum_mesh"]
                    and self.material_properties["static_dielectric"]
                    and ("IMP" in self.scattering_type
                         or self.scattering_type == "auto")):
                inv_screening_length_sq = np.min(
                    calculate_inverse_screening_length_sq(
                        amset_data,
                        self.material_properties["static_dielectric"]))

            densifier = BandDensifier(
                interpolater,
                amset_data,
                energy_cutoff=self.performance_parameters["energy_cutoff"],
                dos_estep=self.performance_parameters["dos_estep"],
                inverse_screening_length_sq=inv_screening_length_sq)
            amset_data.set_extra_kpoints(*densifier.densify(
                self.interpolation_parameters["fine_mesh_de"]))

            # recalculate DOS and Fermi levels using denser band structure
            amset_data.calculate_dos(
                estep=self.performance_parameters["dos_estep"])
            amset_data.set_doping_and_temperatures(self.doping,
                                                   self.temperatures)
            amset_data.calculate_fd_cutoffs(
                self.performance_parameters["fd_tol"], cutoff_pad=cutoff_pad)

        log_banner("SCATTERING")
        t0 = time.perf_counter()

        scatter = ScatteringCalculator(
            self.material_properties,
            amset_data,
            scattering_type=self.scattering_type,
            gauss_width=self.performance_parameters["gauss_width"],
            g_tol=self.performance_parameters["ibte_tol"],
            max_g_iter=self.performance_parameters["max_ibte_iter"],
            use_symmetry=self.performance_parameters["symprec"] is not None,
            nworkers=self.performance_parameters["nworkers"])

        amset_data.set_scattering_rates(scatter.calculate_scattering_rates(),
                                        scatter.scatterer_labels)

        timing["scattering"] = time.perf_counter() - t0

        log_banner('TRANSPORT')
        t0 = time.perf_counter()

        solver = TransportCalculator(
            separate_scattering_mobilities=self.
            output_parameters["separate_scattering_mobilities"],
            calculate_mobility=self.output_parameters["calculate_mobility"])
        (amset_data.conductivity, amset_data.seebeck,
         amset_data.electronic_thermal_conductivity,
         amset_data.mobility) = solver.solve_bte(amset_data)

        timing["transport"] = time.perf_counter() - t0

        log_banner('RESULTS')
        _log_results_summary(amset_data, self.output_parameters)

        abs_dir = os.path.abspath(directory)
        logger.info("Writing results to {}".format(abs_dir))
        t0 = time.perf_counter()

        if not os.path.exists(abs_dir):
            os.makedirs(abs_dir)

        if self.output_parameters["write_input"]:
            self.write_settings(abs_dir)

        amset_data.to_file(directory=abs_dir,
                           write_mesh=self.output_parameters["write_mesh"],
                           prefix=prefix,
                           file_format=self.output_parameters["file_format"])

        timing["writing"] = time.perf_counter() - t0
        timing["total"] = time.perf_counter() - tt

        return amset_data, timing
Esempio n. 6
0
    def _run_wrapper(self,
                     directory: Union[str, Path] = '.',
                     prefix: Optional[str] = None):
        tt = time.perf_counter()
        _log_amset_intro()
        _log_settings(self)
        _log_structure_information(self._band_structure.structure,
                                   self.performance_parameters["symprec"])
        _log_band_structure_information(self._band_structure)

        log_banner("INTERPOLATION")
        t0 = time.perf_counter()

        interpolater = Interpolater(
            self._band_structure,
            num_electrons=self._num_electrons,
            interpolation_factor=self.interpolation_factor,
            soc=self.soc,
            interpolate_projections=True)

        amset_data = interpolater.get_amset_data(
            energy_cutoff=self.performance_parameters["energy_cutoff"],
            scissor=self.scissor,
            bandgap=self.user_bandgap,
            symprec=self.performance_parameters["symprec"],
            nworkers=self.performance_parameters["nworkers"])

        timing = {"interpolation": time.perf_counter() - t0}

        log_banner("DOS")
        amset_data.calculate_dos(
            dos_estep=self.performance_parameters["dos_estep"],
            dos_width=self.performance_parameters["dos_width"])
        amset_data.set_doping_and_temperatures(self.doping, self.temperatures)

        if self.num_extra_kpoints:
            log_banner("DENSIFICATION")

            densifier = BandDensifier(
                interpolater,
                amset_data,
                scissor=self.scissor,
                bandgap=self.user_bandgap,
                energy_cutoff=self.performance_parameters["energy_cutoff"],
                dos_estep=self.performance_parameters["dos_estep"])
            amset_data.set_extra_kpoints(
                *densifier.densify(self.num_extra_kpoints))

        log_banner("SCATTERING")
        t0 = time.perf_counter()

        scatter = ScatteringCalculator(
            self.material_properties,
            amset_data,
            scattering_type=self.scattering_type,
            gauss_width=self.performance_parameters["gauss_width"],
            fd_tol=self.performance_parameters["fd_tol"],
            g_tol=self.performance_parameters["ibte_tol"],
            max_g_iter=self.performance_parameters["max_ibte_iter"],
            use_symmetry=self.performance_parameters["symprec"] is not None,
            nworkers=self.performance_parameters["nworkers"])

        amset_data.set_scattering_rates(scatter.calculate_scattering_rates(),
                                        scatter.scatterer_labels)

        timing["scattering"] = time.perf_counter() - t0

        log_banner('TRANSPORT')
        t0 = time.perf_counter()

        solver = TransportCalculator(
            separate_scattering_mobilities=self.
            output_parameters["separate_scattering_mobilities"],
            calculate_mobility=self.output_parameters["calculate_mobility"])
        (amset_data.conductivity, amset_data.seebeck,
         amset_data.electronic_thermal_conductivity,
         amset_data.mobility) = solver.solve_bte(amset_data)

        timing["transport"] = time.perf_counter() - t0

        log_banner('RESULTS')
        _log_results_summary(amset_data, self.output_parameters)

        abs_dir = os.path.abspath(directory)
        logger.info("Writing results to {}".format(abs_dir))
        t0 = time.perf_counter()

        if not os.path.exists(abs_dir):
            os.makedirs(abs_dir)

        if self.output_parameters["write_input"]:
            self.write_settings(abs_dir)

        amset_data.to_file(directory=abs_dir,
                           write_mesh=self.output_parameters["write_mesh"],
                           prefix=prefix,
                           file_format=self.output_parameters["file_format"])

        timing["writing"] = time.perf_counter() - t0
        timing["total"] = time.perf_counter() - tt

        return amset_data, timing