allopockets 1.0.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 (39) hide show
  1. allopockets/__init__.py +78 -0
  2. allopockets/cli.py +372 -0
  3. allopockets/database/__init__.py +24 -0
  4. allopockets/database/allodb.py +342 -0
  5. allopockets/database/cifutils.py +261 -0
  6. allopockets/database/creation.py +654 -0
  7. allopockets/database/siteutils.py +389 -0
  8. allopockets/database/utils.py +765 -0
  9. allopockets/database/viz.py +144 -0
  10. allopockets/features/__init__.py +49 -0
  11. allopockets/features/aa_scales.py +129 -0
  12. allopockets/features/classes.py +740 -0
  13. allopockets/features/embeddings.py +125 -0
  14. allopockets/features/extraction.py +476 -0
  15. allopockets/features/new_pdbs.py +149 -0
  16. allopockets/features/structure_fixing.py +229 -0
  17. allopockets/features/utils.py +111 -0
  18. allopockets/ml/__init__.py +56 -0
  19. allopockets/ml/config.py +255 -0
  20. allopockets/ml/dataset.py +117 -0
  21. allopockets/ml/hub.py +267 -0
  22. allopockets/ml/metrics.py +105 -0
  23. allopockets/ml/models.py +366 -0
  24. allopockets/ml/prepare.py +311 -0
  25. allopockets/ml/train.py +274 -0
  26. allopockets/pockets/__init__.py +27 -0
  27. allopockets/pockets/fpocket.py +97 -0
  28. allopockets/pockets/pocket.py +191 -0
  29. allopockets/predict.py +1553 -0
  30. allopockets/py.typed +0 -0
  31. allopockets/viz/__init__.py +26 -0
  32. allopockets/viz/html_viewer.py +219 -0
  33. allopockets/viz/inspect.py +195 -0
  34. allopockets-1.0.0.dist-info/METADATA +306 -0
  35. allopockets-1.0.0.dist-info/RECORD +39 -0
  36. allopockets-1.0.0.dist-info/WHEEL +5 -0
  37. allopockets-1.0.0.dist-info/entry_points.txt +6 -0
  38. allopockets-1.0.0.dist-info/licenses/LICENSE +674 -0
  39. allopockets-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,78 @@
1
+ """
2
+ AlloPockets - Allosteric Pocket Prediction, Pathway Tracing & 3D Debugging.
3
+
4
+ Original Author: Francho Nerín Fonz <fnerin@bioacademy.gr>
5
+ Refactoring & Packaging: Giuseppe Marco Randazzo <gmrandazzo@gmail.com>
6
+ License: GNU General Public License v3.0 (GPL-3.0)
7
+
8
+ This program is free software: you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation, either version 3 of the License, or
11
+ (at your option) any later version.
12
+
13
+ This program is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
20
+
21
+ AlloPockets: Allosteric Pocket Prediction, Pathway Tracing, and 3D Visualization.
22
+ """
23
+
24
+ __version__ = "1.0.0"
25
+
26
+ from allopockets.pockets import Pocket, run_fpocket, get_pockets_info
27
+ from allopockets.ml import (
28
+ PocketClassifier,
29
+ prepare_dataset,
30
+ train_pipeline,
31
+ load_model,
32
+ download_model,
33
+ get_cache_dir,
34
+ list_available_models,
35
+ )
36
+ from allopockets.viz import inspect_pocket_cli, generate_3d_pocket_html
37
+ from allopockets.predict import (
38
+ get_cif,
39
+ get_clean_pdb,
40
+ get_pockets,
41
+ get_pocket,
42
+ get_features,
43
+ get_pockets_features,
44
+ predict,
45
+ get_pathways,
46
+ view_pdb,
47
+ view_pockets,
48
+ view_pockets_pathways,
49
+ Site,
50
+ )
51
+
52
+ __all__ = [
53
+ "__version__",
54
+ "get_cif",
55
+ "get_clean_pdb",
56
+ "get_pockets",
57
+ "get_pocket",
58
+ "get_features",
59
+ "get_pockets_features",
60
+ "predict",
61
+ "get_pathways",
62
+ "view_pdb",
63
+ "view_pockets",
64
+ "view_pockets_pathways",
65
+ "Site",
66
+ "Pocket",
67
+ "run_fpocket",
68
+ "get_pockets_info",
69
+ "PocketClassifier",
70
+ "prepare_dataset",
71
+ "train_pipeline",
72
+ "inspect_pocket_cli",
73
+ "generate_3d_pocket_html",
74
+ "load_model",
75
+ "download_model",
76
+ "get_cache_dir",
77
+ "list_available_models",
78
+ ]
allopockets/cli.py ADDED
@@ -0,0 +1,372 @@
1
+ """
2
+ AlloPockets - Allosteric Pocket Prediction, Pathway Tracing & 3D Debugging.
3
+
4
+ Author: Giuseppe Marco Randazzo <gmrandazzo@gmail.com>
5
+ License: GNU General Public License v3.0 (GPL-3.0)
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+
20
+ Command Line Interface (CLI) binaries and entrypoints for AlloPockets.
21
+ """
22
+
23
+ from typing import Optional
24
+ import click
25
+
26
+
27
+ @click.group()
28
+ @click.version_option(version="1.0.0", prog_name="allopockets")
29
+ def main():
30
+ """AlloPockets: Allosteric Pocket Prediction, Pathway Tracing & 3D Debugging."""
31
+ pass
32
+
33
+
34
+ @click.command("predict")
35
+ @click.option(
36
+ "--pdb",
37
+ "pdb_input",
38
+ required=True,
39
+ help="PDB ID (e.g. 6t4k) or path to structure file (.cif/.pdb)",
40
+ )
41
+ @click.option("--chains", default=None, help="Comma-separated protein chains (e.g. 'A,B')")
42
+ @click.option("--email", default=None, help="Email for ColabFold MSA server")
43
+ @click.option(
44
+ "--uniref-path", default=None, help="Path to local UniRef30 database for offline HHBlits"
45
+ )
46
+ @click.option("--outdir", default="predict", help="Output directory (default: ./predict)")
47
+ @click.option("--model-path", default=None, help="Path to custom model directory")
48
+ @click.option(
49
+ "--model",
50
+ "model_name",
51
+ default="minimal_lgbm",
52
+ type=click.Choice(["minimal_lgbm", "minimal_xgboost"]),
53
+ help="Pretrained model name to use if --model-path is not set (default: minimal_lgbm)",
54
+ )
55
+ def predict_cli(pdb_input, chains, email, uniref_path, outdir, model_path, model_name):
56
+ """Run allosteric pocket prediction on a protein structure."""
57
+ from allopockets.predict import run_prediction_cli
58
+
59
+ run_prediction_cli(
60
+ pdb_input=pdb_input,
61
+ chains=chains,
62
+ email=email,
63
+ uniref_path=uniref_path,
64
+ outdir=outdir,
65
+ model_path=model_path,
66
+ model_name=model_name,
67
+ )
68
+
69
+
70
+ @click.command("prepare-data")
71
+ @click.option(
72
+ "--db",
73
+ "db_path",
74
+ default="data/database.db",
75
+ help="Path to database.db (default: data/database.db)",
76
+ )
77
+ @click.option(
78
+ "--outdir", default="data", help="Output directory for generated dataset (default: ./data)"
79
+ )
80
+ @click.option("--limit", default=None, type=int, help="Limit number of PDBs for quick testing")
81
+ @click.option(
82
+ "--pdb-file",
83
+ default=None,
84
+ help="Path to CSV or text file containing PDB IDs to extract",
85
+ )
86
+ @click.option(
87
+ "--threshold",
88
+ default=0.65,
89
+ type=float,
90
+ help="Overlap threshold for positive allosteric pockets (default: 0.65)",
91
+ )
92
+ @click.option(
93
+ "--workers",
94
+ default=6,
95
+ type=int,
96
+ help="Number of parallel extraction workers (default: 6)",
97
+ )
98
+ @click.option(
99
+ "--filename",
100
+ "output_filename",
101
+ default="pockets_dataset.parquet",
102
+ help="Output dataset filename (default: pockets_dataset.parquet)",
103
+ )
104
+ @click.option(
105
+ "--minimal-chains/--all-chains",
106
+ default=True,
107
+ help="Restrict cavity detection to minimal interacting protein chains (default: True)",
108
+ )
109
+ @click.option(
110
+ "--outlier-filter/--no-outlier-filter",
111
+ default=False,
112
+ help="Apply author nres outlier filter (|z| < 3) (default: False)",
113
+ )
114
+ def prepare_data_cli(
115
+ db_path,
116
+ outdir,
117
+ limit,
118
+ pdb_file,
119
+ threshold,
120
+ workers,
121
+ output_filename,
122
+ minimal_chains,
123
+ outlier_filter,
124
+ ):
125
+ """Extract and featurize pocket dataset directly from database.db."""
126
+ from allopockets.ml.prepare import prepare_dataset
127
+
128
+ prepare_dataset(
129
+ db_path=db_path,
130
+ output_dir=outdir,
131
+ limit=limit,
132
+ pdb_file=pdb_file,
133
+ label_threshold=threshold,
134
+ workers=workers,
135
+ output_filename=output_filename,
136
+ use_minimal_chains=minimal_chains,
137
+ outlier_filter=outlier_filter,
138
+ )
139
+
140
+
141
+ @click.command("train")
142
+ @click.option(
143
+ "--data", "data_path", required=True, help="Path to prepared dataset (.parquet, .pkl, or .csv)"
144
+ )
145
+ @click.option(
146
+ "--model",
147
+ "model_type",
148
+ default="hist_gradient_boost",
149
+ type=click.Choice(["hist_gradient_boost", "lightgbm", "xgboost", "autogluon"]),
150
+ help="Model architecture: hist_gradient_boost, lightgbm, xgboost, or autogluon",
151
+ )
152
+ @click.option("--seed", default=42, type=int, help="Random seed for reproducibility (default: 42)")
153
+ @click.option(
154
+ "--splits",
155
+ "--n-splits",
156
+ "splits",
157
+ default=5,
158
+ type=int,
159
+ help="Number of CV splits (default: 5)",
160
+ )
161
+ @click.option("--lr", default=0.03, type=float, help="Learning rate (default: 0.03)")
162
+ @click.option(
163
+ "--n-estimators", default=300, type=int, help="Number of boosting trees (default: 300)"
164
+ )
165
+ @click.option("--max-depth", default=6, type=int, help="Maximum tree depth (default: 6)")
166
+ @click.option(
167
+ "--subsample",
168
+ default=0.8,
169
+ type=float,
170
+ help="Row subsampling ratio per tree (default: 0.8)",
171
+ )
172
+ @click.option(
173
+ "--colsample",
174
+ "--colsample-bytree",
175
+ "colsample",
176
+ default=0.8,
177
+ type=float,
178
+ help="Feature subsampling ratio per tree (default: 0.8)",
179
+ )
180
+ @click.option(
181
+ "--reg-lambda",
182
+ default=1.0,
183
+ type=float,
184
+ help="L2 regularization strength (default: 1.0)",
185
+ )
186
+ @click.option(
187
+ "--time-limit",
188
+ default=None,
189
+ type=int,
190
+ help="Time limit in seconds per fit for AutoML backends (e.g. autogluon)",
191
+ )
192
+ @click.option(
193
+ "--outdir", default="models/lgbm_pocket_classifier", help="Directory to save trained model"
194
+ )
195
+ @click.option(
196
+ "--test-data",
197
+ "test_data_path",
198
+ default=None,
199
+ help="Path to independent held-out test dataset (.parquet, .pkl, or .csv)",
200
+ )
201
+ def train_cli(
202
+ data_path,
203
+ model_type,
204
+ seed,
205
+ splits,
206
+ lr,
207
+ n_estimators,
208
+ max_depth,
209
+ subsample,
210
+ colsample,
211
+ reg_lambda,
212
+ time_limit,
213
+ outdir,
214
+ test_data_path,
215
+ ):
216
+ """Train reproducible Gradient Boost pocket classifier with Grouped Stratified CV."""
217
+ from allopockets.ml.train import train_pipeline
218
+
219
+ try:
220
+ train_pipeline(
221
+ data_path=data_path,
222
+ model_type=model_type,
223
+ seed=seed,
224
+ n_splits=splits,
225
+ output_dir=outdir,
226
+ learning_rate=lr,
227
+ n_estimators=n_estimators,
228
+ max_depth=max_depth,
229
+ subsample=subsample,
230
+ colsample=colsample,
231
+ reg_lambda=reg_lambda,
232
+ time_limit=time_limit,
233
+ test_data_path=test_data_path,
234
+ )
235
+ except ImportError as e:
236
+ raise click.ClickException(str(e))
237
+
238
+
239
+ @click.command("inspect-3d")
240
+ @click.option("--pdb", "pdb_id", required=True, help="PDB ID (e.g. 6t4k)")
241
+ @click.option("--pocket", "pocket_id", required=True, help="Pocket ID (e.g. pocket1)")
242
+ @click.option(
243
+ "--path", default="predict", help="Path to prediction/fpocket workspace (default: ./predict)"
244
+ )
245
+ @click.option(
246
+ "--db",
247
+ "db_path",
248
+ default="data/database.db",
249
+ help="Path to database.db (default: data/database.db)",
250
+ )
251
+ @click.option("--html", default=None, help="Output path for standalone interactive 3D HTML viewer")
252
+ @click.option("--open-browser", is_flag=True, help="Open viewer in default browser automatically")
253
+ def inspect_3d_cli(pdb_id, pocket_id, path, db_path, html, open_browser):
254
+ """Inspect and debug 3D pocket coordinates, alpha spheres, and ground truth alignment."""
255
+ from allopockets.viz.inspect import inspect_pocket_cli
256
+
257
+ inspect_pocket_cli(
258
+ pdb_id=pdb_id,
259
+ pocket_id=pocket_id,
260
+ path=path,
261
+ db_path=db_path,
262
+ html_output=html,
263
+ open_browser=open_browser,
264
+ )
265
+
266
+
267
+ @click.command("download-model")
268
+ @click.option(
269
+ "--model",
270
+ "model_name",
271
+ default="minimal_lgbm",
272
+ type=click.Choice(["minimal_lgbm", "minimal_xgboost"]),
273
+ help="Model name to download (default: minimal_lgbm)",
274
+ )
275
+ @click.option("--force", is_flag=True, help="Force re-download even if already cached")
276
+ def download_model_cli(model_name: str, force: bool):
277
+ """Download pretrained model weights into local user cache."""
278
+ from allopockets.ml.hub import download_model
279
+
280
+ click.echo(f"Downloading model '{model_name}'...")
281
+ path = download_model(model_name=model_name, force=force)
282
+ click.echo(f"Model '{model_name}' ready at: {path}")
283
+
284
+
285
+ @click.group("models")
286
+ def models_cli():
287
+ """Manage pretrained AlloPockets model weights and cache."""
288
+ pass
289
+
290
+
291
+ @models_cli.command("list")
292
+ def models_list_cli():
293
+ """List available pretrained models and local cache status."""
294
+ from allopockets.ml.hub import list_available_models
295
+
296
+ models = list_available_models()
297
+ click.echo("\nAvailable Pretrained Models:")
298
+ click.echo("=" * 60)
299
+ for name, meta in models.items():
300
+ status = "CACHED" if meta["cached"] else "NOT CACHED"
301
+ default_flag = " (DEFAULT)" if meta["default"] else ""
302
+ click.echo(f"• {name}{default_flag} [{status}] ({meta['size_kb']} KB)")
303
+ click.echo(f" Description: {meta['description']}")
304
+ if meta["local_path"]:
305
+ click.echo(f" Path: {meta['local_path']}")
306
+ click.echo("-" * 60)
307
+
308
+
309
+ @models_cli.command("download")
310
+ @click.option(
311
+ "--model",
312
+ "model_name",
313
+ default="minimal_lgbm",
314
+ type=click.Choice(["minimal_lgbm", "minimal_xgboost"]),
315
+ help="Model name to download (default: minimal_lgbm)",
316
+ )
317
+ @click.option("--force", is_flag=True, help="Force re-download even if already cached")
318
+ def models_download_cli(model_name: str, force: bool):
319
+ """Download pretrained model weights into local user cache."""
320
+ from allopockets.ml.hub import download_model
321
+
322
+ click.echo(f"Downloading model '{model_name}'...")
323
+ path = download_model(model_name=model_name, force=force)
324
+ click.echo(f"Model '{model_name}' ready at: {path}")
325
+
326
+
327
+ @models_cli.command("path")
328
+ @click.option(
329
+ "--model",
330
+ "model_name",
331
+ default="minimal_lgbm",
332
+ type=click.Choice(["minimal_lgbm", "minimal_xgboost"]),
333
+ help="Model name to locate (default: minimal_lgbm)",
334
+ )
335
+ def models_path_cli(model_name: str):
336
+ """Print the local filesystem directory path for a model."""
337
+ from allopockets.ml.hub import get_model_dir
338
+
339
+ try:
340
+ path = get_model_dir(model_name=model_name, auto_download=False)
341
+ click.echo(str(path))
342
+ except FileNotFoundError as e:
343
+ raise click.ClickException(str(e))
344
+
345
+
346
+ @models_cli.command("clean")
347
+ @click.option(
348
+ "--model",
349
+ "model_name",
350
+ default=None,
351
+ type=click.Choice(["minimal_lgbm", "minimal_xgboost"]),
352
+ help="Specific model to remove from cache (default: all)",
353
+ )
354
+ def models_clean_cli(model_name: Optional[str]):
355
+ """Remove cached model weights from local user cache."""
356
+ from allopockets.ml.hub import clear_cache
357
+
358
+ clear_cache(model_name=model_name)
359
+ target = f"model '{model_name}'" if model_name else "all models"
360
+ click.echo(f"Cleared cache for {target}.")
361
+
362
+
363
+ # Attach subcommands to main group
364
+ main.add_command(predict_cli, name="predict")
365
+ main.add_command(prepare_data_cli, name="prepare-data")
366
+ main.add_command(train_cli, name="train")
367
+ main.add_command(inspect_3d_cli, name="inspect-3d")
368
+ main.add_command(download_model_cli, name="download-model")
369
+ main.add_command(models_cli, name="models")
370
+
371
+ if __name__ == "__main__":
372
+ main()
@@ -0,0 +1,24 @@
1
+ """
2
+ AlloPockets - Allosteric Pocket Prediction, Pathway Tracing & 3D Debugging.
3
+
4
+ Original Author: Francho Nerín Fonz <fnerin@bioacademy.gr>
5
+ Refactoring & Packaging: Giuseppe Marco Randazzo <gmrandazzo@gmail.com>
6
+ License: GNU General Public License v3.0 (GPL-3.0)
7
+
8
+ This program is free software: you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation, either version 3 of the License, or
11
+ (at your option) any later version.
12
+
13
+ This program is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
20
+ """
21
+
22
+ from .allodb import db, PDB, Site, Orthosite
23
+
24
+ tables = [PDB, Site, Orthosite]