From b3c51b87d72efa9c08cdd8ef54ad2810ff82d3e6 Mon Sep 17 00:00:00 2001 From: Jacob Heflin Date: Sun, 5 Oct 2025 18:49:17 -0500 Subject: [PATCH 1/3] clang-format changes --- src/cxx/nux/xyz_to_mol.cpp | 14 +++++++++++--- tests/cxx/unit_tests/xyz_file_to_mol.cpp | 2 +- tests/cxx/unit_tests/xyz_to_mol.cpp | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/cxx/nux/xyz_to_mol.cpp b/src/cxx/nux/xyz_to_mol.cpp index dd1fbde..c64020a 100644 --- a/src/cxx/nux/xyz_to_mol.cpp +++ b/src/cxx/nux/xyz_to_mol.cpp @@ -20,6 +20,12 @@ namespace nux { +double ang2bohr(double ang_value) { + // Converts a anstrom-based value to a bohr-based value + double bohr_value = ang_value * 1.8897259886; + return bohr_value; +} + MODULE_CTOR(XYZToMolecule) { satisfies_property_type(); add_submodule("Z from symbol"); @@ -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() = ang2bohr(x); + atom.y() = ang2bohr(y); + atom.z() = ang2bohr(z); mol.push_back(atom); } diff --git a/tests/cxx/unit_tests/xyz_file_to_mol.cpp b/tests/cxx/unit_tests/xyz_file_to_mol.cpp index aceefaa..688944d 100644 --- a/tests/cxx/unit_tests/xyz_file_to_mol.cpp +++ b/tests/cxx/unit_tests/xyz_file_to_mol.cpp @@ -47,7 +47,7 @@ TEST_CASE("XYZFileToMolecule") { SECTION("Full XYZ To Molecule run: File") { auto atom0{make_atoms(1)}; auto atom1{make_atoms(1)}; - atom1.z() = 1; + atom1.z() = 1.8897259886; simde::type::molecule test_mol{atom0, atom1}; diff --git a/tests/cxx/unit_tests/xyz_to_mol.cpp b/tests/cxx/unit_tests/xyz_to_mol.cpp index 1946807..eb1487c 100644 --- a/tests/cxx/unit_tests/xyz_to_mol.cpp +++ b/tests/cxx/unit_tests/xyz_to_mol.cpp @@ -51,7 +51,7 @@ TEST_CASE("XYZToMolecule") { SECTION("Full XYZ To Molecule run: Data") { auto atom0{make_atoms(1)}; auto atom1{make_atoms(1)}; - atom1.z() = 1; + atom1.z() = 1.8897259886; simde::type::molecule test_mol{atom0, atom1}; From 36e971c573d38b13a028b5f3aa674c00ef475517 Mon Sep 17 00:00:00 2001 From: Jacob Heflin Date: Wed, 8 Oct 2025 13:41:59 -0500 Subject: [PATCH 2/3] clang format changes --- src/cxx/nux/xyz_to_mol.cpp | 18 +++++++++--------- tests/cxx/unit_tests/xyz_file_to_mol.cpp | 2 +- tests/cxx/unit_tests/xyz_to_mol.cpp | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/cxx/nux/xyz_to_mol.cpp b/src/cxx/nux/xyz_to_mol.cpp index c64020a..a552b44 100644 --- a/src/cxx/nux/xyz_to_mol.cpp +++ b/src/cxx/nux/xyz_to_mol.cpp @@ -20,20 +20,20 @@ namespace nux { -double ang2bohr(double ang_value) { - // Converts a anstrom-based value to a bohr-based value - double bohr_value = ang_value * 1.8897259886; - return bohr_value; -} - 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"); @@ -74,9 +74,9 @@ MODULE_RUN(XYZToMolecule) { auto atom = atom_from_z.run_as(Z); // Assumes that the XYZ coordnates given are in angstroms - atom.x() = ang2bohr(x); - atom.y() = ang2bohr(y); - atom.z() = ang2bohr(z); + 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_file_to_mol.cpp b/tests/cxx/unit_tests/xyz_file_to_mol.cpp index 688944d..aceefaa 100644 --- a/tests/cxx/unit_tests/xyz_file_to_mol.cpp +++ b/tests/cxx/unit_tests/xyz_file_to_mol.cpp @@ -47,7 +47,7 @@ TEST_CASE("XYZFileToMolecule") { SECTION("Full XYZ To Molecule run: File") { auto atom0{make_atoms(1)}; auto atom1{make_atoms(1)}; - atom1.z() = 1.8897259886; + atom1.z() = 1; simde::type::molecule test_mol{atom0, atom1}; diff --git a/tests/cxx/unit_tests/xyz_to_mol.cpp b/tests/cxx/unit_tests/xyz_to_mol.cpp index eb1487c..7c193c6 100644 --- a/tests/cxx/unit_tests/xyz_to_mol.cpp +++ b/tests/cxx/unit_tests/xyz_to_mol.cpp @@ -49,6 +49,24 @@ TEST_CASE("XYZToMolecule") { } SECTION("Full XYZ To Molecule run: Data") { + auto atom0{make_atoms(1)}; + auto atom1{make_atoms(1)}; + atom1.z() = 1; + + 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 0 0 1\n"; + + auto mol = xyz_mod.run_as(xyz_data.str()); + + REQUIRE(mol == test_mol); + } + + SECTION("XYZ to Molecule Unit Scaling: Angstroms to Bohr") { auto atom0{make_atoms(1)}; auto atom1{make_atoms(1)}; atom1.z() = 1.8897259886; @@ -61,6 +79,8 @@ TEST_CASE("XYZToMolecule") { xyz_data << "H 0 0 0\n"; xyz_data << "H 0 0 1\n"; + xyz_mod.change_input("Unit scaling factor", 1.8897259886); + auto mol = xyz_mod.run_as(xyz_data.str()); REQUIRE(mol == test_mol); From 663530eea18935d4a8c3504117aa332621b75176 Mon Sep 17 00:00:00 2001 From: Jacob Heflin Date: Wed, 8 Oct 2025 13:44:12 -0500 Subject: [PATCH 3/3] added testing for the x and y components instead of just the z component of the xyz to molecule --- tests/cxx/unit_tests/xyz_to_mol.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/cxx/unit_tests/xyz_to_mol.cpp b/tests/cxx/unit_tests/xyz_to_mol.cpp index 7c193c6..05e2c2a 100644 --- a/tests/cxx/unit_tests/xyz_to_mol.cpp +++ b/tests/cxx/unit_tests/xyz_to_mol.cpp @@ -69,6 +69,8 @@ TEST_CASE("XYZToMolecule") { 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}; @@ -77,7 +79,7 @@ TEST_CASE("XYZToMolecule") { xyz_data << "2\n"; xyz_data << "This is a comment!\n"; xyz_data << "H 0 0 0\n"; - xyz_data << "H 0 0 1\n"; + xyz_data << "H 1 1 1\n"; xyz_mod.change_input("Unit scaling factor", 1.8897259886);