binding_512_SELFIES / README.md
ejy's picture
Update README.md
2acabd4 verified
metadata
dataset_info:
  features:
    - name: seq
      dtype: string
    - name: smiles
      dtype: string
    - name: affinity_uM
      dtype: float64
    - name: neg_log10_affinity_M
      dtype: float64
    - name: smiles_can
      dtype: string
    - name: affinity
      dtype: float64
    - name: selfies
      dtype: string
  splits:
    - name: train
      num_bytes: 872969895.9256648
      num_examples: 1082521
  download_size: 110659389
  dataset_size: 872969895.9256648

From the jglaser/binding_affinity database, converted to SELFIES

Steps to prepare the database:

  1. Download the jglaser/binding_affinity database
from datasets import load_dataset

binding_data = load_dataset('parquet', split='train', data_files="https://huggingface.co/datasets/jglaser/binding_affinity/resolve/main/data/all_512.parquet")
  1. Convert SMILES to SELFIES
import selfies

def smiles_to_selfies(dataset):
  try:
    return {"selfies": selfies.encoder(dataset["smiles_can"])}
  except selfies.EncoderError:
    return {"selfies": None}

binding_data = binding_data.map(smiles_to_selfies)
binding_data = binding_data.filter(lambda dataset: dataset["selfies"] != None)
  1. Compute protein ('prot_bert') / ligand embeddings ('SELFIES-RoBERTa-PubChem10M')
from sentence_transformers import SentenceTransformer
import re
import pickle
import os.path

# Protein embeddings
all_proteins_shortened = binding_data.unique('seq')

protein_sequences = [re.sub(r"[UZOB]", "X", sequence) for sequence in all_proteins_shortened]
protein_sequences = [" ".join(sequence) for sequence in protein_sequences]

protein_model = SentenceTransformer('Rostlab/prot_bert')
protein_model.max_seq_length = 512

protein_emb = protein_model.encode(protein_sequences)

protein_embeddings = dict(zip(protein_sequences, protein_emb))

with open('protein_embeddings.pkl', "wb") as fOut:
  pickle.dump(protein_embeddings, fOut, protocol=pickle.HIGHEST_PROTOCOL)

# Ligand embeddings
all_selfies_shortened = binding_data.unique('selfies')

ligand_sequences = [sequence for sequence in all_selfies_shortened]

ligand_model = SentenceTransformer('ejy/SELFIES-RoBERTa-PubChem10M')
ligand_model.max_seq_length = 128

ligand_emb = ligand_model.encode(ligand_sequences)

ligand_embeddings = dict(zip(ligand_sequences, ligand_emb))

with open('ligand_embeddings.pkl', "wb") as fOut:
  pickle.dump(ligand_embeddings, fOut, protocol=pickle.HIGHEST_PROTOCOL)