Skip to content

Conversation

@alibh95
Copy link
Contributor

@alibh95 alibh95 commented Apr 4, 2025

LOBSTER 5.1.1 sometimes produces an ICOHPLIST.lobster file without a trailing newline, which causes the Icohplist parser to miscount bond entries (e.g., 1079 vs. 1080). This commit updates the file-reading logic in Icohplist.init to use splitlines() and filters out any blank lines, ensuring that only valid, non-empty lines are parsed. This change prevents the ValueError ("COHPCAR and ICOHPLIST do not fit together") and aligns the bond count with COHPCAR.lobster.

Ref: #4349 and JaGeo/LobsterPy#389

Summary

Major changes:

  • Update file reading in Icohplist.init to use splitlines() instead of split("\n").
  • Filter out blank lines from the ICOHPLIST.lobster file to ensure accurate bond count.

Checklist

  • Google format doc strings added. Check with ruff.
  • Type annotations included. Check with mypy.
  • Tests added for new features/fixes.
  • If applicable, new classes/functions/modules have duecredit @due.dcite decorators to reference relevant papers by DOI (example)

Tip: Install pre-commit hooks to auto-check types and linting before every commit:

pip install -U pre-commit
pre-commit install

LOBSTER 5.1.1 sometimes produces an ICOHPLIST.lobster file without a trailing
newline, which causes the Icohplist parser to miscount bond entries (e.g., 1079 vs. 1080).
This commit updates the file-reading logic in Icohplist.__init__ to use splitlines()
and filters out any blank lines, ensuring that only valid, non-empty lines are parsed.
This change prevents the ValueError ("COHPCAR and ICOHPLIST do not fit together")
and aligns the bond count with COHPCAR.lobster.

Ref: See related issue in lobsterpy (materialsproject#389) for additional context.

Signed-off-by: Ali Hussain Umar Bhatti <[email protected]>
@alibh95 alibh95 requested review from mkhorton and shyuep as code owners April 4, 2025 08:46
@naik-aakash
Copy link
Contributor

Thanks, @alibh95, for raising this fix. Can you please also adapt the failing test in the PR?

@shyuep
Copy link
Member

shyuep commented Apr 15, 2025

Please provide a unittest to check for this issue. Thanks.

@naik-aakash
Copy link
Contributor

naik-aakash commented Apr 29, 2025

Hi @alibh95 , it would be great if you can fix the newly added test that is failing and also adapt the existing failing test to reflect correct number of bonds

- Strip only trailing blank lines so a missing final newline still works
- Compute header length dynamically (skip title and optional spin‐line)
- Determine LOBSTER version by column count (6→2.2.1, 8→3.1.1, 9→5.1.0)
- Preserve non‐orbitalwise LCFO entries (fixes length mismatch for non-orbitalwise LCFO lists)
@alibh95
Copy link
Contributor Author

alibh95 commented Apr 30, 2025

@shyuep I have added the unittest for this issue.
@naik-aakash The failing tests are corrected in this commit.

@shyuep shyuep merged commit 45e8bd4 into materialsproject:master May 1, 2025
43 checks passed
@shyuep
Copy link
Member

shyuep commented May 1, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants