Skip to content

Handle missing pdbx_PDB_ins_code in mmCIF parser#877

Merged
padix-key merged 1 commit intobiotite-dev:mainfrom
LiudengZhang:fix/mmcif-optional-ins-code
Mar 19, 2026
Merged

Handle missing pdbx_PDB_ins_code in mmCIF parser#877
padix-key merged 1 commit intobiotite-dev:mainfrom
LiudengZhang:fix/mmcif-optional-ins-code

Conversation

@LiudengZhang
Copy link
Contributor

What

Handle missing optional pdbx_PDB_ins_code column when parsing mmCIF files.

Why

get_structure() unconditionally accesses atom_site["pdbx_PDB_ins_code"], raising a KeyError for structures that lack this optional column (e.g., IHM entries like 8ZZ4, 9A0P, 9A8I).

How

Added a conditional check: if pdbx_PDB_ins_code exists in atom_site, use it as before; otherwise, fill the ins_code annotation with empty strings (the default value).

Testing

Added a test that removes pdbx_PDB_ins_code from a CIF file's atom_site category and verifies get_structure() succeeds with all-empty insertion codes.

Closes #869

The pdbx_PDB_ins_code column is optional per the PDBx dictionary,
but get_structure() assumed it was always present. Fall back to
empty insertion codes when the column is missing.

Closes biotite-dev#869
Copy link
Member

@padix-key padix-key left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the fix. This is also a good template for fixing the other optional fields in _atom_site that are still required as mandatory.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 18, 2026

Merging this PR will not alter performance

✅ 63 untouched benchmarks


Comparing LiudengZhang:fix/mmcif-optional-ins-code (9309023) with main (b777f30)

Open in CodSpeed

@padix-key
Copy link
Member

padix-key commented Mar 18, 2026

The failing test in biotite/biotite/tests/structure/test_info.py::test_one_letter_code is unrelated and likely originates from a new version of the CCD released by the RCSB (will be fixed in #878). I would merge this PR if you agree.

@LiudengZhang
Copy link
Contributor Author

Thanks for the review! Yes, please go ahead and merge. Happy to help — and good to know this can serve as a template for the other optional fields in _atom_site.

@padix-key padix-key merged commit 9c6df8b into biotite-dev:main Mar 19, 2026
12 of 32 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.

Failure to parse mmCIF files lacking _atom_site.pdbx_PDB_ins_code

2 participants