CHEESEOn-Premise

Index Inference

Index your own molecule database for CHEESE search, with input formats, indexing modes, and SMILES standardisation.

Suggest an edit

To search your own database in the CHEESE UI, API, or CLI, you first run inference on it. Inference computes the embeddings and search indexes for every molecule in the file.

Run inference

Usage: cheese run-inference [options]
Options:
  --input_file             Input file in CSV format [REQUIRED]
  --dest                   Destination folder [REQUIRED]
  --index_type             'clustered', 'in_memory', or 'auto' (default: auto)
  --chunk_size             Lines processed per chunk (default: 100000)
  --batch_size             Batch size for embedding computation on GPU (default: 32)
  --valid_smiles           Check SMILES validity (default: false)
  --canonicalize_smiles    Canonicalise SMILES (default: false)
  --skip_file_headers      Skip the file header line (default: true)
  --gpu_devices            IDs of the GPU devices to use (default: 0)
  --clustering_batch_size  Batch size for clustering (default: 10000)
  -h, --help               Show this help message

Example:

cheese run-inference \
  --input_file test_mols.txt \
  --dest . \
  --index_type in_memory \
  --chunk_size 100 \
  --batch_size 32 \
  --valid_smiles false \
  --canonicalize_smiles false \
  --skip_file_headers true \
  --gpu_devices 0 \
  --clustering_batch_size 1000

Index types

  • clustered: requires a GPU.
  • in_memory: runs on CPU or GPU.
  • auto (default): uses clustered if the input file is larger than 1 GB, and in_memory otherwise.

CPU or GPU

Inference runs on CPU unless you pass --gpu_devices. When you pass it, CHEESE looks for GPUs first and fails with an error if none is found.

Input format

The input file is a list of molecules, one per line, with SMILES and an ID:

SMILES,id
C[C@H](NC(=O)N1CC2(CCC2)C1c1ccc(F)cc1)C1CC,Z5348285396
CC(NC(=O)N1CC2(CCC2)C1c1ccc(F)cc1)C1CC1,Z5348285396
C[C@@H](NC(=O)N1CC2(CCC2)C1c1ccc(F)cc1)C1CC1,Z5348285396

.smi, .sdf, and .txt files are also supported.

Output

Embeddings are saved as .npy files, which are NumPy arrays. The API can also return JSON or CSV, but for large sets we recommend .npy or .parquet.

Registering the database

After inference, add the output folder to your configuration so CHEESE can use it. Run cheese configure and add an entry, as described in Installation:

OUTPUT_DIRECTORIES:
  MyDatabase: "/path/to/my_output"

DELIMITERS:
  MyDatabase: ","

INDEX_TYPES:
  MyDatabase: "in_memory"

SMILES standardisation

CHEESE expects SMILES in canonical, RDKit-compatible form, neutralised where possible. Inference can canonicalise for you with --canonicalize_smiles. In casual use you can skip standardisation, but consistent input always gives better results. This is the standardisation used during CHEESE model training:

from rdkit import Chem
from rdkit.Chem import rdMolStandardize


def standardize(smiles):
    """
    Follows the steps in
    https://github.com/greglandrum/RSC_OpenScience_Standardization_202104/blob/main/MolStandardize%20pieces.ipynb
    Source: https://bitsilla.com/blog/2021/06/standardizing-a-molecule-using-rdkit/
    """
    mol = Chem.MolFromSmiles(smiles)

    # Remove Hs, disconnect metals, normalise, and reionise the molecule
    clean_mol = rdMolStandardize.Cleanup(mol)

    # If there are several fragments, keep the parent (the main molecule)
    parent_clean_mol = rdMolStandardize.FragmentParent(clean_mol)

    # Try to neutralise the molecule
    uncharger = rdMolStandardize.Uncharger()
    uncharged_parent_clean_mol = uncharger.uncharge(parent_clean_mol)

    # Canonicalise the tautomer
    te = rdMolStandardize.TautomerEnumerator()
    taut_uncharged_parent_clean_mol = te.Canonicalize(uncharged_parent_clean_mol)

    return Chem.MolToSmiles(taut_uncharged_parent_clean_mol)

On this page