Molecular Orbitals
1. Introduction
The molecular orbitals are linear combinations of the atomic orbitals:
where the sum runs over the atomic orbitals. Their coefficients are stored
in the context in the matrix coefficient. This module evaluates the MOs
on the points of the context: their values, their gradients and Laplacians
(the vgl arrays), and their Hessians.
Orbitals that do not contribute to the wave function, the virtuals of a
single-determinant calculation for instance, can be dropped from the
coefficient matrix with qmckl_mo_basis_select_mo.
The exact wave function has a cusp at each nucleus: the kinetic energy
diverges there and cancels the divergence of the potential, leaving a finite
local energy. To reproduce it, each MO can be replaced close to a nucleus by
a polynomial that satisfies the cusp condition exactly and joins the MO
continuously, in value, gradient and Laplacian, at a radius chosen for each
nucleus and stored in r_cusp. The correction stays off until
qmckl_set_mo_basis_r_cusp provides a radius for each nucleus. Inside a
radius,
where the subtracted term is the contribution to the MO of the s AOs
centered on the same nucleus, and the four coefficients are chosen so that
the polynomial matches that contribution in value, gradient and Laplacian
at the cusp radius, and so that the cusp condition holds at the nucleus.
Finally, qmckl_mo_basis_rescale multiplies the coefficients by a constant,
which brings the determinants back into the range of double precision when
they overflow or underflow. The cusp polynomial is linear in the
coefficients, so it is multiplied by the same constant.
2. Context
The following arrays are stored in the context:
mo_num
| Number of MOs | |
|---|---|---|
coefficient
| [mo_num][ao_num] |
MO coefficients |
coefficient_t
| [ao_num][mo_num] |
Transposed of the Orbital coefficients |
r_cusp
| [nucl_num] |
Radius of the functions for Cusp adjustments |
Computed data:
cusp_param
| [nucl_num][4][mo_num] |
Parameters of the functions for Cusp adjustments |
|---|---|---|
mo_value
| [point_num][mo_num] |
Value of the MOs at point positions |
mo_vgl
| [point_num][5][mo_num] |
Value, gradients, Laplacian of the MOs at point positions |
mo_hessian
| [3][point_num][3][mo_num] |
Hessian of the MOs at point positions |
2.1. Data structure
The uninitialized integer contains one bit set to one for each
initialization function which has not been called. It becomes equal
to zero after all initialization functions have been called. The
struct is then initialized and provided == true.
Some values are initialized by default, and are not concerned by
this mechanism.
2.2. Initialization functions
The MO basis is provided once qmckl_set_mo_basis_mo_num and
qmckl_set_mo_basis_coefficient have both been called;
qmckl_set_mo_basis_r_cusp is optional and turns the cusp adjustment on.
qmckl_exit_code qmckl_set_mo_basis_mo_num (qmckl_context context, const int64_t mo_num);
qmckl_exit_code qmckl_set_mo_basis_coefficient (qmckl_context context, const double * coefficient, const int64_t size_max);
qmckl_exit_code qmckl_set_mo_basis_r_cusp (qmckl_context context, const double * r_cusp, const int64_t size_max);
The setters share the uninitialized bit mask of the context: bit 0 is
cleared by qmckl_set_mo_basis_mo_num and bit 1 by
qmckl_set_mo_basis_coefficient. When both bits are cleared the basis is
provided, and qmckl_finalize_mo_basis builds the transposed
coefficient_t matrix, releases the cached MO values and gradients, and
touches the context so that every cached array is recomputed. A second
call to qmckl_set_mo_basis_mo_num returns
QMCKL_ALREADY_SET, while qmckl_set_mo_basis_coefficient can be called
again: it frees the previous array and copies the new coefficients.
2.3. Cusp adjustment functions
qmckl_set_mo_basis_r_cusp turns the cusp adjustment on. It takes one
radius per nucleus, and inside that radius the contribution of the s AOs
centered on the nucleus is replaced by the cubic polynomial of the
Introduction. The polynomial satisfies the cusp condition at the nucleus,
where Z is the nuclear charge and eta the value of the MO at the nucleus. The polynomial matches the removed contribution in value, gradient and Laplacian at the radius, so the corrected MO stays continuous there.
Setting the radii requires the MO basis and the nuclear charges, and
returns QMCKL_NOT_PROVIDED without them. The function needs the MO values
at the nuclei and the value, gradient and Laplacian of the s AOs at the
radius; it moves the points of the context to those positions, evaluates
them, and puts back the points it found on entry, also when it fails.
Nuclei with a charge below 0.1, dummy atoms, are left without a correction.
The fit divides by quantities that vanish at a radius of zero and at
3/Z, so such a radius, within 1.d-6, is rejected with
QMCKL_INVALID_ARG_2 before the context is modified. If any other step
fails, the context is left without a cusp adjustment rather than with a
half-computed one. The function can be called again to replace the radii.
2.4. Access functions
qmckl_mo_basis_provided returns true once mo_num and the coefficients
have been provided, and false when the context is null. The MO values,
gradients, Laplacians and Hessians are obtained with the getters of the
computation sections below.
bool qmckl_mo_basis_provided (const qmckl_context context);
2.5. Update
It may be desirable to remove certain molecular orbitals (MOs) that do not significantly contribute to the wave function. In particular, in a single determinant calculation, the virtual MOs can be removed as they do not participate in the ground state configuration.
To select a subset of MOs that will be kept, an array of int32_t of size
mo_num is passed in keep, and size_max must be at least mo_num. An
entry equal to zero drops the MO, a non-zero entry keeps it. The kept MOs
are copied in order into a new coefficient matrix, mo_num is updated and
the basis is finalized again; if cusp radii were set, the cusp parameters
are recomputed for the reduced basis. A null keep array, or an array
that keeps no MO at all, is rejected with QMCKL_INVALID_ARG_2.
qmckl_exit_code
qmckl_mo_basis_select_mo (const qmckl_context context,
const int32_t* keep,
const int64_t size_max);
3. Computation
The computed data is stored in the context so that it can be reused by
different kernels. Each array carries the context date at which it was
computed. The point and nucleus setters call qmckl_context_touch, which
copies the new context date into ctx->point.date, and a provider recomputes
its array when ctx->point.date is more recent than the stored date.
The value provider avoids one contraction of the AOs: when the values,
gradients and Laplacians have already been computed at the current point
date, it copies the values out of the vgl array. When r_cusp is set,
the providers call the cusp-corrected kernels instead of the plain ones.
3.1. Computation of MOs: values only
3.1.1. Get
qmckl_exit_code
qmckl_get_mo_basis_mo_value(qmckl_context context,
double* const mo_value,
const int64_t size_max);
qmckl_get_mo_basis_mo_value_inplace computes the values directly into
qmckl_get_mo_basis_mo_value_inplace computes the values directly into
mo_value, which must have room for point.num * mo_num doubles. The
array cached in the context is left untouched; a getter called afterwards
returns the cached values if they are still valid and recomputes them
otherwise.
qmckl_exit_code
qmckl_get_mo_basis_mo_value_inplace (qmckl_context context,
double* const mo_value,
const int64_t size_max);
3.1.2. Provide
qmckl_exit_code qmckl_provide_mo_basis_mo_value(qmckl_context context);
3.1.3. Compute
| Variable | Type | In/Out | Description |
|---|---|---|---|
context |
qmckl_context |
in | Global state |
ao_num |
int64_t |
in | Number of AOs |
mo_num |
int64_t |
in | Number of MOs |
point_num |
int64_t |
in | Number of points |
coefficient_t |
double[ao_num][mo_num] |
in | Transpose of the AO to MO transformation matrix |
ao_value |
double[point_num][ao_num] |
in | Value of the AOs |
mo_value |
double[point_num][mo_num] |
out | Value of the MOs |
The matrix of AO values is very sparse, so we use a sparse-dense matrix multiplication instead of a dgemm, as exposed in https://dx.doi.org/10.1007/978-3-642-38718-0_14.
function qmckl_compute_mo_basis_mo_value_doc(context, &
ao_num, mo_num, point_num, &
coefficient_t, ao_value, mo_value) &
result(info) bind(C)
use qmckl_constants
implicit none
integer (qmckl_context) , intent(in) , value :: context
integer (c_int64_t) , intent(in) , value :: ao_num
integer (c_int64_t) , intent(in) , value :: mo_num
integer (c_int64_t) , intent(in) , value :: point_num
real (c_double ) , intent(in) :: coefficient_t(mo_num,ao_num)
real (c_double ) , intent(in) :: ao_value(ao_num,point_num)
real (c_double ) , intent(out) :: mo_value(mo_num,point_num)
integer(qmckl_exit_code) :: info
integer*8 :: j,k
info = QMCKL_SUCCESS
do j=1,point_num
mo_value(:,j) = 0.d0
do k=1,ao_num
if (ao_value(k,j) == 0.d0) cycle
mo_value(:,j) = mo_value(:,j) + coefficient_t(:,k) * ao_value(k,j)
end do
end do
end function qmckl_compute_mo_basis_mo_value_doc
3.2. Computation of MOs: values, gradient, Laplacian
3.2.1. Get
qmckl_exit_code
qmckl_get_mo_basis_mo_vgl(qmckl_context context,
double* const mo_vgl,
const int64_t size_max);
qmckl_get_mo_basis_mo_vgl_inplace computes the values, gradients and
Laplacians directly into qmckl_get_mo_basis_mo_vgl_inplace computes the values, gradients and
Laplacians directly into mo_vgl, which must have room for
point.num * 5 * mo_num doubles. The array cached in the context is left
untouched; a getter called afterwards returns the cached values if they
are still valid and recomputes them otherwise.
qmckl_exit_code
qmckl_get_mo_basis_mo_vgl_inplace (qmckl_context context,
double* const mo_vgl,
const int64_t size_max);
3.2.2. Provide
qmckl_exit_code qmckl_provide_mo_basis_mo_vgl(qmckl_context context);
3.2.3. Compute
| Variable | Type | In/Out | Description |
|---|---|---|---|
context |
qmckl_context |
in | Global state |
ao_num |
int64_t |
in | Number of AOs |
mo_num |
int64_t |
in | Number of MOs |
point_num |
int64_t |
in | Number of points |
coefficient_t |
double[ao_num][mo_num] |
in | Transpose of the AO to MO transformation matrix |
ao_vgl |
double[point_num][5][ao_num] |
in | Value, gradients and Laplacian of the AOs |
mo_vgl |
double[point_num][5][mo_num] |
out | Value, gradients and Laplacian of the MOs |
The matrix of AO values is very sparse, so we use a sparse-dense matrix multiplication instead of a dgemm, as exposed in https://dx.doi.org/10.1007/978-3-642-38718-0_14.
function qmckl_compute_mo_basis_mo_vgl_doc(context, &
ao_num, mo_num, point_num, &
coefficient_t, ao_vgl, mo_vgl) &
result(info) bind(C)
use qmckl_constants
implicit none
integer(qmckl_context), intent(in), value :: context
integer (c_int64_t) , intent(in) , value :: ao_num
integer (c_int64_t) , intent(in) , value :: mo_num
integer (c_int64_t) , intent(in) , value :: point_num
real (c_double ) , intent(in) :: coefficient_t(mo_num,ao_num)
real (c_double ) , intent(in) :: ao_vgl(ao_num,5,point_num)
real (c_double ) , intent(out) :: mo_vgl(mo_num,5,point_num)
integer(qmckl_exit_code) :: info
integer*8 :: i,j,k
double precision :: c1, c2, c3, c4, c5
info = QMCKL_SUCCESS
do j=1,point_num
mo_vgl(:,:,j) = 0.d0
do k=1,ao_num
if (ao_vgl(k,1,j) /= 0.d0) then
c1 = ao_vgl(k,1,j)
c2 = ao_vgl(k,2,j)
c3 = ao_vgl(k,3,j)
c4 = ao_vgl(k,4,j)
c5 = ao_vgl(k,5,j)
do i=1,mo_num
mo_vgl(i,1,j) = mo_vgl(i,1,j) + coefficient_t(i,k) * c1
mo_vgl(i,2,j) = mo_vgl(i,2,j) + coefficient_t(i,k) * c2
mo_vgl(i,3,j) = mo_vgl(i,3,j) + coefficient_t(i,k) * c3
mo_vgl(i,4,j) = mo_vgl(i,4,j) + coefficient_t(i,k) * c4
mo_vgl(i,5,j) = mo_vgl(i,5,j) + coefficient_t(i,k) * c5
end do
end if
end do
end do
end function qmckl_compute_mo_basis_mo_vgl_doc
3.3. Computation of MOs: Hessian
3.3.1. Get
qmckl_exit_code
qmckl_get_mo_basis_mo_hessian(qmckl_context context,
double* const mo_hessian,
const int64_t size_max);
3.3.2. Provide
qmckl_exit_code qmckl_provide_mo_basis_mo_hessian(qmckl_context context);
3.3.3. Compute
| Variable | Type | In/Out | Description |
|---|---|---|---|
context |
qmckl_context |
in | Global state |
ao_num |
int64_t |
in | Number of AOs |
mo_num |
int64_t |
in | Number of MOs |
point_num |
int64_t |
in | Number of points |
coefficient_t |
double[ao_num][mo_num] |
in | Transpose of the AO to MO transformation matrix |
ao_hessian |
double[3][point_num][4][ao_num] |
in | Hessian of the AOs |
mo_hessian |
double[3][point_num][3][mo_num] |
out | Hessian of the MOs |
integer function qmckl_compute_mo_basis_mo_hessian_doc_f(context, &
ao_num, mo_num, point_num, &
coefficient_t, ao_hessian, mo_hessian) &
bind(C) result(info)
use, intrinsic :: iso_c_binding
use qmckl
implicit none
integer (qmckl_context), intent(in), value :: context
integer (c_int64_t) , intent(in), value :: ao_num, mo_num
integer (c_int64_t) , intent(in), value :: point_num
real (c_double ) , intent(in) :: ao_hessian(ao_num,4,point_num,3)
real (c_double ) , intent(in) :: coefficient_t(mo_num,ao_num)
real (c_double ) , intent(out) :: mo_hessian(mo_num,3,point_num,3)
integer*8 :: i,j,k, kk, jj
info = QMCKL_SUCCESS
do jj=1,3
do j=1,point_num
mo_hessian(:,:,j,jj) = 0.d0
do k=1,ao_num
do kk=1,3
do i=1,mo_num
mo_hessian(i,kk,j,jj) = mo_hessian(i,kk,j,jj) + coefficient_t(i,k) * ao_hessian(k,kk,j,jj)
end do
end do
end do
end do
end do
end function qmckl_compute_mo_basis_mo_hessian_doc_f
| Variable | Type | In/Out | Description |
|---|---|---|---|
context |
qmckl_context |
in | Global state |
nucl_num |
int64_t |
in | Number of nuclei |
ao_num |
int64_t |
in | Number of AOs |
mo_num |
int64_t |
in | Number of MOs |
point_num |
int64_t |
in | Number of points |
ao_nucl |
int64_t[ao_num] |
in | Nucleus on which the AO is centered |
ao_ang_mom |
int32_t[ao_num] |
in | Angular momentum of the shell |
en_distance |
double[point_num][nucl_num] |
in | Electron-nucleus distances |
nucl_coord |
double[3][nucl_num] |
in | Nuclear coordinates |
point_coord |
double[3][point_num] |
in | Electron coordinates |
r_cusp |
double[nucl_num] |
in | Cusp-adjustment radius |
cusp_param |
double[nucl_num][4][mo_num] |
in | Cusp-adjustment parameters |
coefficient_t |
double[ao_num][mo_num] |
in | Transpose of the AO to MO transformation matrix |
ao_hessian |
double[3][point_num][4][ao_num] |
in | Hessian of the AOs |
mo_hessian |
double[3][point_num][3][mo_num] |
out | Hessian of the MOs |
integer function qmckl_compute_mo_basis_mo_hessian_cusp_doc_f(context, &
nucl_num, ao_num, mo_num, point_num, ao_nucl, ao_ang_mom, en_distance, &
nucl_coord, point_coord, r_cusp, cusp_param, coefficient_t, ao_hessian, mo_hessian) &
bind(C) result(info)
use, intrinsic :: iso_c_binding
use qmckl
implicit none
integer(qmckl_context) , intent(in), value :: context
integer (c_int64_t) , intent(in), value :: nucl_num, ao_num, mo_num, point_num
integer (c_int64_t) , intent(in) :: ao_nucl(ao_num)
integer (c_int32_t) , intent(in) :: ao_ang_mom(ao_num)
real (c_double ) , intent(in) :: en_distance(nucl_num, point_num)
real (c_double ) , intent(in) :: nucl_coord(nucl_num,3)
real (c_double ) , intent(in) :: point_coord(point_num,3)
real (c_double ) , intent(in) :: r_cusp(nucl_num)
real (c_double ) , intent(in) :: cusp_param(mo_num,4,nucl_num)
real (c_double ) , intent(in) :: coefficient_t(mo_num,ao_num)
real (c_double ) , intent(in) :: ao_hessian(ao_num,4,point_num,3)
real (c_double ) , intent(out) :: mo_hessian(mo_num,3,point_num,3)
integer*8 :: i,j,k, inucl, kk, jj
double precision :: r, r_inv, r_vec(3)
do jj=1,3
do j=1,point_num
! Initial contribution of the MO
mo_hessian(:,:,j,jj) = 0.d0
do k=1,ao_num
if (ao_hessian(k,1,j,jj) /= 0.d0) then
inucl = ao_nucl(k)+1
if ( (en_distance(inucl,j) > r_cusp(inucl)) .or. (ao_ang_mom(k) > 0) ) then
do kk=1,3
do i=1,mo_num
mo_hessian(i,kk,j,jj) = mo_hessian(i,kk,j,jj) + coefficient_t(i,k) * ao_hessian(k,kk,j,jj)
end do
end do
end if
end if
end do
! Cusp adjustment
do inucl=1,nucl_num
r = en_distance(inucl,j)
if (r < r_cusp(inucl)) then
r_vec(1:3) = point_coord(j,1:3) - nucl_coord(inucl,1:3)
r_inv = 1.d0/r
do kk=1,3
do i=1,mo_num
mo_hessian(i,kk,j,jj) = mo_hessian(i,kk,j,jj) - &
cusp_param(i,2,inucl) * r_vec(kk) * r_vec(jj) * r_inv**3 + &
cusp_param(i,4,inucl) * 3 * r_vec(kk) * r_vec(jj) * r_inv
if (kk == jj) then
mo_hessian(i,kk,j,jj) = mo_hessian(i,kk,j,jj) + &
cusp_param(i,2,inucl) * r_inv + &
cusp_param(i,3,inucl) * 2 + &
cusp_param(i,4,inucl) * 3 * r
end if
end do
end do
end if
end do ! inucl
end do
end do ! jj
info = QMCKL_SUCCESS
end function qmckl_compute_mo_basis_mo_hessian_cusp_doc_f
3.4. Computation of cusp-corrected MOs: values only
3.4.1. Compute
| Variable | Type | In/Out | Description |
|---|---|---|---|
context |
qmckl_context |
in | Global state |
nucl_num |
int64_t |
in | Number of nuclei |
ao_num |
int64_t |
in | Number of AOs |
mo_num |
int64_t |
in | Number of MOs |
point_num |
int64_t |
in | Number of points |
ao_nucl |
int64_t[ao_num] |
in | Nucleus on which the AO is centered |
ao_ang_mom |
int32_t[ao_num] |
in | Angular momentum of the shell |
en_distance |
double[point_num][nucl_num] |
in | Electron-nucleus distances |
r_cusp |
double[nucl_num] |
in | Cusp-adjustment radius |
cusp_param |
double[nucl_num][4][mo_num] |
in | Cusp-adjustment parameters |
coefficient_t |
double[ao_num][mo_num] |
in | Transpose of the AO to MO transformation matrix |
ao_value |
double[point_num][ao_num] |
in | Value of the AOs |
mo_value |
double[point_num][mo_num] |
out | Cusp correction for the values of the MOs |
function qmckl_compute_mo_basis_mo_value_cusp_doc(context, &
nucl_num, ao_num, mo_num, point_num, ao_nucl, ao_ang_mom, en_distance, &
r_cusp, cusp_param, coefficient_t, ao_value, mo_value) &
result(info) bind(C)
use qmckl_constants
implicit none
integer(qmckl_context), intent(in), value :: context
integer (c_int64_t) , intent(in) , value :: nucl_num
integer (c_int64_t) , intent(in) , value :: ao_num
integer (c_int64_t) , intent(in) , value :: mo_num
integer (c_int64_t) , intent(in) , value :: point_num
integer (c_int64_t) , intent(in) :: ao_nucl(ao_num)
integer (c_int32_t) , intent(in) :: ao_ang_mom(ao_num)
real (c_double ) , intent(in) :: en_distance(nucl_num,point_num)
real (c_double ) , intent(in) :: r_cusp(nucl_num)
real (c_double ) , intent(in) :: cusp_param(mo_num,4,nucl_num)
real (c_double ) , intent(in) :: coefficient_t(mo_num,ao_num)
real (c_double ) , intent(in) :: ao_value(ao_num,point_num)
real (c_double ) , intent(out) :: mo_value(mo_num,point_num)
integer(qmckl_exit_code) :: info
integer*8 :: i, j, k, inucl
double precision :: r
info = QMCKL_SUCCESS
do i=1,point_num
mo_value(:,i) = 0.d0
do k=1,ao_num
if (ao_value(k,i) == 0.d0) cycle
inucl = ao_nucl(k)+1
if ( (en_distance(inucl,i) < r_cusp(inucl)) .and. (ao_ang_mom(k) == 0) ) cycle
mo_value(:,i) = mo_value(:,i) + coefficient_t(:,k) * ao_value(k,i)
end do ! k
do inucl=1,nucl_num
r = en_distance(inucl,i)
if (r > r_cusp(inucl)) cycle
do j=1,mo_num
mo_value(j,i) = mo_value(j,i) + &
cusp_param(j,1,inucl) + r*(cusp_param(j,2,inucl) + r*( &
cusp_param(j,3,inucl) + r* cusp_param(j,4,inucl) ))
enddo
enddo ! inucl
enddo ! i
end function qmckl_compute_mo_basis_mo_value_cusp_doc
3.5. Computation of cusp-corrected MOs: values, gradient, Laplacian
3.5.1. Compute
| Variable | Type | In/Out | Description |
|---|---|---|---|
context |
qmckl_context |
in | Global state |
nucl_num |
int64_t |
in | Number of nuclei |
ao_num |
int64_t |
in | Number of AOs |
mo_num |
int64_t |
in | Number of MOs |
point_num |
int64_t |
in | Number of points |
ao_nucl |
int64_t[ao_num] |
in | Nucleus on which the AO is centered |
ao_ang_mom |
int32_t[ao_num] |
in | Angular momentum of the shell |
en_distance |
double[point_num][nucl_num] |
in | Electron-nucleus distances |
nucl_coord |
double[3][nucl_num] |
in | Nuclear coordinates |
point_coord |
double[3][point_num] |
in | Electron coordinates |
r_cusp |
double[nucl_num] |
in | Cusp-adjustment radius |
cusp_param |
double[nucl_num][4][mo_num] |
in | Cusp-adjustment parameters |
coefficient_t |
double[ao_num][mo_num] |
in | Transpose of the AO to MO transformation matrix |
ao_vgl |
double[point_num][5][ao_num] |
in | Value, gradients and Laplacian of the AOs |
mo_vgl |
double[point_num][5][mo_num] |
out | Value, gradients and Laplacian of the MOs |
function qmckl_compute_mo_basis_mo_vgl_cusp_doc(context, &
nucl_num, ao_num, mo_num, point_num, ao_nucl, ao_ang_mom, en_distance, &
nucl_coord, point_coord, r_cusp, cusp_param, coefficient_t, ao_vgl, mo_vgl) &
result(info) bind(C)
use qmckl_constants
implicit none
integer(qmckl_context), intent(in), value :: context
integer (c_int64_t) , intent(in) , value :: nucl_num
integer (c_int64_t) , intent(in) , value :: ao_num
integer (c_int64_t) , intent(in) , value :: mo_num
integer (c_int64_t) , intent(in) , value :: point_num
integer (c_int64_t) , intent(in) :: ao_nucl(ao_num)
integer (c_int32_t) , intent(in) :: ao_ang_mom(ao_num)
real (c_double ) , intent(in) :: en_distance(nucl_num,point_num)
real (c_double ) , intent(in) :: nucl_coord(nucl_num,3)
real (c_double ) , intent(in) :: point_coord(point_num,3)
real (c_double ) , intent(in) :: r_cusp(nucl_num)
real (c_double ) , intent(in) :: cusp_param(mo_num,4,nucl_num)
real (c_double ) , intent(in) :: coefficient_t(mo_num,ao_num)
real (c_double ) , intent(in) :: ao_vgl(ao_num,5,point_num)
real (c_double ) , intent(out) :: mo_vgl(mo_num,5,point_num)
integer(qmckl_exit_code) :: info
integer*8 :: i,j,k, inucl
double precision :: c1, c2, c3, c4, c5
double precision :: r, r_inv, r_vec(3)
do j=1,point_num
! Initial contribution of the MO
mo_vgl(:,:,j) = 0.d0
do k=1,ao_num
if (ao_vgl(k,1,j) /= 0.d0) then
inucl = ao_nucl(k)+1
if ( (en_distance(inucl,j) > r_cusp(inucl)) .or. (ao_ang_mom(k) > 0) ) then
c1 = ao_vgl(k,1,j)
c2 = ao_vgl(k,2,j)
c3 = ao_vgl(k,3,j)
c4 = ao_vgl(k,4,j)
c5 = ao_vgl(k,5,j)
do i=1,mo_num
mo_vgl(i,1,j) = mo_vgl(i,1,j) + coefficient_t(i,k) * c1
mo_vgl(i,2,j) = mo_vgl(i,2,j) + coefficient_t(i,k) * c2
mo_vgl(i,3,j) = mo_vgl(i,3,j) + coefficient_t(i,k) * c3
mo_vgl(i,4,j) = mo_vgl(i,4,j) + coefficient_t(i,k) * c4
mo_vgl(i,5,j) = mo_vgl(i,5,j) + coefficient_t(i,k) * c5
end do
end if
end if
end do
! Cusp adjustment
do inucl=1,nucl_num
r = en_distance(inucl,j)
if (r < r_cusp(inucl)) then
r_vec(1:3) = point_coord(j,1:3) - nucl_coord(inucl,1:3)
r_inv = 1.d0/r
do i=1,mo_num
mo_vgl(i,1,j) = mo_vgl(i,1,j) + &
cusp_param(i,1,inucl) + r*( &
cusp_param(i,2,inucl) + r*( &
cusp_param(i,3,inucl) + r*( &
cusp_param(i,4,inucl) )))
c1 = r_inv * cusp_param(i,2,inucl) + 2.d0*cusp_param(i,3,inucl) + &
r * 3.d0 * cusp_param(i,4,inucl)
mo_vgl(i,2,j) = mo_vgl(i,2,j) + r_vec(1) * c1
mo_vgl(i,3,j) = mo_vgl(i,3,j) + r_vec(2) * c1
mo_vgl(i,4,j) = mo_vgl(i,4,j) + r_vec(3) * c1
mo_vgl(i,5,j) = mo_vgl(i,5,j) + &
2.d0*cusp_param(i,2,inucl)*r_inv + &
6.d0*cusp_param(i,3,inucl) + &
12.d0*cusp_param(i,4,inucl)*r
end do
end if
end do ! inucl
end do
info = QMCKL_SUCCESS
end function qmckl_compute_mo_basis_mo_vgl_cusp_doc
3.6. Rescaling of MO coefficients
When evaluating Slater determinants, the value of the determinants may get out of the range of double precision. A simple fix is to rescale the MO coefficients to put the determinants back in the correct range.
qmckl_mo_basis_rescale multiplies coefficient and coefficient_t by
the scaling factor and touches the context, so the cached MO values,
gradients, Laplacians and Hessians are recomputed from the scaled
coefficients. When the cusp adjustment is on, cusp_param is multiplied by
the same factor: the polynomial is linear in the coefficients, so the
corrected MO stays continuous at the radius and keeps the cusp condition at
the nucleus. A zero factor is rejected with QMCKL_INVALID_ARG_2, and a
basis that is not provided gives QMCKL_NOT_PROVIDED.
qmckl_exit_code
qmckl_mo_basis_rescale(qmckl_context context,
const double scaling_factor);