.. _lecture3: ===================================================================== Why does DFT work? Improving upon it ===================================================================== - :ref:`Why does DFT work? ` - :ref:`Exploiting error cancellation ` - :ref:`Single-point higher-level corrections ` - :ref:`Use machine learning! ` - :ref:`Homework ` .. - :ref:`Further reading ` Slides ------ :download:`Slides <_static/lecture3/Lecture3_wm.pdf>`: .. raw:: html .. _lecture3_dft: Why does DFT work? ------------------- In the previous lecture, we saw that DFT is a pretty bad choice if you want very accurate results. Still, *DFT is the most widely used quantum chemical approach*. Why is that? There are several good reasons for this. We have already seen that DFT provides reasonable geometries within reasonable time compared to more accurate but slower CCSD(T) or to faster but less accurate semi-empirical QM methods. It has occupied a sweet spot in terms of accuracy/cost tradeoff. I believe that ML can change this status quo but it will take time to overcome resistance of the older generation of computational chemists who will stick to their method of choice for as long as they can. See for example that B3LYP continues to be the top choice although it is three decades old and many better methods have emerged. However, there is one very important reason why DFT works well enough in many cases and we explore it in the next exercise. .. include:: materials/lecture3/task3.1_error_cancellation/task3.1_error_cancellation.inc After calculations finish, which will take some time, you will get results similar to the following (why not exactly the same?): ============================================== ============ ============ ============ Molecule/Reaction B3LYP/6-31G* Experiment Error ============================================== ============ ============ ============ butane :math:`\Delta H_{\text{f},298}` -27.44 -30.03 2.59 isobutane :math:`\Delta H_{\text{f},298}` -28.25 -32.07 3.82 isomerization :math:`\Delta H_{\text{r},298}` -0.81 -2.04 1.23 ============================================== ============ ============ ============ After so much effort, the errors for heats of formation are quite large - much more than coveted chemical accuracy (errors below 1 kcal/mol). This is expected from the previous lecture. However, what is interesting, is that isomerization enthalpy has error quite close to 1 kcal/mol. This is the general trend in quantum chemical calculations and the most important lesson of today: the more similar structures, the less error is in the relative energies. In other words, the difference in energies of similar structures is usually small due to the *error cancellation*. That's why DFT works. It banks on error cancellation and you can expect decent results if you calculate relative energies of similar structures. Below we explore how we can improve on the DFT results. .. _lecture3_exploiting_error_cancellation: Exploiting error cancellation ----------------------------- One of the solutions to improve the quality of DFT calculations is to exploit the error cancellation. For example, if we are interested in calculating heat of formation of isobutane with DFT when we know the experimental heat of formation of butane, we can calculate the isomerization enthalpy as we have done before: .. math:: \Delta H^\text{DFT}_{\text{r},298} = H^\text{DFT}_{298}(\text{isobutane}) - H^\text{DFT}_{298}(\text{butane}) \Delta H_{\text{f},298}(\text{isobutane}) = \Delta H^\text{exp}_{\text{f},298}(\text{butane}) + \Delta H^\text{DFT}_{\text{r},298} .. admonition:: Task 3.2. Calculate the heat of formation of isobutane using above equations at B3LYP/6-31G*. Report: 1. What is the resulting heat of formation? 2. Error in this heat of formation? In fact, there are many elaborate schemes which were designed to get the reasonable estimates from DFT calculations (check out isodesmic, homodesmotic reactions, etc.). .. _lecture3_sp_corrections: Single-point higher-level corrections ------------------------------------- Another way to improve DFT calculations is by getting help from our trusty friends from the CCSD(T) family of methods. Although they are too expensive to do calculation of heats of formation (you can try...), we can combine DFT and CCSD(T) calculations. It is quite simple. You just need to perform single-point calculations (i.e., calculate just energies) at CCSD(T) on the geometries optimized with DFT. .. _task3.3: .. admonition:: Task 3.3. Calculate the isomerization energy of butane to isobutane by performing single-point calculations at CCSD(T)/cc-pVDZ (this will take you a minute; cc-pVTZ will take you half an hour...). Use the geometries optimized at B3LYP/6-31G* in your previous Task 3.1. Report: 1. What is the resulting isomerization energy? 2. How does it compare to the experimental isomerization enthalpy? Example of input file: .. code-block:: method=CCSD(T)/cc-pVDZ qmprog=pyscf yestfile=ccsd-t_energy.dat XYZfile=optgeoms.xyz # File with geometry optimized with DFT If you got everything right, you should have obtained final energies for butane (-157.9898929453521 Hartree) and isobutane (-157.9921731980625) with the isomerization energy of -1.43 kcal/mol. This is pretty close to the experimental isomerization enthalpy (difference is only 0.61 kcal/mol, much better than with DFT!). .. note:: In principle, you need to calculate isomerization enthalpy, not energy. For this, you can also re-use your old DFT calculations and add ZPVE and thermal correction at B3LYP to CCSD(T) energies. This can be your advanced exercise. .. _lecture3_ml: Use machine learning! ------------------------------------- All above solutions are still quite time-consuming and not very straightforward to use as you need to do many manual manipulations. A better way to do is to use, guess what? Right, AIQM1 or ANI1-ccx. They are both faster and more accurate and you will get the correct heats of formation out-of-the-box and do not need to any more tricks as the relative energies will automatically be better You can try yourself. There are other solutions too. For example, you can still use DFT but its version improved with ML. Universal models following this route start to emerge, with examples being DM21 (`published in Science `__ but our benchmarks show it is slower and not better than AIQM1 although it has broader coverage of elements; do not always take stuff published in Science/Nature at face value!) and CF22D. Finally, you will learn in the future lessons how to apply techniques like delta-learning to use ML for improving DFT predictions to any level. That was one of the very early and pioneering contributions where `neural networks were used to correct DFT heats of formation by taking as input number of atoms along with other features `__. An important message is that *if you can use machine learning counterparts of quantum chemical methods, you should* as they are often more accurate and faster. .. note:: We have two of new solutions to improve DFT accuracy by making ensemble of them, e.g., our `DENS24 methods `__ and via delta-learning. This will be updated in the future versions of the courses. .. include:: outdating.rst .. _lecture3_homework: Homework -------- .. include:: materials/lecture3/homework3.1/homework3.1.inc .. include:: materials/lecture3/homework3.2/homework3.2.inc .. _lecture3_further_reading: .. Further reading .. ---------------