Note
Go to the end to download the full example code.
Dump File ReaderΒΆ
The DumpFileReader processes LAMMPS trajectory files.
Is has a practical interface to read frames from a trajectory file
and access them as Universe objects
in the UniverseSequence class.
Trajectory contains 1 frames
Dump file contains 3 frames
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)