{ "cells": [ { "cell_type": "markdown", "id": "660891d6", "metadata": {}, "source": [ "## Initial Imports" ] }, { "cell_type": "code", "execution_count": 1, "id": "f46387de", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "PLAMS working folder: /path/plams/examples/ManyJobsInParallel/plams_workdir\n" ] } ], "source": [ "import multiprocessing\n", "from scm.plams import JobRunner, config, Settings, read_molecules, AMSJob, init\n", "\n", "# this line is not required in AMS2025+\n", "init()" ] }, { "cell_type": "markdown", "id": "aaced0e9", "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": "155d9307", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running up to 12 jobs in parallel simultaneously\n" ] } ], "source": [ "maxjobs = multiprocessing.cpu_count()\n", "print(\"Running up to {} jobs in parallel simultaneously\".format(maxjobs))" ] }, { "cell_type": "code", "execution_count": 3, "id": "657dbdda", "metadata": {}, "outputs": [], "source": [ "config.default_jobrunner = JobRunner(parallel=True, maxjobs=maxjobs)" ] }, { "cell_type": "code", "execution_count": 4, "id": "ada7e9d2", "metadata": {}, "outputs": [], "source": [ "config.job.runscript.nproc = 1" ] }, { "cell_type": "markdown", "id": "45a9988b", "metadata": {}, "source": [ "## Load Molecules\n", "\n", "Load set of molecules from directory containing xyz files." ] }, { "cell_type": "code", "execution_count": 5, "id": "decb52b9", "metadata": {}, "outputs": [], "source": [ "molecules = read_molecules(\"molecules\")" ] }, { "cell_type": "markdown", "id": "7806fa9d", "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": "a3b89493", "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": "9b3ab166", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[10.02|15:50:35] JOB Acetic_acid STARTED\n", "[10.02|15:50:35] JOB Benzene STARTED\n", "[10.02|15:50:35] JOB Butane STARTED\n", "[10.02|15:50:35] JOB Ethane STARTED\n", "[10.02|15:50:35] JOB Ethanol STARTED\n", "[10.02|15:50:35] JOB Butane RUNNING\n", "[10.02|15:50:35] JOB Formic_acid STARTED\n", "[10.02|15:50:35] JOB Acetic_acid RUNNING\n", "[10.02|15:50:35] JOB Methanol STARTED\n", "[10.02|15:50:35] JOB Water STARTED\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": "a2bc8668", "metadata": {}, "source": [ "## Results\n", "\n", "Print a table of results only for the successful calculations." ] }, { "cell_type": "code", "execution_count": 8, "id": "0283d525", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[10.02|15:50:35] Waiting for job Acetic_acid to finish\n", "[10.02|15:50:35] JOB Formic_acid RUNNING\n", "[10.02|15:50:35] JOB Benzene RUNNING\n", "[10.02|15:50:35] JOB Water RUNNING\n", "[10.02|15:50:35] JOB Ethane RUNNING\n", "[10.02|15:50:35] JOB Ethanol RUNNING\n", "[10.02|15:50:35] JOB Methanol RUNNING\n", "[10.02|15:50:36] JOB Water FINISHED\n", "[10.02|15:50:36] JOB Formic_acid FINISHED\n", "[10.02|15:50:36] JOB Butane FINISHED\n", "[10.02|15:50:36] JOB Acetic_acid FINISHED\n", "[10.02|15:50:36] JOB Formic_acid SUCCESSFUL\n", "[10.02|15:50:36] JOB Butane SUCCESSFUL\n", "[10.02|15:50:36] JOB Acetic_acid SUCCESSFUL\n", "[10.02|15:50:36] Waiting for job Benzene to finish\n", "[10.02|15:50:36] JOB Water SUCCESSFUL\n", "[10.02|15:50:36] JOB Ethane FINISHED\n", "[10.02|15:50:36] JOB Ethane SUCCESSFUL\n", "[10.02|15:50:36] JOB Methanol FINISHED\n", "[10.02|15:50:36] JOB Methanol SUCCESSFUL\n", "[10.02|15:50:36] JOB Benzene FINISHED\n", "[10.02|15:50:36] JOB Benzene SUCCESSFUL\n", "[10.02|15:50:37] Waiting for job Ethanol to finish\n", "[10.02|15:50:37] JOB Ethanol FINISHED\n", "[10.02|15:50:37] JOB Ethanol SUCCESSFUL\n", "Energy for Acetic_acid : -9913.297 kcal/mol\n", "Energy for Benzene : -12039.482 kcal/mol\n", "Energy for Butane : -8699.182 kcal/mol\n", "Energy for Ethane : -4686.354 kcal/mol\n", "Energy for Ethanol : -7629.287 kcal/mol\n", "Energy for Formic_acid : -7890.662 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(\"Energy for {:<12}: {:>10.3f} kcal/mol\".format(result.name, result.get_energy(unit=\"kcal/mol\")))" ] }, { "cell_type": "code", "execution_count": null, "id": "5d199930", "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 }