How to write a standard MACE-type XYZ file by ASE

Hi, everyone

I am trying to read from OUTCAR (my results file of VASP) and rewrite it as XYZ file.
For MACE, the most important thing is the second line of XYZ file.
In the second line, I want to rewrite the key ‘free_energy’ as ‘energy_dft’
I try the follwing code but failed:

from ase.io import read, write
db = read(‘OUTCAR.vasp’,‘:’)
for at in db[:3]:
at.info[‘energy_dft’] = at.info[‘free_energy’]
print(at.info[‘energy_dft’])

Traceback (most recent call last):
File “d:\code\GAP\test.py”, line 18, in
at.info[‘energy_dft’] = at.info[‘free_energy’]
~~~~~~~^^^^^^^^^^^^^^^
KeyError: ‘free_energy’

It seems that ‘free_energy’ is not the key
but when I rewrite the OUTCAR as XYZ file
I find ‘free_energy’ at the second line of XYZ file like:

free_energy=-899.98937524 energy=-899.98937524 pbc=“T T T”

How can I make ASE realize that ‘free_energy’ at the second line of XYZ file is a info or key so that I can easily use its value?

I am new to ASE. Some description may not be correct.
Thank you!

Baoshuai.

free_energy is ASE’s name for the energy (extrapolated if appropriate to Fermi temperature 0) consistent with the forces. The canonical way to access it is atoms.get_potential_energy(force_consistent=True), which would work with all formats that support this energy.

For some time the parser for this particular format would unfortunately also dump things into the atoms.info dict which is non-standard (doesn’t work with other formats). A somewhat more universal way to access it is through the atoms.calc.results dictionary. That way, the code doing so would then work with most formats that include energies/forces etc.

1 Like