def test_validate_settings(settings, expected): if not isinstance(expected, dict): # ensure errors are thrown correctly with expected: validate_settings(settings) else: settings = validate_settings(settings) for name, expected_value in expected.items(): value = settings[name] assert isinstance(settings[name], type(expected_value)) if isinstance(value, np.ndarray): expected_value = expected_value.tolist() value = value.tolist() assert expected_value == value
def __init__( self, band_structure: BandStructure, num_electrons: int, settings: Dict[str, Any], ): self._band_structure = band_structure self._num_electrons = num_electrons # set materials and performance parameters # if the user doesn't specify a value then use the default self.settings = validate_settings(settings)
def load_settings(filename: str) -> Dict[str, Any]: """Load amset configuration settings from a yaml file. If the settings file does not contain a required parameter, the default value will be added to the configuration. An example file is given in *amset/examples/example_settings.yaml*. Args: filename: Path to settings file. Returns: The settings, with any missing values set according to the amset defaults. """ logger.info(f"Loading settings from: {filename}") settings = loadfn(filename) return validate_settings(settings)
def from_vasprun(vasprun: Union[str, Path, Vasprun], settings: Dict[str, Any]) -> "AmsetRunner": """Initialise an AmsetRunner from a Vasprun. The nelect and soc options will be determined from the Vasprun automatically. Args: vasprun: Path to a vasprun or a Vasprun pymatgen object. settings: AMSET settings. Returns: An :obj:`AmsetRunner` instance. """ if not isinstance(vasprun, Vasprun): vasprun = Vasprun(vasprun, parse_projected_eigen=True) band_structure = vasprun.get_band_structure() nelect = vasprun.parameters["NELECT"] settings["soc"] = vasprun.parameters["LSORBIT"] settings = validate_settings(settings) return AmsetRunner(band_structure, nelect, settings)