Merge branch release-5-1 into release-2016
authorMark Abraham <mark.j.abraham@gmail.com>
Wed, 22 Jun 2016 08:22:48 +0000 (10:22 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Wed, 22 Jun 2016 08:22:48 +0000 (10:22 +0200)
Change-Id: I175bb4c5d313a33c0c95446f85b1af2128ce301c

src/gromacs/domdec/domdec_topology.cpp
src/gromacs/gmxpreprocess/specbond.cpp

index ba47ff540bd1e34ea249db5196ccc3b16012459b..548e373e8564e9237308a1ace4970eccb2fe027f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2006,2007,2008,2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016, 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.
@@ -1258,34 +1258,46 @@ static void combine_idef(t_idef *dest, const thread_work_t *src, int nsrc,
 
                 ild->nr += ils->nr;
             }
-        }
-    }
-
-    /* Position restraints need an additional treatment */
-    if (dest->il[F_POSRES].nr > 0)
-    {
-        int n, s, i;
 
-        n = dest->il[F_POSRES].nr/2;
-        if (n > dest->iparams_posres_nalloc)
-        {
-            dest->iparams_posres_nalloc = over_alloc_large(n);
-            srenew(dest->iparams_posres, dest->iparams_posres_nalloc);
-        }
-        /* Set n to the number of original position restraints in dest */
-        for (s = 1; s < nsrc; s++)
-        {
-            n -= src[s].idef.il[F_POSRES].nr/2;
-        }
-        for (s = 1; s < nsrc; s++)
-        {
-            for (i = 0; i < src[s].idef.il[F_POSRES].nr/2; i++)
+            /* Position restraints need an additional treatment */
+            if (ftype == F_POSRES || ftype == F_FBPOSRES)
             {
-                /* Correct the index into iparams_posres */
-                dest->il[F_POSRES].iatoms[n*2] = n;
-                /* Copy the position restraint force parameters */
-                dest->iparams_posres[n] = src[s].idef.iparams_posres[i];
-                n++;
+                int nposres = dest->il[ftype].nr/2;
+                if (nposres > dest->iparams_posres_nalloc)
+                {
+                    dest->iparams_posres_nalloc = over_alloc_large(nposres);
+                    srenew(dest->iparams_posres, dest->iparams_posres_nalloc);
+                }
+                /* Set nposres to the number of original position restraints in dest */
+                for (int s = 1; s < nsrc; s++)
+                {
+                    nposres -= src[s].idef.il[ftype].nr/2;
+                }
+                for (int s = 1; s < nsrc; s++)
+                {
+                    if (ftype == F_POSRES)
+                    {
+                        for (int i = 0; i < src[s].idef.il[ftype].nr/2; i++)
+                        {
+                            /* Correct the index into iparams_posres */
+                            dest->il[ftype].iatoms[nposres*2] = nposres;
+                            /* Copy the position restraint force parameters */
+                            dest->iparams_posres[nposres] = src[s].idef.iparams_posres[i];
+                            nposres++;
+                        }
+                    }
+                    else
+                    {
+                        for (int i = 0; i < src[s].idef.il[ftype].nr/2; i++)
+                        {
+                            /* Correct the index into iparams_fbposres */
+                            dest->il[ftype].iatoms[nposres*2] = nposres;
+                            /* Copy the position restraint force parameters */
+                            dest->iparams_fbposres[nposres] = src[s].idef.iparams_fbposres[i];
+                            nposres++;
+                        }
+                    }
+                }
             }
         }
     }
index 265e7d4f9330271684ebb16e12f6fd6a84e58f3c..74145c5cd244299318a357287c7716edebd75fed 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,2016, 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.
@@ -331,7 +331,8 @@ int mk_specbonds(t_atoms *pdba, rvec x[], gmx_bool bInteractive,
             for (j = i+1; (j < nspec); j++)
             {
                 aj = sgp[j];
-                if (is_bond(nsb, sb, pdba, ai, aj, d[i][j], &index_sb, &bSwap))
+                /* Ensure creation of at most nspec special bonds to avoid overflowing bonds[] */
+                if (nbonds < nspec && is_bond(nsb, sb, pdba, ai, aj, d[i][j], &index_sb, &bSwap))
                 {
                     fprintf(stderr, "%s %s-%d %s-%d and %s-%d %s-%d%s",
                             bInteractive ? "Link" : "Linking",