How can I convert Vasp OUTCAR file to extxyz with charge & virial for all frames?

I’ve been converting an outcar file of VASP AIMD to extxyz using ase to prepare training set for NequIP and MACE using a following script:

from ase.io import read, write
input_file="./input.outcar"
output_file="./output.extxyz"
input_data = read(input_file, index=':', format='vasp-out')
write(output_file, input_data, format='extxyz')

But now, if I want to calculate virial and print out to information line, I need to use get volume() and get_stress() but those cannot be used for list data (because I read the whole file using index : ).

input_data.info["virial"] = -input_data.get_volume() * input_data.get_stress(voigt=True)

Also, my Vasp outcar file has hirshfeld charge for all atoms of all frames. I hope to print those Hirshfeld charge value as additional column of extxyz file for all frames. But get_charges() requires calculator, I can’t find any example to follow…

How can I print out extxyz of all frames from Outcar file, that includes virial in information line & charge as new column for all frames?

Use Python features to loop over the data and update the properties on each Atoms individually:

for atoms in input_data:
    atoms.info["virial"] = -atoms.get_volume() * atoms.get_stress(voigt=True)

Python lists and Atoms are mutable so this kind of in-place operation will work.

I don’t know that ASE reads the Hirshfeld charges from OUTCAR; I don’t see anything related to this in the source code. You may need to read them some other way and then iterate over the two sets of data using zip.

1 Like