<!-- DO NOT EDIT. -->
<!-- THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. -->
<!-- TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: -->
<!-- "auto_examples/readers_writers/plot_convert_trajectory_to_frame.py" -->
<!-- LINE NUMBERS ARE GIVEN BELOW. -->

#### NOTE
[Go to the end](#sphx-glr-download-auto-examples-readers-writers-plot-convert-trajectory-to-frame-py)
to download the full example code.

<a id="sphx-glr-auto-examples-readers-writers-plot-convert-trajectory-to-frame-py"></a>

# Extract Trajectory Frame to Data File

Take a later entry from a LAMMPS trajectory and save it as a data file.

<!-- GENERATED FROM PYTHON SOURCE LINES 8-18 -->
```Python
import os
from pathlib import Path

from pylimer_tools_cpp import DataFileWriter, UniverseSequence

if not os.path.exists("generated_structures"):
    os.makedirs("generated_structures")
```

<!-- GENERATED FROM PYTHON SOURCE LINES 19-21 -->

For large trajectories, frames are loaded on-demand
Load a LAMMPS dump trajectory file (replace with your file)

<!-- GENERATED FROM PYTHON SOURCE LINES 21-46 -->
```Python
def _find_fixtures_dir() -> Path:
    for cur in (
        [Path(__file__).resolve().parent] if "__file__" in globals() else []
    ) + [Path.cwd()]:
        for p in [cur] + list(cur.parents):
            candidate = p / "tests" / "pylimer_tools" / "fixtures"
            if candidate.is_dir():
                return candidate
    return Path("tests/pylimer_tools/fixtures").resolve()


_fixtures_dir = _find_fixtures_dir()
file_path = str(_fixtures_dir)
sequence = UniverseSequence()
sequence.initialize_from_dump_file(
    initial_data_file=os.path.join(file_path, "big_dump_file_data.out"),
    dump_file=os.path.join(file_path, "big_dump_file.lammpstrj"),
)
# Get the last frame, for example
final_universe = sequence.at_index(len(sequence) - 1)

# Write as data file
writer = DataFileWriter(final_universe)
writer.config_include_angles(True)
writer.write_to_file("generated_structures/final_configuration.data")
```

**Total running time of the script:** (0 minutes 0.079 seconds)

<a id="sphx-glr-download-auto-examples-readers-writers-plot-convert-trajectory-to-frame-py"></a>

[`Download Jupyter notebook: plot_convert_trajectory_to_frame.ipynb`](_downloads/7fd95444cda60585d08d3023ce3b33c4/plot_convert_trajectory_to_frame.ipynb)

[`Download Python source code: plot_convert_trajectory_to_frame.py`](_downloads/fc947f7bf2720e718949e810d3870e92/plot_convert_trajectory_to_frame.py)

[`Download zipped: plot_convert_trajectory_to_frame.zip`](_downloads/ccddbdb2a31e3b452b8faf71bd78deca/plot_convert_trajectory_to_frame.zip)

[Gallery generated by Sphinx-Gallery](https://sphinx-gallery.github.io)
