Target data Writers

The main entry point for writing target information is

metatrain.utils.data.writers.write_predictions(filename: str, systems: List[System], capabilities: ModelCapabilities, predictions: TensorMap, fileformat: str | None = None) None[source]

Writes predictions to a file.

For certain file suffixes, the systems will also be written (i.e xyz).

The capabilities of the model are used to infer the type (physical quantity) of the predictions. In this way, for example, position gradients of energies can be saved as forces.

For the moment, strain gradients of the energy are saved as stresses (and not as virials).

Parameters:
  • filename (str) – name of the file to write

  • systems (List[System]) – list of systems that for some writers will also be written

  • capabilities (ModelCapabilities) – capabilities of the model

  • predictions (TensorMap) – metatensor.torch.TensorMap containing the predictions that should be written

  • fileformat (str | None) – format of the target value file. If None the format is determined from the file extension.

Return type:

None

Based on the provided filename the writer choses which child writer to use. The mapping which reader is used for which file type is stored in

metatrain.utils.data.writers.PREDICTIONS_WRITERS = {'.mts': <function write_mts>, '.xyz': <function write_xyz>}

dict: dictionary mapping file suffixes to a prediction writers

Implemented Writers

metatrain.utils.data.writers.write_xyz(filename: str, systems: List[System], capabilities: ModelCapabilities, predictions: Dict[str, TensorMap]) None[source]

An ase-based xyz file writer. Writes the systems and predictions to an xyz file.

According to ASE practice, arrays which have a dimension corresponding to each atom are saved inside atoms.arrays, while any other arrays are saved inside atoms.info.

Parameters:
  • filename (str) – name of the file to save to.

  • systems (List[System]) – structures to be written to the file.

  • predictions (Dict[str, TensorMap]) – prediction values to be written to the file.

  • capabilities (ModelCapabilities)

Param:

capabilities: capabilities of the model.

Return type:

None

metatrain.utils.data.writers.write_mts(filename: str, systems: List[System], capabilities: ModelCapabilities, predictions: Dict[str, TensorMap]) None[source]

A metatensor-format prediction writer. Writes the predictions to .mts files.

Parameters:
  • filename (str) – name of the file to save to.

  • systems (List[System]) – structures to be written to the file (not written by this writer).

  • predictions (Dict[str, TensorMap]) – prediction values to be written to the file.

  • capabilities (ModelCapabilities)

Param:

capabilities: capabilities of the model (not used by this writer)

Return type:

None