diff --git a/CMakeLists.txt b/CMakeLists.txt index d30e54a..d680079 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.16) # Initialize the CMake project. project(Trexio - VERSION 2.3.2 + VERSION 2.4.0 DESCRIPTION "TREX I/O library" LANGUAGES C Fortran ) diff --git a/ChangeLog b/ChangeLog index 56c8f04..c5b9e36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ CHANGES ======= +2.4 +--- + +- Added state/energy +- Made state/id an index instead of an int + 2.3 --- diff --git a/configure.ac b/configure.ac index 5228d29..b8f26a7 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) -AC_INIT([trexio],[2.3.2],[https://github.com/TREX-CoE/trexio/issues]) +AC_INIT([trexio],[2.4.0],[https://github.com/TREX-CoE/trexio/issues]) AC_CONFIG_SRCDIR([Makefile.in]) AC_CONFIG_HEADERS([include/config.h]) diff --git a/python/pytrexio/_version.py b/python/pytrexio/_version.py index f708a9b..3d67cd6 100644 --- a/python/pytrexio/_version.py +++ b/python/pytrexio/_version.py @@ -1 +1 @@ -__version__ = "1.3.2" +__version__ = "2.4.0" diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index 91bfdf8..5db927f 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -1732,6 +1732,12 @@ def _cp(source: str, destination: str): and write it as ~state_id~ attribute. ~trexio_get_state~ returns current state of the ~trexio_t~ file handle. + **Warning:** The ~trexio_set_state~ and ~trexio_get_state~ functions still + use the old convention where the ground state was state ~0~. From version 2.4.0, + the ~state_id~ variable has changed to ~index~ type, so using the more recent + ~trexio_write_state_id~ and ~trexio_read_state_id~ will give different results + in Fortran. + input parameters: ~file~ -- TREXIO file handle. ~state~ -- ~int32_t~ ID of a state (0 for ground state). @@ -2132,24 +2138,35 @@ trexio_read_$group_num$_64 (trexio_t* const file, $group_num_dtype_double$* cons if (num == NULL) return TREXIO_INVALID_ARG_2; if (trexio_has_$group_num$(file) != TREXIO_SUCCESS) return TREXIO_ATTR_MISSING; + trexio_exit_code rc = TREXIO_GROUP_READ_ERROR; + switch (file->back_end) { case TREXIO_TEXT: - return trexio_text_read_$group_num$(file, num); + rc = trexio_text_read_$group_num$(file, num); + break; case TREXIO_HDF5: #ifdef HAVE_HDF5 - return trexio_hdf5_read_$group_num$(file, num); + rc = trexio_hdf5_read_$group_num$(file, num); #else - return TREXIO_BACK_END_MISSING; + rc = TREXIO_BACK_END_MISSING; #endif + break; /* case TREXIO_JSON: - return trexio_json_read_$group_num$(file, num); + rc = trexio_json_read_$group_num$(file, num); + break; ,*/ } - return TREXIO_FAILURE; + if (rc != TREXIO_SUCCESS) return rc; + + /* Handle index type */ + if ($is_index$) { + ,*num += ($group_num_dtype_double$) 1; + } + return rc; } #+end_src @@ -2161,20 +2178,26 @@ trexio_write_$group_num$_64 (trexio_t* const file, const $group_num_dtype_double //if (num <= 0L) return TREXIO_INVALID_NUM; /* this line is uncommented by the generator for dimensioning variables; do NOT remove! */ if (trexio_has_$group_num$(file) == TREXIO_SUCCESS && file->mode != 'u') return TREXIO_ATTR_ALREADY_EXISTS; + /* Handle index type */ + $group_num_dtype_double$ num_write = num; + if ($is_index$) { + num_write -= ($group_num_dtype_double$) 1; + } + switch (file->back_end) { case TREXIO_TEXT: - return trexio_text_write_$group_num$(file, num); + return trexio_text_write_$group_num$(file, num_write); case TREXIO_HDF5: #ifdef HAVE_HDF5 - return trexio_hdf5_write_$group_num$(file, num); + return trexio_hdf5_write_$group_num$(file, num_write); #else return TREXIO_BACK_END_MISSING; #endif /* case TREXIO_JSON: - return trexio_json_write_$group_num$(file, num); + return trexio_json_write_$group_num$(file, num_write); ,*/ } @@ -2219,6 +2242,12 @@ trexio_read_$group_num$_32 (trexio_t* const file, $group_num_dtype_single$* cons if (rc != TREXIO_SUCCESS) return rc; ,*num = ($group_num_dtype_single$) num_64; + + /* Handle index type */ + if ($is_index$) { + ,*num += ($group_num_dtype_single$) 1; + } + return TREXIO_SUCCESS; } #+end_src @@ -2232,20 +2261,26 @@ trexio_write_$group_num$_32 (trexio_t* const file, const $group_num_dtype_single //if (num <= 0) return TREXIO_INVALID_NUM; /* this line is uncommented by the generator for dimensioning variables; do NOT remove! */ if (trexio_has_$group_num$(file) == TREXIO_SUCCESS && file->mode != 'u') return TREXIO_ATTR_ALREADY_EXISTS; + /* Handle index type */ + $group_num_dtype_single$ num_write = num; + if ($is_index$) { + num_write -= ($group_num_dtype_single$) 1; + } + switch (file->back_end) { case TREXIO_TEXT: - return trexio_text_write_$group_num$(file, ($group_num_dtype_double$) num); + return trexio_text_write_$group_num$(file, ($group_num_dtype_double$) num_write); case TREXIO_HDF5: #ifdef HAVE_HDF5 - return trexio_hdf5_write_$group_num$(file, ($group_num_dtype_double$) num); + return trexio_hdf5_write_$group_num$(file, ($group_num_dtype_double$) num_write); #else return TREXIO_BACK_END_MISSING; #endif /* case TREXIO_JSON: - return trexio_json_write_$group_num$(file, ($group_num_dtype_double$) num); + return trexio_json_write_$group_num$(file, ($group_num_dtype_double$) num_write); break; ,*/ } diff --git a/tests/io_dset_int_hdf5.c b/tests/io_dset_int_hdf5.c index 42db22b..d307cba 100644 --- a/tests/io_dset_int_hdf5.c +++ b/tests/io_dset_int_hdf5.c @@ -17,6 +17,7 @@ static int test_write_dset (const char* file_name, const back_end_t backend) { // parameters to be written int num = 12; int nucl_index[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + int state_id = 2; /*================= START OF TEST ==================*/ @@ -32,6 +33,10 @@ static int test_write_dset (const char* file_name, const back_end_t backend) { rc = trexio_write_basis_nucleus_index(file, nucl_index); assert (rc == TREXIO_SUCCESS); + // write index attribute in a file + rc = trexio_write_state_id(file, state_id); + assert (rc == TREXIO_SUCCESS); + // close current session rc = trexio_close(file); assert (rc == TREXIO_SUCCESS); @@ -89,8 +94,9 @@ static int test_read_dset (const char* file_name, const back_end_t backend) { trexio_exit_code rc; // parameters to be read - int num; - int* nucl_index; + int num = 0; + int* nucl_index = NULL; + int state_id = 0; /*================= START OF TEST ==================*/ @@ -103,6 +109,11 @@ static int test_read_dset (const char* file_name, const back_end_t backend) { assert (rc == TREXIO_SUCCESS); assert (num == 12); + // read index attribute from the file + rc = trexio_read_state_id(file, &state_id); + assert (rc == TREXIO_SUCCESS); + assert (state_id == 2); + // read numerical dataset from the file nucl_index = (int*) calloc(num, sizeof(int)); rc = trexio_read_basis_nucleus_index(file, nucl_index); diff --git a/tests/io_dset_int_text.c b/tests/io_dset_int_text.c index c1f5a1e..09c536b 100644 --- a/tests/io_dset_int_text.c +++ b/tests/io_dset_int_text.c @@ -17,6 +17,7 @@ static int test_write_dset (const char* file_name, const back_end_t backend) { // parameters to be written int num = 12; int nucl_index[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + int state_id = 2; /*================= START OF TEST ==================*/ @@ -32,6 +33,10 @@ static int test_write_dset (const char* file_name, const back_end_t backend) { rc = trexio_write_basis_nucleus_index(file, nucl_index); assert (rc == TREXIO_SUCCESS); + // write index attribute in a file + rc = trexio_write_state_id(file, state_id); + assert (rc == TREXIO_SUCCESS); + // close current session rc = trexio_close(file); assert (rc == TREXIO_SUCCESS); @@ -89,8 +94,9 @@ static int test_read_dset (const char* file_name, const back_end_t backend) { trexio_exit_code rc; // parameters to be read - int num; - int* nucl_index; + int num = 0; + int* nucl_index = NULL; + int state_id = 0; /*================= START OF TEST ==================*/ @@ -103,6 +109,11 @@ static int test_read_dset (const char* file_name, const back_end_t backend) { assert (rc == TREXIO_SUCCESS); assert (num == 12); + // read index attribute from the file + rc = trexio_read_state_id(file, &state_id); + assert (rc == TREXIO_SUCCESS); + assert (state_id == 2); + // read numerical dataset from the file nucl_index = (int*) calloc(num, sizeof(int)); rc = trexio_read_basis_nucleus_index(file, nucl_index); diff --git a/tests/test_f.f90 b/tests/test_f.f90 index c4fff33..523558c 100644 --- a/tests/test_f.f90 +++ b/tests/test_f.f90 @@ -85,6 +85,7 @@ subroutine test_write(file_name, back_end) integer :: i, j, n_buffers = 5 integer(8) :: buf_size_sparse, buf_size_det, offset + integer :: state_id buf_size_sparse = 100/n_buffers buf_size_det = 50/n_buffers @@ -107,6 +108,7 @@ subroutine test_write(file_name, back_end) ! parameters to be written nucleus_num = 12 + state_id = 2 charge = (/ 6., 6., 6., 6., 6., 6., 1., 1., 1., 1., 1., 1. /) coord = reshape( (/ 0.00000000d0, 1.39250319d0 , 0.00000000d0 , & -1.20594314d0, 0.69625160d0 , 0.00000000d0 , & @@ -182,6 +184,9 @@ subroutine test_write(file_name, back_end) rc = trexio_write_basis_nucleus_index(trex_file, basis_nucleus_index) call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE INDEX') + rc = trexio_write_state_id(trex_file, state_id) + call trexio_assert(rc, TREXIO_SUCCESS, 'SUCCESS WRITE INDEX TYPE') + ! write ao_num which will be used to determine the optimal size of int indices if (trexio_has_ao_num(trex_file) == TREXIO_HAS_NOT) then rc = trexio_write_ao_num(trex_file, ao_num) @@ -302,6 +307,7 @@ subroutine test_read(file_name, back_end) integer*8 :: offset_det_data_read = 5 integer*8 :: determinant_num integer :: int_num + integer :: state_id ! orbital lists integer*4 :: orb_list_up(150) @@ -312,6 +318,7 @@ subroutine test_read(file_name, back_end) num = 12 basis_shell_num = 24 + state_id = 0 index_sparse_ao_2e_int_eri = 0 value_sparse_ao_2e_int_eri = 0.0d0 @@ -379,6 +386,15 @@ subroutine test_read(file_name, back_end) call exit(-1) endif + rc = trexio_read_state_id(trex_file, state_id) + call trexio_assert(rc, TREXIO_SUCCESS) + if (state_id == 2) then + write(*,*) 'SUCCESS READ INDEX TYPE' + else + print *, 'FAILURE INDEX TYPE CHECK' + call exit(-1) + endif + rc = trexio_read_nucleus_point_group(trex_file, sym_str, 10) call trexio_assert(rc, TREXIO_SUCCESS) diff --git a/tools/generator_tools.py b/tools/generator_tools.py index 2cde76f..f8e25db 100644 --- a/tools/generator_tools.py +++ b/tools/generator_tools.py @@ -611,8 +611,13 @@ def get_detailed_num_dict (configuration: dict) -> dict: tmp_dict.update(get_dtype_dict(v2[0], 'num')) if v2[0] in ['int', 'dim', 'dim readonly']: tmp_dict['trex_json_int_type'] = v2[0] + tmp_dict['is_index'] = 'false' + elif v2[0] in ['index']: + tmp_dict['trex_json_int_type'] = v2[0] + tmp_dict['is_index'] = 'file->one_based' else: tmp_dict['trex_json_int_type'] = '' + tmp_dict['is_index'] = 'false' num_dict[tmp_num] = tmp_dict diff --git a/trex.org b/trex.org index ba901a0..101040c 100644 --- a/trex.org +++ b/trex.org @@ -190,13 +190,14 @@ The ~id~ and ~current_label~ attributes need to be specified for each file. #+NAME: state - | Variable | Type | Dimensions | Description | - |-----------------+-------+---------------+---------------------------------------------------------------------------------------------| - | ~num~ | ~dim~ | | Number of states (including the ground state) | - | ~id~ | ~int~ | | Index of the current state (0 is ground state) | - | ~current_label~ | ~str~ | | Label of the current state | - | ~label~ | ~str~ | ~(state.num)~ | Labels of all states | - | ~file_name~ | ~str~ | ~(state.num)~ | Names of the TREXIO files linked to the current one (i.e. containing data for other states) | + | Variable | Type | Dimensions | Description | + |-----------------+---------+---------------+---------------------------------------------------------------------------------------------| + | ~num~ | ~dim~ | | Number of states (including the ground state) | + | ~id~ | ~index~ | | Index of the current state (0 is ground state) | + | ~energy~ | ~float~ | | Energy of the current state | + | ~current_label~ | ~str~ | | Label of the current state | + | ~label~ | ~str~ | ~(state.num)~ | Labels of all states | + | ~file_name~ | ~str~ | ~(state.num)~ | Names of the TREXIO files linked to the current one (i.e. containing data for other states) | #+CALL: json(data=state, title="state") @@ -204,11 +205,12 @@ :results: #+begin_src python :tangle trex.json "state": { - "num" : [ "dim", [] ] - , "id" : [ "int", [] ] - , "current_label" : [ "str", [] ] - , "label" : [ "str", [ "state.num" ] ] - , "file_name" : [ "str", [ "state.num" ] ] + "num" : [ "dim" , [] ] + , "id" : [ "index", [] ] + , "energy" : [ "float", [] ] + , "current_label" : [ "str" , [] ] + , "label" : [ "str" , [ "state.num" ] ] + , "file_name" : [ "str" , [ "state.num" ] ] } , #+end_src :end: