kliff.models.model

class kliff.models.model.ComputeArguments(conf, supported_species, influence_distance, compute_energy=True, compute_forces=True, compute_stress=False)[source]

Compute property (e.g. energy, forces, and stress) for a configuration.

This is the base class for other compute arguments. Typically, a user will not directly use this.

Parameters:
  • conf (Configuration) – atomic configurations

  • supported_species (Dict[str, int]) – species supported by the potential model, with chemical symbol as key and integer code as value.

  • influence_distance (float) – influence distance (aka cutoff distance) to calculate neighbors

  • compute_energy (bool) – whether to compute energy

  • compute_forces (bool) – whether to compute forces

  • compute_stress (bool) – whether to compute stress

implemented_property = []
compute(params)[source]

Compute the properties required by the compute flags, and store them in self.results.

Parameters:

params (Dict[str, Parameter]) – the parameters of the model.

Example

energy = a_func_to_compute_energy() forces = a_func_to_compute_forces() stress = a_func_to_compute_stress() self.results[‘energy’] = energy self.results[‘forces’] = forces self.results[‘stress’] = stress

get_compute_flag(name)[source]

Check whether the model is asked to compute property.

Parameters:

name (str) – name of the property, e.g. energy, forces, and stresses

Return type:

bool

get_property(name)[source]

Get a property by name.

Parameters:

name (str) – name of the property, e.g. energy, forces, and stresses

Return type:

Any

get_energy()[source]

Potential energy.

Return type:

float

get_forces()[source]

2D array of shape (N,3) of the forces on atoms, where N is the number of atoms in the configuration.

Return type:

ndarray

get_stress()[source]

1D array of the virial stress, in Voigt notation.

Return type:

ndarray

get_prediction()[source]

1D array of prediction from the model for the configuration.

Return type:

ndarray

get_reference()[source]

1D array of reference values for the configuration.

Return type:

ndarray

class kliff.models.model.Model(model_name=None)[source]
init_model_params(*args, **kwargs)[source]
Return type:

Dict[str, Parameter]

init_influence_distance(*args, **kwargs)[source]
Return type:

float

init_supported_species(*args, **kwargs)[source]
Return type:

Dict[str, int]

get_compute_argument_class()[source]
write_kim_model(path=None)[source]
get_influence_distance()[source]
Return type:

float

get_supported_species()[source]
Return type:

Dict[str, int]

get_model_params()[source]
Return type:

Dict[str, Parameter]

echo_model_params(filename=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]
Return type:

str

read_opt_params(filename)[source]
set_params_mutable(list_of_params)[source]

Set all the optimizable parameters from list of names of parameters :type list_of_params: List[str] :param list_of_params: List of string names of parameters

Example

model.set_params_mutable([“A”, “B”, “sigma”])

set_opt_params(**kwargs)[source]
set_one_opt_param(name, settings)[source]
echo_opt_params(filename=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]

Echo the optimizing parameter to a file.

get_num_opt_params()[source]

Count and return number of optimizable parameters. Utilizes Parameter class.

Return type:

int

get_opt_params()[source]

Get optimizable parameters, concatenated as a single numpy array. Obtained numpy array is the state for the optimizer to optimize. Utilizes Parameter class.

Return type:

ndarray

update_model_params(params)[source]

Copy and update the parameter from incoming params array. This method utilizes the parameters internal function to copy the parameter in a consistent manner.

Parameters:

params (Union[ndarray, List[Union[float, int, Parameter]]]) – numpy array with the shape of optimized parameter concatenated array.

get_opt_param_name_value_and_indices(index)[source]
Return type:

Tuple[str, Union[float, ndarray], int]

get_formatted_param_bounds()[source]

Get the lower and upper bounds of optimizing parameters, to be supplied directly to the scipy optimizer.

Return type:

Tuple[Tuple[int, int]]

Returns:

tuple with bounds values. Unbound variables are provided with value (None, None)

opt_params_has_bounds()[source]

Whether bounds are set for any of the parameters.

Return type:

bool

Returns:

boolean true if any of the parameters are marked mutable.

save(filename='trained_model.yaml')[source]

Save a model to disk.

Parameters:

filename (Path) – Path where to store the model.

load(filename='trained_model.yaml')[source]

Load a model on disk into memory.

Parameters:

filename (Path) – Path where the model is stored.

named_parameters()[source]

Get a dict of parameters that are marked as mutable, and hence can be optimized. The parameter values are subjected to change as per the transformations applied.

Returns:

Dictionary of parameters (~kliff.models.parameters.Parameter)

parameters()[source]

Get a list of parameters that are marked as mutable, and hence can be optimized.

Returns:

List of parameters (~kliff.models.parameters.Parameter)

exception kliff.models.model.ModelError(msg)[source]