diff --git a/src/cxx/nux/xyz_to_mol.cpp b/src/cxx/nux/xyz_to_mol.cpp index dd1fbde..a552b44 100644 --- a/src/cxx/nux/xyz_to_mol.cpp +++ b/src/cxx/nux/xyz_to_mol.cpp @@ -24,10 +24,16 @@ MODULE_CTOR(XYZToMolecule) { satisfies_property_type(); add_submodule("Z from symbol"); add_submodule("Atom from z"); + add_input("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(); auto& z_from_sym = submods.at("Z from symbol"); auto& atom_from_z = submods.at("Atom from z"); @@ -66,9 +72,11 @@ MODULE_RUN(XYZToMolecule) { auto Z = z_from_sym.run_as(atom_string); auto atom = atom_from_z.run_as(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); } diff --git a/tests/cxx/unit_tests/xyz_to_mol.cpp b/tests/cxx/unit_tests/xyz_to_mol.cpp index 1946807..05e2c2a 100644 --- a/tests/cxx/unit_tests/xyz_to_mol.cpp +++ b/tests/cxx/unit_tests/xyz_to_mol.cpp @@ -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(xyz_data.str()); + + REQUIRE(mol == test_mol); + } }