Skip to content

Commit

Permalink
chore: Remove .ipynb files from .gitignore and added example dftbplus…
Browse files Browse the repository at this point in the history
… notebook
  • Loading branch information
galjos committed May 14, 2024
1 parent 6ec4681 commit 3757cc7
Show file tree
Hide file tree
Showing 2 changed files with 296 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ target/

# Jupyter Notebook
.ipynb_checkpoints
*.ipynb

# IPython
profile_default/
Expand Down
296 changes: 296 additions & 0 deletions examples/Notebooks/dftbplus/ThermoScreening.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Example 101 Thermochemistry using DFTB+"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Clone repo on GitHub: https://github.com/MolarVerse/ThermoScreening and install using `pip install .` in the root directory."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from ThermoScreening.thermo.api import dftbplus_thermo\n",
"from ThermoScreening.calculator import Geoopt, Hessian, Modes\n",
"\n",
"from ase.io import read, write\n",
"\n",
"import os\n",
"skf_dir = 'skf-files/3ob-3-1'\n",
"\n",
"# set DFTB perfix and path \n",
"os.environ['DFTB_PREFIX'] = os.path.join(os.environ['HOME'], skf_dir)\n",
"os.environ['OMP_NUM_THREADS'] = '6'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"DFTB+ parameters for thermochemistry with COSMO solvation model"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"dftb_parameters = dict(\n",
" # SCC \n",
" Hamiltonian_SCC=\"Yes\",\n",
" Hamiltonian_MaxSCCIterations=250,\n",
" Hamiltonian_SCCTolerance='1.0e-6',\n",
" Hamiltonian_ReadInitialCharges=\"No\",\n",
"\n",
" # Fermi smearing\n",
" Hamiltonian_Filling=\"Fermi {\",\n",
" Hamiltonian_Filling_empty=\"Temperature [Kelvin] = 300\",\n",
"\n",
" # Convergence helper\n",
" Hamiltonian_Mixer=\"DIIS{}\",\n",
"\n",
" # Dispersion correction\n",
" Hamiltonian_Dispersion=\"DftD4 {\",\n",
" Hamiltonian_Dispersion_s6=1.0,\n",
" Hamiltonian_Dispersion_s8=0.4727337,\n",
" Hamiltonian_Dispersion_s9=0.0,\n",
" Hamiltonian_Dispersion_a1=0.5467502,\n",
" Hamiltonian_Dispersion_a2=4.4955068,\n",
"\n",
" # H-Damping\n",
" Hamiltonian_HCorrection=\"Damping {\",\n",
" Hamiltonian_HCorrection_Exponent=4.00,\n",
"\n",
" # Halogen correction\n",
" Hamiltonian_HalogenXCorr=\"Yes\",\n",
"\n",
" # Are guessed by ase\n",
" Hamiltonian_MaxAngularMomentum_=\"\",\n",
"\n",
" # Solvation model\n",
" Hamiltonian_Solvation_ = \"Cosmo\",\n",
" Hamiltonian_Solvation_Radii = \"VanDerWaalsRadiiD3 {}\",\n",
" Hamiltonian_Solvation_RadiiScaling = 1.55,\n",
" Hamiltonian_Solvation_AngularGrid = 110,\n",
" Hamiltonian_Solvation_Solver = \"DomainDecomposition{\",\n",
" Hamiltonian_Solvation_Solver_MaxMoment = 10,\n",
" Hamiltonian_Solvation_Solver_Accuracy = 1.0e-8,\n",
" Hamiltonian_Solvation_Solver_Regularisation = 0.2,\n",
" Hamiltonian_Solvation_Solvent=\"\"\"FromConstants{\n",
" Epsilon = 37.0,\n",
" MolecularMass [amu] = 73.1,\n",
" Density [kg/l] = 0.95\n",
" }\"\"\",\n",
" Hamiltonian_Solvation_empty = \"FreeEnergyShift [kcal/mol] = 0.0\",\n",
"\n",
" # Hubbard derivatives\n",
" Hamiltonian_ThirdOrderFull=\"Yes\",\n",
" Hamiltonian_hubbardderivs_=\"\",\n",
" Hamiltonian_hubbardderivs_C=-0.1492,\n",
" Hamiltonian_hubbardderivs_N=-0.1535,\n",
" Hamiltonian_hubbardderivs_O=-0.1575,\n",
" Hamiltonian_hubbardderivs_H=-0.1857,\n",
" Hamiltonian_hubbardderivs_S=-0.11,\n",
" Hamiltonian_hubbardderivs_P=-0.14,\n",
" Hamiltonian_hubbardderivs_F=-0.1623,\n",
" Hamiltonian_hubbardderivs_Cl=-0.0697,\n",
" Hamiltonian_hubbardderivs_Br=-0.0573,\n",
" Hamiltonian_hubbardderivs_I=-0.0433,\n",
" Hamiltonian_hubbardderivs_Zn=-0.03,\n",
" Hamiltonian_hubbardderivs_Mg=-0.02,\n",
" Hamiltonian_hubbardderivs_Ca=-0.0340,\n",
" Hamiltonian_hubbardderivs_K=-0.0339,\n",
" Hamiltonian_hubbardderivs_Na=-0.0454,\n",
"\n",
" # Analysis\n",
" Analysis_=\"\",\n",
" Analysis_CalculateForces=\"Yes\",\n",
" Analysis_MullikenAnalysis=\"Yes\",\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"----\n",
"\n",
"TODO:\n",
"- install `wfl` - not in pypi >:( - https://github.com/libAtoms/workflow\n",
"- rdkit NOT in dependencies of `wfl`\n",
"- restart kernel after installation\n",
"\n",
"Commands to install `wfl` and `rdkit`:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# pip install git+https://github.com/libAtoms/workflow.git"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# pip install rdkit"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create `ase.Atoms` from SMILES"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:rdkit:Enabling RDKit 2023.09.6 jupyter extensions\n"
]
}
],
"source": [
"from wfl.generate import smiles\n",
"from ase.calculators.dftb import Dftb\n",
"\n",
"# quinone smile\n",
"smile = 'C1=CC(=O)C=CC1=O'\n",
"system = smiles.smi_to_atoms(smile)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"--------\n",
"\n",
"Run ThermoScreening with DFTB+:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"thermo = dftbplus_thermo(system, charge=0, **dftb_parameters)\n",
"zero = thermo.total_EeGtot()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"thermo = dftbplus_thermo(system, charge=-1, **dftb_parameters)\n",
"neg1 = thermo.total_EeGtot()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"thermo = dftbplus_thermo(system, charge=-2, **dftb_parameters)\n",
"neg2 = thermo.total_EeGtot()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-18.304025003414917 -18.45846575894427 -18.580216476499253\n"
]
}
],
"source": [
"print(zero, neg1, neg2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Calculate redox potential:"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"C1=CC(=O)C=CC1=O redox1: 4.20254791420707 V\n",
"C1=CC(=O)C=CC1=O redox2: 3.3130064817421263 V\n"
]
}
],
"source": [
"# faraday constant\n",
"F = 96485.3329\n",
"# hartree to j/mol\n",
"hartree = 2625500.2\n",
"\n",
"redox1 = - (neg1 - zero) * hartree / F\n",
"redox2 = - (neg2 - neg1) * hartree / F\n",
"\n",
"print(f'{smile} redox1: {redox1} V')\n",
"print(f'{smile} redox2: {redox2} V')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"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.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 3757cc7

Please sign in to comment.