def _overlay_s_plams(self, lj: Iterable[Mapping], sigma_dict: MutableMapping, epsilon_dict: MutableMapping) -> None: """Extract PLAMS-style settings from **lj** and put them in **sigma_dict** and **epsilon_dict**.""" # noqa: E501 for block in lj: with Settings.suppress_missing(): atoms = tuple(block['atoms'].split()) try: unit_sigma, sigma = block['sigma'].split() except ValueError: unit_sigma, sigma = '[angstrom]', block['sigma'] except (TypeError, KeyError): unit_sigma = sigma = None try: unit_eps, epsilon = block['epsilon'].split() except ValueError: unit_eps, epsilon = '[kcalmol]', block['sigma'] except (TypeError, KeyError): unit_eps = epsilon = None if sigma is not None: unit_sigma = unit_sigma[1:-1] unit_sigma = self.UNIT_MAPPING.get(unit_sigma, unit_sigma) sigma_dict[unit_sigma][atoms] = float(sigma) if epsilon is not None: unit_eps = unit_eps[1:-1] unit_eps = self.UNIT_MAPPING.get(unit_eps, unit_eps) epsilon_dict[unit_eps][atoms] = float(epsilon)
def from_template(cls, settings: Union[Settings, SettingsDataFrame], name: str) -> 'WorkFlow': """Construct a :class:`WorkFlow` instance from a |plams.Settings| object. Parameters ---------- settings : |plams.Settings| A Settings instance with all CAT settings. Certain values are extracted from **settings** based on the supplied template (see **name**). name : :class:`str` The name of the settings template. See Also -------- :attr:`WorkFlow._WORKFLOW_TEMPLATES` A dictionary with all available template names (*i.e.* its keys). """ # Extract the settings object from the SettingsDataFrame if isinstance(settings, SettingsDataFrame): settings = settings.settings kwargs: Dict[str, Any] = {'name': name} # Raise a KeyError if a key cannot be found with Settings.suppress_missing(): try: # Extract the correct template template = cls._WORKFLOW_TEMPLATES[name]['template'] except KeyError as ex: err = (f"Invalid value for the 'name' parameter: {name!r}\n" f"Allowed values: {', '.join(repr(k) for k in cls._WORKFLOW_TEMPLATES)}") raise ValueError(err) from ex # Create a dictionary with keyword arguments for k, v in template.items(): kwargs[k] = settings.get_nested(v) # Post process all jobs and job settings kwargs['jobs'] = pop_and_concatenate(kwargs, 'job') kwargs['settings'] = pop_and_concatenate(kwargs, 's') return cls.from_dict(kwargs)