Beispiel #1
0
def write_settings(settings: Dict[str, Any], filename: str):
    """Write amset configuration settings to a formatted yaml file.

    Args:
        settings: The configuration settings.
        filename: A filename.
    """
    settings = cast_dict_list(settings)
    dumpfn(settings, filename, indent=4, default_flow_style=False)
Beispiel #2
0
    def to_dict(self, include_mesh=defaults["write_mesh"]):
        data = {
            "doping": self.doping * cm_to_bohr ** 3,
            "temperatures": self.temperatures,
            "fermi_levels": self.fermi_levels * hartree_to_ev,
            "conductivity": self.conductivity,
            "seebeck": self.seebeck,
            "electronic_thermal_conductivity": self.electronic_thermal_conductivity,
            "mobility": self.mobility,
        }

        if include_mesh:
            rates = self.scattering_rates
            energies = self.energies
            vv = self.velocities_product

            ir_rates = {s: r[..., self.ir_kpoints_idx] for s, r in rates.items()}
            ir_energies = {
                s: e[:, self.ir_kpoints_idx] * hartree_to_ev
                for s, e in energies.items()
            }
            ir_vv = {s: v[..., self.ir_kpoints_idx] for s, v in vv.items()}

            mesh_data = {
                "energies": cast_dict_list(ir_energies),
                "kpoints": self.kpoints,
                "ir_kpoints": self.ir_kpoints,
                "ir_to_full_kpoint_mapping": self.ir_to_full_kpoint_mapping,
                "efermi": self.intrinsic_fermi_level * hartree_to_ev,
                "vb_idx": cast_dict_list(self.vb_idx),
                "dos": self.dos,  # TODO: Convert dos to eV
                "velocities_product": cast_dict_list(ir_vv),  # TODO: convert units
                "scattering_rates": cast_dict_list(ir_rates),
                "scattering_labels": self.scattering_labels,
                "is_metal": self.is_metal,
                "fd_cutoffs": (
                    self.fd_cutoffs[0] * hartree_to_ev,
                    self.fd_cutoffs[1] * hartree_to_ev,
                ),
                "structure": get_angstrom_structure(self.structure),
                "soc": self._soc,
            }
            data.update(mesh_data)
        return data
Beispiel #3
0
    def to_dict(self, include_mesh=defaults["write_mesh"]):
        data = {
            "doping": self.doping,
            "temperatures": self.temperatures,
            "fermi_levels": self.fermi_levels,
            "conductivity": self.conductivity,
            "seebeck": self.seebeck,
            "electronic_thermal_conductivity":
            self.electronic_thermal_conductivity,
            "mobility": self.mobility,
        }

        if include_mesh:
            rates = self.scattering_rates
            energies = self.energies
            ir_rates = {
                s: r[..., self.ir_kpoints_idx]
                for s, r in rates.items()
            }
            ir_energies = {
                s: e[:, self.ir_kpoints_idx]
                for s, e in energies.items()
            }

            mesh_data = {
                "energies": cast_dict_list(ir_energies),
                "kpoints": self.kpoints,
                "ir_kpoints": self.ir_kpoints,
                "ir_to_full_kpoint_mapping": self.ir_to_full_kpoint_mapping,
                "efermi": self.intrinsic_fermi_level,
                "vb_idx": cast_dict_list(self.vb_idx),
                "dos": self.dos,
                "scattering_rates": cast_dict_list(ir_rates),
                "scattering_labels": self.scattering_labels,
                "is_metal": self.is_metal,
                "fd_cutoffs": self.fd_cutoffs,
                "structure": self.structure,
                "soc": self._soc,
            }
            data.update(mesh_data)
        return data
Beispiel #4
0
    def to_file(
        self,
        directory: str = ".",
        prefix: Optional[str] = None,
        write_mesh_file: bool = defaults["write_mesh"],
        file_format: str = defaults["file_format"],
        suffix_mesh: bool = True,
    ):
        if self.conductivity is None:
            raise ValueError(
                "Can't write AmsetData, transport properties not set")

        if not prefix:
            prefix = ""
        else:
            prefix += "_"

        if suffix_mesh:
            suffix = "_{}".format("x".join(map(str, self.kpoint_mesh)))
        else:
            suffix = ""

        if file_format in ["json", "yaml"]:
            data = self.to_dict()
            data = cast_dict_list(data)

            filename = joinpath(
                directory, "{}transport{}.{}".format(prefix, suffix,
                                                     file_format))
            dumpfn(data, filename, indent=4)

        elif file_format in ["csv", "txt"]:
            # don't write the data as JSON, instead write raw text files
            data, headers = self.to_data()
            filename = joinpath(
                directory, "{}transport{}.{}".format(prefix, suffix,
                                                     file_format))
            np.savetxt(filename, data, header=" ".join(headers))

        else:
            raise ValueError(
                "Unrecognised output format: {}".format(file_format))

        if write_mesh_file:
            mesh_data = self.to_dict(include_mesh=True)["mesh"]
            mesh_filename = joinpath(directory,
                                     "{}mesh{}.h5".format(prefix, suffix))
            write_mesh(mesh_data, filename=mesh_filename)
            return filename, mesh_filename
        else:
            return filename
Beispiel #5
0
def test_cast_dict_list(value, expected):
    assert cast_dict_list(value) == expected