Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / gen_ad.c
index 61dc0f9cd71054b75324978d805b6e2249525407..1b7a0b9c5e3f68f57527db29decb909ac2973afd 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,2015, 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.
@@ -1038,102 +1038,105 @@ void gen_pad(t_nextnb *nnb, t_atoms *atoms, t_restp rtp[],
         }
     }
 
-    /* The above approach is great in that we double-check that e.g. an angle
-     * really corresponds to three atoms connected by bonds, but this is not
-     * generally true. Go through the angle and dihedral hackblocks to add
-     * entries that we have not yet marked as matched when going through bonds.
-     */
-    for (i = 0; i < atoms->nres; i++)
+    if (hb)
     {
-        /* Add remaining angles from hackblock */
-        hbang = &hb[i].rb[ebtsANGLES];
-        for (j = 0; j < hbang->nb; j++)
+        /* The above approach is great in that we double-check that e.g. an angle
+         * really corresponds to three atoms connected by bonds, but this is not
+         * generally true. Go through the angle and dihedral hackblocks to add
+         * entries that we have not yet marked as matched when going through bonds.
+         */
+        for (i = 0; i < atoms->nres; i++)
         {
-            if (hbang->b[j].match == TRUE)
-            {
-                /* We already used this entry, continue to the next */
-                continue;
-            }
-            /* Hm - entry not used, let's see if we can find all atoms */
-            if (nang == maxang)
-            {
-                maxang += ninc;
-                srenew(ang, maxang);
-            }
-            bFound = TRUE;
-            for (k = 0; k < 3 && bFound; k++)
+            /* Add remaining angles from hackblock */
+            hbang = &hb[i].rb[ebtsANGLES];
+            for (j = 0; j < hbang->nb; j++)
             {
-                p   = hbang->b[j].a[k];
-                res = i;
-                if (p[0] == '-')
+                if (hbang->b[j].match == TRUE)
                 {
-                    p++;
-                    res--;
+                    /* We already used this entry, continue to the next */
+                    continue;
                 }
-                else if (p[0] == '+')
+                /* Hm - entry not used, let's see if we can find all atoms */
+                if (nang == maxang)
                 {
-                    p++;
-                    res++;
+                    maxang += ninc;
+                    srenew(ang, maxang);
                 }
-                ang[nang].a[k] = search_res_atom(p, res, atoms, "angle", TRUE);
-                bFound         = (ang[nang].a[k] != NO_ATID);
-            }
-            ang[nang].C0 = NOTSET;
-            ang[nang].C1 = NOTSET;
+                bFound = TRUE;
+                for (k = 0; k < 3 && bFound; k++)
+                {
+                    p   = hbang->b[j].a[k];
+                    res = i;
+                    if (p[0] == '-')
+                    {
+                        p++;
+                        res--;
+                    }
+                    else if (p[0] == '+')
+                    {
+                        p++;
+                        res++;
+                    }
+                    ang[nang].a[k] = search_res_atom(p, res, atoms, "angle", TRUE);
+                    bFound         = (ang[nang].a[k] != NO_ATID);
+                }
+                ang[nang].C0 = NOTSET;
+                ang[nang].C1 = NOTSET;
 
-            if (bFound)
-            {
-                set_p_string(&(ang[nang]), hbang->b[j].s);
-                hbang->b[j].match = TRUE;
-                /* Incrementing nang means we save this angle */
-                nang++;
+                if (bFound)
+                {
+                    set_p_string(&(ang[nang]), hbang->b[j].s);
+                    hbang->b[j].match = TRUE;
+                    /* Incrementing nang means we save this angle */
+                    nang++;
+                }
             }
-        }
 
-        /* Add remaining dihedrals from hackblock */
-        hbdih = &hb[i].rb[ebtsPDIHS];
-        for (j = 0; j < hbdih->nb; j++)
-        {
-            if (hbdih->b[j].match == TRUE)
-            {
-                /* We already used this entry, continue to the next */
-                continue;
-            }
-            /* Hm - entry not used, let's see if we can find all atoms */
-            if (ndih == maxdih)
-            {
-                maxdih += ninc;
-                srenew(dih, maxdih);
-            }
-            bFound = TRUE;
-            for (k = 0; k < 4 && bFound; k++)
+            /* Add remaining dihedrals from hackblock */
+            hbdih = &hb[i].rb[ebtsPDIHS];
+            for (j = 0; j < hbdih->nb; j++)
             {
-                p   = hbdih->b[j].a[k];
-                res = i;
-                if (p[0] == '-')
+                if (hbdih->b[j].match == TRUE)
                 {
-                    p++;
-                    res--;
+                    /* We already used this entry, continue to the next */
+                    continue;
                 }
-                else if (p[0] == '+')
+                /* Hm - entry not used, let's see if we can find all atoms */
+                if (ndih == maxdih)
                 {
-                    p++;
-                    res++;
+                    maxdih += ninc;
+                    srenew(dih, maxdih);
+                }
+                bFound = TRUE;
+                for (k = 0; k < 4 && bFound; k++)
+                {
+                    p   = hbdih->b[j].a[k];
+                    res = i;
+                    if (p[0] == '-')
+                    {
+                        p++;
+                        res--;
+                    }
+                    else if (p[0] == '+')
+                    {
+                        p++;
+                        res++;
+                    }
+                    dih[ndih].a[k] = search_res_atom(p, res, atoms, "dihedral", TRUE);
+                    bFound         = (dih[ndih].a[k] != NO_ATID);
+                }
+                for (m = 0; m < MAXFORCEPARAM; m++)
+                {
+                    dih[ndih].c[m] = NOTSET;
                 }
-                dih[ndih].a[k] = search_res_atom(p, res, atoms, "dihedral", TRUE);
-                bFound         = (dih[ndih].a[k] != NO_ATID);
-            }
-            for (m = 0; m < MAXFORCEPARAM; m++)
-            {
-                dih[ndih].c[m] = NOTSET;
-            }
 
-            if (bFound)
-            {
-                set_p_string(&(dih[ndih]), hbdih->b[j].s);
-                hbdih->b[j].match = TRUE;
-                /* Incrementing ndih means we save this dihedral */
-                ndih++;
+                if (bFound)
+                {
+                    set_p_string(&(dih[ndih]), hbdih->b[j].s);
+                    hbdih->b[j].match = TRUE;
+                    /* Incrementing ndih means we save this dihedral */
+                    ndih++;
+                }
             }
         }
     }