Skip to content

Fix to_pdb for ANISOU records after label_models - #166

Merged
a-r-j merged 1 commit into
BioPandas:mainfrom
raashish1601:fix/124-to-pdb-model-id
Oct 10, 2026
Merged

a-r-j merged 1 commit into
BioPandas:mainfrom
raashish1601:fix/124-to-pdb-model-id

Conversation

@raashish1601

Copy link
Copy Markdown
Contributor

Code of Conduct

Read.

Description

label_models() adds an integer model_id column to the ANISOU frame as well as to ATOM and HETATM. to_pdb() only skipped unexpected columns for ATOM and HETATM, so for ANISOU it tried to append the integer column to the output string and failed:

ppdb = PandasPdb().read_pdb("tests/pdb/data/4eiy_anisouchunk.pdb")
ppdb.label_models()
ppdb.to_pdb("out.pdb")
# TypeError: can only concatenate str (not "int") to str

to_pdb() now skips model_id silently, the same way to_pdb_stream() already drops it, and unexpected ANISOU columns are skipped with the same warning used for ATOM/HETATM (checked against the ANISOU record fields).

Two tests added in tests/pdb/test_write_pdb.py: writing the ANISOU test file after label_models() gives back the original file without a model_id warning, and an extra ANISOU column is warned about and skipped. Both fail on main and pass with this change.

Related issues or pull requests

Fixes #124

Pull Request Checklist

  • Added a note about the modification or contribution to the ./docs/sources/CHANGELOG.md file (if applicable) (the changelog lives at docs/CHANGELOG.md)
  • Added appropriate unit test functions in the ./biopandas/*/tests directories (if applicable)
  • Modify documentation in the corresponding Jupyter Notebook under biopandas/docs/sources/ (if applicable) (not needed)
  • Ran PYTHONPATH='.' pytest ./biopandas -sv and make sure that all unit tests pass (ran pytest tests/pdb: 86 passed, 3 skipped, 7 xfailed)
  • Checked for style issues by running flake8 ./biopandas (no new warnings in the changed lines)

label_models() adds an integer model_id column to the ANISOU frame too. to_pdb() only skipped unexpected columns for ATOM and HETATM, so for ANISOU it tried to concatenate the integer column to the output string and raised a TypeError. Skip model_id like to_pdb_stream() does, and skip other unexpected ANISOU columns with a warning.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused implementation resolves the reported failure and includes appropriate regression coverage.

0 open findings

What changed in this PR

Fixes PDB export for labeled models containing ANISOU records.

Changes:

  • Skips model_id during PDB serialization.
  • Validates unexpected columns against each record’s schema.
  • Adds regression tests and changelog documentation.
File Description
biopandas/​pdb/​pandas_pdb.py Corrects column handling during PDB export.
tests/​pdb/​test_write_pdb.py Tests labeled and unexpected ANISOU columns.
docs/​CHANGELOG.md Documents the export fix.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@a-r-j
a-r-j merged commit e6f0e42 into BioPandas:main Oct 10, 2026
9 of 10 checks passed
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.

Unable to export PDB DFs with model_id columns

3 participants