{ "cells": [ { "cell_type": "markdown", "id": "b31dbac2", "metadata": {}, "source": [ "## Initial Imports" ] }, { "cell_type": "code", "execution_count": 1, "id": "37518443", "metadata": {}, "outputs": [], "source": [ "from scm.plams import AMSResults, Units, Settings, read_molecules, AMSJob" ] }, { "cell_type": "markdown", "id": "513c64f0", "metadata": { "lines_to_next_cell": 2 }, "source": [ "## Helper Functions\n", "Set up a couple of useful functions for extracting results." ] }, { "cell_type": "code", "execution_count": 2, "id": "0cc97134", "metadata": {}, "outputs": [], "source": [ "def get_excitations(results):\n", " \"\"\"Returns excitation energies (in eV) and oscillator strengths (in Debye).\"\"\"\n", " if results.job.ok():\n", " exci_energies_au = results.readrkf(\"Excitations SS A\", \"excenergies\", file=\"engine\")\n", " oscillator_str_au = results.readrkf(\n", " \"Excitations SS A\", \"oscillator strengths\", file=\"engine\"\n", " )\n", " # The results are stored in atomic units. Convert them to more convenient units:\n", " exci_energies = Units.convert(exci_energies_au, \"au\", \"eV\")\n", " oscillator_str = Units.convert(oscillator_str_au, \"au\", \"Debye\")\n", " return exci_energies, oscillator_str\n", " else:\n", " return [], []" ] }, { "cell_type": "code", "execution_count": 3, "id": "4e1d79c2", "metadata": {}, "outputs": [], "source": [ "def has_good_excitations(results, min_energy, max_energy, oscillator_str_threshold=1e-4):\n", " \"\"\"Returns True if there is at least one excitation with non-vanishing oscillator strength\n", " in the energy range [min_energy, max_energy]. Unit for min_energy and max energy: eV.\"\"\"\n", " exci_energies, oscillator_str = get_excitations(results)\n", " for e, o in zip(exci_energies, oscillator_str):\n", " if min_energy < e < max_energy and o > oscillator_str_threshold:\n", " return True\n", " return False" ] }, { "cell_type": "markdown", "id": "bc177584", "metadata": {}, "source": [ "## Calculation settings\n", "\n", "Configure the settings for the various jobs." ] }, { "cell_type": "code", "execution_count": 4, "id": "a4d1517e", "metadata": {}, "outputs": [], "source": [ "# Settings for geometry optimization with the AMS driver:\n", "go_sett = Settings()\n", "go_sett.input.ams.Task = \"GeometryOptimization\"\n", "go_sett.input.ams.GeometryOptimization.Convergence.Gradients = 1.0e-4" ] }, { "cell_type": "code", "execution_count": 5, "id": "3c3c7741", "metadata": {}, "outputs": [], "source": [ "# Settings for single point calculation with the AMS driver\n", "sp_sett = Settings()\n", "sp_sett.input.ams.Task = \"SinglePoint\"" ] }, { "cell_type": "code", "execution_count": 6, "id": "676983ca", "metadata": {}, "outputs": [], "source": [ "# Settings for the DFTB engine (including excitations)\n", "dftb_sett = Settings()\n", "dftb_sett.input.dftb.Model = \"SCC-DFTB\"\n", "dftb_sett.input.dftb.ResourcesDir = \"QUASINANO2015\"\n", "dftb_sett.input.dftb.Properties.Excitations.TDDFTB.calc = \"singlet\"\n", "dftb_sett.input.dftb.Properties.Excitations.TDDFTB.lowest = 10\n", "dftb_sett.input.dftb.Occupation.Temperature = 5.0" ] }, { "cell_type": "code", "execution_count": 7, "id": "237a5c2b", "metadata": {}, "outputs": [], "source": [ "# Settings for the geometry optimization with the ADF engine\n", "adf_sett = Settings()\n", "adf_sett.input.adf.Basis.Type = \"DZP\"\n", "adf_sett.input.adf.NumericalQuality = \"Basic\"" ] }, { "cell_type": "code", "execution_count": 8, "id": "7a6bfee6", "metadata": { "lines_to_next_cell": 2 }, "outputs": [], "source": [ "# Settings for the excitation calculation using the ADF engine\n", "adf_exci_sett = Settings()\n", "adf_exci_sett.input.adf.Basis.Type = \"TZP\"\n", "adf_exci_sett.input.adf.XC.GGA = \"PBE\"\n", "adf_exci_sett.input.adf.NumericalQuality = \"Basic\"\n", "adf_exci_sett.input.adf.Symmetry = \"NoSym\"\n", "adf_exci_sett.input.adf.Excitations.lowest = 10\n", "adf_exci_sett.input.adf.Excitations.OnlySing = \"\"" ] }, { "cell_type": "markdown", "id": "b580c98a", "metadata": {}, "source": [ "## Load Molecules\n", "Import all xyz files in the folder 'molecules'." ] }, { "cell_type": "code", "execution_count": 9, "id": "ad25a47b", "metadata": { "lines_to_next_cell": 2 }, "outputs": [], "source": [ "from pathlib import Path\n", "\n", "molecules_dir = Path(\"molecules\")\n", "molecules_dir.mkdir(exist_ok=True)\n", "\n", "alh3_xyz = molecules_dir / \"AlH3.xyz\"\n", "cscl2_xyz = molecules_dir / \"CSCl2.xyz\"\n", "h20_xyz = molecules_dir / \"H2O.xyz\"\n", "nh3_xyz = molecules_dir / \"NH3.xyz\"\n", "s2cl2_xyz = molecules_dir / \"S2Cl2.xyz\"\n", "\n", "alh3_xyz.write_text(\"\"\"\\\n", "4\n", "\n", "Al 0.0 0.0 0.0\n", "H 1.0 0.0 0.0\n", "H 0.5 1.0 0.0\n", "H 0.5 -1.0 0.0\n", "\"\"\")\n", "\n", "cscl2_xyz.write_text(\"\"\"\\\n", "4\n", "\n", "C 0.0 0.0 0.0\n", "S 0.0 0.0 -1.3\n", "Cl 0.0 1.0 1.0\n", "Cl 0.0 -1.0 1.0\n", "\"\"\")\n", "\n", "h20_xyz.write_text(\"\"\"\\\n", "3\n", "\n", "O 0.0 0.0 0.0\n", "H 1.0 0.0 0.0\n", "H 0.0 1.0 0.0\n", "\"\"\")\n", "\n", "nh3_xyz.write_text(\"\"\"\\\n", "4\n", "\n", "N 0.0 0.0 0.1\n", "H 1.0 0.0 0.0\n", "H 0.5 1.0 0.0\n", "H 0.5 -1.0 0.0\n", "\"\"\")\n", "\n", "s2cl2_xyz.write_text(\"\"\"\\\n", "4\n", "\n", "S 0.0 0.0 1.3\n", "S 0.0 0.0 -1.3\n", "Cl 0.1 0.6 2.3\n", "Cl 0.1 -0.6 -2.3\n", "\"\"\")\n", "\n", "molecules = read_molecules(\"molecules\")" ] }, { "cell_type": "markdown", "id": "a070bf30", "metadata": {}, "source": [ "## DFTB Prescreen\n", "Perform an initial prescreen of all molecules with DFTB." ] }, { "cell_type": "code", "execution_count": 10, "id": "12229062", "metadata": {}, "outputs": [], "source": [ "promising_molecules = {}" ] }, { "cell_type": "code", "execution_count": 11, "id": "6a53d3af", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[09.04|17:38:27] JOB DFTB_H2O STARTED\n", "[09.04|17:38:27] JOB DFTB_H2O RUNNING\n", "[09.04|17:38:27] JOB DFTB_H2O FINISHED\n", "[09.04|17:38:27] JOB DFTB_H2O SUCCESSFUL\n", "[09.04|17:38:27] JOB DFTB_AlH3 STARTED\n", "[09.04|17:38:27] JOB DFTB_AlH3 RUNNING\n", "[09.04|17:38:28] JOB DFTB_AlH3 FINISHED\n", "[09.04|17:38:28] JOB DFTB_AlH3 SUCCESSFUL\n", "[09.04|17:38:28] JOB DFTB_NH3 STARTED\n", "[09.04|17:38:28] JOB DFTB_NH3 RUNNING\n", "[09.04|17:38:29] JOB DFTB_NH3 FINISHED\n", "[09.04|17:38:29] JOB DFTB_NH3 SUCCESSFUL\n", "[09.04|17:38:29] JOB DFTB_S2Cl2 STARTED\n", "[09.04|17:38:29] JOB DFTB_S2Cl2 RUNNING\n", "[09.04|17:38:30] JOB DFTB_S2Cl2 FINISHED\n", "[09.04|17:38:30] JOB DFTB_S2Cl2 SUCCESSFUL\n", "[09.04|17:38:30] JOB DFTB_CSCl2 STARTED\n", "[09.04|17:38:30] JOB DFTB_CSCl2 RUNNING\n", "[09.04|17:38:30] JOB DFTB_CSCl2 FINISHED\n", "[09.04|17:38:30] JOB DFTB_CSCl2 SUCCESSFUL\n" ] } ], "source": [ "for name, mol in molecules.items():\n", " dftb_job = AMSJob(name=\"DFTB_\" + name, molecule=mol, settings=go_sett + dftb_sett)\n", " dftb_results = dftb_job.run()\n", "\n", " if has_good_excitations(dftb_results, 1, 6):\n", " promising_molecules[name] = dftb_results.get_main_molecule()" ] }, { "cell_type": "code", "execution_count": 12, "id": "610170c1", "metadata": { "lines_to_next_cell": 2 }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Found 2 promising molecules with DFTB\n" ] } ], "source": [ "print(f\"Found {len(promising_molecules)} promising molecules with DFTB\")" ] }, { "cell_type": "markdown", "id": "1c7a3c74", "metadata": {}, "source": [ "## Optimization and excitations calculation with ADF\n", "For each of the molecules identified in the prescreen, run a further calculation with ADF." ] }, { "cell_type": "code", "execution_count": 13, "id": "7455a98a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[09.04|17:38:30] JOB ADF_GO_S2Cl2 STARTED\n", "[09.04|17:38:30] JOB ADF_GO_S2Cl2 RUNNING\n", "[09.04|17:38:35] JOB ADF_GO_S2Cl2 FINISHED\n", "[09.04|17:38:35] JOB ADF_GO_S2Cl2 SUCCESSFUL\n", "[09.04|17:38:35] JOB ADF_exci_S2Cl2 STARTED\n", "[09.04|17:38:35] JOB ADF_exci_S2Cl2 RUNNING\n", "[09.04|17:38:40] JOB ADF_exci_S2Cl2 FINISHED\n", "[09.04|17:38:40] JOB ADF_exci_S2Cl2 SUCCESSFUL\n", "Molecule S2Cl2 has excitation(s) satysfying our criteria!\n", " Atoms: \n", " 1 S -0.658306 -0.316643 0.909151\n", " 2 S -0.658306 0.316643 -0.909151\n", " 3 Cl 0.758306 0.752857 2.053019\n", " 4 Cl 0.758306 -0.752857 -2.053019\n", "\n", "Excitation energy [eV], oscillator strength:\n", " 3.4107, 0.0114\n", " 3.5386, 0.0160\n", " 3.5400, 0.0011\n", " 3.9864, 0.1105\n", " 4.3225, 0.0049\n", " 4.3513, 0.2551\n", " 4.7544, 0.0011\n", " 4.9414, 0.0105\n", " 5.3188, 0.0036\n", " 5.3272, 0.0721\n", "[09.04|17:38:40] JOB ADF_GO_CSCl2 STARTED\n", "[09.04|17:38:40] JOB ADF_GO_CSCl2 RUNNING\n", "[09.04|17:38:44] JOB ADF_GO_CSCl2 FINISHED\n", "[09.04|17:38:44] JOB ADF_GO_CSCl2 SUCCESSFUL\n", "[09.04|17:38:44] JOB ADF_exci_CSCl2 STARTED\n", "[09.04|17:38:44] JOB ADF_exci_CSCl2 RUNNING\n", "[09.04|17:38:49] JOB ADF_exci_CSCl2 FINISHED\n", "[09.04|17:38:49] JOB ADF_exci_CSCl2 SUCCESSFUL\n" ] } ], "source": [ "for name, mol in promising_molecules.items():\n", " adf_go_job = AMSJob(name=\"ADF_GO_\" + name, molecule=mol, settings=go_sett + adf_sett)\n", " adf_go_job.run()\n", "\n", " optimized_mol = adf_go_job.results.get_main_molecule()\n", "\n", " adf_exci_job = AMSJob(\n", " name=\"ADF_exci_\" + name, molecule=optimized_mol, settings=sp_sett + adf_exci_sett\n", " )\n", " adf_exci_results = adf_exci_job.run()\n", "\n", " if has_good_excitations(adf_exci_results, 2, 4):\n", " print(f\"Molecule {name} has excitation(s) satysfying our criteria!\")\n", " print(optimized_mol)\n", " exci_energies, oscillator_str = get_excitations(adf_exci_results)\n", " print(\"Excitation energy [eV], oscillator strength:\")\n", " for e, o in zip(exci_energies, oscillator_str):\n", " print(f\"{e:8.4f}, {o:8.4f}\")" ] }, { "cell_type": "code", "execution_count": null, "id": "a558de4b", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "executable": "/usr/bin/env amspython", "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 }