/*
+ * This file is part of the GROMACS molecular simulation package.
*
- * This source code is part of
- *
- * G R O M A C S
- *
- * GROningen MAchine for Chemical Simulations
- *
- * VERSION 3.2.0
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2011,2014, 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.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * For more info, check our website at http://www.gromacs.org
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
*
- * And Hey:
- * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
*/
/* This file is completely threadsafe - keep it that way! */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
-#include <string.h>
#include "hackblock.h"
-#include "smalloc.h"
-#include "vec.h"
-#include "string2.h"
-#include "macros.h"
+
+#include <string.h>
+
+#include "gromacs/legacyheaders/names.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/smalloc.h"
/* these MUST correspond to the enum in hackblock.h */
const char *btsNames[ebtsNR] = { "bonds", "angles", "dihedrals", "impropers", "exclusions", "cmap" };
free_t_bondeds(&(*rtp)[i].rb[j]);
}
}
- free(*rtp);
+ sfree(*rtp);
}
void free_t_hack(int nh, t_hack **h)
}
}
-#define safe_strdup(str) ((str != NULL) ? strdup(str) : NULL)
+#define safe_strdup(str) ((str != NULL) ? gmx_strdup(str) : NULL)
static void copy_t_rbonded(t_rbonded *s, t_rbonded *d)
{
{
d->a[i] = safe_strdup(s->a[i]);
}
- d->s = safe_strdup(s->s);
+ d->s = safe_strdup(s->s);
+ d->match = s->match;
}
static gmx_bool contains_char(t_rbonded *s, char c)
return bRet;
}
+gmx_bool rbonded_atoms_exist_in_list(t_rbonded *b, t_rbonded blist[], int nlist, int natoms)
+{
+ int i, k;
+ gmx_bool matchFound = FALSE;
+ gmx_bool atomsMatch;
+
+ for (i = 0; i < nlist && !matchFound; i++)
+ {
+ atomsMatch = TRUE;
+ for (k = 0; k < natoms && atomsMatch; k++)
+ {
+ atomsMatch = atomsMatch && !strcmp(b->a[k], blist[i].a[k]);
+ }
+ /* Try reverse if forward match did not work */
+ if (!atomsMatch)
+ {
+ atomsMatch = TRUE;
+ for (k = 0; k < natoms && atomsMatch; k++)
+ {
+ atomsMatch = atomsMatch && !strcmp(b->a[k], blist[i].a[natoms-1-k]);
+ }
+ }
+ matchFound = atomsMatch;
+ }
+ return matchFound;
+}
+
gmx_bool merge_t_bondeds(t_rbondeds s[], t_rbondeds d[], gmx_bool bMin, gmx_bool bPlus)
{
int i, j;
srenew(d[i].b, d[i].nb + s[i].nb);
for (j = 0; j < s[i].nb; j++)
{
- if (!(bMin && contains_char(&s[i].b[j], '-'))
- && !(bPlus && contains_char(&s[i].b[j], '+')))
+ /* Check if this bonded string already exists before adding.
+ * We are merging from the main rtp to the hackblocks, so this
+ * will mean the hackblocks overwrite the man rtp, as intended.
+ */
+ if (!rbonded_atoms_exist_in_list(&s[i].b[j], d[i].b, d[i].nb, btsNiatoms[i]))
{
- copy_t_rbonded(&s[i].b[j], &d[i].b[ d[i].nb ]);
- d[i].nb++;
- }
- else if (i == ebtsBONDS)
- {
- bBondsRemoved = TRUE;
+ if (!(bMin && contains_char(&s[i].b[j], '-'))
+ && !(bPlus && contains_char(&s[i].b[j], '+')))
+ {
+ copy_t_rbonded(&s[i].b[j], &d[i].b[ d[i].nb ]);
+ d[i].nb++;
+ }
+ else if (i == ebtsBONDS)
+ {
+ bBondsRemoved = TRUE;
+ }
}
}
}
}
-
return bBondsRemoved;
}
}
fprintf(out, " %s]", SS(hb[i].rb[j].b[k].s));
}
- fprintf(out, "\n");
+ fprintf(out, " Entry matched: %s\n", yesno_names[hb[i].rb[j].b[k].match]);
}
}
fprintf(out, "\n");