1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-07-22 10:47:43 +02:00

Fixed dim and better restructuration

This commit is contained in:
Anthony Scemama 2023-01-03 19:28:00 +01:00
parent 484ef632e7
commit 52d45c1e51
4 changed files with 479 additions and 59 deletions

View File

@ -100,6 +100,7 @@ TESTS_C = \
tests/io_dset_int_text \
tests/io_dset_sparse_text \
tests/io_determinant_text \
tests/io_jastrow_text \
tests/io_safe_dset_float_text \
tests/io_str_text \
tests/io_dset_str_text \
@ -116,6 +117,7 @@ TESTS_C += \
tests/io_dset_int_hdf5 \
tests/io_dset_sparse_hdf5 \
tests/io_determinant_hdf5 \
tests/io_jastrow_hdf5 \
tests/io_safe_dset_float_hdf5 \
tests/io_str_hdf5 \
tests/io_dset_str_hdf5 \

198
tests/io_jastrow_hdf5.c Normal file
View File

@ -0,0 +1,198 @@
#include "trexio.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#define TEST_BACKEND TREXIO_HDF5
#define TREXIO_FILE "test_jastrow.h5"
#define RM_COMMAND "rm -f -- " TREXIO_FILE
static int test_write_jastrow (const char* file_name, const back_end_t backend) {
/* Try to write an array of sparse data into the TREXIO file */
trexio_t* file = NULL;
trexio_exit_code rc;
/*================= START OF TEST ==================*/
// open file in 'write' mode
file = trexio_open(file_name, 'w', backend, &rc);
assert (file != NULL);
assert (rc == TREXIO_SUCCESS);
#define nucleus_num 3
#define ee_num 2
#define en_num 3
#define een_num 6
rc = trexio_write_nucleus_num(file, nucleus_num);
assert (rc == TREXIO_SUCCESS);
rc = trexio_write_jastrow_type(file, "CHAMP", 6);
assert (rc == TREXIO_SUCCESS);
rc = trexio_write_jastrow_ee_num(file, ee_num);
assert (rc == TREXIO_SUCCESS);
rc = trexio_write_jastrow_en_num(file, en_num);
assert (rc == TREXIO_SUCCESS);
rc = trexio_write_jastrow_een_num(file, een_num);
assert (rc == TREXIO_SUCCESS);
double ee [2] = { 0.5, 2. };
rc = trexio_write_jastrow_ee(file, ee);
assert (rc == TREXIO_SUCCESS);
double en [3] = { 1., 2., 3. };
rc = trexio_write_jastrow_en(file, en);
assert (rc == TREXIO_SUCCESS);
double een [6] = { 11., 12., 13., 14., 15., 16. };
rc = trexio_write_jastrow_een(file, een);
assert (rc == TREXIO_SUCCESS);
int en_nucleus [3] = { 0, 1, 2 };
rc = trexio_write_jastrow_en_nucleus(file, en_nucleus);
assert (rc == TREXIO_SUCCESS);
int een_nucleus [6] = { 0, 0, 1, 1, 2, 2 };
rc = trexio_write_jastrow_een_nucleus(file, een_nucleus);
assert (rc == TREXIO_SUCCESS);
double ee_scaling = 1.0;
rc = trexio_write_jastrow_ee_scaling(file, ee_scaling);
assert (rc == TREXIO_SUCCESS);
double en_scaling[3] = { 0.5, 1.0, 0.5 };
rc = trexio_write_jastrow_en_scaling(file, en_scaling);
assert (rc == TREXIO_SUCCESS);
#undef nucleus_num
#undef ee_num
#undef en_num
#undef een_num
rc = trexio_close(file);
/*================= END OF TEST ==================*/
return 0;
}
static int test_read_jastrow (const char* file_name, const back_end_t backend) {
/* Try to read one chunk of dataset of sparse data in the TREXIO file */
trexio_t* file = NULL;
trexio_exit_code rc;
/*================= START OF TEST ==================*/
file = trexio_open(file_name, 'r', backend, &rc);
assert (file != NULL);
assert (rc == TREXIO_SUCCESS);
int nucleus_num = 0;
rc = trexio_read_nucleus_num(file, &nucleus_num);
assert (rc == TREXIO_SUCCESS);
assert (nucleus_num == 3);
char type[16] = "";
rc = trexio_read_jastrow_type(file, type, 16);
assert (rc == TREXIO_SUCCESS);
assert (strcmp("CHAMP",type) == 0);
int ee_num = 0;
rc = trexio_read_jastrow_ee_num(file, &ee_num);
assert (rc == TREXIO_SUCCESS);
assert (ee_num == 2);
int en_num = 0;
rc = trexio_read_jastrow_en_num(file, &en_num);
assert (rc == TREXIO_SUCCESS);
assert (en_num == nucleus_num);
int een_num = 0;
rc = trexio_read_jastrow_een_num(file, &een_num);
assert (rc == TREXIO_SUCCESS);
assert (een_num == 2*nucleus_num);
double ee [2] = { 0., 0. };
rc = trexio_read_jastrow_ee(file, ee);
assert (rc == TREXIO_SUCCESS);
assert (ee[0] == 0.5);
assert (ee[1] == 2.0);
double en [3] = { 0., 0., 0. };
rc = trexio_read_jastrow_en(file, en);
assert (rc == TREXIO_SUCCESS);
assert (en[0] == 1.0);
assert (en[1] == 2.0);
assert (en[2] == 3.0);
double een [6];
rc = trexio_read_jastrow_een(file, een);
assert (rc == TREXIO_SUCCESS);
assert (een[0] == 11.0);
assert (een[1] == 12.0);
assert (een[2] == 13.0);
assert (een[3] == 14.0);
assert (een[4] == 15.0);
assert (een[5] == 16.0);
int en_nucleus [3] = { 0, 0, 0 };
rc = trexio_read_jastrow_en_nucleus(file, en_nucleus);
assert (rc == TREXIO_SUCCESS);
assert (en_nucleus[0] == 0);
assert (en_nucleus[1] == 1);
assert (en_nucleus[2] == 2);
int een_nucleus [6] = { 0, 0, 0, 0, 0, 0 };
rc = trexio_read_jastrow_een_nucleus(file, een_nucleus);
assert (rc == TREXIO_SUCCESS);
assert (een_nucleus[0] == 0);
assert (een_nucleus[1] == 0);
assert (een_nucleus[2] == 1);
assert (een_nucleus[3] == 1);
assert (een_nucleus[4] == 2);
assert (een_nucleus[5] == 2);
double ee_scaling = 0.0;
rc = trexio_read_jastrow_ee_scaling(file, &ee_scaling);
assert (rc == TREXIO_SUCCESS);
assert (ee_scaling == 1.0);
double en_scaling[3] = { 0.5, 1.0, 0.5 };
rc = trexio_read_jastrow_en_scaling(file, en_scaling);
assert (rc == TREXIO_SUCCESS);
assert (en_scaling[0] == 0.5);
assert (en_scaling[1] == 1.0);
assert (en_scaling[2] == 0.5);
rc = trexio_close(file);
/*================= END OF TEST ==================*/
return 0;
}
int main(){
/*============== Test launcher ================*/
int rc;
rc = system(RM_COMMAND);
assert (rc == 0);
test_write_jastrow (TREXIO_FILE, TEST_BACKEND);
test_read_jastrow (TREXIO_FILE, TEST_BACKEND);
rc = system(RM_COMMAND);
assert (rc == 0);
return 0;
}

198
tests/io_jastrow_text.c Normal file
View File

@ -0,0 +1,198 @@
#include "trexio.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#define TEST_BACKEND TREXIO_TEXT
#define TREXIO_FILE "test_jastrow.dir"
#define RM_COMMAND "rm -f -- " TREXIO_FILE "/*.txt " TREXIO_FILE "/*.txt.size " TREXIO_FILE "/.lock && rm -fd -- " TREXIO_FILE
static int test_write_jastrow (const char* file_name, const back_end_t backend) {
/* Try to write an array of sparse data into the TREXIO file */
trexio_t* file = NULL;
trexio_exit_code rc;
/*================= START OF TEST ==================*/
// open file in 'write' mode
file = trexio_open(file_name, 'w', backend, &rc);
assert (file != NULL);
assert (rc == TREXIO_SUCCESS);
#define nucleus_num 3
#define ee_num 2
#define en_num 3
#define een_num 6
rc = trexio_write_nucleus_num(file, nucleus_num);
assert (rc == TREXIO_SUCCESS);
rc = trexio_write_jastrow_type(file, "CHAMP", 6);
assert (rc == TREXIO_SUCCESS);
rc = trexio_write_jastrow_ee_num(file, ee_num);
assert (rc == TREXIO_SUCCESS);
rc = trexio_write_jastrow_en_num(file, en_num);
assert (rc == TREXIO_SUCCESS);
rc = trexio_write_jastrow_een_num(file, een_num);
assert (rc == TREXIO_SUCCESS);
double ee [2] = { 0.5, 2. };
rc = trexio_write_jastrow_ee(file, ee);
assert (rc == TREXIO_SUCCESS);
double en [3] = { 1., 2., 3. };
rc = trexio_write_jastrow_en(file, en);
assert (rc == TREXIO_SUCCESS);
double een [6] = { 11., 12., 13., 14., 15., 16. };
rc = trexio_write_jastrow_een(file, een);
assert (rc == TREXIO_SUCCESS);
int en_nucleus [3] = { 0, 1, 2 };
rc = trexio_write_jastrow_en_nucleus(file, en_nucleus);
assert (rc == TREXIO_SUCCESS);
int een_nucleus [6] = { 0, 0, 1, 1, 2, 2 };
rc = trexio_write_jastrow_een_nucleus(file, een_nucleus);
assert (rc == TREXIO_SUCCESS);
double ee_scaling = 1.0;
rc = trexio_write_jastrow_ee_scaling(file, ee_scaling);
assert (rc == TREXIO_SUCCESS);
double en_scaling[3] = { 0.5, 1.0, 0.5 };
rc = trexio_write_jastrow_en_scaling(file, en_scaling);
assert (rc == TREXIO_SUCCESS);
#undef nucleus_num
#undef ee_num
#undef en_num
#undef een_num
rc = trexio_close(file);
/*================= END OF TEST ==================*/
return 0;
}
static int test_read_jastrow (const char* file_name, const back_end_t backend) {
/* Try to read one chunk of dataset of sparse data in the TREXIO file */
trexio_t* file = NULL;
trexio_exit_code rc;
/*================= START OF TEST ==================*/
file = trexio_open(file_name, 'r', backend, &rc);
assert (file != NULL);
assert (rc == TREXIO_SUCCESS);
int nucleus_num = 0;
rc = trexio_read_nucleus_num(file, &nucleus_num);
assert (rc == TREXIO_SUCCESS);
assert (nucleus_num == 3);
char type[16] = "";
rc = trexio_read_jastrow_type(file, type, 16);
assert (rc == TREXIO_SUCCESS);
assert (strcmp("CHAMP",type) == 0);
int ee_num = 0;
rc = trexio_read_jastrow_ee_num(file, &ee_num);
assert (rc == TREXIO_SUCCESS);
assert (ee_num == 2);
int en_num = 0;
rc = trexio_read_jastrow_en_num(file, &en_num);
assert (rc == TREXIO_SUCCESS);
assert (en_num == nucleus_num);
int een_num = 0;
rc = trexio_read_jastrow_een_num(file, &een_num);
assert (rc == TREXIO_SUCCESS);
assert (een_num == 2*nucleus_num);
double ee [2] = { 0., 0. };
rc = trexio_read_jastrow_ee(file, ee);
assert (rc == TREXIO_SUCCESS);
assert (ee[0] == 0.5);
assert (ee[1] == 2.0);
double en [3] = { 0., 0., 0. };
rc = trexio_read_jastrow_en(file, en);
assert (rc == TREXIO_SUCCESS);
assert (en[0] == 1.0);
assert (en[1] == 2.0);
assert (en[2] == 3.0);
double een [6];
rc = trexio_read_jastrow_een(file, een);
assert (rc == TREXIO_SUCCESS);
assert (een[0] == 11.0);
assert (een[1] == 12.0);
assert (een[2] == 13.0);
assert (een[3] == 14.0);
assert (een[4] == 15.0);
assert (een[5] == 16.0);
int en_nucleus [3] = { 0, 0, 0 };
rc = trexio_read_jastrow_en_nucleus(file, en_nucleus);
assert (rc == TREXIO_SUCCESS);
assert (en_nucleus[0] == 0);
assert (en_nucleus[1] == 1);
assert (en_nucleus[2] == 2);
int een_nucleus [6] = { 0, 0, 0, 0, 0, 0 };
rc = trexio_read_jastrow_een_nucleus(file, een_nucleus);
assert (rc == TREXIO_SUCCESS);
assert (een_nucleus[0] == 0);
assert (een_nucleus[1] == 0);
assert (een_nucleus[2] == 1);
assert (een_nucleus[3] == 1);
assert (een_nucleus[4] == 2);
assert (een_nucleus[5] == 2);
double ee_scaling = 0.0;
rc = trexio_read_jastrow_ee_scaling(file, &ee_scaling);
assert (rc == TREXIO_SUCCESS);
assert (ee_scaling == 1.0);
double en_scaling[3] = { 0.5, 1.0, 0.5 };
rc = trexio_read_jastrow_en_scaling(file, en_scaling);
assert (rc == TREXIO_SUCCESS);
assert (en_scaling[0] == 0.5);
assert (en_scaling[1] == 1.0);
assert (en_scaling[2] == 0.5);
rc = trexio_close(file);
/*================= END OF TEST ==================*/
return 0;
}
int main(){
/*============== Test launcher ================*/
int rc;
rc = system(RM_COMMAND);
assert (rc == 0);
test_write_jastrow (TREXIO_FILE, TEST_BACKEND);
test_read_jastrow (TREXIO_FILE, TEST_BACKEND);
rc = system(RM_COMMAND);
assert (rc == 0);
return 0;
}

140
trex.org
View File

@ -175,56 +175,6 @@ with the same name suffixed by ~_im~.
#+end_src
:end:
** Numerical integration grid (grid group)
The molecular integrals have to be computed numerically on a grid in many applications.
A common choice for the angular grid is the one proposed by Lebedev and Laikov
[Russian Academy of Sciences Doklady Mathematics, Volume 59, Number 3, 1999, pages 477-481].
For the radial grids, many approaches have been developed over the years.
The structure of this group is adapted for the [[https://github.com/dftlibs/numgrid][numgrid]] library.
Feel free to submit a PR if you find missing options/functionalities.
#+NAME: grid
| Variable | Type | Dimensions | Description |
|-----------------+---------+------------------+-------------------------------------------------------------------------|
| ~description~ | ~str~ | | Details about the used quadratures can go here |
| ~rad_precision~ | ~float~ | | Radial precision parameter (not used in some schemes like Krack-Köster) |
| ~num~ | ~dim~ | | Number of grid points |
| ~max_ang_num~ | ~int~ | | Maximum number of angular grid points (for pruning) |
| ~min_ang_num~ | ~int~ | | Minimum number of angular grid points (for pruning) |
| ~coord~ | ~float~ | ~(grid.num)~ | Discretized coordinate space |
| ~weight~ | ~float~ | ~(grid.num)~ | Grid weights according to a given partitioning (e.g. Becke) |
| ~ang_num~ | ~dim~ | | Number of angular integration points (if used) |
| ~ang_coord~ | ~float~ | ~(grid.ang_num)~ | Discretized angular space (if used) |
| ~ang_weight~ | ~float~ | ~(grid.ang_num)~ | Angular grid weights (if used) |
| ~rad_num~ | ~dim~ | | Number of radial integration points (if used) |
| ~rad_coord~ | ~float~ | ~(grid.rad_num)~ | Discretized radial space (if used) |
| ~rad_weight~ | ~float~ | ~(grid.rad_num)~ | Radial grid weights (if used) |
#+CALL: json(data=grid, title="grid")
#+RESULTS:
:results:
#+begin_src python :tangle trex.json
"grid": {
"description" : [ "str" , [] ]
, "rad_precision" : [ "float", [] ]
, "num" : [ "dim" , [] ]
, "max_ang_num" : [ "int" , [] ]
, "min_ang_num" : [ "int" , [] ]
, "coord" : [ "float", [ "grid.num" ] ]
, "weight" : [ "float", [ "grid.num" ] ]
, "ang_num" : [ "dim" , [] ]
, "ang_coord" : [ "float", [ "grid.ang_num" ] ]
, "ang_weight" : [ "float", [ "grid.ang_num" ] ]
, "rad_num" : [ "dim" , [] ]
, "rad_coord" : [ "float", [ "grid.rad_num" ] ]
, "rad_weight" : [ "float", [ "grid.rad_num" ] ]
} ,
#+end_src
:end:
** Electron (electron group)
We consider wave functions expressed in the spin-free formalism, where
@ -286,7 +236,7 @@ with the same name suffixed by ~_im~.
#+end_src
:end:
* One-electron basis
* Basis functions
** Basis set (basis group)
*** Gaussian and Slater-type orbitals
@ -583,6 +533,58 @@ power = [
]
#+END_EXAMPLE
** Numerical integration grid (grid group)
In some applications, such as DFT calculations, integrals have to
be computed numerically on a grid. A common choice for the angular
grid is the one proposed by Lebedev and Laikov
[Russian Academy of Sciences Doklady Mathematics, Volume 59, Number 3, 1999, pages 477-481].
For the radial grids, many approaches have been developed over the years.
The structure of this group is adapted for the [[https://github.com/dftlibs/numgrid][numgrid]] library.
Feel free to submit a PR if you find missing options/functionalities.
#+NAME: grid
| Variable | Type | Dimensions | Description |
|-----------------+---------+------------------+-------------------------------------------------------------------------|
| ~description~ | ~str~ | | Details about the used quadratures can go here |
| ~rad_precision~ | ~float~ | | Radial precision parameter (not used in some schemes like Krack-Köster) |
| ~num~ | ~dim~ | | Number of grid points |
| ~max_ang_num~ | ~int~ | | Maximum number of angular grid points (for pruning) |
| ~min_ang_num~ | ~int~ | | Minimum number of angular grid points (for pruning) |
| ~coord~ | ~float~ | ~(grid.num)~ | Discretized coordinate space |
| ~weight~ | ~float~ | ~(grid.num)~ | Grid weights according to a given partitioning (e.g. Becke) |
| ~ang_num~ | ~dim~ | | Number of angular integration points (if used) |
| ~ang_coord~ | ~float~ | ~(grid.ang_num)~ | Discretized angular space (if used) |
| ~ang_weight~ | ~float~ | ~(grid.ang_num)~ | Angular grid weights (if used) |
| ~rad_num~ | ~dim~ | | Number of radial integration points (if used) |
| ~rad_coord~ | ~float~ | ~(grid.rad_num)~ | Discretized radial space (if used) |
| ~rad_weight~ | ~float~ | ~(grid.rad_num)~ | Radial grid weights (if used) |
#+CALL: json(data=grid, title="grid")
#+RESULTS:
:results:
#+begin_src python :tangle trex.json
"grid": {
"description" : [ "str" , [] ]
, "rad_precision" : [ "float", [] ]
, "num" : [ "dim" , [] ]
, "max_ang_num" : [ "int" , [] ]
, "min_ang_num" : [ "int" , [] ]
, "coord" : [ "float", [ "grid.num" ] ]
, "weight" : [ "float", [ "grid.num" ] ]
, "ang_num" : [ "dim" , [] ]
, "ang_coord" : [ "float", [ "grid.ang_num" ] ]
, "ang_weight" : [ "float", [ "grid.ang_num" ] ]
, "rad_num" : [ "dim" , [] ]
, "rad_coord" : [ "float", [ "grid.rad_num" ] ]
, "rad_weight" : [ "float", [ "grid.rad_num" ] ]
} ,
#+end_src
:end:
* Orbitals
** Atomic orbitals (ao group)
Going from the atomic basis set to AOs implies a systematic
@ -860,7 +862,7 @@ power = [
#+end_src
:end:
* N-electron basis
* Multi-determinant information
** Slater determinants (determinant group)
The configuration interaction (CI) wave function $\Psi$
@ -1144,8 +1146,8 @@ power = [
TREXIO files, and are described in the following sections. These
are identified by the ~type~ attribute. The type can be one of the
following:
- ~champ~
- ~mu~
- ~CHAMP~
- ~Mu~
*** CHAMP
@ -1214,16 +1216,15 @@ power = [
# J_{\text{eeN}}(\mathbf{r}) =
# \]
*** Table of values
#+name: jastrow
| Variable | Type | Dimensions | Description |
|---------------+----------+---------------------+-----------------------------------------------------------------|
| ~type~ | ~string~ | | Type of Jastrow factor: ~champ~ or ~mu~ |
| ~type~ | ~string~ | | Type of Jastrow factor: ~CHAMP~ or ~Mu~ |
| ~ee_num~ | ~dim~ | | Number of Electron-electron parameters |
| ~en_num~ | ~dim~ | ~(nucleus.num)~ | Number of Electron-nucleus parameters, per nucleus |
| ~een_num~ | ~dim~ | ~(nucleus.num)~ | Number of Electron-electron-nucleus parameters, per nucleus |
| ~en_num~ | ~dim~ | | Number of Electron-nucleus parameters |
| ~een_num~ | ~dim~ | | Number of Electron-electron-nucleus parameters |
| ~ee~ | ~float~ | ~(jastrow.ee_num)~ | Electron-electron parameters |
| ~en~ | ~float~ | ~(jastrow.en_num)~ | Electron-nucleus parameters |
| ~een~ | ~float~ | ~(jastrow.een_num)~ | Electron-electron-nucleus parameters |
@ -1232,6 +1233,27 @@ power = [
| ~ee_scaling~ | ~float~ | | $\kappa$ value in CHAMP Jastrow for electron-electron distances |
| ~en_scaling~ | ~float~ | ~(nucleus.num)~ | $\kappa$ value in CHAMP Jastrow for electron-nucleus distances |
#+CALL: json(data=jastrow, title="jastrow")
#+RESULTS:
:results:
#+begin_src python :tangle trex.json
"jastrow": {
"type" : [ "string", [] ]
, "ee_num" : [ "dim" , [] ]
, "en_num" : [ "dim" , [] ]
, "een_num" : [ "dim" , [] ]
, "ee" : [ "float" , [ "jastrow.ee_num" ] ]
, "en" : [ "float" , [ "jastrow.en_num" ] ]
, "een" : [ "float" , [ "jastrow.een_num" ] ]
, "en_nucleus" : [ "index" , [ "jastrow.en_num" ] ]
, "een_nucleus" : [ "index" , [ "jastrow.een_num" ] ]
, "ee_scaling" : [ "float" , [] ]
, "en_scaling" : [ "float" , [ "nucleus.num" ] ]
} ,
#+end_src
:end:
* Quantum Monte Carlo data (qmc group)
In quantum Monte Carlo calculations, the wave function is evaluated
@ -1263,7 +1285,7 @@ power = [
}
#+end_src
:end:
* Appendix :noexport:
** Python script from table to json