Use ListOfLists in gmx_mtop_t and gmx_localtop_t
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / toppush.cpp
index af199cdc799e50b0184338e1ce7ccc60d8217dc9..f78a72af0282f114c0864a2d2c884f357f44360d 100644 (file)
@@ -2615,10 +2615,8 @@ static void convert_pairs_to_pairsQ(gmx::ArrayRef<InteractionsOfType> interactio
 
 static void generate_LJCpairsNB(MoleculeInformation* mol, int nb_funct, InteractionsOfType* nbp, warninp* wi)
 {
-    int       n, ntype;
-    t_atom*   atom;
-    t_blocka* excl;
-    bool      bExcl;
+    int     n, ntype;
+    t_atom* atom;
 
     n    = mol->atoms.nr;
     atom = mol->atoms.atom;
@@ -2628,20 +2626,20 @@ static void generate_LJCpairsNB(MoleculeInformation* mol, int nb_funct, Interact
                "Number of pairs of generated non-bonded parameters should be a perfect square");
 
     /* Add a pair interaction for all non-excluded atom pairs */
-    excl = &mol->excls;
+    const auto& excls = mol->excls;
     for (int i = 0; i < n; i++)
     {
         for (int j = i + 1; j < n; j++)
         {
-            bExcl = FALSE;
-            for (int k = excl->index[i]; k < excl->index[i + 1]; k++)
+            bool pairIsExcluded = false;
+            for (const int atomK : excls[i])
             {
-                if (excl->a[k] == j)
+                if (atomK == j)
                 {
-                    bExcl = TRUE;
+                    pairIsExcluded = true;
                 }
             }
-            if (!bExcl)
+            if (!pairIsExcluded)
             {
                 if (nb_funct != F_LJ)
                 {
@@ -2661,24 +2659,20 @@ static void generate_LJCpairsNB(MoleculeInformation* mol, int nb_funct, Interact
     }
 }
 
-static void set_excl_all(t_blocka* excl)
+static void set_excl_all(gmx::ListOfLists<int>* excl)
 {
-    int nat, i, j, k;
-
     /* Get rid of the current exclusions and exclude all atom pairs */
-    nat       = excl->nr;
-    excl->nra = nat * nat;
-    srenew(excl->a, excl->nra);
-    k = 0;
-    for (i = 0; i < nat; i++)
+    const int        numAtoms = excl->ssize();
+    std::vector<int> exclusionsForAtom(numAtoms);
+    for (int i = 0; i < numAtoms; i++)
     {
-        excl->index[i] = k;
-        for (j = 0; j < nat; j++)
-        {
-            excl->a[k++] = j;
-        }
+        exclusionsForAtom[i] = i;
+    }
+    excl->clear();
+    for (int i = 0; i < numAtoms; i++)
+    {
+        excl->pushBack(exclusionsForAtom);
     }
-    excl->index[nat] = k;
 }
 
 static void decouple_atoms(t_atoms*    atoms,