Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,70 @@
|
|
1 |
-
---
|
2 |
-
license: mit
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
---
|
4 |
+
**Github repo: https://github.com/westlake-repl/ProTrek**
|
5 |
+
|
6 |
+
## Overview
|
7 |
+
ProTrek is a multimodal model that integrates protein sequence, protein structure, and text information for better
|
8 |
+
protein understanding. It adopts contrastive learning to learn the representations of protein sequence and structure.
|
9 |
+
During the pre-training phase, we calculate the InfoNCE loss for each two modalities as [CLIP](https://arxiv.org/abs/2103.00020)
|
10 |
+
does.
|
11 |
+
|
12 |
+
## Model architecture
|
13 |
+
**Protein sequence encoder**: [esm2_t33_650M_UR50D](https://huggingface.co/facebook/esm2_t33_650M_UR50D)
|
14 |
+
|
15 |
+
**Protein structure encoder**: foldseek_t30_150M (identical architecture with esm2 except that the vocabulary only contains 3Di tokens)
|
16 |
+
|
17 |
+
**Text encoder**: [BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext](https://huggingface.co/microsoft/BiomedNLP-BiomedBERT-base-uncased-abstract-fulltext)
|
18 |
+
|
19 |
+
## Obtain embeddings and calculate similarity score (please clone our repo first)
|
20 |
+
```
|
21 |
+
import torch
|
22 |
+
|
23 |
+
from model.ProtTrek.protrek_trimodal_model import ProTrekTrimodalModel
|
24 |
+
from utils.foldseek_util import get_struc_seq
|
25 |
+
|
26 |
+
# Load model
|
27 |
+
config = {
|
28 |
+
"protein_config": "weights/ProTrek_35M_UniRef50/esm2_t33_650M_UR50D",
|
29 |
+
"text_config": "weights/ProTrek_35M_UniRef50/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext",
|
30 |
+
"structure_config": "weights/ProTrek_35M_UniRef50/foldseek_t30_150M",
|
31 |
+
"load_protein_pretrained": False,
|
32 |
+
"load_text_pretrained": False,
|
33 |
+
"from_checkpoint": "weights/ProTrek_35M_UniRef50/ProTrek_650M_UniRef50.pt"
|
34 |
+
}
|
35 |
+
|
36 |
+
device = "cuda"
|
37 |
+
model = ProTrekTrimodalModel(**config).eval().to(device)
|
38 |
+
|
39 |
+
# Load protein and text
|
40 |
+
pdb_path = "example/8ac8.cif"
|
41 |
+
seqs = get_struc_seq("bin/foldseek", pdb_path, ["A"])["A"]
|
42 |
+
aa_seq = seqs[0]
|
43 |
+
foldseek_seq = seqs[1].lower()
|
44 |
+
text = "Replication initiator in the monomeric form, and autogenous repressor in the dimeric form."
|
45 |
+
|
46 |
+
with torch.no_grad():
|
47 |
+
# Obtain protein sequence embedding
|
48 |
+
seq_embedding = model.get_protein_repr([aa_seq])
|
49 |
+
print("Protein sequence embedding shape:", seq_embedding.shape)
|
50 |
+
|
51 |
+
# Obtain protein structure embedding
|
52 |
+
struc_embedding = model.get_structure_repr([foldseek_seq])
|
53 |
+
print("Protein structure embedding shape:", struc_embedding.shape)
|
54 |
+
|
55 |
+
# Obtain text embedding
|
56 |
+
text_embedding = model.get_text_repr([text])
|
57 |
+
print("Text embedding shape:", text_embedding.shape)
|
58 |
+
|
59 |
+
# Calculate similarity score between protein sequence and structure
|
60 |
+
seq_struc_score = seq_embedding @ struc_embedding.T / model.temperature
|
61 |
+
print("Similarity score between protein sequence and structure:", seq_struc_score.item())
|
62 |
+
|
63 |
+
# Calculate similarity score between protein sequence and text
|
64 |
+
seq_text_score = seq_embedding @ text_embedding.T / model.temperature
|
65 |
+
print("Similarity score between protein sequence and text:", seq_text_score.item())
|
66 |
+
|
67 |
+
# Calculate similarity score between protein structure and text
|
68 |
+
struc_text_score = struc_embedding @ text_embedding.T / model.temperature
|
69 |
+
print("Similarity score between protein structure and text:", struc_text_score.item())
|
70 |
+
```
|