From 02bfcf67796972e7042a8e2496a0869a92e44ed1 Mon Sep 17 00:00:00 2001 From: Loren Schwiebert Date: Thu, 8 Aug 2024 15:45:13 -0400 Subject: [PATCH] Generate error instead of warning if duplicates have different parameters --- src/FFSetup.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/FFSetup.cpp b/src/FFSetup.cpp index 18b8d2b50..654147623 100644 --- a/src/FFSetup.cpp +++ b/src/FFSetup.cpp @@ -19,6 +19,7 @@ along with this program, also can be found at // For Exotic style parameter header error checking #include +const double EPSILON = 0.001; const uint FFSetup::CHARMM_ALIAS_IDX = 0; const uint FFSetup::EXOTIC_ALIAS_IDX = 1; const std::string FFSetup::paramFileAlias[] = {"CHARMM-Style parameter file", @@ -390,15 +391,27 @@ void Dihedral::Read(Reader ¶m, std::string const &firstVar) { void Dihedral::Add(std::string const &merged, const double coeff, const uint index, const double def) { // Check for (and skip) duplicate periodicities for the same dihedral - bool duplicate = false; + // Generate an error and terminate if the duplicate dihedrals have different + // parameters + auto Kchi_it = Kchi[merged].begin(); + auto delta_it = delta[merged].begin(); for (auto it = n[merged].begin(); it != n[merged].end(); ++it) { - duplicate |= *it == index; - } - - if (duplicate) { - std::cout << "Warning: Skipping duplicate periodicity of " << index - << " for dihedral " << merged << "!\n"; - return; + // Found a duplicate dihedral + if (*it == index) { + if (std::fabs(*Kchi_it - EnConvIfCHARMM(coeff)) > EPSILON || + std::fabs(*delta_it - geom::DegToRad(def)) > EPSILON) { + std::cout << "Error: Inconsistent Dihedral parameters were found in " + "parameter file for dihedral " + << merged << " with periodicity " << index << "!\n"; + exit(EXIT_FAILURE); + } else { + std::cout << "Warning: Skipping duplicate periodicity of " << index + << " for dihedral " << merged << "!\n"; + return; + } + } + Kchi_it++; + delta_it++; } ++countTerms; Kchi[merged].push_back(EnConvIfCHARMM(coeff));