diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index e8a66ca..9e743c2 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -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: @@ -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 @@ -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 @@ -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 @@ -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: @@ -5456,6 +5460,12 @@ 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) @@ -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 (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 */ @@ -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= mo_num) { - return TREXIO_INVALID_ARG_4; + free(list_up); + return TREXIO_INVALID_MO_INDEX; } } - for (int32_t j=0 ; j= mo_num) { - return TREXIO_INVALID_ARG_4; - } - } - + } + 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 @@ -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, @@ -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; @@ -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; @@ -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, &litude[shell_index]); 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; } -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 @@ -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; @@ -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, &litudes[shell_index]); if (rc != TREXIO_SUCCESS) 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: """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. @@ -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 @@ -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. @@ -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 @@ -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