Serialization

metatomic.torch.save(file: str | Path | BinaryIO, system: System) None[source]

Save a System object to a file.

The provided System must contain float64 data and be on the CPU device.

The saved file will be a zip archive containing the following files:

  • types.npy, containing the atomic types in numpy’s NPY format;

  • positions.npy, containing the systems’ positions in numpy’s NPY format;

  • cell.npy, containing the systems’ cell in numpy’s NPY format;

  • pbc.npy, containing the periodic boundary conditions in numpy’s NPY format;

For each neighbor list in the System object, the following files will be saved (where {nl_idx} is the index of the neighbor list):

  • pairs/{nl_idx}/options.json: the NeighborListOptions object converted to a JSON string.

  • pairs/{nl_idx}/data.mts: the neighbor list TensorBlock object

For each extra data in the System object, the following file will be saved (where {name} is the name of the extra data):

  • data/{name}.mts: The extra data TensorMap

Parameters:
  • file (str | Path | BinaryIO) – The path (or file-like object) to save the System to.

  • system (System) – The System object to save.

Return type:

None

metatomic.torch.load_system(file: str | Path | BinaryIO) System[source]

Load a System object from a file.

The loaded System object will be on the CPU device and contain float64 data.

Parameters:

file (str | Path | BinaryIO) – The path (or file-like object) to load the System object from.

Returns:

The System object.

Return type:

System

metatomic.torch.save_buffer(system: System) Tensor[source]

Save the given system to an in-memory buffer, represented as a 1-dimensional torch.Tensor with uint8 dtype.

Parameters:

system (System) – The System object to serialize and save.

Return type:

Tensor

metatomic.torch.load_system_buffer(buffer: Tensor) System[source]

Load a previously saved System from an in-memory buffer, stored inside a 1-dimensional torch.Tensor of uint8.

Parameters:

buffer (Tensor) – CPU tensor with uint8 dtype representing an in-memory buffer.

Return type:

System