| from __future__ import annotations |
|
|
| import json |
| from pathlib import Path |
| import sys |
|
|
| ROOT_DIR = Path(__file__).resolve().parents[1] |
| if str(ROOT_DIR) not in sys.path: |
| sys.path.insert(0, str(ROOT_DIR)) |
|
|
| import requests |
|
|
|
|
| def build_demo_dataset() -> dict: |
| """Attempt to fetch real target structure; fallback to bundled offline demo assets.""" |
| root = Path(__file__).resolve().parents[1] |
| target_path = root / "data/targets/mdm2_1ycr_excerpt.pdb" |
| metadata_path = root / "data/benchmarks/mdm2_demo_metadata.json" |
|
|
| fetched = False |
| url = "https://files.rcsb.org/download/1YCR.pdb" |
| try: |
| response = requests.get(url, timeout=15) |
| if response.status_code == 200 and "ATOM" in response.text: |
| target_path.write_text(response.text, encoding="utf-8") |
| fetched = True |
| except Exception: |
| fetched = False |
|
|
| metadata = json.loads(metadata_path.read_text(encoding="utf-8")) |
| metadata["target"]["download_attempted"] = True |
| metadata["target"]["download_succeeded"] = fetched |
| metadata["target"]["download_url"] = url |
| metadata_path.write_text(json.dumps(metadata, indent=2), encoding="utf-8") |
| return {"target_path": str(target_path), "download_succeeded": fetched} |
|
|
|
|
| if __name__ == "__main__": |
| print(json.dumps(build_demo_dataset(), indent=2)) |
|
|