Skip to content

Build a real protein from the Protein Data Bank - #19

Open
jdeast wants to merge 1 commit into
mainfrom
protein-example
Open

jdeast wants to merge 1 commit into
mainfrom
protein-example

Conversation

@jdeast

@jdeast jdeast commented Sep 9, 2026

Copy link
Copy Markdown
Owner

protein.py reads an entry from RCSB, live, and builds it at a size you can walk round.

The default draws the fold, not the atoms. A protein is one long chain that folds into one shape, and the shape is the point. Drawn as every atom you get a solid lump, because the inside of a protein is packed and the chain you came to see is buried. One point per amino acid, joined up, is the chain. --style spacefill gives the lump, which is worth seeing once for exactly that reason.

The colours are read, not guessed. A PDB file carries HELIX and SHEET records written by whoever solved the structure, so red helix / yellow sheet / white loops is what the crystallographers said. It reproduces the known composition of four very different folds:

helix sheet
1MBN myoglobin 118/153 0 canonical all-α globin
4HHB haemoglobin 448/574 0 same fold
1EMA GFP 16 107 β-barrel, 11 strands
1CRN crambin 21 8 two short helices + small sheet

Two globins with zero sheet and GFP overwhelmingly sheet is not something a parsing bug lands.

The format is punch cards, and that is the whole difficulty. An atom named CA in columns 13–16 is the alpha carbon every amino acid has in the middle of it; an atom whose element is CA in columns 77–78 is calcium. Split the line on whitespace and the chain trace grows a spur out to wherever the calcium ion sits. There's a test for that, and for altLoc conformers, waters, ligands and NMR models — all against inline text, no network.

Built and verified in-world: 1UBQ came out at exactly the planned 14,613 blocks, with the colour split (42% sheet / 37% loop / 21% helix) mirroring the residue counts.

14 new tests, 250 total.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kq1Cjkh3bVT1WLzh5FRVQG

A protein is one long chain that folds into one particular shape, and the
shape is the entire point -- it decides what the protein does, and the same
links in a different arrangement do a different job or none. protein.py reads
an entry from RCSB and builds it at a size you can walk round.

The default draws the fold and not the atoms. Every atom gives a solid lump,
because the inside of a protein is packed and the chain you came to see is
buried; one point per amino acid, joined up, is the chain itself. --style
spacefill gives the lump, which is worth seeing once for exactly that reason.

Colours are the secondary structure, and they are read rather than guessed: a
PDB file carries HELIX and SHEET records written by whoever solved the
structure, so red helix / yellow sheet / white loops is what the crystallo-
graphers said, not what some heuristic here decided. It reproduces the known
composition of four very different folds -- myoglobin 118 helix and 0 sheet,
haemoglobin 448 and 0, both all-alpha globins; GFP 16 and 107, a beta barrel;
crambin 21 and 8.

The format is punch-card fixed columns and that is the whole difficulty. An
atom NAMED "CA" in columns 13-16 is the alpha carbon every amino acid has in
the middle of it; an atom whose ELEMENT is "CA" in columns 77-78 is calcium.
Split the line on whitespace and the chain trace grows a spur out to wherever
the calcium ion is sitting. There is a test for that, and for altLoc, waters,
ligands and NMR models, all against inline text and no network.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kq1Cjkh3bVT1WLzh5FRVQG

This branch has not been deployed

No deployments
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.

1 participant