2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2011, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
37 /* This file is completely threadsafe - keep it that way! */
43 #include "hackblock.h"
49 /* these MUST correspond to the enum in hackblock.h */
50 const char *btsNames[ebtsNR] = { "bonds", "angles", "dihedrals", "impropers", "exclusions", "cmap" };
51 const int btsNiatoms[ebtsNR] = { 2, 3, 4, 4, 2, 5 };
53 static void free_t_bonded(t_rbonded *rb)
57 for (i = 0; i < MAXATOMLIST; i++)
64 static void free_t_bondeds(t_rbondeds *rbs)
68 for (i = 0; i < rbs->nb; i++)
70 free_t_bonded(&rbs->b[i]);
77 void free_t_restp(int nrtp, t_restp **rtp)
81 for (i = 0; i < nrtp; i++)
83 sfree((*rtp)[i].resname);
84 sfree((*rtp)[i].atom);
85 for (j = 0; j < (*rtp)[i].natom; j++)
87 sfree(*(*rtp)[i].atomname[j]);
88 sfree((*rtp)[i].atomname[j]);
90 sfree((*rtp)[i].atomname);
91 sfree((*rtp)[i].cgnr);
92 for (j = 0; j < ebtsNR; j++)
94 free_t_bondeds(&(*rtp)[i].rb[j]);
100 void free_t_hack(int nh, t_hack **h)
104 for (i = 0; i < nh; i++)
106 sfree((*h)[i].oname);
107 sfree((*h)[i].nname);
109 for (j = 0; j < 4; j++)
118 void free_t_hackblock(int nhb, t_hackblock **hb)
122 for (i = 0; i < nhb; i++)
124 sfree((*hb)[i].name);
125 free_t_hack((*hb)[i].nhack, &(*hb)[i].hack);
126 for (j = 0; j < ebtsNR; j++)
128 free_t_bondeds(&(*hb)[i].rb[j]);
134 void clear_t_hackblock(t_hackblock *hb)
142 for (i = 0; i < ebtsNR; i++)
149 void clear_t_hack(t_hack *hack)
160 for (i = 0; i < 4; i++)
164 for (i = 0; i < DIM; i++)
166 hack->newx[i] = NOTSET;
170 #define safe_strdup(str) ((str != NULL) ? strdup(str) : NULL)
172 static void copy_t_rbonded(t_rbonded *s, t_rbonded *d)
176 for (i = 0; i < MAXATOMLIST; i++)
178 d->a[i] = safe_strdup(s->a[i]);
180 d->s = safe_strdup(s->s);
183 static gmx_bool contains_char(t_rbonded *s, char c)
189 for (i = 0; i < MAXATOMLIST; i++)
191 if (s->a[i] && s->a[i][0] == c)
200 gmx_bool merge_t_bondeds(t_rbondeds s[], t_rbondeds d[], gmx_bool bMin, gmx_bool bPlus)
203 gmx_bool bBondsRemoved;
205 bBondsRemoved = FALSE;
206 for (i = 0; i < ebtsNR; i++)
211 srenew(d[i].b, d[i].nb + s[i].nb);
212 for (j = 0; j < s[i].nb; j++)
214 if (!(bMin && contains_char(&s[i].b[j], '-'))
215 && !(bPlus && contains_char(&s[i].b[j], '+')))
217 copy_t_rbonded(&s[i].b[j], &d[i].b[ d[i].nb ]);
220 else if (i == ebtsBONDS)
222 bBondsRemoved = TRUE;
228 return bBondsRemoved;
231 void copy_t_restp(t_restp *s, t_restp *d)
236 d->resname = safe_strdup(s->resname);
237 snew(d->atom, s->natom);
238 for (i = 0; i < s->natom; i++)
240 d->atom[i] = s->atom[i];
242 snew(d->atomname, s->natom);
243 for (i = 0; i < s->natom; i++)
245 snew(d->atomname[i], 1);
246 *d->atomname[i] = safe_strdup(*s->atomname[i]);
248 snew(d->cgnr, s->natom);
249 for (i = 0; i < s->natom; i++)
251 d->cgnr[i] = s->cgnr[i];
253 for (i = 0; i < ebtsNR; i++)
255 d->rb[i].type = s->rb[i].type;
259 merge_t_bondeds(s->rb, d->rb, FALSE, FALSE);
262 void copy_t_hack(t_hack *s, t_hack *d)
267 d->oname = safe_strdup(s->oname);
268 d->nname = safe_strdup(s->nname);
272 *(d->atom) = *(s->atom);
278 for (i = 0; i < 4; i++)
280 d->a[i] = safe_strdup(s->a[i]);
282 copy_rvec(s->newx, d->newx);
285 void merge_hacks_lo(int ns, t_hack *s, int *nd, t_hack **d)
291 srenew(*d, *nd + ns);
292 for (i = 0; i < ns; i++)
294 copy_t_hack(&s[i], &(*d)[*nd + i]);
300 void merge_hacks(t_hackblock *s, t_hackblock *d)
302 merge_hacks_lo(s->nhack, s->hack, &d->nhack, &d->hack);
305 void merge_t_hackblock(t_hackblock *s, t_hackblock *d)
308 merge_t_bondeds(s->rb, d->rb, FALSE, FALSE);
311 void copy_t_hackblock(t_hackblock *s, t_hackblock *d)
316 d->name = safe_strdup(s->name);
319 for (i = 0; i < ebtsNR; i++)
324 merge_t_hackblock(s, d);
329 void dump_hb(FILE *out, int nres, t_hackblock hb[])
333 #define SS(s) (s) ? (s) : "-"
334 #define SA(s) (s) ? "+" : ""
335 fprintf(out, "t_hackblock\n");
336 for (i = 0; i < nres; i++)
338 fprintf(out, "%3d %4s %2d %2d\n",
339 i, SS(hb[i].name), hb[i].nhack, hb[i].maxhack);
342 for (j = 0; j < hb[i].nhack; j++)
344 fprintf(out, "%d: %d %4s %4s %1s %2d %d %4s %4s %4s %4s\n",
346 SS(hb[i].hack[j].oname), SS(hb[i].hack[j].nname),
347 SA(hb[i].hack[j].atom), hb[i].hack[j].tp, hb[i].hack[j].cgnr,
348 SS(hb[i].hack[j].AI), SS(hb[i].hack[j].AJ),
349 SS(hb[i].hack[j].AK), SS(hb[i].hack[j].AL) );
352 for (j = 0; j < ebtsNR; j++)
356 fprintf(out, " %c %d:", btsNames[j][0], hb[i].rb[j].nb);
357 for (k = 0; k < hb[i].rb[j].nb; k++)
360 for (l = 0; l < btsNiatoms[j]; l++)
362 fprintf(out, " %s", hb[i].rb[j].b[k].a[l]);
364 fprintf(out, " %s]", SS(hb[i].rb[j].b[k].s));
375 void init_t_protonate(t_protonate *protonate)
377 protonate->bInit = FALSE;