lammpsio.DataFile

class lammpsio.DataFile(filename, atom_style=None)

LAMMPS data file.

LAMMPS can both read a data file for initialization and also write a data file (e.g., for visualization or restart purposes). A Snapshot can be written to a data file using create:

snapshot = lammpsio.Snapshot(
    N=3,
    box=lammpsio.Box([-5, -5, -5], [5, 5, 5]),
    step=10
)

data = lammpsio.DataFile.create(tmp_path / "atoms.data", snapshot)

A data file can also be read into a Snapshot:

snap = data.read()

There are many sections that can be stored in a data file, but lammpsio does not currently understand all of them. You can check known_headers, unknown_headers, known_bodies and unknown_bodies for lists of what is currently supported.

Parameters:
  • filename (str) – Path to data file.

  • atom_style (str) – LAMMPS atom style to use. Defaults to None, which means the style should be read from the file.

filename

Path to the file.

Type:

str

atom_style

Atom style for the file.

Type:

str

known_headers

Data file headers that can be processed.

Type:

list of str

unknown_headers

Data file headers that will be ignored.

Type:

list of str

known_bodies

Data file body sections that can be processed.

Type:

list of str

unknown_bodies

Data file body sections that will be ignored.

Type:

list of str

Methods:

create(filename, snapshot[, atom_style])

Create a LAMMPS data file from a snapshot.

read()

Read a LAMMPS data file into a snapshot.

Attributes:

classmethod create(filename, snapshot, atom_style=None)

Create a LAMMPS data file from a snapshot.

Parameters:
  • filename (str) – Path to data file.

  • snapshot (Snapshot) – Snapshot to write to file.

  • atom_style (str) – Atom style to use for data file. Defaults to None, which means the style should be inferred from the contents of snapshot.

Returns:

The object representing the new data file.

Return type:

DataFile

Raises:

ValueError – If all masses are not the same for a given type.

read()

Read a LAMMPS data file into a snapshot.

The atom_style will be read from the comment in the Atoms section of the file. If it is not present, it must be specified manually. If atom_style is specified manually and also present in the file, the two must match or an error will be raised.

Unknown headers and sections are silently ignored.

Returns:

Snapshot from the data file.

Return type:

Snapshot