""".. _howto_io_file_conversion: 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. from ase.io import read, write image = read('slab.extxyz', format='extxyz', index=0) write('slab.cif', image, format='cif') # %% # .. 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... imagepath = 'md_trajectory.traj' # load all configurations images = read(imagepath, format='traj', index=':') # load every 2nd configurations images = read(imagepath, format='traj', index='::2') # load last configuration image = read(imagepath, format='traj', index='-1') # %% # 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: # # .. code-block:: bash # # 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 # # .. code-block:: bash # # 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.