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
14 changes: 11 additions & 3 deletions src/cxx/nux/xyz_to_mol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ MODULE_CTOR(XYZToMolecule) {
satisfies_property_type<simde::MoleculeFromString>();
add_submodule<simde::ZFromSymbol>("Z from symbol");
add_submodule<simde::AtomFromZ>("Atom from z");
add_input<double>("Unit scaling factor")
.set_default(1.0)
.set_description(
"Sets the unit scaling factor, default 1.0 for bohr input units")
.set_default(1.0);
}

MODULE_RUN(XYZToMolecule) {
const auto& [xyz_data] = simde::MoleculeFromString::unwrap_inputs(inputs);
auto unit_scale = inputs.at("Unit scaling factor").value<double>();
auto& z_from_sym = submods.at("Z from symbol");
auto& atom_from_z = submods.at("Atom from z");

Expand Down Expand Up @@ -66,9 +72,11 @@ MODULE_RUN(XYZToMolecule) {

auto Z = z_from_sym.run_as<simde::ZFromSymbol>(atom_string);
auto atom = atom_from_z.run_as<simde::AtomFromZ>(Z);
atom.x() = x;
atom.y() = y;
atom.z() = z;

// Assumes that the XYZ coordnates given are in angstroms
atom.x() = x * unit_scale;
atom.y() = y * unit_scale;
atom.z() = z * unit_scale;

mol.push_back(atom);
}
Expand Down
22 changes: 22 additions & 0 deletions tests/cxx/unit_tests/xyz_to_mol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,26 @@ TEST_CASE("XYZToMolecule") {

REQUIRE(mol == test_mol);
}

SECTION("XYZ to Molecule Unit Scaling: Angstroms to Bohr") {
auto atom0{make_atoms(1)};
auto atom1{make_atoms(1)};
atom1.x() = 1.8897259886;
atom1.y() = 1.8897259886;
atom1.z() = 1.8897259886;

simde::type::molecule test_mol{atom0, atom1};

std::stringstream xyz_data;
xyz_data << "2\n";
xyz_data << "This is a comment!\n";
xyz_data << "H 0 0 0\n";
xyz_data << "H 1 1 1\n";

xyz_mod.change_input("Unit scaling factor", 1.8897259886);

auto mol = xyz_mod.run_as<simde::MoleculeFromString>(xyz_data.str());

REQUIRE(mol == test_mol);
}
}