kliff.transforms.configuration_transforms

class kliff.transforms.configuration_transforms.ConfigurationTransform(copy_to_config=False)[source]

A configuration transform is a function that maps a configuration to a “fingerprint”. The fingerprint can be any object that represents the configuration, and restriction or checks on the fingerprint is not imposed. For example, current configuration transforms include graph representations of the configuration,and descriptors.

forward(configuration)[source]

Map a configuration to a fingerprint. Also handle the implicit copying of the fingerprint to the configuration.

Parameters:

configuration (Configuration) – Instance of ~:class:kliff.dataset.Configuration. For which the fingerprint is to be generated.

Return type:

Any

Returns:

Fingerprint of the configuration.

inverse(*args, **kargs)[source]

Inverse mapping of the transform. This is not implemented for any of the transforms, but is there for future use.

Return type:

Configuration

transform(configuration)[source]
Return type:

Any

property copy_to_config: bool
collate_fn(config_list)[source]

Collate a list of configurations into a list of transforms. This is useful for batch processing.

Parameters:

config_list (List[Configuration]) – List of configurations.

Return type:

List[Any]

export_kim_model(filename, modelname)[source]

Save the configuration transform to a file.

Parameters:
  • filename (Path) – Name of the file to save the transform to.

  • modelname (str) – Name of the model to save.

class kliff.transforms.configuration_transforms.RadialGraph(species, cutoff, n_layers=1, copy_to_config=False, mic=False)[source]

Generate a graph representation of a configuration. This generator will also save the required parameters for porting the model over to KIM-API using TorchMLModelDriver. The configuration file saved here will generate identical graphs at KIM-API runtime. For porting the graph representation you also need to provide the TorchScript model file name.

Parameters:
  • species (list) – List of species.

  • cutoff (float) – Cutoff distance.

  • n_layers (int) – Number of convolution layers.

  • copy_to_config (bool) – If True, the graph will be copied to the Configuration object’s fingerprint attribute.

  • mic (bool) – If True, module will return conventional MIC graphs, as opposed to the parallel staged graphs.

forward(configuration)[source]

Generate a graph representation of a configuration.

Parameters:

configuration (Configuration) – Instance of ~:class:kliff.dataset.Configuration. For which the graph representation is to be generated.

Return type:

PyGGraph

Returns:

C++ custom graph object or Pytorch Geometric Data object.

static to_py_graph(graph)[source]

Convert a C++ graph object to a KLIFF Geometric Graph Data object, GraphData.

Parameters:

graph (GraphData) – C++ graph data object.

Return type:

PyGGraph

Returns:

PyGGraph object.

export_kim_model(path, model)[source]

Save the transform toa text file for reuse. This is currently used to load the model into KIM-API for pre-processing. The model name is also required to correctly load the model into KIM-API.

Parameters:
  • path (Path) – Path to save the parameter file.

  • model (str) – name of model to save.

kliff.transforms.configuration_transforms.Descriptor(cutoff: float, species: List[str], descriptor: str, hyperparameters: Dict | str, cutoff_function: str = 'cos', copy_to_config: bool = False)[source]

Descriptor class provides interface with the libdescriptor library. It provides a unified interface to all the descriptors in libdescriptor, however all descriptors need to have a corresponding initializer routine, to deal with hyperparameters. The descriptor is initialized with a cutoff radius, a list of species,a descriptor type and an ordered list of hyperparameters. The descriptor type is a string, which can be obtained by show_available_descriptors() function. Some sane default values for the hyperparameters are provided in ~:kliff.transforms.configuration_transforms.default_hyperparameters module. This class methods to compute derivatives of the descriptor with respect to atomic positions. The functions generating descriptors and their derivatives are implemented as forward() and backward(), respectively, to match the PyTorch nomenclature.

kliff.transforms.configuration_transforms.show_available_descriptors()[source]

Show all the available descriptors in libdescriptor.

class kliff.transforms.configuration_transforms.PyGGraph(*args: Any, **kwargs: Any)[source]

A Pytorch Geometric compatible graph representation of a configuration. When loaded into a class:torch_geometric.data.DataLoader the graphs of type PyGGraph will be automatically collated and batched.

classmethod from_dict(mapping)[source]

Create a PyGGraph object from a dictionary.

Parameters:

mapping (Dict[str, Any]) – Dictionary containing the graph data.

Returns:

PyGGraph object.

to_dict()[source]

Convert the PyGGraph object to a dictionary.

Returns:

Dictionary containing the graph data.