Fingerprint generation
Fingerprint generation turns a molecule into a compact structural signature. RDKit supports several signatures that describe local atom environments, atom pairs, paths, fixed structural keys, or molecular shingles. These signatures feed similarity search, clustering, screening, and machine-learning workflows; see Molecular descriptors and fingerprints for the wider feature model and Descriptor calculation for non-fingerprint features.
Fingerprint families
The fingerprint families use different views of a molecule. Choose a family based on the structural signal that must remain visible after hashing.
RDKit fingerprints
The RDKit fingerprint is a path-based signature. It finds linear paths or branched subgraphs within a bond-length range, describes their atom and bond context, hashes each feature, and sets one or more bits. The standard range is 1 through 7 bonds in a 2048-bit result. It can include explicit hydrogens, branched paths, and bond order.
Its default atom labels distinguish atomic number and aromatic state. Path labels also reflect the local bond arrangement and the number of distinct atoms in a path. Paths that contain query bonds are not added to the result. These rules make the fingerprint sensitive to both the connected shape and the chemical labels of each path.
The fingerprint can fold to a smaller size to reach a target bit density. Folding preserves the relationship between a larger fingerprint and the same fingerprint generated at the smaller size, but it increases bit collisions. The path-based fingerprint is exposed by RDKFingerprint and by GetRDKitFPGenerator.
References: Code/…/FingerprintUtil.cpp• L267-331 Code/…/FingerprintUtil.cpp• L333-444 Code/…/RDKitFPGenerator.cpp• L43-116 Code/…/RDKitFPGenerator.cpp• L179-248 Code/…/Fingerprints.h• L23-63 Code/…/RDKitFPGenerator.h• L20-57 Code/…/RDKitFPWrapper.cpp• L51-103
Morgan fingerprints
The Morgan fingerprint is a circular atom-environment signature. It starts with atom invariants and grows each atom environment out to a chosen radius. The radius controls how much of the local structure can affect a feature. The default generator radius is 3, while the convenience bulk helpers use radius 2.
The default atom invariants produce ECFP-like features. A feature-invariant generator can instead group atoms by chemical features such as donors, acceptors, aromatic atoms, halogens, bases, and acids. Bond types and chirality can also affect the environment. The generator can omit redundant environments or restrict work to selected atoms.
References: Code/…/MorganGenerator.h• L21-78 Code/…/MorganGenerator.h• L111-156 Code/…/MorganWrapper.cpp• L76-145 Code/…/FingerprintGenerator.cpp• L847-865
Atom-pair fingerprints
The atom-pair fingerprint describes pairs of atoms by their atom invariants and the distance between them. It therefore keeps a longer-range relationship that a single local atom environment may not show. The generator can use topological 2D distance or distance from a 3D conformation, and it can limit the minimum and maximum distance.
Atom-pair fingerprints use count simulation by default. This represents repeated pairs with threshold bits rather than one bit with an unbounded count. Chirality can be part of the atom invariants, and a custom atom-invariant generator can replace the default one.
References: Code/…/AtomPairGenerator.h• L22-46 Code/…/AtomPairGenerator.h• L49-86 Code/…/AtomPairWrapper.cpp• L49-102
Topological torsion fingerprints
The topological torsion fingerprint describes fixed-length sequences of connected atoms. Its usual four-atom torsions capture local order along a path rather than only the two endpoints. The generator can use another atom count and can keep only paths that are shortest between their endpoints.
Topological torsion fingerprints use count simulation by default. Chirality can affect the atom invariants. This fingerprint type uses the 64-bit generator output in the Python interface.
References: Code/…/TopologicalTorsionGenerator.h• L21-48 Code/…/TopologicalTorsionGenerator.h• L96-136 Code/…/TopologicalTorsionWrapper.cpp• L45-89
MACCS fingerprints
The MACCS fingerprint is a fixed key signature. Each key represents a predefined structural or chemical pattern, and the result reports which keys match the molecule. RDKit returns a 167-bit vector because the 166 public keys use positions 1 through 166 for compatibility with other software. The extra position preserves that numbering scheme.
MACCS is not configured through the general fingerprint generator. Its fixed key set makes it useful when a workflow requires a known external key definition rather than a tunable hashed feature space.
References: Code/…/MACCS.h• L12-29 Code/…/MACCS.cpp• L22-36 Code/…/MACCS.cpp• L939-945
Pattern fingerprints
The pattern fingerprint is a fixed set of structural pattern matches. RDKit checks predefined substructure patterns and sets bits for matches. The normal result has a caller-selected size with a default of 2048 bits. A tautomeric mode can add a representation that treats selected single, double, and aromatic bond choices as equivalent.
Pattern fingerprints can also combine a molecule bundle into one result. In that case the result keeps bits common to the molecules in the bundle. This makes the bundle form useful for a shared screening pattern rather than for a count of all patterns across the bundle.
References: Code/…/Fingerprints.h• L116-153 Code/…/PatternFingerprints.cpp• L161-234 Code/…/PatternFingerprints.cpp• L338-373
MHFP fingerprints
MHFP uses molecular shingling and MinHash. A molecular shingle is a canonical substructure string taken from circular neighborhoods and, optionally, rings. The encoder hashes the shingles and keeps the minimum value for each configured permutation. The result is a vector of unsigned integers, not a normal bit vector.
The number of permutations sets the vector length. The seed and permutation count are part of the fingerprint contract, so vectors made with different values are not compatible. The standard encoder uses 2048 permutations and seed 42. Shingle radius, ring inclusion, isomeric output, kekulization, and minimum radius control which structural strings enter the MinHash. The default shingle radius is 3, ring shingles are included, and the minimum radius is 1.
The MHFP interface accepts either SMILES text or an RDKit molecule. It can return the shingle list before hashing, one MinHash vector, or a tuple of vectors for a batch. Its distance operation compares two MinHash vectors by their fraction of mismatched positions.
MHFP also provides SECFP. SECFP hashes the same type of circular substructure strings and folds them into an ExplicitBitVect, so it is the MHFP family’s binary output for bit-based similarity work. The SECFP length defaults to 2048 bits.
References: Code/…/MHFP.h• L44-59 Code/…/MHFP.h• L90-119 Code/…/MHFP.h• L180-249 Code/…/MHFP.cpp• L38-95 Code/…/MHFP.cpp• L98-181 Code/…/MHFP.cpp• L220-269 Code/…/MHFPWrapper.cpp• L31-73 Code/…/MHFPWrapper.cpp• L75-157 Code/…/MHFPWrapper.cpp• L34-197 Code/…/testMHFP.py• L21-92 Code/…/testMHFPFingerprint.cpp• L26-180
Fingerprint generator model
The general generator model separates the fingerprint family from the molecule-independent choices that shape its features. A generator combines fingerprint arguments with an environment generator and optional atom and bond invariant generators. This lets the same family produce several output forms without changing the structural definition.
The generation flow moves from a molecule to invariants and environments, then to hashed feature IDs, and finally to a bit or count representation. This diagram shows that shared flow and the separate MHFP path.
flowchart LR
M[Molecule] --> C[Configured fingerprint generator]
C --> I[Atom and bond invariants]
I --> E[Structural environments]
E --> H[Feature hashes]
H --> B[Explicit or sparse bit vector]
H --> N[Count vector]
M --> S[MHFP molecular shingles]
S --> Q[MinHash vector]
S --> SE[SECFP folded bit vector]
Common generator options
Common options apply across the generator families, although a family can ignore an option that does not fit its structural view. Per-call controls can also limit the atoms used to make a fingerprint or provide a selected 3D conformation where the family supports it.
| Option | Effect |
|---|---|
fpSize | Sets the width of dense and folded outputs. It does not set the natural size of sparse outputs. |
countSimulation | Converts feature counts into threshold bits for bit-vector output. |
countBounds | Supplies the thresholds used by count simulation. The default bounds are 1, 2, 4, and 8. |
numBitsPerFeature | Sets how many hashed bits represent each feature. It matters most for path-based RDKit fingerprints. |
includeChirality | Adds stereochemical information where the fingerprint family supports it. |
| custom atom or bond invariants | Replaces the family’s default atom or bond labels. |
fromAtoms | Limits environments to those that start at or center on selected atoms. |
ignoreAtoms | Excludes environments that include selected atoms. |
confId | Selects a 3D conformation for atom-pair fingerprints. |
Family-specific options add the structural limits described in Fingerprint families. For example, Morgan uses radius, atom-pair uses distance limits, RDKit uses path limits, and topological torsion uses atom count. MHFP uses its own encoder settings for permutation count and seed, plus shingle settings for radius, rings, stereochemistry, kekulization, and minimum radius.
References: Code/…/FingerprintGenerator.h• L90-123 Code/…/FingerprintGenerator.cpp• L36-87 Code/…/FingerprintGeneratorWrapper.cpp• L648-665 Code/…/FingerprintGeneratorWrapper.cpp• L426-546 Code/…/testGenerators.py• L301-345 Code/…/MHFP.h• L44-59 Code/…/MHFPWrapper.cpp• L178-264
Generator persistence
Generators can report their full configuration and serialize it to JSON. The JSON records the fingerprint arguments and the environment and invariant generators that define the feature space. Restoring that configuration is important when stored fingerprints must match fingerprints made later.
The JSON loader supports the four general generator families: Morgan, RDKit, atom-pair, and topological torsion. MACCS, pattern, and MHFP use their own APIs and are not restored through this general generator loader.
References: Code/…/FingerprintGenerator.cpp• L162-225 Code/…/FingerprintGenerator.cpp• L227-320 Code/…/FingerprintGeneratorWrapper.cpp• L603-604 Code/…/FingerprintGeneratorWrapper.cpp• L689-695 Code/…/testGenerators.py• L410-417
Fingerprint outputs
The generator exposes the same feature definition as dense bits, sparse bits, or counts. The choice changes storage and downstream arithmetic, not the structural features that the generator finds.
Bit-vector forms
An ExplicitBitVect stores a fixed-width array of bits. A SparseBitVect stores the set bits without requiring the full dense array. Both represent presence, but a count-simulated dense or sparse bit vector can use several positions to show that a feature occurs above different thresholds.
The Python wrapper also returns dense bits as a NumPy array of uint8. Bulk methods return one result per input molecule and preserve input order. They can use more than one thread without changing the result for each molecule. These forms are suited to bit similarity measures and bit-vector indexes; see Molecular descriptors and fingerprints.
References: Code/…/FingerprintGenerator.h• L348-372 Code/…/FingerprintGeneratorWrapper.cpp• L144-185 Code/…/FingerprintGeneratorWrapper.cpp• L550-587 Code/…/FingerprintGeneratorWrapper.cpp• L677-687 Code/…/testGenerators.py• L114-206 Code/…/testGenerators.py• L347-389
Count-vector forms
SparseIntVect count output keeps the number of times each hashed feature occurs. The fixed-width count form uses the configured fpSize; the sparse count form keeps feature IDs and counts without applying that dense width. A count vector preserves more occurrence information than a presence-only bit vector and can be converted to a NumPy uint32 array.
Hashing can map different environments to the same feature ID. Count output adds those occurrences together. Dense bit output only records that the resulting position is on.
References: Code/…/FingerprintGenerator.cpp• L323-434 Code/…/FingerprintGenerator.cpp• L575-651 Code/…/FingerprintGeneratorWrapper.cpp• L118-140 Code/…/FingerprintGeneratorWrapper.cpp• L257-278 Code/…/testGenerators.py• L269-288
MinHash-vector forms
MHFP MinHash output is a fixed-length vector of uint32 values. Each position stores the minimum transformed hash found for one permutation. The vector length equals the encoder’s permutation count, so it is not a dense bit-vector width.
The MinHash distance is the fraction of positions that differ. A separate SECFP call produces an ExplicitBitVect by hashing the shingles and folding them into the requested length. Use the MinHash form with MHFP distance and the SECFP form with bit-vector tools.
References: Code/…/MHFP.h• L61-88 Code/…/MHFP.h• L205-249 Code/…/MHFP.h• L258-272 Code/…/MHFPWrapper.cpp• L106-157 Code/…/MHFPWrapper.cpp• L138-197 Code/…/testMHFP.py• L21-92 Code/…/testMHFPFingerprint.cpp• L107-163
Feature provenance
Additional output can connect set bits back to the molecule. Depending on the fingerprint family, it can report the atoms involved in each bit, the bits linked to each atom, atom participation counts, Morgan atom-and-radius pairs, or path information. These reports are for interpretation and debugging; they are not part of the bit-vector value.
The available provenance differs by family. Morgan reports atom centers and radii, atom-pair reports endpoint pairs, RDKit reports bond paths, and topological torsion reports atom paths. Request only the reports needed by the caller because unrequested reports are absent.
References: Code/…/FingerprintGenerator.h• L27-81 Code/…/FingerprintGeneratorWrapper.cpp• L343-420 Code/…/FingerprintGeneratorWrapper.cpp• L615-646 Code/…/MorganWrapper.cpp• L119-124 Code/…/RDKitFPWrapper.cpp• L97-101 Code/…/testGenerators.py• L218-243 Code/…/testGenerators.py• L396-408
Fingerprint selection
The fingerprint family determines what “similar” means. A path fingerprint emphasizes connected fragments, Morgan emphasizes local circular environments, atom-pair emphasizes typed distances, and torsion emphasizes ordered atom sequences. MACCS and pattern use fixed structural definitions, while MHFP compares sets of molecular shingles through MinHash.
Use one configuration for every molecule in a comparison set. A change to fingerprint width, radius, path or distance limits, atom invariants, bond treatment, chirality, shingle settings, seed, or permutation count changes the feature space. For descriptor features that are not fingerprints, see Descriptor calculation.
Configuration matching
When a fingerprint is used for similarity or a stored index, keep these values aligned:
- Fingerprint family and API.
- Dense width or sparse feature-space definition.
- Count-simulation state and count bounds.
- Atom and bond invariant rules.
- Chirality, bond-type, hydrogen, path, distance, torsion, or shingle settings.
- MHFP seed and permutation count.
References: Code/…/FingerprintGenerator.cpp• L50-87 Code/…/MHFP.h• L47-59 Code/…/FingerprintGeneratorWrapper.cpp• L648-665 Code/…/FingerprintGeneratorWrapper.cpp• L735-766
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to generator arguments or invariant rules can make stored fingerprints incompatible even when the output width stays the same.
- Changes to count bounds must be applied to both count-simulated bit generation and any code that interprets threshold positions.
- Changes to
AdditionalOutputmappings must stay aligned with the family-specific provenance promised by the Python wrapper. - Changes to MACCS key numbering or pattern definitions can alter external compatibility without changing the API shape.
- Changes to MHFP permutation count or seed require coordinated updates to every producer and consumer of MinHash vectors.
- Changes to MHFP shingle defaults or the SMILES-to-molecule wrapper path can change both the shingle set and the MinHash values.
- Changes to MHFP and SECFP bulk wrappers must preserve one output per input and the same order as the input sequence.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Compare fingerprints made with different family settings | Similarity scores describe different feature spaces | Persist and restore the generator configuration with the fingerprint data. |
| Enable count simulation without usable count bounds | Dense generation rejects the configuration or produces the wrong threshold layout | Keep non-empty bounds and ensure the configured fingerprint size can hold the simulated positions. |
| Use different MHFP seeds or permutation counts | MinHash vectors cannot be compared as compatible signatures | Construct all encoders with the same seed and permutation count. |
| Treat an MHFP MinHash vector as a bit vector | Bit-vector similarity code receives the wrong representation | Use MHFP distance for MinHash vectors or use SECFP when a binary vector is required. |
| Request provenance that a fingerprint family does not support | The requested report is absent or has no family-specific meaning | Check the family’s supported AdditionalOutput fields before consuming the report. |
| Kekulization fails during MHFP shingling | Shingle creation stops with an exception | Use a valid molecule and enable kekulization only when the input can be kekulized. |
| Compare MinHash vectors with different lengths | The distance calculation does not represent the same permutation space | Use encoders with the same permutation count before calling Distance. |
Key files
| File | Why to read it |
|---|---|
| Code/…/FingerprintGenerator.h | Defines the shared generator model, configuration, output forms, and provenance contract. |
| Code/…/FingerprintGenerator.cpp | Shows how configured environments become count, dense-bit, sparse-bit, and bulk results. |
| Code/…/MorganGenerator.h | Describes Morgan environments, ECFP-like and feature-based invariants, and radius choices. |
| Code/…/FingerprintUtil.cpp | Defines shared atom labels, path discovery, and path feature construction used by fingerprint families. |
| Code/…/RDKitFPGenerator.cpp | Shows how RDKit path settings and atom labels become path environments and fingerprint features. |
| Code/…/RDKitFPGenerator.h | Describes path and branched-subgraph settings for the RDKit fingerprint. |
| Code/…/AtomPairGenerator.h | Describes typed atom pairs, distance bounds, and count simulation. |
| Code/…/TopologicalTorsionGenerator.h | Describes torsion length, shortest-path choice, and supported outputs. |
| Code/…/Fingerprints.h | Defines the public RDKit, pattern, and unfolded path-fingerprint entry points. |
| Code/…/MACCS.h | Defines the fixed 167-bit MACCS result and key-numbering contract. |
| Code/…/MHFP.h | Defines molecular shingling, MinHash, SECFP, and encoder compatibility rules. |
| Code/…/MHFP.cpp | Shows how shingle settings produce MinHash vectors and folded SECFP bit vectors. |
| Code/…/MHFPWrapper.cpp | Defines the current Python-facing MHFP and SECFP entry points and their defaults. |
| Code/…/FingerprintGeneratorWrapper.cpp | Shows the Python-facing generator methods, NumPy forms, bulk calls, per-call controls, and JSON boundary. |