{ "cells": [ { "cell_type": "markdown", "id": "d4042ccc-59c7-48a2-bbd0-0d4804c8dee8", "metadata": {}, "source": [ "# Run a Template Job\n", "\n", "This notebook demonstrates how to run a customizable job using a template.\n", "\n", "## Imports\n", "\n", "As in every notebook we make, first import the various packages needed for the rest of the notebook function." ] }, { "cell_type": "code", "execution_count": null, "id": "e4618ffa-130c-4982-bc71-9dc4790e3397", "metadata": { "tags": [] }, "outputs": [], "source": [ "import webmo # to run the job itself and download the results\n", "from webmo.util import xyz_from_name # to get molecular geometries by name\n", "from webmo.gui import JupyterGUI #alternative we can use a GUI to specify the job options" ] }, { "cell_type": "markdown", "id": "96682f6c-6bce-462e-98d2-54066e572285", "metadata": {}, "source": [ "## User Setup\n", "\n", "Set up the user-supplied information that defines the job." ] }, { "cell_type": "code", "execution_count": null, "id": "f4add38f-5515-4d26-832b-b421e7c3f2ef", "metadata": { "tags": [] }, "outputs": [], "source": [ "## BOOKKEEPING PARAMETERS\n", "# the URL of your WebMO instance\n", "URL = \"https://server.university.edu/~webmo/cgi-bin/webmo/rest.cgi\"\n", "\n", "# your username on the above WebMO instance\n", "username = \"smith\"\n", "\n", "## JOB PARAMETERS\n", "# name of the molecule to run a job on\n", "molecule = \"formaldehyde\"\n", "\n", "# job type to run\n", "job_type = \"Geometry Optimization\"\n", "\n", "# theory of the theory/basis pair to run the job at\n", "theory = \"HF\"\n", "\n", "# basis of the theory/basis pair to run the job at\n", "basis = \"STO-3G\"\n", "\n", "# charge of the molecule\n", "charge = 0\n", "\n", "# multiplicity of the molecule\n", "multiplicity = 1\n", "\n", "# job title as it will show up in WebMO\n", "title = \"formaldehyde\"" ] }, { "cell_type": "markdown", "id": "8c9e7bf5-7022-4171-ba32-2cf18b7b0872", "metadata": {}, "source": [ "## Initializaiton\n", "\n", "Open a REST session." ] }, { "cell_type": "code", "execution_count": null, "id": "5a749ebb-b5d4-4065-bd98-033c862415e6", "metadata": { "tags": [] }, "outputs": [], "source": [ "rest = webmo.WebMOREST(URL, username=username)" ] }, { "cell_type": "markdown", "id": "5aa8f4ab-c13d-4273-87a0-4c298f50c9f1", "metadata": {}, "source": [ "## Geometry\n", "\n", "Grab the 3D geometry from PubChem." ] }, { "cell_type": "code", "execution_count": null, "id": "170ea260-3711-4390-93f7-5239cdd5ed39", "metadata": { "tags": [] }, "outputs": [], "source": [ "geom = xyz_from_name(molecule)" ] }, { "cell_type": "markdown", "id": "099507cd-76b4-44fa-a3d4-b541b50b6867", "metadata": { "tags": [] }, "source": [ "## Template\n", "\n", "Using the geometry (in `geom`), fill in a string template for the job. Alternatively, a GUI can be used to specify job options interactively!" ] }, { "cell_type": "code", "execution_count": null, "id": "84d0d0c4-961b-448f-9466-a10715ce326c", "metadata": { "tags": [] }, "outputs": [], "source": [ "templates = rest.get_templates('gaussian')\n", "template = templates[job_type]\n", "\n", "template_variables = {\n", " 'jobName' : title,\n", " 'geometry' : geom,\n", " 'theory' : theory,\n", " 'basisSet' : basis\n", "}\n", "\n", "#alternatively a Jupyter-based GUI can be used to query for the job options interactively\n", "#gui = JupyterGUI(template, query_vars=['jobName', 'theory', 'basisSet'], additional_vars={'geometry':geom})\n", "#gui.display()" ] }, { "cell_type": "code", "execution_count": null, "id": "822cd1a3-a326-46bd-985e-93550f9ff390", "metadata": { "tags": [] }, "outputs": [], "source": [ "#...if GUI was used\n", "#template_variables = gui.get_variables()\n", "\n", "input_file_contents = rest.generate_input(template, variables=template_variables)\n", "print(\"The job that will be submitted:\")\n", "print(input_file_contents)" ] }, { "cell_type": "markdown", "id": "1e627a47-4250-4c6c-b503-81dee83623e0", "metadata": {}, "source": [ "## Job Submission\n" ] }, { "cell_type": "markdown", "id": "463b2b04-3f1b-422c-ab33-89b3e0d4542c", "metadata": {}, "source": [ "Submit the job through that REST session and wait for it to complete." ] }, { "cell_type": "code", "execution_count": null, "id": "c8097303-ab66-4325-a091-782cbd0a06cf", "metadata": { "tags": [] }, "outputs": [], "source": [ "n = rest.submit_job(title, input_file_contents, \"gaussian\")\n", "rest.wait_for_job(n)" ] }, { "cell_type": "markdown", "id": "386be75a-70be-4f19-85c6-fb96efae3fc4", "metadata": {}, "source": [ "After the job is finished, get some of its output." ] }, { "cell_type": "code", "execution_count": null, "id": "0a47a3fe-7c40-4c6b-9bce-93e172639e54", "metadata": { "tags": [] }, "outputs": [], "source": [ "print(rest.get_job_output(n)[:400])" ] }, { "cell_type": "markdown", "id": "f7446dd9-739c-4049-95f7-3b6080a8a2f3", "metadata": {}, "source": [ "We can also get numeric results through the WebMO library, such as the energy." ] }, { "cell_type": "code", "execution_count": null, "id": "89c96c8c-6dee-42d3-b685-49e6d709f5fc", "metadata": { "tags": [] }, "outputs": [], "source": [ "results = rest.get_job_results(n)\n", "energy = results['properties']['rhf_energy']['value']\n", "units = results['properties']['rhf_energy']['units']\n", "print(\"Energy: {} {}\".format(energy, units))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.5" } }, "nbformat": 4, "nbformat_minor": 5 }