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 configurationssupported_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 neighborscompute_energy (
bool) – whether to compute energycompute_forces (
bool) – whether to compute forcescompute_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_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
- class kliff.models.model.Model(model_name=None)[source]¶
-
- echo_model_params(filename=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]¶
- Return type:
str
- 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 parametersExample
model.set_params_mutable([“A”, “B”, “sigma”])
- 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.