rcsb-embedding-model 0.0.6__tar.gz → 0.0.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rcsb-embedding-model might be problematic. Click here for more details.
- rcsb_embedding_model-0.0.7/PKG-INFO +126 -0
- rcsb_embedding_model-0.0.7/README.md +108 -0
- rcsb_embedding_model-0.0.7/examples/esm_embeddings.py +23 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/pyproject.toml +1 -1
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/cli/args_utils.py +0 -2
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/cli/inference.py +57 -31
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/dataset/esm_prot_from_csv.py +2 -3
- rcsb_embedding_model-0.0.7/src/rcsb_embedding_model/inference/structure_inference.py +51 -0
- rcsb_embedding_model-0.0.7/src/rcsb_embedding_model/modules/structure_module.py +27 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/rcsb_structure_embedding.py +4 -5
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/utils/structure_parser.py +4 -4
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/tests/test_embedding_model.py +2 -2
- rcsb_embedding_model-0.0.6/PKG-INFO +0 -117
- rcsb_embedding_model-0.0.6/README.md +0 -99
- rcsb_embedding_model-0.0.6/examples/esm_embeddings.py +0 -77
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/.gitignore +0 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/LICENSE.md +0 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/assets/embedding-model-architecture.png +0 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/__init__.py +0 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/dataset/residue_embedding_from_csv.py +0 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/inference/chain_inference.py +0 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/inference/esm_inference.py +0 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/model/layers.py +0 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/model/residue_embedding_aggregator.py +0 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/modules/chain_module.py +0 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/modules/esm_module.py +0 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/types/api_types.py +0 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/utils/data.py +0 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/utils/model.py +0 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/writer/batch_writer.py +0 -0
- {rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/tests/resources/1acb.cif +0 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rcsb-embedding-model
|
|
3
|
+
Version: 0.0.7
|
|
4
|
+
Summary: Protein Embedding Model for Structure Search
|
|
5
|
+
Project-URL: Homepage, https://github.com/rcsb/rcsb-embedding-model
|
|
6
|
+
Project-URL: Issues, https://github.com/rcsb/rcsb-embedding-model/issues
|
|
7
|
+
Author-email: Joan Segura <joan.segura@rcsb.org>
|
|
8
|
+
License-Expression: BSD-3-Clause
|
|
9
|
+
License-File: LICENSE.md
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Requires-Dist: esm>=3.2.0
|
|
14
|
+
Requires-Dist: lightning>=2.5.0
|
|
15
|
+
Requires-Dist: torch>=2.2.0
|
|
16
|
+
Requires-Dist: typer>=0.15.0
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# RCSB Embedding Model
|
|
20
|
+
|
|
21
|
+
**Version** 0.0.7
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Overview
|
|
25
|
+
|
|
26
|
+
RCSB Embedding Model is a neural network architecture designed to encode macromolecular 3D structures into fixed-length vector embeddings for efficient large-scale structure similarity search.
|
|
27
|
+
|
|
28
|
+
Preprint: [Multi-scale structural similarity embedding search across entire proteomes](https://www.biorxiv.org/content/10.1101/2025.02.28.640875v1).
|
|
29
|
+
|
|
30
|
+
A web-based implementation using this model for structure similarity search is available at [rcsb-embedding-search](http://embedding-search.rcsb.org).
|
|
31
|
+
|
|
32
|
+
If you are interested in training the model with a new dataset, visit the [rcsb-embedding-search repository](https://github.com/bioinsilico/rcsb-embedding-search), which provides scripts and documentation for training.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
- **Residue-level embeddings** computed using the ESM3 protein language model
|
|
38
|
+
- **Structure-level embeddings** aggregated via a transformer-based aggregator network
|
|
39
|
+
- **Command-line interface** implemented with Typer for high-throughput inference workflows
|
|
40
|
+
- **Python API** for interactive embedding computation and integration into analysis pipelines
|
|
41
|
+
- **High-performance inference** leveraging PyTorch Lightning, with multi-node and multi-GPU support
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
pip install rcsb-embedding-model
|
|
48
|
+
|
|
49
|
+
**Requirements:**
|
|
50
|
+
|
|
51
|
+
- Python ≥ 3.10
|
|
52
|
+
- ESM ≥ 3.2.0
|
|
53
|
+
- PyTorch ≥ 2.2.0
|
|
54
|
+
- Lightning ≥ 2.5.0
|
|
55
|
+
- Typer ≥ 0.15.0
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Quick Start
|
|
60
|
+
|
|
61
|
+
### CLI
|
|
62
|
+
|
|
63
|
+
# 1. Compute residue embeddings: Calculate residue level embeddings of protein structures using ESM3.
|
|
64
|
+
inference residue-embedding --src-file data/structures.csv --output-path results/residue_embeddings --src-format mmcif --batch-size 8 --devices auto
|
|
65
|
+
|
|
66
|
+
# 2. Compute structure embeddings: Calculate single-chain protein embeddings from structural files. Predictions are stored in a single pandas data-frame file.
|
|
67
|
+
inference structure-embedding --src-file results/residue_embeddings.csv --output-path results/structure_embeddings --out-df-id embeddings.pkl --batch-size 4 --devices 0 --devives 1
|
|
68
|
+
|
|
69
|
+
# 3. Compute chain embeddings: Calculate single-chain protein embeddings from residue level embeddings stored as torch tensor files.
|
|
70
|
+
inference chain-embedding --src-file results/residue_embeddings.csv --output-path results/chain_embeddings --batch-size 4
|
|
71
|
+
|
|
72
|
+
### Python API
|
|
73
|
+
|
|
74
|
+
from rcsb_embedding_model import RcsbStructureEmbedding
|
|
75
|
+
|
|
76
|
+
model = RcsbStructureEmbedding()
|
|
77
|
+
|
|
78
|
+
# Compute per-residue embeddings
|
|
79
|
+
res_emb = model.residue_embedding(
|
|
80
|
+
src_structure="examples/1abc.cif",
|
|
81
|
+
src_format="mmcif",
|
|
82
|
+
chain_id="A"
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# Aggregate to structure-level embedding
|
|
86
|
+
struct_emb = model.aggregator_embedding(res_emb)
|
|
87
|
+
|
|
88
|
+
See the examples directory for complete scripts.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Model Architecture
|
|
93
|
+
|
|
94
|
+
The embedding model is trained to predict structural similarity by approximating TM-scores using cosine distances between embeddings. It consists of two main components:
|
|
95
|
+
|
|
96
|
+
- **Protein Language Model (PLM)**: Computes residue-level embeddings from a given 3D structure.
|
|
97
|
+
- **Residue Embedding Aggregator**: A transformer-based neural network that aggregates these residue-level embeddings into a single vector.
|
|
98
|
+
|
|
99
|
+

|
|
100
|
+
|
|
101
|
+
### **Protein Language Model (PLM)**
|
|
102
|
+
Residue-wise embeddings of protein structures are computed using the [ESM3](https://www.evolutionaryscale.ai/) generative protein language model.
|
|
103
|
+
|
|
104
|
+
### **Residue Embedding Aggregator**
|
|
105
|
+
The aggregation component consists of six transformer encoder layers, each with a 3,072-neuron feedforward layer and ReLU activations. After processing through these layers, a summation pooling operation is applied, followed by 12 fully connected residual layers that refine the embeddings into a single 1,536-dimensional vector.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Development
|
|
110
|
+
|
|
111
|
+
git clone https://github.com/rcsb/rcsb-embedding-model.git
|
|
112
|
+
cd rcsb-embedding-model
|
|
113
|
+
pip install -e .
|
|
114
|
+
pytest
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Citation
|
|
119
|
+
|
|
120
|
+
Segura, J., Bittrich, S., et al. (2024). *Multi-scale structural similarity embedding search across entire proteomes*. bioRxiv. (Preprint: https://www.biorxiv.org/content/10.1101/2024.03.07.XXXXX)
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
This project is licensed under the BSD 3-Clause License. See [LICENSE.md](LICENSE.md) for details.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# RCSB Embedding Model
|
|
2
|
+
|
|
3
|
+
**Version** 0.0.7
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
|
|
8
|
+
RCSB Embedding Model is a neural network architecture designed to encode macromolecular 3D structures into fixed-length vector embeddings for efficient large-scale structure similarity search.
|
|
9
|
+
|
|
10
|
+
Preprint: [Multi-scale structural similarity embedding search across entire proteomes](https://www.biorxiv.org/content/10.1101/2025.02.28.640875v1).
|
|
11
|
+
|
|
12
|
+
A web-based implementation using this model for structure similarity search is available at [rcsb-embedding-search](http://embedding-search.rcsb.org).
|
|
13
|
+
|
|
14
|
+
If you are interested in training the model with a new dataset, visit the [rcsb-embedding-search repository](https://github.com/bioinsilico/rcsb-embedding-search), which provides scripts and documentation for training.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- **Residue-level embeddings** computed using the ESM3 protein language model
|
|
20
|
+
- **Structure-level embeddings** aggregated via a transformer-based aggregator network
|
|
21
|
+
- **Command-line interface** implemented with Typer for high-throughput inference workflows
|
|
22
|
+
- **Python API** for interactive embedding computation and integration into analysis pipelines
|
|
23
|
+
- **High-performance inference** leveraging PyTorch Lightning, with multi-node and multi-GPU support
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
pip install rcsb-embedding-model
|
|
30
|
+
|
|
31
|
+
**Requirements:**
|
|
32
|
+
|
|
33
|
+
- Python ≥ 3.10
|
|
34
|
+
- ESM ≥ 3.2.0
|
|
35
|
+
- PyTorch ≥ 2.2.0
|
|
36
|
+
- Lightning ≥ 2.5.0
|
|
37
|
+
- Typer ≥ 0.15.0
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
### CLI
|
|
44
|
+
|
|
45
|
+
# 1. Compute residue embeddings: Calculate residue level embeddings of protein structures using ESM3.
|
|
46
|
+
inference residue-embedding --src-file data/structures.csv --output-path results/residue_embeddings --src-format mmcif --batch-size 8 --devices auto
|
|
47
|
+
|
|
48
|
+
# 2. Compute structure embeddings: Calculate single-chain protein embeddings from structural files. Predictions are stored in a single pandas data-frame file.
|
|
49
|
+
inference structure-embedding --src-file results/residue_embeddings.csv --output-path results/structure_embeddings --out-df-id embeddings.pkl --batch-size 4 --devices 0 --devives 1
|
|
50
|
+
|
|
51
|
+
# 3. Compute chain embeddings: Calculate single-chain protein embeddings from residue level embeddings stored as torch tensor files.
|
|
52
|
+
inference chain-embedding --src-file results/residue_embeddings.csv --output-path results/chain_embeddings --batch-size 4
|
|
53
|
+
|
|
54
|
+
### Python API
|
|
55
|
+
|
|
56
|
+
from rcsb_embedding_model import RcsbStructureEmbedding
|
|
57
|
+
|
|
58
|
+
model = RcsbStructureEmbedding()
|
|
59
|
+
|
|
60
|
+
# Compute per-residue embeddings
|
|
61
|
+
res_emb = model.residue_embedding(
|
|
62
|
+
src_structure="examples/1abc.cif",
|
|
63
|
+
src_format="mmcif",
|
|
64
|
+
chain_id="A"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
# Aggregate to structure-level embedding
|
|
68
|
+
struct_emb = model.aggregator_embedding(res_emb)
|
|
69
|
+
|
|
70
|
+
See the examples directory for complete scripts.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Model Architecture
|
|
75
|
+
|
|
76
|
+
The embedding model is trained to predict structural similarity by approximating TM-scores using cosine distances between embeddings. It consists of two main components:
|
|
77
|
+
|
|
78
|
+
- **Protein Language Model (PLM)**: Computes residue-level embeddings from a given 3D structure.
|
|
79
|
+
- **Residue Embedding Aggregator**: A transformer-based neural network that aggregates these residue-level embeddings into a single vector.
|
|
80
|
+
|
|
81
|
+

|
|
82
|
+
|
|
83
|
+
### **Protein Language Model (PLM)**
|
|
84
|
+
Residue-wise embeddings of protein structures are computed using the [ESM3](https://www.evolutionaryscale.ai/) generative protein language model.
|
|
85
|
+
|
|
86
|
+
### **Residue Embedding Aggregator**
|
|
87
|
+
The aggregation component consists of six transformer encoder layers, each with a 3,072-neuron feedforward layer and ReLU activations. After processing through these layers, a summation pooling operation is applied, followed by 12 fully connected residual layers that refine the embeddings into a single 1,536-dimensional vector.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Development
|
|
92
|
+
|
|
93
|
+
git clone https://github.com/rcsb/rcsb-embedding-model.git
|
|
94
|
+
cd rcsb-embedding-model
|
|
95
|
+
pip install -e .
|
|
96
|
+
pytest
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Citation
|
|
101
|
+
|
|
102
|
+
Segura, J., Bittrich, S., et al. (2024). *Multi-scale structural similarity embedding search across entire proteomes*. bioRxiv. (Preprint: https://www.biorxiv.org/content/10.1101/2024.03.07.XXXXX)
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
This project is licensed under the BSD 3-Clause License. See [LICENSE.md](LICENSE.md) for details.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
|
|
3
|
+
from rcsb_embedding_model import RcsbStructureEmbedding
|
|
4
|
+
|
|
5
|
+
if __name__ == "__main__":
|
|
6
|
+
|
|
7
|
+
parser = argparse.ArgumentParser()
|
|
8
|
+
parser.add_argument('--file', type=str, required=True)
|
|
9
|
+
parser.add_argument('--file_format', type=str)
|
|
10
|
+
parser.add_argument('--chain', type=str)
|
|
11
|
+
args = parser.parse_args()
|
|
12
|
+
|
|
13
|
+
model = RcsbStructureEmbedding()
|
|
14
|
+
res_embedding = model.residue_embedding(
|
|
15
|
+
src_structure=args.file,
|
|
16
|
+
src_format=args.file_format,
|
|
17
|
+
chain_id=args.chain
|
|
18
|
+
)
|
|
19
|
+
structure_embedding = model.aggregator_embedding(
|
|
20
|
+
res_embedding
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
print(res_embedding.shape, structure_embedding.shape)
|
{rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/cli/inference.py
RENAMED
|
@@ -5,17 +5,29 @@ import typer
|
|
|
5
5
|
from rcsb_embedding_model.cli.args_utils import arg_devices
|
|
6
6
|
from rcsb_embedding_model.types.api_types import SrcFormat, Accelerator, SrcLocation
|
|
7
7
|
|
|
8
|
-
app = typer.Typer(
|
|
8
|
+
app = typer.Typer(
|
|
9
|
+
add_completion=False
|
|
10
|
+
)
|
|
9
11
|
|
|
10
12
|
|
|
11
|
-
@app.command(
|
|
13
|
+
@app.command(
|
|
14
|
+
name="residue-embedding",
|
|
15
|
+
help="Calculate residue level embeddings of protein structures using ESM3."
|
|
16
|
+
)
|
|
12
17
|
def residue_embedding(
|
|
13
18
|
src_file: Annotated[typer.FileText, typer.Option(
|
|
14
19
|
exists=True,
|
|
15
20
|
file_okay=True,
|
|
16
21
|
dir_okay=False,
|
|
17
22
|
resolve_path=True,
|
|
18
|
-
help='CSV file 3 columns: Structure File | Chain Id (asym_i for cif files) | Output file name.'
|
|
23
|
+
help='CSV file 3 columns: Structure File Path | Chain Id (asym_i for cif files) | Output file name.'
|
|
24
|
+
)],
|
|
25
|
+
output_path: Annotated[typer.FileText, typer.Option(
|
|
26
|
+
exists=True,
|
|
27
|
+
file_okay=False,
|
|
28
|
+
dir_okay=True,
|
|
29
|
+
resolve_path=True,
|
|
30
|
+
help='Output path to store predictions.'
|
|
19
31
|
)],
|
|
20
32
|
src_location: Annotated[SrcLocation, typer.Option(
|
|
21
33
|
help='Source input location.'
|
|
@@ -37,14 +49,7 @@ def residue_embedding(
|
|
|
37
49
|
)] = Accelerator.auto,
|
|
38
50
|
devices: Annotated[List[str], typer.Option(
|
|
39
51
|
help='The devices to use. Can be set to a positive number or "auto". Repeat this argument to indicate multiple indices of devices. "auto" for automatic selection based on the chosen accelerator.'
|
|
40
|
-
)] = tuple(['auto'])
|
|
41
|
-
output_path: Annotated[typer.FileText, typer.Option(
|
|
42
|
-
exists=True,
|
|
43
|
-
file_okay=False,
|
|
44
|
-
dir_okay=True,
|
|
45
|
-
resolve_path=True,
|
|
46
|
-
help='Output path to store predictions.'
|
|
47
|
-
)] = None
|
|
52
|
+
)] = tuple(['auto'])
|
|
48
53
|
):
|
|
49
54
|
from rcsb_embedding_model.inference.esm_inference import predict
|
|
50
55
|
predict(
|
|
@@ -60,14 +65,27 @@ def residue_embedding(
|
|
|
60
65
|
)
|
|
61
66
|
|
|
62
67
|
|
|
63
|
-
@app.command(
|
|
68
|
+
@app.command(
|
|
69
|
+
name="structure-embedding",
|
|
70
|
+
help="Calculate single-chain protein embeddings from structural files. Predictions are stored in a single pandas data-frame file."
|
|
71
|
+
)
|
|
64
72
|
def structure_embedding(
|
|
65
73
|
src_file: Annotated[typer.FileText, typer.Option(
|
|
66
74
|
exists=True,
|
|
67
75
|
file_okay=True,
|
|
68
76
|
dir_okay=False,
|
|
69
77
|
resolve_path=True,
|
|
70
|
-
help='CSV file 3 columns: Structure File | Chain Id (asym_i for cif files) | Output file name.'
|
|
78
|
+
help='CSV file 3 columns: Structure File Path | Chain Id (asym_i for cif files) | Output file name.'
|
|
79
|
+
)],
|
|
80
|
+
output_path: Annotated[typer.FileText, typer.Option(
|
|
81
|
+
exists=True,
|
|
82
|
+
file_okay=False,
|
|
83
|
+
dir_okay=True,
|
|
84
|
+
resolve_path=True,
|
|
85
|
+
help='Output path to store predictions.'
|
|
86
|
+
)],
|
|
87
|
+
out_df_id: Annotated[str, typer.Option(
|
|
88
|
+
help='File name to store predicted embeddings.'
|
|
71
89
|
)],
|
|
72
90
|
src_location: Annotated[SrcLocation, typer.Option(
|
|
73
91
|
help='Source input location.'
|
|
@@ -89,19 +107,27 @@ def structure_embedding(
|
|
|
89
107
|
)] = Accelerator.auto,
|
|
90
108
|
devices: Annotated[List[str], typer.Option(
|
|
91
109
|
help='The devices to use. Can be set to a positive number or "auto". Repeat this argument to indicate multiple indices of devices. "auto" for automatic selection based on the chosen accelerator.'
|
|
92
|
-
)] = tuple(['auto'])
|
|
93
|
-
output_path: Annotated[typer.FileText, typer.Option(
|
|
94
|
-
exists=True,
|
|
95
|
-
file_okay=False,
|
|
96
|
-
dir_okay=True,
|
|
97
|
-
resolve_path=True,
|
|
98
|
-
help='Output path to store predictions.'
|
|
99
|
-
)] = None
|
|
110
|
+
)] = tuple(['auto'])
|
|
100
111
|
):
|
|
101
|
-
|
|
112
|
+
from rcsb_embedding_model.inference.structure_inference import predict
|
|
113
|
+
predict(
|
|
114
|
+
csv_file=src_file,
|
|
115
|
+
src_location=src_location,
|
|
116
|
+
src_format=src_format,
|
|
117
|
+
batch_size=batch_size,
|
|
118
|
+
num_workers=num_workers,
|
|
119
|
+
num_nodes=num_nodes,
|
|
120
|
+
accelerator=accelerator,
|
|
121
|
+
devices=arg_devices(devices),
|
|
122
|
+
out_path=output_path,
|
|
123
|
+
out_df_id=out_df_id
|
|
124
|
+
)
|
|
102
125
|
|
|
103
126
|
|
|
104
|
-
@app.command(
|
|
127
|
+
@app.command(
|
|
128
|
+
name="chain-embedding",
|
|
129
|
+
help="Calculate single-chain protein embeddings from residue level embeddings stored as torch tensor files."
|
|
130
|
+
)
|
|
105
131
|
def chain_embedding(
|
|
106
132
|
src_file: Annotated[typer.FileText, typer.Option(
|
|
107
133
|
exists=True,
|
|
@@ -110,6 +136,13 @@ def chain_embedding(
|
|
|
110
136
|
resolve_path=True,
|
|
111
137
|
help='CSV file 2 columns: Residue Embedding Tensor File | Output file name.'
|
|
112
138
|
)],
|
|
139
|
+
output_path: Annotated[typer.FileText, typer.Option(
|
|
140
|
+
exists=True,
|
|
141
|
+
file_okay=False,
|
|
142
|
+
dir_okay=True,
|
|
143
|
+
resolve_path=True,
|
|
144
|
+
help='Output path to store predictions.'
|
|
145
|
+
)],
|
|
113
146
|
batch_size: Annotated[int, typer.Option(
|
|
114
147
|
help='Number of samples processed together in one iteration.'
|
|
115
148
|
)] = 1,
|
|
@@ -124,14 +157,7 @@ def chain_embedding(
|
|
|
124
157
|
)] = Accelerator.auto,
|
|
125
158
|
devices: Annotated[List[str], typer.Option(
|
|
126
159
|
help='The devices to use. Can be set to a positive number or "auto". Repeat this argument to indicate multiple indices of devices. "auto" for automatic selection based on the chosen accelerator.'
|
|
127
|
-
)] = tuple(['auto'])
|
|
128
|
-
output_path: Annotated[typer.FileText, typer.Option(
|
|
129
|
-
exists=True,
|
|
130
|
-
file_okay=False,
|
|
131
|
-
dir_okay=True,
|
|
132
|
-
resolve_path=True,
|
|
133
|
-
help='Output path to store predictions.'
|
|
134
|
-
)] = None
|
|
160
|
+
)] = tuple(['auto'])
|
|
135
161
|
):
|
|
136
162
|
from rcsb_embedding_model.inference.chain_inference import predict
|
|
137
163
|
predict(
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import argparse
|
|
2
|
-
import os
|
|
3
2
|
|
|
4
3
|
import torch
|
|
5
4
|
from biotite.structure import chain_iter
|
|
@@ -48,11 +47,11 @@ class EsmProtFromCsv(Dataset):
|
|
|
48
47
|
return len(self.data)
|
|
49
48
|
|
|
50
49
|
def __getitem__(self, idx):
|
|
51
|
-
|
|
50
|
+
src_structure = self.data.loc[idx, EsmProtFromCsv.STREAM_ATTR]
|
|
52
51
|
chain_id = self.data.loc[idx, EsmProtFromCsv.CH_ATTR]
|
|
53
52
|
name = self.data.loc[idx, EsmProtFromCsv.NAME_ATTR]
|
|
54
53
|
structure = get_structure_from_src(
|
|
55
|
-
|
|
54
|
+
src_structure=src_structure if self.src_location == SrcLocation.local else stringio_from_url(src_structure),
|
|
56
55
|
src_format=self.src_format,
|
|
57
56
|
chain_id=chain_id
|
|
58
57
|
)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from torch.utils.data import DataLoader
|
|
2
|
+
from lightning import Trainer
|
|
3
|
+
from typer import FileText
|
|
4
|
+
|
|
5
|
+
from rcsb_embedding_model.dataset.esm_prot_from_csv import EsmProtFromCsv
|
|
6
|
+
from rcsb_embedding_model.modules.esm_module import EsmModule
|
|
7
|
+
from rcsb_embedding_model.types.api_types import SrcFormat, Accelerator, Devices, OptionalPath, SrcLocation
|
|
8
|
+
from rcsb_embedding_model.writer.batch_writer import DataFrameStorage
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def predict(
|
|
12
|
+
csv_file: FileText,
|
|
13
|
+
src_location: SrcLocation = SrcLocation.local,
|
|
14
|
+
src_format: SrcFormat = SrcFormat.mmcif,
|
|
15
|
+
batch_size: int = 1,
|
|
16
|
+
num_workers: int = 0,
|
|
17
|
+
num_nodes: int = 1,
|
|
18
|
+
accelerator: Accelerator = Accelerator.auto,
|
|
19
|
+
devices: Devices = 'auto',
|
|
20
|
+
out_path: OptionalPath = None,
|
|
21
|
+
out_df_id: str = None
|
|
22
|
+
):
|
|
23
|
+
|
|
24
|
+
inference_set = EsmProtFromCsv(
|
|
25
|
+
csv_file=csv_file,
|
|
26
|
+
src_location=src_location,
|
|
27
|
+
src_format=src_format
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
inference_dataloader = DataLoader(
|
|
31
|
+
dataset=inference_set,
|
|
32
|
+
batch_size=batch_size,
|
|
33
|
+
num_workers=num_workers,
|
|
34
|
+
collate_fn=lambda _: _
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
module = EsmModule()
|
|
38
|
+
inference_writer = DataFrameStorage(out_path, out_df_id) if out_path is not None and out_df_id is not None else None
|
|
39
|
+
trainer = Trainer(
|
|
40
|
+
callbacks=[inference_writer] if inference_writer is not None else None,
|
|
41
|
+
num_nodes=num_nodes,
|
|
42
|
+
accelerator=accelerator,
|
|
43
|
+
devices=devices
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
prediction = trainer.predict(
|
|
47
|
+
module,
|
|
48
|
+
inference_dataloader
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
return prediction
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from esm.sdk.api import SamplingConfig
|
|
2
|
+
from lightning import LightningModule
|
|
3
|
+
|
|
4
|
+
from rcsb_embedding_model.utils.data import collate_seq_embeddings
|
|
5
|
+
from rcsb_embedding_model.utils.model import get_residue_model, get_aggregator_model
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class StructureModule(LightningModule):
|
|
9
|
+
|
|
10
|
+
def __init__(
|
|
11
|
+
self
|
|
12
|
+
):
|
|
13
|
+
super().__init__()
|
|
14
|
+
self.esm3 = get_residue_model(self.device)
|
|
15
|
+
self.aggregator = get_aggregator_model(device=self.device)
|
|
16
|
+
|
|
17
|
+
def predict_step(self, prot_batch, batch_idx):
|
|
18
|
+
prot_embeddings = []
|
|
19
|
+
prot_names = []
|
|
20
|
+
for esm_prot, name in prot_batch:
|
|
21
|
+
embeddings = self.esm3.forward_and_sample(
|
|
22
|
+
self.esm3.encode(esm_prot), SamplingConfig(return_per_residue_embeddings=True)
|
|
23
|
+
).per_residue_embedding
|
|
24
|
+
prot_embeddings.append(embeddings)
|
|
25
|
+
prot_names.append(name)
|
|
26
|
+
res_batch_embedding, res_batch_mask = collate_seq_embeddings(prot_embeddings)
|
|
27
|
+
return self.aggregator(res_batch_embedding, res_batch_mask), tuple(prot_names)
|
|
@@ -2,7 +2,6 @@ import torch
|
|
|
2
2
|
from biotite.structure import get_residues, chain_iter, filter_amino_acids
|
|
3
3
|
from esm.sdk.api import ESMProtein, SamplingConfig
|
|
4
4
|
from esm.utils.structure.protein_chain import ProteinChain
|
|
5
|
-
from huggingface_hub import hf_hub_download
|
|
6
5
|
|
|
7
6
|
from rcsb_embedding_model.types.api_types import StreamSrc, SrcFormat
|
|
8
7
|
from rcsb_embedding_model.utils.model import get_aggregator_model, get_residue_model
|
|
@@ -42,23 +41,23 @@ class RcsbStructureEmbedding:
|
|
|
42
41
|
|
|
43
42
|
def structure_embedding(
|
|
44
43
|
self,
|
|
45
|
-
|
|
44
|
+
src_structure: StreamSrc,
|
|
46
45
|
src_format: SrcFormat = SrcFormat.mmcif,
|
|
47
46
|
chain_id: str = None,
|
|
48
47
|
assembly_id: str = None
|
|
49
48
|
):
|
|
50
|
-
res_embedding = self.residue_embedding(
|
|
49
|
+
res_embedding = self.residue_embedding(src_structure, src_format, chain_id, assembly_id)
|
|
51
50
|
return self.aggregator_embedding(res_embedding)
|
|
52
51
|
|
|
53
52
|
def residue_embedding(
|
|
54
53
|
self,
|
|
55
|
-
|
|
54
|
+
src_structure: StreamSrc,
|
|
56
55
|
src_format: SrcFormat = SrcFormat.mmcif,
|
|
57
56
|
chain_id: str = None,
|
|
58
57
|
assembly_id: str = None
|
|
59
58
|
):
|
|
60
59
|
self.__check_residue_embedding()
|
|
61
|
-
structure = get_structure_from_src(
|
|
60
|
+
structure = get_structure_from_src(src_structure, src_format, chain_id, assembly_id)
|
|
62
61
|
embedding_ch = []
|
|
63
62
|
for atom_ch in chain_iter(structure):
|
|
64
63
|
atom_res = atom_ch[filter_amino_acids(atom_ch)]
|
|
@@ -4,19 +4,19 @@ from biotite.structure.io.pdbx import CIFFile, get_structure, get_assembly, Bina
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
def get_structure_from_src(
|
|
7
|
-
|
|
7
|
+
src_structure,
|
|
8
8
|
src_format="mmcif",
|
|
9
9
|
chain_id=None,
|
|
10
10
|
assembly_id=None
|
|
11
11
|
):
|
|
12
12
|
if src_format == "pdb":
|
|
13
|
-
pdb_file = PDBFile.read(
|
|
13
|
+
pdb_file = PDBFile.read(src_structure)
|
|
14
14
|
structure = __get_pdb_structure(pdb_file, assembly_id)
|
|
15
15
|
elif src_format == "mmcif":
|
|
16
|
-
cif_file = CIFFile.read(
|
|
16
|
+
cif_file = CIFFile.read(src_structure)
|
|
17
17
|
structure = __get_structure(cif_file, assembly_id)
|
|
18
18
|
elif src_format == "binarycif":
|
|
19
|
-
cif_file = BinaryCIFFile.read(
|
|
19
|
+
cif_file = BinaryCIFFile.read(src_structure)
|
|
20
20
|
structure = __get_structure(cif_file, assembly_id)
|
|
21
21
|
else:
|
|
22
22
|
raise RuntimeError(f"Unknown file format {src_format}")
|
|
@@ -13,7 +13,7 @@ class TestEmbeddingModel(unittest.TestCase):
|
|
|
13
13
|
|
|
14
14
|
model = RcsbStructureEmbedding()
|
|
15
15
|
res_embedding = model.residue_embedding(
|
|
16
|
-
f"{self.__test_path}/resources/1acb.cif",
|
|
16
|
+
src_structure=f"{self.__test_path}/resources/1acb.cif",
|
|
17
17
|
src_format=SrcFormat.mmcif,
|
|
18
18
|
chain_id='A'
|
|
19
19
|
)
|
|
@@ -33,7 +33,7 @@ class TestEmbeddingModel(unittest.TestCase):
|
|
|
33
33
|
|
|
34
34
|
model = RcsbStructureEmbedding()
|
|
35
35
|
res_embedding = model.residue_embedding(
|
|
36
|
-
f"{self.__test_path}/resources/1acb.cif",
|
|
36
|
+
src_structure=f"{self.__test_path}/resources/1acb.cif",
|
|
37
37
|
src_format=SrcFormat.mmcif,
|
|
38
38
|
chain_id='A'
|
|
39
39
|
)
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: rcsb-embedding-model
|
|
3
|
-
Version: 0.0.6
|
|
4
|
-
Summary: Protein Embedding Model for Structure Search
|
|
5
|
-
Project-URL: Homepage, https://github.com/rcsb/rcsb-embedding-model
|
|
6
|
-
Project-URL: Issues, https://github.com/rcsb/rcsb-embedding-model/issues
|
|
7
|
-
Author-email: Joan Segura <joan.segura@rcsb.org>
|
|
8
|
-
License-Expression: BSD-3-Clause
|
|
9
|
-
License-File: LICENSE.md
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Requires-Python: >=3.10
|
|
13
|
-
Requires-Dist: esm>=3.2.0
|
|
14
|
-
Requires-Dist: lightning>=2.5.0
|
|
15
|
-
Requires-Dist: torch>=2.2.0
|
|
16
|
-
Requires-Dist: typer>=0.15.0
|
|
17
|
-
Description-Content-Type: text/markdown
|
|
18
|
-
|
|
19
|
-
# RCSB Embedding Model: A Deep Learning Approach for 3D Structure Embeddings
|
|
20
|
-
|
|
21
|
-
## Overview
|
|
22
|
-
RCSB Embedding Model is a PyTorch-based neural network that transforms macromolecular 3D structures into vector embeddings.
|
|
23
|
-
|
|
24
|
-
Preprint: [Multi-scale structural similarity embedding search across entire proteomes](https://www.biorxiv.org/content/10.1101/2025.02.28.640875v1).
|
|
25
|
-
|
|
26
|
-
A web-based implementation using this model for structure similarity search is available at [rcsb-embedding-search](http://embedding-search.rcsb.org).
|
|
27
|
-
|
|
28
|
-
If you are interested in training the model with a new dataset, visit the [rcsb-embedding-search repository](https://github.com/bioinsilico/rcsb-embedding-search), which provides scripts and documentation for training.
|
|
29
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
## Embedding Model
|
|
33
|
-
The embedding model is trained to predict structural similarity by approximating TM-scores using cosine distances between embeddings. It consists of two main components:
|
|
34
|
-
|
|
35
|
-
- **Protein Language Model (PLM)**: Computes residue-level embeddings from a given 3D structure.
|
|
36
|
-
- **Residue Embedding Aggregator**: A transformer-based neural network that aggregates these residue-level embeddings into a single vector.
|
|
37
|
-
|
|
38
|
-

|
|
39
|
-
|
|
40
|
-
### **Protein Language Model (PLM)**
|
|
41
|
-
Residue-wise embeddings of protein structures are computed using the [ESM3](https://www.evolutionaryscale.ai/) generative protein language model.
|
|
42
|
-
|
|
43
|
-
### **Residue Embedding Aggregator**
|
|
44
|
-
The aggregation component consists of six transformer encoder layers, each with a 3,072-neuron feedforward layer and ReLU activations. After processing through these layers, a summation pooling operation is applied, followed by 12 fully connected residual layers that refine the embeddings into a single 1,536-dimensional vector.
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
## How to Use the Model
|
|
49
|
-
This repository provides the tools to compute embeddings for 3D macromolecular structure data.
|
|
50
|
-
|
|
51
|
-
### **Installation**
|
|
52
|
-
`pip install rcsb-embedding-model`
|
|
53
|
-
|
|
54
|
-
### **Requirements**
|
|
55
|
-
Ensure you have the following dependencies installed:
|
|
56
|
-
- `python >= 3.10`
|
|
57
|
-
- `esm`
|
|
58
|
-
- `torch`
|
|
59
|
-
|
|
60
|
-
### **Generating Residue Embeddings**
|
|
61
|
-
ESM3 embeddings for the 3D structures can be calculated as:
|
|
62
|
-
|
|
63
|
-
```python
|
|
64
|
-
from rcsb_embedding_model import RcsbStructureEmbedding
|
|
65
|
-
|
|
66
|
-
mmcif_file = "<path_to_file>/<name>.cif"
|
|
67
|
-
model = RcsbStructureEmbedding()
|
|
68
|
-
res_embedding = model.residue_embedding(
|
|
69
|
-
structure_src=mmcif_file,
|
|
70
|
-
format="mmcif",
|
|
71
|
-
chain_id='A'
|
|
72
|
-
)
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### **Generating Protein Structure Embeddings**
|
|
76
|
-
Protein 3D structure embedding can be calculated as:
|
|
77
|
-
|
|
78
|
-
```python
|
|
79
|
-
from rcsb_embedding_model import RcsbStructureEmbedding
|
|
80
|
-
|
|
81
|
-
mmcif_file = "<path_to_file>/<name>.cif"
|
|
82
|
-
model = RcsbStructureEmbedding()
|
|
83
|
-
res_embedding = model.residue_embedding(
|
|
84
|
-
structure_src=mmcif_file,
|
|
85
|
-
format="mmcif",
|
|
86
|
-
chain_id='A'
|
|
87
|
-
)
|
|
88
|
-
structure_embedding = model.aggregator_embedding(
|
|
89
|
-
res_embedding
|
|
90
|
-
)
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### **Pretrained Model**
|
|
94
|
-
You can download a pretrained Residue Embedding Aggregator model from [Hugging Face](https://huggingface.co/jseguramora/rcsb-embedding-model/resolve/main/rcsb-embedding-model.pt).
|
|
95
|
-
|
|
96
|
-
---
|
|
97
|
-
|
|
98
|
-
## Questions & Issues
|
|
99
|
-
For any questions or comments, please open an issue on this repository.
|
|
100
|
-
|
|
101
|
-
---
|
|
102
|
-
|
|
103
|
-
## License
|
|
104
|
-
This software is released under the BSD 3-Clause License. See the full license text below.
|
|
105
|
-
|
|
106
|
-
### BSD 3-Clause License
|
|
107
|
-
|
|
108
|
-
Copyright (c) 2024, RCSB Protein Data Bank, UC San Diego
|
|
109
|
-
|
|
110
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
111
|
-
|
|
112
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
|
|
113
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
114
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
115
|
-
|
|
116
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
117
|
-
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
# RCSB Embedding Model: A Deep Learning Approach for 3D Structure Embeddings
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
RCSB Embedding Model is a PyTorch-based neural network that transforms macromolecular 3D structures into vector embeddings.
|
|
5
|
-
|
|
6
|
-
Preprint: [Multi-scale structural similarity embedding search across entire proteomes](https://www.biorxiv.org/content/10.1101/2025.02.28.640875v1).
|
|
7
|
-
|
|
8
|
-
A web-based implementation using this model for structure similarity search is available at [rcsb-embedding-search](http://embedding-search.rcsb.org).
|
|
9
|
-
|
|
10
|
-
If you are interested in training the model with a new dataset, visit the [rcsb-embedding-search repository](https://github.com/bioinsilico/rcsb-embedding-search), which provides scripts and documentation for training.
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
## Embedding Model
|
|
15
|
-
The embedding model is trained to predict structural similarity by approximating TM-scores using cosine distances between embeddings. It consists of two main components:
|
|
16
|
-
|
|
17
|
-
- **Protein Language Model (PLM)**: Computes residue-level embeddings from a given 3D structure.
|
|
18
|
-
- **Residue Embedding Aggregator**: A transformer-based neural network that aggregates these residue-level embeddings into a single vector.
|
|
19
|
-
|
|
20
|
-

|
|
21
|
-
|
|
22
|
-
### **Protein Language Model (PLM)**
|
|
23
|
-
Residue-wise embeddings of protein structures are computed using the [ESM3](https://www.evolutionaryscale.ai/) generative protein language model.
|
|
24
|
-
|
|
25
|
-
### **Residue Embedding Aggregator**
|
|
26
|
-
The aggregation component consists of six transformer encoder layers, each with a 3,072-neuron feedforward layer and ReLU activations. After processing through these layers, a summation pooling operation is applied, followed by 12 fully connected residual layers that refine the embeddings into a single 1,536-dimensional vector.
|
|
27
|
-
|
|
28
|
-
---
|
|
29
|
-
|
|
30
|
-
## How to Use the Model
|
|
31
|
-
This repository provides the tools to compute embeddings for 3D macromolecular structure data.
|
|
32
|
-
|
|
33
|
-
### **Installation**
|
|
34
|
-
`pip install rcsb-embedding-model`
|
|
35
|
-
|
|
36
|
-
### **Requirements**
|
|
37
|
-
Ensure you have the following dependencies installed:
|
|
38
|
-
- `python >= 3.10`
|
|
39
|
-
- `esm`
|
|
40
|
-
- `torch`
|
|
41
|
-
|
|
42
|
-
### **Generating Residue Embeddings**
|
|
43
|
-
ESM3 embeddings for the 3D structures can be calculated as:
|
|
44
|
-
|
|
45
|
-
```python
|
|
46
|
-
from rcsb_embedding_model import RcsbStructureEmbedding
|
|
47
|
-
|
|
48
|
-
mmcif_file = "<path_to_file>/<name>.cif"
|
|
49
|
-
model = RcsbStructureEmbedding()
|
|
50
|
-
res_embedding = model.residue_embedding(
|
|
51
|
-
structure_src=mmcif_file,
|
|
52
|
-
format="mmcif",
|
|
53
|
-
chain_id='A'
|
|
54
|
-
)
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### **Generating Protein Structure Embeddings**
|
|
58
|
-
Protein 3D structure embedding can be calculated as:
|
|
59
|
-
|
|
60
|
-
```python
|
|
61
|
-
from rcsb_embedding_model import RcsbStructureEmbedding
|
|
62
|
-
|
|
63
|
-
mmcif_file = "<path_to_file>/<name>.cif"
|
|
64
|
-
model = RcsbStructureEmbedding()
|
|
65
|
-
res_embedding = model.residue_embedding(
|
|
66
|
-
structure_src=mmcif_file,
|
|
67
|
-
format="mmcif",
|
|
68
|
-
chain_id='A'
|
|
69
|
-
)
|
|
70
|
-
structure_embedding = model.aggregator_embedding(
|
|
71
|
-
res_embedding
|
|
72
|
-
)
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### **Pretrained Model**
|
|
76
|
-
You can download a pretrained Residue Embedding Aggregator model from [Hugging Face](https://huggingface.co/jseguramora/rcsb-embedding-model/resolve/main/rcsb-embedding-model.pt).
|
|
77
|
-
|
|
78
|
-
---
|
|
79
|
-
|
|
80
|
-
## Questions & Issues
|
|
81
|
-
For any questions or comments, please open an issue on this repository.
|
|
82
|
-
|
|
83
|
-
---
|
|
84
|
-
|
|
85
|
-
## License
|
|
86
|
-
This software is released under the BSD 3-Clause License. See the full license text below.
|
|
87
|
-
|
|
88
|
-
### BSD 3-Clause License
|
|
89
|
-
|
|
90
|
-
Copyright (c) 2024, RCSB Protein Data Bank, UC San Diego
|
|
91
|
-
|
|
92
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
93
|
-
|
|
94
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
|
|
95
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
96
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
97
|
-
|
|
98
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
99
|
-
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import argparse
|
|
2
|
-
|
|
3
|
-
import torch
|
|
4
|
-
from biotite.structure import chain_iter, get_residues, filter_amino_acids
|
|
5
|
-
from biotite.structure.io.pdb import PDBFile
|
|
6
|
-
from biotite.structure.io.pdbx import CIFFile, get_structure, BinaryCIFFile
|
|
7
|
-
from esm.models.esm3 import ESM3, ESM3_OPEN_SMALL
|
|
8
|
-
from esm.sdk.api import ESMProtein, SamplingConfig
|
|
9
|
-
from esm.utils.structure.protein_chain import ProteinChain
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def get_structure_from_file(file_name, format="pdb", chain_id=None):
|
|
13
|
-
try:
|
|
14
|
-
if format == "pdb":
|
|
15
|
-
structure = PDBFile.read(file_name).get_structure(
|
|
16
|
-
model=1
|
|
17
|
-
)
|
|
18
|
-
elif format == "mmcif":
|
|
19
|
-
cif_file = CIFFile.read(file_name)
|
|
20
|
-
structure = get_structure(
|
|
21
|
-
cif_file,
|
|
22
|
-
model=1,
|
|
23
|
-
use_author_fields=False
|
|
24
|
-
)
|
|
25
|
-
elif format == "binarycif":
|
|
26
|
-
cif_file = BinaryCIFFile.read(file_name)
|
|
27
|
-
structure = get_structure(
|
|
28
|
-
cif_file,
|
|
29
|
-
model=1,
|
|
30
|
-
use_author_fields=False
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
if chain_id:
|
|
34
|
-
structure = structure[structure.chain_id == chain_id]
|
|
35
|
-
return structure
|
|
36
|
-
except:
|
|
37
|
-
return None
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
esm3_model = ESM3.from_pretrained(ESM3_OPEN_SMALL)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def compute_embeddings(structure):
|
|
44
|
-
embedding_ch = []
|
|
45
|
-
for atom_ch in chain_iter(structure):
|
|
46
|
-
atom_res = atom_ch[filter_amino_acids(atom_ch)]
|
|
47
|
-
if len(atom_res) == 0 or len(get_residues(atom_res)[0]) < 10:
|
|
48
|
-
continue
|
|
49
|
-
protein_chain = ProteinChain.from_atomarray(atom_ch)
|
|
50
|
-
protein = ESMProtein.from_protein_chain(protein_chain)
|
|
51
|
-
protein_tensor = esm3_model.encode(protein)
|
|
52
|
-
embedding_ch.append( esm3_model.forward_and_sample(
|
|
53
|
-
protein_tensor, SamplingConfig(return_per_residue_embeddings=True)
|
|
54
|
-
).per_residue_embedding)
|
|
55
|
-
return torch.cat(
|
|
56
|
-
embedding_ch,
|
|
57
|
-
dim=0
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if __name__ == "__main__":
|
|
62
|
-
|
|
63
|
-
parser = argparse.ArgumentParser()
|
|
64
|
-
parser.add_argument('--file', type=str, required=True)
|
|
65
|
-
parser.add_argument('--file_format', type=str)
|
|
66
|
-
parser.add_argument('--chain', type=str)
|
|
67
|
-
args = parser.parse_args()
|
|
68
|
-
|
|
69
|
-
structure = get_structure_from_file(
|
|
70
|
-
args.file,
|
|
71
|
-
"pdb" if not args.file_format else args.file_format,
|
|
72
|
-
chain_id=args.chain
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
embeddings = compute_embeddings(structure)
|
|
76
|
-
|
|
77
|
-
print(embeddings.shape)
|
|
File without changes
|
|
File without changes
|
{rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/assets/embedding-model-architecture.png
RENAMED
|
File without changes
|
{rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/model/layers.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/utils/data.py
RENAMED
|
File without changes
|
{rcsb_embedding_model-0.0.6 → rcsb_embedding_model-0.0.7}/src/rcsb_embedding_model/utils/model.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|