From 22dacf27b5618fea80e286479248b82732b9e108 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Tue, 26 Nov 2024 15:04:21 -0500 Subject: [PATCH 1/2] Add decimal precision as per forum debate (10 decimals) Signed-off-by: Geoff Hutchison --- avogadro/io/xyzformat.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/avogadro/io/xyzformat.cpp b/avogadro/io/xyzformat.cpp index 59278bf48a..e2cc91c22c 100644 --- a/avogadro/io/xyzformat.cpp +++ b/avogadro/io/xyzformat.cpp @@ -326,12 +326,12 @@ bool XyzFormat::write(std::ostream& outStream, const Core::Molecule& mol) } outStream << std::setw(3) << std::left - << Elements::symbol(atom.atomicNumber()) << " " << std::setw(10) - << std::right << std::fixed << std::setprecision(5) - << atom.position3d().x() << " " << std::setw(10) << std::right - << std::fixed << std::setprecision(5) << atom.position3d().y() - << " " << std::setw(10) << std::right << std::fixed - << std::setprecision(5) << atom.position3d().z() << "\n"; + << Elements::symbol(atom.atomicNumber()) << " " << std::setw(15) + << std::right << std::fixed << std::setprecision(10) + << atom.position3d().x() << " " << std::setw(15) << std::right + << std::fixed << std::setprecision(10) << atom.position3d().y() + << " " << std::setw(15) << std::right << std::fixed + << std::setprecision(10) << atom.position3d().z() << "\n"; } return true; From f94d30d51dbc600116911f3cfdfa391b9cf315ca Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Fri, 29 Nov 2024 11:43:38 -0500 Subject: [PATCH 2/2] Fix unit test for new XYZ precision Signed-off-by: Geoff Hutchison --- tests/io/xyztest.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/tests/io/xyztest.cpp b/tests/io/xyztest.cpp index 457b885ecb..84cce2e7bf 100644 --- a/tests/io/xyztest.cpp +++ b/tests/io/xyztest.cpp @@ -28,11 +28,11 @@ #include #include +using Avogadro::Vector3; using Avogadro::Core::Atom; using Avogadro::Core::Molecule; using Avogadro::Io::FileFormat; using Avogadro::Io::XyzFormat; -using Avogadro::Vector3; // methane.xyz uses atomic symbols to identify atoms TEST(XyzTest, readAtomicSymbols) @@ -119,19 +119,25 @@ TEST(XyzTest, write) std::string output; EXPECT_EQ(xyz.writeString(output, molecule), true); - // The output should be an exact match with the sample file. - std::istringstream outputStream(output); - std::ifstream refStream(AVOGADRO_DATA "/data/methane.xyz"); - char outputChar = '\0'; - char refChar = '\0'; - outputStream >> std::noskipws; - refStream >> std::noskipws; - bool checkedSomething = false; - while ((outputStream >> outputChar) && (refStream >> refChar)) { - ASSERT_EQ(refChar, outputChar); - checkedSomething = true; - } - EXPECT_TRUE(checkedSomething); + // this part is more of a roundtrip test + Molecule readMolecule; + xyz.readString(output, readMolecule); + + // make sure we've got the same thing + EXPECT_EQ(readMolecule.atomCount(), 5); + + // Bond perception will result in 4 bonds + EXPECT_EQ(readMolecule.bondCount(), 4); + + EXPECT_EQ(readMolecule.atom(0).atomicNumber(), 6); + EXPECT_EQ(readMolecule.atom(1).atomicNumber(), 1); + EXPECT_EQ(readMolecule.atom(2).atomicNumber(), 1); + EXPECT_EQ(readMolecule.atom(3).atomicNumber(), 1); + EXPECT_EQ(readMolecule.atom(4).atomicNumber(), 1); + + EXPECT_EQ(readMolecule.atom(4).position3d().x(), -0.51336); + EXPECT_EQ(readMolecule.atom(4).position3d().y(), 0.889165); + EXPECT_EQ(readMolecule.atom(4).position3d().z(), -0.36300); } TEST(XyzTest, modes)