#include <algorithm>
#include <array>
+#include <map>
#include <string>
+#include <unordered_set>
#include <vector>
#include "gromacs/commandline/pargs.h"
static void histogramming(FILE* log,
int nbin,
- ResidueType* rt,
int nf,
int maxchi,
real** dih,
char hisfile[256], hhisfile[256], title[256], *ss_str = nullptr;
char** leg;
- size_t rt_size = rt->numberOfEntries();
if (bSSHisto)
{
fp = gmx_ffopen(ssdump, "r");
gmx_ffclose(fp);
}
+ // Build a list of unique residue names found in the dihedral
+ // list, so we can loop over those unique names conveniently. The
+ // names are the same as the residue names found in rt in the
+ // caller, but ResidueType doesn't yet have a way to loop over its
+ // contents.
+ std::unordered_set<std::string> uniqueResidueNames;
+ for (const auto& dihedral : dlist)
+ {
+ uniqueResidueNames.emplace(dihedral.residueName);
+ }
// Build the lookup tables for data relating to the all dihedrals
// from each unique residue name represented in the dihedral list.
- std::array<std::vector<std::vector<std::vector<int>>>, 3> his_aa_ss;
- if (bSSHisto)
+ std::array<std::map<std::string, std::vector<std::vector<int>>>, 3> his_aa_ss;
+ std::vector<std::map<std::string, std::vector<int>>> his_aa(edMax);
+ for (const auto& residueName : uniqueResidueNames)
{
- for (auto& secondaryStructure : his_aa_ss)
+ if (bSSHisto)
+ {
+ for (auto& secondaryStructure : his_aa_ss)
+ {
+ secondaryStructure[residueName] =
+ std::vector<std::vector<int>>(edMax, std::vector<int>(nbin, 0));
+ }
+ }
+ for (auto& dihedraltype : his_aa)
{
- // Construct the vector nest
- secondaryStructure = { rt_size + 1, { edMax, std::vector<int>(nbin, 0) } };
+ dihedraltype[residueName] = std::vector<int>(nbin, 0);
}
}
- std::vector<std::vector<std::vector<int>>> his_aa = { edMax,
- { rt_size + 1, std::vector<int>(nbin, 0) } };
snew(histmp, nbin);
snew(Jc, dlist.size());
*/
switch (ss_str[dihedral.resnr])
{
- case 'E': his_aa_ss[0][dihedral.index][Dih][hindex]++; break;
- case 'H': his_aa_ss[1][dihedral.index][Dih][hindex]++; break;
- default: his_aa_ss[2][dihedral.index][Dih][hindex]++; break;
+ case 'E': his_aa_ss[0][dihedral.residueName][Dih][hindex]++; break;
+ case 'H': his_aa_ss[1][dihedral.residueName][Dih][hindex]++; break;
+ default: his_aa_ss[2][dihedral.residueName][Dih][hindex]++; break;
}
}
else if (debug)
/* Sum distribution per amino acid type as well */
for (int k = 0; (k < nbin); k++)
{
- his_aa[Dih][dihedral.index][k] += histmp[k];
+ his_aa[Dih][dihedral.residueName][k] += histmp[k];
histmp[k] = 0;
}
j++;
/* finished -jc stuff */
std::vector<real> normhisto(nbin);
- for (size_t i = 0; (i < rt_size); i++)
+ for (const auto& residueName : uniqueResidueNames)
{
for (int Dih = 0; (Dih < edMax); Dih++)
{
int j;
for (j = 0; (j < nbin); j++)
{
- if (his_aa[Dih][i][j] != 0)
+ if (his_aa[Dih][residueName][j] != 0)
{
break;
}
{
if (bNormalize)
{
- normalize_histo(his_aa[Dih][i], (360.0 / nbin), normhisto);
+ normalize_histo(his_aa[Dih][residueName], (360.0 / nbin), normhisto);
}
- std::string residueName = rt->nameFromResidueIndex(i);
switch (Dih)
{
case edPhi:
}
else
{
- fprintf(fp, "%5d %10d\n", angle, his_aa[Dih][i][j]);
+ fprintf(fp, "%5d %10d\n", angle, his_aa[Dih][residueName][j]);
}
if (bSSHisto)
{
for (int k = 0; (k < 3); k++)
{
- fprintf(ssfp[k], "%5d %10d\n", angle, his_aa_ss[k][i][Dih][j]);
+ fprintf(ssfp[k], "%5d %10d\n", angle, his_aa_ss[k][residueName][Dih][j]);
}
}
}
/* Histogramming & J coupling constants & calc of S2 order params */
histogramming(log,
nbin,
- &rt,
nf,
maxchi,
dih,
#include <cstdio>
#include <algorithm>
-#include <iterator>
#include <optional>
#include <string>
return foundIt ? gmx::equalCaseInsensitive(residueType, (*foundIt)->residueType) : false;
}
-int ResidueType::numberOfEntries() const
-{
- return impl_->entry.size();
-}
-
-int ResidueType::indexFromResidueName(const std::string& residueName) const
-{
- gmx::ArrayRef<const ResidueTypeEntry> temp(impl_->entry);
- auto foundIt = findResidueEntryWithName(temp, residueName);
- return foundIt ? std::distance(temp.begin(), *foundIt) : -1;
-}
-
-std::string ResidueType::nameFromResidueIndex(int index) const
-{
- if (index >= 0 && index < gmx::ssize(impl_->entry))
- {
- return impl_->entry[index].residueName;
- }
- else
- {
- return "";
- }
-}
-
std::string ResidueType::typeOfNamedDatabaseResidue(const std::string& residueName)
{
auto foundIt = findResidueEntryWithName(impl_->entry, residueName);
//! Get handle to underlying residue type data.
ResidueTypeEntry* ResidueTypes();
- //! Get number of entries in ResidueTypes.
- int numberOfEntries() const;
/*! \brief
* Return true if residue \p residueName is found or false otherwise.
*
* \returns If the check was successful.
*/
bool namedResidueHasType(const std::string& residueName, const std::string& residueType);
- /*! \brief
- * Get index to entry in ResidueTypes with name \p residueName.
- *
- * \param[in] residueName Name of the residue being searched.
- * \returns The index or -1 if not found.
- */
- int indexFromResidueName(const std::string& residueName) const;
- /*! \brief
- * Get the name of the entry in ResidueTypes with \p index.
- *
- * \param[in] index Which entry should be returned.
- * \returns The name of the entry at \p index, or nullptr.
- */
- std::string nameFromResidueIndex(int index) const;
/*! \brief
* Return the residue type if a residue with that name exists, or "Other"
*