diff --git a/data/module_gitignore b/data/module_gitignore index f5461472..66716ccc 100644 --- a/data/module_gitignore +++ b/data/module_gitignore @@ -5,7 +5,9 @@ /vortex/u/eginer/qp_toto/quantum_package/src/tools/fcidump /vortex/u/eginer/qp_toto/quantum_package/src/tools/four_idx_transform /vortex/u/eginer/qp_toto/quantum_package/src/tools/molden +/vortex/u/eginer/qp_toto/quantum_package/src/tools/print_wf /vortex/u/eginer/qp_toto/quantum_package/src/tools/save_natorb +/vortex/u/eginer/qp_toto/quantum_package/src/tools/save_one_body_dm /vortex/u/eginer/qp_toto/quantum_package/src/tools/save_ortho_mos /vortex/u/eginer/qp_toto/quantum_package/src/tools/write_integrals_erf IRPF90_man @@ -16,6 +18,7 @@ ao_basis ao_one_e_integrals ao_two_e_erf_integrals ao_two_e_integrals +aux_quantities bitmask davidson davidson_undressed diff --git a/src/becke_numerical_grid/README.rst b/src/becke_numerical_grid/README.rst index a860eef4..457e5259 100644 --- a/src/becke_numerical_grid/README.rst +++ b/src/becke_numerical_grid/README.rst @@ -6,7 +6,7 @@ This module contains all quantities needed to build the Becke's grid used in gen This grid is built as the reunion of a spherical grid around each atom. Each spherical grid contains a certain number of radial and angular points. -For a simple example of how to use the grid, see example.irp.f. +For a simple example of how to use the grid, see :file:`example.irp.f`. The spherical integration uses Lebedev-Laikov grids, which was used from the code distributed through CCL (http://www.ccl.net/). See next section for explanations and citation policies. diff --git a/src/bitmask/README.rst b/src/bitmask/README.rst index 7a2590b1..82e0825e 100644 --- a/src/bitmask/README.rst +++ b/src/bitmask/README.rst @@ -25,4 +25,4 @@ transforming a bit string to a list of integers for example. bit_kind = bit_kind_size / 8 - +For an example of how to use the bitmaks, see the file :file:`example.irp.f`. diff --git a/src/hartree_fock/README.rst b/src/hartree_fock/README.rst index 373a611d..6ea2d00d 100644 --- a/src/hartree_fock/README.rst +++ b/src/hartree_fock/README.rst @@ -6,13 +6,20 @@ Hartree-Fock The Hartree-Fock module performs *Restricted* Hartree-Fock calculations (the spatial part of the |MOs| is common for alpha and beta spinorbitals). -The Hartree-Fock program does the following: +The Hartree-Fock in an SCF and therefore is based on the ``scf_utils`` structure. +It performs the following actions: #. Compute/Read all the one- and two-electron integrals, and store them in memory #. Check in the |EZFIO| database if there is a set of |MOs|. If there is, it will read them as initial guess. Otherwise, it will create a guess. #. Perform the |SCF| iterations +The definition of the Fock matrix is in :file:`hartree_fock fock_matrix_hf.irp.f` +For the keywords related to the |SCF| procedure, see the ``scf_utils`` directory where you will find all options. +The main are: +# :option:`scf_utils thresh_scf` +# :option:`scf_utils level_shift` + At each iteration, the |MOs| are saved in the |EZFIO| database. Hence, if the calculation crashes for any unexpected reason, the calculation can be restarted by running again the |SCF| with the same |EZFIO| database. diff --git a/src/hartree_fock/hf_energy.irp.f b/src/hartree_fock/hf_energy.irp.f index a4fe52be..d24c37f9 100644 --- a/src/hartree_fock/hf_energy.irp.f +++ b/src/hartree_fock/hf_energy.irp.f @@ -1,6 +1,13 @@ -BEGIN_PROVIDER [double precision, extra_energy_contrib_from_density] +BEGIN_PROVIDER [double precision, extra_e_contrib_density] implicit none - extra_energy_contrib_from_density = 0.D0 + BEGIN_DOC +! Extra contribution to the SCF energy coming from the density. +! +! For a Hartree-Fock calculation: extra_e_contrib_density = 0 +! +! For a Kohn-Sham or Range-separated Kohn-Sham: the exchange/correlation - trace of the V_xc potential + END_DOC + extra_e_contrib_density = 0.D0 END_PROVIDER @@ -8,6 +15,9 @@ END_PROVIDER &BEGIN_PROVIDER [ double precision, HF_two_electron_energy] &BEGIN_PROVIDER [ double precision, HF_one_electron_energy] implicit none + BEGIN_DOC + ! Hartree-Fock energy containing the nuclear repulsion, and its one- and two-body components. + END_DOC integer :: i,j HF_energy = nuclear_repulsion do j=1,ao_num diff --git a/src/kohn_sham/README.rst b/src/kohn_sham/README.rst index 373a611d..197509c8 100644 --- a/src/kohn_sham/README.rst +++ b/src/kohn_sham/README.rst @@ -1,18 +1,25 @@ ============ -Hartree-Fock +Kohn-Sham ============ -The Hartree-Fock module performs *Restricted* Hartree-Fock calculations (the +The Kohn-Sham module performs *Restricted* Kohn-Sham calculations (the spatial part of the |MOs| is common for alpha and beta spinorbitals). -The Hartree-Fock program does the following: +The Kohn-Sham in an SCF and therefore is based on the ``scf_utils`` structure. +It performs the following actions: #. Compute/Read all the one- and two-electron integrals, and store them in memory #. Check in the |EZFIO| database if there is a set of |MOs|. If there is, it will read them as initial guess. Otherwise, it will create a guess. #. Perform the |SCF| iterations +The definition of the Fock matrix is in :file:`kohn_sham fock_matrix_ks.irp.f` +For the keywords related to the |SCF| procedure, see the ``scf_utils`` directory where you will find all options. +The main are: +# :option:`scf_utils thresh_scf` +# :option:`scf_utils level_shift` + At each iteration, the |MOs| are saved in the |EZFIO| database. Hence, if the calculation crashes for any unexpected reason, the calculation can be restarted by running again the |SCF| with the same |EZFIO| database. diff --git a/src/kohn_sham/fock_matrix_ks.irp.f b/src/kohn_sham/fock_matrix_ks.irp.f index fe4c29db..6ab34514 100644 --- a/src/kohn_sham/fock_matrix_ks.irp.f +++ b/src/kohn_sham/fock_matrix_ks.irp.f @@ -199,46 +199,3 @@ END_PROVIDER END_PROVIDER - - - - BEGIN_PROVIDER [ double precision, KS_energy] -&BEGIN_PROVIDER [ double precision, two_electron_energy] -&BEGIN_PROVIDER [ double precision, one_electron_energy] -&BEGIN_PROVIDER [ double precision, Fock_matrix_energy] -&BEGIN_PROVIDER [ double precision, trace_potential_xc ] - implicit none - BEGIN_DOC - ! Hartree-Fock energy - END_DOC - - integer :: i,j - double precision :: accu_mono,accu_fock - KS_energy = nuclear_repulsion - one_electron_energy = 0.d0 - two_electron_energy = 0.d0 - Fock_matrix_energy = 0.d0 - trace_potential_xc = 0.d0 - do j=1,ao_num - do i=1,ao_num - Fock_matrix_energy += Fock_matrix_ao_alpha(i,j) * SCF_density_matrix_ao_alpha(i,j) + & - Fock_matrix_ao_beta(i,j) * SCF_density_matrix_ao_beta(i,j) - two_electron_energy += 0.5d0 * ( ao_bi_elec_integral_alpha(i,j) * SCF_density_matrix_ao_alpha(i,j) & - +ao_bi_elec_integral_beta(i,j) * SCF_density_matrix_ao_beta(i,j) ) - one_electron_energy += ao_mono_elec_integral(i,j) * (SCF_density_matrix_ao_alpha(i,j) + SCF_density_matrix_ao_beta (i,j) ) -! possible bug fix for open-shell -! trace_potential_xc += (ao_potential_alpha_xc(i,j) + ao_potential_beta_xc(i,j) ) * (SCF_density_matrix_ao_alpha(i,j) + SCF_density_matrix_ao_beta (i,j) ) - trace_potential_xc += ao_potential_alpha_xc(i,j) * SCF_density_matrix_ao_alpha(i,j) + ao_potential_beta_xc(i,j) * SCF_density_matrix_ao_beta (i,j) - enddo - enddo - - KS_energy += e_exchange_dft + e_correlation_dft + one_electron_energy + two_electron_energy -END_PROVIDER - -BEGIN_PROVIDER [double precision, extra_energy_contrib_from_density] - implicit none -! possible bug fix for open-shell: -! extra_energy_contrib_from_density = e_exchange_dft + e_correlation_dft - 0.25d0 * trace_potential_xc - extra_energy_contrib_from_density = e_exchange_dft + e_correlation_dft - 0.5d0 * trace_potential_xc -END_PROVIDER - diff --git a/src/kohn_sham/ks_enery.irp.f b/src/kohn_sham/ks_enery.irp.f new file mode 100644 index 00000000..aec5074e --- /dev/null +++ b/src/kohn_sham/ks_enery.irp.f @@ -0,0 +1,43 @@ + BEGIN_PROVIDER [ double precision, KS_energy] +&BEGIN_PROVIDER [ double precision, two_electron_energy] +&BEGIN_PROVIDER [ double precision, one_electron_energy] +&BEGIN_PROVIDER [ double precision, Fock_matrix_energy] +&BEGIN_PROVIDER [ double precision, trace_potential_xc ] + implicit none + BEGIN_DOC + ! Kohn-Sham energy containing the nuclear repulsion energy, and the various components of this quantity. + END_DOC + + integer :: i,j + double precision :: accu_mono,accu_fock + KS_energy = nuclear_repulsion + one_electron_energy = 0.d0 + two_electron_energy = 0.d0 + Fock_matrix_energy = 0.d0 + trace_potential_xc = 0.d0 + do j=1,ao_num + do i=1,ao_num + Fock_matrix_energy += Fock_matrix_ao_alpha(i,j) * SCF_density_matrix_ao_alpha(i,j) + & + Fock_matrix_ao_beta(i,j) * SCF_density_matrix_ao_beta(i,j) + two_electron_energy += 0.5d0 * ( ao_bi_elec_integral_alpha(i,j) * SCF_density_matrix_ao_alpha(i,j) & + +ao_bi_elec_integral_beta(i,j) * SCF_density_matrix_ao_beta(i,j) ) + one_electron_energy += ao_mono_elec_integral(i,j) * (SCF_density_matrix_ao_alpha(i,j) + SCF_density_matrix_ao_beta (i,j) ) + trace_potential_xc += ao_potential_alpha_xc(i,j) * SCF_density_matrix_ao_alpha(i,j) + ao_potential_beta_xc(i,j) * SCF_density_matrix_ao_beta (i,j) + enddo + enddo + + KS_energy += e_exchange_dft + e_correlation_dft + one_electron_energy + two_electron_energy +END_PROVIDER + +BEGIN_PROVIDER [double precision, extra_e_contrib_density] + implicit none + BEGIN_DOC +! Extra contribution to the SCF energy coming from the density. +! +! For a Hartree-Fock calculation: extra_e_contrib_density = 0 +! +! For a Kohn-Sham or Range-separated Kohn-Sham: the exchange/correlation - 1/2 trace of the V_xc potential + END_DOC + extra_e_contrib_density = e_exchange_dft + e_correlation_dft - 0.5d0 * trace_potential_xc +END_PROVIDER + diff --git a/src/kohn_sham_rs/README.rst b/src/kohn_sham_rs/README.rst index 373a611d..95ad0cab 100644 --- a/src/kohn_sham_rs/README.rst +++ b/src/kohn_sham_rs/README.rst @@ -1,18 +1,27 @@ -============ -Hartree-Fock -============ +========================= +Range-separated Kohn-Sham +========================= -The Hartree-Fock module performs *Restricted* Hartree-Fock calculations (the -spatial part of the |MOs| is common for alpha and beta spinorbitals). +The Range-separated Kohn-Sham module performs *Restricted* Kohn-Sham calculations (the +spatial part of the |MOs| is common for alpha and beta spinorbitals) where the coulomb interaction is partially treated using exact exchange. +The splitting of the interaction between long- and short-range is determined by the range-separation parameter :option:`ao_two_e_erf_integrals mu_erf`. The long-range part of the interaction is explicitly treated with exact exchange, and the short-range part of the interaction is treated with appropriate DFT functionals. -The Hartree-Fock program does the following: +The Range-separated Kohn-Sham in an SCF and therefore is based on the ``scf_utils`` structure. +It performs the following actions: #. Compute/Read all the one- and two-electron integrals, and store them in memory #. Check in the |EZFIO| database if there is a set of |MOs|. If there is, it will read them as initial guess. Otherwise, it will create a guess. #. Perform the |SCF| iterations +The definition of the Fock matrix is in :file:`kohn_sham_rs fock_matrix_rs_ks.irp.f` +For the keywords related to the |SCF| procedure, see the ``scf_utils`` directory where you will find all options. +The main are: +# :option:`scf_utils thresh_scf` +# :option:`scf_utils level_shift` + + At each iteration, the |MOs| are saved in the |EZFIO| database. Hence, if the calculation crashes for any unexpected reason, the calculation can be restarted by running again the |SCF| with the same |EZFIO| database. @@ -24,8 +33,6 @@ To start a calculation from scratch, the simplest way is to remove the ``mo_basis`` directory from the |EZFIO| database, and run the |SCF| again. - - .. _DIIS: https://en.wikipedia.org/w/index.php?title=DIIS .. _level-shifting: https://doi.org/10.1002/qua.560070407 diff --git a/src/kohn_sham_rs/fock_matrix_rs_ks.irp.f b/src/kohn_sham_rs/fock_matrix_rs_ks.irp.f index fdc26dba..31f912ea 100644 --- a/src/kohn_sham_rs/fock_matrix_rs_ks.irp.f +++ b/src/kohn_sham_rs/fock_matrix_rs_ks.irp.f @@ -245,50 +245,3 @@ END_PROVIDER END_PROVIDER - - - BEGIN_PROVIDER [ double precision, RS_KS_energy ] -!BEGIN_PROVIDER [ double precision, SCF_energy ] -&BEGIN_PROVIDER [ double precision, two_electron_energy] -&BEGIN_PROVIDER [ double precision, one_electron_energy] -&BEGIN_PROVIDER [ double precision, Fock_matrix_energy] -&BEGIN_PROVIDER [ double precision, trace_potential_xc ] - implicit none - BEGIN_DOC - ! Range-separated Kohn-Sham energy - END_DOC - RS_KS_energy = nuclear_repulsion - - integer :: i,j - double precision :: accu_mono,accu_fock - one_electron_energy = 0.d0 - two_electron_energy = 0.d0 - Fock_matrix_energy = 0.d0 - trace_potential_xc = 0.d0 - do j=1,ao_num - do i=1,ao_num - Fock_matrix_energy += Fock_matrix_ao_alpha(i,j) * SCF_density_matrix_ao_alpha(i,j) + & - Fock_matrix_ao_beta(i,j) * SCF_density_matrix_ao_beta(i,j) - two_electron_energy += 0.5d0 * ( ao_bi_elec_integral_alpha(i,j) * SCF_density_matrix_ao_alpha(i,j) & - +ao_bi_elec_integral_beta(i,j) * SCF_density_matrix_ao_beta(i,j) ) - one_electron_energy += ao_mono_elec_integral(i,j) * (SCF_density_matrix_ao_alpha(i,j) + SCF_density_matrix_ao_beta (i,j) ) -! possible bug fix for open-shell -! trace_potential_xc += (ao_potential_alpha_xc(i,j) + ao_potential_beta_xc(i,j) ) * (SCF_density_matrix_ao_alpha(i,j) + SCF_density_matrix_ao_beta (i,j) ) - trace_potential_xc += ao_potential_alpha_xc(i,j) * SCF_density_matrix_ao_alpha(i,j) + ao_potential_beta_xc(i,j) * SCF_density_matrix_ao_beta (i,j) - enddo - enddo - RS_KS_energy += e_exchange_dft + e_correlation_dft + one_electron_energy + two_electron_energy -!SCF_energy = RS_KS_energy -END_PROVIDER - -BEGIN_PROVIDER [double precision, extra_energy_contrib_from_density] - implicit none -! possible bug fix for open-shell: -! extra_energy_contrib_from_density = e_exchange_dft + e_correlation_dft - 0.25d0 * trace_potential_xc - extra_energy_contrib_from_density = e_exchange_dft + e_correlation_dft - 0.5d0 * trace_potential_xc -END_PROVIDER - -!BEGIN_PROVIDER [ double precision, SCF_energy ] -! implicit none -! SCF_energy = RS_KS_energy -!END_PROVIDER diff --git a/src/kohn_sham_rs/rs_ks_energy.irp.f b/src/kohn_sham_rs/rs_ks_energy.irp.f new file mode 100644 index 00000000..a1bcd769 --- /dev/null +++ b/src/kohn_sham_rs/rs_ks_energy.irp.f @@ -0,0 +1,42 @@ + BEGIN_PROVIDER [ double precision, RS_KS_energy ] +&BEGIN_PROVIDER [ double precision, two_electron_energy] +&BEGIN_PROVIDER [ double precision, one_electron_energy] +&BEGIN_PROVIDER [ double precision, Fock_matrix_energy] +&BEGIN_PROVIDER [ double precision, trace_potential_xc ] + implicit none + BEGIN_DOC + ! Range-separated Kohn-Sham energy containing the nuclear repulsion energy, and the various components of this quantity. + END_DOC + RS_KS_energy = nuclear_repulsion + + integer :: i,j + double precision :: accu_mono,accu_fock + one_electron_energy = 0.d0 + two_electron_energy = 0.d0 + Fock_matrix_energy = 0.d0 + trace_potential_xc = 0.d0 + do j=1,ao_num + do i=1,ao_num + Fock_matrix_energy += Fock_matrix_ao_alpha(i,j) * SCF_density_matrix_ao_alpha(i,j) + & + Fock_matrix_ao_beta(i,j) * SCF_density_matrix_ao_beta(i,j) + two_electron_energy += 0.5d0 * ( ao_bi_elec_integral_alpha(i,j) * SCF_density_matrix_ao_alpha(i,j) & + +ao_bi_elec_integral_beta(i,j) * SCF_density_matrix_ao_beta(i,j) ) + one_electron_energy += ao_mono_elec_integral(i,j) * (SCF_density_matrix_ao_alpha(i,j) + SCF_density_matrix_ao_beta (i,j) ) + trace_potential_xc += ao_potential_alpha_xc(i,j) * SCF_density_matrix_ao_alpha(i,j) + ao_potential_beta_xc(i,j) * SCF_density_matrix_ao_beta (i,j) + enddo + enddo + RS_KS_energy += e_exchange_dft + e_correlation_dft + one_electron_energy + two_electron_energy +END_PROVIDER + +BEGIN_PROVIDER [double precision, extra_e_contrib_density] + implicit none + BEGIN_DOC +! Extra contribution to the SCF energy coming from the density. +! +! For a Hartree-Fock calculation: extra_e_contrib_density = 0 +! +! For a Kohn-Sham or Range-separated Kohn-Sham: the exchange/correlation - 1/2 trace of the V_xc potential + END_DOC + extra_e_contrib_density = e_exchange_dft + e_correlation_dft - 0.5d0 * trace_potential_xc +END_PROVIDER + diff --git a/src/scf_utils/README.rst b/src/scf_utils/README.rst index a672b7f6..db4f3c2c 100644 --- a/src/scf_utils/README.rst +++ b/src/scf_utils/README.rst @@ -3,4 +3,35 @@ scf_utils ========= -TODO + +The scf_utils module performs *Restricted* SCF calculations (the +spatial part of the |MOs| is common for alpha and beta spinorbitals) based on a single-determinant wave function. + +This module does not produce any executable *and must not do*, but instead it contains everything one needs to perform an orbital optimization based on an Fock matrix. +The ``scf_utils`` module is included in the :file:`NEED` of the various single determinant SCF procedures, such as ``hartree_fock`` or ``kohn_sham``, where a specific definition of the Fock matrix is given (see :file:`hartree_fock fock_matrix_hf.irp.f` for an example). + +All SCF programs perform the following actions: + +#. Compute/Read all the one- and two-electron integrals, and store them in memory +#. Check in the |EZFIO| database if there is a set of |MOs|. If there is, it + will read them as initial guess. Otherwise, it will create a guess. +#. Perform the |SCF| iterations based on the definition of the Fock matrix + + +The main keywords/options are: +# :option:`scf_utils thresh_scf` +# :option:`scf_utils level_shift` + +At each iteration, the |MOs| are saved in the |EZFIO| database. Hence, if the calculation +crashes for any unexpected reason, the calculation can be restarted by running again +the |SCF| with the same |EZFIO| database. + +The `DIIS`_ algorithm is implemented, as well as the `level-shifting`_ method. +If the |SCF| does not converge, try again with a higher value of :option:`level_shift`. + +To start a calculation from scratch, the simplest way is to remove the +``mo_basis`` directory from the |EZFIO| database, and run the |SCF| again. + +.. _DIIS: https://en.wikipedia.org/w/index.php?title=DIIS +.. _level-shifting: https://doi.org/10.1002/qua.560070407 + diff --git a/src/scf_utils/fock_matrix.irp.f b/src/scf_utils/fock_matrix.irp.f index 63141d04..ef7725e9 100644 --- a/src/scf_utils/fock_matrix.irp.f +++ b/src/scf_utils/fock_matrix.irp.f @@ -138,7 +138,7 @@ BEGIN_PROVIDER [ double precision, SCF_energy ] (ao_mono_elec_integral(i,j) + Fock_matrix_ao_beta (i,j) ) * SCF_density_matrix_ao_beta (i,j) ) enddo enddo - SCF_energy += extra_energy_contrib_from_density + SCF_energy += extra_e_contrib_density END_PROVIDER