{ "cells": [ { "cell_type": "markdown", "id": "a92f9abe-116b-4afb-b2e7-53dc45ba488c", "metadata": {}, "source": [ "## Initial Imports" ] }, { "cell_type": "code", "execution_count": 1, "id": "ea87db27-0f82-41c7-8e7f-5dfe9fef669b", "metadata": {}, "outputs": [], "source": [ "import sys\n", "from scm.plams import AMSJob, Settings, from_smiles" ] }, { "cell_type": "markdown", "id": "e5e7849e-730d-46ff-8536-f5cb19eb3174", "metadata": {}, "source": [ "## Run/Load Job with ForceField Information" ] }, { "cell_type": "markdown", "id": "a6b5a174-741b-4366-96cf-739bc90cfbab", "metadata": {}, "source": [ "First run a reference calculation where charges are guessed (using DFTB by default):" ] }, { "cell_type": "code", "execution_count": 2, "id": "2d3fb20f-31f1-4317-96ff-fe8e05d25963", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[25.03|09:47:58] JOB plamsjob STARTED\n", "[25.03|09:47:58] JOB plamsjob RUNNING\n", "[25.03|09:47:59] JOB plamsjob FINISHED\n", "[25.03|09:47:59] JOB plamsjob SUCCESSFUL\n" ] } ], "source": [ "ref_job = AMSJob.from_input(\n", " \"\"\"\n", "Task GeometryOptimization\n", "\n", "GeometryOptimization\n", " Convergence Step=1.0e-3\n", "End\n", "\n", "System\n", " Atoms\n", " C 0.0 0.0 0.0\n", " O 1.13 0.0 0.0\n", " C 0.0 0.0 2.1\n", " O 1.13 0.0 1.9\n", " End\n", "End\n", "\n", "Engine ForceField\n", " Verbosity Verbose\n", " GuessCharges True\n", "EndEngine\n", "\"\"\"\n", ")\n", "\n", "# Alternatively, load a previously run calculation\n", "# ref_job = AMSJob.load_external(\"./plams_workdir/plamsjob/ams.rkf\")\n", "\n", "ref_job.run();" ] }, { "cell_type": "markdown", "id": "f589a951-1dd0-4e98-a837-8eabfa71c42c", "metadata": {}, "source": [ "## Reuse ForceField Parameters" ] }, { "cell_type": "markdown", "id": "4f4ab593-cbbb-4a2d-bb19-0d0b17412d82", "metadata": {}, "source": [ "Extract the charges and types from the job results and add them as properties on the molecule:" ] }, { "cell_type": "code", "execution_count": 3, "id": "685756e8-c9da-4c53-9ec0-494b1c883e6c", "metadata": {}, "outputs": [], "source": [ "charges, types, patch = ref_job.results.get_forcefield_params()" ] }, { "cell_type": "code", "execution_count": 4, "id": "0d79278c-ef3e-41a4-a39b-489a62b2fb01", "metadata": {}, "outputs": [], "source": [ "mol = ref_job.molecule[\"\"].copy()\n", "\n", "for i, at in enumerate(mol.atoms):\n", " at.properties.ForceField.Charge = charges[i]\n", " at.properties.ForceField.Type = types[i]" ] }, { "cell_type": "code", "execution_count": 5, "id": "34a5b1ba-bdc3-4e3b-abd2-2e96ead16f00", "metadata": {}, "outputs": [], "source": [ "sett = Settings()\n", "sett.input.AMS.Task = \"SinglePoint\"\n", "sett.input.ForceField.Type = \"UFF\"" ] }, { "cell_type": "code", "execution_count": 6, "id": "0f9c454d-f41b-425b-8f36-4c64fcd5137f", "metadata": {}, "outputs": [], "source": [ "# Create a patch file if required\n", "if patch:\n", " with open(\"patch.dat\", \"w\") as outfile:\n", " outfile.write(str(patch))\n", " outfile.close()\n", " # For example with:\n", " # sett.input.ForceField.GAFF.ForceFieldPatchFile = \"patch.dat\"" ] }, { "cell_type": "code", "execution_count": 7, "id": "06813554-f47b-457e-ba1d-735abea20cce", "metadata": {}, "outputs": [], "source": [ "job = AMSJob(molecule=mol, settings=sett)" ] }, { "cell_type": "code", "execution_count": 8, "id": "8c78410b-c361-4931-9087-65af6aa8c4b2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Task SinglePoint\n", "\n", "System\n", " Atoms\n", " C 0.0000000000 0.0000000000 0.0000000000 ForceField.Charge=0.2881959744167275 ForceField.Type=C_1\n", " O 1.1300000000 0.0000000000 0.0000000000 ForceField.Charge=-0.2676126103828702 ForceField.Type=O_2\n", " C 0.0000000000 0.0000000000 2.1000000000 ForceField.Charge=0.2536150412119178 ForceField.Type=C_1\n", " O 1.1300000000 0.0000000000 1.9000000000 ForceField.Charge=-0.27419840524497996 ForceField.Type=O_2\n", " End\n", "End\n", "\n", "Engine ForceField\n", " Type UFF\n", "EndEngine\n", "\n", "\n" ] } ], "source": [ "print(job.get_input())" ] }, { "cell_type": "code", "execution_count": 9, "id": "c6b469a5-70f7-4db6-a163-2ea4093717ce", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[25.03|09:47:59] JOB plamsjob STARTED\n", "[25.03|09:47:59] Renaming job plamsjob to plamsjob.002\n", "[25.03|09:47:59] JOB plamsjob.002 RUNNING\n", "[25.03|09:48:00] JOB plamsjob.002 FINISHED\n", "[25.03|09:48:00] JOB plamsjob.002 SUCCESSFUL\n" ] } ], "source": [ "job.run();" ] } ], "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.8.16" } }, "nbformat": 4, "nbformat_minor": 5 }