Download libs/adaptive/state.py from QPromaQ/Docking_project: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/datasets/QPromaQ/Docking_project/resolve/main/libs/adaptive/state.py
- Command line
-
hf download hf://datasets/QPromaQ/Docking_project/libs/adaptive/state.py
-
curl -L -o state.py https://huggingface.co/datasets/QPromaQ/Docking_project/resolve/main/libs/adaptive/state.py
1.55 kB
| from __future__ import annotations | |
| from dataclasses import asdict, dataclass, field | |
| from pathlib import Path | |
| from typing import Any, Dict, List | |
| import json | |
| class QueueItem: | |
| ligand_id: str | |
| status: str = "active" | |
| priority: float = 0.0 | |
| hypercluster_id: int = -1 | |
| cluster_id: int = -1 | |
| times_selected: int = 0 | |
| last_score: float | None = None | |
| class SchedulerState: | |
| queue: List[QueueItem] = field(default_factory=list) | |
| batch_history: List[Dict[str, Any]] = field(default_factory=list) | |
| round_idx: int = 0 | |
| def to_dict(self) -> Dict[str, Any]: | |
| return { | |
| "queue": [asdict(item) for item in self.queue], | |
| "batch_history": self.batch_history, | |
| "round_idx": self.round_idx, | |
| } | |
| def from_dict(cls, payload: Dict[str, Any]) -> "SchedulerState": | |
| queue = [QueueItem(**item) for item in payload.get("queue", [])] | |
| return cls(queue=queue, batch_history=payload.get("batch_history", []), round_idx=int(payload.get("round_idx", 0))) | |
| def save(self, path: str | Path) -> Path: | |
| target = Path(path) | |
| target.parent.mkdir(parents=True, exist_ok=True) | |
| with target.open("w", encoding="utf-8") as handle: | |
| json.dump(self.to_dict(), handle, indent=2) | |
| return target | |
| def load(cls, path: str | Path) -> "SchedulerState": | |
| source = Path(path) | |
| with source.open("r", encoding="utf-8") as handle: | |
| return cls.from_dict(json.load(handle)) | |