Fixes a problem with pair type 2 interactions with free energy
authorMichael Shirts <michael.shirts@virginia.edu>
Sat, 5 Oct 2013 18:28:12 +0000 (14:28 -0400)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Wed, 16 Oct 2013 11:19:06 +0000 (13:19 +0200)
Pair type 2 interactions, which should remain on regardless
of couple-intramol=yes, were being turned off. Currently, when free
energies were turned on, they were just ignored, because the (empty)
pair one 1 type list was copied over them.  This fix adresses
this problem by adding onto the list instead of copying it over.

Fixes #1315

Change-Id: I240479a8dc083f7a355917ed9f74f4337fa3448f

src/kernel/toppush.c

index 18e4284ac447e35b500f1f5942e60a20547ad064..d2f142a02511edab1dba6a179f3f44d29c925614 100644 (file)
@@ -2516,26 +2516,66 @@ int add_atomtype_decoupled(t_symtab *symtab, gpp_atomtype_t at,
 static void convert_pairs_to_pairsQ(t_params *plist,
                                     real fudgeQQ, t_atoms *atoms)
 {
-    t_param *param;
-    int      i;
-    real     v, w;
+    t_param *paramp1,*paramp2,*paramnew;
+    int      i,j,p1nr,p2nr,p2newnr;
 
-    /* Copy the pair list to the pairQ list */
-    plist[F_LJC14_Q] = plist[F_LJ14];
-    /* Empty the pair list */
-    plist[F_LJ14].nr    = 0;
-    plist[F_LJ14].param = NULL;
-    param               = plist[F_LJC14_Q].param;
-    for (i = 0; i < plist[F_LJC14_Q].nr; i++)
+    /* Add the pair list to the pairQ list */
+    p1nr = plist[F_LJ14].nr;
+    p2nr = plist[F_LJC14_Q].nr;
+    p2newnr = p1nr + p2nr;
+    snew(paramnew,p2newnr);
+
+    paramp1             = plist[F_LJ14].param;
+    paramp2             = plist[F_LJC14_Q].param;
+
+    /* Fill in the new F_LJC14_Q array with the old one. NOTE:
+       it may be possible to just ADD the converted F_LJ14 array
+       to the old F_LJC14_Q array, but since we have to create
+       a new sized memory structure, better just to deep copy it all.
+    */
+
+    for (i = 0; i < p2nr; i++)
+    {
+        /* Copy over parameters */
+        for (j=0;j<5;j++) /* entries are 0-4 for F_LJC14_Q */
+        {
+            paramnew[i].c[j] = paramp2[i].c[j];
+        }
+
+        /* copy over atoms */
+        for (j=0;j<2;j++)
+        {
+            paramnew[i].a[j] = paramp2[i].a[j];
+        }
+    }
+
+    for (i = p2nr; i < p2newnr; i++)
     {
-        v             = param[i].c[0];
-        w             = param[i].c[1];
-        param[i].c[0] = fudgeQQ;
-        param[i].c[1] = atoms->atom[param[i].a[0]].q;
-        param[i].c[2] = atoms->atom[param[i].a[1]].q;
-        param[i].c[3] = v;
-        param[i].c[4] = w;
+        j             = i-p2nr;
+
+        /* Copy over parameters */
+        paramnew[i].c[0] = fudgeQQ;
+        paramnew[i].c[1] = atoms->atom[paramp1[j].a[0]].q;
+        paramnew[i].c[2] = atoms->atom[paramp1[j].a[1]].q;
+        paramnew[i].c[3] = paramp1[j].c[0];
+        paramnew[i].c[4] = paramp1[j].c[1];
+
+        /* copy over atoms */
+        paramnew[i].a[0] = paramp1[j].a[0];
+        paramnew[i].a[1] = paramp1[j].a[1];
     }
+
+    /* free the old pairlists */
+    sfree(plist[F_LJC14_Q].param);
+    sfree(plist[F_LJ14].param);
+
+    /* now assign the new data to the F_LJC14_Q structure */
+    plist[F_LJC14_Q].param   = paramnew;
+    plist[F_LJC14_Q].nr      = p2newnr;
+
+    /* Empty the LJ14 pairlist */
+    plist[F_LJ14].nr    = 0;
+    plist[F_LJ14].param = NULL;
 }
 
 static void generate_LJCpairsNB(t_molinfo *mol, int nb_funct, t_params *nbp)