Note
Go to the end to download the full example code.
File conversion#
Here we create the necessary files for this example. Go to next section for the file conversion.
from ase.build import fcc111
from ase.io import write
atoms = fcc111('Au', size=(4, 4, 6), vacuum=6.0)
atoms.info.clear()
write('slab.extxyz', atoms, format='extxyz')
images_rattled = []
for i in range(10):
atoms.rattle(stdev=0.1, seed=i)
images_rattled.append(atoms.copy())
write('md_trajectory.traj', images_rattled)
With python interpreter#
Note
To begin, the formats available for reading and writing are listed here: Input/Output module.
You can also access this page by looking for the IO module.
This is a very simple example of a file conversion.
It takes a extended xyz (.extxyz) file as entry,
and output a .cif file.
Note
Format can be automatically found with extension but it is preferable to specify it explicitly.
The index argument allow to load a specific configuration or range of configuration.
You can pass an integer (0 for
first configuration, -1 for the last) or a string.
The string follows array indexing, meaning “:” for all,
“::2” for all and every 2, etc…
Load a trajectory from a MD tutorial.
Load from the third element to the last.
Write it in extended xyz every 2 frame.
This format can hold several configurations.
trajectory = read(
imagepath,
format='traj',
index='2:',
)
write('md_trajectory.extxyz', trajectory[::2], format='extxyz')
With command line input (cli)#
You can also convert the file using the cli:
ase convert md_trajectory.traj \
md_trajectory_cli.xyz \
--input-format traj --output-format extxyz --image-number ::2
With graphical user interface (gui)#
You can also convert the file using the gui.
Open the GUI
ase gui md_trajectory.traj
in File -> save you can save your image/trajectory.
You can provide the name as: md_last.cif@-1
to save only the last image.