{"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":"markdown","source":"# xyz2graph\n[**xyz2graph**](https://github.com/zotko/xyz2graph) is a Python package for reading of .xyz files and constructing of molecular graphs from atomic coordinates. The molecular graph can be converted into [NetworkX](https://networkx.github.io) graph or [Plotly](https://plot.ly) figure for 3D visualization in a browser window or in a [Jupyter notebook](https://jupyter.org).","metadata":{}},{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\nimport random\n\nPATH = '../input/champs-scalar-coupling/'","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-06-11T22:02:31.629243Z","iopub.execute_input":"2022-06-11T22:02:31.629721Z","iopub.status.idle":"2022-06-11T22:02:31.634614Z","shell.execute_reply.started":"2022-06-11T22:02:31.629677Z","shell.execute_reply":"2022-06-11T22:02:31.633905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python -m pip install git+https://github.com/zotko/xyz2graph.git","metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","execution":{"iopub.status.busy":"2022-06-11T22:02:31.639851Z","iopub.execute_input":"2022-06-11T22:02:31.640348Z","iopub.status.idle":"2022-06-11T22:02:42.250178Z","shell.execute_reply.started":"2022-06-11T22:02:31.640302Z","shell.execute_reply":"2022-06-11T22:02:42.249157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from xyz2graph import MolGraph, to_networkx_graph, to_plotly_figure\nfrom plotly.offline import init_notebook_mode, iplot\nimport networkx as nx\n\n# initiate the Plotly notebook mode\ninit_notebook_mode(connected=True)\n\nstructures = pd.read_csv(PATH + 'structures.csv')\nmol_names = structures.molecule_name.unique()","metadata":{"execution":{"iopub.status.busy":"2022-06-11T22:02:42.252685Z","iopub.execute_input":"2022-06-11T22:02:42.253084Z","iopub.status.idle":"2022-06-11T22:02:47.995637Z","shell.execute_reply.started":"2022-06-11T22:02:42.253019Z","shell.execute_reply":"2022-06-11T22:02:47.994750Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def draw_random_mol():\n    \"\"\"Draws a random molecule\"\"\"\n    mol_name = random.choice(mol_names)\n    # Create the MolGraph object\n    mg = MolGraph()\n    # Read the data from the .xyz file\n    mg.read_xyz(f'{PATH}structures/{mol_name}.xyz')\n    # Create the Plotly figure\n    fig = to_plotly_figure(mg)\n    iplot(fig)\n\ndef draw_random_networx_graph():\n    \"\"\"Draws the NetworkX graph of a random molecule\"\"\"\n    mol_name = random.choice(mol_names)\n    # Create the MolGraph object\n    mg = MolGraph()\n    # Read the data from the .xyz file\n    mg.read_xyz(f'{PATH}structures/{mol_name}.xyz')\n    # Create the NetworkX figure\n    G = to_networkx_graph(mg)\n    nodes = list(G.nodes(data=True))\n    print('Nodes:')\n    print(nodes[:5])\n    edges = list(G.edges(data=True))\n    print('Edges:')\n    print(print(edges[:5]))\n    nx.draw(G, with_labels=True)","metadata":{"execution":{"iopub.status.busy":"2022-06-11T22:02:47.997319Z","iopub.execute_input":"2022-06-11T22:02:47.997629Z","iopub.status.idle":"2022-06-11T22:02:48.007878Z","shell.execute_reply.started":"2022-06-11T22:02:47.997571Z","shell.execute_reply":"2022-06-11T22:02:48.007009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"draw_random_mol()","metadata":{"execution":{"iopub.status.busy":"2022-06-11T22:02:48.009236Z","iopub.execute_input":"2022-06-11T22:02:48.009748Z","iopub.status.idle":"2022-06-11T22:02:49.910384Z","shell.execute_reply.started":"2022-06-11T22:02:48.009693Z","shell.execute_reply":"2022-06-11T22:02:49.909641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"draw_random_mol()","metadata":{"execution":{"iopub.status.busy":"2022-06-11T22:02:49.912662Z","iopub.execute_input":"2022-06-11T22:02:49.913136Z","iopub.status.idle":"2022-06-11T22:02:50.442293Z","shell.execute_reply.started":"2022-06-11T22:02:49.913072Z","shell.execute_reply":"2022-06-11T22:02:50.441586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"draw_random_mol()","metadata":{"execution":{"iopub.status.busy":"2022-06-11T22:02:50.443482Z","iopub.execute_input":"2022-06-11T22:02:50.443860Z","iopub.status.idle":"2022-06-11T22:02:51.040329Z","shell.execute_reply.started":"2022-06-11T22:02:50.443821Z","shell.execute_reply":"2022-06-11T22:02:51.039352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"draw_random_mol()","metadata":{"execution":{"iopub.status.busy":"2022-06-11T22:02:51.041962Z","iopub.execute_input":"2022-06-11T22:02:51.042347Z","iopub.status.idle":"2022-06-11T22:02:51.525470Z","shell.execute_reply.started":"2022-06-11T22:02:51.042282Z","shell.execute_reply":"2022-06-11T22:02:51.524595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"draw_random_mol()","metadata":{"execution":{"iopub.status.busy":"2022-06-11T22:02:51.526560Z","iopub.execute_input":"2022-06-11T22:02:51.526806Z","iopub.status.idle":"2022-06-11T22:02:52.155679Z","shell.execute_reply.started":"2022-06-11T22:02:51.526764Z","shell.execute_reply":"2022-06-11T22:02:52.154803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"draw_random_mol()","metadata":{"execution":{"iopub.status.busy":"2022-06-11T22:02:52.156952Z","iopub.execute_input":"2022-06-11T22:02:52.157245Z","iopub.status.idle":"2022-06-11T22:02:52.719229Z","shell.execute_reply.started":"2022-06-11T22:02:52.157199Z","shell.execute_reply":"2022-06-11T22:02:52.718331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"draw_random_mol()","metadata":{"execution":{"iopub.status.busy":"2022-06-11T22:02:52.720496Z","iopub.execute_input":"2022-06-11T22:02:52.720752Z","iopub.status.idle":"2022-06-11T22:02:53.195711Z","shell.execute_reply.started":"2022-06-11T22:02:52.720710Z","shell.execute_reply":"2022-06-11T22:02:53.194863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"draw_random_mol()","metadata":{"execution":{"iopub.status.busy":"2022-06-11T22:02:53.197305Z","iopub.execute_input":"2022-06-11T22:02:53.197599Z","iopub.status.idle":"2022-06-11T22:02:53.846910Z","shell.execute_reply.started":"2022-06-11T22:02:53.197545Z","shell.execute_reply":"2022-06-11T22:02:53.845945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"draw_random_networx_graph()","metadata":{"execution":{"iopub.status.busy":"2022-06-11T22:02:53.848677Z","iopub.execute_input":"2022-06-11T22:02:53.849375Z","iopub.status.idle":"2022-06-11T22:02:54.094025Z","shell.execute_reply.started":"2022-06-11T22:02:53.849312Z","shell.execute_reply":"2022-06-11T22:02:54.092900Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"draw_random_networx_graph()","metadata":{"execution":{"iopub.status.busy":"2022-06-11T22:02:54.095753Z","iopub.execute_input":"2022-06-11T22:02:54.096390Z","iopub.status.idle":"2022-06-11T22:02:54.357789Z","shell.execute_reply.started":"2022-06-11T22:02:54.096325Z","shell.execute_reply":"2022-06-11T22:02:54.356605Z"},"trusted":true},"execution_count":null,"outputs":[]}]}