Three ways to write down a molecule

Lesson 0.3 of Biology Primer for Computer Scientists. Download the code as a notebook.

Take the fifth and the sixty-eighth letters of ubiquitin's sequence. There are 62 residues between them. If you draw the sequence across a page, they sit near opposite ends. Fold the chain, and their central carbon atoms sit about 5.7 Å apart. They have become neighbors.

This is the first difficulty in doing geometry with a protein string. The order of the letters tells us which residues are linked along the chain. To know which residues meet across a fold, we need another representation. We will build it directly from ubiquitin's coordinates, then ask what each representation allows us to know.

The first folds were hard to guess

When John Kendrew and his colleagues worked out myoglobin's structure, the chain did not resolve into one simple repeating shape. Their early map revealed a compact, irregular arrangement; the more detailed 2 Å model published in 1960 showed how helical stretches were connected and packed. Myoglobin binds oxygen in muscle, using a heme group like the one in hemoglobin.See the 1960 structure report and Kendrew's account of the irregular fold.

The regular local pieces were easier to describe than their arrangement into a whole molecule. A helix can have repeated geometry while each connecting turn takes a different route. That is the distinction we are about to encounter numerically: knowing the local chain connections does not tell us which distant stretches pack together. For ubiquitin, we can now load the answer and inspect it a pair of residues at a time.

Start with the coordinates

The Protein Data Bank, or PDB, archives experimentally determined structures. An entry contains an atomic model and information about the experiment behind it. The identifier 1UBQ names a crystal structure of ubiquitin. Its coordinates were inferred from X-ray diffraction data, with chemical constraints helping determine an arrangement consistent with those data.

Load chain A and take one point per residue: the α-carbon, Cα, to which the side chain attaches.

import numpy as np
from primer import structure, sequence

ubq = structure("1UBQ")[0]["A"]          # model 0, chain A
residues = [r for r in ubq if r.id[0] == " "]   # amino acids only (skip the 58 waters)
seq = sequence(ubq)
print(seq, len(seq))

ca = np.array([r["CA"].coord for r in residues], dtype=float)   # one atom per residue: the alpha carbon
print(ca[:3].round(2))
MQIFVKTLTGKTITLEVEPSDTIENVKAKIQDKEGIPPDQQRLIFAGKQLEDGRTLSDYNIQKESTLHLVLRLRGG 76
[[26.27 25.41  2.84]
 [26.85 29.02  3.9 ]
 [26.24 30.06  7.5 ]]

The result is a 76-letter string and a 76×3 array. Row i of the array is the position of one residue's Cα. The full model lists 602 protein atoms; selecting Cα gives us a simpler trace of the chain. We have deliberately discarded the positions of the other atoms.

The coordinate origin is arbitrary. A value of x=27 Å does not mean that an atom is 27 Å from some biologically special point. Differences between coordinates are what let us measure the molecule. For two positions 𝐫i and 𝐫j, their separation is

dij=‖𝐫i−𝐫j‖.

Compute this for every pair and we have a distance matrix. For 76 points it contains 762=5,776 entries. It is symmetric because dij=dji, and its diagonal is zero.

Turning geometry into a graph

Choose a cutoff, say 8 Å, and call two residues in contact when their Cα atoms lie closer than that. Each residue becomes a node, each contact an edge. The resulting adjacency matrix is a contact map. The cutoff is a convention: a Cα contact says two residues are near one another, without promising that particular side-chain atoms actually touch.

D = np.linalg.norm(ca[:, None, :] - ca[None, :, :], axis=-1)   # 76 x 76 distance matrix, in Å
contact = D < 8.0
i, j = np.triu_indices(len(ca), k=1)                            # each pair once
in_contact = contact[i, j]
sep = j - i                                                     # distance along the sequence
print(f"{in_contact.sum()} residue pairs in contact")
print(f"  {(in_contact & (sep < 6)).sum()} of them within 5 positions in the sequence")
print(f"  {(in_contact & (sep >= 24)).sum()} of them 24 or more positions apart")
print(f"consecutive Cα atoms: {np.diag(D, 1).min():.2f} to {np.diag(D, 1).max():.2f} Å apart")
326 residue pairs in contact
  210 of them within 5 positions in the sequence
  73 of them 24 or more positions apart
consecutive Cα atoms: 3.76 to 3.85 Å apart

Consecutive Cα atoms are usually about 3.8 Å apart, so contacts near the diagonal are expected simply from chain connectivity. They do not tell us much about the fold. Contacts far from the diagonal are more revealing. The 5–68 contact means that a late part of the chain has returned to a region occupied near its beginning.

Code
from primer import display_widget

display_widget(
    "molecule-views",
    "Ubiquitin (1UBQ) three ways. Point at a letter, a cell of the contact map, or an atom, and the same "
    "residues light up in all three. Pale cells in the map are sequence neighbors (fewer than 6 positions "
    "apart); dark cells are contacts between distant parts of the chain. Drag the 3D view to turn it. Atoms "
    "run from light (N-terminus) to dark (C-terminus).",
    sequence=seq,
    ca=ca.round(2).tolist(),
    cutoff=8,
)

Loading the interactive figure…

Ubiquitin (1UBQ) three ways. Point at a letter, a cell of the contact map, or an atom, and the same residues light up in all three. Pale cells in the map are sequence neighbors (fewer than 6 positions apart); dark cells are contacts between distant parts of the chain. Drag the 3D view to turn it. Atoms run from light (N-terminus) to dark (C-terminus).

Point at residue 5 in the linked views, then find its contact with residue 68. Turn the structure until you can follow the two stretches of chain alongside one another. Now move to a point near the map's diagonal. Its neighbors are easy to predict from the sequence because they are close along the chain.

There is another graph we must keep separate: the covalent bond graph. Its nodes are atoms, and an edge means a chemical bond. Folding usually changes the contact map while leaving this bond graph intact. For a standard protein, the sequence largely specifies the bond graph through known residue chemistry. It does not directly specify the contact graph.

RepresentationWhat it explicitly recordsWhat a computation still needs
Sequenceresidue identities and ordera model of their chemistry and spatial arrangement
Covalent bond graphatoms, chemical connections, and bond orderscoordinates or other geometric constraints
Cα contact mapwhich selected atom pairs pass a distance cutoffdistances within the cutoff, atomic detail, and handedness
Atomic coordinatespositions of the listed atoms in one arrangementatom identities, bonding, protonation, experimental context, and other possible arrangements

Even full coordinates are not a complete description of a protein in solution. A flexible loop may occupy many positions, a ligand may bind and leave, and protons may come and go. A single model is a specific representation of that physical system.

Move the molecule without changing it

Suppose we translate every coordinate by the same vector. The vector cancels in every difference 𝐫i−𝐫j, so distances are unchanged. A rotation also preserves lengths. We can change every number in the coordinate array while preserving the internal geometry exactly.

rng = np.random.default_rng(0)
Q, _ = np.linalg.qr(rng.normal(size=(3, 3)))      # a random orthogonal matrix
R = Q if np.linalg.det(Q) > 0 else -Q             # make it a proper rotation (det = +1)
moved = ca @ R.T + np.array([10.0, -4.0, 25.0])   # rotate, then translate

D_moved = np.linalg.norm(moved[:, None] - moved[None], axis=-1)
print("first atom before:", ca[0].round(2), " after:", moved[0].round(2))
print("largest change in any distance:", np.abs(D_moved - D).max().round(6), "Å")

mirror = ca * np.array([-1.0, 1.0, 1.0])          # reflect through a plane
D_mirror = np.linalg.norm(mirror[:, None] - mirror[None], axis=-1)
print("mirror image, largest change in any distance:", np.abs(D_mirror - D).max().round(6), "Å")
first atom before: [26.27 25.41  2.84]  after: [ -3.68 -28.91   1.85]
largest change in any distance: 0.0 Å
mirror image, largest change in any distance: 0.0 Å

The first atom moves, while the largest change in a pairwise distance is zero to the printed precision. An isolated molecule's internal energy should obey the same symmetry. If we include a binding partner, we must move that partner too: rotating only the protein changes its position relative to the partner.

This tells us something useful before choosing a prediction algorithm. A scalar output such as an internal energy should be invariant under a joint rigid motion. A coordinate output should be equivariant: rotate the input arrangement and the output should rotate with it. A model can learn an approximation to this behavior from many rotated training examples. It can also have the behavior built into its mathematics, making the symmetry hold for inputs it has never seen.

The last part of the cell reflects the coordinates through a plane. Every distance survives this operation too. But a reflected protein has reversed handedness, just as your left hand is a reflection of your right. You cannot obtain that arrangement by rotating the original protein. Even a complete exact distance matrix leaves this ambiguity; a thresholded contact map discards still more information. We will measure handedness explicitly in lesson 1.6.

Which question are we computing?

Structural bioinformatics uses representations like these to store, retrieve, compare, and reason about molecules in space. Sequence analysis might ask whether two strings share an ancestor. Structural analysis might ask whether the molecules have similar folds, or whether a particular surface could bind another molecule. The choice of representation follows the question.

TaskGivenSought
Structure determinationexperimental measurementsan atomic model consistent with those measurements
Structural classificationa collection of structuresgroups with shared structural features
Structure predictionsequence and relevant contextplausible structures, with estimates of uncertainty
Function predictionsequence or structureproposed activities, binding sites, or partners
Simulationa molecular model, conditions, and interaction rulesbehavior over time or sampled arrangements
Molecular designa desired structure or behaviora sequence or molecule likely to produce it

Analysis finds patterns in existing data. Prediction infers an unknown outcome from an input. Design chooses an input to obtain a desired outcome. A design program can call a predictor repeatedly, changing the proposed sequence and asking whether its predicted behavior has improved.

Consider a pocket that appears to bind a negatively charged ligand. Its positive side chains suggest a hypothesis: removing one positive charge will weaken binding. A program can propose the mutation and estimate its effect. An experiment can then measure binding before and after the change. If binding barely changes, perhaps water compensated, the side chain moved, or the original pose was wrong. The result gives us a reason to revise the model.

The programs in that loop have different jobs. A predictor generates a hypothesis. A program choosing which mutants to make helps design an experiment. A database stores its observations. A validation program tests whether a model fits the measured data or accepted geometry. A persuasive picture is useful for proposing an explanation; the comparison with evidence tests it.

Physics and examples teach different things

One way to search for a structure is to write an energy function and find favorable arrangements. Bond lengths, electric charges, and the cost of overlapping atoms provide explicit physical rules. The difficulty is that an approximate energy function must distinguish among an enormous number of shapes while accounting for water and thermal motion.

Another way is to learn from known sequences and structures. Related proteins contain examples of which substitutions a fold tolerates. Solved structures contain examples of how strands pack and which geometries recur. A model can learn regularities that would be difficult to specify by hand. Its success depends on whether its training examples are informative about the new case.

These approaches can be combined. A learned model can propose a fold while using geometric constraints to construct atoms. AlphaFold 2, for example, uses residue frames and operations designed to handle rigid motions consistently; its training also incorporates local structural geometry. This is a concrete example of known symmetry reducing what must be learned from examples.The geometric architecture and training are described in the AlphaFold 2 paper.

Machine-learning tasks still have particular inputs and outputs. A function classifier may map a sequence to activity labels. A design model may map a desired backbone to candidate sequences. A structure model returns geometry. Good geometry alone does not establish that a designed molecule binds tightly, reaches a target in the body, or has a useful effect there. Each further claim requires relevant measurements or a separately validated prediction.

Why sequence coverage and structure coverage differ

Sequencing a genome yields information about many proteins at once. Determining a structure requires additional work on a particular molecule or assembly: preparing a sample, collecting measurements, and building and checking a model. Sequence collections therefore contain far more distinct proteins than have been individually studied by structural experiments.

Counting database entries obscures this difference. One protein may have hundreds of deposited structures, each with a different ligand, mutation, or experimental condition. One deposited assembly may contain several different proteins. A predicted-model database counts another kind of object again. Dividing structure entries by sequence entries does not directly give the fraction of proteins whose structures we know experimentally.

The gap is partly softened by structural conservation. Proteins can accumulate many sequence changes while keeping a similar fold, the overall arrangement of their chain. A known structure can therefore inform models of related sequences. A classification's number of folds counts recurring arrangements, not molecules; that number also depends on how the classification draws its boundaries.

The same imbalance appears in machine learning. A large sequence collection can teach a model which strings resemble biological proteins. It supplies no automatic answer to which compounds bind a particular protein, or how strongly. Those labels require different experiments. A billion unlabeled examples cannot simply be counted as a billion measurements of the property we want.

A few structures to get to know

Ubiquitin will supply our smallest working example. The other recurring structures introduce features that one small chain cannot show:

EntryMoleculeSomething to inspect
1UBQubiquitin, 76 residuescontacts between distant parts of one sequence
4HHBdeoxyhemoglobin, two α and two β chainsfour chains assembled around four heme groups
1ATPprotein kinase A with ATP, manganese ions, and an inhibitor peptidea protein binding several chemically different partners
7RSAribonuclease A, 124 residuesfour disulfide cross-links
1EHZyeast phenylalanine tRNA, 76 nucleotidesan RNA chain folded into a compact three-dimensional shape

Turn deoxyhemoglobin until you can distinguish all four chains and their heme groups. Each heme contains an iron atom at which oxygen can bind; this entry represents the deoxygenated state. A single protein sequence would describe only one of the chain types in the assembly.

Open 4HHB in Mol*

Check yourself

You know a protein's complete covalent bond graph. Can you construct its contact map without making any additional assumptions? Explain using the effect of rotating a single bond.

Reasoning

No. Rotation about a suitable single bond can move distant atoms while keeping all covalent connections unchanged. Some contacts appear and others disappear. To obtain a contact map, we need coordinates or another source of information about the conformation.

A predictor assigns different internal energies to a protein and a rigidly rotated copy. What has failed? Would comparing all pairwise distances detect a mirror-image error as well?

Reasoning

The energy prediction violates rotational invariance. Distance-based inputs or a suitable symmetric architecture can enforce that property; rotation augmentation can approximate it. Pairwise distances cannot detect a mirror image, because reflection preserves every distance. Handedness needs additional information, such as an oriented volume.

A program proposes a sequence to bind hemoglobin, then another program predicts a convincing complex. Where are design, prediction, and experimental testing in this workflow?

Reasoning

Choosing the sequence is design. Inferring the complex is prediction. Testing would require evidence, such as measuring whether the proposed molecule binds and with what affinity. A second prediction may help choose an experiment, but agreement between programs is not a binding measurement.

An archive contains 1,000 structures, including 400 entries for one protein. A sequence collection has 10,000 proteins. Why does “10% have structures” fail, and how could fewer than 1,000 measured proteins still inform models of many more?

Reasoning

The numerator counts entries, including repeated observations of the same protein. It does not count 1,000 distinct proteins. Yet related proteins often share a fold, so an experimental structure can inform models for several sequences. Experimental coverage and the reach of inference are different quantities and need different accounting.