rcsb-embedding-model 0.0.32__tar.gz → 0.0.34__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.

Files changed (51) hide show
  1. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/PKG-INFO +1 -1
  2. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/pyproject.toml +1 -1
  3. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/dataset/esm_prot_from_chain.py +10 -6
  4. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/utils/data.py +4 -6
  5. rcsb_embedding_model-0.0.34/src/rcsb_embedding_model/utils/structure_parser.py +100 -0
  6. rcsb_embedding_model-0.0.32/src/rcsb_embedding_model/utils/structure_parser.py +0 -92
  7. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/.dockerignore +0 -0
  8. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/.github/workflows/_workflow-docker.yaml +0 -0
  9. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/.github/workflows/publish.yaml +0 -0
  10. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/.gitignore +0 -0
  11. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/Dockerfile +0 -0
  12. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/LICENSE.md +0 -0
  13. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/README.md +0 -0
  14. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/assets/embedding-model-architecture.png +0 -0
  15. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/examples/esm_embeddings.py +0 -0
  16. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/__init__.py +0 -0
  17. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/cli/args_utils.py +0 -0
  18. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/cli/inference.py +0 -0
  19. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/dataset/esm_prot_from_structure.py +0 -0
  20. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/dataset/resdiue_assembly_embedding_from_structure.py +0 -0
  21. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/dataset/residue_assembly_embedding_from_tensor_file.py +0 -0
  22. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/dataset/residue_embedding_from_structure.py +0 -0
  23. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/dataset/residue_embedding_from_tensor_file.py +0 -0
  24. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/inference/assembly_inferece.py +0 -0
  25. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/inference/chain_inference.py +0 -0
  26. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/inference/esm_inference.py +0 -0
  27. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/inference/structure_inference.py +0 -0
  28. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/model/layers.py +0 -0
  29. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/model/residue_embedding_aggregator.py +0 -0
  30. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/modules/chain_module.py +0 -0
  31. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/modules/esm_module.py +0 -0
  32. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/modules/structure_module.py +0 -0
  33. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/rcsb_structure_embedding.py +0 -0
  34. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/types/api_types.py +0 -0
  35. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/utils/model.py +0 -0
  36. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/utils/structure_provider.py +0 -0
  37. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/src/rcsb_embedding_model/writer/batch_writer.py +0 -0
  38. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/tests/resources/embeddings/1acb.A.pt +0 -0
  39. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/tests/resources/embeddings/1acb.B.pt +0 -0
  40. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/tests/resources/embeddings/2uzi.A.pt +0 -0
  41. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/tests/resources/embeddings/2uzi.B.pt +0 -0
  42. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/tests/resources/embeddings/2uzi.C.pt +0 -0
  43. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/tests/resources/pdb/1acb.cif +0 -0
  44. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/tests/resources/pdb/2uzi.cif +0 -0
  45. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/tests/resources/src_stream/assembly-complete-test.csv +0 -0
  46. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/tests/resources/src_stream/instance-complete-test.csv +0 -0
  47. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/tests/resources/src_stream/instance.csv +0 -0
  48. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/tests/test_cli_inference.py +0 -0
  49. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/tests/test_embedding_model.py +0 -0
  50. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/tests/test_inference.py +0 -0
  51. {rcsb_embedding_model-0.0.32 → rcsb_embedding_model-0.0.34}/tests/test_remote_inference.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rcsb-embedding-model
3
- Version: 0.0.32
3
+ Version: 0.0.34
4
4
  Summary: Protein Embedding Model for Structure Search
5
5
  Project-URL: Homepage, https://github.com/rcsb/rcsb-embedding-model
6
6
  Project-URL: Issues, https://github.com/rcsb/rcsb-embedding-model/issues
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "rcsb-embedding-model"
3
- version = "0.0.32"
3
+ version = "0.0.34"
4
4
  authors = [
5
5
  { name="Joan Segura", email="joan.segura@rcsb.org" },
6
6
  ]
@@ -11,7 +11,7 @@ import pandas as pd
11
11
 
12
12
  from rcsb_embedding_model.types.api_types import StructureFormat, StructureLocation, SrcLocation
13
13
  from rcsb_embedding_model.utils.data import stringio_from_url
14
- from rcsb_embedding_model.utils.structure_parser import rename_atom_ch, check_all_hetero, remove_hetero
14
+ from rcsb_embedding_model.utils.structure_parser import rename_atom_attr,filter_residues
15
15
  from rcsb_embedding_model.utils.structure_provider import StructureProvider
16
16
 
17
17
 
@@ -72,13 +72,17 @@ class EsmProtFromChain(Dataset):
72
72
  for atom_ch in chain_iter(structure):
73
73
  if len(atom_ch) == 0:
74
74
  raise IOError(f"No atoms were found in structure chain {src_name}.{chain_id}")
75
- if check_all_hetero(atom_ch):
76
- atom_ch = remove_hetero(atom_ch)
77
- atom_ch = rename_atom_ch(atom_ch)
78
- protein_chain = ProteinChain.from_atomarray(atom_ch)
79
- protein_chain = ESMProtein.from_protein_chain(protein_chain)
75
+ atom_ch = filter_residues(atom_ch)
76
+ atom_ch = rename_atom_attr(atom_ch)
77
+ try:
78
+ protein_chain = ProteinChain.from_atomarray(atom_ch)
79
+ protein_chain = ESMProtein.from_protein_chain(protein_chain)
80
+ except Exception as e:
81
+ raise IOError(f"Error while creating ESMProtein from structure chain {src_name}.{chain_id}: {e}")
82
+
80
83
  if len(protein_chain) == 0:
81
84
  raise IOError(f"No atoms were found in structure chain {src_name}.{chain_id}")
85
+
82
86
  return protein_chain, item_name
83
87
  raise IOError(f"No atoms were found in structure chain {src_name}.{chain_id}")
84
88
 
@@ -4,6 +4,7 @@ import gzip
4
4
  from io import StringIO, BytesIO
5
5
 
6
6
  import torch
7
+ from requests import RequestException
7
8
 
8
9
 
9
10
  def collate_seq_embeddings(batch_list):
@@ -52,13 +53,10 @@ def stringio_from_url(url):
52
53
  return StringIO(f.read())
53
54
  else:
54
55
  return StringIO(response.text)
55
- except requests.exceptions.RequestException as e:
56
- print(f"Error fetching URL: {e}")
57
- return None
56
+ except RequestException as e:
57
+ raise RuntimeError(f"Error fetching URL: {e}")
58
58
  except (OSError, gzip.BadGzipFile) as e:
59
- print(f"Error decompressing gzip file: {e}")
60
- return None
61
-
59
+ raise RuntimeError(f"Error decompressing gzip file: {e}")
62
60
 
63
61
 
64
62
  def concatenate_tensors(file_list, max_residues, dim=0):
@@ -0,0 +1,100 @@
1
+ import numpy as np
2
+ from biotite.structure import filter_amino_acids, filter_polymer, chain_iter, get_chains, get_residues, \
3
+ filter_peptide_backbone, residue_iter, array
4
+ from biotite.structure.io.pdb import PDBFile, get_structure as get_pdb_structure, get_assembly as get_pdb_assembly, list_assemblies as list_pdb_assemblies
5
+ from biotite.structure.io.pdbx import CIFFile, get_structure, get_assembly, BinaryCIFFile, list_assemblies
6
+
7
+
8
+ def get_structure_from_src(
9
+ src_structure,
10
+ structure_format="mmcif",
11
+ chain_id=None,
12
+ assembly_id=None
13
+ ):
14
+ try:
15
+ if structure_format == "pdb":
16
+ pdb_file = PDBFile.read(src_structure)
17
+ structure = __get_pdb_structure(pdb_file, assembly_id)
18
+ elif structure_format == "mmcif":
19
+ cif_file = CIFFile.read(src_structure)
20
+ structure = __get_structure(cif_file, assembly_id)
21
+ elif structure_format == "binarycif":
22
+ cif_file = BinaryCIFFile.read(src_structure)
23
+ structure = __get_structure(cif_file, assembly_id)
24
+ else:
25
+ raise RuntimeError(f"Unknown file format {structure_format}")
26
+ except Exception as e:
27
+ raise RuntimeError(f"Error reading structure from {src_structure}: {e}")
28
+
29
+ if chain_id is not None:
30
+ return structure[structure.chain_id == chain_id]
31
+
32
+ return structure
33
+
34
+
35
+ def get_protein_chains(structure, min_res_n=0):
36
+ chain_ids = []
37
+ for atom_ch in chain_iter(structure):
38
+ atom_res = atom_ch[filter_polymer(atom_ch)]
39
+ atom_res = atom_res[filter_amino_acids(atom_res)]
40
+ if len(atom_res) > 0 and len(get_residues(atom_res)[0]) > min_res_n:
41
+ chain_ids.append(str(get_chains(atom_res)[0]))
42
+ return tuple(chain_ids)
43
+
44
+
45
+ def get_assemblies(structure, structure_format="mmcif"):
46
+ try:
47
+ if structure_format == "pdb":
48
+ return tuple(list_pdb_assemblies(PDBFile.read(structure)))
49
+ elif structure_format == "mmcif":
50
+ return tuple(list_assemblies(CIFFile.read(structure)).keys())
51
+ elif structure_format == "binarycif":
52
+ return tuple(list_assemblies(BinaryCIFFile.read(structure)))
53
+ else:
54
+ raise RuntimeError(f"Unknown file format {structure_format}")
55
+ except Exception as e:
56
+ raise RuntimeError(f"Error reading assemblies from {structure}: {e}")
57
+
58
+
59
+ def rename_atom_attr(atom_ch):
60
+ return array([__rename_atom(a) for a in atom_ch])
61
+
62
+
63
+ def filter_residues(atom_ch):
64
+ return atom_ch[filter_amino_acids(atom_ch)]
65
+
66
+
67
+ def get_backbone_atoms(atom_ch):
68
+ return np.array([(lambda x: [a.coord for a in x])(r) for r in residue_iter(atom_ch[filter_peptide_backbone(atom_ch)])])
69
+
70
+
71
+ def __get_pdb_structure(pdb_file, assembly_id=None):
72
+ return get_pdb_structure(
73
+ pdb_file,
74
+ model=1
75
+ ) if assembly_id is None else get_pdb_assembly(
76
+ pdb_file,
77
+ assembly_id=assembly_id,
78
+ model=1
79
+ )
80
+
81
+
82
+ def __rename_atom(atom):
83
+ atom.chain_id = "A"
84
+ atom.hetero = False
85
+ if len(atom.res_name) > 3:
86
+ atom.res_name = 'UNK'
87
+ return atom
88
+
89
+
90
+ def __get_structure(cif_file, assembly_id=None):
91
+ return get_structure(
92
+ cif_file,
93
+ model=1,
94
+ use_author_fields=False
95
+ ) if assembly_id is None else get_assembly(
96
+ cif_file,
97
+ assembly_id=assembly_id,
98
+ model=1,
99
+ use_author_fields=False
100
+ )
@@ -1,92 +0,0 @@
1
- from biotite.structure import filter_amino_acids, filter_polymer, chain_iter, get_chains, get_residues, AtomArray
2
- from biotite.structure.io.pdb import PDBFile, get_structure as get_pdb_structure, get_assembly as get_pdb_assembly, list_assemblies as list_pdb_assemblies
3
- from biotite.structure.io.pdbx import CIFFile, get_structure, get_assembly, BinaryCIFFile, list_assemblies
4
-
5
-
6
- def get_structure_from_src(
7
- src_structure,
8
- structure_format="mmcif",
9
- chain_id=None,
10
- assembly_id=None
11
- ):
12
- if structure_format == "pdb":
13
- pdb_file = PDBFile.read(src_structure)
14
- structure = __get_pdb_structure(pdb_file, assembly_id)
15
- elif structure_format == "mmcif":
16
- cif_file = CIFFile.read(src_structure)
17
- structure = __get_structure(cif_file, assembly_id)
18
- elif structure_format == "binarycif":
19
- cif_file = BinaryCIFFile.read(src_structure)
20
- structure = __get_structure(cif_file, assembly_id)
21
- else:
22
- raise RuntimeError(f"Unknown file format {structure_format}")
23
-
24
- if chain_id is not None:
25
- return structure[structure.chain_id == chain_id]
26
-
27
- return structure
28
-
29
-
30
- def get_protein_chains(structure, min_res_n=0):
31
- chain_ids = []
32
- for atom_ch in chain_iter(structure):
33
- atom_res = atom_ch[filter_polymer(atom_ch)]
34
- atom_res = atom_res[filter_amino_acids(atom_res)]
35
- if len(atom_res) > 0 and len(get_residues(atom_res)[0]) > min_res_n:
36
- chain_ids.append(str(get_chains(atom_res)[0]))
37
- return tuple(chain_ids)
38
-
39
-
40
- def get_assemblies(structure, structure_format="mmcif"):
41
- if structure_format == "pdb":
42
- return tuple(list_pdb_assemblies(PDBFile.read(structure)))
43
- elif structure_format == "mmcif":
44
- return tuple(list_assemblies(CIFFile.read(structure)).keys())
45
- elif structure_format == "binarycif":
46
- return tuple(list_assemblies(BinaryCIFFile.read(structure)))
47
- else:
48
- raise RuntimeError(f"Unknown file format {structure_format}")
49
-
50
-
51
- def rename_atom_ch(atom_ch, ch="A"):
52
- renamed_atom_ch = AtomArray(len(atom_ch))
53
- for idx, atom in enumerate(atom_ch):
54
- atom.chain_id = ch
55
- renamed_atom_ch[idx] = atom
56
- return renamed_atom_ch
57
-
58
-
59
- def remove_hetero(atom_ch):
60
- renamed_atom_ch = AtomArray(len(atom_ch))
61
- for idx, atom in enumerate(atom_ch):
62
- atom.hetero = False
63
- renamed_atom_ch[idx] = atom
64
- return renamed_atom_ch
65
-
66
-
67
- def check_all_hetero(atom_ch):
68
- return sum(atom_ch.hetero) == len(atom_ch)
69
-
70
-
71
- def __get_pdb_structure(pdb_file, assembly_id=None):
72
- return get_pdb_structure(
73
- pdb_file,
74
- model=1
75
- ) if assembly_id is None else get_pdb_assembly(
76
- pdb_file,
77
- assembly_id=assembly_id,
78
- model=1
79
- )
80
-
81
-
82
- def __get_structure(cif_file, assembly_id=None):
83
- return get_structure(
84
- cif_file,
85
- model=1,
86
- use_author_fields=False
87
- ) if assembly_id is None else get_assembly(
88
- cif_file,
89
- assembly_id=assembly_id,
90
- model=1,
91
- use_author_fields=False
92
- )