# 11. Interfaces to psi4 and pyscf

CheMPS2 is currently interfaced with two ab initio quantum chemistry packages:

1. The `dmrg` plugin to psi4 allows to perform DMRG-CI, DMRG-SCF, and DMRG-CASPT2 calculations with CheMPS2. Since April 2015, CheMPS2 is also an integral part of psi4.

2. There are also DMRG-CI and DMRG-SCF interfaces between pyscf and CheMPS2.

## 11.1. psi4 `dmrg` plugin

DMRG-CI, DMRG-SCF, and DMRG-CASPT2 calculations can be performed directly with psi4. The plugin has been tested on late March 2017 psi4 pre-1.1. .. comment tag (released February 17, 2016).

Note that as of late June 2016, DMRG keywords in psi4 have been realigned to those of the chemps2 executable. A translation table is available.

To perform DMRG-CI, DMRG-SCF, and DMRG-CASPT2 calculations, build psi4 or use the conda binary, and then run:

    $ cd /mypsi4plugins
    $ psi4 --plugin-name dmrg
    $ cd dmrg

Now, replace the file `plugin.cc` with `/sourcefolder/chemps2/integrals/psi4plugins/dmrg.cc` (file can be named `plugin.cc` or `dmrg.cc`, but if the latter, change `CMakeLists.txt` to match). To compile the plugin, the CMakeLists.txt should be adjusted. Change the line

    find_package(psi4 1.0 REQUIRED)

to

    find_package(psi4 1.0 REQUIRED COMPONENTS chemps2)

Now call `psi4 --plugin-compile` and execute the result. Additional variables can be passed to the `cmake` command (including -DCheMPS2_DIR), but none should be necessary. Avoid building against a Psi4 with PCMSolver enabled, as this will cause trouble with capturing stdout. To compile the plugin, run:

    $ make

An example input file to perform a DMRG-CI calculation with the `dmrg` plugin:

    molecule H2O {
     0 1
       O   0.000000000   0.00   0.000000000
       H   0.790689766   0.00   0.612217330
       H  -0.790689766   0.00   0.612217330
     units angstrom
    }

    sys.path.insert(0, './..')
    import dmrg

    set basis          cc-pVDZ
    set reference      rhf
    set scf_type       PK
    set e_convergence  1e-13
    set d_convergence  1e-13
    set ints_tolerance 0.0

    set dmrg_irrep                0
    set dmrg_multiplicity         1
    set restricted_docc           [ 1 , 0 , 0 , 0 ]
    set active                    [ 5 , 0 , 4 , 2 ]

    set dmrg_sweep_states         [  200,  500, 1000, 1000 ]
    set dmrg_sweep_energy_conv    [ 1e-8, 1e-8, 1e-8, 1e-8 ]
    set dmrg_sweep_max_sweeps     [    5,    5,    5,  100 ]
    set dmrg_sweep_noise_prefac   [ 0.03, 0.03, 0.03,  0.0 ]
    set dmrg_sweep_dvdson_rtol    [ 1e-5, 1e-5, 1e-5, 1e-9 ]
    set dmrg_print_corr           false
    set dmrg_mp2_write            false

    set dmrg_scf_max_iter         1

    set dmrg_molden_write         true  # DMRG-CI pseudocanonical orbitals
    set dmrg_opdm_ao_print        true  # DMRG-CI density in the AO basis

    energy('dmrg')

Note that the option `dmrg_max_iter` has been set to `1`, so that only one active space calculation is performed. This file (`H2O.dmrgci.in`) should be placed in the folder `/mypsi4plugins/dmrg`. The DMRG-CI calculation can then be started with:

    $ cd /mypsi4plugins/dmrg
    $ psi4 H2O.dmrgci.in H2O.dmrgci.out

An example input file to perform a DMRG-SCF calculation with the `dmrg` plugin:

    molecule O2 {
      O       0.0   0.0   0.0
      O       0.0   0.0   3.0
    units au
    }

    sys.path.insert(0, './..')
    import dmrg

    set basis          cc-pVDZ
    set reference      rhf
    set scf_type       PK

    set dmrg_irrep                0
    set dmrg_multiplicity         1
    set restricted_docc           [ 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 ]
    set active                    [ 2 , 0 , 2 , 2 , 0 , 2 , 2 , 2 ]

    set dmrg_sweep_states         [   500,  1000,  1000 ]
    set dmrg_sweep_energy_conv    [ 1e-10, 1e-10, 1e-10 ]
    set dmrg_sweep_max_sweeps     [     5,     5,    10 ]
    set dmrg_sweep_noise_prefac   [  0.05,  0.05,   0.0 ]
    set dmrg_sweep_dvdson_rtol    [  1e-5,  1e-5,  1e-9 ]
    set dmrg_print_corr           false
    set dmrg_mps_write            false

    set dmrg_scf_grad_thr         1e-6
    set dmrg_unitary_write        true
    set dmrg_diis                 true
    set dmrg_scf_diis_thr         1e-2
    set dmrg_diis_write           true

    set dmrg_scf_max_iter         100
    set dmrg_excitation           1   # First excited state
    set dmrg_scf_state_avg        true
    set dmrg_scf_active_space     NO  # INPUT; NO; LOC
    set dmrg_local_init           false

    set dmrg_molden_write         true  # Converged DMRG-SCF pseudocanonical orbitals
    set dmrg_opdm_ao_print        true  # Converged DMRG-SCF density in the AO basis

    energy('dmrg')

This file (`O2.dmrgscf.in`) should be placed in the folder `/mypsi4plugins/dmrg`. The DMRG-SCF calculation can then be started with:

    $ cd /mypsi4plugins/dmrg
    $ psi4 O2.dmrgscf.in O2.dmrgscf.out

An example input file to perform a DMRG-CASPT2 calculation with the `dmrg` plugin:

    molecule N2 {
      N       0.0000   0.0000   0.0000
      N       0.0000   0.0000   2.1180
    units au
    }

    sys.path.insert(0, './..')
    import dmrg

    set basis          cc-pVDZ
    set reference      rhf
    set scf_type       PK
    set e_convergence  1e-12
    set d_convergence  1e-12

    set dmrg_irrep                0
    set dmrg_multiplicity         1
    set restricted_docc           [ 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 ]
    set active                    [ 2 , 0 , 1 , 1 , 0 , 2 , 1 , 1 ]

    set dmrg_sweep_states         [   500,  1000,  1000 ]
    set dmrg_sweep_energy_conv    [ 1e-10, 1e-10, 1e-10 ]
    set dmrg_sweep_max_sweeps     [     5,     5,    10 ]
    set dmrg_sweep_noise_prefac   [  0.05,  0.05,   0.0 ]
    set dmrg_sweep_dvdson_rtol    [  1e-5,  1e-5,  1e-9 ]
    set dmrg_print_corr           false
    set dmrg_mps_write            false

    set dmrg_scf_grad_thr         1e-6
    set dmrg_unitary_write        true
    set dmrg_diis                 true
    set dmrg_scf_diis_thr         1e-2
    set dmrg_diis_write           true

    set dmrg_scf_max_iter         100
    set dmrg_excitation           0   # Ground state
    set dmrg_scf_state_avg        false
    set dmrg_scf_active_space     INPUT # INPUT; NO; LOC
    set dmrg_local_init           false

    set dmrg_molden_write         false # Converged DMRG-SCF pseudocanonical orbitals
    set dmrg_opdm_ao_print        true  # Converged DMRG-SCF density in the AO basis

    set dmrg_caspt2_calc          true
    set dmrg_caspt2_orbs          ACTIVE
    set dmrg_caspt2_ipea          0.00
    set dmrg_caspt2_imag_shift    0.00

    energy('dmrg')

This file (`N2.caspt2.in`) should be placed in the folder `/mypsi4plugins/dmrg`. The DMRG-CASPT2 calculation can then be started with:

    $ cd /mypsi4plugins/dmrg
    $ psi4 N2.caspt2.in N2.caspt2.out

Since April 2015, CheMPS2 is also an integral part of psi4. Please consult psi4’s documentation on how to run DMRG-CI, DMRG-SCF, and DMRG-CASPT2 calculations with psi4.

## 11.2. pyscf

pyscf is a new quantum chemistry package, in which all layers are written or interfaced in python. In the future, the package will be able to perform DMRG-CI and DMRG-SCF calculations using PyCheMPS2: chemps2.py.

Examples of how to extract MO integrals from pyscf to perform DMRG-CI calculations with PyCheMPS2 can be found in:

1. `/sourcefolder/chemps2/integrals/pyscf/example.py`

2. `/sourcefolder/chemps2/integrals/pyscf/example2.py`

3. `/sourcefolder/chemps2/integrals/pyscf/example3.py`

4. `/sourcefolder/chemps2/integrals/pyscf/dmrgci.py`

5. `/sourcefolder/chemps2/integrals/pyscf/call_chemps2.py`

Please remember to append the correct pyscf and PyCheMPS2 directories to `sys.path` at the top of these files.