.. _caspt2:

********************************************************
Multireference second-order perturbation theory (CASPT2)
********************************************************

===========
Description
===========
CASPT2 is the second-order perturbation theory based on the multiconfiguration self-consistent field theory.
Fully internally contracted single-state version (SS-CASPT2), multi-state version (MS-CASPT2) and its extended variant (XMS-CASPT2) are available.
CASPT2 in BAGEL is implemented with the automatic code generator SMITH3,
and the SMITH information for XMS-CASPT2 should be passed in a separate array in the input.

Title: ``smith``

==================
Prerequisites
==================

A reference wavefunction generated by a :ref:`HF <hf>` or :ref:`CASSCF <casscf>` calculation.

========
Keywords
========
CASSCF keywords
---------------
See :ref:`casscf`.

SMITH keywords
--------------

The default values are recommended unless mentioned otherwise.

.. topic:: ``method``

   | **Description:** Do multistate CASPT2.
   | **Datatype:** string
   | **Values:**
   |    ``caspt2``: Standard CASPT2.
   |    ``casa``  : Use Dyall's Hamiltonian

.. topic:: ``ms``

   | **Description:** Do multistate CASPT2.
   | **Datatype:** bool
   | **Default:** true.

.. topic:: ``xms``

   | **Description:** Do extended multistate CASPT2.
   | **Datatype:** bool
   | **Default:** true.

.. topic:: ``sssr``

   | **Description:** Use SS-SR contraction scheme.
   | **Datatype:** bool
   | **Values:**
   |    ``true``: use SS-SR contraction scheme.
   |    ``false``: use MS-MR contraction scheme.
   | **Default:** true.

.. topic:: ``shift``

   | **Description:** Vertical shift.
   | **Datatype:** double precision
   | **Default:** 0.0
   
.. topic:: ``shift_imag``

   | **Description:** Whether to use imaginary or real shift.
   | **Datatype:** bool
   | **Values:**
   |    ``true``: use imaginary shift.
   |    ``false``: use real shift.
   | **Default:** false.

.. topic:: ``orthogonal_basis``

   | **Description:** Whether to use orthogonal basis in CASPT2 iterations.
   | **Datatype:** bool
   | **Values:**
   |    ``true``: use orthogonal basis.
   |    ``false``: use redundant basis.
   | **Default:** with imaginary shift, true. otherwise, false.
   | **Recommendation:** Imaginary shift only works with true. Use of orthogonal basis makes the code slightly slower due to the additional transformations.

.. topic:: ``thresh``

   | **Description:** Convergence threshold.
   | **Datatype:** double precision
   | **Default:** For single point energy calculation, 1.0e-6. Tight convergence for gradient calculation, 1.0e-8.

.. topic:: ``thresh_overlap``

   | **Description:** Overlap cutoff threshold for internally contracted basis.
   | **Datatype:** Double precision
   | **Default:** 1.0e-9

.. topic:: ``frozen``

   | **Description**: Freeze core orbitals. 
   | **Datatype**: bool
   | **Default**: true

.. topic:: ``ncore``

   | **Description:** Number of frozen core orbitals.
   | **Datatype:** int 
   | **Default:** If ``frozen`` is true, subvalence orbitals are frozen. If false, zero. 

.. topic:: ``nfrozenvirt``

   | **Description:** Number of frozen virtual orbitals.
   | **Datatype:** int
   | **Default:** 0

.. topic:: ``block_diag_fock``

   | **Description:** Using a block-diagonal zeroth-order Hamiltonian
   | **Datatype:** bool
   | **Default:** false.

.. topic:: ``maxiter``

   | **Description:** Maximum number of iterations in CASPT2 calculations.
   | **Datatype:** int
   | **Default:** 50

.. topic:: ``maxtile``

   | **Description:** Maximum number of orbitals in a single data tile used in CASPT2.
   | **Datatype:** int
   | **Default:** 10

.. topic:: ``cimaxchunk``

   | **Description:** Number of elements per pass in the multipassing algorithm.
   | **Datatype:** int
   | **Default:** 317520001
   | **Recommendation:** This number is adjusted for 64GB of memory per node. Decrease if necessary. 

.. topic:: ``davidson_subspace``

   | **Description:**  Number of vectors retained in the limited-memory Davidson algorithm.
   | **Datatype:** int
   | **Default:** 10
   | **Recommendation:** Reduce if an insufficient amount of memory is available (do not reduce to a value lower than 3). 

=======
Example
=======
XMS-CASPT2 calculation based on the two-state CASSCF reference function, with vertical shift of 0.2 :math:`E_h`. "SS-SR" contraction scheme is used.
The active space of (6e,6o), which comprises three :math:`\pi` and three :math:`\pi^*` orbitals, is used.

Sample input
------------

.. code-block:: javascript

   { "bagel" : [ 
   {
     "title" : "molecule",
     "basis" : "svp",
     "df_basis" : "svp-jkfit",
     "geometry" : [ 
     { "atom" : "C", "xyz" : [     -0.079002,      2.543870,      0.000000 ] },
     { "atom" : "C", "xyz" : [      2.557470,      2.543870,      0.000000 ] },
     { "atom" : "C", "xyz" : [      3.875630,      4.826190,      0.000000 ] },
     { "atom" : "C", "xyz" : [      2.557250,      7.109950,     -0.002266 ] },
     { "atom" : "C", "xyz" : [     -0.078588,      7.109800,     -0.003171 ] },
     { "atom" : "C", "xyz" : [     -1.396870,      4.826620,     -0.001289 ] },
     { "atom" : "H", "xyz" : [     -1.117900,      0.744245,      0.000850 ] },
     { "atom" : "H", "xyz" : [      3.595900,      0.743875,      0.002485 ] },
     { "atom" : "H", "xyz" : [      5.953730,      4.826340,      0.001198 ] },
     { "atom" : "H", "xyz" : [      3.596980,      8.909240,     -0.002377 ] },
     { "atom" : "H", "xyz" : [     -1.118170,      8.909350,     -0.004972 ] },
     { "atom" : "H", "xyz" : [     -3.474820,      4.826960,     -0.001629 ] } 
     ]
   },
   {
     "title" : "casscf",
     "nstate" : 2,
     "nact" : 6,
     "nclosed" : 18, 
     "active" : [17, 20, 21, 22, 23, 30] 
   },
   {
     "title" : "smith",
     "method" : "caspt2",
     "ms" : true,
     "xms" : true,
     "sssr" : true,
     "shift" : 0.2 
   }
   ]}

from which one obtains

.. code-block:: javascript

    * freezing 6 orbitals
    * SS-SR internal contraction is used
       - MO integral evaluation                    0.17

  ++ State-averaged Fock matrix over basis states ++

                         0                   1
     0       -2.0342653161       -0.0001122518
     1       -0.0001122518       -1.5807049808


    * Extended multi-state CASPT2 (XMS-CASPT2)
      Rotation matrix:
             -0.9999999694        0.0002474903
             -0.0002474903       -0.9999999694


  ++ Reference energies in XMS basis ++

                         0                   1
     0     -230.6050217539        0.0000451863
     1        0.0000451863     -230.4224437279

    - linear dependency detected:    2 /  144    min eigenvalue:     6.1865e-16    max eigenvalue:     2.4045e-15
    - linear dependency detected:   17 /  432    min eigenvalue:    -3.1714e-15    max eigenvalue:     4.8064e-10
    - linear dependency detected:   17 /  432    min eigenvalue:    -1.2669e-15    max eigenvalue:     2.6360e-10
       - RDM + denominator evaluation              0.66

    * Zeroth order energy : state  0       -2.0342653439
    * Zeroth order energy : state  1       -1.5807049530

      ---- iteration ----

        0    -0.66979449     0.00181235      0.38
        1    -0.67020074     0.00009168      0.40
        2    -0.67020211     0.00000478      0.40
        3    -0.67020211     0.00000040      0.41

        0    -0.66833574     0.00152666      0.40
        1    -0.66872419     0.00007727      0.38
        2    -0.66872593     0.00000453      0.39
        3    -0.66872594     0.00000033      0.40

      -------------------

       - CASPT2 energy evaluation                  3.27

    * CASPT2 energy : state  0     -231.3177899925
        w/o shift correction       -231.2752238675
        reference weight              0.8245174383

    * CASPT2 energy : state  1     -231.1349876522
        w/o shift correction       -231.0911696633
        reference weight              0.8202840199


    * MS-CASPT2 Heff
           -231.3177899925        0.0000232719
              0.0000232719     -231.1349876522


    * MS-CASPT2 rotation matrix
             -0.9999999919       -0.0001273065
              0.0001273065       -0.9999999919


    * XMS-CASPT2 rotation matrix
              0.9999999928       -0.0001201838
              0.0001201838        0.9999999928

    * MS-CASPT2 energy : state  0     -231.3177899955
    * MS-CASPT2 energy : state  1     -231.1349876492



    * METHOD: SMITH                                4.40


==========
References
==========

BAGEL References
----------------
+---------------------------------------------------+----------------------------------------------------------------------------------------------+
|          Description of Reference                 |                          Reference                                                           |
+===================================================+==============================================================================================+
| CASPT2 gradients / SMITH3                         | M\. K. MacLeod and T. Shiozaki, J. Chem. Phys. **142**, 010507 (2015).                       |
+---------------------------------------------------+----------------------------------------------------------------------------------------------+
| XMS-CASPT2 gradients                              | B\. Vlaisavljevich and T. Shiozaki, J. Chem. Theory Comput. **12**, 3781 (2016).             |
+---------------------------------------------------+----------------------------------------------------------------------------------------------+
| XMS-CASPT2 derivative couplings                   | J\. W. Park and T. Shiozaki, J. Chem. Theory Comput. **13**, 2561 (2017).                    |
+---------------------------------------------------+----------------------------------------------------------------------------------------------+
| Current XMS-CASPT2 gradient algorithm             | J\. W. Park and T. Shiozaki, J. Chem. Theory Comput. **13**, 3676 (2017).                    |
+---------------------------------------------------+----------------------------------------------------------------------------------------------+

General References
------------------
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------+
|          Description of Reference                 |                          Reference                                                                    |
+===================================================+=======================================================================================================+
| CASPT2                                            | K\. Andersson, P.-Å. Malmqvist, and B. O. Roos, J. Chem. Phys. **96**, 1218 (1992).                   |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------+
| MS-CASPT2                                         | J\. Finley, P.-Å. Malmqvist, B. O. Roos, and L. Serrano-Andres, Chem. Phys. Lett. **288**, 299 (1998).|
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------+
| XMCQDPT                                           | A\. A. Granovsky, J. Chem. Phys. **134**, 214113 (2011).                                              |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------+
| XMS-CASPT2                                        | T\. Shiozaki, W. Győrffy, P. Celani, and H.-J. Werner, J. Chem. Phys. **135**, 081106 (2011).         |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------+
