File size: 2,533 Bytes
e44306d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f3ebb84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2acabd4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f3ebb84
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---
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](https://huggingface.co/datasets/jglaser/binding_affinity) database, converted to SELFIES

Steps to prepare the database:

1. Download the jglaser/binding_affinity database

```python
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")
```

2. Convert SMILES to [SELFIES](https://github.com/aspuru-guzik-group/selfies)

```python
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)
```

3. Compute protein ('prot_bert') / ligand embeddings ('SELFIES-RoBERTa-PubChem10M')

```python
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)
```