{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "intro",
   "metadata": {},
   "source": [
    "# Getting started with OMNI-P3x\n",
    "\n",
    "Download pyrazine.xyz and pyrazine_tddft.json into the same directory. Use a Python environment with OMNI-P3x and aimnetex installed."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "single-point",
   "metadata": {},
   "source": [
    "## Excitation energies and gradients\n",
    "\n",
    "Predict the ground and three excited states at one geometry."
   ]
  },
  {
   "cell_type": "code",
   "id": "predict",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "import mlatom as ml\n",
    "\n",
    "model = ml.models.methods(method='OMNI-P3x', nthreads=4)\n",
    "mol = ml.data.molecule.from_xyz_file('pyrazine.xyz')\n",
    "model.predict(molecule=mol, nstates=4, calculate_energy_gradients=True)\n",
    "\n",
    "print(f'S0 energy: {mol.electronic_states[0].energy:.6f} Hartree')\n",
    "for state, (energy, strength) in enumerate(\n",
    "    zip(mol.excitation_energies * ml.constants.Hartree2eV, mol.oscillator_strengths),\n",
    "    start=1,\n",
    "):\n",
    "    print(f'S{state}: {energy:.3f} eV, oscillator strength {strength:.4f}')\n",
    "print('S1 gradient (Hartree/angstrom):')\n",
    "print(mol.electronic_states[1].energy_gradients)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "absorption",
   "metadata": {},
   "source": [
    "## UV/vis absorption\n",
    "\n",
    "Predict ten excited states and plot the broadened absorption spectrum, together with TD-DFT (TDA-ωB97X-D/def2-SVP) at the same geometry."
   ]
  },
  {
   "cell_type": "code",
   "id": "plot",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "model.predict(molecule=mol, nstates=11)\n",
    "tddft = ml.data.molecule.load('pyrazine_tddft.json', format='json')\n",
    "ml.spectra.plot_uvvis(molecular_database=ml.data.molecular_database(molecules=[mol, tddft]),\n",
    "                      spc=True, band_width=0.3, labels=['OMNI-P3x', 'TDA-ωB97X-D/def2-SVP'],\n",
    "                      filename='pyrazine_uvvis.png', title='Pyrazine')\n",
    "\n",
    "from IPython.display import Image, display\n",
    "display(Image(filename=\"pyrazine_uvvis.png\"))\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
