1111 */
1212#include " ut_common.hpp"
1313#include " catch2/catch.hpp"
14- #include < gauxc/molecule.h>
1514#include < gauxc/molecule.hpp>
1615#include < gauxc/molmeta.hpp>
1716#include < gauxc/external/hdf5.hpp>
2423
2524#include < gauxc/gauxc_config.hpp>
2625
26+ #ifdef GAUXC_HAS_C
27+ #include < gauxc/molecule.h>
28+ #include < gauxc/external/hdf5.h>
29+ #endif
30+
2731#ifdef GAUXC_HAS_MPI
2832#include < mpi.h>
2933#endif
@@ -42,7 +46,7 @@ TEST_CASE("Atom", "[moltypes]") {
4246 CHECK ( atom.y == y );
4347 CHECK ( atom.z == z );
4448
45- #if GAUXC_HAS_C
49+ #ifdef GAUXC_HAS_C
4650 SECTION (" C Interop" ) {
4751 C::GauXCAtom c_atom = { Z, x, y, z };
4852
@@ -69,9 +73,9 @@ TEST_CASE("Molecule", "[moltypes]") {
6973 CHECK (mol.natoms () == 0 );
7074 }
7175
72- #if GAUXC_HAS_C
76+ #ifdef GAUXC_HAS_C
7377 SECTION (" Default C" ) {
74- C::GauXCStatus = status;
78+ C::GauXCStatus status;
7579 C::GauXCMolecule mol = C::gauxc_molecule_new (&status);
7680 CHECK (status.code == 0 );
7781 CHECK (C::gauxc_molecule_natoms (&status, mol) == 0 );
@@ -203,27 +207,67 @@ TEST_CASE("HDF5-MOLECULE", "[moltypes]") {
203207 if ( world_rank ) return ; // Only run on root rank
204208#endif
205209
206-
210+ SECTION ( " HDF5 IO " ) {
207211 Molecule mol = make_water ();
208212
209- // Write file
210- const std::string fname = GAUXC_REF_DATA_PATH " /test_mol.hdf5" ;
211- // if( std::filesystem::exists(fname) ) std::filesystem::remove(fname);
212- auto file_exists = [](const auto & f ) {
213- std::ifstream file (f); return file.good ();
214- };
215- if (file_exists (fname)) std::remove (fname.c_str ());
213+ // Write file
214+ const std::string fname = GAUXC_REF_DATA_PATH " /test_mol.hdf5" ;
215+ // if( std::filesystem::exists(fname) ) std::filesystem::remove(fname);
216+ auto file_exists = [](const auto & f ) {
217+ std::ifstream file (f); return file.good ();
218+ };
219+ if (file_exists (fname)) std::remove (fname.c_str ());
220+
221+ write_hdf5_record ( mol, fname , " /MOL" );
222+
223+ // Read File
224+ Molecule mol_read;
225+ read_hdf5_record ( mol_read, fname, " /MOL" );
226+
227+ // Check that IO was correct
228+ CHECK ( mol == mol_read );
229+
230+ // std::filesystem::remove(fname); // Delete the test file
231+ std::remove (fname.c_str ());
232+ }
233+
234+ #ifdef GAUXC_HAS_C
235+ SECTION (" C HDF5 IO" ) {
236+ C::GauXCStatus status;
237+
238+ C::GauXCMolecule mol;
239+ C::GauXCAtom atoms[3 ] = {
240+ { 8 , 0.000000000000000 , 0.000000000000000 , 0.000000000000000 },
241+ { 1 , 1.579252144093028 , 2.174611055780858 , 0.000000000000000 },
242+ { 1 , 1.579252144093028 , -2.174611055780858 , 0.000000000000000 }
243+ };
244+ mol = C::gauxc_molecule_new_from_atoms (&status, atoms, 3 );
245+ CHECK (status.code == 0 );
246+
247+ auto file_exists = [](const auto & f ) {
248+ std::ifstream file (f); return file.good ();
249+ };
250+ // Write file
251+ const std::string fname_c = GAUXC_REF_DATA_PATH " /test_mol_c.hdf5" ;
252+ if (file_exists (fname_c)) std::remove (fname_c.c_str ());
253+
254+ C::gauxc_molecule_write_hdf5_record (&status, mol, fname_c.c_str (), " /MOL" );
255+ CHECK (status.code == 0 );
216256
217- write_hdf5_record ( mol, fname , " /MOL" );
257+ C::GauXCMolecule mol_read = C::gauxc_molecule_new (&status);
258+ CHECK (status.code == 0 );
218259
219- // Read File
220- Molecule mol_read;
221- read_hdf5_record ( mol_read, fname, " /MOL" );
260+ C::gauxc_molecule_read_hdf5_record (&status, mol_read, fname_c.c_str (), " /MOL" );
261+ CHECK (status.code == 0 );
222262
223- // Check that IO was correct
224- CHECK ( mol == mol_read );
263+ CHECK ( C::gauxc_molecule_equal (&status, mol, mol_read));
264+ CHECK (status. code == 0 );
225265
226- // std::filesystem::remove(fname); // Delete the test file
227- std::remove (fname.c_str ());
266+ C::gauxc_molecule_delete (&status, &mol);
267+ CHECK (status.code == 0 );
268+ C::gauxc_molecule_delete (&status, &mol_read);
269+ CHECK (status.code == 0 );
270+ }
271+ #endif
228272
229273}
0 commit comments