← Back to list

Beyond Molecular Fingerprints: Why Graph Neural Networks are the future.

For decades, the standard has relied on simple but powerful idea: fixed length vectors known as molecular fingerprints to represent complex…

falaq · 2026-03-26 13:37 · 5 claps · 3.5 min read
#graph-neural-networks #machine-learning #drug-discovery #computational-chemistry #ai-in-healthcare
Open on Medium ↗
Wiki topics: RAG · RAG & Retrieval ML · Machine Learning PHM · Pharmacology & Drug Discovery EDU · Education & Learning 🧪 · Chemistry

Beyond Molecular Fingerprints: Why Graph Neural Networks are the future.

For decades, the standard has relied on simple but powerful idea: fixed length vectors known as molecular fingerprints to represent complex molecules.

While this approach is powerful, it simplifies molecules while compressing rich and complex structural representation into binary patterns.

A molecular fingerprint is a numerical representation of molecule’s structure in 1’s and 0’s and are the foundation of modern chemistry.

Libraries like RDKit, make them accessible for wide range of tasks, such as structure prediction, property estimation and similarity searches.

As AI and machine learning evolves, the question remains. Are we representing the molecules effectively or are we limiting what models can learn.

To illustrate how molecular fingerprints work, let us consider a circular fingerprint (Morgan Fingerprint) to represent a molecule like Paracetamol

from rdkit import Chem
from rdkit.Chem import rdFingerprintGenerator

paracetamol_molecule_smiles = "CC(=O)NC1=CC=C(O)C=C1" # Example used Paracetamol
mol = Chem.MolFromSmiles(paracetamol_molecule_smiles)

fpgen = rdFingerprintGenerator.GetMorganGenerator(radius=2, fpSize=2048)

fp = fpgen.GetFingerprint(mol)

bits = list(fp.GetOnBits())
print("Morgan fingerprint active bits:", bits[:10], "...")
bit_string = fp.ToBitString()
print("Morgan fingerprint bits:", bit_string[:20], "...")
Morgan fingerprint active bits: [191, 245, 530, 650, 745, 807, 843, 849, 1017, 1057] ...
Morgan fingerprint bits: 00000000000000000000 ...

By using morgan fingerprint we generate a 2048 bit sparse vector

Shift in Paradigm: Why GNN’s are powerful for representing molecules.

Graph Neural Networks represent a different philosophy since the molecules are naturally represented as graphs. GNN’s operate directly on the form of molecule, representing atoms as nodes and edges as bonds.

Modern tools like Pytorch Geometric (based on Pytorch framework), or DeepChem make this practical and at scale.

GNN’s move us from fixed representation to learned representations, which with enough data can unlock hidden patterns by considering the structure of the molecule.(i.e relationship between atoms and molecules).

Message Passing mechanism in GNN’s can capture both the complex long range dependencies as well as subtle structural effects. GNN’s learn how molecules are arranged which in itself is a humongous challenge.

GNN’s also have an added benefit of compressing the sparse embedding and generating a dense embedding.

Instead of flattening molecule into sparse vectors, we can represent them using Graphs. Here is the same Paracetamol represented as a Graph object


import torch
from rdkit import Chem
from torch_geometric.data import Data
from torch_geometric.nn import GCNConv, global_add_pool

def smiles_to_graph(smiles:str) -> Data:
    """
        Function for converting smiles -> Homogenous Graph Data compatible with 
        Pytorch geometric
    """

    mol = Chem.MolFromSmiles(smiles)
    if not mol:
        print("Invalid SMILES....")
        return None
    mol = Chem.AddHs(mol) 
    nodes = [[atom.GetAtomicNum(), float(atom.IsInRing())] for atom in mol.GetAtoms()]
    x = torch.tensor(nodes, dtype=torch.float)

    edges = []
    for bond in mol.GetBonds():
        start, end = bond.GetBeginAtomIdx(),  bond.GetEndAtomIdx()
        edges += [[start, end], [end, start]]

    edge_index = torch.tensor(edges, dtype=torch.long).t().contiguous()
    return Data(x=x, edge_index=edge_index)

# Paracetamol SMILES
paracetamol_smiles = "CC(=O)NC1=CC=C(O)C=C1"
data = smiles_to_graph(paracetamol_smiles)
print(f"Topology: {data.num_nodes} atoms connected by {data.num_edges} directed message paths.")
Topology: 20 atoms connected by 40 directed message paths.
Paracetamol Graph Ready. Nodes: 20 (C, N, O)

Once the molecule is a graph, we can feed it to a Graph Neural Network, the GNN learns embeddings and aggregates them.

class GNNModel(torch.nn.Module):
    def __init__(self, input_dim, hidden_dim):
        super().__init__()
        self.conv1 = GCNConv(input_dim, hidden_dim)
        self.conv2 = GCNConv(hidden_dim, hidden_dim)

    def forward(self, data):
        x, edge_index = data.x, data.edge_index
        x = self.conv1(x, edge_index).relu()
        x = self.conv2(x, edge_index).relu()
        batch = torch.zeros(x.size(0), dtype= torch.long)
        x = global_add_pool(x,batch=batch)
        return x

model = GNNModel(input_dim=1, hidden_dim=32)
with torch.no_grad():
    embedding = model(data)

print(f"Paracetamol Graph Ready. Nodes: {data.num_nodes} (C8H9NO2)")
print(f"Predicted Embeddings: {embedding[:10]}")
Predicted Embeddings: tensor([[25.2734, 17.2890,  0.0000,  6.7664, 12.3449,  0.0000,  6.0679,  2.6838,
          0.0000, 18.0029, 21.4321, 28.3917,  0.0000, 12.1310,  0.0000,  7.2844,
          0.0000,  6.5838, 33.4079,  0.0000, 11.0224,  0.0000,  4.0623, 24.1106,
          0.0000,  4.1550,  0.0000, 11.9457,  9.0635, 12.9014,  0.0000,  0.0000]])

Why does this matters?

In analytical chemistry, drug discovery and toxicology representing molecules accurately is a fundamental task. A molecules structure represents its physical, chemical and biological properties and any inaccurate representation can have real world consequences, from failed experiments to wasted R&D spending.

So how we encode molecules matter!

Trade offs:

The traditional methods of encoding molecules are faster and interpretable (1’s and 0’s based), while GNN embeddings look opaque.

classical ML techniques and RDKit work well when data is limited and it encodes some chemical rules (Adjacency, Valence, Stereo chemistry, Aromaticity). However in case of using GNN’s there are more data requirements and more complex pipelines (GPU’s, infrastructure, storage).

In certain scenarios, fixed fingerprints will remain a practical choice such as high throughput applications, but where understanding and capturing complex relationship matters, GNN’s are preferred.

What comes next?

The integration of GNNs and foundational AI models opens opportunities:

  • In closed loop systems analyze novel chemical compounds and system learns in real time.
  • Capture complex chemical space.
  • De novo drug design that explores chemical spaces beyond human intuition. While some proposed molecules may be impractical, GNN’s expand the limits of chemical modeling.
  • Systems that suggest practical and novel chemical structures, potentially accelerating discovery

While some chemical structures may remain impractical, GNNs expand the knowledge horizon, providing insights and guiding experimentation..

Beyond Molecules:

Graph Based Representation extends beyond chemistry.

  • Supply chains
  • Knowledge graphs
  • Fraud modelling
  • Biological networks
  • Recommender systems

In each of these cases, value lies in relationships not just entities. The same principal of capturing patterns in relationships and makes GNN powerful for molecules, applies universally.

GraphNeuralNetworks #Cheminformatics #DrugDiscovery #MachineLearning #GNN #DigitalHealth #AI

Disclaimer: Topic image generated via AI


메타데이터
post_id
fc5344e14945
slug
beyond-molecular-fingerprints-why-graph-neural-networks-are-the-future-fc5344e14945
url
https://medium.com/@falaqm/beyond-molecular-fingerprints-why-graph-neural-networks-are-the-future-fc5344e14945
canonical_url
https://medium.com/@falaqm/beyond-molecular-fingerprints-why-graph-neural-networks-are-the-future-fc5344e14945
author_url
https://medium.com/@falaqm
status
ok
fetched_at
2026-06-11 05:11:55