Skip to content

Commit

Permalink
Enhance patch to print filename in warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
LSchwiebert committed Aug 23, 2024
1 parent 61d0398 commit 34c80ab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
20 changes: 11 additions & 9 deletions src/FFSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ std::string FFBase::ReadKind(Reader &param, 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);
Expand Down Expand Up @@ -389,11 +390,11 @@ void Dihedral::Read(Reader &param, 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
Expand All @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/FFSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ class Dihedral : public ReadableBaseWithFirst, public FFBase {
public:
Dihedral(void) : FFBase(4, true), last(""), countTerms(0) {}
virtual void Read(Reader &param, 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 {
Expand Down
2 changes: 2 additions & 0 deletions src/Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 34c80ab

Please sign in to comment.