Skip to content

Commit

Permalink
Changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
scemama committed Nov 11, 2024
1 parent 0867434 commit 9459377
Showing 1 changed file with 56 additions and 37 deletions.
93 changes: 56 additions & 37 deletions src/templates_front/templator_front.org
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ with open('../../trex.json','r') as f:
res += line.rstrip()+'\n'
res += "*/"
return res
#+end_src
#+end_src

#+RESULTS: trex_json
:results:
Expand Down Expand Up @@ -470,6 +470,7 @@ __trexio_path__ = None
| ~TREXIO_INVALID_STATE~ | 35 | 'Inconsistent state of the file' |
| ~TREXIO_VERSION_PARSING_ISSUE~ | 36 | 'Failed to parse package_version' |
| ~TREXIO_PHASE_CHANGE~ | 37 | 'The function succeeded with a change of sign' |
| ~TREXIO_INVALID_MO_INDEX~ | 38 | 'Invalid MO index' |

# We need to force Emacs not to indent the Python code:
# -*- org-src-preserve-indentation: t
Expand Down Expand Up @@ -554,6 +555,7 @@ return '\n'.join(result)
#define TREXIO_INVALID_STATE ((trexio_exit_code) 35)
#define TREXIO_VERSION_PARSING_ISSUE ((trexio_exit_code) 36)
#define TREXIO_PHASE_CHANGE ((trexio_exit_code) 37)
#define TREXIO_INVALID_MO_INDEX ((trexio_exit_code) 38)
#+end_src

#+begin_src f90 :tangle prefix_fortran.f90 :exports none
Expand Down Expand Up @@ -596,6 +598,7 @@ return '\n'.join(result)
integer(trexio_exit_code), parameter :: TREXIO_INVALID_STATE = 35
integer(trexio_exit_code), parameter :: TREXIO_VERSION_PARSING_ISSUE = 36
integer(trexio_exit_code), parameter :: TREXIO_PHASE_CHANGE = 37
integer(trexio_exit_code), parameter :: TREXIO_INVALID_MO_INDEX = 38
#+end_src

#+begin_src python :tangle prefix_python.py :exports none
Expand Down Expand Up @@ -639,6 +642,7 @@ return '\n'.join(result)
TREXIO_INVALID_STATE = 35
TREXIO_VERSION_PARSING_ISSUE = 36
TREXIO_PHASE_CHANGE = 37
TREXIO_INVALID_MO_INDEX = 38
#+end_src
:end:

Expand Down Expand Up @@ -5456,14 +5460,20 @@ trexio_read_safe_determinant_list (trexio_t* const file, const int64_t offset_fi
}
#+end_src

When writing a determinant list, the indices of the MOs are checked. If they
are out of bounds (<0 or >= mo_num), the error ~TREXIO_INVALID_MO_INDEX~ is returned.
If the number of orbitals in up-spin or down-spin determinants is different from
the number of up-spin and down-spin electrons, the error ~TREXIO_INVALID_ELECTRON_NUM~
is returned.

#+begin_src c :tangle write_determinant_front.c
trexio_exit_code
trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file, const int64_t buffer_size, const int64_t* dset)
{

if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2;
if (buffer_size < 0) return TREXIO_INVALID_ARG_3;
if (buffer_size <= 0) return TREXIO_INVALID_ARG_3;
if (dset == NULL) return TREXIO_INVALID_ARG_4;

/* Get the number of int bit fields per determinant */
Expand All @@ -5481,40 +5491,49 @@ trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file,
rc = trexio_read_mo_num_64(file, &mo_num);
if (rc != TREXIO_SUCCESS) return rc;

// Read up/dn num
// Read up/dn num
int32_t nup = 0;
rc = trexio_read_electron_up_num(file, &nup);
if (rc != TREXIO_SUCCESS) return rc;

int32_t ndn = 0;
rc = trexio_read_electron_dn_num(file, &ndn);
if (rc != TREXIO_SUCCESS) return rc;

/* Check all determinants */
int32_t list_up[nup];
int32_t list_dn[ndn];
int32_t occ_num_up;
int32_t occ_num_dn;
int32_t occ_num_up = 0;
int32_t occ_num_dn = 0;

/* list_up contains first the up-spin orbitals, then the down-spin
int32_t* list_up = (int32_t*) calloc(nup+ndn,sizeof(int32_t));

if (list_up == NULL) {
return TREXIO_ALLOCATION_FAILED;
}

int32_t* list_dn = &(list_up[nup]);

for (int64_t i=0 ; i<buffer_size ; i+= 2*int_num) {
rc = trexio_to_orbital_list_up_dn(int_num, &dset[i],
list_up, list_dn,
&occ_num_up, &occ_num_dn);
if (rc != TREXIO_SUCCESS) return rc;
if (rc != TREXIO_SUCCESS) {
free(list_up);
return rc;
}
if (occ_num_up != nup || occ_num_dn != ndn) {
return TREXIO_INVALID_ARG_4;
free(list_up);
return TREXIO_INVALID_ELECTRON_NUM;
}
for (int32_t j=0 ; j<occ_num_up ; ++j) {
for (int32_t j=0 ; j<nup+ndn ; ++j) {
if (list_up[j] < 0 || list_up[j] >= mo_num) {
return TREXIO_INVALID_ARG_4;
}
}
for (int32_t j=0 ; j<occ_num_dn ; ++j) {
if (list_dn[j] < 0 || list_dn[j] >= mo_num) {
return TREXIO_INVALID_ARG_4;
free(list_up);
return TREXIO_INVALID_MO_INDEX;
}
}

}
free(list_up);

/* Up to this point, all the determinants have been checked to
have the correct sizes (number of electrons), and MOs in the
Expand Down Expand Up @@ -5917,18 +5936,18 @@ trexio_exit_code trexio_convert_nao_radius_py (const double r,
double* grid_r, int32_t n_grid_r, double* const log_r_out);
trexio_exit_code trexio_evaluate_nao_radial (const int32_t shell_index,
const double r, const int32_t* const grid_start, const int32_t* const grid_size,
const double* const grid_r, const double* const interpolator,
const double* const grid_r, const double* const interpolator,
const double* const normalization, double* const amplitude);

trexio_exit_code trexio_evaluate_nao_radial_all (const int32_t shell_num,
const int32_t* const nucleus_index, const double* const nucleus_coords,
const int32_t* const grid_start, const int32_t* const grid_size,
const double* const grid_r, const double* const interpolator, const double* const normalization,
const int32_t* const nucleus_index, const double* const nucleus_coords,
const int32_t* const grid_start, const int32_t* const grid_size,
const double* const grid_r, const double* const interpolator, const double* const normalization,
const double rx, const double ry, const double rz, double* const amplitude);

trexio_exit_code trexio_evaluate_nao_radial_py (const int shell_index,
trexio_exit_code trexio_evaluate_nao_radial_py (const int shell_index,
const double r, int64_t* grid_start, int n_grid_st, int64_t* grid_size,
int n_grid_si, double* grid_r, int n_grid_r, double* interpolator,
int n_grid_si, double* grid_r, int n_grid_r, double* interpolator,
int n_interp, double* normalization, int n_norm, double* const amplitude);

trexio_exit_code trexio_evaluate_nao_radial_all_py (const int32_t shell_num,
Expand Down Expand Up @@ -6128,7 +6147,7 @@ trexio_evaluate_nao_radial (const int32_t shell_index, const double r, const int

const int32_t i0 = 4*grid_start[shell_index];

// Convert radius to logarithmic units
// Convert radius to logarithmic units
double r_log = 0.0;
trexio_convert_nao_radius_64 (r, grid_r + grid_start[shell_index], &r_log);
int32_t i_log = (int32_t) r_log;
Expand All @@ -6149,7 +6168,7 @@ trexio_evaluate_nao_radial (const int32_t shell_index, const double r, const int

trexio_exit_code
trexio_evaluate_nao_radial_all (const int32_t shell_num, const int32_t* const nucleus_index, const double* const nucleus_coords, const int32_t* const grid_start,
const int32_t* const grid_size, const double* const grid_r, const double* const interpolator,
const int32_t* const grid_size, const double* const grid_r, const double* const interpolator,
const double* const normalization, const double rx, const double ry, const double rz, double* const amplitude)
{
if (shell_num < 0) return TREXIO_INVALID_ARG_1;
Expand All @@ -6171,7 +6190,7 @@ trexio_evaluate_nao_radial_all (const int32_t shell_num, const int32_t* const nu
const double r = sqrt(dx*dx + dy*dy + dz*dz);

// All possibly reported errors have been caught above
rc = trexio_evaluate_nao_radial(shell_index, r, grid_start,
rc = trexio_evaluate_nao_radial(shell_index, r, grid_start,
grid_size, grid_r, interpolator, normalization, &amplitude[shell_index]);

if (rc != TREXIO_SUCCESS)
Expand All @@ -6181,9 +6200,9 @@ trexio_evaluate_nao_radial_all (const int32_t shell_num, const int32_t* const nu
return TREXIO_SUCCESS;
}

trexio_exit_code trexio_evaluate_nao_radial_py (const int shell_index,
trexio_exit_code trexio_evaluate_nao_radial_py (const int shell_index,
const double r, int64_t* grid_start, int n_grid_st,
int64_t* grid_size, int n_grid_si, double* grid_r, int n_grid_r,
int64_t* grid_size, int n_grid_si, double* grid_r, int n_grid_r,
double* interpolator, int n_interp, double* normalization, int n_norm, double* const amplitude)
{
// Code needs to be copied because of the use of int64_t mandated by Python
Expand All @@ -6198,7 +6217,7 @@ trexio_exit_code trexio_evaluate_nao_radial_py (const int shell_index,

const int32_t i0 = 4*grid_start[shell_index];

// Convert radius to logarithmic units
// Convert radius to logarithmic units
double r_log = 0.0;
trexio_convert_nao_radius_64 (r, grid_r + grid_start[shell_index], &r_log);
int32_t i_log = (int32_t) r_log;
Expand Down Expand Up @@ -6246,7 +6265,7 @@ trexio_exit_code trexio_evaluate_nao_radial_all_py (const int32_t shell_num,
const double r = sqrt(dx*dx + dy*dy + dz*dz);

// All possibly reported errors have been caught above
rc = trexio_evaluate_nao_radial_py(shell_index, r, grid_start, n_grid_st,
rc = trexio_evaluate_nao_radial_py(shell_index, r, grid_start, n_grid_st,
grid_size, n_grid_si, grid_r, n_grid_r, interpolator, n_interp, normalization, n_norm, &amplitudes[shell_index]);
if (rc != TREXIO_SUCCESS)
return rc;
Expand Down Expand Up @@ -6550,14 +6569,14 @@ def to_orbital_list_up_dn(n_int: int, determinant: list) -> tuple:
def convert_nao_radius(r: float, grid_r) -> float:
"""Converts the radius r as a distance from a nucleus to the shell
s logarithmic grid.

Input:
~r~ - the radius to be converted
~grid_r~ - The radial grid of the shell. Note that this is only the
grid of the shell of interest, not the array of all shells.

Returns:
Float that gives the radius in the shell's logarithmic units
Float that gives the radius in the shell's logarithmic units

Raises:
- Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.
Expand All @@ -6574,7 +6593,7 @@ def convert_nao_radius(r: float, grid_r) -> float:

def evaluate_nao_radial(shell_index, r, grid_start, grid_size, grid_r, interpolator, normalization) -> float:
"""Evaluates the radial function of a given NAO shell at a distance from its center.

Input:
~shell_index~ - index of the shell of interest
~r~ - distance from the shell center
Expand All @@ -6587,7 +6606,7 @@ def evaluate_nao_radial(shell_index, r, grid_start, grid_size, grid_r, interpola
~normalization~ - array of radial function normalization constants.

Returns:
Value of the spline at the given radius
Value of the spline at the given radius

Raises:
- Error from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.
Expand All @@ -6604,7 +6623,7 @@ def evaluate_nao_radial(shell_index, r, grid_start, grid_size, grid_r, interpola
def evaluate_nao_radial_all(nucleus_index, nucleus_coords, grid_start,
grid_size, grid_r, interpolator, normalization, r) -> float:
"""Evaluates the radial functions of all NAO shells at a given position in space.

Input:
~nucleus_index~ - array giving the centers of the NAO
~nucleus_coords~ - array giving the coordinates of the NAO centers
Expand All @@ -6618,7 +6637,7 @@ def evaluate_nao_radial_all(nucleus_index, nucleus_coords, grid_start,
~r~ - the position in space at which the functions are evaluated

Returns:
Array of spline values at ~r~
Array of spline values at ~r~

Raises:
- Error if ~r~ is not three dimensional
Expand Down

0 comments on commit 9459377

Please sign in to comment.