Refactor t_params to InteractionTypeParameters
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / toppush.cpp
index d529057a6b1acada146a865fd2d2518a99553768..ca06defb24117d84261541b169c6d71850b22bce 100644 (file)
@@ -66,7 +66,7 @@
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/stringutil.h"
 
-void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype *atype,
+void generate_nbparams(int comb, int ftype, InteractionTypeParameters *plist, gpp_atomtype *atype,
                        warninp *wi)
 {
     int   i, j, k = -1, nf;
@@ -192,7 +192,7 @@ void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype *atype
 }
 
 /*! \brief Used to temporarily store the explicit non-bonded parameter
- * combinations, which will be copied to t_params. */
+ * combinations, which will be copied to InteractionTypeParameters. */
 struct t_nbparam
 {
     //! Has this combination been set.
@@ -215,7 +215,7 @@ static void realloc_nb_params(gpp_atomtype *at,
     }
 }
 
-int copy_nbparams(t_nbparam **param, int ftype, t_params *plist, int nr)
+int copy_nbparams(t_nbparam **param, int ftype, InteractionTypeParameters *plist, int nr)
 {
     int i, j, f;
     int nrfp, ncopy;
@@ -581,13 +581,13 @@ static bool equalEitherForwardOrBackward(gmx::ArrayRef<const T> a, gmx::ArrayRef
             std::equal(a.begin(), a.end(), b.rbegin()));
 }
 
-static void push_bondtype(t_params     *       bt,
-                          const t_param *      b,
-                          int                  nral,
-                          int                  ftype,
-                          bool                 bAllowRepeat,
-                          const char *         line,
-                          warninp             *wi)
+static void push_bondtype(InteractionTypeParameters     *       bt,
+                          const t_param                  *      b,
+                          int                                   nral,
+                          int                                   ftype,
+                          bool                                  bAllowRepeat,
+                          const char                  *         line,
+                          warninp                              *wi)
 {
     int      nr   = bt->nr;
     int      nrfp = NRFP(ftype);
@@ -715,7 +715,7 @@ static void push_bondtype(t_params     *       bt,
     }
 }
 
-void push_bt(Directive d, t_params bt[], int nral,
+void push_bt(Directive d, gmx::ArrayRef<InteractionTypeParameters> bt, int nral,
              gpp_atomtype *at,
              gpp_bond_atomtype *bat, char *line,
              warninp *wi)
@@ -815,7 +815,7 @@ void push_bt(Directive d, t_params bt[], int nral,
 }
 
 
-void push_dihedraltype(Directive d, t_params bt[],
+void push_dihedraltype(Directive d, gmx::ArrayRef<InteractionTypeParameters> bt,
                        gpp_bond_atomtype *bat, char *line,
                        warninp *wi)
 {
@@ -1111,7 +1111,7 @@ void push_nbt(Directive d, t_nbparam **nbt, gpp_atomtype *atype,
 }
 
 void
-push_cmaptype(Directive d, t_params bt[], int nral, gpp_atomtype *at,
+push_cmaptype(Directive d, gmx::ArrayRef<InteractionTypeParameters> bt, int nral, gpp_atomtype *at,
               gpp_bond_atomtype *bat, char *line,
               warninp *wi)
 {
@@ -1155,10 +1155,6 @@ push_cmaptype(Directive d, t_params bt[], int nral, gpp_atomtype *at,
     nrfpB  = strtol(alc[7], nullptr, 10)*strtol(alc[7], nullptr, 10);
     nrfp   = nrfpA+nrfpB;
 
-    /* Allocate memory for the CMAP grid */
-    bt[F_CMAP].ncmap += nrfp;
-    srenew(bt[F_CMAP].cmap, bt[F_CMAP].ncmap);
-
     /* Read in CMAP parameters */
     sl = 0;
     for (i = 0; i < ncmap; i++)
@@ -1169,7 +1165,7 @@ push_cmaptype(Directive d, t_params bt[], int nral, gpp_atomtype *at,
         }
         nn  = sscanf(line+start+sl, " %s ", s);
         sl += strlen(s);
-        bt[F_CMAP].cmap[i+(bt[F_CMAP].ncmap)-nrfp] = strtod(s, nullptr);
+        bt[F_CMAP].cmap.emplace_back(strtod(s, nullptr));
 
         if (nn == 1)
         {
@@ -1188,7 +1184,7 @@ push_cmaptype(Directive d, t_params bt[], int nral, gpp_atomtype *at,
     {
         for (i = 0; i < ncmap; i++)
         {
-            bt[F_CMAP].cmap[i+ncmap] = bt[F_CMAP].cmap[i];
+            bt[F_CMAP].cmap.emplace_back(bt[F_CMAP].cmap[i]);
         }
     }
     else
@@ -1211,12 +1207,9 @@ push_cmaptype(Directive d, t_params bt[], int nral, gpp_atomtype *at,
     /* Set grid spacing and the number of grids (we assume these numbers to be the same for all grids
      * so we can safely assign them each time
      */
-    bt[F_CMAP].grid_spacing = nxcmap;            /* Or nycmap, they need to be equal */
-    bt[F_CMAP].nc           = bt[F_CMAP].nc + 1; /* Since we are incrementing here, we need to subtract later, see (*****) */
-    nct                     = (nral+1) * bt[F_CMAP].nc;
-
-    /* Allocate memory for the cmap_types information */
-    srenew(bt[F_CMAP].cmap_types, nct);
+    bt[F_CMAP].cmakeGridSpacing = nxcmap; /* Or nycmap, they need to be equal */
+    bt[F_CMAP].cmapAngles++;              /* Since we are incrementing here, we need to subtract later, see (*****) */
+    nct                     = (nral+1) * bt[F_CMAP].cmapAngles;
 
     for (i = 0; (i < nral); i++)
     {
@@ -1232,16 +1225,16 @@ push_cmaptype(Directive d, t_params bt[], int nral, gpp_atomtype *at,
         }
 
         /* Assign a grid number to each cmap_type */
-        bt[F_CMAP].cmap_types[bt[F_CMAP].nct++] = get_bond_atomtype_type(alc[i], bat);
+        bt[F_CMAP].cmapAtomTypes.emplace_back(get_bond_atomtype_type(alc[i], bat));
     }
 
     /* Assign a type number to this cmap */
-    bt[F_CMAP].cmap_types[bt[F_CMAP].nct++] = bt[F_CMAP].nc-1; /* Since we inremented earlier, we need to subtrac here, to get the types right (****) */
+    bt[F_CMAP].cmapAtomTypes.emplace_back(bt[F_CMAP].cmapAngles-1); /* Since we inremented earlier, we need to subtrac here, to get the types right (****) */
 
     /* Check for the correct number of atoms (again) */
-    if (bt[F_CMAP].nct != nct)
+    if (bt[F_CMAP].nct() != nct)
     {
-        auto message = gmx::formatString("Incorrect number of atom types (%d) in cmap type %d\n", nct, bt[F_CMAP].nc);
+        auto message = gmx::formatString("Incorrect number of atom types (%d) in cmap type %d\n", nct, bt[F_CMAP].cmapAngles);
         warning_error(wi, message);
     }
 
@@ -1469,7 +1462,7 @@ void push_molt(t_symtab                         *symtab,
     mol->back().excl_set = false;
 }
 
-static bool default_nb_params(int ftype, t_params bt[], t_atoms *at,
+static bool default_nb_params(int ftype, gmx::ArrayRef<InteractionTypeParameters> bt, t_atoms *at,
                               t_param *p, int c_start, bool bB, bool bGenPairs)
 {
     int          i, j, ti, tj, ntype;
@@ -1564,7 +1557,7 @@ static bool default_nb_params(int ftype, t_params bt[], t_atoms *at,
     return bFound;
 }
 
-static bool default_cmap_params(t_params bondtype[],
+static bool default_cmap_params(gmx::ArrayRef<InteractionTypeParameters> bondtype,
                                 t_atoms *at, gpp_atomtype *atype,
                                 t_param *p, bool bB,
                                 int *cmap_type, int *nparam_def,
@@ -1578,7 +1571,7 @@ static bool default_cmap_params(t_params bondtype[],
     ct           = 0;
 
     /* Match the current cmap angle against the list of cmap_types */
-    for (i = 0; i < bondtype[F_CMAP].nct && !bFound; i += 6)
+    for (i = 0; i < bondtype[F_CMAP].nct() && !bFound; i += 6)
     {
         if (bB)
         {
@@ -1587,15 +1580,15 @@ static bool default_cmap_params(t_params bondtype[],
         else
         {
             if (
-                (get_atomtype_batype(at->atom[p->a[0]].type, atype) == bondtype[F_CMAP].cmap_types[i])   &&
-                (get_atomtype_batype(at->atom[p->a[1]].type, atype) == bondtype[F_CMAP].cmap_types[i+1]) &&
-                (get_atomtype_batype(at->atom[p->a[2]].type, atype) == bondtype[F_CMAP].cmap_types[i+2]) &&
-                (get_atomtype_batype(at->atom[p->a[3]].type, atype) == bondtype[F_CMAP].cmap_types[i+3]) &&
-                (get_atomtype_batype(at->atom[p->a[4]].type, atype) == bondtype[F_CMAP].cmap_types[i+4]))
+                (get_atomtype_batype(at->atom[p->a[0]].type, atype) == bondtype[F_CMAP].cmapAtomTypes[i])   &&
+                (get_atomtype_batype(at->atom[p->a[1]].type, atype) == bondtype[F_CMAP].cmapAtomTypes[i+1]) &&
+                (get_atomtype_batype(at->atom[p->a[2]].type, atype) == bondtype[F_CMAP].cmapAtomTypes[i+2]) &&
+                (get_atomtype_batype(at->atom[p->a[3]].type, atype) == bondtype[F_CMAP].cmapAtomTypes[i+3]) &&
+                (get_atomtype_batype(at->atom[p->a[4]].type, atype) == bondtype[F_CMAP].cmapAtomTypes[i+4]))
             {
                 /* Found cmap torsion */
                 bFound       = TRUE;
-                ct           = bondtype[F_CMAP].cmap_types[i+5];
+                ct           = bondtype[F_CMAP].cmapAtomTypes[i+5];
                 nparam_found = 1;
             }
         }
@@ -1639,11 +1632,11 @@ static int natom_match(t_param *pi,
     }
 }
 
-static bool default_params(int ftype, t_params bt[],
-                           t_atoms *at, gpp_atomtype *atype,
-                           t_param *p, bool bB,
-                           t_param **param_def,
-                           int *nparam_def)
+static bool defaultInteractionTypeParameters(int ftype, gmx::ArrayRef<InteractionTypeParameters> bt,
+                                             t_atoms *at, gpp_atomtype *atype,
+                                             t_param *p, bool bB,
+                                             t_param **param_def,
+                                             int *nparam_def)
 {
     int          nparam_found;
     bool         bFound, bSame;
@@ -1758,7 +1751,8 @@ static bool default_params(int ftype, t_params bt[],
 
 
 
-void push_bond(Directive d, t_params bondtype[], t_params bond[],
+void push_bond(Directive d, gmx::ArrayRef<InteractionTypeParameters> bondtype,
+               gmx::ArrayRef<InteractionTypeParameters> bond,
                t_atoms *at, gpp_atomtype *atype, char *line,
                bool bBonded, bool bGenPairs, real fudgeQQ,
                bool bZero, bool *bWarn_copy_A_B,
@@ -1904,7 +1898,7 @@ void push_bond(Directive d, t_params bondtype[], t_params bond[],
 
     if (bBonded)
     {
-        bFoundA = default_params(ftype, bondtype, at, atype, &param, FALSE, &param_defA, &nparam_defA);
+        bFoundA = defaultInteractionTypeParameters(ftype, bondtype, at, atype, &param, FALSE, &param_defA, &nparam_defA);
         if (bFoundA)
         {
             /* Copy the A-state and B-state default parameters. */
@@ -1914,7 +1908,7 @@ void push_bond(Directive d, t_params bondtype[], t_params bond[],
                 param.c[j] = param_defA->c[j];
             }
         }
-        bFoundB = default_params(ftype, bondtype, at, atype, &param, TRUE, &param_defB, &nparam_defB);
+        bFoundB = defaultInteractionTypeParameters(ftype, bondtype, at, atype, &param, TRUE, &param_defB, &nparam_defB);
         if (bFoundB)
         {
             /* Copy only the B-state default parameters */
@@ -2166,7 +2160,8 @@ void push_bond(Directive d, t_params bondtype[], t_params bond[],
     }
 }
 
-void push_cmap(Directive d, t_params bondtype[], t_params bond[],
+void push_cmap(Directive d, gmx::ArrayRef<InteractionTypeParameters> bondtype,
+               gmx::ArrayRef<InteractionTypeParameters> bond,
                t_atoms *at, gpp_atomtype *atype, char *line,
                warninp *wi)
 {
@@ -2259,7 +2254,7 @@ void push_cmap(Directive d, t_params bondtype[], t_params bond[],
 
 
 
-void push_vsitesn(Directive d, t_params bond[],
+void push_vsitesn(Directive d, gmx::ArrayRef<InteractionTypeParameters> bond,
                   t_atoms *at, char *line,
                   warninp *wi)
 {
@@ -2508,7 +2503,7 @@ int add_atomtype_decoupled(t_symtab *symtab, gpp_atomtype *at,
     return nr;
 }
 
-static void convert_pairs_to_pairsQ(t_params *plist,
+static void convert_pairs_to_pairsQ(gmx::ArrayRef<InteractionTypeParameters> plist,
                                     real fudgeQQ, t_atoms *atoms)
 {
     t_param *paramp1, *paramp2, *paramnew;
@@ -2573,7 +2568,7 @@ static void convert_pairs_to_pairsQ(t_params *plist,
     plist[F_LJ14].param = nullptr;
 }
 
-static void generate_LJCpairsNB(MoleculeInformation *mol, int nb_funct, t_params *nbp, warninp *wi)
+static void generate_LJCpairsNB(MoleculeInformation *mol, int nb_funct, InteractionTypeParameters *nbp, warninp *wi)
 {
     int       n, ntype, i, j, k;
     t_atom   *atom;
@@ -2695,7 +2690,7 @@ static void decouple_atoms(t_atoms *atoms, int atomtype_decouple,
 
 void convert_moltype_couple(MoleculeInformation *mol, int atomtype_decouple, real fudgeQQ,
                             int couple_lam0, int couple_lam1,
-                            bool bCoupleIntra, int nb_funct, t_params *nbp,
+                            bool bCoupleIntra, int nb_funct, InteractionTypeParameters *nbp,
                             warninp *wi)
 {
     convert_pairs_to_pairsQ(mol->plist, fudgeQQ, &mol->atoms);