1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-12-22 20:36:01 +01:00

Read electrons from trexio

This commit is contained in:
Anthony Scemama 2021-10-06 23:34:58 +02:00
parent 97cdfa6df8
commit 9d67a29122
8 changed files with 60969 additions and 0 deletions

230
org/qmckl_trexio.org Normal file
View File

@ -0,0 +1,230 @@
#+TITLE: TREXIO I/O library
#+SETUPFILE: ../tools/theme.setup
#+INCLUDE: ../tools/lib.org
The [[https://github.com/trex-coe/trexio][TREXIO library]] enables easy and efficient input/output of wave
function parameters. In this section we provide high-level functions
to prepare the context by reading the required data from a TREXIO file.
* Headers :noexport:
#+begin_src elisp :noexport :results none
(org-babel-lob-ingest "../tools/lib.org")
#+end_src
#+begin_src c :tangle (eval c_test) :noweb yes
#include "qmckl.h"
#include <assert.h>
#include <math.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "chbrclf.h"
int main() {
qmckl_context context;
context = qmckl_context_create();
#ifdef HAVE_TREXIO
#+end_src
#+begin_src c :tangle (eval c)
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
#elif HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#ifdef HAVE_TREXIO
#include <trexio.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include "qmckl.h"
#+end_src
* Local functions
Functions defined in this section are all local: they should not be
exposed in the API. To identify them, we append an underscore to
their name.
** Open file
We first define a helper function to open a file by first trying to
use the TEXT back end, and then the HDF5 back end. If both
strategies fail, a ~NULL~ pointer is returned. This will allow to
open only once the file and call multiple small functions to read
groups of data by passing the ~trexio_t~ handle.
#+begin_src c :tangle (eval c)
#ifdef HAVE_TREXIO
trexio_t* qmckl_trexio_open_(const char* file_name, qmckl_exit_code* rc)
{
*rc = QMCKL_SUCCESS;
trexio_t* file = NULL;
file = trexio_open(file_name, 'r', TREXIO_TEXT, rc);
if (file != NULL) return file;
file = trexio_open(file_name, 'r', TREXIO_HDF5, rc);
if (file != NULL) return file;
*rc = QMCKL_FAILURE;
return NULL;
}
#endif
#+end_src
** Electron
In this section we read all the data into the electron data structure.
#+begin_src c :tangle (eval c)
#ifdef HAVE_TREXIO
qmckl_exit_code
qmckl_trexio_read_electron_(qmckl_context context, trexio_t* const file)
{
// Should not be possible by construction.
assert (context != (qmckl_context) 0);
assert (file != NULL);
int rcio = 0;
int64_t up_num = 0;
int64_t dn_num = 0;
rcio = trexio_read_electron_up_num_64(file, &up_num);
if (rcio != TREXIO_SUCCESS) {
return qmckl_failwith( context,
QMCKL_FAILURE,
"trexio_read_electron_up_num",
trexio_string_of_error(rcio));
}
assert (up_num >= 0);
rcio = trexio_read_electron_dn_num_64(file, &dn_num);
if (rcio != TREXIO_SUCCESS) {
return qmckl_failwith( context,
QMCKL_FAILURE,
"trexio_read_electron_dn_num",
trexio_string_of_error(rcio));
}
assert (dn_num >= 0);
qmckl_exit_code rc;
rc = qmckl_set_electron_num(context, up_num, dn_num);
return rc;
}
#endif
#+end_src
* Read everything
#+begin_src c :tangle (eval h_func)
qmckl_exit_code qmckl_trexio_read(const qmckl_context context, const char* file_name);
#+end_src
#+begin_src c :tangle (eval c)
qmckl_exit_code
qmckl_trexio_read(const qmckl_context context, const char* file_name)
{
if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
return false;
}
qmckl_exit_code rc;
#ifdef HAVE_TREXIO
trexio_t* file = qmckl_trexio_open_(file_name, &rc);
if (file == NULL) {
trexio_close(file);
return qmckl_failwith( context,
QMCKL_INVALID_ARG_2,
"qmckl_trexio_read",
trexio_string_of_error(rc));
}
assert (file != NULL);
rc = qmckl_trexio_read_electron_(context, file);
printf("%d %d\n", rc, QMCKL_SUCCESS);
if (rc != QMCKL_SUCCESS) {
trexio_close(file);
return qmckl_failwith( context,
QMCKL_FAILURE,
"qmckl_trexio_read",
"Error reading electron");
}
trexio_close(file);
file = NULL;
#else
rc = qmckl_failwith( context,
QMCKL_FAILURE,
"qmckl_trexio_read",
"QMCkl was not compiled without TREXIO");
#endif
return rc;
}
#+end_src
* Test
#+begin_src c :tangle (eval c_test)
#ifdef HAVE_TREXIO
qmckl_exit_code rc;
char fname[256];
char message[256];
rc = qmckl_trexio_read(context, "share/qmckl/test_data/chbrclf");
if (rc != QMCKL_SUCCESS) {
printf("%s\n", qmckl_string_of_error(rc));
qmckl_get_error(context, &rc, fname, message);
printf("%s\n", fname);
printf("%s\n", message);
}
assert ( rc == QMCKL_SUCCESS );
int64_t num;
rc = qmckl_get_electron_up_num(context, &num);
assert (num == chbrclf_elec_up_num);
rc = qmckl_get_electron_down_num(context, &num);
assert (num == chbrclf_elec_dn_num);
#endif
#+end_src
* End of files :noexport:
*** Test
#+begin_src c :tangle (eval c_test)
if (qmckl_context_destroy(context) != QMCKL_SUCCESS)
return QMCKL_FAILURE;
#endif
return 0;
}
#+end_src
# -*- mode: org -*-
# vim: syntax=c

View File

View File

@ -0,0 +1,536 @@
rank_ao_shell 1
dims_ao_shell 0 263
rank_ao_normalization 1
dims_ao_normalization 0 263
ao_cartesian_isSet 1
ao_cartesian 1
ao_num_isSet 1
ao_num 263
ao_shell
0
1
2
3
4
5
5
5
6
6
6
7
7
7
8
8
8
9
9
9
9
9
9
10
10
10
10
10
10
11
11
11
11
11
11
12
12
12
12
12
12
12
12
12
12
13
13
13
13
13
13
13
13
13
13
14
15
16
17
18
18
18
19
19
19
20
20
20
21
21
21
21
21
21
22
22
22
22
22
22
23
24
25
26
27
28
28
28
29
29
29
30
30
30
31
31
31
32
32
32
32
32
32
33
33
33
33
33
33
34
34
34
34
34
34
35
35
35
35
35
35
35
35
35
35
36
36
36
36
36
36
36
36
36
36
37
38
39
40
41
42
43
43
43
44
44
44
45
45
45
46
46
46
47
47
47
48
48
48
48
48
48
49
49
49
49
49
49
50
50
50
50
50
50
51
51
51
51
51
51
51
51
51
51
52
52
52
52
52
52
52
52
52
52
53
54
55
56
57
58
59
60
60
60
61
61
61
62
62
62
63
63
63
64
64
64
65
65
65
66
66
66
66
66
66
67
67
67
67
67
67
68
68
68
68
68
68
69
69
69
69
69
69
70
70
70
70
70
70
70
70
70
70
71
71
71
71
71
71
71
71
71
71
ao_normalization
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.7320508075688772e+00
1.7320508075688772e+00
9.9999999999999978e-01
1.7320508075688772e+00
9.9999999999999978e-01
1.0000000000000000e+00
1.7320508075688772e+00
1.7320508075688772e+00
1.0000000000000000e+00
1.7320508075688772e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.7320508075688776e+00
1.7320508075688776e+00
1.0000000000000000e+00
1.7320508075688776e+00
1.0000000000000000e+00
1.0000000000000000e+00
2.2360679774997894e+00
2.2360679774997894e+00
2.2360679774997898e+00
3.8729833462074166e+00
2.2360679774997894e+00
1.0000000000000000e+00
2.2360679774997898e+00
2.2360679774997894e+00
1.0000000000000000e+00
1.0000000000000000e+00
2.2360679774997894e+00
2.2360679774997894e+00
2.2360679774997894e+00
3.8729833462074157e+00
2.2360679774997894e+00
1.0000000000000000e+00
2.2360679774997894e+00
2.2360679774997894e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000002e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.7320508075688774e+00
1.7320508075688772e+00
1.0000000000000000e+00
1.7320508075688774e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.7320508075688776e+00
1.7320508075688776e+00
1.0000000000000000e+00
1.7320508075688776e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000002e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.7320508075688774e+00
1.7320508075688774e+00
1.0000000000000000e+00
1.7320508075688774e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.7320508075688772e+00
1.7320508075688772e+00
1.0000000000000000e+00
1.7320508075688772e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.7320508075688774e+00
1.7320508075688774e+00
1.0000000000000000e+00
1.7320508075688774e+00
1.0000000000000000e+00
1.0000000000000000e+00
2.2360679774997902e+00
2.2360679774997902e+00
2.2360679774997902e+00
3.8729833462074170e+00
2.2360679774997902e+00
1.0000000000000000e+00
2.2360679774997902e+00
2.2360679774997902e+00
1.0000000000000000e+00
1.0000000000000000e+00
2.2360679774997902e+00
2.2360679774997902e+00
2.2360679774997902e+00
3.8729833462074170e+00
2.2360679774997902e+00
1.0000000000000000e+00
2.2360679774997902e+00
2.2360679774997902e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.7320508075688770e+00
1.7320508075688770e+00
1.0000000000000000e+00
1.7320508075688770e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.7320508075688774e+00
1.7320508075688774e+00
1.0000000000000000e+00
1.7320508075688774e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.7320508075688770e+00
1.7320508075688770e+00
1.0000000000000000e+00
1.7320508075688770e+00
1.0000000000000000e+00
1.0000000000000000e+00
2.2360679774997898e+00
2.2360679774997898e+00
2.2360679774997902e+00
3.8729833462074170e+00
2.2360679774997898e+00
9.9999999999999989e-01
2.2360679774997902e+00
2.2360679774997898e+00
1.0000000000000000e+00
1.0000000000000000e+00
2.2360679774997894e+00
2.2360679774997894e+00
2.2360679774997894e+00
3.8729833462074175e+00
2.2360679774997894e+00
1.0000000000000000e+00
2.2360679774997894e+00
2.2360679774997894e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.7320508075688774e+00
1.7320508075688774e+00
1.0000000000000000e+00
1.7320508075688774e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.7320508075688772e+00
1.7320508075688772e+00
1.0000000000000000e+00
1.7320508075688772e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.7320508075688776e+00
1.7320508075688776e+00
1.0000000000000000e+00
1.7320508075688776e+00
1.0000000000000000e+00
1.0000000000000000e+00
1.7320508075688774e+00
1.7320508075688774e+00
1.0000000000000000e+00
1.7320508075688774e+00
1.0000000000000000e+00
1.0000000000000000e+00
2.2360679774997898e+00
2.2360679774997898e+00
2.2360679774997898e+00
3.8729833462074170e+00
2.2360679774997898e+00
1.0000000000000000e+00
2.2360679774997898e+00
2.2360679774997898e+00
1.0000000000000000e+00
1.0000000000000000e+00
2.2360679774997902e+00
2.2360679774997898e+00
2.2360679774997902e+00
3.8729833462074170e+00
2.2360679774997898e+00
1.0000000000000002e+00
2.2360679774997902e+00
2.2360679774997902e+00
1.0000000000000000e+00

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,4 @@
electron_up_num_isSet 1
electron_up_num 34
electron_dn_num_isSet 1
electron_dn_num 34

View File

@ -0,0 +1,11 @@
rank_metadata_code 0
rank_metadata_author 0
metadata_code_num_isSet 0
metadata_author_num_isSet 0
len_metadata_package_version 6
metadata_package_version
0.3.0
len_metadata_description 0
metadata_description
metadata_code
metadata_author

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,39 @@
rank_nucleus_charge 1
dims_nucleus_charge 0 5
rank_nucleus_coord 2
dims_nucleus_coord 0 5
dims_nucleus_coord 1 3
rank_nucleus_label 1
dims_nucleus_label 0 5
nucleus_num_isSet 1
nucleus_num 5
len_nucleus_point_group 0
nucleus_point_group
nucleus_charge
6.0000000000000000e+00
1.0000000000000000e+00
9.0000000000000000e+00
1.7000000000000000e+01
3.5000000000000000e+01
nucleus_coord
1.0962433534584579e+00
8.9070540169738155e-01
7.7770922802588915e-01
1.1684592373426630e+00
1.1256607200533930e+00
2.8333703148293430e+00
1.4870972977121319e+00
3.1196524844787969e+00
-3.8554381384115000e-01
3.4976638499838888e+00
-1.3029208100731819e+00
-1.2722203194390641e-01
-2.3025745920813350e+00
-3.5420270605050352e-01
-5.3341299343176142e-02
nucleus_label
C
H
F
Cl
Br