Changes implementation to class with private implementation pointer.
Change-Id: Ia623a23e32ca95a00460c536e2868106b32ad7f9
real occup, bfac;
gmx_bool bOccup;
int chainnum, lastchainnum;
- gmx_residuetype_t*rt;
const char *p_restype;
const char *p_lastrestype;
- gmx_residuetype_init(&rt);
-
fprintf(out, "TITLE %s\n", (title && title[0]) ? title : gmx::bromacs().c_str());
if (box && ( (norm2(box[XX]) != 0.0f) || (norm2(box[YY]) != 0.0f) || (norm2(box[ZZ]) != 0.0f) ) )
{
lastchainnum = -1;
p_restype = nullptr;
+ ResidueType rt;
for (ii = 0; ii < nindex; ii++)
{
i = index[ii];
resind = atoms->atom[i].resind;
chainnum = atoms->resinfo[resind].chainnum;
p_lastrestype = p_restype;
- gmx_residuetype_get_type(rt, *atoms->resinfo[resind].name, &p_restype);
+ rt.nameIndexedInResidueTypes(*atoms->resinfo[resind].name, &p_restype);
/* Add a TER record if we changed chain, and if either the previous or this chain is protein/DNA/RNA. */
if (bTerSepChains && ii > 0 && chainnum != lastchainnum)
{
/* Only add TER if the previous chain contained protein/DNA/RNA. */
- if (gmx_residuetype_is_protein(rt, p_lastrestype) || gmx_residuetype_is_dna(rt, p_lastrestype) || gmx_residuetype_is_rna(rt, p_lastrestype))
+ if (rt.namedResidueHasType(p_lastrestype, "Protein") || rt.namedResidueHasType(p_lastrestype, "DNA") || rt.namedResidueHasType(p_lastrestype, "RNA"))
{
fprintf(out, "TER\n");
}
fprintf(out, "CONECT%5d%5d\n", gc->conect[i].ai+1, gc->conect[i].aj+1);
}
}
-
- gmx_residuetype_destroy(rt);
}
void write_pdbfile(FILE *out, const char *title, const t_atoms *atoms, const rvec x[],
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2018,2019, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
t_dlist *mk_dlist(FILE *log,
const t_atoms *atoms, int *nlist,
gmx_bool bPhi, gmx_bool bPsi, gmx_bool bChi, gmx_bool bHChi,
- int maxchi, int r0, gmx_residuetype_t *rt)
+ int maxchi, int r0, ResidueType *rt)
{
int i, j, ii;
t_dihatms atm, prev;
{
nc[6]++;
}
- dl[nl].index = gmx_residuetype_get_index(rt, thisres);
+ dl[nl].index = rt->indexFromResidueName(thisres);
/* Prevent seg fault from unknown residues. If one adds a custom residue to
* residuetypes.dat but somehow loses it, changes it, or does analysis on
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
return j;
}
-static void histogramming(FILE *log, int nbin, gmx_residuetype_t *rt,
+static void histogramming(FILE *log, int nbin, ResidueType *rt,
int nf, int maxchi, real **dih,
int nlist, t_dlist dlist[],
const int index[],
const char *residue_name;
int rt_size;
- rt_size = gmx_residuetype_get_size(rt);
+ rt_size = rt->numberOfEntries();
if (bSSHisto)
{
fp = gmx_ffopen(ssdump, "r");
normalize_histo(nbin, his_aa[Dih][i], (360.0/nbin), normhisto);
}
- residue_name = gmx_residuetype_get_name(rt, i);
+ residue_name = rt->nameFromResidueIndex(i);
switch (Dih)
{
case edPhi:
gmx_bool bDo_rt, bDo_oh, bDo_ot, bDo_jc;
real dt = 0, traj_t_ns;
gmx_output_env_t *oenv;
- gmx_residuetype_t *rt;
int isize, *index;
int ndih, nactdih, nf;
}
fprintf(log, "Title: %s\n", *top->name);
- gmx_residuetype_init(&rt);
- dlist = mk_dlist(log, &atoms, &nlist, bPhi, bPsi, bChi, bHChi, maxchi, r0, rt);
+ ResidueType rt;
+ dlist = mk_dlist(log, &atoms, &nlist, bPhi, bPsi, bChi, bHChi, maxchi, r0, &rt);
fprintf(stderr, "%d residues with dihedrals found\n", nlist);
if (nlist == 0)
}
/* Histogramming & J coupling constants & calc of S2 order params */
- histogramming(log, nbin, rt, nf, maxchi, dih, nlist, dlist, index,
+ histogramming(log, nbin, &rt, nf, maxchi, dih, nlist, dlist, index,
bPhi, bPsi, bOmega, bChi,
bNormHisto, bSSHisto, ftp2fn(efDAT, NFILE, fnm), bfac_max, &atoms,
bDo_jc, opt2fn("-jc", NFILE, fnm), oenv);
do_view(oenv, opt2fn("-corr", NFILE, fnm), "-nxy");
}
- gmx_residuetype_destroy(rt);
-
return 0;
}
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2018,2019, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include "gromacs/topology/index.h"
struct gmx_output_env_t;
-struct gmx_residuetype_t;
+class ResidueType;
/* must correspond with 'leg' g_chi.c:727 */
enum {
t_dlist *mk_dlist(FILE *log,
const t_atoms *atoms, int *nlist,
gmx_bool bPhi, gmx_bool bPsi, gmx_bool bChi, gmx_bool bHChi,
- int maxchi, int r0, struct gmx_residuetype_t *rt);
+ int maxchi, int r0, ResidueType *rt);
void pr_dlist(FILE *fp, int nl, t_dlist dl[], real dt, int printtype,
gmx_bool bPhi, gmx_bool bPsi, gmx_bool bChi, gmx_bool bOmega, int maxchi);
}
static int get_atype(int atom, t_atoms *at, int nrtp, t_restp rtp[],
- gmx_residuetype_t *rt)
+ ResidueType *rt)
{
int type;
bool bNterm;
{
/* get type from rtp */
rtpp = get_restp(*(at->resinfo[at->atom[atom].resind].name), nrtp, rtp);
- bNterm = gmx_residuetype_is_protein(rt, *(at->resinfo[at->atom[atom].resind].name)) &&
+ bNterm = rt->namedResidueHasType(*(at->resinfo[at->atom[atom].resind].name), "Protein") &&
(at->atom[atom].resind == 0);
j = search_jtype(rtpp, *(at->atomname[atom]), bNterm);
type = rtpp->atom[j].type;
}
static real get_amass(int atom, t_atoms *at, int nrtp, t_restp rtp[],
- gmx_residuetype_t *rt)
+ ResidueType *rt)
{
real mass;
bool bNterm;
{
/* get mass from rtp */
rtpp = get_restp(*(at->resinfo[at->atom[atom].resind].name), nrtp, rtp);
- bNterm = gmx_residuetype_is_protein(rt, *(at->resinfo[at->atom[atom].resind].name)) &&
+ bNterm = rt->namedResidueHasType(*(at->resinfo[at->atom[atom].resind].name), "Protein") &&
(at->atom[atom].resind == 0);
j = search_jtype(rtpp, *(at->atomname[atom]), bNterm);
mass = rtpp->atom[j].m;
char *resnm = nullptr;
int nvsiteconf, nvsitetop, cmplength;
bool isN, planarN, bFound;
- gmx_residuetype_t*rt;
t_vsiteconf *vsiteconflist;
/* pointer to a list of CH3/NH3/NH2 configuration entries.
/* make index to tell which residues were already processed */
snew(bResProcessed, at->nres);
- gmx_residuetype_init(&rt);
+ ResidueType rt;
/* generate vsite constructions */
/* loop over all atoms */
if (bVsiteAromatics &&
!strcmp(*(at->atomname[i]), "CA") &&
!bResProcessed[resind] &&
- gmx_residuetype_is_protein(rt, *(at->resinfo[resind].name)) )
+ rt.namedResidueHasType(*(at->resinfo[resind].name), "Protein") )
{
/* mark this residue */
bResProcessed[resind] = TRUE;
count_bonds(i, &plist[F_BONDS], at->atomname,
&nrbonds, &nrHatoms, Hatoms, &Heavy, &nrheavies, heavies);
/* get Heavy atom type */
- tpHeavy = get_atype(Heavy, at, nrtp, rtp, rt);
+ tpHeavy = get_atype(Heavy, at, nrtp, rtp, &rt);
strcpy(tpname, get_atomtype_name(tpHeavy, atype));
bWARNING = FALSE;
}
/* get dummy mass type from first char of heavy atom type (N or C) */
- strcpy(nexttpname, get_atomtype_name(get_atype(heavies[0], at, nrtp, rtp, rt), atype));
+ strcpy(nexttpname, get_atomtype_name(get_atype(heavies[0], at, nrtp, rtp, &rt), atype));
ch = get_dummymass_name(vsiteconflist, nvsiteconf, tpname, nexttpname);
if (ch == nullptr)
/* get atom masses, and set Heavy and Hatoms mass to zero */
for (j = 0; j < nrHatoms; j++)
{
- mHtot += get_amass(Hatoms[j], at, nrtp, rtp, rt);
+ mHtot += get_amass(Hatoms[j], at, nrtp, rtp, &rt);
at->atom[Hatoms[j]].m = at->atom[Hatoms[j]].mB = 0;
}
- mtot = mHtot + get_amass(Heavy, at, nrtp, rtp, rt);
+ mtot = mHtot + get_amass(Heavy, at, nrtp, rtp, &rt);
at->atom[Heavy].m = at->atom[Heavy].mB = 0;
if (mHmult != 1.0)
{
} /* for i < at->nr */
- gmx_residuetype_destroy(rt);
-
if (debug)
{
fprintf(debug, "Before inserting new atoms:\n");
static int read_pdball(const char *inf, bool bOutput, const char *outf, char **title,
t_atoms *atoms, rvec **x,
int *ePBC, matrix box, bool bRemoveH,
- t_symtab *symtab, gmx_residuetype_t *rt, const char *watres,
+ t_symtab *symtab, ResidueType *rt, const char *watres,
AtomProperties *aps, bool bVerbose)
/* Read a pdb file. (containing proteins) */
{
}
static void
-checkResidueTypeSanity(t_atoms * pdba,
- int r0,
- int r1,
- gmx_residuetype_t * rt)
+checkResidueTypeSanity(t_atoms *pdba,
+ int r0,
+ int r1,
+ ResidueType *rt)
{
std::string startResidueString = gmx::formatString("%s%d", *pdba->resinfo[r0].name, pdba->resinfo[r0].nr);
std::string endResidueString = gmx::formatString("%s%d", *pdba->resinfo[r1-1].name, pdba->resinfo[r1-1].nr);
bool allResiduesHaveSameType = true;
const char *restype0;
const char *restype;
- gmx_residuetype_get_type(rt, *pdba->resinfo[r0].name, &restype0);
+ rt->nameIndexedInResidueTypes(*pdba->resinfo[r0].name, &restype0);
for (int i = r0 + 1; i < r1; i++)
{
- gmx_residuetype_get_type(rt, *pdba->resinfo[i].name, &restype);
+ rt->nameIndexedInResidueTypes(*pdba->resinfo[i].name, &restype);
if (gmx_strcasecmp(restype, restype0))
{
allResiduesHaveSameType = false;
}
static void find_nc_ter(t_atoms *pdba, int r0, int r1, int *r_start, int *r_end,
- gmx_residuetype_t *rt)
+ ResidueType *rt)
{
int i;
const char *p_startrestype;
/* Find the starting terminus (typially N or 5') */
for (i = r0; i < r1 && *r_start == -1; i++)
{
- gmx_residuetype_get_type(rt, *pdba->resinfo[i].name, &p_startrestype);
+ rt->nameIndexedInResidueTypes(*pdba->resinfo[i].name, &p_startrestype);
if (!gmx_strcasecmp(p_startrestype, "Protein") || !gmx_strcasecmp(p_startrestype, "DNA") || !gmx_strcasecmp(p_startrestype, "RNA") )
{
printf("Identified residue %s%d as a starting terminus.\n", *pdba->resinfo[i].name, pdba->resinfo[i].nr);
/* Go through the rest of the residues, check that they are the same class, and identify the ending terminus. */
for (i = *r_start; i < r1; i++)
{
- gmx_residuetype_get_type(rt, *pdba->resinfo[i].name, &p_restype);
+ rt->nameIndexedInResidueTypes(*pdba->resinfo[i].name, &p_restype);
if (!gmx_strcasecmp(p_restype, p_startrestype) && endWarnings == 0)
{
*r_end = i;
open_symtab(&symtab);
/* Residue type database */
- gmx_residuetype_t *rt;
- gmx_residuetype_init(&rt);
+ ResidueType rt;
/* Read residue renaming database(s), if present */
std::vector<std::string> rrn = fflib_search_file_end(ffdir_, ".r2b", FALSE);
const char *p_restype;
for (int i = 0; i < nrtprename; i++)
{
- int rc = gmx_residuetype_get_type(rt, rtprename[i].gmx, &p_restype);
-
/* Only add names if the 'standard' gromacs/iupac base name was found */
- if (rc == 0)
+ if (rt.nameIndexedInResidueTypes(rtprename[i].gmx, &p_restype))
{
- gmx_residuetype_add(rt, rtprename[i].main, p_restype);
- gmx_residuetype_add(rt, rtprename[i].nter, p_restype);
- gmx_residuetype_add(rt, rtprename[i].cter, p_restype);
- gmx_residuetype_add(rt, rtprename[i].bter, p_restype);
+ rt.addResidue(rtprename[i].main, p_restype);
+ rt.addResidue(rtprename[i].nter, p_restype);
+ rt.addResidue(rtprename[i].cter, p_restype);
+ rt.addResidue(rtprename[i].bter, p_restype);
}
}
rvec *pdbx;
int natom = read_pdball(inputConfFile_.c_str(), bOutputSet_, outFile_.c_str(),
&title, &pdba_all, &pdbx, &ePBC, box, bRemoveH_,
- &symtab, rt, watres, &aps, bVerbose_);
+ &symtab, &rt, watres, &aps, bVerbose_);
if (natom == 0)
{
for (int i = 0; i < cc->nterpairs; i++)
{
find_nc_ter(pdba, cc->chainstart[i], cc->chainstart[i+1],
- &(cc->r_start[j]), &(cc->r_end[j]), rt);
+ &(cc->r_start[j]), &(cc->r_end[j]), &rt);
if (cc->r_start[j] >= 0 && cc->r_end[j] >= 0)
{
do now :( AF 26-7-99 */
rename_atoms(nullptr, ffdir_,
- pdba, &symtab, restp_chain, false, rt, false, bVerbose_);
+ pdba, &symtab, restp_chain, false, &rt, false, bVerbose_);
match_atomnames_with_rtp(restp_chain, hb_chain, pdba, x, bVerbose_);
int k = (cc->nterpairs > 0 && cc->r_start[0] >= 0) ? cc->r_start[0] : 0;
- gmx_residuetype_get_type(rt, *pdba->resinfo[k].name, &p_restype);
+ rt.nameIndexedInResidueTypes(*pdba->resinfo[k].name, &p_restype);
std::string molname;
std::string suffix;
print_top_mols(top_file, title, ffdir_, watermodel_, nincl_, incls_, nmol_, mols_);
gmx_fio_fclose(top_file);
- gmx_residuetype_destroy(rt);
-
/* now merge all chains back together */
natom = 0;
int nres = 0;
}
static int name2type(t_atoms *at, int **cgnr,
- t_restp restp[], gmx_residuetype_t *rt)
+ t_restp restp[], ResidueType *rt)
{
int i, j, prevresind, resind, i0, prevcg, cg, curcg;
char *name;
{
bool bProt;
resind = at->atom[i].resind;
- bProt = gmx_residuetype_is_protein(rt, *(at->resinfo[resind].name));
+ bProt = rt->namedResidueHasType(*(at->resinfo[resind].name), "Protein");
bNterm = bProt && (resind == 0);
if (resind > 0)
{
int *vsite_type;
int i, nmissat;
int bts[ebtsNR];
- gmx_residuetype_t*rt;
init_plist(plist);
- gmx_residuetype_init(&rt);
+ ResidueType rt;
/* Make bonds */
at2bonds(&(plist[F_BONDS]), hb,
atoms, nssbonds, ssbonds,
bAllowMissing);
- nmissat = name2type(atoms, &cgnr, restp, rt);
+ nmissat = name2type(atoms, &cgnr, restp, &rt);
if (nmissat)
{
if (bAllowMissing)
/* cleaning up */
free_t_hackblock(atoms->nres, &hb);
free_t_restp(atoms->nres, &restp);
- gmx_residuetype_destroy(rt);
/* we should clean up hb and restp here, but that is a *L*O*T* of work! */
sfree(cgnr);
void rename_atoms(const char* xlfile, const char *ffdir,
t_atoms *atoms, t_symtab *symtab, const t_restp *restp,
- bool bResname, gmx_residuetype_t *rt, bool bReorderNum,
+ bool bResname, ResidueType *rt, bool bReorderNum,
bool bVerbose)
{
int nxlate, a, i, resind;
/* Match the residue name */
bMatch = (xlatom[i].res == nullptr ||
(gmx_strcasecmp("protein-nterm", xlatom[i].res) == 0 &&
- gmx_residuetype_is_protein(rt, rnm) && bStartTerm) ||
+ rt->namedResidueHasType(rnm, "Protein") && bStartTerm) ||
(gmx_strcasecmp("protein-cterm", xlatom[i].res) == 0 &&
- gmx_residuetype_is_protein(rt, rnm) && bEndTerm) ||
+ rt->namedResidueHasType(rnm, "Protein") && bEndTerm) ||
(gmx_strcasecmp("protein", xlatom[i].res) == 0 &&
- gmx_residuetype_is_protein(rt, rnm)) ||
+ rt->namedResidueHasType(rnm, "Protein")) ||
(gmx_strcasecmp("DNA", xlatom[i].res) == 0 &&
- gmx_residuetype_is_dna(rt, rnm)) ||
+ rt->namedResidueHasType(rnm, "DNA")) ||
(gmx_strcasecmp("RNA", xlatom[i].res) == 0 &&
- gmx_residuetype_is_rna(rt, rnm)));
+ rt->namedResidueHasType(rnm, "RNA")));
if (!bMatch)
{
ptr0 = rnm;
#ifndef GMX_GMXPREPROCESS_XLATE_H
#define GMX_GMXPREPROCESS_XLATE_H
-struct gmx_residuetype_t;
+class ResidueType;
struct t_atoms;
struct t_restp;
struct t_symtab;
*/
void rename_atoms(const char* xlfile, const char *ffdir,
t_atoms *atoms, t_symtab *symtab, const t_restp *restp,
- bool bResname, gmx_residuetype_t *rt, bool bReorderNum,
+ bool bResname, ResidueType *rt, bool bReorderNum,
bool bVerbose);
#endif
//! The different atom properties.
AtomProperty prop[epropNR];
//! The residue types.
- gmx_residuetype_t *restype = nullptr;
+ ResidueType restype;
};
/*! \brief
* \param[in] bExact Do we have the correct match.
* \returns The index for the property.
*/
-static int findPropertyIndex(AtomProperty *ap, gmx_residuetype_t *restype,
+static int findPropertyIndex(AtomProperty *ap, ResidueType *restype,
const std::string &residueName, const std::string &atomName,
gmx_bool *bExact)
{
int j = NOTFOUND;
- bool bProtein = gmx_residuetype_is_protein(restype, residueName.c_str());
+ bool bProtein = restype->namedResidueHasType(residueName.c_str(), "Protein");
bool bProtWild = residueName == "AAA";
int malen = NOTFOUND;
int mrlen = NOTFOUND;
* \param[in] propValue Value of property.
* \param[in] line Where to add property.
*/
-static void addProperty(AtomProperty *ap, gmx_residuetype_t *restype,
+static void addProperty(AtomProperty *ap, ResidueType *restype,
const std::string &residueName, const std::string &atomName,
real propValue, int line)
{
* \param[in] restype Library of residue types.
* \param[in] factor Scaling factor for property.
*/
-static void readProperty(AtomProperty *ap, gmx_residuetype_t *restype, double factor)
+static void readProperty(AtomProperty *ap, ResidueType *restype, double factor)
{
char line[STRLEN], resnm[32], atomnm[32];
* \param[in] haveBeenWarned If we already set a warning before
* \returns True of warning should be printed.
*/
-static bool setProperties(AtomProperty *ap, gmx_residuetype_t *restype, int eprop, bool haveBeenWarned)
+static bool setProperties(AtomProperty *ap, ResidueType *restype, int eprop, bool haveBeenWarned)
{
const char *fns[epropNR] = { "atommass.dat", "vdwradii.dat", "dgsolv.dat", "electroneg.dat", "elements.dat" };
double fac[epropNR] = { 1.0, 1.0, 418.4, 1.0, 1.0 };
AtomProperties::AtomProperties()
: impl_(new Impl)
{
- gmx_residuetype_init(&impl_->restype);
}
AtomProperties::~AtomProperties()
{
- gmx_residuetype_destroy(impl_->restype);
}
AtomProperty *AtomProperties::prop(int eprop)
return &impl_->prop[eprop];
}
-gmx_residuetype_t *AtomProperties::restype()
+ResidueType *AtomProperties::restype()
{
- return impl_->restype;
+ return &impl_->restype;
}
//! Print warning that vdW radii and masses are guessed.
{
tmpAtomName = atomName;
}
- j = findPropertyIndex(&(impl_->prop[eprop]), impl_->restype, residueName,
+ j = findPropertyIndex(&(impl_->prop[eprop]), &impl_->restype, residueName,
tmpAtomName, &bExact);
if (eprop == epropVDW && !impl_->bWarnVDW)
};
struct AtomProperty;
-struct gmx_residuetype_t;
+class ResidueType;
/*! \brief
* Holds all the atom property information loaded.
*/
*/
AtomProperty *prop(int eprop);
//! Get handle to residuetype library.
- gmx_residuetype_t *restype();
+ ResidueType *restype();
private:
//! Implementation pointer.
void analyse(const t_atoms *atoms, t_blocka *gb, char ***gn, gmx_bool bASK, gmx_bool bVerb)
{
- gmx_residuetype_t*rt = nullptr;
char *resnm;
int i;
int iwater, iion;
add_grp(gb, gn, aid, "System");
/* For every residue, get a pointer to the residue type name */
- gmx_residuetype_init(&rt);
- assert(rt);
+ ResidueType rt;
std::vector<std::string> restype;
std::vector<std::string> previousTypename;
resnm = *atoms->resinfo[i].name;
const char *type = nullptr;
- gmx_residuetype_get_type(rt, resnm, &type);
+ rt.nameIndexedInResidueTypes(resnm, &type);
restype.emplace_back(type);
previousTypename.push_back(restype[i]);
for (i = 1; i < atoms->nres; i++)
{
resnm = *atoms->resinfo[i].name;
- gmx_residuetype_get_type(rt, resnm, &type);
+ rt.nameIndexedInResidueTypes(resnm, &type);
restype.emplace_back(type);
/* Note that this does not lead to a N*N loop, but N*K, where
gb->nr++;
gb->index[gb->nr] = gb->nra;
}
- gmx_residuetype_destroy(rt);
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include <cassert>
#include <cstdio>
+#include <algorithm>
+#include <iterator>
+
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/futil.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/strdb.h"
-const char gmx_residuetype_undefined[] = "Other";
+//! Definition for residue type that is not known.
+const char undefinedResidueType[] = "Other";
-struct gmx_residuetype_t
+//! Single ResidueType entry object
+struct ResidueTypeEntry
{
- int n;
- char ** resname;
- char ** restype;
+ //! Name of residue.
+ char *residueName;
+ //! Type name for residue entry.
+ char *residueType;
};
-int
-gmx_residuetype_init(gmx_residuetype_t **prt)
+//! Implementation detail for ResidueTypes
+class ResidueType::Impl
+{
+ public:
+ //! Number of entries
+ int n = 0;
+ //! Storage object for entries.
+ ResidueTypeEntry *entry = nullptr;
+};
+
+ResidueType::ResidueType()
+ : impl_(new Impl)
{
char line[STRLEN];
char resname[STRLEN], restype[STRLEN], dum[STRLEN];
- gmx_residuetype_t *rt;
-
- snew(rt, 1);
- *prt = rt;
- rt->n = 0;
- rt->resname = nullptr;
- rt->restype = nullptr;
-
- gmx::FilePtr db = gmx::openLibraryFile("residuetypes.dat");
+ gmx::FilePtr db = gmx::openLibraryFile("residuetypes.dat");
while (get_a_line(db.get(), line, STRLEN))
{
{
if (sscanf(line, "%1000s %1000s %1000s", resname, restype, dum) != 2)
{
- gmx_fatal(FARGS, "Incorrect number of columns (2 expected) for line in residuetypes.dat");
+ gmx_fatal(FARGS, "Incorrect number of columns (2 expected) for line in residuetypes.dat ");
}
- gmx_residuetype_add(rt, resname, restype);
+ addResidue(resname, restype);
}
}
-
- return 0;
}
-int
-gmx_residuetype_destroy(gmx_residuetype_t *rt)
+ResidueType::~ResidueType()
{
- int i;
-
- for (i = 0; i < rt->n; i++)
+ for (int i = 0; i < impl_->n; i++)
{
- sfree(rt->resname[i]);
- sfree(rt->restype[i]);
+ sfree(impl_->entry[i].residueName);
+ sfree(impl_->entry[i].residueType);
}
- sfree(rt->resname);
- sfree(rt->restype);
- sfree(rt);
-
- return 0;
+ sfree(impl_->entry);
}
-/* Return 0 if the name was found, otherwise -1.
- * p_restype is set to a pointer to the type name, or 'Other' if we did not find it.
- */
-int
-gmx_residuetype_get_type(gmx_residuetype_t *rt, const char * resname, const char ** p_restype)
+bool ResidueType::nameIndexedInResidueTypes(const char *residueName, const char **residueTypePointer)
{
int i, rc;
rc = -1;
- for (i = 0; i < rt->n && rc; i++)
+ for (i = 0; i < impl_->n && rc; i++)
{
- rc = gmx_strcasecmp(rt->resname[i], resname);
+ rc = gmx_strcasecmp(impl_->entry[i].residueName, residueName);
}
- *p_restype = (rc == 0) ? rt->restype[i-1] : gmx_residuetype_undefined;
+ *residueTypePointer = (rc == 0) ? impl_->entry[i-1].residueType : undefinedResidueType;
- return rc;
+ return (rc == 0);
}
-int
-gmx_residuetype_add(gmx_residuetype_t *rt, const char *newresname, const char *newrestype)
+void ResidueType::addResidue(const char *residueName, const char *residueType)
{
- bool found;
const char * p_oldtype;
- found = (gmx_residuetype_get_type(rt, newresname, &p_oldtype) == 0);
+ bool found = nameIndexedInResidueTypes(residueName, &p_oldtype);
- if (found && gmx_strcasecmp(p_oldtype, newrestype))
+ if (found && gmx_strcasecmp(p_oldtype, residueType))
{
fprintf(stderr, "Warning: Residue '%s' already present with type '%s' in database, ignoring new type '%s'.",
- newresname, p_oldtype, newrestype);
+ residueName, p_oldtype, residueType);
}
if (!found)
{
- srenew(rt->resname, rt->n+1);
- srenew(rt->restype, rt->n+1);
- rt->resname[rt->n] = gmx_strdup(newresname);
- rt->restype[rt->n] = gmx_strdup(newrestype);
- rt->n++;
- }
-
- return 0;
-}
-
-int
-gmx_residuetype_get_alltypes(gmx_residuetype_t *rt,
- const char *** p_typenames,
- int * ntypes)
-{
- int n = 0;
- const char **my_typename = nullptr;
-
- if (rt->n > 0)
- {
- int i = 0;
- const char *p = rt->restype[i];
- snew(my_typename, n+1);
- my_typename[n] = p;
- n = 1;
-
- for (i = 1; i < rt->n; i++)
- {
- p = rt->restype[i];
- bool bFound = false;
- for (int j = 0; j < n && !bFound; j++)
- {
- bFound = (gmx_strcasecmp(p, my_typename[j]) == 0);
- }
- if (!bFound)
- {
- srenew(my_typename, n+1);
- my_typename[n] = p;
- n++;
- }
- }
+ srenew(impl_->entry, impl_->n+1);
+ impl_->entry[impl_->n].residueName = gmx_strdup(residueName);
+ impl_->entry[impl_->n].residueType = gmx_strdup(residueType);
+ impl_->n++;
}
- *ntypes = n;
- *p_typenames = my_typename;
-
- return 0;
}
-gmx_bool
-gmx_residuetype_is_protein(gmx_residuetype_t *rt, const char *resnm)
+bool ResidueType::namedResidueHasType(const char *residueName, const char *residueType)
{
- gmx_bool rc;
+ bool rc;
const char *p_type;
- rc = gmx_residuetype_get_type(rt, resnm, &p_type) == 0 &&
- gmx_strcasecmp(p_type, "Protein") == 0;
- return rc;
-}
+ rc = nameIndexedInResidueTypes(residueName, &p_type) &&
+ gmx_strcasecmp(p_type, residueType) == 0;
-gmx_bool
-gmx_residuetype_is_dna(gmx_residuetype_t *rt, const char *resnm)
-{
- gmx_bool rc;
- const char *p_type;
-
- rc = gmx_residuetype_get_type(rt, resnm, &p_type) == 0 &&
- gmx_strcasecmp(p_type, "DNA") == 0;
return rc;
}
-gmx_bool
-gmx_residuetype_is_rna(gmx_residuetype_t *rt, const char *resnm)
+int ResidueType::numberOfEntries() const
{
- gmx_bool rc;
- const char *p_type;
-
- rc = gmx_residuetype_get_type(rt, resnm, &p_type) == 0 &&
- gmx_strcasecmp(p_type, "RNA") == 0;
- return rc;
+ return impl_->n;
}
-/* Return the size of the arrays */
-int
-gmx_residuetype_get_size(gmx_residuetype_t *rt)
-{
- return rt->n;
-}
-
-/* Search for a residuetype with name resnm within the
- * gmx_residuetype database. Return the index if found,
- * otherwise -1.
- */
-int
-gmx_residuetype_get_index(gmx_residuetype_t *rt, const char *resnm)
+int ResidueType::indexFromResidueName(const char *residueName) const
{
int i, rc;
rc = -1;
- for (i = 0; i < rt->n && rc; i++)
+ for (i = 0; i < impl_->n && rc; i++)
{
- rc = gmx_strcasecmp(rt->resname[i], resnm);
+ rc = gmx_strcasecmp(impl_->entry[i].residueName, residueName);
}
return (0 == rc) ? i-1 : -1;
}
-/* Return the name of the residuetype with the given index, or
- * NULL if not found. */
-const char *
-gmx_residuetype_get_name(gmx_residuetype_t *rt, int index)
+const char *ResidueType::nameFromResidueIndex(int index) const
{
- if (index >= 0 && index < rt->n)
+ if (index >= 0 && index < impl_->n)
{
- return rt->resname[index];
+ return impl_->entry[index].residueName;
}
else
{
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2014,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2014,2018,2019, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#define GMX_TOPOLOGY_RESIDUETYPES_H
#include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/classhelpers.h"
-typedef struct gmx_residuetype_t gmx_residuetype_t;
+struct ResidueTypeEntry;
-int
-gmx_residuetype_init(gmx_residuetype_t **rt);
+class ResidueType
+{
+ public:
+ //! Default constructor.
+ ResidueType();
+ //! Default destructor.
+ ~ResidueType();
-int
-gmx_residuetype_destroy(gmx_residuetype_t *rt);
+ //! Get handle to underlying residue type data.
+ ResidueTypeEntry *ResidueTypes();
-int
-gmx_residuetype_get_type(gmx_residuetype_t *rt, const char *resname, const char **p_restype);
+ //! Get number of entries in ResidueTypes.
+ int numberOfEntries() const;
+ /*! \brief
+ * Return true if residue \p residueName is found or false otherwise.
+ * \p residueTypePointer is set to the type name, or "Other" if not found.
+ *
+ * \param[in] residueName Residue name to search database for.
+ * \param[out] residueTypePointer Name of found type or "Other".
+ * \returns true if successful.
+ */
+ bool nameIndexedInResidueTypes(const char *residueName, const char **residueTypePointer);
+ /*! \brief
+ * Add entry to ResidueTypes if unique.
+ *
+ * \param[in] residueName Name of new residue.
+ * \param[in] residueType Type of new residue.
+ */
+ void addResidue(const char *residueName, const char *residueType);
+ /*! \brief
+ * Checks if the indicated \p residueName if of \p residueType.
+ *
+ * \param[in] residueName Residue that should be checked.
+ * \param[in] residueType Which ResidueType the residue should have.
+ * \returns If the check was successful.
+ */
+ bool namedResidueHasType(const char *residueName, const char *residueType);
+ /*! \brief
+ * Get entry index in ResidueTypes with name \p residueName.
+ *
+ * \param[in] residueName Name of the residue being searched.
+ * \returns Value of the entry or -1.
+ */
+ int indexFromResidueName(const char *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.
+ */
+ const char *nameFromResidueIndex(int index) const;
-int
-gmx_residuetype_add(gmx_residuetype_t *rt, const char *newresname, const char *newrestype);
+ private:
+ //! Implementation pointer.
+ class Impl;
-int
-gmx_residuetype_get_alltypes(gmx_residuetype_t *rt,
- const char ***p_typenames,
- int *ntypes);
+ gmx::PrivateImplPointer<Impl> impl_;
+};
-gmx_bool
-gmx_residuetype_is_protein(gmx_residuetype_t *rt, const char *resnm);
-
-gmx_bool
-gmx_residuetype_is_dna(gmx_residuetype_t *rt, const char *resnm);
-
-gmx_bool
-gmx_residuetype_is_rna(gmx_residuetype_t *rt, const char *resnm);
-
-int
-gmx_residuetype_get_size(gmx_residuetype_t *rt);
-
-int
-gmx_residuetype_get_index(gmx_residuetype_t *rt, const char *resnm);
-
-const char *
-gmx_residuetype_get_name(gmx_residuetype_t *rt, int index);
#endif