{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!conda install openbabel -c openbabel -y","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-10-11T01:12:32.331193Z","iopub.execute_input":"2021-10-11T01:12:32.33164Z","iopub.status.idle":"2021-10-11T01:16:14.947443Z","shell.execute_reply.started":"2021-10-11T01:12:32.331565Z","shell.execute_reply":"2021-10-11T01:16:14.946416Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os","metadata":{"execution":{"iopub.status.busy":"2021-10-11T01:16:14.952667Z","iopub.execute_input":"2021-10-11T01:16:14.95294Z","iopub.status.idle":"2021-10-11T01:16:14.958616Z","shell.execute_reply.started":"2021-10-11T01:16:14.952888Z","shell.execute_reply":"2021-10-11T01:16:14.957773Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2021-10-11T01:16:14.959919Z","iopub.execute_input":"2021-10-11T01:16:14.960494Z","iopub.status.idle":"2021-10-11T01:16:14.996083Z","shell.execute_reply.started":"2021-10-11T01:16:14.960444Z","shell.execute_reply":"2021-10-11T01:16:14.995376Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pybel","metadata":{"execution":{"iopub.status.busy":"2021-10-11T01:21:23.033516Z","iopub.execute_input":"2021-10-11T01:21:23.033846Z","iopub.status.idle":"2021-10-11T01:21:23.037674Z","shell.execute_reply.started":"2021-10-11T01:21:23.033789Z","shell.execute_reply":"2021-10-11T01:21:23.036774Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def cif_to_smiles(fname):\n    mol = next(pybel.readfile(\"cif\", fname))\n\n    smi = mol.write(format=\"mol2\")\n\n    return smi.split()[0].strip()","metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","execution":{"iopub.status.busy":"2021-10-11T01:16:28.990564Z","iopub.status.idle":"2021-10-11T01:16:28.99096Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"path=\"../input/mof-cif-zip/mof_cif_train/mof_cif_train/\"","metadata":{"execution":{"iopub.status.busy":"2021-10-11T01:16:28.99217Z","iopub.status.idle":"2021-10-11T01:16:28.992941Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"files_name=[]\nfor (root,dirs,files) in os.walk(path, topdown=True):\n  files_name.extend(files)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T01:16:28.994247Z","iopub.status.idle":"2021-10-11T01:16:28.994989Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train=pd.DataFrame(data={\"name\":files_name})","metadata":{"execution":{"iopub.status.busy":"2021-10-11T01:16:28.996362Z","iopub.status.idle":"2021-10-11T01:16:28.997089Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def add_path(fp):\n    return \"../input/mof-cif-zip/mof_cif_train/mof_cif_train/\"+fp","metadata":{"execution":{"iopub.status.busy":"2021-10-11T01:16:28.999105Z","iopub.status.idle":"2021-10-11T01:16:28.999753Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(train)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T01:16:29.001009Z","iopub.status.idle":"2021-10-11T01:16:29.001704Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"path\"]=train[[\"name\"]].apply(add_path)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T01:16:29.002968Z","iopub.status.idle":"2021-10-11T01:16:29.003659Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[\"smiles\"]=\"\"\nfor i in range(len(train)):\n    train[\"smiles\"][i]=cif_to_smiles(train[\"path\"][i])\n    if i%1000==0:\n        print(i)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T01:16:29.004967Z","iopub.status.idle":"2021-10-11T01:16:29.005681Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[train[\"smiles\"]!=\"\"]","metadata":{"execution":{"iopub.status.busy":"2021-10-11T01:16:29.006883Z","iopub.status.idle":"2021-10-11T01:16:29.007564Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[train[\"smiles\"]!=\"\"].to_csv(\"smiles_train2.csv\")","metadata":{"execution":{"iopub.status.busy":"2021-10-11T01:16:29.008833Z","iopub.status.idle":"2021-10-11T01:16:29.00959Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}