{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"markdown","source":"# Visualize molecule structure\n\nThe plots are interactive, you can rotate, zoom in/out, etc."},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nimport plotly.offline as py\nimport plotly.graph_objs as go\n\nfrom plotly import tools\n\ncolor = sns.color_palette()\n%matplotlib inline\npy.init_notebook_mode(connected=True)\n\npd.options.mode.chained_assignment = None\npd.options.display.max_columns = 999","execution_count":1,"outputs":[{"output_type":"display_data","data":{"text/html":"        <script type=\"text/javascript\">\n        window.PlotlyConfig = {MathJaxConfig: 'local'};\n        if (window.MathJax) {MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}\n        if (typeof require !== 'undefined') {\n        require.undef(\"plotly\");\n        requirejs.config({\n            paths: {\n                'plotly': ['https://cdn.plot.ly/plotly-latest.min']\n            }\n        });\n        require(['plotly'], function(Plotly) {\n            window._Plotly = Plotly;\n        });\n        }\n        </script>\n        "},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df = pd.read_csv('../input/train.csv')\nstructure_df = pd.read_csv('../input/structures.csv')","execution_count":2,"outputs":[]},{"metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"cell_type":"code","source":"def show_molecule(mdata, mstruct):\n    mdata = mdata.merge(right=mstruct, how='left',\n                        left_on=['molecule_name', 'atom_index_0'],\n                        right_on=['molecule_name', 'atom_index'])\n    mdata.rename(index=str, columns={\"x\": \"x0\", \"y\": \"y0\", \"z\": \"z0\", \"atom\": \"atom0\"}, inplace=True)\n    mdata.drop(['atom_index'], axis=1, inplace=True)\n\n    mdata = mdata.merge(right=mstruct, how='left',\n                  left_on=['molecule_name', 'atom_index_1'],\n                  right_on=['molecule_name', 'atom_index']\n                 )\n    mdata.rename(index=str, columns={\"x\": \"x1\", \"y\": \"y1\", \"z\": \"z1\", \"atom\": \"atom1\"}, inplace=True)\n    mdata.drop(['atom_index'], axis=1, inplace=True)    \n    \n    data = []\n  \n    atoms = mstruct['atom'].unique()\n    types = mdata['type'].unique()\n    \n    atom_cfg = {\n        'H': {\"name\": \"Hydrogen\", \"color\": \"#757575\", \"size\": 4},\n        'C': {\"name\": \"Carbon\", \"color\": \"#f44336\", \"size\": 12},\n        'O': {\"name\": \"Oxygen\", \"color\": \"#03a9f4\", \"size\": 12},\n        'N': {\"name\": \"Nitrogen\", \"color\": \"#ff9800\", \"size\": 12},\n        'F': {\"name\": \"Fluorine\", \"color\": \"#673ab7\", \"size\": 12},\n    }\n    \n    type_cfg = {\n        '2JHH': {\"color\": \"#757575\", \"width\": 2},\n        '3JHH': {\"color\": \"#757575\", \"width\": 3},\n\n        '1JHC': {\"color\": \"#f44336\", \"width\": 1},\n        '2JHC': {\"color\": \"#f44336\", \"width\": 2},\n        '3JHC': {\"color\": \"#f44336\", \"width\": 3},\n\n        '1JHN': {\"color\": \"#ff9800\", \"width\": 2},\n        '2JHN': {\"color\": \"#ff9800\", \"width\": 2},\n        '3JHN': {\"color\": \"#ff9800\", \"width\": 3},\n    }\n\n    for atom, config in atom_cfg.items(): \n        if atom in atoms:\n            data.append(\n                go.Scatter3d(\n                    x=mstruct[mstruct['atom'] == atom]['x'].values,\n                    y=mstruct[mstruct['atom'] == atom]['y'].values,\n                    z=mstruct[mstruct['atom'] == atom]['z'].values,\n                    mode='markers',\n                    marker=dict(\n                        color=config['color'],\n                        size=config['size'],\n                        opacity=0.8\n                    ),\n                    name=config['name']\n                )\n            )\n\n    for ctype, config in type_cfg.items():\n        if ctype in types:\n            eX = []; eY = []; eZ = []\n            for row in mdata[mdata['type'] == ctype].iterrows():\n                rd = row[1]\n                eX += [rd['x0'], rd['x1']]\n                eY += [rd['y0'], rd['y1']]\n                eZ += [rd['z0'], rd['z1']]            \n            \n            data.append(\n                go.Scatter3d(\n                    x=eX,\n                    y=eY,\n                    z=eZ,\n                    mode='lines',\n                    line=dict(color=config['color'], width=config['width']),\n                    name=ctype\n                )\n            )            \n\n    axis=dict(showbackground=False, showline=False, zeroline=False, showgrid=False, showticklabels=False, title='')\n    layout = go.Layout(\n        margin=dict(l=50, r=50, b=50, t=50),\n        width=720,\n        height=640,\n        showlegend=True,\n        scene=dict(\n            xaxis=dict(axis),\n            yaxis=dict(axis),\n            zaxis=dict(axis),\n        )\n    )\n    fig = go.Figure(data=data, layout=layout)\n    py.iplot(fig, filename='molecule')","execution_count":11,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"molecule = 'dsgdb9nsd_000001'\nshow_molecule(train_df[train_df['molecule_name'] == molecule], structure_df[structure_df['molecule_name'] == molecule])","execution_count":12,"outputs":[{"output_type":"display_data","data":{"text/html":"<div>\n        \n        \n            <div id=\"b40f6c2b-7d0b-4f1e-a99e-812bb400261a\" class=\"plotly-graph-div\" style=\"height:640px; width:720px;\"></div>\n            <script type=\"text/javascript\">\n                require([\"plotly\"], function(Plotly) {\n                    window.PLOTLYENV=window.PLOTLYENV || {};\n                    window.PLOTLYENV.BASE_URL='https://plot.ly';\n                    \n                if (document.getElementById(\"b40f6c2b-7d0b-4f1e-a99e-812bb400261a\")) {\n                    Plotly.newPlot(\n                        'b40f6c2b-7d0b-4f1e-a99e-812bb400261a',\n                        [{\"marker\": {\"color\": \"#757575\", \"opacity\": 0.8, \"size\": 4}, \"mode\": \"markers\", \"name\": \"Hydrogen\", \"type\": \"scatter3d\", \"uid\": \"c5c5090d-685b-49e4-acdf-91f71a044bf5\", \"x\": [0.002150416, 1.011730843, -0.540815069, -0.5238136345000001], \"y\": [-0.0060313176, 1.4637511619999999, 1.447526614, 1.437932644], \"z\": [0.0019761204, 0.0002765748, -0.8766437152, 0.9063972942]}, {\"marker\": {\"color\": \"#f44336\", \"opacity\": 0.8, \"size\": 12}, \"mode\": \"markers\", \"name\": \"Carbon\", \"type\": \"scatter3d\", \"uid\": \"6b0e5062-296e-4524-9b47-55bd9632f9fe\", \"x\": [-0.012698135900000001], \"y\": [1.085804158], \"z\": [0.008000995799999999]}, {\"line\": {\"color\": \"#757575\", \"width\": 2}, \"mode\": \"lines\", \"name\": \"2JHH\", \"type\": \"scatter3d\", \"uid\": \"137f3bcb-127b-4af3-824a-be6035772907\", \"x\": [0.002150416, 1.011730843, 0.002150416, -0.540815069, 0.002150416, -0.5238136345000001, 1.011730843, -0.540815069, 1.011730843, -0.5238136345000001, -0.540815069, -0.5238136345000001], \"y\": [-0.0060313176, 1.4637511619999999, -0.0060313176, 1.447526614, -0.0060313176, 1.437932644, 1.4637511619999999, 1.447526614, 1.4637511619999999, 1.437932644, 1.447526614, 1.437932644], \"z\": [0.0019761204, 0.0002765748, 0.0019761204, -0.8766437152, 0.0019761204, 0.9063972942, 0.0002765748, -0.8766437152, 0.0002765748, 0.9063972942, -0.8766437152, 0.9063972942]}, {\"line\": {\"color\": \"#f44336\", \"width\": 1}, \"mode\": \"lines\", \"name\": \"1JHC\", \"type\": \"scatter3d\", \"uid\": \"2941c01f-0979-408f-a3cc-921845a22939\", \"x\": [0.002150416, -0.012698135900000001, 1.011730843, -0.012698135900000001, -0.540815069, -0.012698135900000001, -0.5238136345000001, -0.012698135900000001], \"y\": [-0.0060313176, 1.085804158, 1.4637511619999999, 1.085804158, 1.447526614, 1.085804158, 1.437932644, 1.085804158], \"z\": [0.0019761204, 0.008000995799999999, 0.0002765748, 0.008000995799999999, -0.8766437152, 0.008000995799999999, 0.9063972942, 0.008000995799999999]}],\n                        {\"height\": 640, \"margin\": {\"b\": 50, \"l\": 50, \"r\": 50, \"t\": 50}, \"scene\": {\"xaxis\": {\"showbackground\": false, \"showgrid\": false, \"showline\": false, \"showticklabels\": false, \"title\": {\"text\": \"\"}, \"zeroline\": false}, \"yaxis\": {\"showbackground\": false, \"showgrid\": false, \"showline\": false, \"showticklabels\": false, \"title\": {\"text\": \"\"}, \"zeroline\": false}, \"zaxis\": {\"showbackground\": false, \"showgrid\": false, \"showline\": false, \"showticklabels\": false, \"title\": {\"text\": \"\"}, \"zeroline\": false}}, \"showlegend\": true, \"width\": 720},\n                        {\"showLink\": false, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\", \"responsive\": true}\n                    ).then(function(){\n                            \nvar gd = document.getElementById('b40f6c2b-7d0b-4f1e-a99e-812bb400261a');\nvar x = new MutationObserver(function (mutations, observer) {{\n        var display = window.getComputedStyle(gd).display;\n        if (!display || display === 'none') {{\n            console.log([gd, 'removed!']);\n            Plotly.purge(gd);\n            observer.disconnect();\n        }}\n}});\n\n// Listen for the removal of the full notebook cells\nvar notebookContainer = gd.closest('#notebook-container');\nif (notebookContainer) {{\n    x.observe(notebookContainer, {childList: true});\n}}\n\n// Listen for the clearing of the current output cell\nvar outputEl = gd.closest('.output');\nif (outputEl) {{\n    x.observe(outputEl, {childList: true});\n}}\n\n                        })\n                };\n                });\n            </script>\n        </div>","application/vnd.plotly.v1+json":{"config":{"linkText":"Export to plot.ly","plotlyServerURL":"https://plot.ly","responsive":true,"showLink":false},"data":[{"marker":{"color":"#757575","opacity":0.8,"size":4},"mode":"markers","name":"Hydrogen","type":"scatter3d","uid":"66f892ba-6c6a-4b12-8b2f-b6503fba9fcf","x":[0.002150416,1.011730843,-0.540815069,-0.5238136345000001],"y":[-0.0060313176,1.4637511619999999,1.447526614,1.437932644],"z":[0.0019761204,0.0002765748,-0.8766437152,0.9063972942]},{"marker":{"color":"#f44336","opacity":0.8,"size":12},"mode":"markers","name":"Carbon","type":"scatter3d","uid":"e0e6b1f2-a5ae-4ea2-a92b-613c22f6223d","x":[-0.012698135900000001],"y":[1.085804158],"z":[0.008000995799999999]},{"line":{"color":"#757575","width":2},"mode":"lines","name":"2JHH","type":"scatter3d","uid":"c8c55810-25ef-4bce-904b-b3c209fb38d9","x":[0.002150416,1.011730843,0.002150416,-0.540815069,0.002150416,-0.5238136345000001,1.011730843,-0.540815069,1.011730843,-0.5238136345000001,-0.540815069,-0.5238136345000001],"y":[-0.0060313176,1.4637511619999999,-0.0060313176,1.447526614,-0.0060313176,1.437932644,1.4637511619999999,1.447526614,1.4637511619999999,1.437932644,1.447526614,1.437932644],"z":[0.0019761204,0.0002765748,0.0019761204,-0.8766437152,0.0019761204,0.9063972942,0.0002765748,-0.8766437152,0.0002765748,0.9063972942,-0.8766437152,0.9063972942]},{"line":{"color":"#f44336","width":1},"mode":"lines","name":"1JHC","type":"scatter3d","uid":"6e8f1448-9948-45ff-b5b8-63853bea771e","x":[0.002150416,-0.012698135900000001,1.011730843,-0.012698135900000001,-0.540815069,-0.012698135900000001,-0.5238136345000001,-0.012698135900000001],"y":[-0.0060313176,1.085804158,1.4637511619999999,1.085804158,1.447526614,1.085804158,1.437932644,1.085804158],"z":[0.0019761204,0.008000995799999999,0.0002765748,0.008000995799999999,-0.8766437152,0.008000995799999999,0.9063972942,0.008000995799999999]}],"layout":{"height":640,"margin":{"b":50,"l":50,"r":50,"t":50},"scene":{"xaxis":{"showbackground":false,"showgrid":false,"showline":false,"showticklabels":false,"title":{"text":""},"zeroline":false},"yaxis":{"showbackground":false,"showgrid":false,"showline":false,"showticklabels":false,"title":{"text":""},"zeroline":false},"zaxis":{"showbackground":false,"showgrid":false,"showline":false,"showticklabels":false,"title":{"text":""},"zeroline":false}},"showlegend":true,"width":720}}},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"molecule = 'dsgdb9nsd_128739'\nshow_molecule(train_df[train_df['molecule_name'] == molecule], structure_df[structure_df['molecule_name'] == molecule])","execution_count":78,"outputs":[{"output_type":"display_data","data":{"text/html":"<div>\n        \n        \n            <div id=\"1495ab4a-5327-4290-9d2f-905976e78bf4\" class=\"plotly-graph-div\" style=\"height:640px; width:720px;\"></div>\n            <script type=\"text/javascript\">\n                require([\"plotly\"], function(Plotly) {\n                    window.PLOTLYENV=window.PLOTLYENV || {};\n                    window.PLOTLYENV.BASE_URL='https://plot.ly';\n                    \n                if (document.getElementById(\"1495ab4a-5327-4290-9d2f-905976e78bf4\")) {\n                    Plotly.newPlot(\n                        '1495ab4a-5327-4290-9d2f-905976e78bf4',\n                        [{\"marker\": {\"color\": \"#757575\", \"opacity\": 0.8, \"size\": 4}, \"mode\": \"markers\", \"name\": \"Hydrogen\", \"type\": \"scatter3d\", \"uid\": \"19a7e9e2-7e1d-472c-a416-10d135dea2dc\", \"x\": [1.02821642, -0.5649449746999999, -0.4571379271, 1.34932916], \"y\": [1.7812944569999998, 1.78411015, 1.5690703190000002, -3.577845383], \"z\": [0.0626465149, -0.7303207795000001, 1.049230532, -2.600135327]}, {\"marker\": {\"color\": \"#f44336\", \"opacity\": 0.8, \"size\": 12}, \"mode\": \"markers\", \"name\": \"Carbon\", \"type\": \"scatter3d\", \"uid\": \"83a412d0-414c-4b2e-96e3-2232f7595c59\", \"x\": [0.0190090754, 0.6078128235, 1.257143159, 0.6388464281], \"y\": [1.3615416580000002, -0.5875199586, -2.512778415, -2.065687641], \"z\": [0.0918588269, -1.098044528, -2.410262672, -1.165281568]}, {\"marker\": {\"color\": \"#03a9f4\", \"opacity\": 0.8, \"size\": 12}, \"mode\": \"markers\", \"name\": \"Oxygen\", \"type\": \"scatter3d\", \"uid\": \"11da036e-947d-4894-9198-807b60daa804\", \"x\": [0.0649398857, 1.6312772130000002, 0.20786134], \"y\": [-0.0692419202, -0.3935487274, -2.804034073], \"z\": [-0.0055050188, -3.153500091, -0.3037577703]}, {\"marker\": {\"color\": \"#ff9800\", \"opacity\": 0.8, \"size\": 12}, \"mode\": \"markers\", \"name\": \"Nitrogen\", \"type\": \"scatter3d\", \"uid\": \"5f20d9ce-bad5-4923-a81e-29e22d18cbd8\", \"x\": [1.071127137, 1.71728615], \"y\": [0.1874954014, -1.737420908], \"z\": [-2.025960342, -3.331813136]}, {\"line\": {\"color\": \"#757575\", \"width\": 2}, \"mode\": \"lines\", \"name\": \"2JHH\", \"type\": \"scatter3d\", \"uid\": \"23ade9e8-7c38-4a4e-9eb1-17c0500e5d02\", \"x\": [1.02821642, -0.5649449746999999, 1.02821642, -0.4571379271, -0.5649449746999999, -0.4571379271], \"y\": [1.7812944569999998, 1.78411015, 1.7812944569999998, 1.5690703190000002, 1.78411015, 1.5690703190000002], \"z\": [0.0626465149, -0.7303207795000001, 0.0626465149, 1.049230532, -0.7303207795000001, 1.049230532]}, {\"line\": {\"color\": \"#f44336\", \"width\": 1}, \"mode\": \"lines\", \"name\": \"1JHC\", \"type\": \"scatter3d\", \"uid\": \"54ffcfa5-d058-4c0c-97c2-43370aabddbf\", \"x\": [1.02821642, 0.0190090754, -0.5649449746999999, 0.0190090754, -0.4571379271, 0.0190090754, 1.34932916, 1.257143159], \"y\": [1.7812944569999998, 1.3615416580000002, 1.78411015, 1.3615416580000002, 1.5690703190000002, 1.3615416580000002, -3.577845383, -2.512778415], \"z\": [0.0626465149, 0.0918588269, -0.7303207795000001, 0.0918588269, 1.049230532, 0.0918588269, -2.600135327, -2.410262672]}, {\"line\": {\"color\": \"#f44336\", \"width\": 2}, \"mode\": \"lines\", \"name\": \"2JHC\", \"type\": \"scatter3d\", \"uid\": \"0604f2be-dc97-410b-8695-486909f099a5\", \"x\": [1.34932916, 0.6388464281], \"y\": [-3.577845383, -2.065687641], \"z\": [-2.600135327, -1.165281568]}, {\"line\": {\"color\": \"#f44336\", \"width\": 3}, \"mode\": \"lines\", \"name\": \"3JHC\", \"type\": \"scatter3d\", \"uid\": \"d0ff3739-642d-4545-9d3a-57a37b85c79c\", \"x\": [1.02821642, 0.6078128235, -0.5649449746999999, 0.6078128235, -0.4571379271, 0.6078128235, 1.34932916, 0.6078128235], \"y\": [1.7812944569999998, -0.5875199586, 1.78411015, -0.5875199586, 1.5690703190000002, -0.5875199586, -3.577845383, -0.5875199586], \"z\": [0.0626465149, -1.098044528, -0.7303207795000001, -1.098044528, 1.049230532, -1.098044528, -2.600135327, -1.098044528]}, {\"line\": {\"color\": \"#ff9800\", \"width\": 2}, \"mode\": \"lines\", \"name\": \"2JHN\", \"type\": \"scatter3d\", \"uid\": \"dc7208e7-2c18-4646-aa39-c6241eec20cb\", \"x\": [1.34932916, 1.71728615], \"y\": [-3.577845383, -1.737420908], \"z\": [-2.600135327, -3.331813136]}],\n                        {\"height\": 640, \"margin\": {\"b\": 50, \"l\": 50, \"r\": 50, \"t\": 50}, \"scene\": {\"xaxis\": {\"showbackground\": false, \"showgrid\": false, \"showline\": false, \"showticklabels\": false, \"title\": {\"text\": \"\"}, \"zeroline\": false}, \"yaxis\": {\"showbackground\": false, \"showgrid\": false, \"showline\": false, \"showticklabels\": false, \"title\": {\"text\": \"\"}, \"zeroline\": false}, \"zaxis\": {\"showbackground\": false, \"showgrid\": false, \"showline\": false, \"showticklabels\": false, \"title\": {\"text\": \"\"}, \"zeroline\": false}}, \"showlegend\": true, \"width\": 720},\n                        {\"showLink\": false, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\", \"responsive\": true}\n                    ).then(function(){\n                            \nvar gd = document.getElementById('1495ab4a-5327-4290-9d2f-905976e78bf4');\nvar x = new MutationObserver(function (mutations, observer) {{\n        var display = window.getComputedStyle(gd).display;\n        if (!display || display === 'none') {{\n            console.log([gd, 'removed!']);\n            Plotly.purge(gd);\n            observer.disconnect();\n        }}\n}});\n\n// Listen for the removal of the full notebook cells\nvar notebookContainer = gd.closest('#notebook-container');\nif (notebookContainer) {{\n    x.observe(notebookContainer, {childList: true});\n}}\n\n// Listen for the clearing of the current output cell\nvar outputEl = gd.closest('.output');\nif (outputEl) {{\n    x.observe(outputEl, {childList: true});\n}}\n\n                        })\n                };\n                });\n            </script>\n        </div>","application/vnd.plotly.v1+json":{"config":{"linkText":"Export to plot.ly","plotlyServerURL":"https://plot.ly","responsive":true,"showLink":false},"data":[{"marker":{"color":"#757575","opacity":0.8,"size":4},"mode":"markers","name":"Hydrogen","type":"scatter3d","uid":"8531f93f-05f6-4936-a769-46df7489cd0f","x":[1.02821642,-0.5649449746999999,-0.4571379271,1.34932916],"y":[1.7812944569999998,1.78411015,1.5690703190000002,-3.577845383],"z":[0.0626465149,-0.7303207795000001,1.049230532,-2.600135327]},{"marker":{"color":"#f44336","opacity":0.8,"size":12},"mode":"markers","name":"Carbon","type":"scatter3d","uid":"19ce4217-376e-4a42-9605-bfb23b20fa58","x":[0.0190090754,0.6078128235,1.257143159,0.6388464281],"y":[1.3615416580000002,-0.5875199586,-2.512778415,-2.065687641],"z":[0.0918588269,-1.098044528,-2.410262672,-1.165281568]},{"marker":{"color":"#03a9f4","opacity":0.8,"size":12},"mode":"markers","name":"Oxygen","type":"scatter3d","uid":"1b37d47e-ab76-403d-a1c2-077806216753","x":[0.0649398857,1.6312772130000002,0.20786134],"y":[-0.0692419202,-0.3935487274,-2.804034073],"z":[-0.0055050188,-3.153500091,-0.3037577703]},{"marker":{"color":"#ff9800","opacity":0.8,"size":12},"mode":"markers","name":"Nitrogen","type":"scatter3d","uid":"144ac74d-4226-4020-a392-cf7942ea88d2","x":[1.071127137,1.71728615],"y":[0.1874954014,-1.737420908],"z":[-2.025960342,-3.331813136]},{"line":{"color":"#757575","width":2},"mode":"lines","name":"2JHH","type":"scatter3d","uid":"b8846fec-0594-4ce8-81ef-6647370a7f5a","x":[1.02821642,-0.5649449746999999,1.02821642,-0.4571379271,-0.5649449746999999,-0.4571379271],"y":[1.7812944569999998,1.78411015,1.7812944569999998,1.5690703190000002,1.78411015,1.5690703190000002],"z":[0.0626465149,-0.7303207795000001,0.0626465149,1.049230532,-0.7303207795000001,1.049230532]},{"line":{"color":"#f44336","width":1},"mode":"lines","name":"1JHC","type":"scatter3d","uid":"afa8fed2-714e-4421-9ee1-3ad6ef87b514","x":[1.02821642,0.0190090754,-0.5649449746999999,0.0190090754,-0.4571379271,0.0190090754,1.34932916,1.257143159],"y":[1.7812944569999998,1.3615416580000002,1.78411015,1.3615416580000002,1.5690703190000002,1.3615416580000002,-3.577845383,-2.512778415],"z":[0.0626465149,0.0918588269,-0.7303207795000001,0.0918588269,1.049230532,0.0918588269,-2.600135327,-2.410262672]},{"line":{"color":"#f44336","width":2},"mode":"lines","name":"2JHC","type":"scatter3d","uid":"474045e9-0a56-4485-b615-8a73920ab716","x":[1.34932916,0.6388464281],"y":[-3.577845383,-2.065687641],"z":[-2.600135327,-1.165281568]},{"line":{"color":"#f44336","width":3},"mode":"lines","name":"3JHC","type":"scatter3d","uid":"472bbb3e-5645-4451-9c77-960b4bb7a9a8","x":[1.02821642,0.6078128235,-0.5649449746999999,0.6078128235,-0.4571379271,0.6078128235,1.34932916,0.6078128235],"y":[1.7812944569999998,-0.5875199586,1.78411015,-0.5875199586,1.5690703190000002,-0.5875199586,-3.577845383,-0.5875199586],"z":[0.0626465149,-1.098044528,-0.7303207795000001,-1.098044528,1.049230532,-1.098044528,-2.600135327,-1.098044528]},{"line":{"color":"#ff9800","width":2},"mode":"lines","name":"2JHN","type":"scatter3d","uid":"1a2cef2f-ea66-4c73-9b79-30698d19b9a8","x":[1.34932916,1.71728615],"y":[-3.577845383,-1.737420908],"z":[-2.600135327,-3.331813136]}],"layout":{"height":640,"margin":{"b":50,"l":50,"r":50,"t":50},"scene":{"xaxis":{"showbackground":false,"showgrid":false,"showline":false,"showticklabels":false,"title":{"text":""},"zeroline":false},"yaxis":{"showbackground":false,"showgrid":false,"showline":false,"showticklabels":false,"title":{"text":""},"zeroline":false},"zaxis":{"showbackground":false,"showgrid":false,"showline":false,"showticklabels":false,"title":{"text":""},"zeroline":false}},"showlegend":true,"width":720}}},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"molecule = 'dsgdb9nsd_000037'","execution_count":13,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"mstructure = structure_df[structure_df['molecule_name'] == molecule]\nmstructure.head(20)","execution_count":14,"outputs":[{"output_type":"execute_result","execution_count":14,"data":{"text/plain":"        molecule_name  atom_index atom         x         y         z\n256  dsgdb9nsd_000037           0    C  0.106538  1.435120  0.033361\n257  dsgdb9nsd_000037           1    O  0.426866  0.047169  0.093099\n258  dsgdb9nsd_000037           2    C  0.507149 -0.636527 -1.063183\n259  dsgdb9nsd_000037           3    O  0.769270 -1.799550 -1.110105\n260  dsgdb9nsd_000037           4    H  0.923493  2.003851  0.484657\n261  dsgdb9nsd_000037           5    H -0.037578  1.769272 -1.000574\n262  dsgdb9nsd_000037           6    H -0.812696  1.608019  0.598733\n263  dsgdb9nsd_000037           7    H  0.304585 -0.002319 -1.949656","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>molecule_name</th>\n      <th>atom_index</th>\n      <th>atom</th>\n      <th>x</th>\n      <th>y</th>\n      <th>z</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>256</th>\n      <td>dsgdb9nsd_000037</td>\n      <td>0</td>\n      <td>C</td>\n      <td>0.106538</td>\n      <td>1.435120</td>\n      <td>0.033361</td>\n    </tr>\n    <tr>\n      <th>257</th>\n      <td>dsgdb9nsd_000037</td>\n      <td>1</td>\n      <td>O</td>\n      <td>0.426866</td>\n      <td>0.047169</td>\n      <td>0.093099</td>\n    </tr>\n    <tr>\n      <th>258</th>\n      <td>dsgdb9nsd_000037</td>\n      <td>2</td>\n      <td>C</td>\n      <td>0.507149</td>\n      <td>-0.636527</td>\n      <td>-1.063183</td>\n    </tr>\n    <tr>\n      <th>259</th>\n      <td>dsgdb9nsd_000037</td>\n      <td>3</td>\n      <td>O</td>\n      <td>0.769270</td>\n      <td>-1.799550</td>\n      <td>-1.110105</td>\n    </tr>\n    <tr>\n      <th>260</th>\n      <td>dsgdb9nsd_000037</td>\n      <td>4</td>\n      <td>H</td>\n      <td>0.923493</td>\n      <td>2.003851</td>\n      <td>0.484657</td>\n    </tr>\n    <tr>\n      <th>261</th>\n      <td>dsgdb9nsd_000037</td>\n      <td>5</td>\n      <td>H</td>\n      <td>-0.037578</td>\n      <td>1.769272</td>\n      <td>-1.000574</td>\n    </tr>\n    <tr>\n      <th>262</th>\n      <td>dsgdb9nsd_000037</td>\n      <td>6</td>\n      <td>H</td>\n      <td>-0.812696</td>\n      <td>1.608019</td>\n      <td>0.598733</td>\n    </tr>\n    <tr>\n      <th>263</th>\n      <td>dsgdb9nsd_000037</td>\n      <td>7</td>\n      <td>H</td>\n      <td>0.304585</td>\n      <td>-0.002319</td>\n      <td>-1.949656</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"mdata = train_df[train_df['molecule_name'] == molecule]\nmdata.head(20)","execution_count":15,"outputs":[{"output_type":"execute_result","execution_count":15,"data":{"text/plain":"      id     molecule_name  atom_index_0  atom_index_1  type  \\\n434  434  dsgdb9nsd_000037             4             0  1JHC   \n435  435  dsgdb9nsd_000037             4             2  3JHC   \n436  436  dsgdb9nsd_000037             4             5  2JHH   \n437  437  dsgdb9nsd_000037             4             6  2JHH   \n438  438  dsgdb9nsd_000037             5             0  1JHC   \n439  439  dsgdb9nsd_000037             5             2  3JHC   \n440  440  dsgdb9nsd_000037             5             6  2JHH   \n441  441  dsgdb9nsd_000037             6             0  1JHC   \n442  442  dsgdb9nsd_000037             6             2  3JHC   \n443  443  dsgdb9nsd_000037             7             0  3JHC   \n444  444  dsgdb9nsd_000037             7             2  1JHC   \n\n     scalar_coupling_constant  \n434                  89.61690  \n435                   4.23671  \n436                  -9.99405  \n437                  -8.74586  \n438                  94.96520  \n439                  10.76020  \n440                  -9.99519  \n441                  89.61640  \n442                   4.24490  \n443                   3.78426  \n444                 126.36100  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>id</th>\n      <th>molecule_name</th>\n      <th>atom_index_0</th>\n      <th>atom_index_1</th>\n      <th>type</th>\n      <th>scalar_coupling_constant</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>434</th>\n      <td>434</td>\n      <td>dsgdb9nsd_000037</td>\n      <td>4</td>\n      <td>0</td>\n      <td>1JHC</td>\n      <td>89.61690</td>\n    </tr>\n    <tr>\n      <th>435</th>\n      <td>435</td>\n      <td>dsgdb9nsd_000037</td>\n      <td>4</td>\n      <td>2</td>\n      <td>3JHC</td>\n      <td>4.23671</td>\n    </tr>\n    <tr>\n      <th>436</th>\n      <td>436</td>\n      <td>dsgdb9nsd_000037</td>\n      <td>4</td>\n      <td>5</td>\n      <td>2JHH</td>\n      <td>-9.99405</td>\n    </tr>\n    <tr>\n      <th>437</th>\n      <td>437</td>\n      <td>dsgdb9nsd_000037</td>\n      <td>4</td>\n      <td>6</td>\n      <td>2JHH</td>\n      <td>-8.74586</td>\n    </tr>\n    <tr>\n      <th>438</th>\n      <td>438</td>\n      <td>dsgdb9nsd_000037</td>\n      <td>5</td>\n      <td>0</td>\n      <td>1JHC</td>\n      <td>94.96520</td>\n    </tr>\n    <tr>\n      <th>439</th>\n      <td>439</td>\n      <td>dsgdb9nsd_000037</td>\n      <td>5</td>\n      <td>2</td>\n      <td>3JHC</td>\n      <td>10.76020</td>\n    </tr>\n    <tr>\n      <th>440</th>\n      <td>440</td>\n      <td>dsgdb9nsd_000037</td>\n      <td>5</td>\n      <td>6</td>\n      <td>2JHH</td>\n      <td>-9.99519</td>\n    </tr>\n    <tr>\n      <th>441</th>\n      <td>441</td>\n      <td>dsgdb9nsd_000037</td>\n      <td>6</td>\n      <td>0</td>\n      <td>1JHC</td>\n      <td>89.61640</td>\n    </tr>\n    <tr>\n      <th>442</th>\n      <td>442</td>\n      <td>dsgdb9nsd_000037</td>\n      <td>6</td>\n      <td>2</td>\n      <td>3JHC</td>\n      <td>4.24490</td>\n    </tr>\n    <tr>\n      <th>443</th>\n      <td>443</td>\n      <td>dsgdb9nsd_000037</td>\n      <td>7</td>\n      <td>0</td>\n      <td>3JHC</td>\n      <td>3.78426</td>\n    </tr>\n    <tr>\n      <th>444</th>\n      <td>444</td>\n      <td>dsgdb9nsd_000037</td>\n      <td>7</td>\n      <td>2</td>\n      <td>1JHC</td>\n      <td>126.36100</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"show_molecule(mdata, mstructure)","execution_count":16,"outputs":[{"output_type":"display_data","data":{"text/html":"<div>\n        \n        \n            <div id=\"17e91441-aa98-4010-ae7f-686345738a12\" class=\"plotly-graph-div\" style=\"height:640px; width:720px;\"></div>\n            <script type=\"text/javascript\">\n                require([\"plotly\"], function(Plotly) {\n                    window.PLOTLYENV=window.PLOTLYENV || {};\n                    window.PLOTLYENV.BASE_URL='https://plot.ly';\n                    \n                if (document.getElementById(\"17e91441-aa98-4010-ae7f-686345738a12\")) {\n                    Plotly.newPlot(\n                        '17e91441-aa98-4010-ae7f-686345738a12',\n                        [{\"marker\": {\"color\": \"#757575\", \"opacity\": 0.8, \"size\": 4}, \"mode\": \"markers\", \"name\": \"Hydrogen\", \"type\": \"scatter3d\", \"uid\": \"7f2a1e06-6673-4500-bd82-99d2a4439ab0\", \"x\": [0.9234925079, -0.0375781504, -0.8126956863, 0.3045845993], \"y\": [2.003851386, 1.7692718280000002, 1.608019155, -0.002319017], \"z\": [0.4846572797, -1.000574254, 0.5987328735, -1.949655532]}, {\"marker\": {\"color\": \"#f44336\", \"opacity\": 0.8, \"size\": 12}, \"mode\": \"markers\", \"name\": \"Carbon\", \"type\": \"scatter3d\", \"uid\": \"0a2e150b-28dc-4c5b-982a-37a4a5391b9c\", \"x\": [0.1065378106, 0.5071486248], \"y\": [1.4351204880000001, -0.6365266459000001], \"z\": [0.0333609957, -1.063182974]}, {\"marker\": {\"color\": \"#03a9f4\", \"opacity\": 0.8, \"size\": 12}, \"mode\": \"markers\", \"name\": \"Oxygen\", \"type\": \"scatter3d\", \"uid\": \"2b34c322-9795-438a-bda5-61f96c624bdf\", \"x\": [0.4268656414, 0.7692701426999999], \"y\": [0.0471692892, -1.799550173], \"z\": [0.093099449, -1.110104748]}, {\"line\": {\"color\": \"#757575\", \"width\": 2}, \"mode\": \"lines\", \"name\": \"2JHH\", \"type\": \"scatter3d\", \"uid\": \"0a21a74b-2e0c-4734-8535-d81b85bff752\", \"x\": [0.9234925079, -0.0375781504, 0.9234925079, -0.8126956863, -0.0375781504, -0.8126956863], \"y\": [2.003851386, 1.7692718280000002, 2.003851386, 1.608019155, 1.7692718280000002, 1.608019155], \"z\": [0.4846572797, -1.000574254, 0.4846572797, 0.5987328735, -1.000574254, 0.5987328735]}, {\"line\": {\"color\": \"#f44336\", \"width\": 1}, \"mode\": \"lines\", \"name\": \"1JHC\", \"type\": \"scatter3d\", \"uid\": \"9314f931-9233-450d-970d-036802dd28d3\", \"x\": [0.9234925079, 0.1065378106, -0.0375781504, 0.1065378106, -0.8126956863, 0.1065378106, 0.3045845993, 0.5071486248], \"y\": [2.003851386, 1.4351204880000001, 1.7692718280000002, 1.4351204880000001, 1.608019155, 1.4351204880000001, -0.002319017, -0.6365266459000001], \"z\": [0.4846572797, 0.0333609957, -1.000574254, 0.0333609957, 0.5987328735, 0.0333609957, -1.949655532, -1.063182974]}, {\"line\": {\"color\": \"#f44336\", \"width\": 3}, \"mode\": \"lines\", \"name\": \"3JHC\", \"type\": \"scatter3d\", \"uid\": \"e3579287-4319-4ff9-a100-f6623054b822\", \"x\": [0.9234925079, 0.5071486248, -0.0375781504, 0.5071486248, -0.8126956863, 0.5071486248, 0.3045845993, 0.1065378106], \"y\": [2.003851386, -0.6365266459000001, 1.7692718280000002, -0.6365266459000001, 1.608019155, -0.6365266459000001, -0.002319017, 1.4351204880000001], \"z\": [0.4846572797, -1.063182974, -1.000574254, -1.063182974, 0.5987328735, -1.063182974, -1.949655532, 0.0333609957]}],\n                        {\"height\": 640, \"margin\": {\"b\": 50, \"l\": 50, \"r\": 50, \"t\": 50}, \"scene\": {\"xaxis\": {\"showbackground\": false, \"showgrid\": false, \"showline\": false, \"showticklabels\": false, \"title\": {\"text\": \"\"}, \"zeroline\": false}, \"yaxis\": {\"showbackground\": false, \"showgrid\": false, \"showline\": false, \"showticklabels\": false, \"title\": {\"text\": \"\"}, \"zeroline\": false}, \"zaxis\": {\"showbackground\": false, \"showgrid\": false, \"showline\": false, \"showticklabels\": false, \"title\": {\"text\": \"\"}, \"zeroline\": false}}, \"showlegend\": true, \"width\": 720},\n                        {\"showLink\": false, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\", \"responsive\": true}\n                    ).then(function(){\n                            \nvar gd = document.getElementById('17e91441-aa98-4010-ae7f-686345738a12');\nvar x = new MutationObserver(function (mutations, observer) {{\n        var display = window.getComputedStyle(gd).display;\n        if (!display || display === 'none') {{\n            console.log([gd, 'removed!']);\n            Plotly.purge(gd);\n            observer.disconnect();\n        }}\n}});\n\n// Listen for the removal of the full notebook cells\nvar notebookContainer = gd.closest('#notebook-container');\nif (notebookContainer) {{\n    x.observe(notebookContainer, {childList: true});\n}}\n\n// Listen for the clearing of the current output cell\nvar outputEl = gd.closest('.output');\nif (outputEl) {{\n    x.observe(outputEl, {childList: true});\n}}\n\n                        })\n                };\n                });\n            </script>\n        </div>","application/vnd.plotly.v1+json":{"config":{"linkText":"Export to plot.ly","plotlyServerURL":"https://plot.ly","responsive":true,"showLink":false},"data":[{"marker":{"color":"#757575","opacity":0.8,"size":4},"mode":"markers","name":"Hydrogen","type":"scatter3d","uid":"0e7fe50f-b9cc-43da-8b6f-5a0a3d04521f","x":[0.9234925079,-0.0375781504,-0.8126956863,0.3045845993],"y":[2.003851386,1.7692718280000002,1.608019155,-0.002319017],"z":[0.4846572797,-1.000574254,0.5987328735,-1.949655532]},{"marker":{"color":"#f44336","opacity":0.8,"size":12},"mode":"markers","name":"Carbon","type":"scatter3d","uid":"746fc84b-f8e0-4766-8c28-9a64f0e91137","x":[0.1065378106,0.5071486248],"y":[1.4351204880000001,-0.6365266459000001],"z":[0.0333609957,-1.063182974]},{"marker":{"color":"#03a9f4","opacity":0.8,"size":12},"mode":"markers","name":"Oxygen","type":"scatter3d","uid":"3c0dce64-c471-419c-8534-7e0762589a51","x":[0.4268656414,0.7692701426999999],"y":[0.0471692892,-1.799550173],"z":[0.093099449,-1.110104748]},{"line":{"color":"#757575","width":2},"mode":"lines","name":"2JHH","type":"scatter3d","uid":"32d4763f-dd65-45d2-8e13-2d6da046fa9a","x":[0.9234925079,-0.0375781504,0.9234925079,-0.8126956863,-0.0375781504,-0.8126956863],"y":[2.003851386,1.7692718280000002,2.003851386,1.608019155,1.7692718280000002,1.608019155],"z":[0.4846572797,-1.000574254,0.4846572797,0.5987328735,-1.000574254,0.5987328735]},{"line":{"color":"#f44336","width":1},"mode":"lines","name":"1JHC","type":"scatter3d","uid":"11dde871-372e-44ff-8a25-b64564a4d457","x":[0.9234925079,0.1065378106,-0.0375781504,0.1065378106,-0.8126956863,0.1065378106,0.3045845993,0.5071486248],"y":[2.003851386,1.4351204880000001,1.7692718280000002,1.4351204880000001,1.608019155,1.4351204880000001,-0.002319017,-0.6365266459000001],"z":[0.4846572797,0.0333609957,-1.000574254,0.0333609957,0.5987328735,0.0333609957,-1.949655532,-1.063182974]},{"line":{"color":"#f44336","width":3},"mode":"lines","name":"3JHC","type":"scatter3d","uid":"2c78ebe7-2cdb-4e32-a296-d07cdde0fbbe","x":[0.9234925079,0.5071486248,-0.0375781504,0.5071486248,-0.8126956863,0.5071486248,0.3045845993,0.1065378106],"y":[2.003851386,-0.6365266459000001,1.7692718280000002,-0.6365266459000001,1.608019155,-0.6365266459000001,-0.002319017,1.4351204880000001],"z":[0.4846572797,-1.063182974,-1.000574254,-1.063182974,0.5987328735,-1.063182974,-1.949655532,0.0333609957]}],"layout":{"height":640,"margin":{"b":50,"l":50,"r":50,"t":50},"scene":{"xaxis":{"showbackground":false,"showgrid":false,"showline":false,"showticklabels":false,"title":{"text":""},"zeroline":false},"yaxis":{"showbackground":false,"showgrid":false,"showline":false,"showticklabels":false,"title":{"text":""},"zeroline":false},"zaxis":{"showbackground":false,"showgrid":false,"showline":false,"showticklabels":false,"title":{"text":""},"zeroline":false}},"showlegend":true,"width":720}}},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}