{ "cells": [ { "cell_type": "markdown", "id": "1b883adf", "metadata": {}, "source": [ "# $\\text{Preparing } \\textit{ab-initio} \\text{ data}$" ] }, { "cell_type": "markdown", "id": "5d7273cd", "metadata": {}, "source": [ "## Displacements using CFOUR\n", "\n", "To create displaced geometries in `.xyz` format, we will follow these steps:\n", "\n", "1. **Geometry Optimization and Frequency Calculation**:\n", " - Use **CFOUR** to optimize the molecular geometry and compute harmonic frequencies.\n", " - Extract the results from the `output` file generated by the harmonic frequency calculation.\n", "\n", "2. **Generating Displacements**:\n", " - Utilize the `cfour_displacements.py` script located in the `Tools` directory to process the output and generate the displaced geometries in `.xyz` format." ] }, { "cell_type": "markdown", "id": "a6c4991a", "metadata": {}, "source": [ "### Configuring and Running the `cfour_displacements.py` Script\n", "\n", "To generate displaced geometries using the `cfour_displacements.py` script, configure the following variables within the script:\n", "\n", "```python\n", "############## Variables to Change ###############\n", "\n", "inputfile = \"\" # Output file from CFOUR frequency calculation\n", "natoms = 0 # Number of atoms in the molecule\n", "is_linear = # Indicate whether the molecule is linear (True or false)\n", "\n", "min_displacement = 0.0 # Minimum displacement in dimensionless units\n", "max_displacement = 0.0 # Maximum displacement in dimensionless units\n", "step_displacement = 0.0 # Step size for displacement in dimensionless units\n", "\n", "outputfile = \"\" # Output directory for the displaced geometries\n", "##################################################\n", "```" ] }, { "cell_type": "markdown", "id": "7949df76", "metadata": {}, "source": [ "After configuring the variables, execute the script using the following command:\n", "```bash\n", "python3 cfour_displacements.py\n", "```\n", "\n", "### Displaced Geometries\n", "Upon executing the `cfour_displacements.py` script, a directory will be created containing all displaced geometries in `.xyz` format. The naming convention for these files is as follows:\n", "\n", "```\n", "geo_v{normal_mode}_{displacement}.xyz\n", "```\n", "\n", "- **`normal_mode`**: Indicates the vibrational normal mode.\n", "- **`displacement`**: Specifies the displacement value in dimensionless units, including the sign for negative displacements.\n", "\n", "For example, `geo_v1_-01.xyz` for a negative displacement and `geo_v1_01.xyz` for a positive displacement." ] }, { "cell_type": "markdown", "id": "29d3c16b", "metadata": {}, "source": [ "## Preparing ADCC Input Files\n", "\n", "### Running ADCC Calculations\n", "To process these geometry files and run ADCC calculations, you can use the provided Python script `run_adc.py`. This script takes a single geometry file as input, performs an SCF calculation using pyscf, computes excited states using adcc, and generates a molden file.\n", "\n", "#### run_adc.py\n", "```python\n", "import numpy as np\n", "import sys\n", "import adcc\n", "import pyscf\n", "from pyscf.tools import molden\n", "\n", "# Create the molden filename\n", "def change_extension(filename):\n", " if filename.endswith('.xyz'):\n", " return filename[:-4] + '.molden'\n", " return filename\n", "\n", "def main():\n", " # Run SCF in pyscf\n", " mol = pyscf.gto.M(\n", " atom=sys.argv[1], # Take the geometry from the displaced folder\n", " basis=\"cc-pvdz\"\n", " )\n", "\n", " scfres = pyscf.scf.RHF(mol)\n", " scfres.conv_tol = 1e-13\n", " scfres.kernel()\n", "\n", " adcc.set_n_threads(8)\n", " hf = adcc.ReferenceState(scfres)\n", " print(adcc.LazyMp(hf).energy(level=3)) # Print MP3 energy; for better precision, CCSD(T) could be used\n", " state = adcc.cvs_adc3(scfres, n_singlets=10, core_orbitals=4)\n", " print(state.describe()) # Print the data obtained\n", " print(state.describe_amplitudes()) # Print the transitions\n", "\n", " new_filename = change_extension(sys.argv[1])\n", " # Creating the .molden file\n", " with open(new_filename, 'w') as f1:\n", " molden.header(mol, f1)\n", " molden.orbital_coeff(mol, f1, scfres.mo_coeff, ene=scfres.mo_energy, occ=scfres.mo_occ)\n", "\n", "if __name__ == \"__main__\":\n", " main()\n", "```\n", "\n", "### Submitting Jobs to the Cluster\n", "To run the `run_adc.py` script on a cluster, you can use the following sbatch script. Replace the placeholders (X) with appropriate values for your system.\n", "\n", "#### run_sbatch_adcc.sh\n", "```bash\n", "#!/bin/bash\n", "#SBATCH --partition=X\n", "#SBATCH --nodes=X\n", "#SBATCH --ntasks-per-node=X\n", "#SBATCH --time=XX:XX:XX\n", "#SBATCH --mem=Xgb\n", "\n", "new_filename=\"${1%.xyz}.out\" # This will create an output file\n", "python3 run_adc.py ${1} > $new_filename\n", "```\n", "\n", "### Running Multiple Calculations\n", "To efficiently run calculations for all displaced geometries, you can use the following bash script. This script iterates over all normal modes and displacements, submitting a separate job for each geometry file. Ensure that the filename formatting matches the output of `cfour_displacements.py`.\n", "\n", "#### run_everything.sh\n", "```bash\n", "#!/bin/bash\n", "nmodes=x\n", "min_disp=x\n", "max_disp=x\n", "step=x\n", "for nmode in $(seq 1 1 $nmodes); do\n", " for ((disp=$min_disp; disp<=$max_disp; disp+=$step)); do\n", " if [ $disp -lt 0 ]; then\n", " inpgeo=$(printf \"geo_v%d_%03d.xyz\" $nmode $disp)\n", " else\n", " inpgeo=$(printf \"geo_v%d_%02d.xyz\" $nmode $disp)\n", " fi\n", " sbatch run_sbatch_adcc.sh $inpgeo\n", " done\n", "done\n", "```\n", "\n", "**Note**: Adjust the values of `nmodes`, `min_disp`, `max_disp`, and `step` to match your specific calculation parameters. Also, verify that the filename formatting in the script (e.g., `geo_v%d_%03d.xyz` for negative displacements and `geo_v%d_%02d.xyz` for positive displacements) matches the naming convention used by `cfour_displacements.py`. For example, this script assumes filenames like `geo_v1_-01.xyz` and `geo_v1_01.xyz`." ] }, { "cell_type": "markdown", "id": "17690535", "metadata": {}, "source": [ "### Extracting Data from ADC Output Files\n", "\n", ". **Configure the Extraction Script**:\n", " - Open `Tools/extract_adcc.py` in a text editor.\n", " - Modify the configuration parameters as needed\n", " - Running it by executing\n", " ```bash\n", " python3 extract_adcc.py\n", " ```\n", " - This will create the data files `gs_v{mode}.dat` and `ce{state}_v{mode}.dat`, each file consisting of two columns, the displacement and the energy.\n", " " ] } ], "metadata": { "kernelspec": { "display_name": "test_vc", "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.12.2" } }, "nbformat": 4, "nbformat_minor": 5 }