From 8ebd438f3ca81c9cc5725b3149f2cd6f91422df5 Mon Sep 17 00:00:00 2001 From: Erik Lindahl Date: Mon, 23 Jun 2014 02:01:56 +0200 Subject: [PATCH] Make sure duplicates bondeds are set from hackblocks Previously the rtp file could end up containing two entries when the N/C termini databases added interactions. These were then quicksorted, which could make the assignment random. We now check for duplicates and discard the rtp entry in favor of the hackblock. Fixes #1395. Change-Id: I505cfbb7e6c8e8050e6e2935cc417e49a515d8d8 --- src/gromacs/gmxpreprocess/hackblock.c | 51 ++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/src/gromacs/gmxpreprocess/hackblock.c b/src/gromacs/gmxpreprocess/hackblock.c index 262e308f72..a5cdc7a0af 100644 --- a/src/gromacs/gmxpreprocess/hackblock.c +++ b/src/gromacs/gmxpreprocess/hackblock.c @@ -196,6 +196,33 @@ 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; @@ -210,20 +237,26 @@ gmx_bool merge_t_bondeds(t_rbondeds s[], t_rbondeds d[], gmx_bool bMin, gmx_bool 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; } -- 2.22.0