Skip to content

Chem

Compute molecular descriptors, fingerprints, similarity, substructure matches and InChI keys from SMILES strings

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/chem/index.md to help me query Chem with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Browse the built-in example molecules by molecular weight.

Example output · captured
Connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT name, formula
FROM chem.main.example_molecules()
ORDER BY mol_weight
LIMIT 3;
Result
name formula
water H2O
ethanol C2H6O
acetic acid C2H4O2

Quick start

Choose where to run Chem, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'chem' AS chem (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-chem-worker'
);

3. Run a query

query.sql
SELECT name, formula
FROM chem.main.example_molecules()
ORDER BY mol_weight
LIMIT 3;
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'chem' AS chem (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-chem-worker'
);

Overview

RDKit cheminformatics for SQL: molecular descriptors, fingerprints, substructure, InChI.

Catalog

Everything chem exposes once attached — read straight from the worker's released build.

chem 1 schema
main 1 table · 19 functions

RDKit cheminformatics for SQL: descriptors, fingerprints, substructure, InChI.

Schema examples (12)
Examples (12)

Check that a SMILES string parses to a real molecule.

SELECT chem.main.is_valid_smiles('CCO');

Canonicalize a SMILES so equivalent spellings compare equal.

SELECT chem.main.canonical_smiles('OCC');

Molecular formula of aspirin in Hill notation.

SELECT chem.main.mol_formula('CC(=O)OC1=CC=CC=C1C(=O)O');

Molecular weight of aspirin, rounded to two decimals.

SELECT ROUND(chem.main.mol_weight('CC(=O)OC1=CC=CC=C1C(=O)O'), 2);
8 more examples

InChIKey structure hash of aspirin for joins and lookup.

SELECT chem.main.inchikey('CC(=O)OC1=CC=CC=C1C(=O)O');

Tanimoto self-similarity is exactly 1.0.

SELECT chem.main.tanimoto('CCO', 'CCO');

Does phenol contain a benzene ring (SMARTS match)?

SELECT chem.main.substructure_match('c1ccccc1O', 'c1ccccc1');

Lipinski rule-of-five breakdown for aspirin, one row per rule.

SELECT rule, value, passes
FROM chem.main.lipinski('CC(=O)OC1=CC=CC=C1C(=O)O')
ORDER BY rule;

Similarity search: the three built-in molecules most similar to salicylic acid (OC(=O)c1ccccc1O) by Tanimoto -- aspirin 0.448, phenol 0.381, paracetamol 0.226

SELECT name,
  round(chem.main.tanimoto(smiles, 'OC(=O)c1ccccc1O'), 3) AS similarity
FROM chem.main.example_molecules
ORDER BY similarity DESC, name
LIMIT 3;

Substructure filter over the registry: molecules carrying a carboxylic-acid group (SMARTS [CX3](=O)[OX2H1]) -- acetic acid, aspirin, ibuprofen, penicillin g -- lightest first

SELECT name, formula, round(mol_weight, 2) AS mol_weight
FROM chem.main.example_molecules
WHERE chem.main.substructure_match(smiles, '[CX3](=O)[OX2H1]')
ORDER BY mol_weight;

Identify unfamiliar SMILES spellings by joining on InChIKey to the built-in registry: C(O)C is ethanol, OC(=O)C acetic acid, Oc1ccccc1 phenol; NCCO (ethanolamine) is not in the registry, so its name is NULL

SELECT q.smiles AS query_smiles, m.name
FROM (VALUES ('OC(=O)C'), ('C(O)C'), ('Oc1ccccc1'), ('NCCO')) AS q(smiles)
LEFT JOIN chem.main.example_molecules AS m ON chem.main.inchikey(q.smiles) = chem.main.inchikey(m.smiles)
ORDER BY query_smiles;

All-pairs Tanimoto over the registry: its three most similar pairs -- paracetamol/phenol 0.292, benzene/phenol 0.273, aspirin/phenol 0.25

SELECT a.name AS molecule_a, b.name AS molecule_b,
  round(chem.main.tanimoto(a.smiles, b.smiles), 3) AS similarity
FROM chem.main.example_molecules AS a
JOIN chem.main.example_molecules AS b ON a.name < b.name
ORDER BY similarity DESC, molecule_a, molecule_b
LIMIT 3;
Tables
example_molecules 5 examples10 cols

Curated registry of well-known molecules with pre-computed descriptors (discovery table).

Columns
name VARCHAR
Common name of the molecule.
smilesnot null VARCHAR
SMILES string you can pass to any chem function.
formulanot null VARCHAR
Hill-system molecular formula.
mol_weight DOUBLE
Average molecular weight in g/mol.
logp DOUBLE
Crippen logP (octanol-water partition estimate).
tpsa DOUBLE
Topological polar surface area in Angstrom^2.
h_bond_donors INTEGER
Lipinski hydrogen-bond donor count.
h_bond_acceptors INTEGER
Lipinski hydrogen-bond acceptor count.
num_rings INTEGER
Ring count (SSSR).
drug_like BOOLEAN
True if the molecule passes all four Lipinski rules.
ConstraintsPRIMARY KEY (name)
Examples (5)

Browse the built-in molecules from lightest to heaviest.

SELECT name, formula, mol_weight
FROM chem.main.example_molecules
ORDER BY mol_weight;

How many example molecules are drug-like (pass all four Lipinski rules)?

SELECT count(*) AS drug_like
FROM chem.main.example_molecules
WHERE drug_like;

All-pairs Tanimoto over the registry: its three most similar pairs -- paracetamol/phenol 0.292, benzene/phenol 0.273, aspirin/phenol 0.25

SELECT a.name AS molecule_a, b.name AS molecule_b,
  round(chem.main.tanimoto(a.smiles, b.smiles), 3) AS similarity
FROM chem.main.example_molecules AS a
JOIN chem.main.example_molecules AS b ON a.name < b.name
ORDER BY similarity DESC, molecule_a, molecule_b
LIMIT 3;
2 more examples
SELECT name, smiles, formula, mol_weight
FROM chem.main.example_molecules()
ORDER BY mol_weight;
SELECT name, logp
FROM chem.main.example_molecules()
WHERE drug_like
ORDER BY logp DESC;
Link
Scalar functions
canonical_smiles (smiles VARCHAR) 1 example

RDKit canonical SMILES form, or NULL if the input is invalid

Arguments
smiles VARCHAR
SMILES string to canonicalize.
ReturnsVARCHAR
Example

Canonicalize ethanol -> 'CCO'

SELECT chem.main.canonical_smiles('OCC');
Link
drug_like (smiles VARCHAR) 1 example

True if the molecule passes all four Lipinski rule-of-five criteria, NULL if invalid

Arguments
smiles VARCHAR
SMILES string to screen.
ReturnsBOOLEAN
Example

Aspirin passes all four Lipinski rules -> true

SELECT chem.main.drug_like('CC(=O)OC1=CC=CC=C1C(=O)O');
Link
exact_mass (smiles VARCHAR) 1 example

Monoisotopic (exact) mass, or NULL if invalid

Arguments
smiles VARCHAR
SMILES string.
ReturnsDOUBLE
Example

Exact mass of ethanol

SELECT chem.main.exact_mass('CCO');
Link
inchi (smiles VARCHAR) 1 example

Standard InChI string, or NULL if invalid

Arguments
smiles VARCHAR
SMILES string.
ReturnsVARCHAR
Example

InChI of ethanol

SELECT chem.main.inchi('CCO');
Link
inchikey (smiles VARCHAR) 2 examples

Standard InChIKey (27-char hashed InChI), or NULL if invalid

Arguments
smiles VARCHAR
SMILES string.
ReturnsVARCHAR
Examples (2)

InChIKey of aspirin -> 'BSYNRYMUTXBXSQ-UHFFFAOYSA-N'

SELECT chem.main.inchikey('CC(=O)OC1=CC=CC=C1C(=O)O');

Identify unfamiliar SMILES spellings by joining on InChIKey to the built-in registry: C(O)C is ethanol, OC(=O)C acetic acid, Oc1ccccc1 phenol; NCCO (ethanolamine) is not in the registry, so its name is NULL

SELECT q.smiles AS query_smiles, m.name
FROM (VALUES ('OC(=O)C'), ('C(O)C'), ('Oc1ccccc1'), ('NCCO')) AS q(smiles)
LEFT JOIN chem.main.example_molecules AS m ON chem.main.inchikey(q.smiles) = chem.main.inchikey(m.smiles)
ORDER BY query_smiles;
Link
is_valid_smiles (smiles VARCHAR) 2 examples

True if the SMILES string parses to a valid molecule (false if not, NULL if NULL)

Arguments
smiles VARCHAR
SMILES string to validate.
ReturnsBOOLEAN
Examples (2)

A valid SMILES (ethanol)

SELECT chem.main.is_valid_smiles('CCO');

An invalid SMILES -> false

SELECT chem.main.is_valid_smiles('xyz');
Link
logp (smiles VARCHAR) 1 example

Crippen MolLogP (octanol-water partition coefficient estimate), or NULL if invalid

Arguments
smiles VARCHAR
SMILES string.
ReturnsDOUBLE
Example

logP of ethanol

SELECT chem.main.logp('CCO');
Link
mol_formula (smiles VARCHAR) 1 example

Hill-system molecular formula, e.g. 'C9H8O4', or NULL if invalid

Arguments
smiles VARCHAR
SMILES string.
ReturnsVARCHAR
Example

Molecular formula of aspirin

SELECT chem.main.mol_formula('CC(=O)OC1=CC=CC=C1C(=O)O');
Link
mol_weight (smiles VARCHAR) 1 example

Average molecular weight in g/mol, or NULL if invalid

Arguments
smiles VARCHAR
SMILES string.
ReturnsDOUBLE
Example

Molecular weight of aspirin (~180.16)

SELECT chem.main.mol_weight('CC(=O)OC1=CC=CC=C1C(=O)O');
Link
morgan_fingerprint (smiles VARCHAR, radius BIGINT, nbits BIGINT) +1 overload 4 examples

Morgan (ECFP-like) fingerprint as a hex bit-string (defaults radius=2, nbits=2048); NULL if invalid

Arguments
smiles VARCHAR
SMILES string.
radius BIGINT
Morgan radius (e.g. 2).
nbits BIGINT
Fingerprint length in bits (e.g. 2048).
Overloads
morgan_fingerprint(smiles VARCHAR) → VARCHARmorgan_fingerprint(smiles VARCHAR, radius BIGINT, nbits BIGINT) → VARCHAR
ReturnsVARCHAR
Examples (4)

Default Morgan fingerprint of ethanol (radius=2, nbits=2048)

SELECT chem.main.morgan_fingerprint('CCO');

Morgan fingerprint with explicit radius=3 and nbits=1024

SELECT chem.main.morgan_fingerprint('CCO', 3, 1024);
SELECT chem.main.morgan_fingerprint('CCO') AS fp;
1 more example
SELECT chem.main.morgan_fingerprint('CCO', 3, 1024) AS fp;
Link
num_atoms (smiles VARCHAR) 1 example

Number of heavy (non-hydrogen) atoms, or NULL if invalid

Arguments
smiles VARCHAR
SMILES string.
ReturnsINTEGER
Example

Heavy-atom count of benzene (6)

SELECT chem.main.num_atoms('c1ccccc1');
Link
num_h_acceptors (smiles VARCHAR) 1 example

Number of hydrogen-bond acceptors (Lipinski), or NULL if invalid

Arguments
smiles VARCHAR
SMILES string.
ReturnsINTEGER
Example

H-bond acceptors of ethanol

SELECT chem.main.num_h_acceptors('CCO');
Link
num_h_donors (smiles VARCHAR) 1 example

Number of hydrogen-bond donors (Lipinski), or NULL if invalid

Arguments
smiles VARCHAR
SMILES string.
ReturnsINTEGER
Example

H-bond donors of ethanol (1)

SELECT chem.main.num_h_donors('CCO');
Link
num_rings (smiles VARCHAR) 1 example

Number of rings (SSSR ring count), or NULL if invalid

Arguments
smiles VARCHAR
SMILES string.
ReturnsINTEGER
Example

Ring count of benzene (1)

SELECT chem.main.num_rings('c1ccccc1');
Link
num_rotatable_bonds (smiles VARCHAR) 1 example

Number of rotatable bonds, or NULL if invalid

Arguments
smiles VARCHAR
SMILES string.
ReturnsINTEGER
Example

Rotatable bonds of aspirin

SELECT chem.main.num_rotatable_bonds('CC(=O)OC1=CC=CC=C1C(=O)O');
Link
substructure_match (smiles VARCHAR, smarts VARCHAR) 2 examples

True if the molecule contains the SMARTS pattern. NULL if the SMILES is invalid OR the SMARTS pattern is invalid.

Arguments
smiles VARCHAR
SMILES string of the molecule.
smarts VARCHAR
SMARTS query pattern.
ReturnsBOOLEAN
Examples (2)

Phenol contains a benzene ring -> true

SELECT chem.main.substructure_match('c1ccccc1O', 'c1ccccc1');

Substructure filter over the registry: molecules carrying a carboxylic-acid group (SMARTS [CX3](=O)[OX2H1]) -- acetic acid, aspirin, ibuprofen, penicillin g -- lightest first

SELECT name, formula, round(mol_weight, 2) AS mol_weight
FROM chem.main.example_molecules
WHERE chem.main.substructure_match(smiles, '[CX3](=O)[OX2H1]')
ORDER BY mol_weight;
Link
tanimoto (smiles_a VARCHAR, smiles_b VARCHAR, radius BIGINT) +1 overload 3 examples

Morgan/Tanimoto similarity in [0,1] (radius=2); NULL if either SMILES is invalid

Arguments
smiles_a VARCHAR
First SMILES string.
smiles_b VARCHAR
Second SMILES string.
radius BIGINT
Morgan radius (e.g. 2).
Overloads
tanimoto(smiles_a VARCHAR, smiles_b VARCHAR) → DOUBLEtanimoto(smiles_a VARCHAR, smiles_b VARCHAR, radius BIGINT) → DOUBLE
ReturnsDOUBLE
Examples (3)

Self-similarity is 1.0

SELECT chem.main.tanimoto('CCO', 'CCO');

Similarity search: the three built-in molecules most similar to salicylic acid (OC(=O)c1ccccc1O) by Tanimoto -- aspirin 0.448, phenol 0.381, paracetamol 0.226

SELECT name,
  round(chem.main.tanimoto(smiles, 'OC(=O)c1ccccc1O'), 3) AS similarity
FROM chem.main.example_molecules
ORDER BY similarity DESC, name
LIMIT 3;

Tanimoto similarity with radius=2

SELECT chem.main.tanimoto('CCO', 'CCC', 2);
Link
tpsa (smiles VARCHAR) 1 example

Topological polar surface area (TPSA) in Angstrom^2, or NULL if invalid

Arguments
smiles VARCHAR
SMILES string.
ReturnsDOUBLE
Example

TPSA of aspirin

SELECT chem.main.tpsa('CC(=O)OC1=CC=CC=C1C(=O)O');
Link
Table functions
lipinski (smiles VARCHAR) 2 examples

Lipinski rule-of-five breakdown (MW<=500, logP<=5, HBD<=5, HBA<=10), one row per rule

Arguments
smiles VARCHAR
SMILES string to analyze.
Returns columns
rule VARCHAR
Lipinski rule name: molecular_weight, logp, h_bond_donors, or h_bond_acceptors.
value DOUBLE
Computed descriptor value for the rule.
passes BOOLEAN
True if this rule's rule-of-five threshold is satisfied.
Examples (2)

Rule-of-five breakdown for aspirin, one row per rule

SELECT rule, value, passes
FROM chem.main.lipinski('CC(=O)OC1=CC=CC=C1C(=O)O')
ORDER BY rule;

Does aspirin pass all four rules?

SELECT bool_and(passes) AS drug_like
FROM chem.main.lipinski('CC(=O)OC1=CC=CC=C1C(=O)O');
Link

Try these queries

Molecular formula of aspirin.

SELECT chem.main.mol_formula('CC(=O)OC1=CC=CC=C1C(=O)O') AS formula;

Uses mol_formula

Tanimoto self-similarity is exactly 1.0.

SELECT chem.main.tanimoto('CCO', 'CCO') AS sim;

Uses tanimoto

Check that a SMILES string parses to a real molecule.

SELECT chem.main.is_valid_smiles('CCO')

Uses is_valid_smiles

Canonicalize a SMILES so equivalent spellings compare equal.

SELECT chem.main.canonical_smiles('OCC')

Uses canonical_smiles

Molecular weight of aspirin, rounded to two decimals.

SELECT ROUND(chem.main.mol_weight('CC(=O)OC1=CC=CC=C1C(=O)O'), 2)

Uses mol_weight

InChIKey structure hash of aspirin for joins and lookup.

SELECT chem.main.inchikey('CC(=O)OC1=CC=CC=C1C(=O)O')

Uses inchikey

30 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • The SMILES for aspirin is CC(=O)OC1=CC=CC=C1C(=O)O. What is its molecular formula?
  • Is the string 'xyz' a valid SMILES molecule? Return a boolean.
  • Rewrite the SMILES 'OCC' into its canonical form (it denotes ethanol).
  • What is the standard InChI string for ethanol, whose SMILES is CCO?
  • Give the InChIKey identifier for aspirin, whose SMILES is CC(=O)OC1=CC=CC=C1C(=O)O.
  • Compute the molecular weight of aspirin (SMILES CC(=O)OC1=CC=CC=C1C(=O)O), rounded to two decimal places.

Chem is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.