1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-11-19 12:32:40 +01:00
qmckl/org/qmckl_nucleus.org

42 KiB

Nucleus

All the data relative to the molecular geometry is described here.

Context

The following data stored in the context:

uninitialized int32_t Keeps bit set for uninitialized data
num int64_t Total number of nuclei
provided bool If true, nucleus is valid
charge double[num] Nuclear charges
coord double[3][num] Nuclear coordinates, in transposed format
coord_date int64_t Nuclear coordinates, date if modified
rescale_factor_kappa double The distance scaling factor

Computed data:

nn_distance double[num][num] Nucleus-nucleus distances
nn_distance_date int64_t Date when Nucleus-nucleus distances were computed
nn_distance_rescaled double[num][num] Nucleus-nucleus rescaled distances
nn_distance_rescaled_date int64_t Date when Nucleus-nucleus rescaled distances were computed
repulsion double Nuclear repulsion energy
repulsion_date int64_t Date when the nuclear repulsion energy was computed
en_pot double[walk_num] Electron-nucleus potential energy
en_pot_date int64_t Date when the electron-nucleus potential energy was computed

Data structure

typedef struct qmckl_nucleus_struct {
int64_t   num;
int64_t   repulsion_date;
int64_t   nn_distance_date;
int64_t   nn_distance_rescaled_date;
int64_t   coord_date;
double*   coord;
double*   charge;
double*   nn_distance;
double*   nn_distance_rescaled;
double    repulsion;
double    rescale_factor_kappa;
int32_t   uninitialized;
bool      provided;
int64_t   en_pot_date;
double*   en_pot;
} qmckl_nucleus_struct;

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.

qmckl_exit_code qmckl_init_nucleus(qmckl_context context);
qmckl_exit_code qmckl_init_nucleus(qmckl_context context) {

if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
 return false;
}

qmckl_context_struct* const ctx = (qmckl_context_struct* const) context;
assert (ctx != NULL);

ctx->nucleus.uninitialized = (1 << 3) - 1;

/* Default values */
ctx->nucleus.rescale_factor_kappa = 1.0;

return QMCKL_SUCCESS;
}

Access functions

#+NAME:post

When all the data relative to nuclei have been set, the following function returns true.

bool qmckl_nucleus_provided (const qmckl_context context);

Initialization functions

To set the data relative to the nuclei in the context, the following functions need to be called.

qmckl_exit_code  qmckl_set_nucleus_num    (qmckl_context context, const int64_t num);
qmckl_exit_code  qmckl_set_nucleus_charge (qmckl_context context, const double* charge);
qmckl_exit_code  qmckl_set_nucleus_coord  (qmckl_context context, const char transp, const double* coord);

qmckl_exit_code  qmckl_set_nucleus_rescale_factor (qmckl_context context, const double rescale_factor_kappa);

#+NAME:pre2

#+NAME:post2

To set the number of nuclei, use

The following function sets the nuclear charges of all the atoms.

The following function sets the rescale parameter for the nuclear distances.

The following function sets the nuclear coordinates of all the atoms. The coordinates should be given in atomic units.

Test

const int64_t   nucl_num      = chbrclf_nucl_num;
const double*   nucl_charge   = chbrclf_charge;
const double*   nucl_coord    = &(chbrclf_nucl_coord[0][0]);
const double    nucl_rescale_factor_kappa = 2.0;

/* --- */

qmckl_exit_code rc;

assert(!qmckl_nucleus_provided(context));

int64_t n;
rc = qmckl_get_nucleus_num (context, &n);
assert(rc == QMCKL_NOT_PROVIDED);


rc = qmckl_set_nucleus_num (context, nucl_num);
assert(rc == QMCKL_SUCCESS);
assert(!qmckl_nucleus_provided(context));

rc = qmckl_get_nucleus_num (context, &n);
assert(rc == QMCKL_SUCCESS);
assert(n == nucl_num);

double k;
rc = qmckl_get_nucleus_rescale_factor (context, &k);
assert(rc == QMCKL_SUCCESS);
assert(k == 1.0);


rc = qmckl_set_nucleus_rescale_factor (context, nucl_rescale_factor_kappa);
assert(rc == QMCKL_SUCCESS);

rc = qmckl_get_nucleus_rescale_factor (context, &k);
assert(rc == QMCKL_SUCCESS);
assert(k == nucl_rescale_factor_kappa);

double nucl_coord2[3*nucl_num];

rc = qmckl_get_nucleus_coord (context, 'T', nucl_coord2);
assert(rc == QMCKL_NOT_PROVIDED);

rc = qmckl_set_nucleus_coord (context, 'T', &(nucl_coord[0]));
assert(rc == QMCKL_SUCCESS);

assert(!qmckl_nucleus_provided(context));

rc = qmckl_get_nucleus_coord (context, 'N', nucl_coord2);
assert(rc == QMCKL_SUCCESS);
for (size_t k=0 ; k<3 ; ++k) {
for (size_t i=0 ; i<nucl_num ; ++i) {
assert( nucl_coord[nucl_num*k+i] == nucl_coord2[3*i+k] );
}
}

rc = qmckl_get_nucleus_coord (context, 'T', nucl_coord2);
assert(rc == QMCKL_SUCCESS);
for (size_t i=0 ; i<3*nucl_num ; ++i) {
assert( nucl_coord[i] == nucl_coord2[i] );
}

double nucl_charge2[nucl_num];

rc = qmckl_get_nucleus_charge(context, nucl_charge2);
assert(rc == QMCKL_NOT_PROVIDED);

rc = qmckl_set_nucleus_charge(context, nucl_charge);
assert(rc == QMCKL_SUCCESS);

rc = qmckl_get_nucleus_charge(context, nucl_charge2);
assert(rc == QMCKL_SUCCESS);
for (size_t i=0 ; i<nucl_num ; ++i) {
assert( nucl_charge[i] == nucl_charge2[i] );
}
assert(qmckl_nucleus_provided(context));

Computation

The computed data is stored in the context so that it can be reused by different kernels. To ensure that the data is valid, for each computed data the date of the context is stored when it is computed. To know if some data needs to be recomputed, we check if the date of the dependencies are more recent than the date of the data to compute. If it is the case, then the data is recomputed and the current date is stored.

Nucleus-nucleus distances

Get

qmckl_exit_code qmckl_get_nucleus_nn_distance(qmckl_context context, double* distance);

Compute

qmckl_context context in Global state
int64_t nucl_num in Number of nuclei
double coord[3][nucl_num] in Nuclear coordinates (au)
double nn_distance[nucl_num][nucl_num] out Nucleus-nucleus distances (au)
integer function qmckl_compute_nn_distance_f(context, nucl_num, coord, nn_distance) &
 result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in)  :: context
integer*8             , intent(in)  :: nucl_num
double precision      , intent(in)  :: coord(nucl_num,3)
double precision      , intent(out) :: nn_distance(nucl_num,nucl_num)

integer*8 :: k

info = QMCKL_SUCCESS

if (context == QMCKL_NULL_CONTEXT) then
 info = QMCKL_INVALID_CONTEXT
 return
endif

if (nucl_num <= 0) then
 info = QMCKL_INVALID_ARG_2
 return
endif

info = qmckl_distance(context, 'T', 'T', nucl_num, nucl_num, &
      coord, nucl_num, &
      coord, nucl_num, &
      nn_distance, nucl_num)

end function qmckl_compute_nn_distance_f

Test

/* Reference input data */

assert(qmckl_nucleus_provided(context));

double distance[nucl_num*nucl_num];
rc = qmckl_get_nucleus_nn_distance(context, distance);
assert(distance[0] == 0.);
assert(distance[1] == distance[nucl_num]);
assert(fabs(distance[1]-2.070304721365169) < 1.e-12);

Nucleus-nucleus rescaled distances

Get

qmckl_exit_code qmckl_get_nucleus_nn_distance_rescaled(qmckl_context context, double* distance_rescaled);

Compute

qmckl_context context in Global state
int64_t nucl_num in Number of nuclei
double coord[3][nucl_num] in Nuclear coordinates (au)
double nn_distance_rescaled[nucl_num][nucl_num] out Nucleus-nucleus rescaled distances (au)
integer function qmckl_compute_nn_distance_rescaled_f(context, nucl_num, rescale_factor_kappa, coord, nn_distance_rescaled) &
 result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in)  :: context
integer*8             , intent(in)  :: nucl_num
double precision      , intent(in)  :: rescale_factor_kappa
double precision      , intent(in)  :: coord(nucl_num,3)
double precision      , intent(out) :: nn_distance_rescaled(nucl_num,nucl_num)

integer*8 :: k

info = QMCKL_SUCCESS

if (context == QMCKL_NULL_CONTEXT) then
 info = QMCKL_INVALID_CONTEXT
 return
endif

if (nucl_num <= 0) then
 info = QMCKL_INVALID_ARG_2
 return
endif

info = qmckl_distance_rescaled(context, 'T', 'T', nucl_num, nucl_num, &
      coord, nucl_num, &
      coord, nucl_num, &
      nn_distance_rescaled, nucl_num, rescale_factor_kappa)

end function qmckl_compute_nn_distance_rescaled_f

Test

/* Reference input data */
/* TODO */

//assert(qmckl_nucleus_provided(context));
//
//double distance[nucl_num*nucl_num];
//rc = qmckl_get_nucleus_nn_distance(context, distance);
//assert(distance[0] == 0.);
//assert(distance[1] == distance[nucl_num]);
//assert(fabs(distance[1]-2.070304721365169) < 1.e-12);

Nuclear repulsion energy

\[ V_{NN} = \sum_{A=1}^{N-1} \sum_{B>A}^N \frac{Q_A Q_B}{R_{AB}} \]

Get

qmckl_exit_code qmckl_get_nucleus_repulsion(qmckl_context context, double* energy);

Compute

qmckl_context context in Global state
int64_t nucl_num in Number of nuclei
double charge[nucl_num] in Nuclear charges (au)
double nn_distance[nucl_num][nucl_num] in Nucleus-nucleus distances (au)
double energy out Nuclear repulsion energy
integer function qmckl_compute_nucleus_repulsion_f(context, nucl_num, charge, nn_distance, energy) &
 result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in)  :: context
integer*8             , intent(in)  :: nucl_num
double precision      , intent(in)  :: charge(nucl_num)
double precision      , intent(in)  :: nn_distance(nucl_num,nucl_num)
double precision      , intent(out) :: energy

integer*8 :: i, j

info = QMCKL_SUCCESS

if (context == QMCKL_NULL_CONTEXT) then
 info = QMCKL_INVALID_CONTEXT
 return
endif

if (nucl_num <= 0) then
 info = QMCKL_INVALID_ARG_2
 return
endif

energy = 0.d0
do j=2, nucl_num
 do i=1, j-1
    energy = energy + charge(i) * charge(j) / nn_distance(i,j)
 end do
end do

end function qmckl_compute_nucleus_repulsion_f

Test

/* Reference input data */

assert(qmckl_nucleus_provided(context));

double rep;
rc = qmckl_get_nucleus_repulsion(context, &rep);
assert(rep - 318.2309879436158 < 1.e-10);

Electron-nucleus potential

en_potential stores the en potential energy

\[ \mathcal{V}_{en} = -\sum_{i=1}^{N_e}\sum_{A=1}^{N_n}\frac{Z_A}{r_{iA}} \]

where \(\mathcal{V}_{en}\) is the en potential, \[r_{iA}\] the en distance and \[Z_A\] is the nuclear charge.

Get

qmckl_exit_code qmckl_get_electron_en_potential(qmckl_context context, double* const en_pot);

Compute

qmckl_context context in Global state
int64_t elec_num in Number of electrons
int64_t nucl_num in Number of nucleii
int64_t walk_num in Number of walkers
double charge[nucl_num] in charge of nucleus
double en_distance[walk_num][nucl_num][elec_num] in Electron-electron rescaled distances
double en_pot[walk_num] out Electron-electron potential
integer function qmckl_compute_en_potential_f(context, elec_num, nucl_num, walk_num, &
 charge, en_distance, en_pot) &
 result(info)
use qmckl
implicit none
integer(qmckl_context), intent(in)  :: context
integer*8             , intent(in)  :: elec_num
integer*8             , intent(in)  :: nucl_num
integer*8             , intent(in)  :: walk_num
double precision      , intent(in)  :: charge(nucl_num)
double precision      , intent(in)  :: en_distance(elec_num,nucl_num,walk_num)
double precision      , intent(out) :: en_pot(walk_num)

integer*8 :: nw, i, j

info = QMCKL_SUCCESS

if (context == QMCKL_NULL_CONTEXT) then
 info = QMCKL_INVALID_CONTEXT
 return
endif

if (elec_num <= 0) then
 info = QMCKL_INVALID_ARG_2
 return
endif

if (walk_num <= 0) then
 info = QMCKL_INVALID_ARG_3
 return
endif

en_pot = 0.0d0
do nw=1,walk_num
do j=1,nucl_num
  do i=1,elec_num
    en_pot(nw) = en_pot(nw) - charge(j)/(en_distance(i,j,nw))
  end do
end do
end do

end function qmckl_compute_en_potential_f
qmckl_exit_code qmckl_compute_en_potential (
const qmckl_context context,
const int64_t elec_num,
const int64_t nucl_num,
const int64_t walk_num,
const double* charge,
const double* en_distance,
double* const en_pot );

Test