Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/nux/nux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
67 changes: 34 additions & 33 deletions src/cxx/nux/bo_approximation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,42 +48,43 @@ Terms that are zero will not appear in the Hamiltonian.
)";

MODULE_CTOR(BOApproximation) {
satisfies_property_type<pt>();
description(desc);
satisfies_property_type<pt>();
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<T_e_type>(electrons));
if (has_nuclei)
H.emplace_back(1.0, std::make_unique<V_en_type>(electrons, nuclei));
if (electrons.size() > 1)
H.emplace_back(1.0, std::make_unique<V_ee_type>(electrons, electrons));
}
if (nuclei.size() > 1) {
H.emplace_back(1.0, std::make_unique<V_nn_type>(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<T_e_type>(electrons));
if(has_nuclei)
H.emplace_back(1.0, std::make_unique<V_en_type>(electrons, nuclei));
if(electrons.size() > 1)
H.emplace_back(1.0,
std::make_unique<V_ee_type>(electrons, electrons));
}
if(nuclei.size() > 1) {
H.emplace_back(1.0, std::make_unique<V_nn_type>(nuclei, nuclei));
}

auto rv = results();
return pt::wrap_results(rv, H);
}

} // namespace nux
6 changes: 3 additions & 3 deletions src/cxx/nux/nux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

namespace nux {

void load_modules(pluginplay::ModuleManager &mm) {
mm.add_module<BOApproximation>("Born-Oppenheimer Approximation");
mm.add_module<XYZToMolecule>("XYZ To Molecule");
void load_modules(pluginplay::ModuleManager& mm) {
mm.add_module<BOApproximation>("Born-Oppenheimer Approximation");
mm.add_module<XYZToMolecule>("XYZ To Molecule");
}

} // namespace nux
2 changes: 1 addition & 1 deletion src/cxx/nux/nux_modules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ namespace nux {
DECLARE_MODULE(BOApproximation);
DECLARE_MODULE(XYZToMolecule);

}
} // namespace nux
50 changes: 24 additions & 26 deletions src/cxx/nux/xyz_to_mol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,54 @@

namespace nux {

MODULE_CTOR(XYZToMolecule) {
MODULE_CTOR(XYZToMolecule) {
satisfies_property_type<simde::MoleculeFromString>();
add_submodule<simde::ZFromSymbol>("Z from symbol");
add_submodule<simde::AtomFromZ>("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
// atoms in the file, and the 2nd line, the comment line.
std::getline(xyz_file, line);
std::getline(xyz_file, line);

while (std::getline(xyz_file, line)) {
std::istringstream iss(line);
std::vector<std::string> tokens;
std::string token;
while (std::getline(iss, token, ' ')) {
if (token.size()) { tokens.emplace_back(token); }
}
auto Z = z_from_sym.run_as<simde::ZFromSymbol>(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<std::string> tokens;
std::string token;
while(std::getline(iss, token, ' ')) {
if(token.size()) { tokens.emplace_back(token); }
}
auto Z = z_from_sym.run_as<simde::ZFromSymbol>(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<simde::AtomFromZ>(Z);
atm.x() = x;
atm.y() = y;
atm.z() = z;
mol.push_back(atm);
auto atm = atom_from_z.run_as<simde::AtomFromZ>(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
37 changes: 19 additions & 18 deletions tests/cxx/test_nux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename ResultType> ResultType make_h2() {
using simde::type::chemical_system;
using simde::type::molecule;
using simde::type::nuclei;
if constexpr (std::is_same_v<ResultType, nuclei>) {
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<ResultType, molecule>) {
return molecule(0, 1, make_h2<nuclei>());
} else if constexpr (std::is_same_v<ResultType, chemical_system>) {
return chemical_system(make_h2<molecule>());
} 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<ResultType, nuclei>);
}
template<typename ResultType>
ResultType make_h2() {
using simde::type::chemical_system;
using simde::type::molecule;
using simde::type::nuclei;
if constexpr(std::is_same_v<ResultType, nuclei>) {
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<ResultType, molecule>) {
return molecule(0, 1, make_h2<nuclei>());
} else if constexpr(std::is_same_v<ResultType, chemical_system>) {
return chemical_system(make_h2<molecule>());
} 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<ResultType, nuclei>);
}
}
} // namespace test_nux
Loading