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) 2012,2014, 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.
45 #include "gromacs/utility/smalloc.h"
51 #include "gmx_fatal.h"
52 #include "gpp_atomtype.h"
56 void set_p_string(t_param *p, const char *s)
60 if (strlen(s) < sizeof(p->s)-1)
62 strncpy(p->s, s, sizeof(p->s));
66 gmx_fatal(FARGS, "Increase MAXSLEN in include/grompp-impl.h to at least %d,"
67 " or shorten your definition of bonds like %s to at most %d",
68 strlen(s)+1, s, MAXSLEN-1);
77 void pr_alloc (int extra, t_params *pr)
81 /* get new space for arrays */
84 gmx_fatal(FARGS, "Trying to make array smaller.\n");
90 assert(!((pr->nr == 0) && (pr->param != NULL)));
91 if (pr->nr+extra > pr->maxnr)
93 pr->maxnr = max(1.2*pr->maxnr, pr->maxnr + extra);
94 srenew(pr->param, pr->maxnr);
95 for (i = pr->nr; (i < pr->maxnr); i++)
97 for (j = 0; (j < MAXATOMLIST); j++)
99 pr->param[i].a[j] = 0;
101 for (j = 0; (j < MAXFORCEPARAM); j++)
103 pr->param[i].c[j] = 0;
105 set_p_string(&(pr->param[i]), "");
110 void init_plist(t_params plist[])
114 for (i = 0; (i < F_NRE); i++)
118 plist[i].param = NULL;
122 plist[i].cmap = NULL;
123 plist[i].grid_spacing = 0;
126 plist[i].cmap_types = NULL;
130 void cp_param(t_param *dest, t_param *src)
134 for (j = 0; (j < MAXATOMLIST); j++)
136 dest->a[j] = src->a[j];
138 for (j = 0; (j < MAXFORCEPARAM); j++)
140 dest->c[j] = src->c[j];
142 strncpy(dest->s, src->s, sizeof(dest->s));
145 void add_param_to_list(t_params *list, t_param *b)
149 /* allocate one position extra */
152 /* fill the arrays */
153 for (j = 0; (j < MAXFORCEPARAM); j++)
155 list->param[list->nr].c[j] = b->c[j];
157 for (j = 0; (j < MAXATOMLIST); j++)
159 list->param[list->nr].a[j] = b->a[j];
161 memset(list->param[list->nr].s, 0, sizeof(list->param[list->nr].s));
167 void init_molinfo(t_molinfo *mol)
170 mol->excl_set = FALSE;
171 mol->bProcessed = FALSE;
172 init_plist(mol->plist);
173 init_block(&mol->cgs);
174 init_block(&mol->mols);
175 init_blocka(&mol->excls);
176 init_atom(&mol->atoms);
181 void done_bt (t_params *pl)
186 void done_mi(t_molinfo *mi)
190 done_atom (&(mi->atoms));
191 done_block(&(mi->cgs));
192 done_block(&(mi->mols));
193 for (i = 0; (i < F_NRE); i++)
195 done_bt(&(mi->plist[i]));
199 /* PRINTING STRUCTURES */
201 void print_bt(FILE *out, directive d, gpp_atomtype_t at,
202 int ftype, int fsubtype, t_params plist[],
205 /* This dihp is a DIRTY patch because the dih-types do not use
206 * all four atoms to determine the type.
208 const int dihp[2][2] = { { 1, 2 }, { 0, 3 } };
210 int i, j, f, nral, nrfp;
211 gmx_bool bDih = FALSE, bSwapParity;
213 bt = &(plist[ftype]);
241 case F_CROSS_BOND_ANGLES:
244 case F_CROSS_BOND_BONDS:
294 fprintf(out, "[ %s ]\n", dir2str(d));
298 fprintf (out, "%3s %4s", "ai", "aj");
299 for (j = 2; (j < nral); j++)
301 fprintf (out, " %3c%c", 'a', 'i'+j);
306 for (j = 0; (j < 2); j++)
308 fprintf (out, "%3c%c", 'a', 'i'+dihp[f][j]);
312 fprintf (out, " funct");
313 for (j = 0; (j < nrfp); j++)
315 fprintf (out, " %12c%1d", 'c', j);
319 /* print bondtypes */
320 for (i = 0; (i < bt->nr); i++)
322 bSwapParity = (bt->param[i].C0 == NOTSET) && (bt->param[i].C1 == -1);
325 for (j = 0; (j < nral); j++)
327 fprintf (out, "%5s ", get_atomtype_name(bt->param[i].a[j], at));
332 for (j = 0; (j < 2); j++)
334 fprintf (out, "%5s ", get_atomtype_name(bt->param[i].a[dihp[f][j]], at));
337 fprintf (out, "%5d ", bSwapParity ? -f-1 : f+1);
339 if (bt->param[i].s[0])
341 fprintf(out, " %s", bt->param[i].s);
345 for (j = 0; (j < nrfp && (bt->param[i].c[j] != NOTSET)); j++)
347 fprintf (out, "%13.6e ", bt->param[i].c[j]);
357 void print_blocka(FILE *out, const char *szName,
358 const char *szIndex, const char *szA,
363 fprintf (out, "; %s\n", szName);
364 fprintf (out, "; %4s %s\n", szIndex, szA);
365 for (i = 0; (i < block->nr); i++)
367 for (i = 0; (i < block->nr); i++)
369 fprintf (out, "%6d", i+1);
370 for (j = block->index[i]; (j < ((int)block->index[i+1])); j++)
372 fprintf (out, "%5d", block->a[j]+1);
380 void print_excl(FILE *out, int natoms, t_excls excls[])
387 for (i = 0; i < natoms && !have_excl; i++)
389 have_excl = (excls[i].nr > 0);
394 fprintf (out, "[ %s ]\n", dir2str(d_exclusions));
395 fprintf (out, "; %4s %s\n", "i", "excluded from i");
396 for (i = 0; i < natoms; i++)
400 fprintf (out, "%6d ", i+1);
401 for (j = 0; j < excls[i].nr; j++)
403 fprintf (out, " %5d", excls[i].e[j]+1);
413 static double get_residue_charge(const t_atoms *atoms, int at)
418 ri = atoms->atom[at].resind;
420 while (at < atoms->nr && atoms->atom[at].resind == ri)
422 q += atoms->atom[at].q;
429 void print_atoms(FILE *out, gpp_atomtype_t atype, t_atoms *at, int *cgnr,
430 gmx_bool bRTPresname)
438 as = dir2str(d_atoms);
439 fprintf(out, "[ %s ]\n", as);
440 fprintf(out, "; %4s %10s %6s %7s%6s %6s %10s %10s %6s %10s %10s\n",
441 "nr", "type", "resnr", "residue", "atom", "cgnr", "charge", "mass", "typeB", "chargeB", "massB");
447 fprintf(debug, "This molecule has %d atoms and %d residues\n",
453 /* if the information is present... */
454 for (i = 0; (i < at->nr); i++)
456 ri = at->atom[i].resind;
457 if ((i == 0 || ri != at->atom[i-1].resind) &&
458 at->resinfo[ri].rtp != NULL)
460 qres = get_residue_charge(at, i);
461 fprintf(out, "; residue %3d %-3s rtp %-4s q ",
463 *at->resinfo[ri].name,
464 *at->resinfo[ri].rtp);
465 if (fabs(qres) < 0.001)
467 fprintf(out, " %s", "0.0");
471 fprintf(out, "%+3.1f", qres);
475 tpA = at->atom[i].type;
476 if ((tpnmA = get_atomtype_name(tpA, atype)) == NULL)
478 gmx_fatal(FARGS, "tpA = %d, i= %d in print_atoms", tpA, i);
481 fprintf(out, "%6d %10s %6d%c %5s %6s %6d %10g %10g",
486 *(at->resinfo[at->atom[i].resind].rtp) :
487 *(at->resinfo[at->atom[i].resind].name),
488 *(at->atomname[i]), cgnr[i],
489 at->atom[i].q, at->atom[i].m);
490 if (PERTURBED(at->atom[i]))
492 tpB = at->atom[i].typeB;
493 if ((tpnmB = get_atomtype_name(tpB, atype)) == NULL)
495 gmx_fatal(FARGS, "tpB = %d, i= %d in print_atoms", tpB, i);
497 fprintf(out, " %6s %10g %10g",
498 tpnmB, at->atom[i].qB, at->atom[i].mB);
500 qtot += (double)at->atom[i].q;
501 if (fabs(qtot) < 4*GMX_REAL_EPS)
505 fprintf(out, " ; qtot %.4g\n", qtot);
512 void print_bondeds(FILE *out, int natoms, directive d,
513 int ftype, int fsubtype, t_params plist[])
516 gpp_atomtype_t atype;
521 atype = init_atomtype();
525 for (i = 0; (i < natoms); i++)
528 sprintf(buf, "%4d", (i+1));
529 add_atomtype(atype, &stab, a, buf, param, 0, 0, 0, 0, 0, 0, 0);
531 print_bt(out, d, atype, ftype, fsubtype, plist, TRUE);
536 done_atomtype(atype);