Ejemplo n.º 1
0
    def from_directory(
        directory: Union[str, Path] = ".",
        vasprun: Optional[Union[str, Path]] = None,
        settings_file: Optional[Union[str, Path]] = None,
        settings_override: Optional[Dict[str, Any]] = None,
    ):
        if not vasprun:
            vr_file = joinpath(directory, "vasprun.xml")
            vr_file_gz = joinpath(directory, "vasprun.xml.gz")

            if os.path.exists(vr_file):
                vasprun = Vasprun(vr_file, parse_projected_eigen=True)
            elif os.path.exists(vr_file_gz):
                vasprun = Vasprun(vr_file_gz, parse_projected_eigen=True)
            else:
                msg = "No vasprun.xml found in {}".format(directory)
                logger.error(msg)
                raise FileNotFoundError(msg)

        if not settings_file:
            settings_file = joinpath(directory, "settings.yaml")
        settings = load_settings(settings_file)

        if settings_override:
            settings.update(settings_override)

        return Runner.from_vasprun(vasprun, settings)
Ejemplo n.º 2
0
def test_load_settings(test_dir):
    settings = load_settings(test_dir / "amset_settings.yaml")

    # test settings loaded correctly
    assert settings["scissor"] == 3.0
    assert settings["high_frequency_dielectric"].tolist() == [
        [10, 0, 0],
        [0, 10, 0],
        [0, 0, 10],
    ]

    # test defaults inferred correctly
    assert settings["pop_frequency"] == defaults["pop_frequency"]
    assert settings["dos_estep"] == defaults["dos_estep"]
Ejemplo n.º 3
0
    def from_directory(
        directory: Union[str, Path] = ".",
        input_file: Optional[Union[str, Path]] = None,
        settings_file: Optional[Union[str, Path]] = None,
        settings_override: Optional[Dict[str, Any]] = None,
    ):
        """
        Initialize amset Runner from a directory.

        If input_file or settings_file are not specified, the code will look in the
        specified directory for these files.

        Args:
            directory: A directory.
            input_file: An input file path, can either be vasprun.xml(.gz) or a
                band_structure_data.json(.gz) file containing the keys:

                - "nelect" (int): The number of electrons in the system.
                - "band_structure (BandStructure)": A pymatgen band structure object.
            settings_file: Path to settings file.
            settings_override: Settings that will be used to override the settings
                in the settings file.

        Returns:
            A Runner instance that can be used to run amset.
        """
        directory = Path(directory)

        if not settings_file:
            settings_file = directory / "settings.yaml"
        settings = load_settings(settings_file)

        if settings_override:
            settings.update(settings_override)

        run_type, input_file = _get_run_type(directory, input_file)
        if run_type == "vasprun":
            return Runner.from_vasprun(input_file, settings)
        elif run_type == "band_structure":
            data = loadfn(input_file)
            nelect = data["nelect"]
            band_structure = data["band_structure"]
            return Runner(band_structure, nelect, settings)
        else:
            raise ValueError(f"Unrecognised run type: {run_type}")