diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index e2c72a4..2bee7d1 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -25,7 +25,7 @@ jobs: uses: NWChemEx/.github/.github/workflows/common_pull_request.yaml@master with: config_file: '.github/.licenserc.yaml' - source_dir: '' + source_dir: 'include src tests' compilers: '["gcc-11"]' doc_target: 'nux_cxx_api' build_fail_on_warning: false diff --git a/include/nux/nux.hpp b/include/nux/nux.hpp index 7fb9803..81f9a4f 100644 --- a/include/nux/nux.hpp +++ b/include/nux/nux.hpp @@ -21,6 +21,6 @@ namespace nux { /** @brief Loads the modules contained in the NUX module collection into the * provided ModuleManager instance. */ -void load_modules(pluginplay::ModuleManager &mm); +void load_modules(pluginplay::ModuleManager& mm); } // namespace nux diff --git a/src/cxx/nux/bo_approximation.cpp b/src/cxx/nux/bo_approximation.cpp index abc6502..7f17a1d 100644 --- a/src/cxx/nux/bo_approximation.cpp +++ b/src/cxx/nux/bo_approximation.cpp @@ -48,42 +48,43 @@ Terms that are zero will not appear in the Hamiltonian. )"; MODULE_CTOR(BOApproximation) { - satisfies_property_type(); - description(desc); + satisfies_property_type(); + description(desc); } MODULE_RUN(BOApproximation) { - const auto &[sys] = pt::unwrap_inputs(inputs); - - // Step 0: Decompose system into pieces - const auto electrons = sys.molecule().electrons(); - const auto nuclei = sys.molecule().nuclei().as_nuclei(); - bool has_electrons = electrons.size(); - bool has_nuclei = nuclei.size(); - - using simde::type::T_e_type; - using simde::type::V_ee_type; - using simde::type::V_en_type; - using simde::type::V_nn_type; - - // Step 1: Create non-zero terms and add them to the Hamiltonian - // N.b. the logic is a bit convoluted to conform to "usual" ordering (see - // module description) - - hamiltonian H; - if (has_electrons) { - H.emplace_back(1.0, std::make_unique(electrons)); - if (has_nuclei) - H.emplace_back(1.0, std::make_unique(electrons, nuclei)); - if (electrons.size() > 1) - H.emplace_back(1.0, std::make_unique(electrons, electrons)); - } - if (nuclei.size() > 1) { - H.emplace_back(1.0, std::make_unique(nuclei, nuclei)); - } - - auto rv = results(); - return pt::wrap_results(rv, H); + const auto& [sys] = pt::unwrap_inputs(inputs); + + // Step 0: Decompose system into pieces + const auto electrons = sys.molecule().electrons(); + const auto nuclei = sys.molecule().nuclei().as_nuclei(); + bool has_electrons = electrons.size(); + bool has_nuclei = nuclei.size(); + + using simde::type::T_e_type; + using simde::type::V_ee_type; + using simde::type::V_en_type; + using simde::type::V_nn_type; + + // Step 1: Create non-zero terms and add them to the Hamiltonian + // N.b. the logic is a bit convoluted to conform to "usual" ordering (see + // module description) + + hamiltonian H; + if(has_electrons) { + H.emplace_back(1.0, std::make_unique(electrons)); + if(has_nuclei) + H.emplace_back(1.0, std::make_unique(electrons, nuclei)); + if(electrons.size() > 1) + H.emplace_back(1.0, + std::make_unique(electrons, electrons)); + } + if(nuclei.size() > 1) { + H.emplace_back(1.0, std::make_unique(nuclei, nuclei)); + } + + auto rv = results(); + return pt::wrap_results(rv, H); } } // namespace nux \ No newline at end of file diff --git a/src/cxx/nux/nux.cpp b/src/cxx/nux/nux.cpp index 0812604..7f77484 100644 --- a/src/cxx/nux/nux.cpp +++ b/src/cxx/nux/nux.cpp @@ -19,9 +19,9 @@ namespace nux { -void load_modules(pluginplay::ModuleManager &mm) { - mm.add_module("Born-Oppenheimer Approximation"); - mm.add_module("XYZ To Molecule"); +void load_modules(pluginplay::ModuleManager& mm) { + mm.add_module("Born-Oppenheimer Approximation"); + mm.add_module("XYZ To Molecule"); } } // namespace nux diff --git a/src/cxx/nux/nux_modules.hpp b/src/cxx/nux/nux_modules.hpp index a6d64ba..d8a65d3 100644 --- a/src/cxx/nux/nux_modules.hpp +++ b/src/cxx/nux/nux_modules.hpp @@ -22,4 +22,4 @@ namespace nux { DECLARE_MODULE(BOApproximation); DECLARE_MODULE(XYZToMolecule); -} +} // namespace nux diff --git a/src/cxx/nux/xyz_to_mol.cpp b/src/cxx/nux/xyz_to_mol.cpp index ef42832..c3166a6 100644 --- a/src/cxx/nux/xyz_to_mol.cpp +++ b/src/cxx/nux/xyz_to_mol.cpp @@ -22,26 +22,24 @@ namespace nux { - MODULE_CTOR(XYZToMolecule) { +MODULE_CTOR(XYZToMolecule) { satisfies_property_type(); add_submodule("Z from symbol"); add_submodule("Atom from z"); - } +} - MODULE_RUN(XYZToMolecule) { +MODULE_RUN(XYZToMolecule) { const auto& [filename] = simde::MoleculeFromString::unwrap_inputs(inputs); - auto& z_from_sym = submods.at("Z from symbol"); + auto& z_from_sym = submods.at("Z from symbol"); auto& atom_from_z = submods.at("Atom from z"); chemist::Molecule mol; std::ifstream xyz_file(filename); - if (!xyz_file) { - throw std::runtime_error("File not found: " + filename); - } - + if(!xyz_file) { throw std::runtime_error("File not found: " + filename); } + std::string line; // Skips the 1st line of the file, associated with the number of @@ -49,29 +47,29 @@ namespace nux { std::getline(xyz_file, line); std::getline(xyz_file, line); - while (std::getline(xyz_file, line)) { - std::istringstream iss(line); - std::vector tokens; - std::string token; - while (std::getline(iss, token, ' ')) { - if (token.size()) { tokens.emplace_back(token); } - } - auto Z = z_from_sym.run_as(tokens.at(0)); - auto x = std::stod(tokens.at(1)); - auto y = std::stod(tokens.at(2)); - auto z = std::stod(tokens.at(3)); + while(std::getline(xyz_file, line)) { + std::istringstream iss(line); + std::vector tokens; + std::string token; + while(std::getline(iss, token, ' ')) { + if(token.size()) { tokens.emplace_back(token); } + } + auto Z = z_from_sym.run_as(tokens.at(0)); + auto x = std::stod(tokens.at(1)); + auto y = std::stod(tokens.at(2)); + auto z = std::stod(tokens.at(3)); - auto atm = atom_from_z.run_as(Z); - atm.x() = x; - atm.y() = y; - atm.z() = z; - mol.push_back(atm); + auto atm = atom_from_z.run_as(Z); + atm.x() = x; + atm.y() = y; + atm.z() = z; + mol.push_back(atm); } xyz_file.close(); - + auto rv = results(); return simde::MoleculeFromString::wrap_results(rv, mol); - } +} } // namespace nux diff --git a/tests/cxx/test_nux.hpp b/tests/cxx/test_nux.hpp index 69a6e17..7095eec 100644 --- a/tests/cxx/test_nux.hpp +++ b/tests/cxx/test_nux.hpp @@ -22,25 +22,26 @@ namespace test_nux { inline auto h_nucleus(double x, double y, double z) { - return simde::type::nucleus("H", 1ul, 1836.15, x, y, z); + return simde::type::nucleus("H", 1ul, 1836.15, x, y, z); } -template ResultType make_h2() { - using simde::type::chemical_system; - using simde::type::molecule; - using simde::type::nuclei; - if constexpr (std::is_same_v) { - auto h0 = h_nucleus(0.0, 0.0, 0.0); - auto h1 = h_nucleus(0.0, 0.0, 1.3984); - return nuclei{h0, h1}; - } else if constexpr (std::is_same_v) { - return molecule(0, 1, make_h2()); - } else if constexpr (std::is_same_v) { - return chemical_system(make_h2()); - } else { - // We know this assert fails if we're in the else statement - // Getting here means you provided a bad type. - static_assert(std::is_same_v); - } +template +ResultType make_h2() { + using simde::type::chemical_system; + using simde::type::molecule; + using simde::type::nuclei; + if constexpr(std::is_same_v) { + auto h0 = h_nucleus(0.0, 0.0, 0.0); + auto h1 = h_nucleus(0.0, 0.0, 1.3984); + return nuclei{h0, h1}; + } else if constexpr(std::is_same_v) { + return molecule(0, 1, make_h2()); + } else if constexpr(std::is_same_v) { + return chemical_system(make_h2()); + } else { + // We know this assert fails if we're in the else statement + // Getting here means you provided a bad type. + static_assert(std::is_same_v); + } } } // namespace test_nux \ No newline at end of file diff --git a/tests/cxx/unit_tests/bo_approximation.cpp b/tests/cxx/unit_tests/bo_approximation.cpp index 8264233..9560dd3 100644 --- a/tests/cxx/unit_tests/bo_approximation.cpp +++ b/tests/cxx/unit_tests/bo_approximation.cpp @@ -20,78 +20,84 @@ using namespace nux; TEST_CASE("BOApproximation") { - pluginplay::ModuleManager mm; - load_modules(mm); - - using simde::type::chemical_system; - using simde::type::hamiltonian; - using simde::type::T_e_type; - using simde::type::V_ee_type; - using simde::type::V_en_type; - using simde::type::V_nn_type; - - using pt = simde::Convert; - - auto &mod = mm.at("Born-Oppenheimer Approximation"); - - SECTION("Empty chemical system") { - chemical_system sys; - auto H = mod.run_as(sys); - REQUIRE(H == hamiltonian{}); - } - - SECTION("H2") { - auto h2 = test_nux::make_h2(); - auto electrons = h2.molecule().electrons(); - auto nuclei = h2.molecule().nuclei().as_nuclei(); - - auto H = mod.run_as(h2); - hamiltonian H_corr; - H_corr.emplace_back(1.0, std::make_unique(electrons)); - H_corr.emplace_back(1.0, std::make_unique(electrons, nuclei)); - H_corr.emplace_back(1.0, std::make_unique(electrons, electrons)); - H_corr.emplace_back(1.0, std::make_unique(nuclei, nuclei)); - REQUIRE(H == H_corr); - } - - SECTION("H atom") { - simde::type::nuclei nuclei{test_nux::h_nucleus(0.0, 0.0, 0.0)}; - simde::type::chemical_system h(simde::type::molecule(0, 2, nuclei)); - - auto electrons = h.molecule().electrons(); - - auto H = mod.run_as(h); - hamiltonian H_corr; - H_corr.emplace_back(1.0, std::make_unique(electrons)); - H_corr.emplace_back(1.0, std::make_unique(electrons, nuclei)); - REQUIRE(H == H_corr); - } - - SECTION("H anion") { - simde::type::nuclei nuclei{test_nux::h_nucleus(0.0, 0.0, 0.0)}; - simde::type::chemical_system h(simde::type::molecule(-1, 1, nuclei)); - - auto electrons = h.molecule().electrons(); - - auto H = mod.run_as(h); - hamiltonian H_corr; - H_corr.emplace_back(1.0, std::make_unique(electrons)); - H_corr.emplace_back(1.0, std::make_unique(electrons, nuclei)); - H_corr.emplace_back(1.0, std::make_unique(electrons, electrons)); - REQUIRE(H == H_corr); - } - - SECTION("H2 cation") { - auto nuclei = test_nux::make_h2(); - simde::type::chemical_system h(simde::type::molecule(1, 2, nuclei)); - - auto electrons = h.molecule().electrons(); - - auto H = mod.run_as(h); - hamiltonian H_corr; - H_corr.emplace_back(1.0, std::make_unique(electrons)); - H_corr.emplace_back(1.0, std::make_unique(electrons, nuclei)); - H_corr.emplace_back(1.0, std::make_unique(nuclei, nuclei)); - REQUIRE(H == H_corr); - } + pluginplay::ModuleManager mm; + load_modules(mm); + + using simde::type::chemical_system; + using simde::type::hamiltonian; + using simde::type::T_e_type; + using simde::type::V_ee_type; + using simde::type::V_en_type; + using simde::type::V_nn_type; + + using pt = simde::Convert; + + auto& mod = mm.at("Born-Oppenheimer Approximation"); + + SECTION("Empty chemical system") { + chemical_system sys; + auto H = mod.run_as(sys); + REQUIRE(H == hamiltonian{}); + } + + SECTION("H2") { + auto h2 = test_nux::make_h2(); + auto electrons = h2.molecule().electrons(); + auto nuclei = h2.molecule().nuclei().as_nuclei(); + + auto H = mod.run_as(h2); + hamiltonian H_corr; + H_corr.emplace_back(1.0, std::make_unique(electrons)); + H_corr.emplace_back(1.0, + std::make_unique(electrons, nuclei)); + H_corr.emplace_back(1.0, + std::make_unique(electrons, electrons)); + H_corr.emplace_back(1.0, std::make_unique(nuclei, nuclei)); + REQUIRE(H == H_corr); + } + + SECTION("H atom") { + simde::type::nuclei nuclei{test_nux::h_nucleus(0.0, 0.0, 0.0)}; + simde::type::chemical_system h(simde::type::molecule(0, 2, nuclei)); + + auto electrons = h.molecule().electrons(); + + auto H = mod.run_as(h); + hamiltonian H_corr; + H_corr.emplace_back(1.0, std::make_unique(electrons)); + H_corr.emplace_back(1.0, + std::make_unique(electrons, nuclei)); + REQUIRE(H == H_corr); + } + + SECTION("H anion") { + simde::type::nuclei nuclei{test_nux::h_nucleus(0.0, 0.0, 0.0)}; + simde::type::chemical_system h(simde::type::molecule(-1, 1, nuclei)); + + auto electrons = h.molecule().electrons(); + + auto H = mod.run_as(h); + hamiltonian H_corr; + H_corr.emplace_back(1.0, std::make_unique(electrons)); + H_corr.emplace_back(1.0, + std::make_unique(electrons, nuclei)); + H_corr.emplace_back(1.0, + std::make_unique(electrons, electrons)); + REQUIRE(H == H_corr); + } + + SECTION("H2 cation") { + auto nuclei = test_nux::make_h2(); + simde::type::chemical_system h(simde::type::molecule(1, 2, nuclei)); + + auto electrons = h.molecule().electrons(); + + auto H = mod.run_as(h); + hamiltonian H_corr; + H_corr.emplace_back(1.0, std::make_unique(electrons)); + H_corr.emplace_back(1.0, + std::make_unique(electrons, nuclei)); + H_corr.emplace_back(1.0, std::make_unique(nuclei, nuclei)); + REQUIRE(H == H_corr); + } } \ No newline at end of file diff --git a/tests/cxx/unit_tests/main.cpp b/tests/cxx/unit_tests/main.cpp index 20182f5..bdfff19 100644 --- a/tests/cxx/unit_tests/main.cpp +++ b/tests/cxx/unit_tests/main.cpp @@ -18,10 +18,10 @@ #include #include -int main(int argc, char *argv[]) { - auto rt = parallelzone::runtime::RuntimeView(); +int main(int argc, char* argv[]) { + auto rt = parallelzone::runtime::RuntimeView(); - int res = Catch::Session().run(argc, argv); + int res = Catch::Session().run(argc, argv); - return res; + return res; } \ No newline at end of file diff --git a/tests/cxx/unit_tests/nux.cpp b/tests/cxx/unit_tests/nux.cpp index 2064ae1..974ab99 100644 --- a/tests/cxx/unit_tests/nux.cpp +++ b/tests/cxx/unit_tests/nux.cpp @@ -18,7 +18,7 @@ #include TEST_CASE("load_plugin") { - pluginplay::ModuleManager mm; - nux::load_modules(mm); - REQUIRE(mm.size() > 0); + pluginplay::ModuleManager mm; + nux::load_modules(mm); + REQUIRE(mm.size() > 0); } \ No newline at end of file diff --git a/tests/cxx/unit_tests/xyz_to_mol.cpp b/tests/cxx/unit_tests/xyz_to_mol.cpp index ce76c97..d6547fb 100644 --- a/tests/cxx/unit_tests/xyz_to_mol.cpp +++ b/tests/cxx/unit_tests/xyz_to_mol.cpp @@ -22,50 +22,50 @@ TEST_CASE("XYZToMolecule") { nux::load_modules(mm); auto make_atoms = [=](auto&& Z) { - REQUIRE(Z == 1); - double h_mass = 1837.4260218693814; - return simde::type::atom{"H", 1, h_mass, 0.0, 0.0, 0.0}; + REQUIRE(Z == 1); + double h_mass = 1837.4260218693814; + return simde::type::atom{"H", 1, h_mass, 0.0, 0.0, 0.0}; }; auto atom_mod = pluginplay::make_lambda(make_atoms); - auto z_mod = pluginplay::make_lambda([=](auto&& symbol) { - return simde::type::atomic_number{1}; - }); + auto z_mod = pluginplay::make_lambda( + [=](auto&& symbol) { return simde::type::atomic_number{1}; }); auto& xyz_mod = mm.at("XYZ To Molecule"); xyz_mod.change_submod("Z from symbol", z_mod); xyz_mod.change_submod("Atom from z", atom_mod); - SECTION("No XYZ file found") { - std::string file = "file.xyz"; - REQUIRE_THROWS_AS(xyz_mod.run_as(file), std::runtime_error); - } + SECTION("No XYZ file found") { + std::string file = "file.xyz"; + REQUIRE_THROWS_AS(xyz_mod.run_as(file), + std::runtime_error); + } - SECTION("Full XYZ To Molecule run") { - auto atom0{make_atoms(1)}; - auto atom1{make_atoms(1)}; - atom1.z() = 1; + SECTION("Full XYZ To Molecule run") { + auto atom0{make_atoms(1)}; + auto atom1{make_atoms(1)}; + atom1.z() = 1; - simde::type::molecule test_mol{atom0, atom1}; + simde::type::molecule test_mol{atom0, atom1}; - std::ofstream xyz_file; - xyz_file.open("h2.xyz"); + std::ofstream xyz_file; + xyz_file.open("h2.xyz"); - xyz_file << "2\n"; - xyz_file << "This is a comment!\n"; - xyz_file << "H 0 0 0\n"; - xyz_file << "H 0 0 1\n"; - xyz_file.close(); - - std::string filename = "h2.xyz"; + xyz_file << "2\n"; + xyz_file << "This is a comment!\n"; + xyz_file << "H 0 0 0\n"; + xyz_file << "H 0 0 1\n"; + xyz_file.close(); - auto mol = xyz_mod.run_as(filename); + std::string filename = "h2.xyz"; - remove("h2.xyz"); - std::ifstream del_file("h2.xyz"); + auto mol = xyz_mod.run_as(filename); - REQUIRE(mol == test_mol); - REQUIRE(del_file.good() == false); - } + remove("h2.xyz"); + std::ifstream del_file("h2.xyz"); + + REQUIRE(mol == test_mol); + REQUIRE(del_file.good() == false); + } }