{"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":"none","dataSources":[{"sourceId":118765,"databundleVersionId":15231210,"sourceType":"competition"},{"sourceId":10855324,"sourceType":"datasetVersion","datasetId":6742586},{"sourceId":290004465,"sourceType":"kernelVersion"}],"dockerImageVersionId":31259,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport random\npd.options.mode.chained_assignment = None","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-02-02T15:25:08.075453Z","iopub.execute_input":"2026-02-02T15:25:08.075772Z","iopub.status.idle":"2026-02-02T15:25:11.588418Z","shell.execute_reply.started":"2026-02-02T15:25:08.075743Z","shell.execute_reply":"2026-02-02T15:25:11.585559Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# install the metric and defined the score() function\n!ls /kaggle/usr/lib/\nimport runpy\nmodule_globals = runpy.run_path(\"/kaggle/usr/lib/tm-score-permutechains/metric.py\")\nscore = module_globals['score']\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-02T15:25:13.513436Z","iopub.execute_input":"2026-02-02T15:25:13.51387Z","iopub.status.idle":"2026-02-02T15:25:13.674902Z","shell.execute_reply.started":"2026-02-02T15:25:13.513831Z","shell.execute_reply":"2026-02-02T15:25:13.673081Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"DATA_PATH = '/kaggle/input/stanford-rna-3d-folding-2/'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-02T15:25:16.166471Z","iopub.execute_input":"2026-02-02T15:25:16.166971Z","iopub.status.idle":"2026-02-02T15:25:16.172383Z","shell.execute_reply.started":"2026-02-02T15:25:16.166917Z","shell.execute_reply":"2026-02-02T15:25:16.171376Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"a_target_id = '5EPI'\nb_target_id = '8RN1'\ntrn_lbl = pd.read_csv(DATA_PATH + 'train_labels.csv')\n\nsol_a = trn_lbl.loc[trn_lbl.ID.str[0:4] == a_target_id, ]\n\nfor el in range(2,41):\n    sol_a['x_'+ str(el)] = -1*(10**18)\n    sol_a['y_'+ str(el)] = -1*(10**18)\n    sol_a['z_'+ str(el)] = -1*(10**18)\n    sol_a['x_'+ str(el)] = sol_a['x_'+ str(el)].astype(np.float64)\n    sol_a['y_'+ str(el)] = sol_a['y_'+ str(el)].astype(np.float64)\n    sol_a['z_'+ str(el)] = sol_a['z_'+ str(el)].astype(np.float64)\nsol_a['Usage'] = 'Public'\nsol_a['chain'] = 'A'\nsol_a['copy'] = 1\n\nsub_b = trn_lbl.loc[trn_lbl.ID.str[0:4] == b_target_id, ]\nx_1 = trn_lbl.loc[trn_lbl.ID.str[0:4] == b_target_id, ]['x_1']\ny_1 = trn_lbl.loc[trn_lbl.ID.str[0:4] == b_target_id, ]['y_1']\nz_1 = trn_lbl.loc[trn_lbl.ID.str[0:4] == b_target_id, ]['z_1']\nfor el in range(2,6):\n    sub_b['x_'+ str(el)] = x_1\n    sub_b['y_'+ str(el)] = y_1\n    sub_b['z_'+ str(el)] = z_1\n    sub_b['x_'+ str(el)] = sub_b['x_'+ str(el)].astype(np.float64)\n    sub_b['y_'+ str(el)] = sub_b['y_'+ str(el)].astype(np.float64)\n    sub_b['z_'+ str(el)] = sub_b['z_'+ str(el)].astype(np.float64)\n\n\nsol = sol_a.copy(deep=True)\nsub = sub_b.copy(deep=True)\nsub['ID'] = sol['ID'].values\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-02T15:25:18.338052Z","iopub.execute_input":"2026-02-02T15:25:18.338518Z","iopub.status.idle":"2026-02-02T15:25:44.483935Z","shell.execute_reply.started":"2026-02-02T15:25:18.338475Z","shell.execute_reply":"2026-02-02T15:25:44.481986Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Run the eval code on each target and get the score, if this is a notebook run using the public test set (whose size matches the solution file, `validation_labels.csv`]\nsol['target_id'] = sol['ID'].apply(lambda x: '_'.join(str(x).split('_')[:-1]))\nsub['target_id'] = sub['ID'].apply(lambda x: '_'.join(str(x).split('_')[:-1]))\n\nif len(sol)==len(sub): # This tests if we're looking at public val\n    results = []\n    for target_id, group_native in sol.groupby('target_id'):\n        group_predicted = sub[sub['target_id'] == target_id]\n        result = score(group_native,group_predicted,'ID')\n        print(target_id,result)\n        results.append( result )\n    print( 'Mean score:',  \n          float(sum(results) / len(results)) if len(results)>0 else 0.0, \n          f'(n={len(results)})' )","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-02-02T15:25:51.251955Z","iopub.execute_input":"2026-02-02T15:25:51.252328Z","iopub.status.idle":"2026-02-02T15:25:51.417107Z","shell.execute_reply.started":"2026-02-02T15:25:51.252289Z","shell.execute_reply":"2026-02-02T15:25:51.415434Z"}},"outputs":[],"execution_count":null}]}