10
$\begingroup$

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 import read, write
from ase.io.vasp import write_vasp_xdatcar

bec = ase.io.read("./run10/local_minima.traj")
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>
      5 bec = ase.io.read("./run10/local_minima.traj")
      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.
$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$
    – Tyberius
    Dec 8 '21 at 16:24
  • $\begingroup$ Sure, I can do that. Good idea, thanks. $\endgroup$
    – Saha_1994
    Dec 8 '21 at 16:28
  • 2
    $\begingroup$ 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 $\endgroup$
    – Tyberius
    Dec 8 '21 at 17:01
  • $\begingroup$ Thanks a lot, it worked. $\endgroup$
    – Saha_1994
    Dec 8 '21 at 21:01
6
$\begingroup$

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 import read, write
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)
$\endgroup$
6
$\begingroup$

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 
from ase.io import read, write
from ase.io.vasp import write_vasp_xdatcar

bec = ase.io.read("./run10/local_minima.traj", index=':')
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)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.