{"cells":[{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":"import os\nimport sys\nimport subprocess\n\nprint(\"=\" * 60)\nprint(\"STEP 0: Discovering input file structure...\")\nprint(\"=\" * 60)\n\n# Auto-discover all inputs\nrnapro_dir = None\ncheckpoint_path = None\ntemplate_path = None\nwheels_dir = None\nccd_files = []\n\nfor root, dirs, files in os.walk('/kaggle/input'):\n    depth = root.replace('/kaggle/input', '').count(os.sep)\n    if depth > 3:\n        continue\n    indent = '  ' * depth\n    print(f\"{indent}{os.path.basename(root)}/\")\n    for f in files:\n        subindent = '  ' * (depth + 1)\n        print(f\"{subindent}{f}\")\n        fpath = os.path.join(root, f)\n        # Auto-detect key files\n        if f == 'rnapro-private-best-500m.ckpt':\n            checkpoint_path = fpath\n        elif f == 'templates.pt':\n            template_path = fpath\n        elif f.endswith('.cif') or f.endswith('.cif.rdkit_mol.pkl'):\n            ccd_files.append(fpath)\n\n    # Detect RNAPro directory (has rnapro_inference_kaggle.sh inside)\n    if 'rnapro_inference_kaggle.sh' in files:\n        rnapro_dir = root\n    # Detect wheels directory\n    if root.endswith('/wheels') and any(f.endswith('.whl') for f in files):\n        wheels_dir = root\n\nprint()\nprint(\"=\" * 60)\nprint(\"AUTO-DETECTED PATHS:\")\nprint(f\"  RNAPro dir: {rnapro_dir}\")\nprint(f\"  Checkpoint: {checkpoint_path}\")\nprint(f\"  Templates:  {template_path}\")\nprint(f\"  Wheels:     {wheels_dir}\")\nprint(f\"  CCD files:  {ccd_files}\")\nprint(\"=\" * 60)\n\n# Validate required paths\nif not rnapro_dir:\n    raise RuntimeError(\"Could not find RNAPro directory (missing rnapro_inference_kaggle.sh)\")\nif not checkpoint_path:\n    raise RuntimeError(\"Could not find checkpoint file rnapro-private-best-500m.ckpt\")\n\n# Setup environment\nos.environ[\"DUMP_DIR\"] = \"../output\"\nos.environ[\"CHECKPOINT_PATH\"] = checkpoint_path\nos.environ[\"USE_TEMPLATE\"] = \"True\"\nos.environ[\"USE_MSA\"] = \"False\"\nif template_path:\n    os.environ[\"TEMPLATE_DATA\"] = template_path\n\nprint()\nprint(\"STEP 1: Copy RNAPro repo...\")\n# Copy the RNAPro directory to working\nret = subprocess.run([\"cp\", \"-r\", rnapro_dir, \"/kaggle/working/RNAPro\"], capture_output=True, text=True)\nif ret.returncode != 0:\n    print(f\"cp RNAPro error: {ret.stderr}\")\nelse:\n    print(\"RNAPro copied successfully.\")\n\n# Setup CCD cache\nDIST = \"/kaggle/working/RNAPro/release_data/ccd_cache/\"\nos.makedirs(DIST, exist_ok=True)\nfor ccd_file in ccd_files:\n    ret = subprocess.run([\"cp\", ccd_file, DIST], capture_output=True, text=True)\n    if ret.returncode != 0:\n        print(f\"cp CCD error ({ccd_file}): {ret.stderr}\")\n    else:\n        print(f\"Copied CCD file: {os.path.basename(ccd_file)}\")\n\nprint()\nprint(\"STEP 2: Install dependencies...\")\nos.chdir(\"/kaggle/working/RNAPro\")\nif wheels_dir:\n    ret = subprocess.run(\n        [\"pip\", \"install\", \"-r\", \"requirements.txt\", \"--no-index\", f\"--find-links={wheels_dir}\"],\n        capture_output=True, text=True\n    )\n    print(ret.stdout[-500:] if ret.stdout else \"\")\n    if ret.returncode != 0:\n        print(f\"pip install error: {ret.stderr[-500:]}\")\nelse:\n    print(\"No wheels dir found, installing from PyPI...\")\n    ret = subprocess.run([\"pip\", \"install\", \"-r\", \"requirements.txt\"], capture_output=True, text=True)\n    print(ret.stdout[-300:])\n\nret = subprocess.run([\"pip\", \"install\", \"-e\", \".\", \"--no-deps\"], capture_output=True, text=True)\nif ret.returncode == 0:\n    print(\"Package installed successfully!\")\nelse:\n    print(f\"Install error: {ret.stderr[-300:]}\")\n\nprint()\nprint(\"STEP 3: Preprocessing CCD cache...\")\nret = subprocess.run(\n    [\"python\", \"preprocess/gen_ccd_cache.py\", \"-c\", DIST],\n    capture_output=True, text=True\n)\nprint(ret.stdout[-300:] if ret.stdout else \"\")\nif ret.returncode != 0:\n    print(f\"CCD cache error: {ret.stderr[-300:]}\")\n\nprint()\nprint(\"STEP 4: Running inference...\")\nret = subprocess.run([\"bash\", \"./rnapro_inference_kaggle.sh\"], capture_output=True, text=True)\nprint(ret.stdout[-500:] if ret.stdout else \"\")\nif ret.returncode != 0:\n    print(f\"Inference error: {ret.stderr[-500:]}\")\n\nprint()\nprint(\"STEP 5: Checking output...\")\noutput_dir = \"/kaggle/working/\"\nfor f in os.listdir(output_dir):\n    print(f\"  {f}\")\n"}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.10.0"}},"nbformat":4,"nbformat_minor":5}