rdkit

Cheminformatics functionality for PostgreSQL.

Overview

PackageVersionCategoryLicenseLanguage
rdkit202503.1FEATBSD 3-ClauseC++
IDExtensionBinLibLoadCreateTrustRelocSchema
2930rdkitNoYesNoYesNoYes-
Relatedage hll rum pg_graphql pg_jsonschema jsquery pg_hint_plan hypopg

u24 has rdkit for pg17

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG202503.11817161514rdkit-
DEBPGDG202503.11817161514postgresql-$v-rdkit-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64PGDG MISSPGDG MISSPGDG MISSPGDG MISSPGDG MISS
el8.aarch64PGDG MISSPGDG MISSPGDG MISSPGDG MISSPGDG MISS
el9.x86_64PGDG MISSPGDG MISSPGDG MISSPGDG MISSPGDG MISS
el9.aarch64PGDG MISSPGDG MISSPGDG MISSPGDG MISSPGDG MISS
el10.x86_64PGDG MISSPGDG MISSPGDG MISSPGDG MISSPGDG MISS
el10.aarch64PGDG MISSPGDG MISSPGDG MISSPGDG MISSPGDG MISS
d12.x86_64PGDG MISSPGDG MISS
d12.aarch64PGDG MISSPGDG MISS
d13.x86_64
d13.aarch64
PGDG 202503.1
PGDG 202503.1
PGDG 202503.1
PGDG 202503.1
PGDG 202503.1
u22.x86_64PGDG MISSPGDG MISS
u22.aarch64PGDG MISSPGDG MISS
u24.x86_64
u24.aarch64

Install

You can install rdkit directly. First, make sure the PGDG repository is added and enabled:

pig repo add pgdg -u          # Add PGDG repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install rdkit;          # Install for current active PG version
pig ext install -y rdkit -v 18  # PG 18
pig ext install -y rdkit -v 17  # PG 17
pig ext install -y rdkit -v 16  # PG 16
pig ext install -y rdkit -v 15  # PG 15
pig ext install -y rdkit -v 14  # PG 14
apt install -y postgresql-18-rdkit   # PG 18
apt install -y postgresql-17-rdkit   # PG 17
apt install -y postgresql-16-rdkit   # PG 16
apt install -y postgresql-15-rdkit   # PG 15
apt install -y postgresql-14-rdkit   # PG 14

Create Extension:

CREATE EXTENSION rdkit;

Usage

rdkit: Cheminformatics and molecule toolkit PostgreSQL cartridge

The RDKit PostgreSQL cartridge provides the mol datatype for molecules, fp datatype for fingerprints, substructure and similarity search operations, and GiST index support.

CREATE EXTENSION rdkit;

Data Types

TypeDescription
molMolecular structure (from SMILES, SMARTS, etc.)
bfpBit vector fingerprint
sfpSparse (count) fingerprint

Molecule Input/Output

-- Create molecule from SMILES
SELECT 'c1ccccc1'::mol;

-- Check if SMILES is valid
SELECT is_valid_smiles('c1ccccc1');

-- Convert molecule to SMILES
SELECT mol_to_smiles('c1ccccc1'::mol);
-- Substructure match operator
SELECT 'c1ccccc1O'::mol @> 'c1ccccc1'::mol;   -- true (phenol contains benzene)
SELECT 'c1ccccc1'::mol <@ 'c1ccccc1O'::mol;    -- true

-- Using SMARTS patterns
SELECT 'c1ccccc1O'::mol @> 'c1ccc(O)cc1'::mol;
-- Tanimoto similarity (returns value between 0 and 1)
SELECT tanimoto_sml(morganbv_fp('c1ccccc1'::mol), morganbv_fp('c1ccccc1O'::mol));

-- Dice similarity
SELECT dice_sml(morganbv_fp('c1ccccc1'::mol), morganbv_fp('c1ccccc1O'::mol));

Fingerprint Functions

-- Morgan fingerprint (bit vector)
SELECT morganbv_fp('c1ccccc1'::mol);
SELECT morganbv_fp('c1ccccc1'::mol, 2);  -- radius=2

-- RDKit fingerprint
SELECT rdkit_fp('c1ccccc1'::mol);

-- Topological torsion fingerprint
SELECT torsionbv_fp('c1ccccc1'::mol);

-- Atom pair fingerprint
SELECT atompairbv_fp('c1ccccc1'::mol);

Descriptor Calculations

SELECT mol_amw('c1ccccc1'::mol);          -- average molecular weight
SELECT mol_logp('c1ccccc1'::mol);         -- LogP
SELECT mol_hba('c1ccccc1O'::mol);         -- H-bond acceptors
SELECT mol_hbd('c1ccccc1O'::mol);         -- H-bond donors
SELECT mol_numrotatablebonds('c1ccccc1'::mol); -- rotatable bonds
SELECT mol_numatoms('c1ccccc1'::mol);     -- number of atoms
SELECT mol_numheavyatoms('c1ccccc1'::mol);    -- heavy atoms
SELECT mol_numrings('c1ccccc1'::mol);     -- number of rings

GiST Index Support

Create indexes for fast substructure and similarity searches:

-- Substructure search index
CREATE INDEX idx_mol ON molecules USING gist(molecule);

-- Fingerprint similarity index
CREATE INDEX idx_fp ON molecules USING gist(morganbv_fp(molecule));

Query with index support:

-- Substructure search
SELECT * FROM molecules WHERE molecule @> 'c1ccccc1'::mol;

-- Similarity search (with threshold)
SET rdkit.dice_threshold = 0.5;
SELECT * FROM molecules WHERE morganbv_fp(molecule) % morganbv_fp('c1ccccc1O'::mol);

GUC Parameters

ParameterDefaultDescription
rdkit.tanimoto_threshold0.5Threshold for Tanimoto similarity operator <%>
rdkit.dice_threshold0.5Threshold for Dice similarity operator %

Last Modified 2026-03-12: add pg extension catalog (95749bf)