Write the entry identifier as a data item, not only as the block name - #1144
Open
aalhossary wants to merge 1 commit into
Open
Write the entry identifier as a data item, not only as the block name#1144aalhossary wants to merge 1 commit into
aalhossary wants to merge 1 commit into
Conversation
AbstractCifFileSupplier put the PDB identifier only in the data_ block
header, so it was lost for every consumer that reads it as a data item:
- BioJava's own CifStructureConsumerImpl.consumeStruct reads
_struct.entry_id, so Structure.getPdbId() came back null after a
write-then-read round trip;
- Jmol's mmCIF reader takes _M.pdbID from _entry.id, so a structure
handed over with openStringInline(structure.toMMCIF()) arrived with
no identifier, which in turn breaks anything keyed on the entry
(for instance "isosurface ... eds", which needs an entry to fetch
the electron density map for).
Write both categories when the structure has an identifier. Both are
needed: _entry.id is the canonical item and the one Jmol reads, while
BioJava's own reader only looks at _struct.entry_id.
Adds a round-trip regression test; there was nothing asserting that an
identifier survived toMMCIF().
Fixes biojava#1143
aalhossary
force-pushed
the
aa/emit-entry-id
branch
from
August 18, 2026 14:34
909df43 to
0225df7
Compare
aalhossary
marked this pull request as ready for review
August 18, 2026 14:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1143
The problem
AbstractCifFileSupplierwrote the PDB identifier only as the name of thedata_block, and emitted neither_entry.idnor_struct.entry_id. Consumers read the identifier as a data item, not from the block header, so it did not survive being written:CifStructureConsumerImpl.consumeStructreads_struct.entry_id, soStructure.getPdbId()came back null after atoText()/fromInputStream()round trip._M.pdbIDfrom_entry.id, so a structure handed over withopenStringInline(structure.toMMCIF())arrived with no identifier — which in turn breaks anything keyed on the entry, such asisosurface ... eds, which needs an entry to fetch the electron density map for.The change
Write both categories immediately after entering the block, guarded on the identifier being present (mirroring the existing null check):
Both are needed, not one:
_entry.idis the canonical item and the one Jmol reads, while BioJava's own reader only looks at_struct.entry_id, so omitting that one would leave BioJava still unable to read back what it just wrote._structwas not previously written anywhere in this class (only_struct_keywords, a separate category), so there is no duplicate-category concern.Tests
CifFileSupplierImplTestgains two cases — there was previously nothing asserting that an identifier survivestoMMCIF():shouldWriteEntryIdAndSurviveRoundTrip— reads4hhb.cif.gz, asserts both items are written, reads the text back and assertsgetPdbId()still equals4HHB.shouldNotWriteEntryIdWhenPdbIdIsAbsent— a structure with no identifier gains no empty entry categories.Verified that the round-trip test fails on unpatched
master(_entry.id must be written) and passes with the change; the pre-existing test in that class is unaffected.Notes
master(5b29945); independent of any other open PR.