File size: 1,327 Bytes
504d922
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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))