TREXIO I/O library
1. Introduction
The TREXIO library stores the data of a quantum-chemistry calculation — geometry, basis set, electron and orbital data — in a single file, in text or HDF5 format, so that codes can exchange it.
The public function of this module, qmckl_trexio_read, fills a context
from such a file: it opens the file, reads the electrons, the nuclei, the
atomic basis and the molecular orbitals, and closes it. The rest of this
page documents the helpers that read one TREXIO group each.
The file is tried as text first, then as HDF5. Effective core potentials are
not read. When QMCkl is built without TREXIO, qmckl_trexio_read still
exists but returns QMCKL_FAILURE with a message saying so.
2. Local functions
Functions defined in this section are all local (internal to this module):
they should not be exposed in the public API. To identify them clearly,
we append _X to their name, indicating their private status.
Users are not able to call these functions directly. Since they are only
called from within this module where the context validity has already been
checked, the context parameter can't be NULL. Therefore, we verify this
precondition with an assert statement rather than returning an error code.
In the functions defined in this section, we use the following local variable naming conventions:
rc: the return code for QMCkl functionsrcio: the return code for TREXIO library functions.
2.1. Open file
The file is opened once by a helper that tries the TEXT backend first and
then the HDF5 backend, and returns a NULL pointer if both fail. The handle
it returns is passed to the other helpers, each of which reads one group of
data. qmckl_trexio_read closes it when it is done, on the error paths as
well as on the last one.
2.2. Electron
The electron group holds the number of up-spin and down-spin electrons.
The helper reads both and sets them together with qmckl_set_electron_num;
no electron position is read.
2.3. Nucleus
The nucleus helper reads the number of nuclei, the nuclear charges and the
molecular geometry, in that order: the setters for the last two need the
number of nuclei. It ends by asserting that qmckl_nucleus_provided holds.
2.3.1. Number of nuclei
nucleus.num is read and must be positive. It is set first, because the
charges and the coordinates are stored per nucleus.
2.3.2. Nuclear charges
The whole nucleus.charge array is read in one call and passed to
qmckl_set_nucleus_charge.
2.3.3. Nuclear coordinates
The geometry comes from nucleus.coord, which TREXIO stores as three
coordinates per nucleus. The setter is called with 'N', so QMCkl
transposes the array into its own [3][nucl_num] layout.
2.4. Basis set and AOs
In this section we read the atomic basis set and atomic orbitals. The basis type and the three sizes come first, because every array that follows is allocated from one of the sizes. The per-nucleus and per-shell arrays come next, then the per-primitive arrays, and the AO normalization factor closes the group.
2.4.1. Basis set type
basis.type is read as a string and only its first character is used. It
must be G for a Gaussian basis or S for a Slater basis. Any other value
fails: a leading N reaches qmckl_set_ao_basis_type, which rejects it,
and any other character is rejected here.
2.4.2. Number of shells
basis.shell_num is read and must be positive. It sizes every per-shell
array below.
2.4.3. Number of primitives
basis.prim_num is read and must be positive. It sizes every per-primitive
array below.
2.4.4. Number of atomic orbitals
ao.num is read and must be positive. It sizes the ao_factor array read
at the end of the section.
2.4.5. Nucleus index array
basis.nucleus_index gives, for each shell, the nucleus it belongs to,
numbered from zero. QMCkl keeps the opposite table, the index of the first
shell of each nucleus. The helper walks the shells from the last to the
first, so each nucleus ends up holding its first shell, and it rejects an
index outside the range.
2.4.6. Number of shells per nucleus
The same dataset is read a second time and counted per nucleus, which gives
nucleus_shell_num.
2.4.7. Power of r
basis.r_power gives the power of r in the radial part of a Slater basis.
If the dataset cannot be read, the failure is not reported: every shell is
given a power of zero instead.
2.4.8. Angular momentum
basis.shell_ang_mom gives the angular momentum of each shell.
2.4.9. Number of primitives per shell
basis.shell_index gives, for each primitive, the shell it belongs to.
Counting it per shell gives shell_prim_num.
2.4.10. Indices of the primitives
basis.shell_index is read a second time and walked backward over the
primitives, as nucleus_index was walked backward over the shells. What
survives is, for each shell, the address of its first primitive in the
exponent array, numbered from zero.
2.4.11. Normalization of the shells
basis.shell_factor gives the normalization factor of each shell.
2.4.12. Exponents
basis.exponent gives the exponent of each primitive, in atomic units.
2.4.13. Coefficients
basis.coefficient gives the contraction coefficient of each primitive.
QMCkl keeps one coefficient per primitive, so the array is read flat.
2.4.14. Normalization of the primitives
basis.prim_factor gives the normalization factor of each primitive.
2.4.15. AO Normalization
ao.normalization gives the normalization factor of each atomic orbital.
QMCkl calls it ao_factor.
2.5. Molecular orbitals
The molecular-orbital group holds the number of orbitals and the matrix of coefficients.
2.5.1. Number of MOs
mo.num is read and must be positive. The coefficient array is allocated
from it and from the number of atomic orbitals read in the previous
section.
2.5.2. MO coefficients
mo.coefficient is read as a flat array of ao_num * mo_num values and
stored as it is.
3. Read everything
Reads the electron, nucleus, atomic-basis and molecular-orbital data of a
TREXIO file into the context, in that order, and closes the file. A NULL
context is rejected with QMCKL_INVALID_CONTEXT; a NULL file_name and an
out-of-range size_max are rejected before the file is opened, with
QMCKL_INVALID_ARG_2 and QMCKL_INVALID_ARG_3.
size_max is the number of characters that may be read from file_name,
excluding the terminating NUL character. It must be positive and smaller
than 4096, the size of the buffer that holds the NUL-terminated copy of the
name. When the file cannot be opened with either backend, the read fails
with QMCKL_INVALID_ARG_2.
qmckl_exit_code
qmckl_trexio_read(const qmckl_context context,
const char* file_name,
const int64_t size_max);
4. Test
The test reads the CHBrClF file from QMCKL_TEST_DIR. It first checks that
a NULL file name, a zero size_max and a size_max of 4096 are rejected,
then reads the file and compares the electrons, the nuclei, the shell and
primitive arrays and the molecular orbitals with the arrays of
chbrclf.h. The body of the test is compiled only when TREXIO is
available.