{ "cells": [ { "cell_type": "markdown", "id": "091eec3b", "metadata": {}, "source": [ "Visualization with inquanto-nglview\n", "=============================================\n", "\n", "It is often useful to visualize certain molecular data. For this purpose, InQuanto uses an extension to interface with the [NGLview](https://nglviewer.org/#nglview) nglview package. The [inquanto-nglview](https://docs.quantinuum.com/inquanto/extensions/inquanto-nglview.html) extension is focused on providing some basic visualizing utilities to the user. The return types from the functions are widgets which can be viewed in a jupyter notebook. The functionality includes visualizing molecular structures, fragmentation patterns defined in the `Geometry` object and molecular orbitals.\n", "\n", "\n", "Visualizing Structures\n", "-----------------------\n", "VisualizerNGL is initialized by an InQuanto Geometry object specifying molecular, or unit cell, geometry. The molecule can then be visualized by calling the\n", "`.visualize_molecule()` in the last line of a notebook cell. See below for a short example.\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "3328160f", "metadata": {}, "outputs": [], "source": [ "# pip install inquanto-nglview --index https://...\n", "\n", "\n", "from inquanto.geometries import GeometryMolecular\n", "from inquanto.extensions.nglview import VisualizerNGL\n", "\n", "xyz = [\n", " ['C', [ 0.0000000, 1.4113170, 0.0000000]],\n", " ['C', [ 1.2222370, 0.7056590, 0.0000000]],\n", " ['C', [ 1.2222370, -0.7056590, 0.0000000]],\n", " ['C', [ 0.0000000, -1.4113170, 0.0000000]],\n", " ['C', [-1.2222370, -0.7056590, 0.0000000]],\n", " ['C', [-1.2222370, 0.7056590, 0.0000000]],\n", " ['H', [ 0.0000000, 2.5070120, 0.0000000]],\n", " ['H', [ 2.1711360, 1.2535060, 0.0000000]],\n", " ['H', [ 2.1711360, -1.2535060, 0.0000000]],\n", " ['H', [ 0.0000000, -2.5070120, 0.0000000]],\n", " ['H', [-2.1711360, -1.2535060, 0.0000000]],\n", " ['H', [-2.1711360, 1.2535060, 0.0000000]]\n", "]\n", "g = GeometryMolecular(xyz)\n", "visualizer = VisualizerNGL(g)" ] }, { "cell_type": "code", "execution_count": null, "id": "69cf243b", "metadata": {}, "outputs": [], "source": [ "#visualizer.visualize_molecule(atom_labels=\"index\").display(gui=True)\n", "#markdown cell below is a presaved image " ] }, { "cell_type": "markdown", "id": "27020847", "metadata": {}, "source": [ "![1](_images/nglview_img1.png)" ] }, { "cell_type": "markdown", "id": "852415de", "metadata": {}, "source": [ "Visualizing Fragments\n", "----------------------\n", "\n", "There are several [fragmentation methods](https://docs.quantinuum.com/inquanto/tutorials/tutorial_overview.html#fragmentation-tutorials) available in inquanto, to visualize a fragmentation defined in a `Geometry`\n", "object, call the `visualize_fragmentation()` method as illustrated in the code-snippet below.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "12fa4721", "metadata": {}, "outputs": [], "source": [ "g.set_groups(\n", " \"fragments\",\n", " {\n", " \"ch1\": [0, 6],\n", " \"ch2\": [5, 11],\n", " \"ch3\": [4, 10],\n", " \"ch4\": [3, 9],\n", " \"ch5\": [2, 8],\n", " \"ch6\": [1, 7]\n", " }\n", ")\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "b63ef40b", "metadata": {}, "outputs": [], "source": [ "#visualizer.visualize_fragmentation(\"fragments\", atom_labels=\"index\")" ] }, { "cell_type": "markdown", "id": "b347f266", "metadata": {}, "source": [ "![2](_images/nglview_img2.png)" ] }, { "cell_type": "markdown", "id": "2149bf3f", "metadata": {}, "source": [ "Visualizing Orbitals\n", "---------------------\n", "\n", "To aid in active space selection, it is also possible to view the molecular orbitals of a system if the appropriate\n", "`.cube` strings are available.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "6158f879", "metadata": {}, "outputs": [], "source": [ "from inquanto.extensions.pyscf import ChemistryDriverPySCFMolecularRHF\n", "\n", "driver = ChemistryDriverPySCFMolecularRHF(geometry=g.xyz, basis=\"sto3g\")\n", "\n", "# runs HF and returns orbitals\n", "cube_orbitals=driver.get_cube_orbitals()\n", "ngl_mos = [visualizer.visualize_orbitals(orb, atom_labels=\"index\") for i, orb in enumerate(cube_orbitals)]\n" ] }, { "cell_type": "code", "execution_count": null, "id": "d6c4b676", "metadata": {}, "outputs": [], "source": [ "#ngl_mos[16]" ] }, { "cell_type": "markdown", "id": "da72575a", "metadata": {}, "source": [ "![3](_images/nglview_img3.png)" ] } ], "metadata": { "kernelspec": { "display_name": "11jun25_docs", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.12.6" } }, "nbformat": 4, "nbformat_minor": 5 }