{"cells":[{"metadata":{},"cell_type":"markdown","source":"# To rdkit molecule and back!\n\nI have an idea, that it is possible to predict molecule graph and then convert it to rdkit molecule and then create inchi.\n\nLet's covert inchi to rdkit molecule and turn it back into inchi."},{"metadata":{"trusted":true},"cell_type":"code","source":"!conda install -y rdkit","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import pandas as pd\nfrom rdkit.Chem import inchi","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df = pd.read_csv(\"/kaggle/input/bms-molecular-translation/train_labels.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df[\"InChI\"].head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df[\"InChI\"].head()[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"mol = inchi.MolFromInchi(df[\"InChI\"].head()[0])\nmol","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"inchi.MolToInchi(mol)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"inchi.MolToInchi(mol) == df[\"InChI\"].head()[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"for inch in df[\"InChI\"]:\n    rdkit_inchi = inchi.MolToInchi(inchi.MolFromInchi(inch))\n    assert rdkit_inchi == inch, f\"gt inchi '{inch}' != rdkit_inchi '{rdkit_inchi}'\"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"So, as it seems, this approach might lead to some errors.\n\nStill, this approach might be useful to export molecule graph via rdkit to inchi."}],"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":4,"nbformat_minor":4}