{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Molpro tutorial\n", "\n", "The `molpro` module contains the `Molpro` convenience class, which is python wrapper for running the [Molpro] program with methods for writing input files, running the calculations and parsing the output files. \n", "\n", "[Molpro]: https://www.molpro.net/" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from chemtools.calculators.molpro import Molpro" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Molpro wrapper\n", "\n", "`Molpro` object can be created by either providing the path to the molpro executable with `executable` keyword argument or name of the environmental variable holding the path through `exevar`." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "molpro = Molpro(exevar=\"MOLPRO_EXE\",\n", " runopts=[\"-s\", \"-n\", \"1\"],\n", " scratch=\"/home/lmentel/scratch\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we can write some sample molpro input and run in from python using the `Molpro` object created earlier." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "inpstr = '''***,H2O finite field calculations\n", "r=1.85,theta=104 !set geometry parameters\n", "geometry={O; !z-matrix input\n", "H1,O,r;\n", "H2,O,r,H1,theta}\n", "\n", "basis=avtz !define default basis\n", "\n", "hf\n", "ccsd(t)\n", "'''\n", "\n", "with open('h2o.inp', 'w') as finp:\n", " finp.write(inpstr)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`run` method runs the job and returns the ouput file name" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "output = molpro.run('h2o.inp')" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'h2o.out'" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "output" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Parsing the results\n", "\n", "To check if the calculation finished without errors you can use `accomplished` method" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "molpro.accomplished(output)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-76.058288041466" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "molpro.parse(output, 'hf total energy')" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "molpro.parse(output, 'mp2 total energy')" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-76.341780640047" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "molpro.parse(output, 'ccsd(t) total energy')" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "8.99162654" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "molpro.parse(output, 'regexp', regularexp=r'NUCLEAR REPULSION ENERGY\\s*(-?\\d+\\.\\d+)')" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "application/json": { "Software versions": [ { "module": "Python", "version": "3.6.3 64bit [GCC 7.2.0]" }, { "module": "IPython", "version": "6.2.1" }, { "module": "OS", "version": "Linux 4.9.0 4 amd64 x86_64 with debian 9.1" }, { "module": "chemtools", "version": "0.8.4" } ] }, "text/html": [ "
SoftwareVersion
Python3.6.3 64bit [GCC 7.2.0]
IPython6.2.1
OSLinux 4.9.0 4 amd64 x86_64 with debian 9.1
chemtools0.8.4
Mon Nov 27 16:49:17 2017 CET
" ], "text/latex": [ "\\begin{tabular}{|l|l|}\\hline\n", "{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n", "Python & 3.6.3 64bit [GCC 7.2.0] \\\\ \\hline\n", "IPython & 6.2.1 \\\\ \\hline\n", "OS & Linux 4.9.0 4 amd64 x86\\_64 with debian 9.1 \\\\ \\hline\n", "chemtools & 0.8.4 \\\\ \\hline\n", "\\hline \\multicolumn{2}{|l|}{Mon Nov 27 16:49:17 2017 CET} \\\\ \\hline\n", "\\end{tabular}\n" ], "text/plain": [ "Software versions\n", "Python 3.6.3 64bit [GCC 7.2.0]\n", "IPython 6.2.1\n", "OS Linux 4.9.0 4 amd64 x86_64 with debian 9.1\n", "chemtools 0.8.4\n", "Mon Nov 27 16:49:17 2017 CET" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%version_information chemtools" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.3" } }, "nbformat": 4, "nbformat_minor": 1 }