{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":118765,"databundleVersionId":15231210,"sourceType":"competition"}],"dockerImageVersionId":31260,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport torch\nfrom tqdm import tqdm","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-02-05T04:28:28.790157Z","iopub.execute_input":"2026-02-05T04:28:28.790437Z","iopub.status.idle":"2026-02-05T04:28:32.407891Z","shell.execute_reply.started":"2026-02-05T04:28:28.790406Z","shell.execute_reply":"2026-02-05T04:28:32.407328Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df = pd.read_csv(\"/kaggle/input/stanford-rna-3d-folding-2/test_sequences.csv\")\ntest_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-05T04:28:35.769649Z","iopub.execute_input":"2026-02-05T04:28:35.770087Z","iopub.status.idle":"2026-02-05T04:28:35.804943Z","shell.execute_reply.started":"2026-02-05T04:28:35.770059Z","shell.execute_reply":"2026-02-05T04:28:35.804344Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-05T04:28:39.71607Z","iopub.execute_input":"2026-02-05T04:28:39.716853Z","iopub.status.idle":"2026-02-05T04:28:39.721406Z","shell.execute_reply.started":"2026-02-05T04:28:39.716823Z","shell.execute_reply":"2026-02-05T04:28:39.720657Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"base_to_vec = {\n    \"A\": np.array([1.0, 0.0, 0.0]),\n    \"U\": np.array([-1.0, 0.0, 0.0]),\n    \"G\": np.array([0.0, 1.0, 0.0]),\n    \"C\": np.array([0.0, -1.0, 0.0]),\n}","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-05T04:28:42.568769Z","iopub.execute_input":"2026-02-05T04:28:42.569093Z","iopub.status.idle":"2026-02-05T04:28:42.573334Z","shell.execute_reply.started":"2026-02-05T04:28:42.569066Z","shell.execute_reply":"2026-02-05T04:28:42.572602Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def generate_structure(sequence, seed=0, noise=0.5):\n    np.random.seed(seed)\n    coords = []\n    pos = np.zeros(3)\n\n    for base in sequence:\n        direction = base_to_vec[base]\n        step = direction + np.random.normal(0, noise, 3)\n        pos = pos + step\n        coords.append(pos.copy())\n\n    return np.array(coords)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-05T04:28:46.052407Z","iopub.execute_input":"2026-02-05T04:28:46.053002Z","iopub.status.idle":"2026-02-05T04:28:46.057357Z","shell.execute_reply.started":"2026-02-05T04:28:46.052976Z","shell.execute_reply":"2026-02-05T04:28:46.056707Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"all_rows = []\n\nfor _, row in tqdm(test_df.iterrows(), total=len(test_df)):\n    seq_id = row[\"target_id\"]      # ✅ FIX HERE\n    sequence = row[\"sequence\"]\n\n    for model_i in range(1, 6):\n        coords = generate_structure(sequence, seed=model_i * 17)\n\n        for resid, (x, y, z) in enumerate(coords, start=1):\n            all_rows.append({\n                \"ID\": seq_id,      # submission still expects column name \"ID\"\n                \"resname\": sequence[resid-1],\n                \"resid\": resid,\n                f\"x_{model_i}\": x,\n                f\"y_{model_i}\": y,\n                f\"z_{model_i}\": z\n            })","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-05T04:28:49.301609Z","iopub.execute_input":"2026-02-05T04:28:49.302338Z","iopub.status.idle":"2026-02-05T04:28:49.599949Z","shell.execute_reply.started":"2026-02-05T04:28:49.302309Z","shell.execute_reply":"2026-02-05T04:28:49.599326Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission = pd.DataFrame(all_rows)\n\nsubmission = submission.groupby(\n    [\"ID\", \"resname\", \"resid\"], as_index=False\n).first()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-05T04:28:53.272775Z","iopub.execute_input":"2026-02-05T04:28:53.273347Z","iopub.status.idle":"2026-02-05T04:28:53.396136Z","shell.execute_reply.started":"2026-02-05T04:28:53.273317Z","shell.execute_reply":"2026-02-05T04:28:53.395316Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-05T04:28:55.988783Z","iopub.execute_input":"2026-02-05T04:28:55.989669Z","iopub.status.idle":"2026-02-05T04:28:56.00516Z","shell.execute_reply.started":"2026-02-05T04:28:55.989639Z","shell.execute_reply":"2026-02-05T04:28:56.004477Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(submission.shape)\nsubmission.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-05T04:28:59.208049Z","iopub.execute_input":"2026-02-05T04:28:59.208352Z","iopub.status.idle":"2026-02-05T04:28:59.214057Z","shell.execute_reply.started":"2026-02-05T04:28:59.208328Z","shell.execute_reply":"2026-02-05T04:28:59.213356Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission.to_csv(\"/kaggle/working/submission.csv\", index=False)\n\nprint(\"Saved . Files now:\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-05T04:29:01.942737Z","iopub.execute_input":"2026-02-05T04:29:01.943062Z","iopub.status.idle":"2026-02-05T04:29:02.163359Z","shell.execute_reply.started":"2026-02-05T04:29:01.943035Z","shell.execute_reply":"2026-02-05T04:29:02.162717Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}