3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
35 /* This file is completely threadsafe - keep it that way! */
41 #include "hackblock.h"
47 /* these MUST correspond to the enum in hackblock.h */
48 const char *btsNames[ebtsNR] = { "bonds", "angles", "dihedrals", "impropers", "exclusions", "cmap" };
49 const int btsNiatoms[ebtsNR] = { 2, 3, 4, 4, 2, 5 };
51 static void free_t_bonded(t_rbonded *rb)
55 for (i=0; i<MAXATOMLIST; i++)
60 static void free_t_bondeds(t_rbondeds *rbs)
64 for(i=0; i<rbs->nb; i++)
65 free_t_bonded(&rbs->b[i]);
71 void free_t_restp(int nrtp, t_restp **rtp)
75 for(i=0; i<nrtp; i++) {
76 sfree((*rtp)[i].resname);
77 sfree((*rtp)[i].atom);
78 for(j=0; j<(*rtp)[i].natom; j++) {
79 sfree(*(*rtp)[i].atomname[j]);
80 sfree((*rtp)[i].atomname[j]);
82 sfree((*rtp)[i].atomname);
83 sfree((*rtp)[i].cgnr);
84 for(j=0; j<ebtsNR; j++)
85 free_t_bondeds(&(*rtp)[i].rb[j]);
90 void free_t_hack(int nh, t_hack **h)
105 void free_t_hackblock(int nhb, t_hackblock **hb)
109 for(i=0; i<nhb; i++) {
110 sfree((*hb)[i].name);
111 free_t_hack((*hb)[i].nhack, &(*hb)[i].hack);
112 for(j=0; j<ebtsNR; j++)
113 free_t_bondeds(&(*hb)[i].rb[j]);
118 void clear_t_hackblock(t_hackblock *hb)
126 for(i=0; i<ebtsNR; i++) {
132 void clear_t_hack(t_hack *hack)
146 hack->newx[i] = NOTSET;
149 #define safe_strdup(str) ((str != NULL) ? strdup(str) : NULL)
151 static void copy_t_rbonded(t_rbonded *s, t_rbonded *d)
155 for(i=0; i<MAXATOMLIST; i++)
156 d->a[i] = safe_strdup(s->a[i]);
157 d->s = safe_strdup(s->s);
160 static gmx_bool contains_char(t_rbonded *s,char c)
166 for(i=0; i<MAXATOMLIST; i++)
167 if (s->a[i] && s->a[i][0]==c)
173 gmx_bool merge_t_bondeds(t_rbondeds s[], t_rbondeds d[],gmx_bool bMin,gmx_bool bPlus)
176 gmx_bool bBondsRemoved;
178 bBondsRemoved = FALSE;
179 for(i=0; i < ebtsNR; i++) {
182 srenew(d[i].b, d[i].nb + s[i].nb);
183 for(j=0; j < s[i].nb; j++)
184 if (!(bMin && contains_char(&s[i].b[j],'-'))
185 && !(bPlus && contains_char(&s[i].b[j],'+'))) {
186 copy_t_rbonded(&s[i].b[j], &d[i].b[ d[i].nb ]);
188 } else if (i == ebtsBONDS) {
189 bBondsRemoved = TRUE;
194 return bBondsRemoved;
197 void copy_t_restp(t_restp *s, t_restp *d)
202 d->resname = safe_strdup(s->resname);
203 snew(d->atom, s->natom);
204 for(i=0; i < s->natom; i++)
205 d->atom[i] = s->atom[i];
206 snew(d->atomname, s->natom);
207 for(i=0; i < s->natom; i++) {
208 snew(d->atomname[i],1);
209 *d->atomname[i] = safe_strdup(*s->atomname[i]);
211 snew(d->cgnr, s->natom);
212 for(i=0; i < s->natom; i++)
213 d->cgnr[i] = s->cgnr[i];
214 for(i=0; i < ebtsNR; i++) {
215 d->rb[i].type = s->rb[i].type;
219 merge_t_bondeds(s->rb, d->rb,FALSE,FALSE);
222 void copy_t_hack(t_hack *s, t_hack *d)
227 d->oname = safe_strdup(s->oname);
228 d->nname = safe_strdup(s->nname);
231 *(d->atom) = *(s->atom);
235 d->a[i] = safe_strdup(s->a[i]);
236 copy_rvec(s->newx, d->newx);
239 void merge_hacks_lo(int ns, t_hack *s, int *nd, t_hack **d)
244 srenew(*d, *nd + ns);
245 for(i=0; i < ns; i++)
246 copy_t_hack(&s[i], &(*d)[*nd + i]);
251 void merge_hacks(t_hackblock *s, t_hackblock *d)
253 merge_hacks_lo(s->nhack, s->hack, &d->nhack, &d->hack);
256 void merge_t_hackblock(t_hackblock *s, t_hackblock *d)
259 merge_t_bondeds(s->rb, d->rb,FALSE,FALSE);
262 void copy_t_hackblock(t_hackblock *s, t_hackblock *d)
267 d->name = safe_strdup(s->name);
270 for(i=0; i<ebtsNR; i++) {
274 merge_t_hackblock(s, d);
279 void dump_hb(FILE *out, int nres, t_hackblock hb[])
283 #define SS(s) (s) ? (s) : "-"
284 #define SA(s) (s) ? "+" : ""
285 fprintf(out,"t_hackblock\n");
286 for(i=0; i<nres; i++) {
287 fprintf(out, "%3d %4s %2d %2d\n",
288 i, SS(hb[i].name), hb[i].nhack, hb[i].maxhack);
290 for(j=0; j<hb[i].nhack; j++) {
291 fprintf(out, "%d: %d %4s %4s %1s %2d %d %4s %4s %4s %4s\n",
293 SS(hb[i].hack[j].oname), SS(hb[i].hack[j].nname),
294 SA(hb[i].hack[j].atom), hb[i].hack[j].tp, hb[i].hack[j].cgnr,
295 SS(hb[i].hack[j].AI), SS(hb[i].hack[j].AJ),
296 SS(hb[i].hack[j].AK), SS(hb[i].hack[j].AL) );
298 for(j=0; j<ebtsNR; j++)
299 if (hb[i].rb[j].nb) {
300 fprintf(out, " %c %d:", btsNames[j][0], hb[i].rb[j].nb);
301 for(k=0; k<hb[i].rb[j].nb; k++) {
303 for(l=0; l<btsNiatoms[j]; l++)
304 fprintf(out, " %s",hb[i].rb[j].b[k].a[l]);
305 fprintf(out, " %s]",SS(hb[i].rb[j].b[k].s));
315 void init_t_protonate(t_protonate *protonate)
317 protonate->bInit=FALSE;