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

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

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

# Log & Thermo File Reader

Read LAMMPS log files containing thermodynamic output from the `thermo` command.

The log file reader automatically:

- Detects different thermodynamic output sections with varying columns
- Handles (ignores) warnings and broken lines in the log
- Skips non-numeric data
- Supports multi-run simulations with different `thermo_style` commands

Relevant documentation: [`read_log_file()`](../../pylimer_tools.io.html.md#pylimer_tools.io.read_lammps_output_file.read_log_file)
and [`extract_thermo_params()`](../../pylimer_tools.io.html.md#pylimer_tools.io.extract_thermo_data.extract_thermo_params)

<!-- GENERATED FROM PYTHON SOURCE LINES 18-58 -->
```none
Temperature range: 0.00 - 0.36
Final pressure: -0.170444
```

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

import matplotlib.pyplot as plt

from pylimer_tools.io.read_lammps_output_file import read_log_file


# Read complete log file
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()
log_file = str(_fixtures_dir / "log.lammps")
thermo_data = read_log_file(log_file)

# Access thermodynamic properties
print(
    "Temperature range: {:.2f} - {:.2f}".format(
        thermo_data["Temp"].min(), thermo_data["Temp"].max()
    )
)
print("Final pressure: {:.6f}".format(thermo_data["Press"].iloc[-1]))

# Plot temperature evolution
plt.plot(thermo_data["Step"], thermo_data["Temp"])
plt.xlabel("Simulation Step")
plt.ylabel("Temperature [LJ-units]")
plt.show()
plt.ylabel("Temperature [LJ-units]")
plt.show()
```

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

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

[`Download Jupyter notebook: plot_log_thermo_file_reader.ipynb`](_downloads/36298dd5ad3ab06565bdf1018d166d31/plot_log_thermo_file_reader.ipynb)

[`Download Python source code: plot_log_thermo_file_reader.py`](_downloads/43d6d4ce69d0b315e36bc90a881146c5/plot_log_thermo_file_reader.py)

[`Download zipped: plot_log_thermo_file_reader.zip`](_downloads/0d3b29160f8944c16bd05f01392f5306/plot_log_thermo_file_reader.zip)

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