There isn't that many tutorials on Atomic Simulation Environment on the net and among those I saw, the atoms object is always built explicitly within Python.

What if I have a data file containing the coordinate positions of each element in a particular material: Let's say either a CIF or an XYZ or LAMMPS data file of a 4 x 4 cell of molybdenum disulfide.

How do I read this into the atoms object in ASE?

  • 1
    $\begingroup$ Don't have the time to write it up in detail, but here is the documentation to read a file into ASE. You just need to specify the format. If you figure it out from this, you can self answer the question to give an example of how this is done. $\endgroup$
    – Tyberius
    Apr 21, 2021 at 4:16
  • 1
    $\begingroup$ It's typically very simple: from ase import io; atoms=io.read('abc.xyz'); $\endgroup$
    – Fabian
    Apr 21, 2021 at 13:25

1 Answer 1


Reading coordinates from a file is a very simple task with ASE. The following code reads the three different file types into an Atoms object:

from ase import io
lammps = io.read('mos2.pos',format='lammps-data')
cif = io.read('mos2.cif')
xyz = io.read('mos2.xyz') 

ASE can detect certain file formats from the ending, like in the case of .cif and .xyz. For the lammps file the format needs to be set explicitly.

The formats that ASE natively supports are documented here: https://wiki.fysik.dtu.dk/ase/ase/io/io.html

And some format specific options are listed here: https://wiki.fysik.dtu.dk/ase/ase/io/formatoptions.html

If the file contains multiple sets of coordinates index can be used to select a certain one or a selection.

from ase import io
xyz_last = io.read('mos2.xyz',index='-1') 
xyz_all = io.read('mos2.xyz',index=':') 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .