Make AtomProperties class with Impl
authorPaul Bauer <paul.bauer.q@gmail.com>
Thu, 10 Jan 2019 12:33:34 +0000 (13:33 +0100)
committerMark Abraham <mark.j.abraham@gmail.com>
Fri, 11 Jan 2019 16:46:41 +0000 (17:46 +0100)
Moved the atomprop structure to a class with the underlying arrays
implementation detail. Changed names to be more descriptive. Changed
functions to be class methods where appropriate.

Change-Id: Iffee0635008567735798d0ad5ac560d0cb1e582a

18 files changed:
src/gromacs/fileio/pdbio.cpp
src/gromacs/fileio/pdbio.h
src/gromacs/gmxana/gmx_editconf.cpp
src/gromacs/gmxpreprocess/insert-molecules.cpp
src/gromacs/gmxpreprocess/makeexclusiondistances.cpp
src/gromacs/gmxpreprocess/makeexclusiondistances.h
src/gromacs/gmxpreprocess/pdb2gmx.cpp
src/gromacs/gmxpreprocess/solvate.cpp
src/gromacs/tools/check.cpp
src/gromacs/topology/CMakeLists.txt
src/gromacs/topology/atomprop.cpp
src/gromacs/topology/atomprop.h
src/gromacs/topology/atoms.cpp
src/gromacs/trajectoryanalysis/modules/freevolume.cpp
src/gromacs/trajectoryanalysis/modules/sasa.cpp
src/programs/view/Xstuff.h
src/programs/view/manager.cpp
src/programs/view/manager.h

index 26dfd28c149fbbd6e03b99943f26cd922ea82e31..bc29242bbec9e8dc1e65d1b0d690ad29f6662635 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.
@@ -77,7 +77,6 @@ static const char *pdbtp[epdbNR] = {
     "CONECT"
 };
 
-
 #define REMARK_SIM_BOX "REMARK    THIS IS A SIMULATION BOX"
 
 static void xlate_atomname_pdb2gmx(char *name)
@@ -561,11 +560,11 @@ static void read_anisou(char line[], int natom, t_atoms *atoms)
     }
 }
 
-void get_pdb_atomnumber(const t_atoms *atoms, gmx_atomprop_t aps)
+void get_pdb_atomnumber(const t_atoms *atoms, AtomProperties *aps)
 {
     int    i, atomnumber, len;
     size_t k;
-    char   anm[6], anm_copy[6], *ptr;
+    char   anm[6], anm_copy[6];
     char   nc = '\0';
     real   eval;
 
@@ -582,7 +581,7 @@ void get_pdb_atomnumber(const t_atoms *atoms, gmx_atomprop_t aps)
         if ((anm[0] != ' ') && ((len <= 2) || !std::isdigit(anm[2])))
         {
             anm_copy[2] = nc;
-            if (gmx_atomprop_query(aps, epropElement, "???", anm_copy, &eval))
+            if (aps->setAtomProperty(epropElement, "???", anm_copy, &eval))
             {
                 atomnumber    = gmx::roundToInt(eval);
                 atomNumberSet = true;
@@ -590,7 +589,7 @@ void get_pdb_atomnumber(const t_atoms *atoms, gmx_atomprop_t aps)
             else
             {
                 anm_copy[1] = nc;
-                if (gmx_atomprop_query(aps, epropElement, "???", anm_copy, &eval))
+                if (aps->setAtomProperty(epropElement, "???", anm_copy, &eval))
                 {
                     atomnumber    = gmx::roundToInt(eval);
                     atomNumberSet = true;
@@ -606,27 +605,25 @@ void get_pdb_atomnumber(const t_atoms *atoms, gmx_atomprop_t aps)
             }
             anm_copy[0] = anm[k];
             anm_copy[1] = nc;
-            if (gmx_atomprop_query(aps, epropElement, "???", anm_copy, &eval))
+            if (aps->setAtomProperty(epropElement, "???", anm_copy, &eval))
             {
                 atomnumber    = gmx::roundToInt(eval);
                 atomNumberSet = true;
             }
         }
+        std::string buf;
         if (atomNumberSet)
         {
             atoms->atom[i].atomnumber = atomnumber;
-            ptr = gmx_atomprop_element(aps, atomnumber);
+            buf = aps->elementFromAtomNumber(atomnumber);
             if (debug)
             {
                 fprintf(debug, "Atomnumber for atom '%s' is %d\n",
                         anm, atomnumber);
             }
         }
-        else
-        {
-            ptr = nullptr;
-        }
-        std::strncpy(atoms->atom[i].elem, ptr == nullptr ? "" : ptr, 4);
+        buf.resize(3);
+        std::strncpy(atoms->atom[i].elem, buf.c_str(), 4);
     }
 }
 
index f3ecc7eec56013bb0af207c7c44ff19ae14895cd..46a3ca40d7d8f21389b996311d1aa3abc23ca3cd 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.
@@ -45,7 +45,7 @@
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/real.h"
 
-struct gmx_atomprop;
+class AtomProperties;
 struct t_atoms;
 struct t_symtab;
 struct t_topology;
@@ -111,7 +111,7 @@ void write_pdbfile(FILE *out, const char *title, const t_atoms *atoms,
  * which may be useful for visualization purposes.
  */
 
-void get_pdb_atomnumber(const t_atoms *atoms, struct gmx_atomprop *aps);
+void get_pdb_atomnumber(const t_atoms *atoms, AtomProperties *aps);
 /* Routine to extract atomic numbers from the atom names */
 
 int read_pdbfile(FILE *in, char *title, int *model_nr,
index 925cbe4ecec46db9aff7d438cb43aa3d74dabb87..4aecb9e3c3f48fc64a997537c00bbb05b74ff271 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.
@@ -66,8 +66,7 @@
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/strdb.h"
 
-
-static real calc_mass(t_atoms *atoms, gmx_bool bGetMass, gmx_atomprop_t aps)
+static real calc_mass(t_atoms *atoms, gmx_bool bGetMass, AtomProperties *aps)
 {
     real tmass;
     int  i;
@@ -77,9 +76,9 @@ static real calc_mass(t_atoms *atoms, gmx_bool bGetMass, gmx_atomprop_t aps)
     {
         if (bGetMass)
         {
-            gmx_atomprop_query(aps, epropMass,
-                               *atoms->resinfo[atoms->atom[i].resind].name,
-                               *atoms->atomname[i], &(atoms->atom[i].m));
+            aps->setAtomProperty(epropMass,
+                                 *atoms->resinfo[atoms->atom[i].resind].name,
+                                 *atoms->atomname[i], &(atoms->atom[i].m));
         }
         tmass += atoms->atom[i].m;
     }
@@ -716,7 +715,6 @@ int gmx_editconf(int argc, char *argv[])
     gmx_bool          bIndex, bSetSize, bSetAng, bDist, bSetCenter, bAlign;
     gmx_bool          bHaveV, bScale, bRho, bTranslate, bRotate, bCalcGeom, bCalcDiam;
     real              diam = 0, mass = 0, d, vdw;
-    gmx_atomprop_t    aps;
     gmx_conect        conect;
     gmx_output_env_t *oenv;
     t_filenm          fnm[] =
@@ -776,7 +774,7 @@ int gmx_editconf(int argc, char *argv[])
     outftp = fn2ftp(outfile);
     inftp  = fn2ftp(infile);
 
-    aps = gmx_atomprop_init();
+    AtomProperties aps;
 
     if (bMead && bGrasp)
     {
@@ -807,14 +805,14 @@ int gmx_editconf(int argc, char *argv[])
 
     if (fn2ftp(infile) == efPDB)
     {
-        get_pdb_atomnumber(&atoms, aps);
+        get_pdb_atomnumber(&atoms, &aps);
     }
     printf("Read %d atoms\n", atoms.nr);
 
     /* Get the element numbers if available in a pdb file */
     if (fn2ftp(infile) == efPDB)
     {
-        get_pdb_atomnumber(&atoms, aps);
+        get_pdb_atomnumber(&atoms, &aps);
     }
 
     if (ePBC != epbcNONE)
@@ -842,9 +840,9 @@ int gmx_editconf(int argc, char *argv[])
             /* Determine the Van der Waals radius from the force field */
             if (bReadVDW)
             {
-                if (!gmx_atomprop_query(aps, epropVDW,
-                                        *top->atoms.resinfo[top->atoms.atom[i].resind].name,
-                                        *top->atoms.atomname[i], &vdw))
+                if (!aps.setAtomProperty(epropVDW,
+                                         *top->atoms.resinfo[top->atoms.atom[i].resind].name,
+                                         *top->atoms.atomname[i], &vdw))
                 {
                     vdw = rvdw;
                 }
@@ -955,7 +953,7 @@ int gmx_editconf(int argc, char *argv[])
 
     if (bRho || bOrient || bAlign)
     {
-        mass = calc_mass(&atoms, !fn2bTPX(infile), aps);
+        mass = calc_mass(&atoms, !fn2bTPX(infile), &aps);
     }
 
     if (bOrient)
@@ -1341,8 +1339,6 @@ int gmx_editconf(int argc, char *argv[])
             write_sto_conf(outfile, *top_tmp->name, &atoms, x, bHaveV ? v : nullptr, ePBC, box);
         }
     }
-    gmx_atomprop_destroy(aps);
-
     do_view(oenv, outfile, nullptr);
 
     return 0;
index 9b477f91ef22018be891c24dafa90ff2b9a5dfbb..268b56e125bfea63d613b9513a5c24e3640f862e 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.
@@ -173,12 +173,11 @@ static void insert_mols(int nmol_insrt, int ntry, int seed,
                         RotationType enum_rot)
 {
     fprintf(stderr, "Initialising inter-atomic distances...\n");
-    gmx_atomprop_t          aps = gmx_atomprop_init();
+    AtomProperties          aps;
     std::vector<real>       exclusionDistances(
-            makeExclusionDistances(atoms, aps, defaultDistance, scaleFactor));
+            makeExclusionDistances(atoms, &aps, defaultDistance, scaleFactor));
     const std::vector<real> exclusionDistances_insrt(
-            makeExclusionDistances(&atoms_insrt, aps, defaultDistance, scaleFactor));
-    gmx_atomprop_destroy(aps);
+            makeExclusionDistances(&atoms_insrt, &aps, defaultDistance, scaleFactor));
 
     const real       maxInsertRadius
         = *std::max_element(exclusionDistances_insrt.begin(),
index 9392081204531bf8d295ae0578eef2d76b159e58..31dcb187f59e599da18a8f0c2dfe5b014f6cbb5d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 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.
@@ -42,7 +42,7 @@
 #include "gromacs/topology/atoms.h"
 
 std::vector<real>
-makeExclusionDistances(const t_atoms *a, gmx_atomprop_t aps,
+makeExclusionDistances(const t_atoms *a, AtomProperties *aps,
                        real defaultDistance, real scaleFactor)
 {
     std::vector<real> exclusionDistances;
@@ -53,9 +53,9 @@ makeExclusionDistances(const t_atoms *a, gmx_atomprop_t aps,
         for (int i = 0; i < a->nr; ++i)
         {
             real value;
-            if (!gmx_atomprop_query(aps, epropVDW,
-                                    *(a->resinfo[a->atom[i].resind].name),
-                                    *(a->atomname[i]), &value))
+            if (!aps->setAtomProperty(epropVDW,
+                                      *(a->resinfo[a->atom[i].resind].name),
+                                      *(a->atomname[i]), &value))
             {
                 value = defaultDistance;
             }
index 8d0a3739310c5b5e2a27d721cf2e43f61f777192..fd89e741f146163a581b29b53ed2a8cbb412665d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014,2015,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 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.
@@ -39,7 +39,7 @@
 
 #include "gromacs/utility/real.h"
 
-struct gmx_atomprop;
+class AtomProperties;
 struct t_atoms;
 
 /*! \brief Allocate and fill an array of inter-atomic half distances
@@ -49,7 +49,7 @@ struct t_atoms;
  * insert-molecules for deciding whether molecules clash. The return
  * pointer should be freed by the caller. */
 std::vector<real>
-makeExclusionDistances(const t_atoms *a, gmx_atomprop *aps,
+makeExclusionDistances(const t_atoms *a, AtomProperties *aps,
                        real defaultDistance, real scaleFactor);
 
 #endif
index b5006f1fad59192e902b0fbeaeca7425d8543e81..3173e36291ac56619422c7d108892c674ab75c14 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.
@@ -536,7 +536,7 @@ static int read_pdball(const char *inf, bool bOutput, const char *outf, char **t
                        t_atoms *atoms, rvec **x,
                        int *ePBC, matrix box, bool bRemoveH,
                        t_symtab *symtab, gmx_residuetype_t *rt, const char *watres,
-                       gmx_atomprop_t aps, bool bVerbose)
+                       AtomProperties *aps, bool bVerbose)
 /* Read a pdb file. (containing proteins) */
 {
     int natom, new_natom, i;
@@ -1722,14 +1722,14 @@ int pdb2gmx::run()
         watres = "HOH";
     }
 
-    gmx_atomprop_t aps   = gmx_atomprop_init();
+    AtomProperties aps;
     char          *title;
     int            ePBC;
     t_atoms        pdba_all;
     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)
     {
index 59764a9f70c99de9848d6b57063d6fe6fd3ef865..5e077e116489a0aaa86c625d0df777f8dbfb3027 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.
@@ -642,7 +642,7 @@ static void add_solv(const char *filename,
                      const gmx::TopologyInformation &topInfo,
                      t_atoms *atoms,
                      std::vector<RVec> *x, std::vector<RVec> *v,
-                     matrix box, gmx_atomprop_t aps,
+                     matrix box, AtomProperties *aps,
                      real defaultDistance, real scaleFactor,
                      real rshell, int max_sol)
 {
@@ -743,8 +743,12 @@ static void add_solv(const char *filename,
     }
 }
 
-static void update_top(t_atoms *atoms, int firstSolventResidueIndex, matrix box, int NFILE, t_filenm fnm[],
-                       gmx_atomprop_t aps)
+static void update_top(t_atoms        *atoms,
+                       int             firstSolventResidueIndex,
+                       matrix          box,
+                       int             NFILE,
+                       t_filenm        fnm[],
+                       AtomProperties *aps)
 {
     FILE        *fpin, *fpout;
     char         buf[STRLEN*2], buf2[STRLEN], *temp;
@@ -760,9 +764,9 @@ static void update_top(t_atoms *atoms, int firstSolventResidueIndex, matrix box,
     mtot = 0;
     for (i = 0; (i < atoms->nr); i++)
     {
-        gmx_atomprop_query(aps, epropMass,
-                           *atoms->resinfo[atoms->atom[i].resind].name,
-                           *atoms->atomname[i], &mm);
+        aps->setAtomProperty(epropMass,
+                             *atoms->resinfo[atoms->atom[i].resind].name,
+                             *atoms->atomname[i], &mm);
         mtot += mm;
     }
 
@@ -920,7 +924,6 @@ int gmx_solvate(int argc, char *argv[])
     /* parameter data */
     gmx_bool       bProt, bBox;
     const char    *conf_prot, *confout;
-    gmx_atomprop_t aps;
 
     t_filenm       fnm[] = {
         { efSTX, "-cp", "protein", ffOPTRD },
@@ -968,7 +971,7 @@ int gmx_solvate(int argc, char *argv[])
                   "a box size (-box) must be specified");
     }
 
-    aps = gmx_atomprop_init();
+    AtomProperties           aps;
 
     gmx::TopologyInformation topInfo;
     std::vector<RVec>        x, v;
@@ -1017,7 +1020,7 @@ int gmx_solvate(int argc, char *argv[])
     }
 
     add_solv(solventFileName, topInfo, atoms.get(), &x, &v, box,
-             aps, defaultDistance, scaleFactor, r_shell, max_sol);
+             &aps, defaultDistance, scaleFactor, r_shell, max_sol);
 
     /* write new configuration 1 to file confout */
     confout = ftp2fn(efSTO, NFILE, fnm);
@@ -1029,9 +1032,7 @@ int gmx_solvate(int argc, char *argv[])
     /* print size of generated configuration */
     fprintf(stderr, "\nOutput configuration contains %d atoms in %d residues\n",
             atoms->nr, atoms->nres);
-    update_top(atoms.get(), firstSolventResidueIndex, box, NFILE, fnm, aps);
-
-    gmx_atomprop_destroy(aps);
+    update_top(atoms.get(), firstSolventResidueIndex, box, NFILE, fnm, &aps);
     output_env_done(oenv);
 
     return 0;
index 86adadd8d4ff3c3374d360b47f37d0a027bbd425..b4a410854b828d102897a73cd20b4f369e52c08c 100644 (file)
@@ -441,7 +441,6 @@ static void chk_tps(const char *fn, real vdw_fac, real bon_lo, real bon_hi)
     gmx_bool       bV, bX, bB, bFirst, bOut;
     real           r2, ekin, temp1, temp2, dist2, vdwfac2, bonlo2, bonhi2;
     real          *atom_vdw;
-    gmx_atomprop_t aps;
 
     fprintf(stderr, "Checking coordinate file %s\n", fn);
     read_tps_conf(fn, &top, &ePBC, &x, &v, box, TRUE);
@@ -506,12 +505,12 @@ static void chk_tps(const char *fn, real vdw_fac, real bon_lo, real bon_hi)
                 "relative to sum of Van der Waals distance:\n",
                 vdw_fac, bon_lo, bon_hi);
         snew(atom_vdw, natom);
-        aps = gmx_atomprop_init();
+        AtomProperties aps;
         for (i = 0; (i < natom); i++)
         {
-            gmx_atomprop_query(aps, epropVDW,
-                               *(atoms->resinfo[atoms->atom[i].resind].name),
-                               *(atoms->atomname[i]), &(atom_vdw[i]));
+            aps.setAtomProperty(epropVDW,
+                                *(atoms->resinfo[atoms->atom[i].resind].name),
+                                *(atoms->atomname[i]), &(atom_vdw[i]));
             if (debug)
             {
                 fprintf(debug, "%5d %4s %4s %7g\n", i+1,
@@ -520,7 +519,6 @@ static void chk_tps(const char *fn, real vdw_fac, real bon_lo, real bon_hi)
                         atom_vdw[i]);
             }
         }
-        gmx_atomprop_destroy(aps);
         if (bB)
         {
             set_pbc(&pbc, ePBC, box);
index 14ac3201f0004ef315b891081615d95e142428ed..a495c06905a58cecd7ca3db5319c20b71fda0ccd 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2014,2015,2018, by the GROMACS development team, led by
+# Copyright (c) 2014,2015,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.
index a2512322daf012f952fa9d45fa8fceaddd711177..0dfdc29b7477636dfdca7bbc7b46a183bb74b941 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,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,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.
@@ -43,6 +43,7 @@
 #include <cstdio>
 #include <cstring>
 
+#include "gromacs/compat/make_unique.h"
 #include "gromacs/math/functions.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/topology/residuetypes.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/strdb.h"
 
-typedef struct {
-    gmx_bool    bSet;
-    int         nprop, maxprop;
-    char       *db;
-    double      def;
-    char      **atomnm;
-    char      **resnm;
-    gmx_bool   *bAvail;
-    real       *value;
-} aprop_t;
-
-typedef struct gmx_atomprop {
-    gmx_bool           bWarned, bWarnVDW;
-    aprop_t            prop[epropNR];
-    gmx_residuetype_t *restype;
-} gmx_atomprop;
-
-
-
 /* NOTFOUND should be smallest, others larger in increasing priority */
 enum {
     NOTFOUND = -4, WILDCARD, WILDPROT, PROTEIN
 };
 
-/* return number of matching characters,
-   or NOTFOUND if not at least all characters in char *database match */
-static int dbcmp_len(const char *search, const char *database)
+//! Conglomeration of atom property entries.
+struct AtomProperty {
+    //! Has property been set.
+    bool   isSet = false;
+    //! Number of properties.
+    int    nprop = 0;
+    //! Max number of properties.
+    int    maxprop = 0;
+    //! Database the property is coming from.
+    char  *db = nullptr;
+    //! Default value for property.
+    double def = 0.0;
+    //! Array of names for atoms.
+    char **atomName = nullptr;
+    //! Array of names for residues.
+    char **residueName = nullptr;
+    //! Array of flags if property is available.
+    bool  *isAvailable = nullptr;
+    //! Array of values for property.
+    real  *value = nullptr;
+};
+
+//! Implementation detail type for Atomproperties.
+class AtomProperties::Impl
 {
-    int i;
+    public:
+        //! Should user be warned about error.
+        bool               bWarned = false;
+        //! Should user be warned about vdW not found.
+        bool               bWarnVDW = false;
+        //! The different atom properties.
+        AtomProperty       prop[epropNR];
+        //! The residue types.
+        gmx_residuetype_t *restype = nullptr;
+};
 
-    i = 0;
+/*! \brief
+ * Find number of matching characters in entry.
+ *
+ * If not all characters are matching, return NOTFOUND.
+ * If the length of the database entry is different from the search,
+ * also return NOTFOUND.
+ *
+ * \param[in] search Entry to compare to database.
+ * \param[in] database Name of the database entry to compare to.
+ * \returns Number of matching characters or NOTFOUND.
+ */
+static int findNumberOfMatches(const char *search, const char *database)
+{
+    int i = 0;
     while (search[i] && database[i] && (search[i] == database[i]) )
     {
         i++;
@@ -97,35 +122,42 @@ static int dbcmp_len(const char *search, const char *database)
     return i;
 }
 
-static int get_prop_index(aprop_t *ap, gmx_residuetype_t *restype,
-                          char *resnm, char *atomnm,
-                          gmx_bool *bExact)
+/*! \brief
+ * Finds the index for the property being searched.
+ *
+ * \param[in] ap Property to search for.
+ * \param[in] restype Residuetypes in database.
+ * \param[in] residueName The name of the residue to look for.
+ * \param[in] atomName The name of the atom to look for.
+ * \param[in] bExact Do we have the correct match.
+ * \returns The index for the property.
+ */
+static int findPropertyIndex(AtomProperty *ap, gmx_residuetype_t *restype,
+                             char *residueName, char *atomName,
+                             gmx_bool *bExact)
 {
-    int      i, j = NOTFOUND;
-    long int alen, rlen;
-    long int malen, mrlen;
-    gmx_bool bProtein, bProtWild;
-
-    bProtein  = gmx_residuetype_is_protein(restype, resnm);
-    bProtWild = (strcmp(resnm, "AAA") == 0);
-    malen     = NOTFOUND;
-    mrlen     = NOTFOUND;
-    for (i = 0; (i < ap->nprop); i++)
+    int      j = NOTFOUND;
+
+    bool     bProtein  = gmx_residuetype_is_protein(restype, residueName);
+    bool     bProtWild = (strcmp(residueName, "AAA") == 0);
+    int      malen     = NOTFOUND;
+    int      mrlen     = NOTFOUND;
+    for (int i = 0; (i < ap->nprop); i++)
     {
-        rlen = dbcmp_len(resnm, ap->resnm[i]);
+        int rlen = findNumberOfMatches(residueName, ap->residueName[i]);
         if (rlen == NOTFOUND)
         {
-            if ( (strcmp(ap->resnm[i], "*") == 0) ||
-                 (strcmp(ap->resnm[i], "???") == 0) )
+            if ( (strcmp(ap->residueName[i], "*") == 0) ||
+                 (strcmp(ap->residueName[i], "???") == 0) )
             {
                 rlen = WILDCARD;
             }
-            else if (strcmp(ap->resnm[i], "AAA") == 0)
+            else if (strcmp(ap->residueName[i], "AAA") == 0)
             {
                 rlen = WILDPROT;
             }
         }
-        alen = dbcmp_len(atomnm, ap->atomnm[i]);
+        int alen = findNumberOfMatches(atomName, ap->atomName[i]);
         if ( (alen > NOTFOUND) && (rlen > NOTFOUND))
         {
             if ( ( (alen > malen) && (rlen >= mrlen)) ||
@@ -138,98 +170,108 @@ static int get_prop_index(aprop_t *ap, gmx_residuetype_t *restype,
         }
     }
 
-    *bExact = ((malen == static_cast<long int>(strlen(atomnm))) &&
-               ((mrlen == static_cast<long int>(strlen(resnm))) ||
+    *bExact = ((malen == static_cast<long int>(strlen(atomName))) &&
+               ((mrlen == static_cast<long int>(strlen(residueName))) ||
                 ((mrlen == WILDPROT) && bProtWild) ||
                 ((mrlen == WILDCARD) && !bProtein && !bProtWild)));
 
     if (debug)
     {
-        fprintf(debug, "searching residue: %4s atom: %4s\n", resnm, atomnm);
+        fprintf(debug, "searching residue: %4s atom: %4s\n", residueName, atomName);
         if (j == NOTFOUND)
         {
             fprintf(debug, " not successful\n");
         }
         else
         {
-            fprintf(debug, " match: %4s %4s\n", ap->resnm[j], ap->atomnm[j]);
+            fprintf(debug, " match: %4s %4s\n", ap->residueName[j], ap->atomName[j]);
         }
     }
     return j;
 }
 
-static void add_prop(aprop_t *ap, gmx_residuetype_t *restype,
-                     char *resnm, char *atomnm,
-                     real p, int line)
+/*! \brief
+ * Add new property to list.
+ *
+ * \param[in] ap Atomproperty to add.
+ * \param[in] restype Residue type database to use.
+ * \param[in] residueName Name of the residue.
+ * \param[in] atomName Name of the atom.
+ * \param[in] propValue Value of property.
+ * \param[in] line Where to add property.
+ */
+static void addProperty(AtomProperty *ap, gmx_residuetype_t *restype,
+                        char *residueName, char *atomName,
+                        real propValue, int line)
 {
-    int      i, j;
-    gmx_bool bExact;
-
-    j = get_prop_index(ap, restype, resnm, atomnm, &bExact);
+    bool bExact;
+    int  j = findPropertyIndex(ap, restype, residueName, atomName, &bExact);
 
     if (!bExact)
     {
         if (ap->nprop >= ap->maxprop)
         {
             ap->maxprop += 10;
-            srenew(ap->resnm, ap->maxprop);
-            srenew(ap->atomnm, ap->maxprop);
+            srenew(ap->residueName, ap->maxprop);
+            srenew(ap->atomName, ap->maxprop);
             srenew(ap->value, ap->maxprop);
-            srenew(ap->bAvail, ap->maxprop);
-            for (i = ap->nprop; (i < ap->maxprop); i++)
+            srenew(ap->isAvailable, ap->maxprop);
+            for (int i = ap->nprop; (i < ap->maxprop); i++)
             {
-                ap->atomnm[i] = nullptr;
-                ap->resnm[i]  = nullptr;
-                ap->value[i]  = 0;
-                ap->bAvail[i] = FALSE;
+                ap->atomName[i]     = nullptr;
+                ap->residueName[i]  = nullptr;
+                ap->value[i]        = 0;
+                ap->isAvailable[i]  = FALSE;
             }
         }
-        ap->atomnm[ap->nprop] = gmx_strdup(atomnm);
-        ap->resnm[ap->nprop]  = gmx_strdup(resnm);
-        j                     = ap->nprop;
+        ap->atomName[ap->nprop]     = gmx_strdup(atomName);
+        ap->residueName[ap->nprop]  = gmx_strdup(residueName);
+        j                           = ap->nprop;
         ap->nprop++;
     }
-    if (ap->bAvail[j])
+    if (ap->isAvailable[j])
     {
-        if (ap->value[j] == p)
+        if (ap->value[j] == propValue)
         {
             fprintf(stderr, "Warning double identical entries for %s %s %g on line %d in file %s\n",
-                    resnm, atomnm, p, line, ap->db);
+                    residueName, atomName, propValue, line, ap->db);
         }
         else
         {
             fprintf(stderr, "Warning double different entries %s %s %g and %g on line %d in file %s\n"
                     "Using last entry (%g)\n",
-                    resnm, atomnm, p, ap->value[j], line, ap->db, p);
-            ap->value[j] = p;
+                    residueName, atomName, propValue, ap->value[j], line, ap->db, propValue);
+            ap->value[j] = propValue;
         }
     }
     else
     {
-        ap->bAvail[j] = TRUE;
-        ap->value[j]  = p;
+        ap->isAvailable[j] = TRUE;
+        ap->value[j]       = propValue;
     }
 }
 
-static void read_prop(gmx_atomprop_t aps, int eprop, double factor)
+/*! \brief
+ * Read property value into structure.
+ *
+ * \param[in] ap Atomproperty to be read in.
+ * \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)
 {
-    gmx_atomprop *ap2 = static_cast<gmx_atomprop*>(aps);
     char          line[STRLEN], resnm[32], atomnm[32];
-    double        pp;
-    int           line_no;
-    aprop_t      *ap;
-
-    ap = &ap2->prop[eprop];
 
-    gmx::FilePtr fp = gmx::openLibraryFile(ap->db);
-    line_no = 0;
+    gmx::FilePtr  fp      = gmx::openLibraryFile(ap->db);
+    int           line_no = 0;
     while (get_a_line(fp.get(), line, STRLEN))
     {
         line_no++;
+        double pp;
         if (sscanf(line, "%31s %31s %20lf", resnm, atomnm, &pp) == 3)
         {
             pp *= factor;
-            add_prop(ap, aps->restype, resnm, atomnm, pp, line_no);
+            addProperty(ap, restype, resnm, atomnm, pp, line_no);
         }
         else
         {
@@ -237,98 +279,101 @@ static void read_prop(gmx_atomprop_t aps, int eprop, double factor)
                     ap->db, line_no);
         }
     }
-    ap->bSet = TRUE;
+    ap->isSet = TRUE;
 }
 
-static void set_prop(gmx_atomprop_t aps, int eprop)
+/*! \brief
+ * Set value for properties.
+ *
+ * \param[in] ap Atomproperty to set.
+ * \param[in] restype Library of residue types.
+ * \param[in] eprop Which property to set.
+ * \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)
 {
-    gmx_atomprop *ap2           = static_cast<gmx_atomprop*>(aps);
-    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 };
-    double        def[epropNR]  = { 12.011, 0.14, 0.0, 2.2, -1 };
-    aprop_t      *ap;
-
-    ap = &ap2->prop[eprop];
-    if (!ap->bSet)
+    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 };
+    double            def[epropNR]  = { 12.011, 0.14, 0.0, 2.2, -1 };
+
+    bool              printWarning = false;
+    if (!ap->isSet)
     {
         ap->db  = gmx_strdup(fns[eprop]);
         ap->def = def[eprop];
-        read_prop(aps, eprop, fac[eprop]);
+        readProperty(ap, restype, fac[eprop]);
 
         if (debug)
         {
             fprintf(debug, "Entries in %s: %d\n", ap->db, ap->nprop);
         }
 
-        if ( ( (!aps->bWarned) && (eprop == epropMass) ) || (eprop == epropVDW))
+        if ( (!haveBeenWarned && (eprop == epropMass) ) || (eprop == epropVDW))
         {
-            printf("\n"
-                   "WARNING: Masses and atomic (Van der Waals) radii will be guessed\n"
-                   "         based on residue and atom names, since they could not be\n"
-                   "         definitively assigned from the information in your input\n"
-                   "         files. These guessed numbers might deviate from the mass\n"
-                   "         and radius of the atom type. Please check the output\n"
-                   "         files if necessary.\n\n");
-            aps->bWarned = TRUE;
+            printWarning = true;
         }
+
     }
+    return printWarning;
 }
 
-gmx_atomprop_t gmx_atomprop_init()
+AtomProperties::AtomProperties()
+    : impl_(new Impl)
 {
-    gmx_atomprop *aps;
-
-    snew(aps, 1);
-
-    gmx_residuetype_init(&aps->restype);
-    aps->bWarned  = FALSE;
-    aps->bWarnVDW = FALSE;
-
-    return static_cast<gmx_atomprop_t>(aps);
+    gmx_residuetype_init(&impl_->restype);
 }
 
-static void destroy_prop(aprop_t *ap)
+static void destroy_prop(AtomProperty *ap)
 {
-    int i;
-
-    if (ap->bSet)
+    if (ap->isSet)
     {
         sfree(ap->db);
 
-        for (i = 0; i < ap->nprop; i++)
+        for (int i = 0; i < ap->nprop; i++)
         {
-            sfree(ap->atomnm[i]);
-            sfree(ap->resnm[i]);
+            sfree(ap->atomName[i]);
+            sfree(ap->residueName[i]);
         }
-        sfree(ap->atomnm);
-        sfree(ap->resnm);
-        sfree(ap->bAvail);
+        sfree(ap->atomName);
+        sfree(ap->residueName);
+        sfree(ap->isAvailable);
         sfree(ap->value);
     }
 }
 
-void gmx_atomprop_destroy(gmx_atomprop_t aps)
+AtomProperties::~AtomProperties()
 {
-    gmx_atomprop *ap = static_cast<gmx_atomprop*>(aps);
-    int           p;
-
-    if (aps == nullptr)
+    for (int p = 0; p < epropNR; p++)
     {
-        printf("\nWARNING: gmx_atomprop_destroy called with a NULL pointer\n\n");
-        return;
+        destroy_prop(&impl_->prop[p]);
     }
+    gmx_residuetype_destroy(impl_->restype);
+}
 
-    for (p = 0; p < epropNR; p++)
-    {
-        destroy_prop(&ap->prop[p]);
-    }
+AtomProperty *AtomProperties::prop(int eprop)
+{
+    return &impl_->prop[eprop];
+}
 
-    gmx_residuetype_destroy(ap->restype);
+gmx_residuetype_t *AtomProperties::restype()
+{
+    return impl_->restype;
+}
 
-    sfree(ap);
+//! Print warning about vdW to terminal.
+static void printWarning()
+{
+    printf("\n"
+           "WARNING: Masses and atomic (Van der Waals) radii will be guessed\n"
+           "         based on residue and atom names, since they could not be\n"
+           "         definitively assigned from the information in your input\n"
+           "         files. These guessed numbers might deviate from the mass\n"
+           "         and radius of the atom type. Please check the output\n"
+           "         files if necessary.\n\n");
 }
 
-static void vdw_warning(FILE *fp)
+static void printvdwWarning(FILE *fp)
 {
     if (nullptr != fp)
     {
@@ -340,18 +385,22 @@ static void vdw_warning(FILE *fp)
     }
 }
 
-gmx_bool gmx_atomprop_query(gmx_atomprop_t aps,
-                            int eprop, const char *resnm, const char *atomnm,
-                            real *value)
+bool AtomProperties::setAtomProperty(int         eprop,
+                                     const char *residueName,
+                                     const char *atomName,
+                                     real       *value)
 {
-    gmx_atomprop *ap = static_cast<gmx_atomprop*>(aps);
-    int           j;
+    int  j;
 #define MAXQ 32
-    char          atomname[MAXQ], resname[MAXQ];
-    gmx_bool      bExact;
+    char atomname[MAXQ], resname[MAXQ];
+    bool bExact;
 
-    set_prop(aps, eprop);
-    if ((strlen(atomnm) > MAXQ-1) || (strlen(resnm) > MAXQ-1))
+    if (setProperties(prop(eprop), restype(), eprop, impl_->bWarned))
+    {
+        printWarning();
+        impl_->bWarned = true;
+    }
+    if ((strlen(atomName) > MAXQ-1) || (strlen(residueName) > MAXQ-1))
     {
         if (debug)
         {
@@ -359,70 +408,73 @@ gmx_bool gmx_atomprop_query(gmx_atomprop_t aps,
                     MAXQ-1);
         }
     }
-    if (isdigit(atomnm[0]))
+    if (isdigit(atomName[0]))
     {
         int i;
         /* put digit after atomname */
-        for (i = 1; i < MAXQ-1 && atomnm[i] != '\0'; i++)
+        for (i = 1; i < MAXQ-1 && atomName[i] != '\0'; i++)
         {
-            atomname[i-1] = atomnm[i];
+            atomname[i-1] = atomName[i];
         }
-        atomname[i-1] = atomnm[0];
+        atomname[i-1] = atomName[0];
         atomname[i]   = '\0';
     }
     else
     {
-        strncpy(atomname, atomnm, MAXQ-1);
+        strncpy(atomname, atomName, MAXQ-1);
     }
-    strncpy(resname, resnm, MAXQ-1);
+    strncpy(resname, residueName, MAXQ-1);
 
-    j = get_prop_index(&(ap->prop[eprop]), ap->restype, resname,
-                       atomname, &bExact);
+    j = findPropertyIndex(&(impl_->prop[eprop]), impl_->restype, resname,
+                          atomname, &bExact);
 
-    if (eprop == epropVDW && !ap->bWarnVDW)
+    if (eprop == epropVDW && !impl_->bWarnVDW)
     {
-        vdw_warning(stdout);
-        ap->bWarnVDW = TRUE;
+        printvdwWarning(stdout);
+        impl_->bWarnVDW = true;
     }
     if (j >= 0)
     {
-        *value = ap->prop[eprop].value[j];
-        return TRUE;
+        *value = impl_->prop[eprop].value[j];
+        return true;
     }
     else
     {
-        *value = ap->prop[eprop].def;
-        return FALSE;
+        *value = impl_->prop[eprop].def;
+        return false;
     }
 }
 
-char *gmx_atomprop_element(gmx_atomprop_t aps, int atomnumber)
-{
-    gmx_atomprop *ap = static_cast<gmx_atomprop*>(aps);
-    int           i;
 
-    set_prop(aps, epropElement);
-    for (i = 0; (i < ap->prop[epropElement].nprop); i++)
+const char *AtomProperties::elementFromAtomNumber(int atomNumber)
+{
+    if (setProperties(prop(epropElement), restype(), epropElement, impl_->bWarned))
     {
-        if (std::round(ap->prop[epropElement].value[i]) == atomnumber)
+        printWarning();
+        impl_->bWarned = true;
+    }
+    for (int i = 0; (i < impl_->prop[epropElement].nprop); i++)
+    {
+        if (std::round(impl_->prop[epropElement].value[i]) == atomNumber)
         {
-            return ap->prop[epropElement].atomnm[i];
+            return impl_->prop[epropElement].atomName[i];
         }
     }
     return nullptr;
 }
 
-int gmx_atomprop_atomnumber(gmx_atomprop_t aps, const char *elem)
+int AtomProperties::atomNumberFromElement(const char *element)
 {
-    gmx_atomprop *ap = static_cast<gmx_atomprop*>(aps);
-    int           i;
-
-    set_prop(aps, epropElement);
-    for (i = 0; (i < ap->prop[epropElement].nprop); i++)
+    if (setProperties(prop(epropElement), restype(), epropElement, impl_->bWarned))
+    {
+        printWarning();
+        impl_->bWarned = true;
+    }
+    for (int i = 0; (i < impl_->prop[epropElement].nprop); i++)
     {
-        if (gmx_strcasecmp(ap->prop[epropElement].atomnm[i], elem) == 0)
+        if (gmx_strcasecmp(impl_->prop[epropElement].atomName[i], element) == 0)
         {
-            return gmx::roundToInt(ap->prop[epropElement].value[i]);
+            return gmx::roundToInt(impl_->prop[epropElement].value[i]);
         }
     }
     return -1;
index 73b95fbd9470060abacd65553b51292d9426627a..6b3cd081e61aaeb43864894a6d02996579347a6b 100644 (file)
@@ -1,9 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2010,2014,2018, by the GROMACS development team, led by
+ * Copyright (c) 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_ATOMPROP_H
 
 #include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/classhelpers.h"
 #include "gromacs/utility/real.h"
 
-/* Abstract type for the atom property database */
-typedef struct gmx_atomprop *gmx_atomprop_t;
-
 enum {
     epropMass, epropVDW, epropDGsol, epropElectroneg, epropElement,
     epropNR
 };
 
-gmx_atomprop_t gmx_atomprop_init();
-/* Initializes and returns the atom properties struct */
-
-void gmx_atomprop_destroy(gmx_atomprop_t aps);
-/* Get rid of memory after use */
+struct AtomProperty;
+struct gmx_residuetype_t;
+/*! \brief
+ * Holds all the atom property information loaded.
+ */
+class AtomProperties
+{
+    public:
+        //! Default constructor.
+        AtomProperties();
+        //! Default destructor
+        ~AtomProperties();
 
-char *gmx_atomprop_element(gmx_atomprop_t aps, int atomnumber);
+        /*! \brief
+         * Get element string from atom number.
+         *
+         * \param[in] atomNumber Atomnumber to check.
+         * \returns Name of the element.
+         *
+         * \todo This should be made const once the lazy
+         * implementation is done properly for the class.
+         */
+        const char *elementFromAtomNumber(int atomNumber);
+        /*! \brief
+         * Get atom number from element string.
+         *
+         * \param[in] element Name of element.
+         * \returns AtomNumber that was being looked for.
+         *
+         * \todo This should be made const once the lazy
+         * implementation is done properly for the class.
+         */
+        int atomNumberFromElement(const char *element);
+        /*! \brief
+         * Set atom property based on atomname.
+         *
+         * Extract a \p value from the database. Returns true
+         * if this is successful, or false if not. Sets default value
+         * in the later case. The first time this function is called
+         * for this property the database will be initialized.
+         *
+         * \param[in] eprop Property to set.
+         * \param[in] residueName Residue name for entry.
+         * \param[in] atomName Atom name for entry.
+         * \param[out] value New value to set or default.
+         * \returns If the operation has been succesful.
+         */
+        bool setAtomProperty(int         eprop,
+                             const char* residueName,
+                             const char* atomName,
+                             real       *value);
+        /*! \brief
+         * Get handle to property.
+         *
+         * \param[in] eprop Which property we need a handle to.
+         * \returns Pointer to property entry.
+         */
+        AtomProperty *prop(int eprop);
+        //! Get handle to residuetype library.
+        gmx_residuetype_t *restype();
 
-int gmx_atomprop_atomnumber(gmx_atomprop_t aps, const char *element);
+    private:
+        //! Implementation pointer.
+        class Impl;
 
-gmx_bool gmx_atomprop_query(gmx_atomprop_t aps,
-                            int eprop, const char *resnm, const char *atomnm,
-                            real *value);
-/* Extract a value from the database. Returns TRUE on succes,
- * FALSE otherwise. In the latter case, value is a deafult value.
- * The first time this function is called for this property
- * the database will be read.
- */
+        gmx::PrivateImplPointer<Impl> impl_;
+};
 
 #endif
index 2860515ff726317a5361c06697761ff032840e7a..fa0071a64ce7ee02c71d6a08f995a2f2860f23e1 100644 (file)
@@ -464,17 +464,17 @@ void atomsSetMassesBasedOnNames(t_atoms *atoms, gmx_bool printMissingMasses)
     int            maxWarn  = (printMissingMasses ? 10 : 0);
     int            numWarn  = 0;
 
-    gmx_atomprop_t aps      = gmx_atomprop_init();
+    AtomProperties aps;
 
-    gmx_bool       haveMass = TRUE;
+    bool           haveMass = true;
     for (int i = 0; i < atoms->nr; i++)
     {
-        if (!gmx_atomprop_query(aps, epropMass,
-                                *atoms->resinfo[atoms->atom[i].resind].name,
-                                *atoms->atomname[i],
-                                &atoms->atom[i].m))
+        if (!aps.setAtomProperty(epropMass,
+                                 *atoms->resinfo[atoms->atom[i].resind].name,
+                                 *atoms->atomname[i],
+                                 &atoms->atom[i].m))
         {
-            haveMass = FALSE;
+            haveMass = false;
 
             if (numWarn < maxWarn)
             {
@@ -491,6 +491,4 @@ void atomsSetMassesBasedOnNames(t_atoms *atoms, gmx_bool printMissingMasses)
         }
     }
     atoms->haveMass = haveMass;
-
-    gmx_atomprop_destroy(aps);
 }
index 2080c657ab029a469b7f38f04838f56c3e188e29..5c23093395a082b9e25f2175075d4d16047a81c8 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * 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.
@@ -234,7 +234,7 @@ FreeVolume::initAnalysis(const TrajectoryAnalysisSettings &settings,
     // Initiate variable
     cutoff_               = 0;
     int            nnovdw = 0;
-    gmx_atomprop_t aps    = gmx_atomprop_init();
+    AtomProperties aps;
     auto           atoms  = top.copyAtoms();
 
     // Compute total mass
@@ -258,10 +258,10 @@ FreeVolume::initAnalysis(const TrajectoryAnalysisSettings &settings,
 
         // Lookup the Van der Waals radius of this atom
         int resnr = atoms->atom[i].resind;
-        if (gmx_atomprop_query(aps, epropVDW,
-                               *(atoms->resinfo[resnr].name),
-                               *(atoms->atomname[i]),
-                               &value))
+        if (aps.setAtomProperty(epropVDW,
+                                *(atoms->resinfo[resnr].name),
+                                *(atoms->atomname[i]),
+                                &value))
         {
             vdw_radius_.push_back(value);
             if (value > cutoff_)
@@ -281,7 +281,6 @@ FreeVolume::initAnalysis(const TrajectoryAnalysisSettings &settings,
             vdw_radius_.push_back(0.0);
         }
     }
-    gmx_atomprop_destroy(aps);
 
     // Increase cutoff by proberadius to make sure we do not miss
     // anything
index a33148e5901e14f9d975e009e431c84d96535f01..c10b32b648b9af5e4c4abbfe269926da5eedc630 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2006, The GROMACS development team.
- * Copyright (c) 2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2008,2009,2010,2011,2012,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.
@@ -564,7 +564,7 @@ Sasa::initAnalysis(const TrajectoryAnalysisSettings &settings,
 
     // TODO: Not exception-safe, but nice solution would be to have a C++
     // atom properties class...
-    gmx_atomprop_t      aps = gmx_atomprop_init();
+    AtomProperties      aps;
 
     ArrayRef<const int> atomIndices = surfaceSel_.atomIndices();
     int                 ndefault    = 0;
@@ -573,9 +573,9 @@ Sasa::initAnalysis(const TrajectoryAnalysisSettings &settings,
         const int ii     = atomIndices[i];
         const int resind = atoms_->atom[ii].resind;
         real      radius;
-        if (!gmx_atomprop_query(aps, epropVDW,
-                                *(atoms_->resinfo[resind].name),
-                                *(atoms_->atomname[ii]), &radius))
+        if (!aps.setAtomProperty(epropVDW,
+                                 *(atoms_->resinfo[resind].name),
+                                 *(atoms_->atomname[ii]), &radius))
         {
             ndefault++;
         }
@@ -583,9 +583,9 @@ Sasa::initAnalysis(const TrajectoryAnalysisSettings &settings,
         if (bDGsol)
         {
             real dgsFactor;
-            if (!gmx_atomprop_query(aps, epropDGsol,
-                                    *(atoms_->resinfo[resind].name),
-                                    *(atoms_->atomtype[ii]), &dgsFactor))
+            if (!aps.setAtomProperty(epropDGsol,
+                                     *(atoms_->resinfo[resind].name),
+                                     *(atoms_->atomtype[ii]), &dgsFactor))
             {
                 dgsFactor = dgsDefault_;
             }
@@ -596,7 +596,6 @@ Sasa::initAnalysis(const TrajectoryAnalysisSettings &settings,
     {
         fprintf(stderr, "WARNING: could not find a Van der Waals radius for %d atoms\n", ndefault);
     }
-    gmx_atomprop_destroy(aps);
 
     // Pre-compute mapping from the output groups to the calculation group,
     // and store it in the selection ID map for easy lookup.
index f5439d8d942c81c7e9bb71f68a098b1b49f98b51..cbf3ebcb5c358ba2004ded597730f463ac9dfc9e 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, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,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.
@@ -60,9 +60,9 @@ typedef char bmchar;
 
 #define XTextHeight(font) ((font)->max_bounds.ascent+(font)->max_bounds.descent)
 #define XDrawCircle(disp, win, gc, x, y, rad) \
-    XDrawArc(disp, win, gc, x-rad, y-rad, 2*rad, 2*rad, 0, 64*360)
+    XDrawArc(disp, win, gc, (x)-(rad), (y)-(rad), 2*(rad), 2*(rad), 0, 64*360)
 #define XFillCircle(disp, win, gc, x, y, rad) \
-    XFillArc(disp, win, gc, x-rad, y-rad, 2*rad, 2*rad, 0, 64*360)
+    XFillArc(disp, win, gc, (x)-(rad), (y)-(rad), 2*(rad), 2*(rad), 0, 64*360)
 
 #ifdef NEED_XSTUFF
 
index 8695978f12271963df28b263c7ca3ac8f67407d6..13766c0fcab2ef8b1ea35c5bb608b3eaf596d748 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, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,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.
@@ -79,7 +79,7 @@ static void add_object(t_manager *man, eObject eO, int ai, int aj)
     man->obj[man->nobj-1].z     = 0.0;
 }
 
-static void add_bonds(t_manager *man, t_functype func[],
+static void add_bonds(t_manager *man, const t_functype func[],
                       t_ilist *b, bool bB[])
 {
     bool        *bH = man->bHydro;
@@ -155,7 +155,7 @@ static int which_atom(t_manager *man, int x, int y)
         {
             if (man->bVis[i])
             {
-                return (int) i;
+                return i;
             }
         }
     }
@@ -205,7 +205,6 @@ static void hide_label(t_x11 *x11, t_manager *man, int x, int y)
 void set_file(t_x11 *x11, t_manager *man, const char *trajectory,
               const char *status)
 {
-    gmx_atomprop_t    aps;
     t_tpxheader       sh;
     t_atoms          *at;
     bool             *bB;
@@ -246,7 +245,7 @@ void set_file(t_x11 *x11, t_manager *man, const char *trajectory,
     man->title.text = gmx_strdup(gmx::formatString("%s: %s", *man->top.name, gmx::getCoolQuote().c_str()).c_str());
     man->view       = init_view(man->box);
     at              = &(man->top.atoms);
-    aps             = gmx_atomprop_init();
+    AtomProperties aps;
     for (i = 0; (i < man->natom); i++)
     {
         char      *aname = *(at->atomname[i]);
@@ -267,18 +266,17 @@ void set_file(t_x11 *x11, t_manager *man, const char *trajectory,
         {
             man->vdw[i] = 0;
         }
-        else if (!gmx_atomprop_query(aps, epropVDW, *ri->name, aname, &(man->vdw[i])))
+        else if (!aps.setAtomProperty(epropVDW, *ri->name, aname, &(man->vdw[i])))
         {
             man->vdw[i] = 0;
         }
     }
-    gmx_atomprop_destroy(aps);
     add_bpl(man, &(man->top.idef), bB);
     for (i = 0; (i < man->natom); i++)
     {
         if (!bB[i])
         {
-            add_object(man, eOSingle, (int) i, 0);
+            add_object(man, eOSingle, i, 0);
         }
     }
     sfree(bB);
@@ -395,7 +393,7 @@ static bool step_man(t_manager *man, int *nat)
     return bEof;
 }
 
-static void HandleClient(t_x11 *x11, t_manager *man, long data[])
+static void HandleClient(t_x11 *x11, t_manager *man, const long data[])
 {
     int  ID, button, x, y;
     bool bPos;
index f5a7d551fc8b1cd72dfb9697edfece0db5634924..ed30a55a8bf200b3b39a2a91f1f1ed4028ad2ea5 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, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,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.
@@ -166,7 +166,7 @@ extern void set_file(t_x11 *x11, t_manager *man, const char *trajectory,
 
 extern void map_man(t_x11 *x11, t_manager *man);
 
-extern void move_man(t_x11 *x11, t_manager *man, int width, int height);
+
 
 extern bool toggle_animate (t_x11 *x11, t_manager *man);