Q&A-8Design and defend a structural analysis for PDBx/mmCIF parsing.
Answer
Assumptions. Input is wwPDB-distributed PDBx/mmCIF, not legacy fixed-column PDB; files run from ~1 MB to a few hundred MB for large assemblies; downstream analysis needs coordinates and metadata (entities, sequences, method). The dictionary version is whatever the file declares in _audit_conform.dict_version.
Core answer. Parse with a dictionary-aware library, gemmi or RCSB's pdbx/CIFParse, into a structure keyed on label identifiers, carry auth identifiers as attributes, keep ? and . distinct, and select models explicitly instead of assuming one. Hand-rolling a tokenizer is defensible only when you consume a single category and control the producer; otherwise you re-implement quoting, semicolon text fields and loop_ semantics, and you break on dictionary drift. BioPython's MMCIFParser is a reasonable middle option for small files and common categories.
Why not split on whitespace. mmCIF is whitespace-separated tokens, but a token can be quoted or a semicolon text field. Trace this tokenizer on one line:
def tokenize(line):
toks, i, n = [], 0, len(line)
while i < n:
c = line[i]
if c in " \t":
i += 1
elif c in "'\"":
j = line.index(c, i + 1)
toks.append(line[i+1:j]); i = j + 1
else:
j = i
while j < n and line[j] not in " \t":
j += 1
toks.append(line[i:j]); i = j
return toksInput _citation.title 'Crystal structure of lysozyme at 1.5 A' yields ['_citation.title', 'Crystal structure of lysozyme at 1.5 A']: 2 tokens. line.split() returns 8. Any loop_ row whose column count disagrees with the header is the detection signal; assert it at parse time.
Identifiers. mmCIF carries two parallel numbering schemes:
| field | meaning | example |
|---|---|---|
label_seq_id | contiguous per entity | 1,2,3 |
auth_seq_id | author numbering, gaps allowed | 1,2,3,100 |
pdbx_PDB_ins_code | insertion code | '', 'A', 'B' |
Key residues on (label_asym_id, label_seq_id); that pair is unique. (auth_asym_id, auth_seq_id) is not: antibody numbering 100, 100A, 100B collapses to one residue if you drop pdbx_PDB_ins_code. Keep auth fields as attributes for reporting.
Models. _atom_site.pdbx_PDB_model_num distinguishes models. An NMR ensemble with 20 models × 1,000 atoms is 20,000 _atom_site rows; merging them yields 1,000 atoms with averaged coordinates and destroys the inter-model RMSD you were going to compute. Select one model, or keep the model axis.
Missing values. ? is unknown, . is not applicable. Coercing both to None loses the distinction; coercing ? to 0 in a numeric column silently corrupts geometry. Detect by counting ?/. per column and failing when a required column exceeds a threshold.
Dictionary drift. New categories appear between dictionary versions. A parser pinned to an old dictionary drops them silently. Read _audit_conform.dict_version, log it, and warn when it is newer than the dictionary your code was built against.
Failure modes and detection. Quoted value split → column-count mismatch. Semicolon text field → line-based parser sees a stray ; at column 1. auth/label confusion → duplicate residue keys. Insertion codes lost → residue count drops. Models merged → atom count equals single-model count. ? coerced → impossible coordinates. Each is caught by an assertion on the parsed structure, not by eyeballing output.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.