From 124ff9895a88f9217eb3a51be8448672879bad65 Mon Sep 17 00:00:00 2001 From: Loren Schwiebert Date: Wed, 7 Aug 2024 11:20:41 -0400 Subject: [PATCH 1/7] Fix grammar in comment --- src/FFSetup.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/FFSetup.cpp b/src/FFSetup.cpp index fded99d3c..605c30ee5 100644 --- a/src/FFSetup.cpp +++ b/src/FFSetup.cpp @@ -380,7 +380,8 @@ void Dihedral::Read(Reader ¶m, std::string const &firstVar) { if (index == 0) { // set phase shift for n=0 to 90 degree // We will have C0 = Kchi (1 + cos(0 * phi + 90)) = Kchi - //this avoids double counting the C0 (constant offset) term, which is used force fields like TraPPE + // this avoids double counting the C0 (constant offset) term, which is used + // in force fields like TraPPE def = 90.00; } Add(merged, coeff, index, def); From 6b2a8eaec59fd0856fffd8f735a85c4256cc150b Mon Sep 17 00:00:00 2001 From: Loren Schwiebert Date: Wed, 7 Aug 2024 12:02:13 -0400 Subject: [PATCH 2/7] Remove duplicate dihedrals with the same periodicity and issue a warning --- src/FFSetup.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/FFSetup.cpp b/src/FFSetup.cpp index 605c30ee5..18b8d2b50 100644 --- a/src/FFSetup.cpp +++ b/src/FFSetup.cpp @@ -389,6 +389,17 @@ 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; + 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; + } ++countTerms; Kchi[merged].push_back(EnConvIfCHARMM(coeff)); n[merged].push_back(index); From 02bfcf67796972e7042a8e2496a0869a92e44ed1 Mon Sep 17 00:00:00 2001 From: Loren Schwiebert Date: Thu, 8 Aug 2024 15:45:13 -0400 Subject: [PATCH 3/7] 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)); From 61d039817ea32262ea72365ed0744a260c4b1287 Mon Sep 17 00:00:00 2001 From: Loren Schwiebert Date: Wed, 21 Aug 2024 13:44:33 -0400 Subject: [PATCH 4/7] Also check for duplicate Bonds, Angles, etc. and minor code cleanup --- src/FFSetup.cpp | 34 +++++++++++++++++++--------------- src/FFSetup.h | 2 +- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/FFSetup.cpp b/src/FFSetup.cpp index 654147623..33251c57a 100644 --- a/src/FFSetup.cpp +++ b/src/FFSetup.cpp @@ -19,7 +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 double EPSILON = 1.0e-4; const uint FFSetup::CHARMM_ALIAS_IDX = 0; const uint FFSetup::EXOTIC_ALIAS_IDX = 1; const std::string FFSetup::paramFileAlias[] = {"CHARMM-Style parameter file", @@ -186,6 +186,11 @@ std::string FFBase::ReadKind(Reader ¶m, std::string const &firstKindName) { param.file >> tmp; merged += tmp; } + // Skip duplicates unless we allow multiple entries, such as for dihedrals + if (!multi && std::find(name.begin(), name.end(), merged) != name.end()) + std::cout << "Warning: Ignoring duplicate entry of " << merged + << ". Using first entry!\n"; + // Might insert duplicates but they will be ignored during execution if (!multi || std::find(name.begin(), name.end(), merged) == name.end()) name.push_back(merged); return merged; @@ -237,7 +242,7 @@ void Particle::Read(Reader ¶m, std::string const &firstVar) { // computation. But need the exponents to be large enough that the arithmetic // or geometric mean of any pair > 6.0. See FFParticle::Blend() for underlying // math. - double smallVal = 1e-20; + double smallVal = 1.0e-20; if (std::fabs(e) < smallVal) { e = 0.0; expN = 12.0; // Set to default (LJ) exponent. @@ -247,12 +252,11 @@ void Particle::Read(Reader ¶m, std::string const &firstVar) { expN_1_4 = 12.0; // Set to default (LJ) exponent. } if ((expN - 6.0) < smallVal) { - std::cout << "ERROR: Mie exponent must be > 6!" << std::endl; + std::cout << "ERROR: Mie exponent must be > 6!\n"; exit(EXIT_FAILURE); } if ((expN_1_4 - 6.0) < smallVal) { - std::cout << "ERROR: Mie exponent for 1-4 interactions must be > 6!" - << std::endl; + std::cout << "ERROR: Mie exponent for 1-4 interactions must be > 6!\n"; exit(EXIT_FAILURE); } @@ -400,13 +404,13 @@ void Dihedral::Add(std::string const &merged, const double coeff, 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"; + 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"; + std::cout << "Warning: Ignoring duplicate periodicity of " << index + << " for dihedral " << merged << ". Using first entry!\n"; return; } } @@ -424,7 +428,7 @@ void Improper::Read(Reader ¶m, std::string const &firstVar) { uint index; std::string merged = ReadKind(param, firstVar); // If new value - if (validname(merged) == true) { + if (validname(merged)) { param.file >> coeff >> index >> def; if (!param.file.good()) { std::cout << "Error: Incomplete Improper parameters was found in " @@ -445,7 +449,7 @@ void CMap::Read(Reader ¶m, std::string const &firstVar) { uint index; std::string merged = ReadKind(param, firstVar); // If new value - if (validname(merged) == true) { + if (validname(merged)) { param.file >> coeff >> index >> def; if (!param.file.good()) { std::cout << "Error: Incomplete Improper parameters was found in " @@ -455,19 +459,19 @@ void CMap::Read(Reader ¶m, std::string const &firstVar) { Add(coeff, def); } } -// Currently dummy method, exact same as improper +// Currently dummy method, exactly the same as improper void CMap::Add(const double coeff, const double def) { Komega.push_back(EnConvIfCHARMM(coeff)); omega0.push_back(def); } -// Currently dummy method, exact same as improper +// Currently dummy method, exactly the same as improper void HBond::Read(Reader ¶m, std::string const &firstVar) { double coeff, def; uint index; std::string merged = ReadKind(param, firstVar); // If new value - if (validname(merged) == true) { + if (validname(merged)) { param.file >> coeff >> index >> def; if (!param.file.good()) { std::cout << "Error: Incomplete Improper parameters was found in " diff --git a/src/FFSetup.h b/src/FFSetup.h index e7bd1f5a4..7a046dbe7 100644 --- a/src/FFSetup.h +++ b/src/FFSetup.h @@ -40,7 +40,7 @@ class FFBase : public SearchableBase { std::string ReadKind(Reader ¶m, std::string const &firstKindName); std::vector &getnamelist() { return name; } - bool validname(std::string &merged) { + bool validname(const std::string &merged) const { return (std::count(name.begin(), name.end(), merged) > 0); } std::string getname(const uint i) const { return name[i]; } From 34c80aba412fe7a9dc388b85e61e1fb8e3e12af3 Mon Sep 17 00:00:00 2001 From: Loren Schwiebert Date: Fri, 23 Aug 2024 19:35:41 -0400 Subject: [PATCH 5/7] Enhance patch to print filename in warnings --- src/FFSetup.cpp | 20 +++++++++++--------- src/FFSetup.h | 4 ++-- src/Reader.h | 2 ++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/FFSetup.cpp b/src/FFSetup.cpp index 33251c57a..c724622e6 100644 --- a/src/FFSetup.cpp +++ b/src/FFSetup.cpp @@ -187,9 +187,10 @@ std::string FFBase::ReadKind(Reader ¶m, std::string const &firstKindName) { merged += tmp; } // Skip duplicates unless we allow multiple entries, such as for dihedrals - if (!multi && std::find(name.begin(), name.end(), merged) != name.end()) - std::cout << "Warning: Ignoring duplicate entry of " << merged - << ". Using first entry!\n"; + if (!multi && std::find(name.begin(), name.end(), merged) != name.end()) { + std::cout << "Warning: Ignoring duplicate entry for " << merged << " in " + << param.getFileName().c_str() << ". Using first entry!\n"; + } // Might insert duplicates but they will be ignored during execution if (!multi || std::find(name.begin(), name.end(), merged) == name.end()) name.push_back(merged); @@ -389,11 +390,11 @@ void Dihedral::Read(Reader ¶m, std::string const &firstVar) { // in force fields like TraPPE def = 90.00; } - Add(merged, coeff, index, def); + Add(param.getFileName(), merged, coeff, index, def); last = merged; } -void Dihedral::Add(std::string const &merged, const double coeff, - const uint index, const double def) { +void Dihedral::Add(const std::string &fileName, const std::string &merged, + const double coeff, const uint index, const double def) { // Check for (and skip) duplicate periodicities for the same dihedral // Generate an error and terminate if the duplicate dihedrals have different // parameters @@ -405,12 +406,13 @@ void Dihedral::Add(std::string const &merged, const double coeff, 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"; + << fileName.c_str() << " for dihedral " << merged + << " with periodicity " << index << "!\n"; exit(EXIT_FAILURE); } else { std::cout << "Warning: Ignoring duplicate periodicity of " << index - << " for dihedral " << merged << ". Using first entry!\n"; + << " for dihedral " << merged << " in " + << fileName.c_str() << ". Using first entry!\n"; return; } } diff --git a/src/FFSetup.h b/src/FFSetup.h index 7a046dbe7..ca34608ed 100644 --- a/src/FFSetup.h +++ b/src/FFSetup.h @@ -146,8 +146,8 @@ class Dihedral : public ReadableBaseWithFirst, public FFBase { public: Dihedral(void) : FFBase(4, true), last(""), countTerms(0) {} virtual void Read(Reader ¶m, std::string const &firstVar); - void Add(std::string const &merged, const double coeff, const uint index, - const double def); + void Add(const std::string &fileName, const std::string &merged, + const double coeff, const uint index, const double def); uint getTerms() const { return countTerms; } uint append(std::string &s, double *Kchi_in, double *delta_in, uint *n_in, uint count) const { diff --git a/src/Reader.h b/src/Reader.h index 28c4e28b9..5775114bf 100644 --- a/src/Reader.h +++ b/src/Reader.h @@ -32,6 +32,7 @@ inline std::ifstream &operator>>(std::ifstream &is, bool &val) { class Reader { public: + friend inline std::ifstream &operator>>(std::ifstream &is, bool &val); Reader(std::string const &name, std::string const &alias, bool useSkipW = false, std::string const *const skipW = NULL, bool useSkipC = false, std::string const *const skipC = NULL, @@ -98,6 +99,7 @@ class Reader { } bool Read(std::string &firstItem); + std::string getFileName() const { return fileName; }; // Make public to expose object. std::ifstream file; From 0dd9bcdbe5a2b486baf27a4133a8c6390840ceb6 Mon Sep 17 00:00:00 2001 From: Loren Schwiebert Date: Fri, 23 Aug 2024 21:38:33 -0400 Subject: [PATCH 6/7] Update new warning messages --- src/FFSetup.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FFSetup.cpp b/src/FFSetup.cpp index c724622e6..8b60a5eee 100644 --- a/src/FFSetup.cpp +++ b/src/FFSetup.cpp @@ -189,7 +189,7 @@ std::string FFBase::ReadKind(Reader ¶m, std::string const &firstKindName) { // Skip duplicates unless we allow multiple entries, such as for dihedrals if (!multi && std::find(name.begin(), name.end(), merged) != name.end()) { std::cout << "Warning: Ignoring duplicate entry for " << merged << " in " - << param.getFileName().c_str() << ". Using first entry!\n"; + << param.getFileName().c_str() << ". Using first entry.\n"; } // Might insert duplicates but they will be ignored during execution if (!multi || std::find(name.begin(), name.end(), merged) == name.end()) @@ -412,7 +412,7 @@ void Dihedral::Add(const std::string &fileName, const std::string &merged, } else { std::cout << "Warning: Ignoring duplicate periodicity of " << index << " for dihedral " << merged << " in " - << fileName.c_str() << ". Using first entry!\n"; + << fileName.c_str() << ". Using first entry.\n"; return; } } From a3a7c1c0d793e5b3a978e8cedd6fc802ce56aa7e Mon Sep 17 00:00:00 2001 From: Loren Schwiebert Date: Sat, 24 Aug 2024 17:31:27 -0400 Subject: [PATCH 7/7] Update warning message for duplicated dihedrals --- src/FFSetup.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FFSetup.cpp b/src/FFSetup.cpp index 8b60a5eee..9f4388b08 100644 --- a/src/FFSetup.cpp +++ b/src/FFSetup.cpp @@ -411,8 +411,8 @@ void Dihedral::Add(const std::string &fileName, const std::string &merged, exit(EXIT_FAILURE); } else { std::cout << "Warning: Ignoring duplicate periodicity of " << index - << " for dihedral " << merged << " in " - << fileName.c_str() << ". Using first entry.\n"; + << " for dihedral " << merged << " in " << fileName.c_str() + << ".\n"; return; } }