.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "howtos_generated/howto_io/io_file_conversion.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_howtos_generated_howto_io_io_file_conversion.py: .. _howto_io_file_conversion: File conversion =========================== .. GENERATED FROM PYTHON SOURCE LINES 8-10 *Here we create the necessary files for this example. Go to next section for the file conversion.* .. GENERATED FROM PYTHON SOURCE LINES 10-25 .. code-block:: Python 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) .. GENERATED FROM PYTHON SOURCE LINES 26-28 With python interpreter ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 31-38 .. 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``. .. GENERATED FROM PYTHON SOURCE LINES 40-43 This is a very simple example of a file conversion. It takes a extended xyz (``.extxyz``) file as entry, and output a ``.cif`` file. .. GENERATED FROM PYTHON SOURCE LINES 43-50 .. code-block:: Python from ase.io import read, write image = read('slab.extxyz', format='extxyz', index=0) write('slab.cif', image, format='cif') .. GENERATED FROM PYTHON SOURCE LINES 51-55 .. note:: Format can be automatically found with extension but it is preferable to specify it explicitly. .. GENERATED FROM PYTHON SOURCE LINES 57-64 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... .. GENERATED FROM PYTHON SOURCE LINES 64-77 .. code-block:: Python 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') .. GENERATED FROM PYTHON SOURCE LINES 78-82 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. .. GENERATED FROM PYTHON SOURCE LINES 82-90 .. code-block:: Python trajectory = read( imagepath, format='traj', index='2:', ) write('md_trajectory.extxyz', trajectory[::2], format='extxyz') .. GENERATED FROM PYTHON SOURCE LINES 91-93 With command line input (cli) ------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 95-102 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 .. GENERATED FROM PYTHON SOURCE LINES 104-106 With graphical user interface (gui) ------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 109-110 You can also convert the file using the gui. .. GENERATED FROM PYTHON SOURCE LINES 112-117 Open the GUI .. code-block:: bash ase gui md_trajectory.traj .. GENERATED FROM PYTHON SOURCE LINES 119-123 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. .. _sphx_glr_download_howtos_generated_howto_io_io_file_conversion.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: io_file_conversion.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: io_file_conversion.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: io_file_conversion.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_