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) 2013, 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.
54 #include "gmx_fatal.h"
56 #include "gpp_atomtype.h"
57 #include "gpp_bond_atomtype.h"
59 void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype_t atype,
64 real c, bi, bj, ci, cj, ci0, ci1, ci2, cj0, cj1, cj2;
67 /* Lean mean shortcuts */
68 nr = get_atomtype_ntypes(atype);
70 snew(plist->param, nr*nr);
73 /* Fill the matrix with force parameters */
81 for (i = k = 0; (i < nr); i++)
83 for (j = 0; (j < nr); j++, k++)
85 for (nf = 0; (nf < nrfp); nf++)
87 ci = get_atomtype_nbparam(i, nf, atype);
88 cj = get_atomtype_nbparam(j, nf, atype);
90 plist->param[k].c[nf] = c;
96 case eCOMB_ARITHMETIC:
97 /* c0 and c1 are epsilon and sigma */
98 for (i = k = 0; (i < nr); i++)
100 for (j = 0; (j < nr); j++, k++)
102 ci0 = get_atomtype_nbparam(i, 0, atype);
103 cj0 = get_atomtype_nbparam(j, 0, atype);
104 ci1 = get_atomtype_nbparam(i, 1, atype);
105 cj1 = get_atomtype_nbparam(j, 1, atype);
106 plist->param[k].c[0] = (ci0+cj0)*0.5;
107 plist->param[k].c[1] = sqrt(ci1*cj1);
112 case eCOMB_GEOM_SIG_EPS:
113 /* c0 and c1 are epsilon and sigma */
114 for (i = k = 0; (i < nr); i++)
116 for (j = 0; (j < nr); j++, k++)
118 ci0 = get_atomtype_nbparam(i, 0, atype);
119 cj0 = get_atomtype_nbparam(j, 0, atype);
120 ci1 = get_atomtype_nbparam(i, 1, atype);
121 cj1 = get_atomtype_nbparam(j, 1, atype);
122 plist->param[k].c[0] = sqrt(ci0*cj0);
123 plist->param[k].c[1] = sqrt(ci1*cj1);
129 gmx_fatal(FARGS, "No such combination rule %d", comb);
133 gmx_incons("Topology processing, generate nb parameters");
138 /* Buckingham rules */
139 for (i = k = 0; (i < nr); i++)
141 for (j = 0; (j < nr); j++, k++)
143 ci0 = get_atomtype_nbparam(i, 0, atype);
144 cj0 = get_atomtype_nbparam(j, 0, atype);
145 ci2 = get_atomtype_nbparam(i, 2, atype);
146 cj2 = get_atomtype_nbparam(j, 2, atype);
147 bi = get_atomtype_nbparam(i, 1, atype);
148 bj = get_atomtype_nbparam(j, 1, atype);
149 plist->param[k].c[0] = sqrt(ci0 * cj0);
150 if ((bi == 0) || (bj == 0))
152 plist->param[k].c[1] = 0;
156 plist->param[k].c[1] = 2.0/(1/bi+1/bj);
158 plist->param[k].c[2] = sqrt(ci2 * cj2);
164 sprintf(errbuf, "Invalid nonbonded type %s",
165 interaction_function[ftype].longname);
166 warning_error(wi, errbuf);
170 static void realloc_nb_params(gpp_atomtype_t at,
171 t_nbparam ***nbparam, t_nbparam ***pair)
173 /* Add space in the non-bonded parameters matrix */
174 int atnr = get_atomtype_ntypes(at);
175 srenew(*nbparam, atnr);
176 snew((*nbparam)[atnr-1], atnr);
180 snew((*pair)[atnr-1], atnr);
184 static void copy_B_from_A(int ftype, double *c)
188 nrfpA = NRFPA(ftype);
189 nrfpB = NRFPB(ftype);
191 /* Copy the B parameters from the first nrfpB A parameters */
192 for (i = 0; (i < nrfpB); i++)
198 void push_at (t_symtab *symtab, gpp_atomtype_t at, t_bond_atomtype bat,
199 char *line, int nb_funct,
200 t_nbparam ***nbparam, t_nbparam ***pair,
207 t_xlate xl[eptNR] = {
215 int nr, i, nfields, j, pt, nfp0 = -1;
216 int batype_nr, nread;
217 char type[STRLEN], btype[STRLEN], ptype[STRLEN];
219 double c[MAXFORCEPARAM];
220 double radius, vol, surftens, gb_radius, S_hct;
221 char tmpfield[12][100]; /* Max 12 fields of width 100 */
226 gmx_bool have_atomic_number;
227 gmx_bool have_bonded_type;
232 /* First assign input line to temporary array */
233 nfields = sscanf(line, "%s%s%s%s%s%s%s%s%s%s%s%s",
234 tmpfield[0], tmpfield[1], tmpfield[2], tmpfield[3], tmpfield[4], tmpfield[5],
235 tmpfield[6], tmpfield[7], tmpfield[8], tmpfield[9], tmpfield[10], tmpfield[11]);
237 /* Comments on optional fields in the atomtypes section:
239 * The force field format is getting a bit old. For OPLS-AA we needed
240 * to add a special bonded atomtype, and for Gerrit Groenhofs QM/MM stuff
241 * we also needed the atomic numbers.
242 * To avoid making all old or user-generated force fields unusable we
243 * have introduced both these quantities as optional columns, and do some
244 * acrobatics to check whether they are present or not.
245 * This will all look much nicer when we switch to XML... sigh.
247 * Field 0 (mandatory) is the nonbonded type name. (string)
248 * Field 1 (optional) is the bonded type (string)
249 * Field 2 (optional) is the atomic number (int)
250 * Field 3 (mandatory) is the mass (numerical)
251 * Field 4 (mandatory) is the charge (numerical)
252 * Field 5 (mandatory) is the particle type (single character)
253 * This is followed by a number of nonbonded parameters.
255 * The safest way to identify the format is the particle type field.
257 * So, here is what we do:
259 * A. Read in the first six fields as strings
260 * B. If field 3 (starting from 0) is a single char, we have neither
261 * bonded_type or atomic numbers.
262 * C. If field 5 is a single char we have both.
263 * D. If field 4 is a single char we check field 1. If this begins with
264 * an alphabetical character we have bonded types, otherwise atomic numbers.
273 if ( (strlen(tmpfield[5]) == 1) && isalpha(tmpfield[5][0]) )
275 have_bonded_type = TRUE;
276 have_atomic_number = TRUE;
278 else if ( (strlen(tmpfield[3]) == 1) && isalpha(tmpfield[3][0]) )
280 have_bonded_type = FALSE;
281 have_atomic_number = FALSE;
285 have_bonded_type = ( isalpha(tmpfield[1][0]) != 0 );
286 have_atomic_number = !have_bonded_type;
289 /* optional fields */
303 if (have_atomic_number)
305 if (have_bonded_type)
307 nread = sscanf(line, "%s%s%d%lf%lf%s%lf%lf%lf%lf%lf%lf",
308 type, btype, &atomnr, &m, &q, ptype, &c[0], &c[1],
309 &radius, &vol, &surftens, &gb_radius);
318 /* have_atomic_number && !have_bonded_type */
319 nread = sscanf(line, "%s%d%lf%lf%s%lf%lf%lf%lf%lf%lf",
320 type, &atomnr, &m, &q, ptype, &c[0], &c[1],
321 &radius, &vol, &surftens, &gb_radius);
331 if (have_bonded_type)
333 /* !have_atomic_number && have_bonded_type */
334 nread = sscanf(line, "%s%s%lf%lf%s%lf%lf%lf%lf%lf%lf",
335 type, btype, &m, &q, ptype, &c[0], &c[1],
336 &radius, &vol, &surftens, &gb_radius);
345 /* !have_atomic_number && !have_bonded_type */
346 nread = sscanf(line, "%s%lf%lf%s%lf%lf%lf%lf%lf%lf",
347 type, &m, &q, ptype, &c[0], &c[1],
348 &radius, &vol, &surftens, &gb_radius);
357 if (!have_bonded_type)
362 if (!have_atomic_number)
372 if (have_atomic_number)
374 if (have_bonded_type)
376 nread = sscanf(line, "%s%s%d%lf%lf%s%lf%lf%lf%lf%lf%lf%lf",
377 type, btype, &atomnr, &m, &q, ptype, &c[0], &c[1], &c[2],
378 &radius, &vol, &surftens, &gb_radius);
387 /* have_atomic_number && !have_bonded_type */
388 nread = sscanf(line, "%s%d%lf%lf%s%lf%lf%lf%lf%lf%lf%lf",
389 type, &atomnr, &m, &q, ptype, &c[0], &c[1], &c[2],
390 &radius, &vol, &surftens, &gb_radius);
400 if (have_bonded_type)
402 /* !have_atomic_number && have_bonded_type */
403 nread = sscanf(line, "%s%s%lf%lf%s%lf%lf%lf%lf%lf%lf%lf",
404 type, btype, &m, &q, ptype, &c[0], &c[1], &c[2],
405 &radius, &vol, &surftens, &gb_radius);
414 /* !have_atomic_number && !have_bonded_type */
415 nread = sscanf(line, "%s%lf%lf%s%lf%lf%lf%lf%lf%lf%lf",
416 type, &m, &q, ptype, &c[0], &c[1], &c[2],
417 &radius, &vol, &surftens, &gb_radius);
426 if (!have_bonded_type)
431 if (!have_atomic_number)
439 gmx_fatal(FARGS, "Invalid function type %d in push_at %s %d", nb_funct,
442 for (j = nfp0; (j < MAXFORCEPARAM); j++)
447 if (strlen(type) == 1 && isdigit(type[0]))
449 gmx_fatal(FARGS, "Atom type names can't be single digits.");
452 if (strlen(btype) == 1 && isdigit(btype[0]))
454 gmx_fatal(FARGS, "Bond atom type names can't be single digits.");
457 /* Hack to read old topologies */
458 if (gmx_strcasecmp(ptype, "D") == 0)
462 for (j = 0; (j < eptNR); j++)
464 if (gmx_strcasecmp(ptype, xl[j].entry) == 0)
471 gmx_fatal(FARGS, "Invalid particle type %s on line %s",
477 fprintf(debug, "ptype: %s\n", ptype_str[pt]);
483 for (i = 0; (i < MAXFORCEPARAM); i++)
488 if ((batype_nr = get_bond_atomtype_type(btype, bat)) == NOTSET)
490 add_bond_atomtype(bat, symtab, btype);
492 batype_nr = get_bond_atomtype_type(btype, bat);
494 if ((nr = get_atomtype_type(type, at)) != NOTSET)
496 sprintf(errbuf, "Overriding atomtype %s", type);
498 if ((nr = set_atomtype(nr, at, symtab, atom, type, param, batype_nr,
499 radius, vol, surftens, atomnr, gb_radius, S_hct)) == NOTSET)
501 gmx_fatal(FARGS, "Replacing atomtype %s failed", type);
504 else if ((nr = add_atomtype(at, symtab, atom, type, param,
505 batype_nr, radius, vol,
506 surftens, atomnr, gb_radius, S_hct)) == NOTSET)
508 gmx_fatal(FARGS, "Adding atomtype %s failed", type);
512 /* Add space in the non-bonded parameters matrix */
513 realloc_nb_params(at, nbparam, pair);
519 static void push_bondtype(t_params * bt,
523 gmx_bool bAllowRepeat,
528 gmx_bool bTest, bFound, bCont, bId;
530 int nrfp = NRFP(ftype);
533 /* If bAllowRepeat is TRUE, we allow multiple entries as long as they
534 are on directly _adjacent_ lines.
537 /* First check if our atomtypes are _identical_ (not reversed) to the previous
538 entry. If they are not identical we search for earlier duplicates. If they are
539 we can skip it, since we already searched for the first line
546 if (bAllowRepeat && nr > 1)
548 for (j = 0, bCont = TRUE; (j < nral); j++)
550 bCont = bCont && (b->a[j] == bt->param[nr-2].a[j]);
554 /* Search for earlier duplicates if this entry was not a continuation
555 from the previous line.
560 for (i = 0; (i < nr); i++)
563 for (j = 0; (j < nral); j++)
565 bTest = (bTest && (b->a[j] == bt->param[i].a[j]));
570 for (j = 0; (j < nral); j++)
572 bTest = (bTest && (b->a[nral-1-j] == bt->param[i].a[j]));
580 for (j = 0; (j < nrfp); j++)
582 bId = bId && (bt->param[i].c[j] == b->c[j]);
586 sprintf(errbuf, "Overriding %s parameters.%s",
587 interaction_function[ftype].longname,
588 (ftype == F_PDIHS) ? "\nUse dihedraltype 4 to allow several multiplicity terms." : "");
590 fprintf(stderr, " old:");
591 for (j = 0; (j < nrfp); j++)
593 fprintf(stderr, " %g", bt->param[i].c[j]);
595 fprintf(stderr, " \n new: %s\n\n", line);
599 for (j = 0; (j < nrfp); j++)
601 bt->param[i].c[j] = b->c[j];
612 /* fill the arrays up and down */
613 memcpy(bt->param[bt->nr].c, b->c, sizeof(b->c));
614 memcpy(bt->param[bt->nr].a, b->a, sizeof(b->a));
615 memcpy(bt->param[bt->nr+1].c, b->c, sizeof(b->c));
617 /* The definitions of linear angles depend on the order of atoms,
618 * that means that for atoms i-j-k, with certain parameter a, the
619 * corresponding k-j-i angle will have parameter 1-a.
621 if (ftype == F_LINEAR_ANGLES)
623 bt->param[bt->nr+1].c[0] = 1-bt->param[bt->nr+1].c[0];
624 bt->param[bt->nr+1].c[2] = 1-bt->param[bt->nr+1].c[2];
627 for (j = 0; (j < nral); j++)
629 bt->param[bt->nr+1].a[j] = b->a[nral-1-j];
636 void push_bt(directive d, t_params bt[], int nral,
638 t_bond_atomtype bat, char *line,
641 const char *formal[MAXATOMLIST+1] = {
650 const char *formnl[MAXATOMLIST+1] = {
656 "%*s%*s%*s%*s%*s%*s",
657 "%*s%*s%*s%*s%*s%*s%*s"
659 const char *formlf = "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf";
660 int i, ft, ftype, nn, nrfp, nrfpA, nrfpB;
662 char alc[MAXATOMLIST+1][20];
663 /* One force parameter more, so we can check if we read too many */
664 double c[MAXFORCEPARAM+1];
668 if ((bat && at) || (!bat && !at))
670 gmx_incons("You should pass either bat or at to push_bt");
673 /* Make format string (nral ints+functype) */
674 if ((nn = sscanf(line, formal[nral],
675 alc[0], alc[1], alc[2], alc[3], alc[4], alc[5])) != nral+1)
677 sprintf(errbuf, "Not enough atomtypes (%d instead of %d)", nn-1, nral);
678 warning_error(wi, errbuf);
682 ft = strtol(alc[nral], NULL, 10);
683 ftype = ifunc_index(d, ft);
685 nrfpA = interaction_function[ftype].nrfpA;
686 nrfpB = interaction_function[ftype].nrfpB;
687 strcpy(f1, formnl[nral]);
689 if ((nn = sscanf(line, f1, &c[0], &c[1], &c[2], &c[3], &c[4], &c[5], &c[6], &c[7], &c[8], &c[9], &c[10], &c[11], &c[12]))
694 /* Copy the B-state from the A-state */
695 copy_B_from_A(ftype, c);
701 warning_error(wi, "Not enough parameters");
703 else if (nn > nrfpA && nn < nrfp)
705 warning_error(wi, "Too many parameters or not enough parameters for topology B");
709 warning_error(wi, "Too many parameters");
711 for (i = nn; (i < nrfp); i++)
717 for (i = 0; (i < nral); i++)
719 if (at && ((p.a[i] = get_atomtype_type(alc[i], at)) == NOTSET))
721 gmx_fatal(FARGS, "Unknown atomtype %s\n", alc[i]);
723 else if (bat && ((p.a[i] = get_bond_atomtype_type(alc[i], bat)) == NOTSET))
725 gmx_fatal(FARGS, "Unknown bond_atomtype %s\n", alc[i]);
728 for (i = 0; (i < nrfp); i++)
732 push_bondtype (&(bt[ftype]), &p, nral, ftype, FALSE, line, wi);
736 void push_dihedraltype(directive d, t_params bt[],
737 t_bond_atomtype bat, char *line,
740 const char *formal[MAXATOMLIST+1] = {
749 const char *formnl[MAXATOMLIST+1] = {
755 "%*s%*s%*s%*s%*s%*s",
756 "%*s%*s%*s%*s%*s%*s%*s"
758 const char *formlf[MAXFORCEPARAM] = {
764 "%lf%lf%lf%lf%lf%lf",
765 "%lf%lf%lf%lf%lf%lf%lf",
766 "%lf%lf%lf%lf%lf%lf%lf%lf",
767 "%lf%lf%lf%lf%lf%lf%lf%lf%lf",
768 "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
769 "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
770 "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
772 int i, ft, ftype, nn, nrfp, nrfpA, nrfpB, nral;
774 char alc[MAXATOMLIST+1][20];
775 double c[MAXFORCEPARAM];
777 gmx_bool bAllowRepeat;
780 /* This routine accepts dihedraltypes defined from either 2 or 4 atoms.
782 * We first check for 2 atoms with the 3th column being an integer
783 * defining the type. If this isn't the case, we try it with 4 atoms
784 * and the 5th column defining the dihedral type.
786 nn = sscanf(line, formal[4], alc[0], alc[1], alc[2], alc[3], alc[4]);
787 if (nn >= 3 && strlen(alc[2]) == 1 && isdigit(alc[2][0]))
790 ft = strtol(alc[nral], NULL, 10);
791 /* Move atom types around a bit and use 'X' for wildcard atoms
792 * to create a 4-atom dihedral definition with arbitrary atoms in
795 if (alc[2][0] == '2')
797 /* improper - the two atomtypes are 1,4. Use wildcards for 2,3 */
798 strcpy(alc[3], alc[1]);
799 sprintf(alc[2], "X");
800 sprintf(alc[1], "X");
801 /* alc[0] stays put */
805 /* proper - the two atomtypes are 2,3. Use wildcards for 1,4 */
806 sprintf(alc[3], "X");
807 strcpy(alc[2], alc[1]);
808 strcpy(alc[1], alc[0]);
809 sprintf(alc[0], "X");
812 else if (nn == 5 && strlen(alc[4]) == 1 && isdigit(alc[4][0]))
815 ft = strtol(alc[nral], NULL, 10);
819 sprintf(errbuf, "Incorrect number of atomtypes for dihedral (%d instead of 2 or 4)", nn-1);
820 warning_error(wi, errbuf);
826 /* Previously, we have always overwritten parameters if e.g. a torsion
827 with the same atomtypes occurs on multiple lines. However, CHARMM and
828 some other force fields specify multiple dihedrals over some bonds,
829 including cosines with multiplicity 6 and somethimes even higher.
830 Thus, they cannot be represented with Ryckaert-Bellemans terms.
831 To add support for these force fields, Dihedral type 9 is identical to
832 normal proper dihedrals, but repeated entries are allowed.
839 bAllowRepeat = FALSE;
843 ftype = ifunc_index(d, ft);
845 nrfpA = interaction_function[ftype].nrfpA;
846 nrfpB = interaction_function[ftype].nrfpB;
848 strcpy(f1, formnl[nral]);
849 strcat(f1, formlf[nrfp-1]);
851 /* Check number of parameters given */
852 if ((nn = sscanf(line, f1, &c[0], &c[1], &c[2], &c[3], &c[4], &c[5], &c[6], &c[7], &c[8], &c[9], &c[10], &c[11]))
857 /* Copy the B-state from the A-state */
858 copy_B_from_A(ftype, c);
864 warning_error(wi, "Not enough parameters");
866 else if (nn > nrfpA && nn < nrfp)
868 warning_error(wi, "Too many parameters or not enough parameters for topology B");
872 warning_error(wi, "Too many parameters");
874 for (i = nn; (i < nrfp); i++)
881 for (i = 0; (i < 4); i++)
883 if (!strcmp(alc[i], "X"))
889 if ((p.a[i] = get_bond_atomtype_type(alc[i], bat)) == NOTSET)
891 gmx_fatal(FARGS, "Unknown bond_atomtype %s", alc[i]);
895 for (i = 0; (i < nrfp); i++)
899 /* Always use 4 atoms here, since we created two wildcard atoms
900 * if there wasn't of them 4 already.
902 push_bondtype (&(bt[ftype]), &p, 4, ftype, bAllowRepeat, line, wi);
906 void push_nbt(directive d, t_nbparam **nbt, gpp_atomtype_t atype,
907 char *pline, int nb_funct,
911 const char *form2 = "%*s%*s%*s%lf%lf";
912 const char *form3 = "%*s%*s%*s%lf%lf%lf";
913 const char *form4 = "%*s%*s%*s%lf%lf%lf%lf";
914 const char *form5 = "%*s%*s%*s%lf%lf%lf%lf%lf";
916 int i, f, n, ftype, atnr, nrfp;
924 if (sscanf (pline, "%s%s%d", a0, a1, &f) != 3)
930 ftype = ifunc_index(d, f);
932 if (ftype != nb_funct)
934 sprintf(errbuf, "Trying to add %s while the default nonbond type is %s",
935 interaction_function[ftype].longname,
936 interaction_function[nb_funct].longname);
937 warning_error(wi, errbuf);
941 /* Get the force parameters */
945 n = sscanf(pline, form4, &c[0], &c[1], &c[2], &c[3]);
951 /* When the B topology parameters are not set,
952 * copy them from topology A
954 for (i = n; i < nrfp; i++)
959 else if (ftype == F_LJC14_Q)
961 n = sscanf(pline, form5, &c[0], &c[1], &c[2], &c[3], &dum);
964 incorrect_n_param(wi);
970 if (sscanf(pline, form3, &c[0], &c[1], &dum) != 2)
972 incorrect_n_param(wi);
978 if (sscanf(pline, form4, &c[0], &c[1], &c[2], &dum) != 3)
980 incorrect_n_param(wi);
986 gmx_fatal(FARGS, "Number of force parameters for nonbonded interactions is %d"
987 " in file %s, line %d", nrfp, __FILE__, __LINE__);
989 for (i = 0; (i < nrfp); i++)
994 /* Put the parameters in the matrix */
995 if ((ai = get_atomtype_type (a0, atype)) == NOTSET)
997 gmx_fatal(FARGS, "Atomtype %s not found", a0);
999 if ((aj = get_atomtype_type (a1, atype)) == NOTSET)
1001 gmx_fatal(FARGS, "Atomtype %s not found", a1);
1003 nbp = &(nbt[max(ai, aj)][min(ai, aj)]);
1008 for (i = 0; i < nrfp; i++)
1010 bId = bId && (nbp->c[i] == cr[i]);
1014 sprintf(errbuf, "Overriding non-bonded parameters,");
1015 warning(wi, errbuf);
1016 fprintf(stderr, " old:");
1017 for (i = 0; i < nrfp; i++)
1019 fprintf(stderr, " %g", nbp->c[i]);
1021 fprintf(stderr, " new\n%s\n", pline);
1025 for (i = 0; i < nrfp; i++)
1032 push_gb_params (gpp_atomtype_t at, char *line,
1037 double radius, vol, surftens, gb_radius, S_hct;
1038 char atypename[STRLEN];
1039 char errbuf[STRLEN];
1041 if ( (nfield = sscanf(line, "%s%lf%lf%lf%lf%lf", atypename, &radius, &vol, &surftens, &gb_radius, &S_hct)) != 6)
1043 sprintf(errbuf, "Too few gb parameters for type %s\n", atypename);
1044 warning(wi, errbuf);
1047 /* Search for atomtype */
1048 atype = get_atomtype_type(atypename, at);
1050 if (atype == NOTSET)
1052 printf("Couldn't find topology match for atomtype %s\n", atypename);
1056 set_atomtype_gbparam(at, atype, radius, vol, surftens, gb_radius, S_hct);
1060 push_cmaptype(directive d, t_params bt[], int nral, gpp_atomtype_t at,
1061 t_bond_atomtype bat, char *line,
1064 const char *formal = "%s%s%s%s%s%s%s%s";
1066 int i, j, ft, ftype, nn, nrfp, nrfpA, nrfpB;
1068 int nxcmap, nycmap, ncmap, read_cmap, sl, nct;
1069 char s[20], alc[MAXATOMLIST+2][20];
1071 gmx_bool bAllowRepeat;
1074 /* Keep the compiler happy */
1078 if ((nn = sscanf(line, formal, alc[0], alc[1], alc[2], alc[3], alc[4], alc[5], alc[6], alc[7])) != nral+3)
1080 sprintf(errbuf, "Incorrect number of atomtypes for cmap (%d instead of 5)", nn-1);
1081 warning_error(wi, errbuf);
1085 /* Compute an offset for each line where the cmap parameters start
1086 * ie. where the atom types and grid spacing information ends
1088 for (i = 0; i < nn; i++)
1090 start += (int)strlen(alc[i]);
1093 /* There are nn-1 spaces between the atom types and the grid spacing info in the cmap.itp file */
1094 /* start is the position on the line where we start to read the actual cmap grid data from the itp file */
1095 start = start + nn -1;
1097 ft = strtol(alc[nral], NULL, 10);
1098 nxcmap = strtol(alc[nral+1], NULL, 10);
1099 nycmap = strtol(alc[nral+2], NULL, 10);
1101 /* Check for equal grid spacing in x and y dims */
1102 if (nxcmap != nycmap)
1104 gmx_fatal(FARGS, "Not the same grid spacing in x and y for cmap grid: x=%d, y=%d", nxcmap, nycmap);
1107 ncmap = nxcmap*nycmap;
1108 ftype = ifunc_index(d, ft);
1109 nrfpA = strtol(alc[6], NULL, 10)*strtol(alc[6], NULL, 10);
1110 nrfpB = strtol(alc[7], NULL, 10)*strtol(alc[7], NULL, 10);
1113 /* Allocate memory for the CMAP grid */
1115 srenew(bt->cmap, bt->ncmap);
1117 /* Read in CMAP parameters */
1119 for (i = 0; i < ncmap; i++)
1121 while (isspace(*(line+start+sl)))
1125 nn = sscanf(line+start+sl, " %s ", s);
1127 bt->cmap[i+(bt->ncmap)-nrfp] = strtod(s, NULL);
1135 gmx_fatal(FARGS, "Error in reading cmap parameter for angle %s %s %s %s %s", alc[0], alc[1], alc[2], alc[3], alc[4]);
1140 /* Check do that we got the number of parameters we expected */
1141 if (read_cmap == nrfpA)
1143 for (i = 0; i < ncmap; i++)
1145 bt->cmap[i+ncmap] = bt->cmap[i];
1150 if (read_cmap < nrfpA)
1152 warning_error(wi, "Not enough cmap parameters");
1154 else if (read_cmap > nrfpA && read_cmap < nrfp)
1156 warning_error(wi, "Too many cmap parameters or not enough parameters for topology B");
1158 else if (read_cmap > nrfp)
1160 warning_error(wi, "Too many cmap parameters");
1165 /* Set grid spacing and the number of grids (we assume these numbers to be the same for all grids
1166 * so we can safely assign them each time
1168 bt->grid_spacing = nxcmap; /* Or nycmap, they need to be equal */
1169 bt->nc = bt->nc + 1; /* Since we are incrementing here, we need to subtract later, see (*****) */
1170 nct = (nral+1) * bt->nc;
1172 /* Allocate memory for the cmap_types information */
1173 srenew(bt->cmap_types, nct);
1175 for (i = 0; (i < nral); i++)
1177 if (at && ((p.a[i] = get_bond_atomtype_type(alc[i], bat)) == NOTSET))
1179 gmx_fatal(FARGS, "Unknown atomtype %s\n", alc[i]);
1181 else if (bat && ((p.a[i] = get_bond_atomtype_type(alc[i], bat)) == NOTSET))
1183 gmx_fatal(FARGS, "Unknown bond_atomtype %s\n", alc[i]);
1186 /* Assign a grid number to each cmap_type */
1187 bt->cmap_types[bt->nct++] = get_bond_atomtype_type(alc[i], bat);
1190 /* Assign a type number to this cmap */
1191 bt->cmap_types[bt->nct++] = bt->nc-1; /* Since we inremented earlier, we need to subtrac here, to get the types right (****) */
1193 /* Check for the correct number of atoms (again) */
1196 gmx_fatal(FARGS, "Incorrect number of atom types (%d) in cmap type %d\n", nct, bt->nc);
1199 /* Is this correct?? */
1200 for (i = 0; i < MAXFORCEPARAM; i++)
1205 /* Push the bond to the bondlist */
1206 push_bondtype (&(bt[ftype]), &p, nral, ftype, FALSE, line, wi);
1210 static void push_atom_now(t_symtab *symtab, t_atoms *at, int atomnr,
1212 int type, char *ctype, int ptype,
1214 char *resname, char *name, real m0, real q0,
1215 int typeB, char *ctypeB, real mB, real qB)
1217 int j, resind = 0, resnr;
1221 if (((nr == 0) && (atomnr != 1)) || (nr && (atomnr != at->nr+1)))
1223 gmx_fatal(FARGS, "Atoms in the .top are not numbered consecutively from 1 (rather, atomnr = %d, while at->nr = %d)", atomnr, at->nr);
1226 j = strlen(resnumberic) - 1;
1227 if (isdigit(resnumberic[j]))
1233 ric = resnumberic[j];
1234 if (j == 0 || !isdigit(resnumberic[j-1]))
1236 gmx_fatal(FARGS, "Invalid residue number '%s' for atom %d",
1237 resnumberic, atomnr);
1240 resnr = strtol(resnumberic, NULL, 10);
1244 resind = at->atom[nr-1].resind;
1246 if (nr == 0 || strcmp(resname, *at->resinfo[resind].name) != 0 ||
1247 resnr != at->resinfo[resind].nr ||
1248 ric != at->resinfo[resind].ic)
1258 at->nres = resind + 1;
1259 srenew(at->resinfo, at->nres);
1260 at->resinfo[resind].name = put_symtab(symtab, resname);
1261 at->resinfo[resind].nr = resnr;
1262 at->resinfo[resind].ic = ric;
1266 resind = at->atom[at->nr-1].resind;
1269 /* New atom instance
1270 * get new space for arrays
1272 srenew(at->atom, nr+1);
1273 srenew(at->atomname, nr+1);
1274 srenew(at->atomtype, nr+1);
1275 srenew(at->atomtypeB, nr+1);
1278 at->atom[nr].type = type;
1279 at->atom[nr].ptype = ptype;
1280 at->atom[nr].q = q0;
1281 at->atom[nr].m = m0;
1282 at->atom[nr].typeB = typeB;
1283 at->atom[nr].qB = qB;
1284 at->atom[nr].mB = mB;
1286 at->atom[nr].resind = resind;
1287 at->atom[nr].atomnumber = atomicnumber;
1288 at->atomname[nr] = put_symtab(symtab, name);
1289 at->atomtype[nr] = put_symtab(symtab, ctype);
1290 at->atomtypeB[nr] = put_symtab(symtab, ctypeB);
1294 void push_cg(t_block *block, int *lastindex, int index, int a)
1298 fprintf (debug, "Index %d, Atom %d\n", index, a);
1301 if (((block->nr) && (*lastindex != index)) || (!block->nr))
1303 /* add a new block */
1305 srenew(block->index, block->nr+1);
1307 block->index[block->nr] = a + 1;
1311 void push_atom(t_symtab *symtab, t_block *cgs,
1312 t_atoms *at, gpp_atomtype_t atype, char *line, int *lastcg,
1316 int cgnumber, atomnr, type, typeB, nscan;
1317 char id[STRLEN], ctype[STRLEN], ctypeB[STRLEN],
1318 resnumberic[STRLEN], resname[STRLEN], name[STRLEN], check[STRLEN];
1319 double m, q, mb, qb;
1320 real m0, q0, mB, qB;
1322 /* Make a shortcut for writing in this molecule */
1325 /* Fixed parameters */
1326 if (sscanf(line, "%s%s%s%s%s%d",
1327 id, ctype, resnumberic, resname, name, &cgnumber) != 6)
1332 sscanf(id, "%d", &atomnr);
1333 if ((type = get_atomtype_type(ctype, atype)) == NOTSET)
1335 gmx_fatal(FARGS, "Atomtype %s not found", ctype);
1337 ptype = get_atomtype_ptype(type, atype);
1339 /* Set default from type */
1340 q0 = get_atomtype_qA(type, atype);
1341 m0 = get_atomtype_massA(type, atype);
1346 /* Optional parameters */
1347 nscan = sscanf(line, "%*s%*s%*s%*s%*s%*s%lf%lf%s%lf%lf%s",
1348 &q, &m, ctypeB, &qb, &mb, check);
1350 /* Nasty switch that falls thru all the way down! */
1359 if ((typeB = get_atomtype_type(ctypeB, atype)) == NOTSET)
1361 gmx_fatal(FARGS, "Atomtype %s not found", ctypeB);
1363 qB = get_atomtype_qA(typeB, atype);
1364 mB = get_atomtype_massA(typeB, atype);
1373 warning_error(wi, "Too many parameters");
1382 fprintf(debug, "mB=%g, qB=%g, typeB=%d\n", mB, qB, typeB);
1385 push_cg(cgs, lastcg, cgnumber, nr);
1387 push_atom_now(symtab, at, atomnr, get_atomtype_atomnumber(type, atype),
1388 type, ctype, ptype, resnumberic,
1389 resname, name, m0, q0, typeB,
1390 typeB == type ? ctype : ctypeB, mB, qB);
1393 void push_molt(t_symtab *symtab, int *nmol, t_molinfo **mol, char *line,
1400 if ((sscanf(line, "%s%d", type, &nrexcl)) != 2)
1402 warning_error(wi, "Expected a molecule type name and nrexcl");
1405 /* Test if this atomtype overwrites another */
1409 if (gmx_strcasecmp(*((*mol)[i].name), type) == 0)
1411 gmx_fatal(FARGS, "moleculetype %s is redefined", type);
1417 srenew(*mol, *nmol);
1418 newmol = &((*mol)[*nmol-1]);
1419 init_molinfo(newmol);
1421 /* Fill in the values */
1422 newmol->name = put_symtab(symtab, type);
1423 newmol->nrexcl = nrexcl;
1424 newmol->excl_set = FALSE;
1427 static gmx_bool default_nb_params(int ftype, t_params bt[], t_atoms *at,
1428 t_param *p, int c_start, gmx_bool bB, gmx_bool bGenPairs)
1430 int i, j, ti, tj, ntype;
1433 int nr = bt[ftype].nr;
1434 int nral = NRAL(ftype);
1435 int nrfp = interaction_function[ftype].nrfpA;
1436 int nrfpB = interaction_function[ftype].nrfpB;
1438 if ((!bB && nrfp == 0) || (bB && nrfpB == 0))
1446 /* First test the generated-pair position to save
1447 * time when we have 1000*1000 entries for e.g. OPLS...
1452 ti = at->atom[p->a[0]].typeB;
1453 tj = at->atom[p->a[1]].typeB;
1457 ti = at->atom[p->a[0]].type;
1458 tj = at->atom[p->a[1]].type;
1460 pi = &(bt[ftype].param[ntype*ti+tj]);
1461 bFound = ((ti == pi->a[0]) && (tj == pi->a[1]));
1464 /* Search explicitly if we didnt find it */
1467 for (i = 0; ((i < nr) && !bFound); i++)
1469 pi = &(bt[ftype].param[i]);
1472 for (j = 0; ((j < nral) &&
1473 (at->atom[p->a[j]].typeB == pi->a[j])); j++)
1480 for (j = 0; ((j < nral) &&
1481 (at->atom[p->a[j]].type == pi->a[j])); j++)
1486 bFound = (j == nral);
1494 if (nrfp+nrfpB > MAXFORCEPARAM)
1496 gmx_incons("Too many force parameters");
1498 for (j = c_start; (j < nrfpB); j++)
1500 p->c[nrfp+j] = pi->c[j];
1505 for (j = c_start; (j < nrfp); j++)
1513 for (j = c_start; (j < nrfp); j++)
1521 static gmx_bool default_cmap_params(t_params bondtype[],
1522 t_atoms *at, gpp_atomtype_t atype,
1523 t_param *p, gmx_bool bB,
1524 int *cmap_type, int *nparam_def)
1526 int i, j, nparam_found;
1528 gmx_bool bFound = FALSE;
1533 /* Match the current cmap angle against the list of cmap_types */
1534 for (i = 0; i < bondtype->nct && !bFound; i += 6)
1543 (get_atomtype_batype(at->atom[p->a[0]].type, atype) == bondtype->cmap_types[i]) &&
1544 (get_atomtype_batype(at->atom[p->a[1]].type, atype) == bondtype->cmap_types[i+1]) &&
1545 (get_atomtype_batype(at->atom[p->a[2]].type, atype) == bondtype->cmap_types[i+2]) &&
1546 (get_atomtype_batype(at->atom[p->a[3]].type, atype) == bondtype->cmap_types[i+3]) &&
1547 (get_atomtype_batype(at->atom[p->a[4]].type, atype) == bondtype->cmap_types[i+4]))
1549 /* Found cmap torsion */
1551 ct = bondtype->cmap_types[i+5];
1557 /* If we did not find a matching type for this cmap torsion */
1560 gmx_fatal(FARGS, "Unknown cmap torsion between atoms %d %d %d %d %d\n",
1561 p->a[0]+1, p->a[1]+1, p->a[2]+1, p->a[3]+1, p->a[4]+1);
1564 *nparam_def = nparam_found;
1570 static gmx_bool default_params(int ftype, t_params bt[],
1571 t_atoms *at, gpp_atomtype_t atype,
1572 t_param *p, gmx_bool bB,
1573 t_param **param_def,
1576 int i, j, nparam_found;
1577 gmx_bool bFound, bSame;
1580 int nr = bt[ftype].nr;
1581 int nral = NRAL(ftype);
1582 int nrfpA = interaction_function[ftype].nrfpA;
1583 int nrfpB = interaction_function[ftype].nrfpB;
1585 if ((!bB && nrfpA == 0) || (bB && nrfpB == 0))
1591 /* We allow wildcards now. The first type (with or without wildcards) that
1592 * fits is used, so you should probably put the wildcarded bondtypes
1593 * at the end of each section.
1597 /* OPLS uses 1000s of dihedraltypes, so in order to speed up the scanning we have a
1598 * special case for this. Check for B state outside loop to speed it up.
1600 if (ftype == F_PDIHS || ftype == F_RBDIHS || ftype == F_IDIHS || ftype == F_PIDIHS)
1604 for (i = 0; ((i < nr) && !bFound); i++)
1606 pi = &(bt[ftype].param[i]);
1609 ((pi->AI == -1) || (get_atomtype_batype(at->atom[p->AI].typeB, atype) == pi->AI)) &&
1610 ((pi->AJ == -1) || (get_atomtype_batype(at->atom[p->AJ].typeB, atype) == pi->AJ)) &&
1611 ((pi->AK == -1) || (get_atomtype_batype(at->atom[p->AK].typeB, atype) == pi->AK)) &&
1612 ((pi->AL == -1) || (get_atomtype_batype(at->atom[p->AL].typeB, atype) == pi->AL))
1619 for (i = 0; ((i < nr) && !bFound); i++)
1621 pi = &(bt[ftype].param[i]);
1624 ((pi->AI == -1) || (get_atomtype_batype(at->atom[p->AI].type, atype) == pi->AI)) &&
1625 ((pi->AJ == -1) || (get_atomtype_batype(at->atom[p->AJ].type, atype) == pi->AJ)) &&
1626 ((pi->AK == -1) || (get_atomtype_batype(at->atom[p->AK].type, atype) == pi->AK)) &&
1627 ((pi->AL == -1) || (get_atomtype_batype(at->atom[p->AL].type, atype) == pi->AL))
1631 /* Find additional matches for this dihedral - necessary for ftype==9 which is used e.g. for charmm.
1632 * The rules in that case is that additional matches HAVE to be on adjacent lines!
1638 /* Continue from current i value */
1639 for (j = i+1; j < nr && bSame; j += 2)
1641 pj = &(bt[ftype].param[j]);
1642 bSame = (pi->AI == pj->AI && pi->AJ == pj->AJ && pi->AK == pj->AK && pi->AL == pj->AL);
1647 /* nparam_found will be increased as long as the numbers match */
1651 else /* Not a dihedral */
1653 for (i = 0; ((i < nr) && !bFound); i++)
1655 pi = &(bt[ftype].param[i]);
1658 for (j = 0; ((j < nral) &&
1659 (get_atomtype_batype(at->atom[p->a[j]].typeB, atype) == pi->a[j])); j++)
1666 for (j = 0; ((j < nral) &&
1667 (get_atomtype_batype(at->atom[p->a[j]].type, atype) == pi->a[j])); j++)
1672 bFound = (j == nral);
1681 *nparam_def = nparam_found;
1688 void push_bond(directive d, t_params bondtype[], t_params bond[],
1689 t_atoms *at, gpp_atomtype_t atype, char *line,
1690 gmx_bool bBonded, gmx_bool bGenPairs, real fudgeQQ,
1691 gmx_bool bZero, gmx_bool *bWarn_copy_A_B,
1694 const char *aaformat[MAXATOMLIST] = {
1702 const char *asformat[MAXATOMLIST] = {
1707 "%*s%*s%*s%*s%*s%*s",
1708 "%*s%*s%*s%*s%*s%*s%*s"
1710 const char *ccformat = "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf";
1711 int nr, i, j, nral, nral_fmt, nread, ftype;
1712 char format[STRLEN];
1713 /* One force parameter more, so we can check if we read too many */
1714 double cc[MAXFORCEPARAM+1];
1715 int aa[MAXATOMLIST+1];
1716 t_param param, paramB, *param_defA, *param_defB;
1717 gmx_bool bFoundA = FALSE, bFoundB = FALSE, bDef, bPert, bSwapParity = FALSE;
1718 int nparam_defA, nparam_defB;
1721 nparam_defA = nparam_defB = 0;
1723 ftype = ifunc_index(d, 1);
1725 for (j = 0; j < MAXATOMLIST; j++)
1729 bDef = (NRFP(ftype) > 0);
1731 if (ftype == F_SETTLE)
1733 /* SETTLE acts on 3 atoms, but the topology format only specifies
1734 * the first atom (for historical reasons).
1743 nread = sscanf(line, aaformat[nral_fmt-1],
1744 &aa[0], &aa[1], &aa[2], &aa[3], &aa[4], &aa[5]);
1746 if (ftype == F_SETTLE)
1753 if (nread < nral_fmt)
1758 else if (nread > nral_fmt)
1760 /* this is a hack to allow for virtual sites with swapped parity */
1761 bSwapParity = (aa[nral] < 0);
1764 aa[nral] = -aa[nral];
1766 ftype = ifunc_index(d, aa[nral]);
1775 gmx_fatal(FARGS, "Negative function types only allowed for %s and %s",
1776 interaction_function[F_VSITE3FAD].longname,
1777 interaction_function[F_VSITE3OUT].longname);
1783 /* Check for double atoms and atoms out of bounds */
1784 for (i = 0; (i < nral); i++)
1786 if (aa[i] < 1 || aa[i] > at->nr)
1788 gmx_fatal(FARGS, "[ file %s, line %d ]:\n"
1789 "Atom index (%d) in %s out of bounds (1-%d).\n"
1790 "This probably means that you have inserted topology section \"%s\"\n"
1791 "in a part belonging to a different molecule than you intended to.\n"
1792 "In that case move the \"%s\" section to the right molecule.",
1793 get_warning_file(wi), get_warning_line(wi),
1794 aa[i], dir2str(d), at->nr, dir2str(d), dir2str(d));
1796 for (j = i+1; (j < nral); j++)
1800 sprintf(errbuf, "Duplicate atom index (%d) in %s", aa[i], dir2str(d));
1801 warning(wi, errbuf);
1806 /* default force parameters */
1807 for (j = 0; (j < MAXATOMLIST); j++)
1809 param.a[j] = aa[j]-1;
1811 for (j = 0; (j < MAXFORCEPARAM); j++)
1816 /* Get force params for normal and free energy perturbation
1817 * studies, as determined by types!
1822 bFoundA = default_params(ftype, bondtype, at, atype, ¶m, FALSE, ¶m_defA, &nparam_defA);
1825 /* Copy the A-state and B-state default parameters */
1826 for (j = 0; (j < NRFPA(ftype)+NRFPB(ftype)); j++)
1828 param.c[j] = param_defA->c[j];
1831 bFoundB = default_params(ftype, bondtype, at, atype, ¶m, TRUE, ¶m_defB, &nparam_defB);
1834 /* Copy only the B-state default parameters */
1835 for (j = NRFPA(ftype); (j < NRFP(ftype)); j++)
1837 param.c[j] = param_defB->c[j];
1841 else if (ftype == F_LJ14)
1843 bFoundA = default_nb_params(ftype, bondtype, at, ¶m, 0, FALSE, bGenPairs);
1844 bFoundB = default_nb_params(ftype, bondtype, at, ¶m, 0, TRUE, bGenPairs);
1846 else if (ftype == F_LJC14_Q)
1848 param.c[0] = fudgeQQ;
1849 /* Fill in the A-state charges as default parameters */
1850 param.c[1] = at->atom[param.a[0]].q;
1851 param.c[2] = at->atom[param.a[1]].q;
1852 /* The default LJ parameters are the standard 1-4 parameters */
1853 bFoundA = default_nb_params(F_LJ14, bondtype, at, ¶m, 3, FALSE, bGenPairs);
1856 else if (ftype == F_LJC_PAIRS_NB)
1858 /* Defaults are not supported here */
1864 gmx_incons("Unknown function type in push_bond");
1867 if (nread > nral_fmt)
1869 /* Manually specified parameters - in this case we discard multiple torsion info! */
1871 strcpy(format, asformat[nral_fmt-1]);
1872 strcat(format, ccformat);
1874 nread = sscanf(line, format, &cc[0], &cc[1], &cc[2], &cc[3], &cc[4], &cc[5],
1875 &cc[6], &cc[7], &cc[8], &cc[9], &cc[10], &cc[11], &cc[12]);
1877 if ((nread == NRFPA(ftype)) && (NRFPB(ftype) != 0))
1879 /* We only have to issue a warning if these atoms are perturbed! */
1881 for (j = 0; (j < nral); j++)
1883 bPert = bPert || PERTURBED(at->atom[param.a[j]]);
1886 if (bPert && *bWarn_copy_A_B)
1889 "Some parameters for bonded interaction involving perturbed atoms are specified explicitly in state A, but not B - copying A to B");
1890 warning(wi, errbuf);
1891 *bWarn_copy_A_B = FALSE;
1894 /* If only the A parameters were specified, copy them to the B state */
1895 /* The B-state parameters correspond to the first nrfpB
1896 * A-state parameters.
1898 for (j = 0; (j < NRFPB(ftype)); j++)
1900 cc[nread++] = cc[j];
1904 /* If nread was 0 or EOF, no parameters were read => use defaults.
1905 * If nread was nrfpA we copied above so nread=nrfp.
1906 * If nread was nrfp we are cool.
1907 * For F_LJC14_Q we allow supplying fudgeQQ only.
1908 * Anything else is an error!
1910 if ((nread != 0) && (nread != EOF) && (nread != NRFP(ftype)) &&
1911 !(ftype == F_LJC14_Q && nread == 1))
1913 gmx_fatal(FARGS, "Incorrect number of parameters - found %d, expected %d or %d for %s.",
1914 nread, NRFPA(ftype), NRFP(ftype),
1915 interaction_function[ftype].longname);
1918 for (j = 0; (j < nread); j++)
1923 /* Check whether we have to use the defaults */
1924 if (nread == NRFP(ftype))
1933 /* nread now holds the number of force parameters read! */
1938 /* When we have multiple terms it would be very dangerous to allow perturbations to a different atom type! */
1939 if (ftype == F_PDIHS)
1941 if ((nparam_defA != nparam_defB) || ((nparam_defA > 1 || nparam_defB > 1) && (param_defA != param_defB)))
1944 "Cannot automatically perturb a torsion with multiple terms to different form.\n"
1945 "Please specify perturbed parameters manually for this torsion in your topology!");
1946 warning_error(wi, errbuf);
1950 if (nread > 0 && nread < NRFPA(ftype))
1952 /* Issue an error, do not use defaults */
1953 sprintf(errbuf, "Not enough parameters, there should be at least %d (or 0 for defaults)", NRFPA(ftype));
1954 warning_error(wi, errbuf);
1957 if (nread == 0 || nread == EOF)
1961 if (interaction_function[ftype].flags & IF_VSITE)
1963 /* set them to NOTSET, will be calculated later */
1964 for (j = 0; (j < MAXFORCEPARAM); j++)
1966 param.c[j] = NOTSET;
1971 param.C1 = -1; /* flag to swap parity of vsite construction */
1978 fprintf(stderr, "NOTE: No default %s types, using zeroes\n",
1979 interaction_function[ftype].longname);
1983 sprintf(errbuf, "No default %s types", interaction_function[ftype].longname);
1984 warning_error(wi, errbuf);
1995 param.C0 = 360 - param.C0;
1998 param.C2 = -param.C2;
2005 /* We only have to issue a warning if these atoms are perturbed! */
2007 for (j = 0; (j < nral); j++)
2009 bPert = bPert || PERTURBED(at->atom[param.a[j]]);
2014 sprintf(errbuf, "No default %s types for perturbed atoms, "
2015 "using normal values", interaction_function[ftype].longname);
2016 warning(wi, errbuf);
2022 if ((ftype == F_PDIHS || ftype == F_ANGRES || ftype == F_ANGRESZ)
2023 && param.c[5] != param.c[2])
2025 gmx_fatal(FARGS, "[ file %s, line %d ]:\n"
2026 " %s multiplicity can not be perturbed %f!=%f",
2027 get_warning_file(wi), get_warning_line(wi),
2028 interaction_function[ftype].longname,
2029 param.c[2], param.c[5]);
2032 if (IS_TABULATED(ftype) && param.c[2] != param.c[0])
2034 gmx_fatal(FARGS, "[ file %s, line %d ]:\n"
2035 " %s table number can not be perturbed %d!=%d",
2036 get_warning_file(wi), get_warning_line(wi),
2037 interaction_function[ftype].longname,
2038 (int)(param.c[0]+0.5), (int)(param.c[2]+0.5));
2041 /* Dont add R-B dihedrals where all parameters are zero (no interaction) */
2042 if (ftype == F_RBDIHS)
2045 for (i = 0; i < NRFP(ftype); i++)
2047 if (param.c[i] != 0)
2058 /* Put the values in the appropriate arrays */
2059 add_param_to_list (&bond[ftype], ¶m);
2061 /* Push additional torsions from FF for ftype==9 if we have them.
2062 * We have already checked that the A/B states do not differ in this case,
2063 * so we do not have to double-check that again, or the vsite stuff.
2064 * In addition, those torsions cannot be automatically perturbed.
2066 if (bDef && ftype == F_PDIHS)
2068 for (i = 1; i < nparam_defA; i++)
2070 /* Advance pointer! */
2072 for (j = 0; (j < NRFPA(ftype)+NRFPB(ftype)); j++)
2074 param.c[j] = param_defA->c[j];
2076 /* And push the next term for this torsion */
2077 add_param_to_list (&bond[ftype], ¶m);
2082 void push_cmap(directive d, t_params bondtype[], t_params bond[],
2083 t_atoms *at, gpp_atomtype_t atype, char *line,
2086 const char *aaformat[MAXATOMLIST+1] =
2097 int i, j, nr, ftype, nral, nread, ncmap_params;
2099 int aa[MAXATOMLIST+1];
2102 t_param param, paramB, *param_defA, *param_defB;
2104 ftype = ifunc_index(d, 1);
2106 nr = bondtype[ftype].nr;
2109 nread = sscanf(line, aaformat[nral-1],
2110 &aa[0], &aa[1], &aa[2], &aa[3], &aa[4], &aa[5]);
2117 else if (nread == nral)
2119 ftype = ifunc_index(d, 1);
2122 /* Check for double atoms and atoms out of bounds */
2123 for (i = 0; i < nral; i++)
2125 if (aa[i] < 1 || aa[i] > at->nr)
2127 gmx_fatal(FARGS, "[ file %s, line %d ]:\n"
2128 "Atom index (%d) in %s out of bounds (1-%d).\n"
2129 "This probably means that you have inserted topology section \"%s\"\n"
2130 "in a part belonging to a different molecule than you intended to.\n"
2131 "In that case move the \"%s\" section to the right molecule.",
2132 get_warning_file(wi), get_warning_line(wi),
2133 aa[i], dir2str(d), at->nr, dir2str(d), dir2str(d));
2136 for (j = i+1; (j < nral); j++)
2140 sprintf(errbuf, "Duplicate atom index (%d) in %s", aa[i], dir2str(d));
2141 warning(wi, errbuf);
2146 /* default force parameters */
2147 for (j = 0; (j < MAXATOMLIST); j++)
2149 param.a[j] = aa[j]-1;
2151 for (j = 0; (j < MAXFORCEPARAM); j++)
2156 /* Get the cmap type for this cmap angle */
2157 bFound = default_cmap_params(bondtype, at, atype, ¶m, FALSE, &cmap_type, &ncmap_params);
2159 /* We want exactly one parameter (the cmap type in state A (currently no state B) back */
2160 if (bFound && ncmap_params == 1)
2162 /* Put the values in the appropriate arrays */
2163 param.c[0] = cmap_type;
2164 add_param_to_list(&bond[ftype], ¶m);
2168 /* This is essentially the same check as in default_cmap_params() done one more time */
2169 gmx_fatal(FARGS, "Unable to assign a cmap type to torsion %d %d %d %d and %d\n",
2170 param.a[0]+1, param.a[1]+1, param.a[2]+1, param.a[3]+1, param.a[4]+1);
2176 void push_vsitesn(directive d, t_params bond[],
2177 t_atoms *at, char *line,
2181 int type, ftype, j, n, ret, nj, a;
2183 double *weight = NULL, weight_tot;
2186 /* default force parameters */
2187 for (j = 0; (j < MAXATOMLIST); j++)
2189 param.a[j] = NOTSET;
2191 for (j = 0; (j < MAXFORCEPARAM); j++)
2197 ret = sscanf(ptr, "%d%n", &a, &n);
2201 gmx_fatal(FARGS, "[ file %s, line %d ]:\n"
2202 " Expected an atom index in section \"%s\"",
2203 get_warning_file(wi), get_warning_line(wi),
2209 ret = sscanf(ptr, "%d%n", &type, &n);
2211 ftype = ifunc_index(d, type);
2217 ret = sscanf(ptr, "%d%n", &a, &n);
2224 srenew(weight, nj+20);
2233 /* Here we use the A-state mass as a parameter.
2234 * Note that the B-state mass has no influence.
2236 weight[nj] = at->atom[atc[nj]].m;
2240 ret = sscanf(ptr, "%lf%n", &(weight[nj]), &n);
2244 gmx_fatal(FARGS, "[ file %s, line %d ]:\n"
2245 " No weight or negative weight found for vsiten constructing atom %d (atom index %d)",
2246 get_warning_file(wi), get_warning_line(wi),
2251 gmx_fatal(FARGS, "Unknown vsiten type %d", type);
2253 weight_tot += weight[nj];
2261 gmx_fatal(FARGS, "[ file %s, line %d ]:\n"
2262 " Expected more than one atom index in section \"%s\"",
2263 get_warning_file(wi), get_warning_line(wi),
2267 if (weight_tot == 0)
2269 gmx_fatal(FARGS, "[ file %s, line %d ]:\n"
2270 " The total mass of the construting atoms is zero",
2271 get_warning_file(wi), get_warning_line(wi));
2274 for (j = 0; j < nj; j++)
2276 param.a[1] = atc[j];
2278 param.c[1] = weight[j]/weight_tot;
2279 /* Put the values in the appropriate arrays */
2280 add_param_to_list (&bond[ftype], ¶m);
2287 void push_mol(int nrmols, t_molinfo mols[], char *pline, int *whichmol,
2295 if (sscanf(pline, "%s%d", type, &copies) != 2)
2301 /* search moleculename */
2302 for (i = 0; ((i < nrmols) && gmx_strcasecmp(type, *(mols[i].name))); i++)
2314 gmx_fatal(FARGS, "No such moleculetype %s", type);
2318 void init_block2(t_block2 *b2, int natom)
2323 snew(b2->nra, b2->nr);
2324 snew(b2->a, b2->nr);
2325 for (i = 0; (i < b2->nr); i++)
2331 void done_block2(t_block2 *b2)
2337 for (i = 0; (i < b2->nr); i++)
2347 void push_excl(char *line, t_block2 *b2)
2351 char base[STRLEN], format[STRLEN];
2353 if (sscanf(line, "%d", &i) == 0)
2358 if ((1 <= i) && (i <= b2->nr))
2366 fprintf(debug, "Unbound atom %d\n", i-1);
2370 strcpy(base, "%*d");
2373 strcpy(format, base);
2374 strcat(format, "%d");
2375 n = sscanf(line, format, &j);
2378 if ((1 <= j) && (j <= b2->nr))
2381 srenew(b2->a[i], ++(b2->nra[i]));
2382 b2->a[i][b2->nra[i]-1] = j;
2383 /* also add the reverse exclusion! */
2384 srenew(b2->a[j], ++(b2->nra[j]));
2385 b2->a[j][b2->nra[j]-1] = i;
2386 strcat(base, "%*d");
2390 gmx_fatal(FARGS, "Invalid Atomnr j: %d, b2->nr: %d\n", j, b2->nr);
2397 void b_to_b2(t_blocka *b, t_block2 *b2)
2402 for (i = 0; (i < b->nr); i++)
2404 for (j = b->index[i]; (j < b->index[i+1]); j++)
2407 srenew(b2->a[i], ++b2->nra[i]);
2408 b2->a[i][b2->nra[i]-1] = a;
2413 void b2_to_b(t_block2 *b2, t_blocka *b)
2419 for (i = 0; (i < b2->nr); i++)
2422 for (j = 0; (j < b2->nra[i]); j++)
2424 b->a[nra+j] = b2->a[i][j];
2428 /* terminate list */
2432 static int icomp(const void *v1, const void *v2)
2434 return (*((atom_id *) v1))-(*((atom_id *) v2));
2437 void merge_excl(t_blocka *excl, t_block2 *b2)
2447 else if (b2->nr != excl->nr)
2449 gmx_fatal(FARGS, "DEATH HORROR: b2->nr = %d, while excl->nr = %d",
2454 fprintf(debug, "Entering merge_excl\n");
2457 /* First copy all entries from excl to b2 */
2460 /* Count and sort the exclusions */
2462 for (i = 0; (i < b2->nr); i++)
2466 /* remove double entries */
2467 qsort(b2->a[i], (size_t)b2->nra[i], (size_t)sizeof(b2->a[i][0]), icomp);
2469 for (j = 1; (j < b2->nra[i]); j++)
2471 if (b2->a[i][j] != b2->a[i][k-1])
2473 b2->a[i][k] = b2->a[i][j];
2482 srenew(excl->a, excl->nra);
2487 int add_atomtype_decoupled(t_symtab *symtab, gpp_atomtype_t at,
2488 t_nbparam ***nbparam, t_nbparam ***pair)
2494 /* Define an atom type with all parameters set to zero (no interactions) */
2497 /* Type for decoupled atoms could be anything,
2498 * this should be changed automatically later when required.
2500 atom.ptype = eptAtom;
2501 for (i = 0; (i < MAXFORCEPARAM); i++)
2506 nr = add_atomtype(at, symtab, &atom, "decoupled", ¶m, -1, 0.0, 0.0, 0.0, 0, 0, 0);
2508 /* Add space in the non-bonded parameters matrix */
2509 realloc_nb_params(at, nbparam, pair);
2514 static void convert_pairs_to_pairsQ(t_params *plist,
2515 real fudgeQQ, t_atoms *atoms)
2517 t_param *paramp1, *paramp2, *paramnew;
2518 int i, j, p1nr, p2nr, p2newnr;
2520 /* Add the pair list to the pairQ list */
2521 p1nr = plist[F_LJ14].nr;
2522 p2nr = plist[F_LJC14_Q].nr;
2523 p2newnr = p1nr + p2nr;
2524 snew(paramnew, p2newnr);
2526 paramp1 = plist[F_LJ14].param;
2527 paramp2 = plist[F_LJC14_Q].param;
2529 /* Fill in the new F_LJC14_Q array with the old one. NOTE:
2530 it may be possible to just ADD the converted F_LJ14 array
2531 to the old F_LJC14_Q array, but since we have to create
2532 a new sized memory structure, better just to deep copy it all.
2535 for (i = 0; i < p2nr; i++)
2537 /* Copy over parameters */
2538 for (j = 0; j < 5; j++) /* entries are 0-4 for F_LJC14_Q */
2540 paramnew[i].c[j] = paramp2[i].c[j];
2543 /* copy over atoms */
2544 for (j = 0; j < 2; j++)
2546 paramnew[i].a[j] = paramp2[i].a[j];
2550 for (i = p2nr; i < p2newnr; i++)
2554 /* Copy over parameters */
2555 paramnew[i].c[0] = fudgeQQ;
2556 paramnew[i].c[1] = atoms->atom[paramp1[j].a[0]].q;
2557 paramnew[i].c[2] = atoms->atom[paramp1[j].a[1]].q;
2558 paramnew[i].c[3] = paramp1[j].c[0];
2559 paramnew[i].c[4] = paramp1[j].c[1];
2561 /* copy over atoms */
2562 paramnew[i].a[0] = paramp1[j].a[0];
2563 paramnew[i].a[1] = paramp1[j].a[1];
2566 /* free the old pairlists */
2567 sfree(plist[F_LJC14_Q].param);
2568 sfree(plist[F_LJ14].param);
2570 /* now assign the new data to the F_LJC14_Q structure */
2571 plist[F_LJC14_Q].param = paramnew;
2572 plist[F_LJC14_Q].nr = p2newnr;
2574 /* Empty the LJ14 pairlist */
2575 plist[F_LJ14].nr = 0;
2576 plist[F_LJ14].param = NULL;
2579 static void generate_LJCpairsNB(t_molinfo *mol, int nb_funct, t_params *nbp)
2581 int n, ntype, i, j, k;
2588 atom = mol->atoms.atom;
2590 ntype = sqrt(nbp->nr);
2592 for (i = 0; i < MAXATOMLIST; i++)
2594 param.a[i] = NOTSET;
2596 for (i = 0; i < MAXFORCEPARAM; i++)
2598 param.c[i] = NOTSET;
2601 /* Add a pair interaction for all non-excluded atom pairs */
2603 for (i = 0; i < n; i++)
2605 for (j = i+1; j < n; j++)
2608 for (k = excl->index[i]; k < excl->index[i+1]; k++)
2610 if (excl->a[k] == j)
2617 if (nb_funct != F_LJ)
2619 gmx_fatal(FARGS, "Can only generate non-bonded pair interactions for Van der Waals type Lennard-Jones");
2623 param.c[0] = atom[i].q;
2624 param.c[1] = atom[j].q;
2625 param.c[2] = nbp->param[ntype*atom[i].type+atom[j].type].c[0];
2626 param.c[3] = nbp->param[ntype*atom[i].type+atom[j].type].c[1];
2627 add_param_to_list(&mol->plist[F_LJC_PAIRS_NB], ¶m);
2633 static void set_excl_all(t_blocka *excl)
2637 /* Get rid of the current exclusions and exclude all atom pairs */
2639 excl->nra = nat*nat;
2640 srenew(excl->a, excl->nra);
2642 for (i = 0; i < nat; i++)
2645 for (j = 0; j < nat; j++)
2650 excl->index[nat] = k;
2653 static void decouple_atoms(t_atoms *atoms, int atomtype_decouple,
2654 int couple_lam0, int couple_lam1)
2658 for (i = 0; i < atoms->nr; i++)
2660 if (couple_lam0 == ecouplamNONE || couple_lam0 == ecouplamVDW)
2662 atoms->atom[i].q = 0.0;
2664 if (couple_lam0 == ecouplamNONE || couple_lam0 == ecouplamQ)
2666 atoms->atom[i].type = atomtype_decouple;
2668 if (couple_lam1 == ecouplamNONE || couple_lam1 == ecouplamVDW)
2670 atoms->atom[i].qB = 0.0;
2672 if (couple_lam1 == ecouplamNONE || couple_lam1 == ecouplamQ)
2674 atoms->atom[i].typeB = atomtype_decouple;
2679 void convert_moltype_couple(t_molinfo *mol, int atomtype_decouple, real fudgeQQ,
2680 int couple_lam0, int couple_lam1,
2681 gmx_bool bCoupleIntra, int nb_funct, t_params *nbp)
2683 convert_pairs_to_pairsQ(mol->plist, fudgeQQ, &mol->atoms);
2686 generate_LJCpairsNB(mol, nb_funct, nbp);
2687 set_excl_all(&mol->excls);
2689 decouple_atoms(&mol->atoms, atomtype_decouple, couple_lam0, couple_lam1);