{ "cells": [ { "cell_type": "markdown", "id": "98a958cb", "metadata": {}, "source": [ "## Initial Imports" ] }, { "cell_type": "code", "execution_count": 1, "id": "85399afc", "metadata": {}, "outputs": [], "source": [ "import psutil\n", "from scm.plams import JobRunner, config, Settings, from_smiles, AMSJob" ] }, { "cell_type": "markdown", "id": "60e16f28", "metadata": {}, "source": [ "## Configure Job Runner\n", "\n", "Set the default job runner to run in parallel. Run as many jobs simultaneously as there are cpu on the system. In addition, set the number of cores for each job to 1." ] }, { "cell_type": "code", "execution_count": 2, "id": "70d44f43", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running up to 12 jobs in parallel simultaneously\n" ] } ], "source": [ "maxjobs = psutil.cpu_count(logical=False)\n", "print(\"Running up to {} jobs in parallel simultaneously\".format(maxjobs))" ] }, { "cell_type": "code", "execution_count": 3, "id": "e2e2cd18", "metadata": {}, "outputs": [], "source": [ "config.default_jobrunner = JobRunner(parallel=True, maxjobs=maxjobs)" ] }, { "cell_type": "code", "execution_count": 4, "id": "8f04a20b", "metadata": {}, "outputs": [], "source": [ "config.job.runscript.nproc = 1" ] }, { "cell_type": "markdown", "id": "58ccc5bc", "metadata": {}, "source": [ "## Load Molecules\n", "\n", "Generate a set of molecules from SMILES strings." ] }, { "cell_type": "code", "execution_count": 5, "id": "beb094b5", "metadata": {}, "outputs": [], "source": [ "molecule_smiles = {\n", " \"Acetic_acid\": \"CC(=O)O\",\n", " \"Benzene\": \"c1ccccc1\",\n", " \"Butane\": \"CCCC\",\n", " \"Ethane\": \"CC\",\n", " \"Ethanol\": \"CCO\",\n", " \"Formic_acid\": \"C(=O)O\",\n", " \"Methanol\": \"CO\",\n", " \"Water\": \"O\",\n", "}\n", "\n", "molecules = {\n", " name: from_smiles(smiles, forcefield=\"uff\") for name, smiles in molecule_smiles.items()\n", "}" ] }, { "cell_type": "markdown", "id": "e5d7f39e", "metadata": {}, "source": [ "## Set Up and Run Jobs\n", "\n", "Configure the calculation settings in the `Settings` object. Run a geometry optimization job for each molecule in parallel." ] }, { "cell_type": "code", "execution_count": 6, "id": "27288e52", "metadata": {}, "outputs": [], "source": [ "settings = Settings()\n", "settings.input.ams.Task = \"GeometryOptimization\"\n", "settings.input.dftb.Model = \"GFN1-xTB\"" ] }, { "cell_type": "code", "execution_count": 7, "id": "45763a9e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[10.04|11:35:08] JOB Acetic_acid STARTED\n", "[10.04|11:35:08] JOB Benzene STARTED\n", "[10.04|11:35:08] JOB Butane STARTED\n", "[10.04|11:35:08] JOB Ethane STARTED\n", "[10.04|11:35:08] JOB Ethanol STARTED\n", "[10.04|11:35:08] JOB Formic_acid STARTED\n", "[10.04|11:35:08] JOB Methanol STARTED\n", "[10.04|11:35:08] JOB Water STARTED\n", "[10.04|11:35:08] JOB Acetic_acid RUNNING\n", "[10.04|11:35:08] JOB Benzene RUNNING\n" ] } ], "source": [ "results = []\n", "for name, molecule in sorted(molecules.items()):\n", " job = AMSJob(molecule=molecule, settings=settings, name=name)\n", " results.append(job.run())" ] }, { "cell_type": "markdown", "id": "d819cc3c", "metadata": {}, "source": [ "## Results\n", "\n", "Print a table of results only for the successful calculations." ] }, { "cell_type": "code", "execution_count": 8, "id": "1d5b0fdd", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[10.04|11:35:08] Waiting for job Acetic_acid to finish\n", "[10.04|11:35:08] JOB Butane RUNNING\n", "[10.04|11:35:08] JOB Ethanol RUNNING\n", "[10.04|11:35:08] JOB Ethane RUNNING\n", "[10.04|11:35:08] JOB Formic_acid RUNNING\n", "[10.04|11:35:08] JOB Water RUNNING\n", "[10.04|11:35:08] JOB Methanol RUNNING\n", "[10.04|11:35:08] JOB Benzene FINISHED\n", "[10.04|11:35:08] JOB Water FINISHED\n", "[10.04|11:35:08] JOB Ethane FINISHED\n", "[10.04|11:35:08] JOB Acetic_acid FINISHED\n", "[10.04|11:35:08] JOB Methanol FINISHED\n", "[10.04|11:35:08] JOB Formic_acid FINISHED\n", "[10.04|11:35:08] JOB Ethanol FINISHED\n", "[10.04|11:35:08] JOB Methanol SUCCESSFUL\n", "[10.04|11:35:08] JOB Ethane SUCCESSFUL\n", "[10.04|11:35:08] JOB Benzene SUCCESSFUL\n", "[10.04|11:35:08] JOB Butane FINISHED\n", "[10.04|11:35:08] JOB Water SUCCESSFUL\n", "[10.04|11:35:08] JOB Acetic_acid SUCCESSFUL\n", "[10.04|11:35:08] JOB Formic_acid SUCCESSFUL\n", "[10.04|11:35:08] JOB Ethanol SUCCESSFUL\n", "[10.04|11:35:08] Waiting for job Butane to finish\n", "[10.04|11:35:08] JOB Butane SUCCESSFUL\n", "Energy for Acetic_acid : -9906.399 kcal/mol\n", "Energy for Benzene : -9973.315 kcal/mol\n", "Energy for Butane : -8699.182 kcal/mol\n", "Energy for Ethane : -4686.354 kcal/mol\n", "Energy for Ethanol : -7630.501 kcal/mol\n", "Energy for Formic_acid : -7898.338 kcal/mol\n", "Energy for Methanol : -5621.724 kcal/mol\n", "Energy for Water : -3618.401 kcal/mol\n" ] } ], "source": [ "# Only print the results of the succesful caluclations:\n", "for result in [r for r in results if r.ok()]:\n", " print(\n", " \"Energy for {:<12}: {:>10.3f} kcal/mol\".format(\n", " result.name, result.get_energy(unit=\"kcal/mol\")\n", " )\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "16901817", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "executable": "/usr/bin/env plams", "main_language": "python", "notebook_metadata_filter": "-all" }, "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.8.16" } }, "nbformat": 4, "nbformat_minor": 5 }