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

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

<a id="sphx-glr-auto-examples-readers-writers-plot-dump-file-reader-py"></a>

# Dump File Reader

The [`DumpFileReader`](../../api/pylimer_tools_cpp.DumpFileReader.html.md#pylimer_tools_cpp.DumpFileReader) processes LAMMPS trajectory files.
Is has a practical interface to read frames from a trajectory file
and access them as [`Universe`](../../api/pylimer_tools_cpp.Universe.html.md#pylimer_tools_cpp.Universe) objects
in the [`UniverseSequence`](../../api/pylimer_tools_cpp.UniverseSequence.html.md#pylimer_tools_cpp.UniverseSequence) class.

<!-- GENERATED FROM PYTHON SOURCE LINES 11-49 -->
```none
Trajectory contains 1 frames
Dump file contains 3 frames
```

<br/>
```Python
import os
from pathlib import Path

from pylimer_tools_cpp import DumpFileReader, UniverseSequence

# Load trajectory data
sequence = UniverseSequence()


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.initialize_from_dump_file(
    initial_data_file=os.path.join(file_path, "lammps_data_file_small.out"),
    dump_file=os.path.join(file_path, "lammps_dump_small.lammpstrj"),
)

print(f"Trajectory contains {len(sequence)} frames")

# Access specific frames
first_frame = sequence.at_index(0)
last_frame = sequence.at_index(len(sequence) - 1)  # Last frame

dump_file_reader = DumpFileReader(
    os.path.join(file_path, "lammps_dump_small_3step.lammpstrj")
)
print(f"Dump file contains {dump_file_reader.get_length()} frames")
```

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

<a id="sphx-glr-download-auto-examples-readers-writers-plot-dump-file-reader-py"></a>

[`Download Jupyter notebook: plot_dump_file_reader.ipynb`](_downloads/72bcbbf2c09dfc4b729a8aa19e517e71/plot_dump_file_reader.ipynb)

[`Download Python source code: plot_dump_file_reader.py`](_downloads/fa4b02210d4b9aa1d6051c730e51fd9d/plot_dump_file_reader.py)

[`Download zipped: plot_dump_file_reader.zip`](_downloads/71f54bfd6f0e5283b6913a4897635c55/plot_dump_file_reader.zip)

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