This repository evaluates molecular similarity search methods by comparing transformer-based embeddings (SMILES and SELFIES) from ChemBERTa and SELFormer against 1024‑bit ECFP4 fingerprints. Using a set of chemically diverse query molecules, the code retrieves top‑k neighbours (k ∈ {5, 8, 10, 15, 20, 25, 35}) and evaluates hits on chemical similarity (Hamming distance) and structural similarity (Graph Edit Distance, GED). Statistical significance is assessed using one‑way ANOVA and Tukey's HSD. The experiments show that ECFP4/Tanimoto gives the best performance; SELFIES embeddings outperform SMILES embeddings but remain inferior to fingerprints.
src/)src/
├─ app.py # FastAPI/Uvicorn entry point used by the pipeline
├─ select_diverse.py # Creates a queries.txt of chemically diverse molecules
├─ download_sdf.py # Downloads molecules from PubChem (SDF)
├─ parse_sdf.py # Extracts SMILES and SELFIES into CSV
├─ generate_embeddings.py # ChemBERTa embeddings (SMILES)
├─ generate_selfies_embeddings.py # ChemBERTa embeddings (SELFIES)
├─ generate_embeddings_SELFormer.py # SELFormer embeddings (SMILES)
├─ generate_selfies_embeddings_SELFormer.py # SELFormer embeddings (SELFIES)
├─ generate_fingerprints_SMILES.py # ECFP4 fingerprint generation
├─ ingest_faiss.py # Insert chemBERTa embeddings into FAISS
├─ ingest_faiss_SELFormer.py # Insert SELFormer embeddings into FAISS
├─ ingest_raw_fingerprints.py # Insert fingerprints into FAISS
├─ run_full_pipeline.py # Runs the full retrieval + evaluation pipeline
└─ utils/ # Utility helpers (parsing, GED, Hamming, stats)
Note: This is a one‑time run. Once embeddings and fingerprints are generated and inserted into FAISS, you can skip these steps for subsequent experiments.
Install libraries:
pip install rdkit
pip install selfies
pip install torch
pip install transformers
pip install pandas
pip install faiss-cpu
pip install matplotlib
cd srcpython download_sdf.py
python parse_sdf.py
python generate_embeddings.py
python generate_selfies_embeddings.py
python generate_embeddings_SELFormer.py
python generate_selfies_embeddings_SELFormer.py
python generate_fingerprints_SMILES.py
python ingest_faiss.py
python ingest_faiss_SELFormer.py
python ingest_raw_fingerprints.py
After these steps you should have 5 FAISS indexes populated and be ready to run experiments.
If you don't want to manually pick query molecules, the repository includes a script that selects chemically diverse queries using a MinMax algorithm (based on Tanimoto coefficient) and your precomputed fingerprints.
cd src
python select_diverse.py
This produces a queries.txt file containing 20 chemically diverse query SMILES (one per line). Assumes fingerprints are already available in CSV form.
Assumptions:
queries.txt file with query SMILES (one SMILES per line, do not enclose in quotes).Steps:
src) start the app:uvicorn src.app:app --reload
cd src and run the pipeline:cd src
python run_full_pipeline.py
When the run completes you will find the following output files:
results_full.csv — top‑k hits information for each query and methodged_summary.csv — mean/median/std summary statistics for GEDhamming_summary.csv — mean/median/std summary statistics for Hamming distancemean_GED_vs_k.png — line plot of mean GED vs. number of hits for each methodmean_Hamming_vs_k.png — line plot of mean Hamming vs. number of hits for each methodSimilarity measures used for retrieval
Post‑retrieval evaluation
Statistical testing
Key experimental finding (from the paper): ECFP4/Tanimoto yields the lowest mean Hamming distances (mean = 12.5 at k = 35) and lowest mean GEDs (mean = 18.9). SELFIES embeddings outperform SMILES embeddings but are still inferior to fingerprints.
queries.txtrun_full_pipeline.pyconda:
conda install -c conda-forge rdkitfaiss-cpu for CPU-only environments, or faiss-gpu if you have CUDA.matplotlib is installed and that your run completed without exceptions.This repository evaluates molecular similarity search methods by comparing transformer-based embeddings (SMILES and SELFIES) from ChemBERTa and SELFormer against 1024‑bit ECFP4 fingerprints. Using a set of chemically diverse query molecules, the code retrieves top‑k neighbours (k ∈ {5, 8, 10, 15, 20, 25, 35}) and evaluates hits on chemical similarity (Hamming distance) and structural similarity (Graph Edit Distance, GED). Statistical significance is assessed using one‑way ANOVA and Tukey's HSD. The experiments show that ECFP4/Tanimoto gives the best performance; SELFIES embeddings outperform SMILES embeddings but remain inferior to fingerprints.
src/)src/
├─ app.py # FastAPI/Uvicorn entry point used by the pipeline
├─ select_diverse.py # Creates a queries.txt of chemically diverse molecules
├─ download_sdf.py # Downloads molecules from PubChem (SDF)
├─ parse_sdf.py # Extracts SMILES and SELFIES into CSV
├─ generate_embeddings.py # ChemBERTa embeddings (SMILES)
├─ generate_selfies_embeddings.py # ChemBERTa embeddings (SELFIES)
├─ generate_embeddings_SELFormer.py # SELFormer embeddings (SMILES)
├─ generate_selfies_embeddings_SELFormer.py # SELFormer embeddings (SELFIES)
├─ generate_fingerprints_SMILES.py # ECFP4 fingerprint generation
├─ ingest_faiss.py # Insert chemBERTa embeddings into FAISS
├─ ingest_faiss_SELFormer.py # Insert SELFormer embeddings into FAISS
├─ ingest_raw_fingerprints.py # Insert fingerprints into FAISS
├─ run_full_pipeline.py # Runs the full retrieval + evaluation pipeline
└─ utils/ # Utility helpers (parsing, GED, Hamming, stats)
Note: This is a one‑time run. Once embeddings and fingerprints are generated and inserted into FAISS, you can skip these steps for subsequent experiments.
Install libraries:
pip install rdkit
pip install selfies
pip install torch
pip install transformers
pip install pandas
pip install faiss-cpu
pip install matplotlib
cd srcpython download_sdf.py
python parse_sdf.py
python generate_embeddings.py
python generate_selfies_embeddings.py
python generate_embeddings_SELFormer.py
python generate_selfies_embeddings_SELFormer.py
python generate_fingerprints_SMILES.py
python ingest_faiss.py
python ingest_faiss_SELFormer.py
python ingest_raw_fingerprints.py
After these steps you should have 5 FAISS indexes populated and be ready to run experiments.
If you don't want to manually pick query molecules, the repository includes a script that selects chemically diverse queries using a MinMax algorithm (based on Tanimoto coefficient) and your precomputed fingerprints.
cd src
python select_diverse.py
This produces a queries.txt file containing 20 chemically diverse query SMILES (one per line). Assumes fingerprints are already available in CSV form.
Assumptions:
queries.txt file with query SMILES (one SMILES per line, do not enclose in quotes).Steps:
src) start the app:uvicorn src.app:app --reload
cd src and run the pipeline:cd src
python run_full_pipeline.py
When the run completes you will find the following output files:
results_full.csv — top‑k hits information for each query and methodged_summary.csv — mean/median/std summary statistics for GEDhamming_summary.csv — mean/median/std summary statistics for Hamming distancemean_GED_vs_k.png — line plot of mean GED vs. number of hits for each methodmean_Hamming_vs_k.png — line plot of mean Hamming vs. number of hits for each methodSimilarity measures used for retrieval
Post‑retrieval evaluation
Statistical testing
Key experimental finding (from the paper): ECFP4/Tanimoto yields the lowest mean Hamming distances (mean = 12.5 at k = 35) and lowest mean GEDs (mean = 18.9). SELFIES embeddings outperform SMILES embeddings but are still inferior to fingerprints.
queries.txtrun_full_pipeline.pyconda:
conda install -c conda-forge rdkitfaiss-cpu for CPU-only environments, or faiss-gpu if you have CUDA.matplotlib is installed and that your run completed without exceptions.