Skip to content

Unify plain/gz PDB parsing and fix short-record handling in gz reader - #46

Open
nz-mtra wants to merge 1 commit into
steineggerlab:masterfrom
nz-mtra:bugfix/pdb-gz-parser-parity
Open

Unify plain/gz PDB parsing and fix short-record handling in gz reader#46
nz-mtra wants to merge 1 commit into
steineggerlab:masterfrom
nz-mtra:bugfix/pdb-gz-parser-parity

Conversation

@nz-mtra

@nz-mtra nz-mtra commented Apr 29, 2026

Copy link
Copy Markdown

What this PR changes

This PR removes divergence between plain and gz PDB parsing by introducing one shared line parser in pdb.rs. Fixes #45 .

Changes included:

  1. Added shared helper parse_pdb_lines to centralize:
    • short-line guard before record prefix matching
    • MODEL counting
    • first-model-only behavior
    • ATOM parsing/update flow
  2. Updated:
    • read_structure to use shared parser
    • read_structure_from_gz to decode and then use the same parser
  3. Replaced gz decode unwrap with map_err to avoid panic on decode/read errors.
  4. Added regression tests in pdb.rs:
    • test_read_pdb_gz_with_end_record (END-terminated content parity plain vs gz)
    • test_plain_and_gz_model_handling_match (multi-model handling parity plain vs gz)
  5. Removed now-unused top-level Write import warning in pdb.rs.

Why

Previously, gz and plain PDB readers used separate parsing paths. That made behavior drift possible and exposed gz parsing to short-record edge cases. The new shared parser keeps behavior aligned and prevents this class of divergence moving forward.

Validation

Executed and passing:

  1. cargo test test_read_pdb_gz_with_end_record -- --nocapture
  2. cargo test test_plain_and_gz_model_handling_match -- --nocapture
  3. cargo test --workspace --all-targets --release

Notes

The new regression tests assert plain/gz behavior parity and non-crashing behavior for END-terminated inputs, which directly targets the reported bug class.

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.

Gzipped PDB reader diverges from plain reader behavior and can panic on short records

1 participant