Skip to main content

Tool to read lammps log files into python data structure

Project description

LAMMPS logfile reader

Tool to read a logfile produced by LAMMPS into a python data structure.

Installation

From pypi (preferred/stable)

pip install lammps-logfile

Depending on your python installation, you may have to use pip3 instead of pip. This is usualy the case if you need to run python3 rather than python to run python version 3.

Install using pip directly from github to get the latest (possibly unstable) version:

pip install git+https://github.com/henriasv/lammps-logfile.git

Or by cloning the repository:

git clone https://github.com/henriasv/lammps-logfile.git
cd lammps-logfile
pip3 install .

Usage (Recommended)

The recommended way to read log files is using the read_log function, which returns a pandas DataFrame containing all thermodynamic data from all runs in the log file.

from lammps_logfile import read_log
import matplotlib.pyplot as plt

# Read the log file into a DataFrame
# This example uses the 'crack_log.lammps' file found in 'examples/logfiles/'
df = read_log("crack_log.lammps")

# The DataFrame contains data from all runs, with a 'run_num' column distinguishing them
print(df.head())

# Plot Temperature vs Step
plt.figure(figsize=(10, 6))
plt.plot(df['Step'], df['Temp'])
plt.xlabel('Step')
plt.ylabel('Temperature')
plt.show()

Example Plot

Benchmarks

lammps-logfile is highly optimized for large files. These benchmarks were run on a standard laptop (MacBook Pro M1).

Simulation Runs Steps Memory (MB) Time (s)
01_fcc_thermo_multi 3 29 0.36 0.01
02_bcc_custom_thermo 4 108 0.30 0.01
03_fcc_custom_longlog 4 30004 21.05 0.07
04_bcc_multi_then_custom 5 62 0.27 0.01
1 GB Log File 1 23,600,000 2560.08 10.10

It uses a memory-mapped parser (backed by the Pandas C engine) to blazing fast performance while keeping memory usage proportional to the output data size.

Legacy Interface

The File class interface is kept for backward compatibility but is considered legacy.

import lammps_logfile

log = lammps_logfile.File("path/to/logfile")

x = log.get("Time")
y = log.get("Temp")

import matplotlib.pyplot as plt
plt.plot(x, y)
plt.show()

This will give the concatenated log entries of all the runs where the style of the thermo output didn't change with respect to the last run. I.e. if the entries in the thermo_style was not changed between runs it will contain the log data for all the timesteps. If the thermo_style was changed, x and y will contain the data from all the timesteps after the thermo_style was changed for the last time.

Multiple runs in the same log file (Legacy)

If multiple run statements have been made in a simulation, these can be retrieved bu supplying the run_num keyword to the get()-function

import lammps_logfile

log = lammps_logfile.File("path/to/logfile")

x = log.get("Time", run_num=N)
y = log.get("Temp", run_num=N)

import matplotlib.pyplot as plt
plt.plot(x, y)
plt.show()

In this case, x and y will contain the log data from the N'th run command in LAMMPS, counting from 0.

Any invalid call to the get()-function will result in the function returning None. This happes if the user asks for a thermo propery that does not exist in the log file, or if the user asks for a run_num larger than the number of runs in the logfile.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lammps_logfile-1.1.3.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lammps_logfile-1.1.3-py3-none-any.whl (25.7 kB view details)

Uploaded Python 3

File details

Details for the file lammps_logfile-1.1.3.tar.gz.

File metadata

  • Download URL: lammps_logfile-1.1.3.tar.gz
  • Upload date:
  • Size: 25.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lammps_logfile-1.1.3.tar.gz
Algorithm Hash digest
SHA256 29b7dfa56463ae9c5047fd77a1c83d857da80c8baa030b2de3fb40b997d8ec34
MD5 0c6cb561bb4f94d677661ff994f776d4
BLAKE2b-256 7832ea84ead948ef9f5de29600343184f7e5ef1caaf9a53fa3cb7231b8be486a

See more details on using hashes here.

Provenance

The following attestation bundles were made for lammps_logfile-1.1.3.tar.gz:

Publisher: release.yml on henriasv/lammps-logfile

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lammps_logfile-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: lammps_logfile-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 25.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lammps_logfile-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 732ed52856a3b883210de2daece0cc0080c8681bbaa6dc22fe160bf555987b3f
MD5 0f27d6248c26aba24502bad154733691
BLAKE2b-256 5fb74db77c78a1a3d0c572f118ec8af5e6e376c6522a2d7855babf6918c9c47c

See more details on using hashes here.

Provenance

The following attestation bundles were made for lammps_logfile-1.1.3-py3-none-any.whl:

Publisher: release.yml on henriasv/lammps-logfile

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page