convertMACEModelToQATKFormat

convertMACEModelToQATKFormat(model_path, model_head_number=-1)

Convert a MACE model to a QATK compatible format.

Parameters:
  • model_path (str | Path) – The full path to a MACE model file.

  • model_head_number (int) – The head number of the model to use for the QATK compatible model.
    Default: The last head of the input model.

Usage Examples

MACE models set up via MACEFittingParameters and trained via MachineLearnedForceFieldTrainer are automatically converted into QATK-compatible formats. For MACE models acquired from elsewhere, it is possible to convert them into a TremoloX-native format by using this method. The conversion is required in order to use MACE models with QuantumATK’s native force field framework.

Assume that we have a MACE model file named mace_model.model with only a single model head in our current working directory. Using the following script, the mace MACE model can be converted into a QATK-compatible format with a .qatkpt extension.

# Convert the MACE model to QATK format
convertMACEModelToQATKFormat('mace_model.model')

After the conversion has saved the model in a QuantumATK compatible format, the MACE model can be loaded as a force field potential and used to set up a TremoloXCalculator that can be used as usual in QuantumATK.

# Load the interatomic potential into a TremoloXCalculator that can be
# attached to and used with QATK configurations...
model_path = 'mace_model.qatkpt'

potentialSet = TremoloXPotentialSet(name='my_mace_potential')
potential = TorchXPotential(
    dtype='float64',
    device='cuda',
    file=model_path,
)
for symbol in potential.get_symbols(model_path):
    potentialSet.addParticleType(ParticleType(symbol))
potentialSet.addPotential(potential)

calculator = TremoloXCalculator(parameters=potentialSet)

This example script is available for download: conversion_example.py

Notes

  • The conversion script is available for .model files containing one or more model heads generated with the MACE framework [1][2].

  • The output model file will have the same name as the input file path but replace the extension to a .qatkpt format.

  • It is only possible to convert one head from a .model file into a .qatkpt file. If several heads from a .model file are required, the conversion needs to be repeated with different model_head_number values.