class matlantis_features.features.common.opt.ASEOptFeature(get_optimizer: Callable[[Atoms], Optimizer], n_run: int = 200, fmax: float = 0.001, attach_methods: Optional[List[Tuple[Callable[[], None], int]]] = None, show_progress_bar: bool = False, tqdm_options: Optional[Dict[str, Any]] = None, show_logger: bool = False, logger_interval: int = 10, filter: Union[bool, MatlantisFilter] = False, estimator_fn: Optional[Callable[[], Estimator]] = None)#

Bases: OptFeatureBase

The matlantis-feature that wraps around an ASE Optimizer object.

Methods

__init__(get_optimizer[, n_run, fmax, …])

Initialize an instance.

__call__(atoms)

Call function.

attach(extn, interval)

Used for attaching a function to the ASE optimizer.

attach_ctx([ctx])

Attach the feature to matlantis_features.utils.Context.

check_estimator_fn(estimator_fn)

Checks if the given estimator function is None and output a warning if so.

cost_estimate([atoms])

Estimate the cost of the feature.

from_dict(res)

Construct a FeatureBase object from serialized dict.

get_savedir_from_ctx()

Get the temporary save directory from the context.

init_scope()

Context manager that enable to set attribution of the feature.

repeat(n_repeat)

Set the maximum number of times that allowed to run the __call__ function.

to_dict()

Dictionary representation of the OptFeatureBase.

__init__(get_optimizer: Callable[[Atoms], Optimizer], n_run: int = 200, fmax: float = 0.001, attach_methods: Optional[List[Tuple[Callable[[], None], int]]] = None, show_progress_bar: bool = False, tqdm_options: Optional[Dict[str, Any]] = None, show_logger: bool = False, logger_interval: int = 10, filter: Union[bool, MatlantisFilter] = False, estimator_fn: Optional[Callable[[], Estimator]] = None)#

Initialize an instance.

Parameters
  • get_optimizer (ASEAtoms -> Optimizer) – A function to get optimizer.

  • n_run (int, optional) – The maximum number of optimization steps performed to try to
    reach force convergence (specified by fmax). Defaults to 200.

  • fmax (float, optional) – The maximum force (in eV/Angstrom) for convergence of optimization.
    Defaults to 0.01.

  • attach_methods (list[tuple[ -> None, int]] or None, optional) – Functions to be called by the optimizer. A list of tuples (or None) must be specified.
    The first element of each tuple is a callable function, and the second element
    is an integer that specifies the interval (in optimization steps) of when
    the optimizer will call the function. If None, no functions will be attached.
    Defaults to None.

  • show_progress_bar (bool, optional) – Show progress bar. Defaults to False.

  • tqdm_options (dict[str, Any] or None, optional) – Options for tqdm.

  • show_logger (bool, optional) – Show log information. Defaults to False.

  • logger_interval (int, optional) – The interval of when to print out logger information.
    Defaults to 10.

  • filter (bool or MatlantisFilter) – The MatlantisFilter used in the optimization. If True, the default filter, i.e.
    UnitCellASEFilter, will be used for the cell shape optimization. If False, no
    filter is used.
    Note: The filter is only applicable in the optimization of ASEAtoms and MatlantisAtoms,
    not NEB class.
    Defaults to False.

  • estimator_fn (EstimatorFnType or None, optional) – A factory method to create a custom estimator.
    Please refer Customizing estimator used in matlantis-features for detail.

__call__(atoms: Union[Atoms, MatlantisAtoms, NEB, Filter]) OptFeatureResult#

Call function.

Parameters

atoms (ASEAtoms or MatlantisAtoms or NEB or Filter) – The system to be optimized. In addition to ASEAtoms and MatlantisAtoms,
NEB (Matlantis) and Filter (ASE) objects are also supported.
Note: the support of ASE Filter class will be deprecated in the future.
Please use the ‘filter’ parameter in the __init__ function.

Returns

A dataclass containing information about the result of optimization.

Return type

OptFeatureResult

attach(extn: Callable[[], None], interval: int) None#

Used for attaching a function to the ASE optimizer.

Parameters
  • extn (-> None) – The function to be attached.

  • interval (int) – The interval (in optimization steps) of when the optimizer will call the function.

attach_ctx(ctx: Optional[Context] = None) None#

Attach the feature to matlantis_features.utils.Context.

Parameters

ctx (Context or None, optional) – The matlantis_features.utils.Context object. Defaults to None.

check_estimator_fn(estimator_fn: Optional[Callable[[], Estimator]]) None#

Checks if the given estimator function is None and output a warning if so.

Parameters

estimator_fn (EstimatorFnType or None, optional) – A factory method to create a custom estimator.
Please refer Customizing estimator used in matlantis-features for detail. Defaults to None.

cost_estimate(atoms: Optional[Union[Atoms, MatlantisAtoms]] = None) FeatureCost#

Estimate the cost of the feature.

Parameters

atoms (ASEAtoms or MatlantisAtoms or None, optional) – The input atoms. Defaults to None.

Returns

The cost of the feature.

Return type

FeatureCost

classmethod from_dict(res: Dict[str, Any]) FeatureBase#

Construct a FeatureBase object from serialized dict.

Parameters

res (dict[str, Any]) – A dict containing a serialized FeatureBase from to_dict().

Returns

The deserialized object from provided dict.

Return type

FeatureBase

get_savedir_from_ctx() Path#

Get the temporary save directory from the context.

Returns

The temporary save directory .

Return type

pathlib.Path

init_scope() Iterator[None]#

Context manager that enable to set attribution of the feature.

Returns

Init_scope context manager.

Return type

Iterator[None]

repeat(n_repeat: int) Self#

Set the maximum number of times that allowed to run the __call__ function.

Parameters

n_repeat (int) – The maximum number of repeats.

Returns

The feature.

Return type

Self

to_dict() Dict[str, Any]#

Dictionary representation of the OptFeatureBase.

Returns

A dict containing a serialized OptFeatureBase.

Return type

dict[str, Any]