DEV Community

devin2xing
devin2xing

Posted on Edited on

Molecular Fingerprints and Tanimoto Similarity — Worked Examples

Molecular Fingerprints and Tanimoto Similarity — Worked Examples

A chemist can look at two structures and say they look alike. A screening script cannot. It needs a number. A common number is a Tanimoto coefficient computed on a molecular fingerprint.

That number is easy to over-interpret. The examples below are responses from SeqChem's public similarity API. They show how the score and the bit counts look for a few pairs, and that changing the fingerprint can change the ranking. A high score is not a proof that two records are the same compound, and there is no Tanimoto cutoff that has that meaning across fingerprints.

What a fingerprint is

This article discusses binary fingerprints: bit strings. A bit may be set because a hashed fragment or a SMARTS pattern was present in the structure. That is not the same as each bit standing for one unique chemical feature. In a hashed fingerprint, different fragments can be assigned the same bit. A set bit does not uniquely identify a fragment: different fragments can map to the same bit.

A fingerprint is not a unique identifier. Two different molecules can share a fingerprint, especially a short one. The same structure is expected to give the same fingerprint only when the implementation, version, settings, and preprocessing — including how the input is read and standardized — are the same.

The Tanimoto coefficient

If A and B are the sets of bits set in each fingerprint:

T = |A ∩ B| / |A ∪ B|

When the union is greater than zero, a score of 1.0 means the two fingerprints have the same set bits, and a score of 0.0 means they share none. The API also returns the four counts behind the ratio: bits_a, bits_b, common and union.

All worked examples in this article have union > 0. This article does not discuss, and does not guess, how the service behaves when the union is zero, including the case where both fingerprints have no bits set.

There is no universal Tanimoto threshold, across fingerprints, that means "the same compound", "a similar scaffold", or "little structural overlap". A cutoff reported for one fingerprint, implementation, or dataset does not automatically apply to another.

Which fingerprint?

SeqChem's similarity endpoint accepts four Open Babel fingerprints. The descriptions below follow Open Babel's fingerprint documentation, not informal comparisons of speed, permissiveness, or interpretability:

  • FP2 — indexes linear fragments of up to 7 atoms; single-atom fragments of C, N, and O are ignored, and a fragment is terminated when the atoms form a ring. Each remaining canonical fragment is assigned a hash number from 0 to 1020, which is used to set a bit in a 1024-bit vector. Open Babel describes this as somewhat similar to Daylight fingerprints. In the checks below, omitting fp on one pair matched an explicit fp=FP2 request; the public API documentation also lists FP2 as the default.
  • FP3 — SMARTS patterns specified in the file patterns.txt.
  • FP4 — SMARTS patterns specified in the file SMARTS_InteLigand.txt.
  • MACCS — SMARTS patterns specified in the file MACCS.txt.

Source: the Open Babel fingerprint documentation (the page retrieved for this revision is titled Open Babel 3.0.1 documentation). Always report the fingerprint with the score. A value of 0.85 under FP2 is not the same claim as a value of 0.85 under FP3.

Worked examples

Unless a table says otherwise, the results below use the default FP2 fingerprint. The numbers are as returned by https://api.seqandchem.com on 22 November 2026 between 11:35 and 11:36, Asia/Shanghai (UTC+8). The JSON bodies and response headers did not include an Open Babel or application version, so the library version for these responses is unknown.

Two SMILES, identical fingerprints

Aspirin can be written CC(=O)Oc1ccccc1C(=O)O or O=C(C)Oc1ccccc1C(=O)O. Those strings are different. In this request, the fingerprints were not:

Field Value
bits_a / bits_b 53 / 53
common / union 53 / 53
Tanimoto 1.0

Identical fingerprints are not a test of chemical identity. If the task is to decide whether two records represent the same compound, first define a normalization policy for salts, protonation, tautomerism and stereochemistry, then compare the standardized structures. InChI can be part of that comparison, but only under a stated InChI standard and option set. Standard InChI and a non-standard InChI are not interchangeable, and the identifier also depends on the standardization applied to the input before InChI is generated.

A close analogue: aspirin and its methyl ester

Input A: CC(=O)Oc1ccccc1C(=O)O (aspirin)

Input B: CC(=O)Oc1ccccc1C(=O)OC (the methyl ester)

Field Value
bits_a / bits_b 53 / 58
common / union 53 / 58
Tanimoto 0.9138

Every bit set in the aspirin fingerprint is also set in the ester fingerprint (common equals bits_a). The ester fingerprint has five additional set bits (bits_b − common = 5). The score is high, but these are not the same compound: one structure is a carboxylic acid and the other is its methyl ester. High similarity is not identity.

A hydrolysis product: aspirin and salicylic acid

Input B: Oc1ccccc1C(=O)O

Field Value
bits_a / bits_b 53 / 33
common / union 33 / 53
Tanimoto 0.6226

All 33 set bits in the salicylic acid fingerprint are also set in the aspirin fingerprint (common equals bits_b). Under this fingerprint, the score is lower than for the ester pair above. That difference reflects a change in the set of features recorded by the current algorithm for these two inputs. The bits were not decoded, so this article does not attribute the change to a single functional group.

A different scaffold: aspirin and caffeine

Input B: CN1C=NC2=C1C(=O)N(C(=O)N2C)C

Field Value
bits_a / bits_b 53 / 70
common / union 15 / 108
Tanimoto 0.1389

Fifteen bits still overlap, on a union of 108. The bits were not decoded, so this article does not treat those shared bits as particular substructures.

The same pair, four fingerprints

Aspirin versus its methyl ester, and aspirin versus salicylic acid, under all four fingerprints:

Fingerprint Aspirin vs methyl ester Aspirin vs salicylic acid
FP2 0.9138 0.6226
FP3 0.5833 0.6667
FP4 0.9167 0.6
MACCS 0.8696 0.7391

For these two pairs, FP2 and FP4 give the ester the higher score, while FP3 ranks them in the opposite order. If you compare scores across papers or tools, check that the fingerprint, implementation, version, settings and preprocessing are the same.

Small molecules, and a score of 1.0 that is not identity

Ethanol (CCO) and propan-1-ol (CCCO) are homologues, not the same molecule.

Fingerprint Tanimoto bits_a / bits_b common / union
FP2 0.6 3 / 5 3 / 5
FP3 1.0 5 / 5 5 / 5
FP4 0.6667 4 / 6 4 / 6
MACCS 0.6429 9 / 14 9 / 14

Under FP3, this request returned identical fingerprints (Tanimoto 1.0, and common equals union). That result is for this pair and this fingerprint only; it is not a general claim about how FP3 behaves on other molecules. Ethanol versus methanol (CO) was 0.3333 under FP2, on a union of three bits. With so few bits set, a single bit moves the score a long way. A cutoff taken from another fingerprint, or from larger molecules, should not be applied here as if it were a general rule.

When a comparison fails

A structure that cannot be parsed is an HTTP 400, not a score of zero. In this check, b was the string not_a_molecule:

{"ok": false, "error": "Could not parse one of the molecules"}
Enter fullscreen mode Exit fullscreen mode

If either a or b is missing, the error in this check is Both molecules are required.

Calling it from a script

curl -sS https://api.seqandchem.com/api/v1/similarity \
  -H 'Content-Type: application/json' \
  -d '{"a":"CC(=O)Oc1ccccc1C(=O)O","b":"CC(=O)Oc1ccccc1C(=O)OC","fp":"FP2"}'
Enter fullscreen mode Exit fullscreen mode

A successful body includes tanimoto, bits_a, bits_b, common and union. The fp field accepts FP2 (the default listed in the public API documentation), FP3, FP4 and MACCS. Both molecules are required.

The same pairs can be pasted into the similarity tool. If you want the bit string itself, POST /api/v1/fingerprint returns it for a molecule, with the same fingerprint names. For aspirin, that endpoint's result text reports 53 bits set, which matches bits_a in the tables above.


Compare two structures with the free molecular similarity tool.

Top comments (0)