From 7eb4a755b91c11dccc6f6ebacf6925aea643da9c Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Fri, 15 Nov 2024 13:10:14 -0500 Subject: [PATCH] Handle upper-case [ATOMS] line in Molden files from Cfour https://discuss.avogadro.cc/t/atoms-in-caps-in-molden-file-does-not-read-the-atoms/6465 Signed-off-by: Geoff Hutchison --- avogadro/core/utilities.h | 20 +++++++++++++++----- avogadro/quantumio/molden.cpp | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/avogadro/core/utilities.h b/avogadro/core/utilities.h index e459b592f5..391d651fea 100644 --- a/avogadro/core/utilities.h +++ b/avogadro/core/utilities.h @@ -40,10 +40,20 @@ inline std::vector split(const std::string& string, char delimiter, * @param search String that will be searched for. * @return True if the string contains search, false otherwise. */ -inline bool contains(const std::string& input, const std::string& search) +inline bool contains(const std::string& input, const std::string& search, + bool caseSensitive = true) { - size_t found = input.find(search); - return found != std::string::npos; + if (caseSensitive) { + return input.find(search) != std::string::npos; + } else { + std::string inputLower = input; + std::string searchLower = search; + std::transform(inputLower.begin(), inputLower.end(), inputLower.begin(), + ::tolower); + std::transform(searchLower.begin(), searchLower.end(), searchLower.begin(), + ::tolower); + return inputLower.find(searchLower) != std::string::npos; + } } /** @@ -98,7 +108,7 @@ T lexicalCast(const std::string& inputString, bool& ok) return value; } -} // end Core namespace -} // end Avogadro namespace +} // namespace Core +} // namespace Avogadro #endif // AVOGADRO_CORE_UTILITIES_H diff --git a/avogadro/quantumio/molden.cpp b/avogadro/quantumio/molden.cpp index f0ce43461c..13b2720d26 100644 --- a/avogadro/quantumio/molden.cpp +++ b/avogadro/quantumio/molden.cpp @@ -97,7 +97,7 @@ void MoldenFile::processLine(std::istream& in) // Molden file format uses sections, each starts with a header line of the // form [Atoms], and the beginning of a new section denotes the end of the // last. - if (Core::contains(line, "[Atoms]")) { + if (Core::contains(line, "[Atoms]") || Core::contains(line, "[ATOMS]")) { if (list.size() > 1 && Core::contains(list[1], "AU")) m_coordFactor = BOHR_TO_ANGSTROM_D; m_mode = Atoms;