Skip to content

ICOHPLIST Parser in pymatgen Does Not Handle Missing Trailing Newline (Ref: lobsterpy#389) #4349

@alibh95

Description

@alibh95

Python version

Python 3.12.7

Pymatgen version

2025.3.10

Operating system version

Ubuntu 24.04.2 LTS

Current behavior

When using LOBSTER version 5.1.1, the generated ICOHPLIST.lobster file may not include a trailing newline. This causes the Icohplist parser in pymatgen’s outputs module to miscount the number of bond entries. For example, ICOHPLIST.lobster is parsed with 1079 entries, while COHPCAR.lobster contains 1080 bonds. This mismatch triggers a ValueError:

ValueError: COHPCAR and ICOHPLIST do not fit together

Expected Behavior

The parser should correctly count the bond entries even if ICOHPLIST.lobster lacks a trailing newline. For instance, by using Python’s splitlines() method (which automatically handles missing trailing newlines) and filtering out any empty lines, the bond count should accurately reflect the intended number of bonds, allowing the analysis to proceed without error.

Minimal example

Relevant files to reproduce this bug

Steps to reproduce the behavior:

  1. Generate LOBSTER output files (ICOHPLIST.lobster and COHPCAR.lobster) using LOBSTER version 5.1.1.

  2. Verify that ICOHPLIST.lobster does not end with a trailing newline (e.g., by opening the file in a text editor or running:

wc -l ICOHPLIST.lobster
grep -n "." ICOHPLIST.lobster

to compare the line counts).

  1. Run a pymatgen-based workflow (or a LobsterPy/pymatgen script) that reads these files.

  2. The parser miscounts the bonds and raises the ValueError.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions