1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2025-01-09 12:44:11 +01:00

Changes after review

This commit is contained in:
Anthony Scemama 2024-11-11 02:54:28 +01:00
parent 08674345a8
commit 9459377a3f

View File

@ -32,7 +32,7 @@ with open('../../trex.json','r') as f:
res += line.rstrip()+'\n' res += line.rstrip()+'\n'
res += "*/" res += "*/"
return res return res
#+end_src #+end_src
#+RESULTS: trex_json #+RESULTS: trex_json
:results: :results:
@ -470,6 +470,7 @@ __trexio_path__ = None
| ~TREXIO_INVALID_STATE~ | 35 | 'Inconsistent state of the file' | | ~TREXIO_INVALID_STATE~ | 35 | 'Inconsistent state of the file' |
| ~TREXIO_VERSION_PARSING_ISSUE~ | 36 | 'Failed to parse package_version' | | ~TREXIO_VERSION_PARSING_ISSUE~ | 36 | 'Failed to parse package_version' |
| ~TREXIO_PHASE_CHANGE~ | 37 | 'The function succeeded with a change of sign' | | ~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: # We need to force Emacs not to indent the Python code:
# -*- org-src-preserve-indentation: t # -*- org-src-preserve-indentation: t
@ -554,6 +555,7 @@ return '\n'.join(result)
#define TREXIO_INVALID_STATE ((trexio_exit_code) 35) #define TREXIO_INVALID_STATE ((trexio_exit_code) 35)
#define TREXIO_VERSION_PARSING_ISSUE ((trexio_exit_code) 36) #define TREXIO_VERSION_PARSING_ISSUE ((trexio_exit_code) 36)
#define TREXIO_PHASE_CHANGE ((trexio_exit_code) 37) #define TREXIO_PHASE_CHANGE ((trexio_exit_code) 37)
#define TREXIO_INVALID_MO_INDEX ((trexio_exit_code) 38)
#+end_src #+end_src
#+begin_src f90 :tangle prefix_fortran.f90 :exports none #+begin_src f90 :tangle prefix_fortran.f90 :exports none
@ -596,6 +598,7 @@ return '\n'.join(result)
integer(trexio_exit_code), parameter :: TREXIO_INVALID_STATE = 35 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_VERSION_PARSING_ISSUE = 36
integer(trexio_exit_code), parameter :: TREXIO_PHASE_CHANGE = 37 integer(trexio_exit_code), parameter :: TREXIO_PHASE_CHANGE = 37
integer(trexio_exit_code), parameter :: TREXIO_INVALID_MO_INDEX = 38
#+end_src #+end_src
#+begin_src python :tangle prefix_python.py :exports none #+begin_src python :tangle prefix_python.py :exports none
@ -639,6 +642,7 @@ return '\n'.join(result)
TREXIO_INVALID_STATE = 35 TREXIO_INVALID_STATE = 35
TREXIO_VERSION_PARSING_ISSUE = 36 TREXIO_VERSION_PARSING_ISSUE = 36
TREXIO_PHASE_CHANGE = 37 TREXIO_PHASE_CHANGE = 37
TREXIO_INVALID_MO_INDEX = 38
#+end_src #+end_src
:end: :end:
@ -5456,6 +5460,12 @@ trexio_read_safe_determinant_list (trexio_t* const file, const int64_t offset_fi
} }
#+end_src #+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 #+begin_src c :tangle write_determinant_front.c
trexio_exit_code 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) trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file, const int64_t buffer_size, const int64_t* dset)
@ -5463,7 +5473,7 @@ trexio_write_determinant_list (trexio_t* const file, const int64_t offset_file,
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0) return TREXIO_INVALID_ARG_2; 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; if (dset == NULL) return TREXIO_INVALID_ARG_4;
/* Get the number of int bit fields per determinant */ /* Get the number of int bit fields per determinant */
@ -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); rc = trexio_read_mo_num_64(file, &mo_num);
if (rc != TREXIO_SUCCESS) return rc; if (rc != TREXIO_SUCCESS) return rc;
// Read up/dn num // Read up/dn num
int32_t nup = 0; int32_t nup = 0;
rc = trexio_read_electron_up_num(file, &nup); rc = trexio_read_electron_up_num(file, &nup);
if (rc != TREXIO_SUCCESS) return rc; if (rc != TREXIO_SUCCESS) return rc;
int32_t ndn = 0; int32_t ndn = 0;
rc = trexio_read_electron_dn_num(file, &ndn); rc = trexio_read_electron_dn_num(file, &ndn);
if (rc != TREXIO_SUCCESS) return rc; if (rc != TREXIO_SUCCESS) return rc;
/* Check all determinants */ /* Check all determinants */
int32_t list_up[nup]; int32_t occ_num_up = 0;
int32_t list_dn[ndn]; int32_t occ_num_dn = 0;
int32_t occ_num_up;
int32_t occ_num_dn; /* 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) { for (int64_t i=0 ; i<buffer_size ; i+= 2*int_num) {
rc = trexio_to_orbital_list_up_dn(int_num, &dset[i], rc = trexio_to_orbital_list_up_dn(int_num, &dset[i],
list_up, list_dn, list_up, list_dn,
&occ_num_up, &occ_num_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) { 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) { if (list_up[j] < 0 || list_up[j] >= mo_num) {
return TREXIO_INVALID_ARG_4; free(list_up);
return TREXIO_INVALID_MO_INDEX;
} }
} }
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);
/* Up to this point, all the determinants have been checked to /* Up to this point, all the determinants have been checked to
have the correct sizes (number of electrons), and MOs in the have the correct sizes (number of electrons), and MOs in the
@ -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); 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, 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 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); const double* const normalization, double* const amplitude);
trexio_exit_code trexio_evaluate_nao_radial_all (const int32_t shell_num, 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 nucleus_index, const double* const nucleus_coords,
const int32_t* const grid_start, const int32_t* const grid_size, 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* const grid_r, const double* const interpolator, const double* const normalization,
const double rx, const double ry, const double rz, double* const amplitude); 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, 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); 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, trexio_exit_code trexio_evaluate_nao_radial_all_py (const int32_t shell_num,
@ -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]; const int32_t i0 = 4*grid_start[shell_index];
// Convert radius to logarithmic units // Convert radius to logarithmic units
double r_log = 0.0; double r_log = 0.0;
trexio_convert_nao_radius_64 (r, grid_r + grid_start[shell_index], &r_log); trexio_convert_nao_radius_64 (r, grid_r + grid_start[shell_index], &r_log);
int32_t i_log = (int32_t) r_log; int32_t i_log = (int32_t) r_log;
@ -6149,7 +6168,7 @@ trexio_evaluate_nao_radial (const int32_t shell_index, const double r, const int
trexio_exit_code 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, 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) 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; if (shell_num < 0) return TREXIO_INVALID_ARG_1;
@ -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); const double r = sqrt(dx*dx + dy*dy + dz*dz);
// All possibly reported errors have been caught above // 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]); grid_size, grid_r, interpolator, normalization, &amplitude[shell_index]);
if (rc != TREXIO_SUCCESS) if (rc != TREXIO_SUCCESS)
@ -6181,9 +6200,9 @@ trexio_evaluate_nao_radial_all (const int32_t shell_num, const int32_t* const nu
return TREXIO_SUCCESS; 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, 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) 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 // Code needs to be copied because of the use of int64_t mandated by Python
@ -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]; const int32_t i0 = 4*grid_start[shell_index];
// Convert radius to logarithmic units // Convert radius to logarithmic units
double r_log = 0.0; double r_log = 0.0;
trexio_convert_nao_radius_64 (r, grid_r + grid_start[shell_index], &r_log); trexio_convert_nao_radius_64 (r, grid_r + grid_start[shell_index], &r_log);
int32_t i_log = (int32_t) r_log; int32_t i_log = (int32_t) r_log;
@ -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); const double r = sqrt(dx*dx + dy*dy + dz*dz);
// All possibly reported errors have been caught above // 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]); grid_size, n_grid_si, grid_r, n_grid_r, interpolator, n_interp, normalization, n_norm, &amplitudes[shell_index]);
if (rc != TREXIO_SUCCESS) if (rc != TREXIO_SUCCESS)
return rc; return rc;
@ -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: def convert_nao_radius(r: float, grid_r) -> float:
"""Converts the radius r as a distance from a nucleus to the shell """Converts the radius r as a distance from a nucleus to the shell
s logarithmic grid. s logarithmic grid.
Input: Input:
~r~ - the radius to be converted ~r~ - the radius to be converted
~grid_r~ - The radial grid of the shell. Note that this is only the ~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. grid of the shell of interest, not the array of all shells.
Returns: Returns:
Float that gives the radius in the shell's logarithmic units Float that gives the radius in the shell's logarithmic units
Raises: Raises:
- Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error. - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.
@ -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: 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. """Evaluates the radial function of a given NAO shell at a distance from its center.
Input: Input:
~shell_index~ - index of the shell of interest ~shell_index~ - index of the shell of interest
~r~ - distance from the shell center ~r~ - distance from the shell center
@ -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. ~normalization~ - array of radial function normalization constants.
Returns: Returns:
Value of the spline at the given radius Value of the spline at the given radius
Raises: Raises:
- Error from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error. - Error from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.
@ -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, def evaluate_nao_radial_all(nucleus_index, nucleus_coords, grid_start,
grid_size, grid_r, interpolator, normalization, r) -> float: grid_size, grid_r, interpolator, normalization, r) -> float:
"""Evaluates the radial functions of all NAO shells at a given position in space. """Evaluates the radial functions of all NAO shells at a given position in space.
Input: Input:
~nucleus_index~ - array giving the centers of the NAO ~nucleus_index~ - array giving the centers of the NAO
~nucleus_coords~ - array giving the coordinates of the NAO centers ~nucleus_coords~ - array giving the coordinates of the NAO centers
@ -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 ~r~ - the position in space at which the functions are evaluated
Returns: Returns:
Array of spline values at ~r~ Array of spline values at ~r~
Raises: Raises:
- Error if ~r~ is not three dimensional - Error if ~r~ is not three dimensional