artios 0.1.0__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.
Files changed (136) hide show
  1. artios/__init__.py +0 -0
  2. artios/assets.py +179 -0
  3. artios/cli.py +535 -0
  4. artios/common/__init__.py +0 -0
  5. artios/common/atom_types.py +349 -0
  6. artios/common/ccd_sets.py +187 -0
  7. artios/common/chain_type.py +42 -0
  8. artios/common/constants.py +960 -0
  9. artios/common/elements.py +163 -0
  10. artios/common/residue_names.py +222 -0
  11. artios/common/residue_stats.py +451 -0
  12. artios/config/__init__.py +14 -0
  13. artios/config/config.py +299 -0
  14. artios/config/extend_types.py +55 -0
  15. artios/configs/__init__.py +0 -0
  16. artios/configs/configs_base.py +322 -0
  17. artios/configs/configs_data.py +262 -0
  18. artios/configs/configs_inference.py +23 -0
  19. artios/contacts/__init__.py +33 -0
  20. artios/contacts/aromatic.py +399 -0
  21. artios/contacts/geometry.py +338 -0
  22. artios/contacts/hydrogen_bonds.py +512 -0
  23. artios/contacts/valence.py +417 -0
  24. artios/data/__init__.py +0 -0
  25. artios/data/array_builder.py +746 -0
  26. artios/data/chem/__init__.py +0 -0
  27. artios/data/chem/ccd.py +513 -0
  28. artios/data/chem/perms.py +257 -0
  29. artios/data/chem/rdkit.py +451 -0
  30. artios/data/collate/__init__.py +0 -0
  31. artios/data/collate/collate.py +107 -0
  32. artios/data/collate/padding.py +75 -0
  33. artios/data/data_pipeline.py +210 -0
  34. artios/data/data_weights.py +526 -0
  35. artios/data/dataloader.py +520 -0
  36. artios/data/dataset.py +901 -0
  37. artios/data/engineering/__init__.py +12 -0
  38. artios/data/engineering/metrics/__init__.py +0 -0
  39. artios/data/engineering/metrics/structural.py +188 -0
  40. artios/data/engineering/pipeline/__init__.py +0 -0
  41. artios/data/engineering/pipeline/thresholds.py +97 -0
  42. artios/data/features/__init__.py +7 -0
  43. artios/data/features/context.py +868 -0
  44. artios/data/features/featurizer.py +823 -0
  45. artios/data/filter.py +763 -0
  46. artios/data/fragment.py +633 -0
  47. artios/data/infer_data_pipeline.py +228 -0
  48. artios/data/motif_maker.py +731 -0
  49. artios/data/msa/__init__.py +6 -0
  50. artios/data/msa/a3m.py +104 -0
  51. artios/data/msa/sampler.py +348 -0
  52. artios/data/parsing/__init__.py +0 -0
  53. artios/data/parsing/_biotite_compat.py +80 -0
  54. artios/data/parsing/bioassembly.py +562 -0
  55. artios/data/parsing/indexing.py +452 -0
  56. artios/data/parsing/json.py +414 -0
  57. artios/data/parsing/mmcif.py +482 -0
  58. artios/data/parsing/motif.py +164 -0
  59. artios/data/parsing/residue_repair.py +565 -0
  60. artios/data/pocket/__init__.py +15 -0
  61. artios/data/pocket/detect.py +322 -0
  62. artios/data/pocket/legacy.py +612 -0
  63. artios/data/pocket/pocket_rf.joblib +0 -0
  64. artios/data/pocket/sphere_rf.joblib +0 -0
  65. artios/data/pocket/tessellation.py +107 -0
  66. artios/data/structure/__init__.py +9 -0
  67. artios/data/structure/annotation.py +1220 -0
  68. artios/data/structure/cropping.py +620 -0
  69. artios/data/structure/id_transforms.py +159 -0
  70. artios/data/structure/structure.py +818 -0
  71. artios/data/structure/tokenization.py +192 -0
  72. artios/data/structure/tokenizer.py +99 -0
  73. artios/data/tokenizer.py +11 -0
  74. artios/data/utils.py +510 -0
  75. artios/electrostatics/__init__.py +31 -0
  76. artios/electrostatics/apbs.py +222 -0
  77. artios/electrostatics/core.py +242 -0
  78. artios/electrostatics/pqr.py +191 -0
  79. artios/electrostatics/surface.py +133 -0
  80. artios/metrics/__init__.py +0 -0
  81. artios/metrics/lddt_metrics.py +161 -0
  82. artios/metrics/rmsd.py +306 -0
  83. artios/model/__init__.py +0 -0
  84. artios/model/artios_backbone.py +373 -0
  85. artios/model/artios_potts.py +655 -0
  86. artios/model/generator.py +1006 -0
  87. artios/model/loss.py +455 -0
  88. artios/model/modules/__init__.py +0 -0
  89. artios/model/modules/components.py +235 -0
  90. artios/model/modules/diffusion_backbone.py +932 -0
  91. artios/model/modules/embedders.py +198 -0
  92. artios/model/modules/layout.py +266 -0
  93. artios/model/modules/message_passing.py +91 -0
  94. artios/model/modules/mpnn.py +349 -0
  95. artios/model/modules/mpnn_features.py +450 -0
  96. artios/model/modules/mpnn_layers.py +302 -0
  97. artios/model/modules/penalty.py +468 -0
  98. artios/model/modules/potts.py +589 -0
  99. artios/model/modules/primitives.py +397 -0
  100. artios/model/modules/transformer.py +576 -0
  101. artios/model/output.py +85 -0
  102. artios/model/utils.py +266 -0
  103. artios/potts/__init__.py +27 -0
  104. artios/potts/designer.py +340 -0
  105. artios/potts/structure.py +526 -0
  106. artios/runner/__init__.py +0 -0
  107. artios/runner/ema.py +88 -0
  108. artios/runner/inference.py +327 -0
  109. artios/runner/train_backbone.py +761 -0
  110. artios/runner/train_potts.py +633 -0
  111. artios/utils/__init__.py +0 -0
  112. artios/utils/casting.py +28 -0
  113. artios/utils/distributed.py +72 -0
  114. artios/utils/dssp.py +221 -0
  115. artios/utils/file_io.py +174 -0
  116. artios/utils/geometry.py +226 -0
  117. artios/utils/inference.py +8 -0
  118. artios/utils/logger.py +84 -0
  119. artios/utils/lr_scheduler.py +169 -0
  120. artios/utils/metrics.py +102 -0
  121. artios/utils/monitoring.py +106 -0
  122. artios/utils/muon.py +291 -0
  123. artios/utils/profiler.py +29 -0
  124. artios/utils/scatter_utils.py +154 -0
  125. artios/utils/seed.py +34 -0
  126. artios/utils/structure_io.py +450 -0
  127. artios/utils/tensor_utils.py +152 -0
  128. artios/utils/training.py +224 -0
  129. artios/utils/typing.py +51 -0
  130. artios-0.1.0.dist-info/METADATA +254 -0
  131. artios-0.1.0.dist-info/RECORD +136 -0
  132. artios-0.1.0.dist-info/WHEEL +5 -0
  133. artios-0.1.0.dist-info/entry_points.txt +2 -0
  134. artios-0.1.0.dist-info/licenses/LICENSE +208 -0
  135. artios-0.1.0.dist-info/licenses/NOTICE +117 -0
  136. artios-0.1.0.dist-info/top_level.txt +1 -0
artios/__init__.py ADDED
File without changes
artios/assets.py ADDED
@@ -0,0 +1,179 @@
1
+ """Pinned release assets hosted on the Hugging Face Hub.
2
+
3
+ Model weights and the Chemical Component Dictionary (CCD) are downloaded from
4
+ immutable Hub revisions and checked against their SHA-256 checksums. Downloads
5
+ are cached by ``huggingface_hub``, so later runs reuse them without network
6
+ access.
7
+ """
8
+
9
+ import functools
10
+ import hashlib
11
+ import logging
12
+ import os
13
+ from dataclasses import dataclass
14
+ from pathlib import Path
15
+
16
+ logger = logging.getLogger(__name__)
17
+
18
+ REPO_ROOT = Path(__file__).resolve().parent.parent
19
+
20
+ # Directory containing components.cif and components.cif.rdkit_mol.pkl.
21
+ CCD_DIR_ENV_VAR = "ARTIOS_CCD_DIR"
22
+
23
+
24
+ @dataclass(frozen=True)
25
+ class HubFile:
26
+ """A file pinned to an immutable Hugging Face Hub revision."""
27
+
28
+ repo_id: str
29
+ filename: str
30
+ revision: str
31
+ sha256: str
32
+ size: int
33
+ repo_type: str = "model"
34
+
35
+
36
+ POTTS_CHECKPOINT = HubFile(
37
+ repo_id="Ligo-Biosciences/ArtiosPotts",
38
+ filename="38400_ema_0.9999.pt",
39
+ revision="c98b78ebcd7691adb915138fed18adea45825439",
40
+ sha256="9c198c105e1d05c7e41d21ec6a898b6833ef5538570ac7afaa78e4e6259a7026",
41
+ size=10_435_129,
42
+ )
43
+
44
+ BACKBONE_CHECKPOINT = HubFile(
45
+ repo_id="Ligo-Biosciences/ArtiosBackbone",
46
+ filename="280000_ema_0.9999.pt",
47
+ revision="3b8939e37aff1544cb74937bad3516673c9914ad",
48
+ sha256="0016f6cffa0a52406f2630d1a82ce1d2ca838f91d3ed923e261c1ce0d4b130fb",
49
+ size=546_762_475,
50
+ )
51
+
52
+ CCD_COMPONENTS = HubFile(
53
+ repo_id="Ligo-Biosciences/Artios-CCD",
54
+ filename="components.cif",
55
+ revision="df1722f8aad777a3a4ec2474bb47fa97bee83f84",
56
+ sha256="fe7c0bf2ca0a51531805f5a5ca7094281ed4d9e9f93b9275d9e6feebe2510892",
57
+ size=427_767_291,
58
+ repo_type="dataset",
59
+ )
60
+
61
+ CCD_RDKIT_MOLS = HubFile(
62
+ repo_id="Ligo-Biosciences/Artios-CCD",
63
+ filename="components.cif.rdkit_mol.pkl",
64
+ revision="df1722f8aad777a3a4ec2474bb47fa97bee83f84",
65
+ sha256="2d6caced2d26c62015115a1d0a50f4106755a300e0c2a2d2b5c101c9038dcbcd",
66
+ size=125_903_802,
67
+ repo_type="dataset",
68
+ )
69
+
70
+
71
+ def sha256sum(path: Path) -> str:
72
+ digest = hashlib.sha256()
73
+ with open(path, "rb") as f:
74
+ for chunk in iter(lambda: f.read(1 << 20), b""):
75
+ digest.update(chunk)
76
+ return digest.hexdigest()
77
+
78
+
79
+ def download(asset: HubFile) -> Path:
80
+ """Return a local path to ``asset``, downloading it if it is not cached.
81
+
82
+ Raises:
83
+ RuntimeError: If the repository cannot be accessed, the file is not
84
+ cached while offline, or the checksum does not match.
85
+ """
86
+ from huggingface_hub import hf_hub_download
87
+ from huggingface_hub.errors import LocalEntryNotFoundError, RepositoryNotFoundError
88
+
89
+ try:
90
+ path = Path(
91
+ hf_hub_download(
92
+ repo_id=asset.repo_id,
93
+ filename=asset.filename,
94
+ revision=asset.revision,
95
+ repo_type=asset.repo_type,
96
+ )
97
+ )
98
+ except RepositoryNotFoundError as e:
99
+ raise RuntimeError(
100
+ f"Could not access {asset.repo_id} on the Hugging Face Hub. If the "
101
+ "repository is private, log in with `hf auth login` or set HF_TOKEN "
102
+ "to a token with read access."
103
+ ) from e
104
+ except LocalEntryNotFoundError as e:
105
+ raise RuntimeError(
106
+ f"{asset.filename} from {asset.repo_id} is not in the local cache and "
107
+ "the Hugging Face Hub could not be reached."
108
+ ) from e
109
+
110
+ actual = sha256sum(path)
111
+ if actual != asset.sha256:
112
+ raise RuntimeError(
113
+ f"Checksum mismatch for {path}: expected {asset.sha256}, got {actual}. "
114
+ "Delete the file and download it again."
115
+ )
116
+ return path
117
+
118
+
119
+ @dataclass(frozen=True)
120
+ class CCDFiles:
121
+ components: Path
122
+ rdkit_mols: Path
123
+
124
+
125
+ @functools.cache
126
+ def resolve_ccd_files() -> CCDFiles:
127
+ """Locate the CCD components file and its matching RDKit molecule cache.
128
+
129
+ Locations are checked in order, and both files always come from the same one:
130
+
131
+ 1. The directory named by the ``ARTIOS_CCD_DIR`` environment variable.
132
+ 2. ``ccd_files/`` at the repository root (source checkouts).
133
+ 3. The pinned Artios-CCD release on the Hugging Face Hub.
134
+ """
135
+ env_dir = os.environ.get(CCD_DIR_ENV_VAR)
136
+ if env_dir:
137
+ files = _local_ccd_files(Path(env_dir))
138
+ if files is None:
139
+ raise FileNotFoundError(
140
+ f"{CCD_DIR_ENV_VAR}={env_dir} does not contain "
141
+ f"{CCD_COMPONENTS.filename} and {CCD_RDKIT_MOLS.filename}."
142
+ )
143
+ return files
144
+
145
+ files = _local_ccd_files(REPO_ROOT / "ccd_files")
146
+ if files is not None:
147
+ return files
148
+
149
+ logger.info(
150
+ f"Using CCD files from {CCD_COMPONENTS.repo_id}@{CCD_COMPONENTS.revision[:8]}"
151
+ )
152
+ return CCDFiles(
153
+ components=download(CCD_COMPONENTS), rdkit_mols=download(CCD_RDKIT_MOLS)
154
+ )
155
+
156
+
157
+ def _local_ccd_files(directory: Path) -> CCDFiles | None:
158
+ files = CCDFiles(
159
+ components=directory / CCD_COMPONENTS.filename,
160
+ rdkit_mols=directory / CCD_RDKIT_MOLS.filename,
161
+ )
162
+ present = [files.components.exists(), files.rdkit_mols.exists()]
163
+ if not any(present):
164
+ return None
165
+ if not all(present):
166
+ raise FileNotFoundError(
167
+ f"{directory} must contain both {CCD_COMPONENTS.filename} and "
168
+ f"{CCD_RDKIT_MOLS.filename} from the same CCD snapshot."
169
+ )
170
+
171
+ sizes = (files.components.stat().st_size, files.rdkit_mols.stat().st_size)
172
+ if sizes != (CCD_COMPONENTS.size, CCD_RDKIT_MOLS.size):
173
+ logger.warning(
174
+ f"CCD files in {directory} differ from the pinned "
175
+ f"{CCD_COMPONENTS.repo_id} release; ligand featurization may not match "
176
+ "published results."
177
+ )
178
+ logger.info(f"Using CCD files from {directory}")
179
+ return files