kliff.models.kim¶
- class kliff.models.kim.KIMComputeArguments(kim_ca, config, supported_species, influence_distance, compute_energy=True, compute_forces=True, compute_stress=False)[source]¶
KIMModel potentials arguments.
- Parameters:
kim_ca – KIM compute argument, can be created by
create_a_compute_argument().config (
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(kim_model)[source]¶
Compute the properties required by the compute flags, and store them in self.results.
- Parameters:
params – 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
- class kliff.models.kim.KIMModel(model_name)[source]¶
A general interface to any KIM model.
- Parameters:
model_name (
str) – name of a KIM model. Available models can be found at: https://openkim.org. For example SW_StillingerWeber_1985_Si__MO_405512056662_006.
- get_kim_model_params()[source]¶
Inquire the KIM model to get all the parameters.
- Returns:
{name, parameter}, all parameters in a kim model.
- 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”])
- set_one_opt_param(name, settings)[source]¶
Set one parameter that will be optimized.
The name of the parameter should be given as the first entry of a list (or tuple), and then each data line should be given in in a list.
- Parameters:
name (
str) – name of a fitting parametersettings (
List[List[Any]]) – List initial value, flag to fix a parameter, lower and upper bounds of a parameter.
Example
name = ‘A’ settings = [[‘default’, 0, 20], [2.0, ‘fix’], [2.2, ‘inf’, 3.3]] instance.set_one(name, settings)
- update_model_params(params)[source]¶
Update optimizing parameters (a sequence used by the optimizer) to the kim model.
- write_kim_model(path=None)[source]¶
Write out a KIM model that can be used directly with the kim-api.
This function typically write two files to path: (1) CMakeLists.txt, and (2) a parameter file like A.params. path will be created if it does not exist.
- Parameters:
path (
Optional[Path]) – Path to a directory to store the model. If None, it is set to ./MODEL_NAME_kliff_trained, where MODEL_NAME is the model_name that provided at the initialization of this class.
Note
This only works for parameterized KIMModel models that support the writing of parameters.
- static get_model_from_manifest(model_manifest, param_manifest=None, is_model_tarfile=False)[source]¶
Get the model from a configuration. If it is a valid KIM model, it will return the KIMModel object. If it is a TorchML model, it will return the torch ReverseScriptedModule object in future. Else raise error. If the model is a tarball, it will extract and install the model.
`{todo} Get torchscript model from TorchML driver. `Example model_manifest: ```yaml
- model:
model_path: ./model.tar.gz # path to the model tarball model_name: SW_StillingerWeber_1985_Si__MO_405512056662_006 # KIM model name, installed if missing model_collection: “user”
Example param_manifest: ```yaml
- parameter:
A # dict means the parameter is transformed
B # these are the parameters that are not transformed
- sigma:
transform_name: LogParameterTransform value: 2.0 bounds: [[1.0, 10.0]]
`{note} `parameter` block is usually defined as the children of the `transform` block in trainer configuration file. `- Parameters:
model_manifest (
dict) – configuration objectparam_manifest (
Optional[dict]) – parameter transformation configurationis_model_tarfile (
bool) – whether the model is a tarball
- Returns:
Model object
- static get_model_driver_name(model_name)[source]¶
Get the model driver from the model name. It will return the model driver string from the installed KIM API model. If the model is not installed, and the model name is a tarball, it will extract the model driver name from the CMakeLists.txt. This is needed to ensure that it excludes the model drivers that it cannot handle. Example: TorchML driver based models. These models are to be trained using the TorchTrainer.
- TODO: This is not a clean solution. I think KIMPY must have a better way to handle this.
Ask Mingjian/Yaser for comment.
- Parameters:
model_name (
str) – name of the model.- Return type:
Optional[str]- Returns:
Model driver name.