How a molecule becomes a vector
“These two molecules are similar” is a sentence a chemist gets to say without much effort. For a database, it is a bit more nuanced. The database needs the same sentence as a number, computable for every pair among tens of thousands of compounds.
SMILES strings, the standard way of writing a structure as a line of text, do not help. Two strings can differ in almost every character and describe nearly the same molecule. There is no straightforward way to average them, cluster them, or measure a distance between them that conveys the intended meaning.
Fingerprints record which substructures are present
In contrast, an ECFP fingerprint - also called a Morgan fingerprint - does something very straightforward. For every atom it looks at the neighborhood around that atom up to a fixed pre-specified radius, describes what it finds, hashes the description into an integer, and sets the corresponding bit. ECFP4 means a radius of two bonds, which is a diameter of four bonds.
The molecule becomes a fixed-length bit vector, commonly 2048 bits. The set bits describe which substructures occur in it. The key property can be broken down to fixed length: whatever arrives in the pipeline, every molecule will occupy the same shape and comparing two molecules is a simple matter of bit operations.
The hashing trick comes with a cost
The conundrum: using the hashing approach, we are trying to fit an unlimited vocabulary of possible substructures into a fixed number of slots which means that unrelated fragments may land on the same bit. Such a collision amounts to a real loss of information, a trade-off which has to be accepted because the alternative is an ever-growing vocabulary. Accepting the alternative would break the fixed-length property that makes everything downstream cheap. Text pipelines make the same trade under the same name.
Tanimoto versus Euclidean distance
Picture each vector as a shopping basket with a bit reserved for every item in it. Two shopping baskets are similar when they share items, not when neither of them contains an apple. Euclidean distance cannot tell the two apart: an item that neither basket contains counts as agreement, exactly like an item both of them contain. With 2048 slots of which perhaps sixty are set, the shared zeros may drown out everything informative.
Tanimoto similarity, the Jaccard index applied to bit vectors, divides the number of bits set in both by the number set in either. What do we achieve by doing so? Only presence counts. That is why SARVault scores similarity with Tanimoto over ECFP4, and it is the same reason text pipelines reach for cosine similarity rather than Euclidean distance on sparse vectors, the kind that are mostly zeros.
What the vector does not know
The vector records which substructures occur. It does not tell us anything about three-dimensional shape, conformation, how tightly the molecule binds anything. Even stereochemistry enters as an optional feature.
What does that mean? Two molecules at Tanimoto 0.9 may differ by an order of magnitude with regard to potency. That gap is not a defect in the encoding but the phenomenon worth studying: an activity cliff is precisely where the encoding calls two molecules similar and the assay disagrees. See When similar molecules disagree.
That is the real lesson of the fingerprint. The encoding and the similarity measure are one decision rather than two, choosing a representation without choosing how distance is computed inside it leaves important parts up for interpretation.
Second of three notes on the same move: How a recipe becomes a row precedes this one, How a page becomes a vector follows.