rcsb-embedding-model 0.0.6__py3-none-any.whl → 0.0.8__py3-none-any.whl

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.

Files changed (26) hide show
  1. rcsb_embedding_model/cli/args_utils.py +0 -2
  2. rcsb_embedding_model/cli/inference.py +164 -42
  3. rcsb_embedding_model/dataset/esm_prot_from_chain.py +102 -0
  4. rcsb_embedding_model/dataset/esm_prot_from_structure.py +63 -0
  5. rcsb_embedding_model/dataset/resdiue_assembly_embedding_from_structure.py +68 -0
  6. rcsb_embedding_model/dataset/residue_assembly_embedding_from_tensor_file.py +94 -0
  7. rcsb_embedding_model/dataset/residue_embedding_from_tensor_file.py +43 -0
  8. rcsb_embedding_model/inference/assembly_inferece.py +53 -0
  9. rcsb_embedding_model/inference/chain_inference.py +12 -8
  10. rcsb_embedding_model/inference/esm_inference.py +18 -8
  11. rcsb_embedding_model/inference/structure_inference.py +61 -0
  12. rcsb_embedding_model/modules/structure_module.py +27 -0
  13. rcsb_embedding_model/rcsb_structure_embedding.py +7 -8
  14. rcsb_embedding_model/types/api_types.py +27 -5
  15. rcsb_embedding_model/utils/data.py +30 -0
  16. rcsb_embedding_model/utils/structure_parser.py +43 -13
  17. rcsb_embedding_model/utils/structure_provider.py +27 -0
  18. rcsb_embedding_model-0.0.8.dist-info/METADATA +129 -0
  19. rcsb_embedding_model-0.0.8.dist-info/RECORD +29 -0
  20. rcsb_embedding_model/dataset/esm_prot_from_csv.py +0 -91
  21. rcsb_embedding_model/dataset/residue_embedding_from_csv.py +0 -32
  22. rcsb_embedding_model-0.0.6.dist-info/METADATA +0 -117
  23. rcsb_embedding_model-0.0.6.dist-info/RECORD +0 -22
  24. {rcsb_embedding_model-0.0.6.dist-info → rcsb_embedding_model-0.0.8.dist-info}/WHEEL +0 -0
  25. {rcsb_embedding_model-0.0.6.dist-info → rcsb_embedding_model-0.0.8.dist-info}/entry_points.txt +0 -0
  26. {rcsb_embedding_model-0.0.6.dist-info → rcsb_embedding_model-0.0.8.dist-info}/licenses/LICENSE.md +0 -0
@@ -1,91 +0,0 @@
1
- import argparse
2
- import os
3
-
4
- import torch
5
- from biotite.structure import chain_iter
6
- from esm.models.esm3 import ESM3
7
- from esm.sdk.api import ESMProtein, SamplingConfig
8
- from esm.utils.constants.models import ESM3_OPEN_SMALL
9
- from esm.utils.structure.protein_chain import ProteinChain
10
- from torch.utils.data import Dataset, DataLoader
11
- import pandas as pd
12
-
13
- from rcsb_embedding_model.types.api_types import SrcFormat, SrcLocation
14
- from rcsb_embedding_model.utils.data import stringio_from_url
15
- from rcsb_embedding_model.utils.structure_parser import get_structure_from_src
16
-
17
-
18
- class EsmProtFromCsv(Dataset):
19
-
20
- MIN_RES = 10
21
- STREAM_ATTR = 'stream'
22
- CH_ATTR = 'chain_id'
23
- NAME_ATTR = 'name'
24
-
25
- COLUMNS = [STREAM_ATTR, CH_ATTR, NAME_ATTR]
26
-
27
- def __init__(
28
- self,
29
- csv_file,
30
- src_location=SrcLocation.local,
31
- src_format=SrcFormat.mmcif,
32
- ):
33
- super().__init__()
34
- self.src_location = src_location
35
- self.src_format = src_format
36
- self.data = pd.DataFrame()
37
- self.__load_stream(csv_file)
38
-
39
- def __load_stream(self, stream_list):
40
- self.data = pd.read_csv(
41
- stream_list,
42
- header=None,
43
- index_col=None,
44
- names=EsmProtFromCsv.COLUMNS
45
- )
46
-
47
- def __len__(self):
48
- return len(self.data)
49
-
50
- def __getitem__(self, idx):
51
- structure_src = self.data.loc[idx, EsmProtFromCsv.STREAM_ATTR]
52
- chain_id = self.data.loc[idx, EsmProtFromCsv.CH_ATTR]
53
- name = self.data.loc[idx, EsmProtFromCsv.NAME_ATTR]
54
- structure = get_structure_from_src(
55
- structure_src if self.src_location == SrcLocation.local else stringio_from_url(structure_src),
56
- src_format=self.src_format,
57
- chain_id=chain_id
58
- )
59
- for atom_ch in chain_iter(structure):
60
- protein_chain = ProteinChain.from_atomarray(atom_ch)
61
- return ESMProtein.from_protein_chain(protein_chain), name
62
-
63
-
64
- if __name__ == '__main__':
65
-
66
- parser = argparse.ArgumentParser()
67
- parser.add_argument('--file_list', type=argparse.FileType('r'), required=True)
68
- args = parser.parse_args()
69
-
70
- dataset = EsmProtFromCsv(
71
- args.file_list
72
- )
73
-
74
- esm3 = ESM3.from_pretrained(
75
- ESM3_OPEN_SMALL,
76
- torch.device("cpu")
77
- )
78
-
79
- dataloader = DataLoader(
80
- dataset,
81
- batch_size=2,
82
- collate_fn=lambda _: _
83
- )
84
-
85
- for _batch in dataloader:
86
- for esm_prot, name in _batch:
87
- protein_tensor = esm3.encode(esm_prot)
88
- embeddings = esm3.forward_and_sample(
89
- protein_tensor, SamplingConfig(return_per_residue_embeddings=True)
90
- ).per_residue_embedding
91
- print(name, embeddings.shape)
@@ -1,32 +0,0 @@
1
- import pandas as pd
2
- import torch
3
- from torch.utils.data import Dataset
4
-
5
-
6
- class ResidueEmbeddingFromCSV(Dataset):
7
-
8
- STREAM_ATTR = 'stream'
9
- NAME_ATTR = 'name'
10
-
11
- COLUMNS = [STREAM_ATTR, NAME_ATTR]
12
-
13
- def __init__(self, csv_file):
14
- super().__init__()
15
- self.data = pd.DataFrame()
16
- self.__load_stream(csv_file)
17
-
18
- def __load_stream(self, csv_file):
19
- self.data = pd.read_csv(
20
- csv_file,
21
- header=None,
22
- index_col=None,
23
- names=ResidueEmbeddingFromCSV.COLUMNS
24
- )
25
-
26
- def __len__(self):
27
- return len(self.data)
28
-
29
- def __getitem__(self, idx):
30
- embedding_src = self.data.loc[idx, ResidueEmbeddingFromCSV.STREAM_ATTR]
31
- name = self.data.loc[idx, ResidueEmbeddingFromCSV.NAME_ATTR]
32
- return torch.load(embedding_src, map_location=torch.device('cpu')), name
@@ -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
- ![Embedding model architecture](assets/embedding-model-architecture.png)
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,22 +0,0 @@
1
- rcsb_embedding_model/__init__.py,sha256=r3gLdeBIXkQEQA_K6QcRPO-TtYuAQSutk6pXRUE_nas,120
2
- rcsb_embedding_model/rcsb_structure_embedding.py,sha256=ZvR_1aNZc_gDtz-ljOfJ7mswXzTGl4hcDAAj59ZGiVw,4477
3
- rcsb_embedding_model/cli/args_utils.py,sha256=rv3rANhjvI9BYvlJUSPsa3B6qp-MjdF4iNwv2YmzFl4,188
4
- rcsb_embedding_model/cli/inference.py,sha256=TpJXKWJkYdUbc0_SI_U3jPk94HcpoQcEXzFmif2DFQo,5706
5
- rcsb_embedding_model/dataset/esm_prot_from_csv.py,sha256=f3R0G7RiwJiCtispq5hFjljDOndPCGsZ5f_hdi9S7iw,2718
6
- rcsb_embedding_model/dataset/residue_embedding_from_csv.py,sha256=0-5L64tyER-RpT166pC71qxOpUdVZbcuBQONPcAIuno,862
7
- rcsb_embedding_model/inference/chain_inference.py,sha256=SgXDa-TkDcvlkQxqEwDt81RdE7NmgiaJD8uaROgMbl8,1506
8
- rcsb_embedding_model/inference/esm_inference.py,sha256=pX-_RhzAIvL0Zdg9wjScLBP6Y1sq4RLNio4-vdR5MLU,1498
9
- rcsb_embedding_model/model/layers.py,sha256=lhKaWC4gTS_T5lHOP0mgnnP8nKTPEOm4MrjhESA4hE8,743
10
- rcsb_embedding_model/model/residue_embedding_aggregator.py,sha256=k3UW63Ax8DtjCMdD3O5xNxtyAu28l2n3-Ab6nS0atm0,1967
11
- rcsb_embedding_model/modules/chain_module.py,sha256=sDSPXJmWuU2C3lt1NorlbUVWZvRSLzumPdFQk01h3VI,403
12
- rcsb_embedding_model/modules/esm_module.py,sha256=CTHGOATXiarqZsBsZ8oxGJBj20A73186Slpr0EzMJsE,770
13
- rcsb_embedding_model/types/api_types.py,sha256=x7274MyjkRXn8B-W-PY5PK9g0CP1pT_clZbrAuFuHPA,626
14
- rcsb_embedding_model/utils/data.py,sha256=LGw3wvq_LCcqSovHZacOqxEczn12SZk2i51WK9xkk0k,1877
15
- rcsb_embedding_model/utils/model.py,sha256=rpZa-gfm3cEtbBd7UXMHrZv3x6f0AC8TJT3gtrSxr5I,852
16
- rcsb_embedding_model/utils/structure_parser.py,sha256=yb_ul7Ci5uBubBSfctrXfq5GqdC7RYyox5U0jWBdKAI,1492
17
- rcsb_embedding_model/writer/batch_writer.py,sha256=ekgzFZyoKpcnZ3IDP9hfOWBpuHxUQ31P35ViDAi-Edw,2843
18
- rcsb_embedding_model-0.0.6.dist-info/METADATA,sha256=_Xvyci0hVEaoSWpMJIBhKhAaIy5JWx3IVFqjQ_V8KIc,5442
19
- rcsb_embedding_model-0.0.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
20
- rcsb_embedding_model-0.0.6.dist-info/entry_points.txt,sha256=MK11jTIEmaV-x4CkPX5IymDaVs7Ky_f2xxU8BJVZ_9Q,69
21
- rcsb_embedding_model-0.0.6.dist-info/licenses/LICENSE.md,sha256=oUaHiKgfBkChth_Sm67WemEvatO1U0Go8LHjaskXY0w,1522
22
- rcsb_embedding_model-0.0.6.dist-info/RECORD,,