Change ResidueTypes to class
authorPaul Bauer <paul.bauer.q@gmail.com>
Fri, 11 Jan 2019 15:21:59 +0000 (16:21 +0100)
committerMark Abraham <mark.j.abraham@gmail.com>
Thu, 17 Jan 2019 21:53:22 +0000 (22:53 +0100)
Changes implementation to class with private implementation pointer.

Change-Id: Ia623a23e32ca95a00460c536e2868106b32ad7f9

14 files changed:
src/gromacs/fileio/pdbio.cpp
src/gromacs/gmxana/dlist.cpp
src/gromacs/gmxana/gmx_chi.cpp
src/gromacs/gmxana/gstat.h
src/gromacs/gmxpreprocess/gen_vsite.cpp
src/gromacs/gmxpreprocess/pdb2gmx.cpp
src/gromacs/gmxpreprocess/pdb2top.cpp
src/gromacs/gmxpreprocess/xlate.cpp
src/gromacs/gmxpreprocess/xlate.h
src/gromacs/topology/atomprop.cpp
src/gromacs/topology/atomprop.h
src/gromacs/topology/index.cpp
src/gromacs/topology/residuetypes.cpp
src/gromacs/topology/residuetypes.h

index bc29242bbec9e8dc1e65d1b0d690ad29f6662635..018d9a926a9cc46c2e148ee97abad72d718a3d81 100644 (file)
@@ -317,12 +317,9 @@ void write_pdbfile_indexed(FILE *out, const char *title,
     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) ) )
     {
@@ -350,19 +347,20 @@ void write_pdbfile_indexed(FILE *out, const char *title,
     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");
             }
@@ -462,8 +460,6 @@ void write_pdbfile_indexed(FILE *out, const char *title,
             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[],
index 6661f757f26ba31a482cf54cc0572de4ee27b06e..70ded720444045a5e5fc918e5b4db3795c23ef41 100644 (file)
@@ -3,7 +3,7 @@
  *
  * 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.
@@ -48,7 +48,7 @@
 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;
@@ -220,7 +220,7 @@ t_dlist *mk_dlist(FILE *log,
             {
                 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
index 2dc33d2b1951dbaad6c45decc44662fc25cb7a45..7524dfc27011a3dceb24293eef381f8a5cd5d184 100644 (file)
@@ -3,7 +3,7 @@
  *
  * 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.
@@ -435,7 +435,7 @@ static int reset_em_all(int nlist, t_dlist dlist[], int nf,
     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[],
@@ -486,7 +486,7 @@ static void histogramming(FILE *log, int nbin, gmx_residuetype_t *rt,
     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");
@@ -742,7 +742,7 @@ static void histogramming(FILE *log, int nbin, gmx_residuetype_t *rt,
                     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:
@@ -1361,7 +1361,6 @@ int gmx_chi(int argc, char *argv[])
     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;
@@ -1453,8 +1452,8 @@ int gmx_chi(int argc, char *argv[])
     }
     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)
@@ -1493,7 +1492,7 @@ int gmx_chi(int argc, char *argv[])
     }
 
     /* 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);
@@ -1593,7 +1592,5 @@ int gmx_chi(int argc, char *argv[])
         do_view(oenv, opt2fn("-corr", NFILE, fnm), "-nxy");
     }
 
-    gmx_residuetype_destroy(rt);
-
     return 0;
 }
index 43b80836a0de0716c7b719a6dd97dddd281d8e23..7abb9717bc047dad489eb12f3abc36d4e6574a93 100644 (file)
@@ -3,7 +3,7 @@
  *
  * 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.
@@ -41,7 +41,7 @@
 #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 {
@@ -220,7 +220,7 @@ gmx_bool has_dihedral(int Dih, t_dlist *dl);
 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);
index 49f965d073070e13f3b42de1697a5053ad6c2b19..5b308bc55df01361eaeea74f06bc59dd9ba146fd 100644 (file)
@@ -540,7 +540,7 @@ static void print_bonds(FILE *fp, int o2n[],
 }
 
 static int get_atype(int atom, t_atoms *at, int nrtp, t_restp rtp[],
-                     gmx_residuetype_t *rt)
+                     ResidueType *rt)
 {
     int      type;
     bool     bNterm;
@@ -555,7 +555,7 @@ static int get_atype(int atom, t_atoms *at, int nrtp, t_restp rtp[],
     {
         /* 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;
@@ -578,7 +578,7 @@ static int vsite_nm2type(const char *name, gpp_atomtype *atype)
 }
 
 static real get_amass(int atom, t_atoms *at, int nrtp, t_restp rtp[],
-                      gmx_residuetype_t *rt)
+                      ResidueType *rt)
 {
     real     mass;
     bool     bNterm;
@@ -593,7 +593,7 @@ static real get_amass(int atom, t_atoms *at, int nrtp, t_restp rtp[],
     {
         /* 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;
@@ -1564,7 +1564,6 @@ void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype *atype,
     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.
@@ -1651,7 +1650,7 @@ void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype *atype,
     /* 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 */
@@ -1672,7 +1671,7 @@ void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype *atype,
         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;
@@ -1783,7 +1782,7 @@ void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype *atype,
             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;
@@ -1890,7 +1889,7 @@ void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype *atype,
                     }
                     /* 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)
@@ -1940,10 +1939,10 @@ void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype *atype,
                     /* 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)
                     {
@@ -2054,8 +2053,6 @@ void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype *atype,
 
     }     /* for i < at->nr */
 
-    gmx_residuetype_destroy(rt);
-
     if (debug)
     {
         fprintf(debug, "Before inserting new atoms:\n");
index b7b8118f793ebaebb4d54c2a949b7e10d5852d9c..2932c831f62f0f01a98ecdec0ceaf0e0e75905f9 100644 (file)
@@ -537,7 +537,7 @@ static void write_posres(const char *fn, t_atoms *pdba, real fc)
 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) */
 {
@@ -848,10 +848,10 @@ static int remove_duplicate_atoms(t_atoms *pdba, rvec x[], bool bVerbose)
 }
 
 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);
@@ -889,11 +889,11 @@ checkResidueTypeSanity(t_atoms *            pdba,
         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;
@@ -919,7 +919,7 @@ checkResidueTypeSanity(t_atoms *            pdba,
 }
 
 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;
@@ -949,7 +949,7 @@ static void find_nc_ter(t_atoms *pdba, int r0, int r1, int *r_start, int *r_end,
     /* 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);
@@ -1003,7 +1003,7 @@ static void find_nc_ter(t_atoms *pdba, int r0, int r1, int *r_start, int *r_end,
         /* 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;
@@ -1666,8 +1666,7 @@ int pdb2gmx::run()
     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);
@@ -1687,15 +1686,13 @@ int pdb2gmx::run()
     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);
         }
     }
 
@@ -1724,7 +1721,7 @@ int pdb2gmx::run()
     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)
     {
@@ -2029,7 +2026,7 @@ int pdb2gmx::run()
         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)
             {
@@ -2148,7 +2145,7 @@ int pdb2gmx::run()
            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_);
 
@@ -2196,7 +2193,7 @@ int pdb2gmx::run()
 
         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;
@@ -2355,8 +2352,6 @@ int pdb2gmx::run()
     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;
index b1a28cc15281110135f08533ff790a84ae768f19..ecb7f264a8ce89982bc45c7960fc88a00b2ed360 100644 (file)
@@ -442,7 +442,7 @@ void choose_watermodel(const char *wmsel, const char *ffdir,
 }
 
 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;
@@ -467,7 +467,7 @@ static int name2type(t_atoms *at, int **cgnr,
         {
             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)
             {
@@ -1528,10 +1528,9 @@ void pdb2top(FILE *top_file, const char *posre_fn, const char *molname,
     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,
@@ -1543,7 +1542,7 @@ void pdb2top(FILE *top_file, const char *posre_fn, const char *molname,
                atoms, nssbonds, ssbonds,
                bAllowMissing);
 
-    nmissat = name2type(atoms, &cgnr, restp, rt);
+    nmissat = name2type(atoms, &cgnr, restp, &rt);
     if (nmissat)
     {
         if (bAllowMissing)
@@ -1656,7 +1655,6 @@ void pdb2top(FILE *top_file, const char *posre_fn, const char *molname,
     /* 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);
index 9039f2468ab36b820fdade6975fd093f4662754d..be603334b5c77f4650da1d0acbb981d8b7d30f41 100644 (file)
@@ -139,7 +139,7 @@ static void done_xlatom(int nxlate, t_xlate_atom *xlatom)
 
 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;
@@ -207,15 +207,15 @@ void rename_atoms(const char* xlfile, const char *ffdir,
                 /* 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;
index 78b11b8c7006261505b79412ebec277dfcc70a8d..43bfe6816c8b3a1e22472bcf4f7d624a1fc247c6 100644 (file)
@@ -38,7 +38,7 @@
 #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;
@@ -48,7 +48,7 @@ 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
index 61066878aa0e76f3baf95fd21824f63b9e90a689..3551002478bc5718606ac581739573654a721f42 100644 (file)
@@ -101,7 +101,7 @@ class AtomProperties::Impl
         //! The different atom properties.
         AtomProperty       prop[epropNR];
         //! The residue types.
-        gmx_residuetype_t *restype = nullptr;
+        ResidueType        restype;
 };
 
 /*! \brief
@@ -149,13 +149,13 @@ static int compareToDatabase(const std::string &search, const std::string &datab
  * \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;
@@ -219,7 +219,7 @@ static int findPropertyIndex(AtomProperty *ap, gmx_residuetype_t *restype,
  * \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)
 {
@@ -262,7 +262,7 @@ static void addProperty(AtomProperty *ap, gmx_residuetype_t *restype,
  * \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];
 
@@ -295,7 +295,7 @@ static void readProperty(AtomProperty *ap, gmx_residuetype_t *restype, double fa
  * \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 };
@@ -325,12 +325,10 @@ static bool setProperties(AtomProperty *ap, gmx_residuetype_t *restype, int epro
 AtomProperties::AtomProperties()
     : impl_(new Impl)
 {
-    gmx_residuetype_init(&impl_->restype);
 }
 
 AtomProperties::~AtomProperties()
 {
-    gmx_residuetype_destroy(impl_->restype);
 }
 
 AtomProperty *AtomProperties::prop(int eprop)
@@ -338,9 +336,9 @@ 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.
@@ -391,7 +389,7 @@ bool AtomProperties::setAtomProperty(int                eprop,
     {
         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)
index 5eba35b3d73f6bb3281b558e11fb70d7b0cb5584..32cd835a39d79ae3544f235dcebca76e332c7c3d 100644 (file)
@@ -49,7 +49,7 @@ enum {
 };
 
 struct AtomProperty;
-struct gmx_residuetype_t;
+class ResidueType;
 /*! \brief
  * Holds all the atom property information loaded.
  */
@@ -107,7 +107,7 @@ class AtomProperties
          */
         AtomProperty *prop(int eprop);
         //! Get handle to residuetype library.
-        gmx_residuetype_t *restype();
+        ResidueType *restype();
 
     private:
         //! Implementation pointer.
index cffaef285281968698849310ec44cb7821747838..6d12641b26fc47621307cfeae2edfd50c188f46e 100644 (file)
@@ -560,7 +560,6 @@ static void analyse_prot(gmx::ArrayRef<const std::string> restype, const t_atoms
 
 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;
@@ -579,8 +578,7 @@ void analyse(const t_atoms *atoms, t_blocka *gb, char ***gn, gmx_bool bASK, gmx_
     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;
@@ -590,14 +588,14 @@ void analyse(const t_atoms *atoms, t_blocka *gb, char ***gn, gmx_bool bASK, gmx_
 
         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
@@ -704,7 +702,6 @@ void analyse(const t_atoms *atoms, t_blocka *gb, char ***gn, gmx_bool bASK, gmx_
         gb->nr++;
         gb->index[gb->nr] = gb->nra;
     }
-    gmx_residuetype_destroy(rt);
 }
 
 
index ee8156cba6ba0422d146d33cf7228143cda53c8d..ddd8087b492dc16f7267137b7f9fa683b0447380 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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))
     {
@@ -78,181 +86,93 @@ gmx_residuetype_init(gmx_residuetype_t **prt)
         {
             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
     {
index 355fb0b999a1c1c07cce8b2c493c27b29ef5206c..3cd9ed59c69e5316591c07ef9b3d76585a2ff890 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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