Impact of 'nBits' on GetHashedMorganFingerprint()

This section provides a tutorial example on impact of the 'nBits' option on fingerprint generation with rdkit.Chem.rdMolDescriptors.GetHashedMorganFingerprint() function.

The 'nBits' option in the rdkit.Chem.rdMolDescriptors.GetHashedMorganFingerprint() function call allows you to control the range of smaller integers of the fingerprint. The default is nBits=2048, which is capable to represent 2048 identifiers in a perfect scenario.

Hashing identifiers to smaller integers may create collision conditions where different identifiers are hashed to the same integer.

1. For example, "OOOOOOOO" has 5 different identifiers with radius=1. They will be hashed into 4 different smaller integers with nBits=16.

from rdkit.Chem import AllChem
from rdkit.DataStructs.cDataStructs import UIntSparseIntVect
mol = AllChem.MolFromSmiles('OOOOOOOO')
fp = AllChem.GetMorganFingerprint(mol, 1)
display(UIntSparseIntVect.GetNonzeroElements(fp))

fp = AllChem.GetHashedMorganFingerprint(mol, 1, nBits=16,
  bitInfo=bitInfo)
display(UIntSparseIntVect.GetNonzeroElements(fp))

# output 
{864662311: 2, 864674487: 6, 2379014453: 2, 3705148550: 4, 3706500114: 2}
{2: 2, 5: 2, 6: 4, 7: 8}

Identifier 864662311 and identifier 864674487 are collided, when both are hashed to 7. But their number of duplications 2 and 6 are maintained in the fingerprint as the sum of 8.

2. Now if we use "nBits=64", there will be no collision when hash those 6 different identifiers.

mol = AllChem.MolFromSmiles('OOOOOOOO')
fp = AllChem.GetMorganFingerprint(mol, 1)
display(UIntSparseIntVect.GetNonzeroElements(fp))

fp = AllChem.GetHashedMorganFingerprint(mol, 1, nBits=64,
  bitInfo=bitInfo)
display(UIntSparseIntVect.GetNonzeroElements(fp))

# output 
{864662311: 2, 864674487: 6, 2379014453: 2, 3705148550: 4, 3706500114: 2}
{6: 4, 18: 2, 39: 2, 53: 2, 55: 6}

Conclusion: We should increase nBits as large as possible to avoid collisions when hashing identifiers into smaller integers.

Table of Contents

 About This Book

 SMILES (Simplified Molecular-Input Line-Entry System)

 Open Babel: The Open Source Chemistry Toolbox

 Using Open Babel Command: "obabel"

 Generating SVG Pictures with Open Babel

 Substructure Search with Open Babel

 Similarity Search with Open Babel

 Fingerprint Index for Fastsearch with Open Babel

 Stereochemistry with Open Babel

 Command Line Tools Provided by Open Babel

 RDKit: Open-Source Cheminformatics Software

 rdkit.Chem.rdchem - The Core Module

 rdkit.Chem.rdmolfiles - Molecular File Module

 rdkit.Chem.rdDepictor - Compute 2D Coordinates

 rdkit.Chem.Draw - Handle Molecule Images

 Molecule Substructure Search with RDKit

 rdkit.Chem.rdmolops - Molecule Operations

 Daylight Fingerprint Generator in RDKit

Morgan Fingerprint Generator in RDKit

 What Is Morgan Fingerprint Generator in RDKit

 GetMorganFingerprint() Method in RDKit

 Impact of 'radius' on GetMorganFingerprint()

 Impact of 'useCounts' on GetMorganFingerprint()

 Impact of 'invariants' on GetMorganFingerprint()

 Impact of 'useBondTypes' on GetMorganFingerprint()

 Impact of 'fromAtoms' on GetMorganFingerprint()

 GetMorganFingerprintAsBitVect() Method in RDKit

 Impact of 'nBits' on GetMorganFingerprintAsBitVect()

 GetHashedMorganFingerprint() Method in RDKit

Impact of 'nBits' on GetHashedMorganFingerprint()

 GetMorganGenerator() Method in RDKit

 Morgan Fingerprint Generator in RDKit for FCFP

 RDKit Performance on Substructure Search

 Introduction to Molecular Fingerprints

 OCSR (Optical Chemical Structure Recognition)

 AlphaFold - Protein Structure Prediction

 Resources and Tools

 Cheminformatics Related Terminologies

 References

 Full Version in PDF/EPUB