# ASE convesion of Trajectory file to XDATCAR

The issue here is while converting a TRAJ file to POSCAR, it works. But, for TRAJ to XDATCAR, it shows TypeError: images should be a sequence of Atoms objects. (Check below to see the error report)

import ase
from ase.io.vasp import write_vasp_xdatcar

bec_new_pos = ase.io.vasp.write_vasp("local_minima_new.poscar", bec, vasp5=True)
bec_new_xdat = ase.io.vasp.write_vasp_xdatcar("local_minima_new.xdatcar", bec, label=None)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_143176/175431421.py in <module>
6 bec_new_pos = ase.io.vasp.write_vasp("local_minima_new.poscar", bec, vasp5=True)
----> 7 bec_new_xdat = ase.io.vasp.write_vasp_xdatcar("local_minima_new.xdatcar", bec, label=None)

/usr/lib/python3/dist-packages/ase/utils/__init__.py in iofunc(file, *args, **kwargs)
453                 else:
454                     fd = file
--> 455                 obj = func(fd, *args, **kwargs)
456                 return obj
457             finally:

/usr/lib/python3/dist-packages/ase/io/vasp.py in write_vasp_xdatcar(fd, images, label)
596
597     if not isinstance(image, Atoms):
--> 598         raise TypeError("images should be a sequence of Atoms objects.")
599
600     symbol_count = _symbol_count_from_symbols(image.get_chemical_symbols())

TypeError: images should be a sequence of Atoms objects.

• Would you be able to convert the error messages to a code block, rather than an image? This will make it more easily searchable if future users have a similar question. It would also help to have your trajectory file or a small example one that gives the same error.
– Tyberius
Dec 8, 2021 at 16:24
• Sure, I can do that. Good idea, thanks. Dec 8, 2021 at 16:28
• Based on the error, it looks as though the read method is just returning a single Atoms object, rather than some iterable of Atoms. Could you use a Trajectory object instead? wiki.fysik.dtu.dk/ase/ase/io/trajectory.html
– Tyberius
Dec 8, 2021 at 17:01
• Thanks a lot, it worked. Dec 8, 2021 at 21:01

This should work, basically, one needs to put iterable of atoms as images. So, using the trajectory reader should do the trick.

import ase
from ase.io.vasp import write_vasp_xdatcar
from ase.io.trajectory import Trajectory

bec = Trajectory("./run10/local_minima.traj")
bec_new_xdat = ase.io.vasp.write_vasp_xdatcar("local_minima_new.xdatcar", bec, label=None)


By default ase.io.read only reads the last frame of the trajectory (an Atoms object), you need to specify the index argument to read several frames. index=':' will read the entire trajectory.

import ase