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,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.
46 #include "gromacs/utility/smalloc.h"
48 #include "gromacs/utility/cstringutil.h"
55 #include "gmx_fatal.h"
57 #include "gpp_atomtype.h"
58 #include "gpp_bond_atomtype.h"
60 void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype_t atype,
65 real c, bi, bj, ci, cj, ci0, ci1, ci2, cj0, cj1, cj2;
68 /* Lean mean shortcuts */
69 nr = get_atomtype_ntypes(atype);
71 snew(plist->param, nr*nr);
74 /* Fill the matrix with force parameters */
82 for (i = k = 0; (i < nr); i++)
84 for (j = 0; (j < nr); j++, k++)
86 for (nf = 0; (nf < nrfp); nf++)
88 ci = get_atomtype_nbparam(i, nf, atype);
89 cj = get_atomtype_nbparam(j, nf, atype);
91 plist->param[k].c[nf] = c;
97 case eCOMB_ARITHMETIC:
98 /* c0 and c1 are sigma and epsilon */
99 for (i = k = 0; (i < nr); i++)
101 for (j = 0; (j < nr); j++, k++)
103 ci0 = get_atomtype_nbparam(i, 0, atype);
104 cj0 = get_atomtype_nbparam(j, 0, atype);
105 ci1 = get_atomtype_nbparam(i, 1, atype);
106 cj1 = get_atomtype_nbparam(j, 1, atype);
107 plist->param[k].c[0] = (fabs(ci0) + fabs(cj0))*0.5;
108 /* Negative sigma signals that c6 should be set to zero later,
109 * so we need to propagate that through the combination rules.
111 if (ci0 < 0 || cj0 < 0)
113 plist->param[k].c[0] *= -1;
115 plist->param[k].c[1] = sqrt(ci1*cj1);
120 case eCOMB_GEOM_SIG_EPS:
121 /* c0 and c1 are sigma and epsilon */
122 for (i = k = 0; (i < nr); i++)
124 for (j = 0; (j < nr); j++, k++)
126 ci0 = get_atomtype_nbparam(i, 0, atype);
127 cj0 = get_atomtype_nbparam(j, 0, atype);
128 ci1 = get_atomtype_nbparam(i, 1, atype);
129 cj1 = get_atomtype_nbparam(j, 1, atype);
130 plist->param[k].c[0] = sqrt(fabs(ci0*cj0));
131 /* Negative sigma signals that c6 should be set to zero later,
132 * so we need to propagate that through the combination rules.
134 if (ci0 < 0 || cj0 < 0)
136 plist->param[k].c[0] *= -1;
138 plist->param[k].c[1] = sqrt(ci1*cj1);
144 gmx_fatal(FARGS, "No such combination rule %d", comb);
148 gmx_incons("Topology processing, generate nb parameters");
153 /* Buckingham rules */
154 for (i = k = 0; (i < nr); i++)
156 for (j = 0; (j < nr); j++, k++)
158 ci0 = get_atomtype_nbparam(i, 0, atype);
159 cj0 = get_atomtype_nbparam(j, 0, atype);
160 ci2 = get_atomtype_nbparam(i, 2, atype);
161 cj2 = get_atomtype_nbparam(j, 2, atype);
162 bi = get_atomtype_nbparam(i, 1, atype);
163 bj = get_atomtype_nbparam(j, 1, atype);
164 plist->param[k].c[0] = sqrt(ci0 * cj0);
165 if ((bi == 0) || (bj == 0))
167 plist->param[k].c[1] = 0;
171 plist->param[k].c[1] = 2.0/(1/bi+1/bj);
173 plist->param[k].c[2] = sqrt(ci2 * cj2);
179 sprintf(errbuf, "Invalid nonbonded type %s",
180 interaction_function[ftype].longname);
181 warning_error(wi, errbuf);
185 static void realloc_nb_params(gpp_atomtype_t at,
186 t_nbparam ***nbparam, t_nbparam ***pair)
188 /* Add space in the non-bonded parameters matrix */
189 int atnr = get_atomtype_ntypes(at);
190 srenew(*nbparam, atnr);
191 snew((*nbparam)[atnr-1], atnr);
195 snew((*pair)[atnr-1], atnr);
199 static void copy_B_from_A(int ftype, double *c)
203 nrfpA = NRFPA(ftype);
204 nrfpB = NRFPB(ftype);
206 /* Copy the B parameters from the first nrfpB A parameters */
207 for (i = 0; (i < nrfpB); i++)
213 void push_at (t_symtab *symtab, gpp_atomtype_t at, t_bond_atomtype bat,
214 char *line, int nb_funct,
215 t_nbparam ***nbparam, t_nbparam ***pair,
222 t_xlate xl[eptNR] = {
230 int nr, i, nfields, j, pt, nfp0 = -1;
231 int batype_nr, nread;
232 char type[STRLEN], btype[STRLEN], ptype[STRLEN];
234 double c[MAXFORCEPARAM];
235 double radius, vol, surftens, gb_radius, S_hct;
236 char tmpfield[12][100]; /* Max 12 fields of width 100 */
241 gmx_bool have_atomic_number;
242 gmx_bool have_bonded_type;
247 /* First assign input line to temporary array */
248 nfields = sscanf(line, "%s%s%s%s%s%s%s%s%s%s%s%s",
249 tmpfield[0], tmpfield[1], tmpfield[2], tmpfield[3], tmpfield[4], tmpfield[5],
250 tmpfield[6], tmpfield[7], tmpfield[8], tmpfield[9], tmpfield[10], tmpfield[11]);
252 /* Comments on optional fields in the atomtypes section:
254 * The force field format is getting a bit old. For OPLS-AA we needed
255 * to add a special bonded atomtype, and for Gerrit Groenhofs QM/MM stuff
256 * we also needed the atomic numbers.
257 * To avoid making all old or user-generated force fields unusable we
258 * have introduced both these quantities as optional columns, and do some
259 * acrobatics to check whether they are present or not.
260 * This will all look much nicer when we switch to XML... sigh.
262 * Field 0 (mandatory) is the nonbonded type name. (string)
263 * Field 1 (optional) is the bonded type (string)
264 * Field 2 (optional) is the atomic number (int)
265 * Field 3 (mandatory) is the mass (numerical)
266 * Field 4 (mandatory) is the charge (numerical)
267 * Field 5 (mandatory) is the particle type (single character)
268 * This is followed by a number of nonbonded parameters.
270 * The safest way to identify the format is the particle type field.
272 * So, here is what we do:
274 * A. Read in the first six fields as strings
275 * B. If field 3 (starting from 0) is a single char, we have neither
276 * bonded_type or atomic numbers.
277 * C. If field 5 is a single char we have both.
278 * D. If field 4 is a single char we check field 1. If this begins with
279 * an alphabetical character we have bonded types, otherwise atomic numbers.
288 if ( (strlen(tmpfield[5]) == 1) && isalpha(tmpfield[5][0]) )
290 have_bonded_type = TRUE;
291 have_atomic_number = TRUE;
293 else if ( (strlen(tmpfield[3]) == 1) && isalpha(tmpfield[3][0]) )
295 have_bonded_type = FALSE;
296 have_atomic_number = FALSE;
300 have_bonded_type = ( isalpha(tmpfield[1][0]) != 0 );
301 have_atomic_number = !have_bonded_type;
304 /* optional fields */
318 if (have_atomic_number)
320 if (have_bonded_type)
322 nread = sscanf(line, "%s%s%d%lf%lf%s%lf%lf%lf%lf%lf%lf",
323 type, btype, &atomnr, &m, &q, ptype, &c[0], &c[1],
324 &radius, &vol, &surftens, &gb_radius);
333 /* have_atomic_number && !have_bonded_type */
334 nread = sscanf(line, "%s%d%lf%lf%s%lf%lf%lf%lf%lf%lf",
335 type, &atomnr, &m, &q, ptype, &c[0], &c[1],
336 &radius, &vol, &surftens, &gb_radius);
346 if (have_bonded_type)
348 /* !have_atomic_number && have_bonded_type */
349 nread = sscanf(line, "%s%s%lf%lf%s%lf%lf%lf%lf%lf%lf",
350 type, btype, &m, &q, ptype, &c[0], &c[1],
351 &radius, &vol, &surftens, &gb_radius);
360 /* !have_atomic_number && !have_bonded_type */
361 nread = sscanf(line, "%s%lf%lf%s%lf%lf%lf%lf%lf%lf",
362 type, &m, &q, ptype, &c[0], &c[1],
363 &radius, &vol, &surftens, &gb_radius);
372 if (!have_bonded_type)
377 if (!have_atomic_number)
387 if (have_atomic_number)
389 if (have_bonded_type)
391 nread = sscanf(line, "%s%s%d%lf%lf%s%lf%lf%lf%lf%lf%lf%lf",
392 type, btype, &atomnr, &m, &q, ptype, &c[0], &c[1], &c[2],
393 &radius, &vol, &surftens, &gb_radius);
402 /* have_atomic_number && !have_bonded_type */
403 nread = sscanf(line, "%s%d%lf%lf%s%lf%lf%lf%lf%lf%lf%lf",
404 type, &atomnr, &m, &q, ptype, &c[0], &c[1], &c[2],
405 &radius, &vol, &surftens, &gb_radius);
415 if (have_bonded_type)
417 /* !have_atomic_number && have_bonded_type */
418 nread = sscanf(line, "%s%s%lf%lf%s%lf%lf%lf%lf%lf%lf%lf",
419 type, btype, &m, &q, ptype, &c[0], &c[1], &c[2],
420 &radius, &vol, &surftens, &gb_radius);
429 /* !have_atomic_number && !have_bonded_type */
430 nread = sscanf(line, "%s%lf%lf%s%lf%lf%lf%lf%lf%lf%lf",
431 type, &m, &q, ptype, &c[0], &c[1], &c[2],
432 &radius, &vol, &surftens, &gb_radius);
441 if (!have_bonded_type)
446 if (!have_atomic_number)
454 gmx_fatal(FARGS, "Invalid function type %d in push_at %s %d", nb_funct,
457 for (j = nfp0; (j < MAXFORCEPARAM); j++)
462 if (strlen(type) == 1 && isdigit(type[0]))
464 gmx_fatal(FARGS, "Atom type names can't be single digits.");
467 if (strlen(btype) == 1 && isdigit(btype[0]))
469 gmx_fatal(FARGS, "Bond atom type names can't be single digits.");
472 /* Hack to read old topologies */
473 if (gmx_strcasecmp(ptype, "D") == 0)
477 for (j = 0; (j < eptNR); j++)
479 if (gmx_strcasecmp(ptype, xl[j].entry) == 0)
486 gmx_fatal(FARGS, "Invalid particle type %s on line %s",
492 fprintf(debug, "ptype: %s\n", ptype_str[pt]);
498 for (i = 0; (i < MAXFORCEPARAM); i++)
503 if ((batype_nr = get_bond_atomtype_type(btype, bat)) == NOTSET)
505 add_bond_atomtype(bat, symtab, btype);
507 batype_nr = get_bond_atomtype_type(btype, bat);
509 if ((nr = get_atomtype_type(type, at)) != NOTSET)
511 sprintf(errbuf, "Overriding atomtype %s", type);
513 if ((nr = set_atomtype(nr, at, symtab, atom, type, param, batype_nr,
514 radius, vol, surftens, atomnr, gb_radius, S_hct)) == NOTSET)
516 gmx_fatal(FARGS, "Replacing atomtype %s failed", type);
519 else if ((nr = add_atomtype(at, symtab, atom, type, param,
520 batype_nr, radius, vol,
521 surftens, atomnr, gb_radius, S_hct)) == NOTSET)
523 gmx_fatal(FARGS, "Adding atomtype %s failed", type);
527 /* Add space in the non-bonded parameters matrix */
528 realloc_nb_params(at, nbparam, pair);
534 static void push_bondtype(t_params * bt,
538 gmx_bool bAllowRepeat,
543 gmx_bool bTest, bFound, bCont, bId;
545 int nrfp = NRFP(ftype);
548 /* If bAllowRepeat is TRUE, we allow multiple entries as long as they
549 are on directly _adjacent_ lines.
552 /* First check if our atomtypes are _identical_ (not reversed) to the previous
553 entry. If they are not identical we search for earlier duplicates. If they are
554 we can skip it, since we already searched for the first line
561 if (bAllowRepeat && nr > 1)
563 for (j = 0, bCont = TRUE; (j < nral); j++)
565 bCont = bCont && (b->a[j] == bt->param[nr-2].a[j]);
569 /* Search for earlier duplicates if this entry was not a continuation
570 from the previous line.
575 for (i = 0; (i < nr); i++)
578 for (j = 0; (j < nral); j++)
580 bTest = (bTest && (b->a[j] == bt->param[i].a[j]));
585 for (j = 0; (j < nral); j++)
587 bTest = (bTest && (b->a[nral-1-j] == bt->param[i].a[j]));
595 for (j = 0; (j < nrfp); j++)
597 bId = bId && (bt->param[i].c[j] == b->c[j]);
601 sprintf(errbuf, "Overriding %s parameters.%s",
602 interaction_function[ftype].longname,
604 "\nUse dihedraltype 9 to allow several multiplicity terms. Only consecutive lines are combined. Non-consective lines overwrite each other."
607 fprintf(stderr, " old: ");
608 for (j = 0; (j < nrfp); j++)
610 fprintf(stderr, " %g", bt->param[i].c[j]);
612 fprintf(stderr, " \n new: %s\n\n", line);
616 for (j = 0; (j < nrfp); j++)
618 bt->param[i].c[j] = b->c[j];
629 /* fill the arrays up and down */
630 memcpy(bt->param[bt->nr].c, b->c, sizeof(b->c));
631 memcpy(bt->param[bt->nr].a, b->a, sizeof(b->a));
632 memcpy(bt->param[bt->nr+1].c, b->c, sizeof(b->c));
634 /* The definitions of linear angles depend on the order of atoms,
635 * that means that for atoms i-j-k, with certain parameter a, the
636 * corresponding k-j-i angle will have parameter 1-a.
638 if (ftype == F_LINEAR_ANGLES)
640 bt->param[bt->nr+1].c[0] = 1-bt->param[bt->nr+1].c[0];
641 bt->param[bt->nr+1].c[2] = 1-bt->param[bt->nr+1].c[2];
644 for (j = 0; (j < nral); j++)
646 bt->param[bt->nr+1].a[j] = b->a[nral-1-j];
653 void push_bt(directive d, t_params bt[], int nral,
655 t_bond_atomtype bat, char *line,
658 const char *formal[MAXATOMLIST+1] = {
667 const char *formnl[MAXATOMLIST+1] = {
673 "%*s%*s%*s%*s%*s%*s",
674 "%*s%*s%*s%*s%*s%*s%*s"
676 const char *formlf = "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf";
677 int i, ft, ftype, nn, nrfp, nrfpA, nrfpB;
679 char alc[MAXATOMLIST+1][20];
680 /* One force parameter more, so we can check if we read too many */
681 double c[MAXFORCEPARAM+1];
685 if ((bat && at) || (!bat && !at))
687 gmx_incons("You should pass either bat or at to push_bt");
690 /* Make format string (nral ints+functype) */
691 if ((nn = sscanf(line, formal[nral],
692 alc[0], alc[1], alc[2], alc[3], alc[4], alc[5])) != nral+1)
694 sprintf(errbuf, "Not enough atomtypes (%d instead of %d)", nn-1, nral);
695 warning_error(wi, errbuf);
699 ft = strtol(alc[nral], NULL, 10);
700 ftype = ifunc_index(d, ft);
702 nrfpA = interaction_function[ftype].nrfpA;
703 nrfpB = interaction_function[ftype].nrfpB;
704 strcpy(f1, formnl[nral]);
706 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]))
711 /* Copy the B-state from the A-state */
712 copy_B_from_A(ftype, c);
718 warning_error(wi, "Not enough parameters");
720 else if (nn > nrfpA && nn < nrfp)
722 warning_error(wi, "Too many parameters or not enough parameters for topology B");
726 warning_error(wi, "Too many parameters");
728 for (i = nn; (i < nrfp); i++)
734 for (i = 0; (i < nral); i++)
736 if (at && ((p.a[i] = get_atomtype_type(alc[i], at)) == NOTSET))
738 gmx_fatal(FARGS, "Unknown atomtype %s\n", alc[i]);
740 else if (bat && ((p.a[i] = get_bond_atomtype_type(alc[i], bat)) == NOTSET))
742 gmx_fatal(FARGS, "Unknown bond_atomtype %s\n", alc[i]);
745 for (i = 0; (i < nrfp); i++)
749 push_bondtype (&(bt[ftype]), &p, nral, ftype, FALSE, line, wi);
753 void push_dihedraltype(directive d, t_params bt[],
754 t_bond_atomtype bat, char *line,
757 const char *formal[MAXATOMLIST+1] = {
766 const char *formnl[MAXATOMLIST+1] = {
772 "%*s%*s%*s%*s%*s%*s",
773 "%*s%*s%*s%*s%*s%*s%*s"
775 const char *formlf[MAXFORCEPARAM] = {
781 "%lf%lf%lf%lf%lf%lf",
782 "%lf%lf%lf%lf%lf%lf%lf",
783 "%lf%lf%lf%lf%lf%lf%lf%lf",
784 "%lf%lf%lf%lf%lf%lf%lf%lf%lf",
785 "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
786 "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
787 "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
789 int i, ft, ftype, nn, nrfp, nrfpA, nrfpB, nral;
791 char alc[MAXATOMLIST+1][20];
792 double c[MAXFORCEPARAM];
794 gmx_bool bAllowRepeat;
797 /* This routine accepts dihedraltypes defined from either 2 or 4 atoms.
799 * We first check for 2 atoms with the 3th column being an integer
800 * defining the type. If this isn't the case, we try it with 4 atoms
801 * and the 5th column defining the dihedral type.
803 nn = sscanf(line, formal[4], alc[0], alc[1], alc[2], alc[3], alc[4]);
804 if (nn >= 3 && strlen(alc[2]) == 1 && isdigit(alc[2][0]))
807 ft = strtol(alc[nral], NULL, 10);
808 /* Move atom types around a bit and use 'X' for wildcard atoms
809 * to create a 4-atom dihedral definition with arbitrary atoms in
812 if (alc[2][0] == '2')
814 /* improper - the two atomtypes are 1,4. Use wildcards for 2,3 */
815 strcpy(alc[3], alc[1]);
816 sprintf(alc[2], "X");
817 sprintf(alc[1], "X");
818 /* alc[0] stays put */
822 /* proper - the two atomtypes are 2,3. Use wildcards for 1,4 */
823 sprintf(alc[3], "X");
824 strcpy(alc[2], alc[1]);
825 strcpy(alc[1], alc[0]);
826 sprintf(alc[0], "X");
829 else if (nn == 5 && strlen(alc[4]) == 1 && isdigit(alc[4][0]))
832 ft = strtol(alc[nral], NULL, 10);
836 sprintf(errbuf, "Incorrect number of atomtypes for dihedral (%d instead of 2 or 4)", nn-1);
837 warning_error(wi, errbuf);
843 /* Previously, we have always overwritten parameters if e.g. a torsion
844 with the same atomtypes occurs on multiple lines. However, CHARMM and
845 some other force fields specify multiple dihedrals over some bonds,
846 including cosines with multiplicity 6 and somethimes even higher.
847 Thus, they cannot be represented with Ryckaert-Bellemans terms.
848 To add support for these force fields, Dihedral type 9 is identical to
849 normal proper dihedrals, but repeated entries are allowed.
856 bAllowRepeat = FALSE;
860 ftype = ifunc_index(d, ft);
862 nrfpA = interaction_function[ftype].nrfpA;
863 nrfpB = interaction_function[ftype].nrfpB;
865 strcpy(f1, formnl[nral]);
866 strcat(f1, formlf[nrfp-1]);
868 /* Check number of parameters given */
869 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]))
874 /* Copy the B-state from the A-state */
875 copy_B_from_A(ftype, c);
881 warning_error(wi, "Not enough parameters");
883 else if (nn > nrfpA && nn < nrfp)
885 warning_error(wi, "Too many parameters or not enough parameters for topology B");
889 warning_error(wi, "Too many parameters");
891 for (i = nn; (i < nrfp); i++)
898 for (i = 0; (i < 4); i++)
900 if (!strcmp(alc[i], "X"))
906 if ((p.a[i] = get_bond_atomtype_type(alc[i], bat)) == NOTSET)
908 gmx_fatal(FARGS, "Unknown bond_atomtype %s", alc[i]);
912 for (i = 0; (i < nrfp); i++)
916 /* Always use 4 atoms here, since we created two wildcard atoms
917 * if there wasn't of them 4 already.
919 push_bondtype (&(bt[ftype]), &p, 4, ftype, bAllowRepeat, line, wi);
923 void push_nbt(directive d, t_nbparam **nbt, gpp_atomtype_t atype,
924 char *pline, int nb_funct,
928 const char *form2 = "%*s%*s%*s%lf%lf";
929 const char *form3 = "%*s%*s%*s%lf%lf%lf";
930 const char *form4 = "%*s%*s%*s%lf%lf%lf%lf";
931 const char *form5 = "%*s%*s%*s%lf%lf%lf%lf%lf";
933 int i, f, n, ftype, atnr, nrfp;
941 if (sscanf (pline, "%s%s%d", a0, a1, &f) != 3)
947 ftype = ifunc_index(d, f);
949 if (ftype != nb_funct)
951 sprintf(errbuf, "Trying to add %s while the default nonbond type is %s",
952 interaction_function[ftype].longname,
953 interaction_function[nb_funct].longname);
954 warning_error(wi, errbuf);
958 /* Get the force parameters */
962 n = sscanf(pline, form4, &c[0], &c[1], &c[2], &c[3]);
968 /* When the B topology parameters are not set,
969 * copy them from topology A
972 for (i = n; i < nrfp; i++)
977 else if (ftype == F_LJC14_Q)
979 n = sscanf(pline, form5, &c[0], &c[1], &c[2], &c[3], &dum);
982 incorrect_n_param(wi);
988 if (sscanf(pline, form3, &c[0], &c[1], &dum) != 2)
990 incorrect_n_param(wi);
996 if (sscanf(pline, form4, &c[0], &c[1], &c[2], &dum) != 3)
998 incorrect_n_param(wi);
1004 gmx_fatal(FARGS, "Number of force parameters for nonbonded interactions is %d"
1005 " in file %s, line %d", nrfp, __FILE__, __LINE__);
1007 for (i = 0; (i < nrfp); i++)
1012 /* Put the parameters in the matrix */
1013 if ((ai = get_atomtype_type (a0, atype)) == NOTSET)
1015 gmx_fatal(FARGS, "Atomtype %s not found", a0);
1017 if ((aj = get_atomtype_type (a1, atype)) == NOTSET)
1019 gmx_fatal(FARGS, "Atomtype %s not found", a1);
1021 nbp = &(nbt[max(ai, aj)][min(ai, aj)]);
1026 for (i = 0; i < nrfp; i++)
1028 bId = bId && (nbp->c[i] == cr[i]);
1032 sprintf(errbuf, "Overriding non-bonded parameters,");
1033 warning(wi, errbuf);
1034 fprintf(stderr, " old:");
1035 for (i = 0; i < nrfp; i++)
1037 fprintf(stderr, " %g", nbp->c[i]);
1039 fprintf(stderr, " new\n%s\n", pline);
1043 for (i = 0; i < nrfp; i++)
1050 push_gb_params (gpp_atomtype_t at, char *line,
1055 double radius, vol, surftens, gb_radius, S_hct;
1056 char atypename[STRLEN];
1057 char errbuf[STRLEN];
1059 if ( (nfield = sscanf(line, "%s%lf%lf%lf%lf%lf", atypename, &radius, &vol, &surftens, &gb_radius, &S_hct)) != 6)
1061 sprintf(errbuf, "Too few gb parameters for type %s\n", atypename);
1062 warning(wi, errbuf);
1065 /* Search for atomtype */
1066 atype = get_atomtype_type(atypename, at);
1068 if (atype == NOTSET)
1070 printf("Couldn't find topology match for atomtype %s\n", atypename);
1074 set_atomtype_gbparam(at, atype, radius, vol, surftens, gb_radius, S_hct);
1078 push_cmaptype(directive d, t_params bt[], int nral, gpp_atomtype_t at,
1079 t_bond_atomtype bat, char *line,
1082 const char *formal = "%s%s%s%s%s%s%s%s";
1084 int i, j, ft, ftype, nn, nrfp, nrfpA, nrfpB;
1086 int nxcmap, nycmap, ncmap, read_cmap, sl, nct;
1087 char s[20], alc[MAXATOMLIST+2][20];
1089 gmx_bool bAllowRepeat;
1092 /* Keep the compiler happy */
1096 if ((nn = sscanf(line, formal, alc[0], alc[1], alc[2], alc[3], alc[4], alc[5], alc[6], alc[7])) != nral+3)
1098 sprintf(errbuf, "Incorrect number of atomtypes for cmap (%d instead of 5)", nn-1);
1099 warning_error(wi, errbuf);
1103 /* Compute an offset for each line where the cmap parameters start
1104 * ie. where the atom types and grid spacing information ends
1106 for (i = 0; i < nn; i++)
1108 start += (int)strlen(alc[i]);
1111 /* There are nn-1 spaces between the atom types and the grid spacing info in the cmap.itp file */
1112 /* start is the position on the line where we start to read the actual cmap grid data from the itp file */
1113 start = start + nn -1;
1115 ft = strtol(alc[nral], NULL, 10);
1116 nxcmap = strtol(alc[nral+1], NULL, 10);
1117 nycmap = strtol(alc[nral+2], NULL, 10);
1119 /* Check for equal grid spacing in x and y dims */
1120 if (nxcmap != nycmap)
1122 gmx_fatal(FARGS, "Not the same grid spacing in x and y for cmap grid: x=%d, y=%d", nxcmap, nycmap);
1125 ncmap = nxcmap*nycmap;
1126 ftype = ifunc_index(d, ft);
1127 nrfpA = strtol(alc[6], NULL, 10)*strtol(alc[6], NULL, 10);
1128 nrfpB = strtol(alc[7], NULL, 10)*strtol(alc[7], NULL, 10);
1131 /* Allocate memory for the CMAP grid */
1132 bt[F_CMAP].ncmap += nrfp;
1133 srenew(bt[F_CMAP].cmap, bt[F_CMAP].ncmap);
1135 /* Read in CMAP parameters */
1137 for (i = 0; i < ncmap; i++)
1139 while (isspace(*(line+start+sl)))
1143 nn = sscanf(line+start+sl, " %s ", s);
1145 bt[F_CMAP].cmap[i+(bt[F_CMAP].ncmap)-nrfp] = strtod(s, NULL);
1153 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]);
1158 /* Check do that we got the number of parameters we expected */
1159 if (read_cmap == nrfpA)
1161 for (i = 0; i < ncmap; i++)
1163 bt[F_CMAP].cmap[i+ncmap] = bt[F_CMAP].cmap[i];
1168 if (read_cmap < nrfpA)
1170 warning_error(wi, "Not enough cmap parameters");
1172 else if (read_cmap > nrfpA && read_cmap < nrfp)
1174 warning_error(wi, "Too many cmap parameters or not enough parameters for topology B");
1176 else if (read_cmap > nrfp)
1178 warning_error(wi, "Too many cmap parameters");
1183 /* Set grid spacing and the number of grids (we assume these numbers to be the same for all grids
1184 * so we can safely assign them each time
1186 bt[F_CMAP].grid_spacing = nxcmap; /* Or nycmap, they need to be equal */
1187 bt[F_CMAP].nc = bt[F_CMAP].nc + 1; /* Since we are incrementing here, we need to subtract later, see (*****) */
1188 nct = (nral+1) * bt[F_CMAP].nc;
1190 /* Allocate memory for the cmap_types information */
1191 srenew(bt[F_CMAP].cmap_types, nct);
1193 for (i = 0; (i < nral); i++)
1195 if (at && ((p.a[i] = get_bond_atomtype_type(alc[i], bat)) == NOTSET))
1197 gmx_fatal(FARGS, "Unknown atomtype %s\n", alc[i]);
1199 else if (bat && ((p.a[i] = get_bond_atomtype_type(alc[i], bat)) == NOTSET))
1201 gmx_fatal(FARGS, "Unknown bond_atomtype %s\n", alc[i]);
1204 /* Assign a grid number to each cmap_type */
1205 bt[F_CMAP].cmap_types[bt[F_CMAP].nct++] = get_bond_atomtype_type(alc[i], bat);
1208 /* Assign a type number to this cmap */
1209 bt[F_CMAP].cmap_types[bt[F_CMAP].nct++] = bt[F_CMAP].nc-1; /* Since we inremented earlier, we need to subtrac here, to get the types right (****) */
1211 /* Check for the correct number of atoms (again) */
1212 if (bt[F_CMAP].nct != nct)
1214 gmx_fatal(FARGS, "Incorrect number of atom types (%d) in cmap type %d\n", nct, bt[F_CMAP].nc);
1217 /* Is this correct?? */
1218 for (i = 0; i < MAXFORCEPARAM; i++)
1223 /* Push the bond to the bondlist */
1224 push_bondtype (&(bt[ftype]), &p, nral, ftype, FALSE, line, wi);
1228 static void push_atom_now(t_symtab *symtab, t_atoms *at, int atomnr,
1230 int type, char *ctype, int ptype,
1232 char *resname, char *name, real m0, real q0,
1233 int typeB, char *ctypeB, real mB, real qB)
1235 int j, resind = 0, resnr;
1239 if (((nr == 0) && (atomnr != 1)) || (nr && (atomnr != at->nr+1)))
1241 gmx_fatal(FARGS, "Atoms in the .top are not numbered consecutively from 1 (rather, atomnr = %d, while at->nr = %d)", atomnr, at->nr);
1244 j = strlen(resnumberic) - 1;
1245 if (isdigit(resnumberic[j]))
1251 ric = resnumberic[j];
1252 if (j == 0 || !isdigit(resnumberic[j-1]))
1254 gmx_fatal(FARGS, "Invalid residue number '%s' for atom %d",
1255 resnumberic, atomnr);
1258 resnr = strtol(resnumberic, NULL, 10);
1262 resind = at->atom[nr-1].resind;
1264 if (nr == 0 || strcmp(resname, *at->resinfo[resind].name) != 0 ||
1265 resnr != at->resinfo[resind].nr ||
1266 ric != at->resinfo[resind].ic)
1276 at->nres = resind + 1;
1277 srenew(at->resinfo, at->nres);
1278 at->resinfo[resind].name = put_symtab(symtab, resname);
1279 at->resinfo[resind].nr = resnr;
1280 at->resinfo[resind].ic = ric;
1284 resind = at->atom[at->nr-1].resind;
1287 /* New atom instance
1288 * get new space for arrays
1290 srenew(at->atom, nr+1);
1291 srenew(at->atomname, nr+1);
1292 srenew(at->atomtype, nr+1);
1293 srenew(at->atomtypeB, nr+1);
1296 at->atom[nr].type = type;
1297 at->atom[nr].ptype = ptype;
1298 at->atom[nr].q = q0;
1299 at->atom[nr].m = m0;
1300 at->atom[nr].typeB = typeB;
1301 at->atom[nr].qB = qB;
1302 at->atom[nr].mB = mB;
1304 at->atom[nr].resind = resind;
1305 at->atom[nr].atomnumber = atomicnumber;
1306 at->atomname[nr] = put_symtab(symtab, name);
1307 at->atomtype[nr] = put_symtab(symtab, ctype);
1308 at->atomtypeB[nr] = put_symtab(symtab, ctypeB);
1312 void push_cg(t_block *block, int *lastindex, int index, int a)
1316 fprintf (debug, "Index %d, Atom %d\n", index, a);
1319 if (((block->nr) && (*lastindex != index)) || (!block->nr))
1321 /* add a new block */
1323 srenew(block->index, block->nr+1);
1325 block->index[block->nr] = a + 1;
1329 void push_atom(t_symtab *symtab, t_block *cgs,
1330 t_atoms *at, gpp_atomtype_t atype, char *line, int *lastcg,
1334 int cgnumber, atomnr, type, typeB, nscan;
1335 char id[STRLEN], ctype[STRLEN], ctypeB[STRLEN],
1336 resnumberic[STRLEN], resname[STRLEN], name[STRLEN], check[STRLEN];
1337 double m, q, mb, qb;
1338 real m0, q0, mB, qB;
1340 /* Make a shortcut for writing in this molecule */
1343 /* Fixed parameters */
1344 if (sscanf(line, "%s%s%s%s%s%d",
1345 id, ctype, resnumberic, resname, name, &cgnumber) != 6)
1350 sscanf(id, "%d", &atomnr);
1351 if ((type = get_atomtype_type(ctype, atype)) == NOTSET)
1353 gmx_fatal(FARGS, "Atomtype %s not found", ctype);
1355 ptype = get_atomtype_ptype(type, atype);
1357 /* Set default from type */
1358 q0 = get_atomtype_qA(type, atype);
1359 m0 = get_atomtype_massA(type, atype);
1364 /* Optional parameters */
1365 nscan = sscanf(line, "%*s%*s%*s%*s%*s%*s%lf%lf%s%lf%lf%s",
1366 &q, &m, ctypeB, &qb, &mb, check);
1368 /* Nasty switch that falls thru all the way down! */
1377 if ((typeB = get_atomtype_type(ctypeB, atype)) == NOTSET)
1379 gmx_fatal(FARGS, "Atomtype %s not found", ctypeB);
1381 qB = get_atomtype_qA(typeB, atype);
1382 mB = get_atomtype_massA(typeB, atype);
1391 warning_error(wi, "Too many parameters");
1400 fprintf(debug, "mB=%g, qB=%g, typeB=%d\n", mB, qB, typeB);
1403 push_cg(cgs, lastcg, cgnumber, nr);
1405 push_atom_now(symtab, at, atomnr, get_atomtype_atomnumber(type, atype),
1406 type, ctype, ptype, resnumberic,
1407 resname, name, m0, q0, typeB,
1408 typeB == type ? ctype : ctypeB, mB, qB);
1411 void push_molt(t_symtab *symtab, int *nmol, t_molinfo **mol, char *line,
1418 if ((sscanf(line, "%s%d", type, &nrexcl)) != 2)
1420 warning_error(wi, "Expected a molecule type name and nrexcl");
1423 /* Test if this atomtype overwrites another */
1427 if (gmx_strcasecmp(*((*mol)[i].name), type) == 0)
1429 gmx_fatal(FARGS, "moleculetype %s is redefined", type);
1435 srenew(*mol, *nmol);
1436 newmol = &((*mol)[*nmol-1]);
1437 init_molinfo(newmol);
1439 /* Fill in the values */
1440 newmol->name = put_symtab(symtab, type);
1441 newmol->nrexcl = nrexcl;
1442 newmol->excl_set = FALSE;
1445 static gmx_bool default_nb_params(int ftype, t_params bt[], t_atoms *at,
1446 t_param *p, int c_start, gmx_bool bB, gmx_bool bGenPairs)
1448 int i, j, ti, tj, ntype;
1451 int nr = bt[ftype].nr;
1452 int nral = NRAL(ftype);
1453 int nrfp = interaction_function[ftype].nrfpA;
1454 int nrfpB = interaction_function[ftype].nrfpB;
1456 if ((!bB && nrfp == 0) || (bB && nrfpB == 0))
1464 /* First test the generated-pair position to save
1465 * time when we have 1000*1000 entries for e.g. OPLS...
1470 ti = at->atom[p->a[0]].typeB;
1471 tj = at->atom[p->a[1]].typeB;
1475 ti = at->atom[p->a[0]].type;
1476 tj = at->atom[p->a[1]].type;
1478 pi = &(bt[ftype].param[ntype*ti+tj]);
1479 bFound = ((ti == pi->a[0]) && (tj == pi->a[1]));
1482 /* Search explicitly if we didnt find it */
1485 for (i = 0; ((i < nr) && !bFound); i++)
1487 pi = &(bt[ftype].param[i]);
1490 for (j = 0; ((j < nral) &&
1491 (at->atom[p->a[j]].typeB == pi->a[j])); j++)
1498 for (j = 0; ((j < nral) &&
1499 (at->atom[p->a[j]].type == pi->a[j])); j++)
1504 bFound = (j == nral);
1512 if (nrfp+nrfpB > MAXFORCEPARAM)
1514 gmx_incons("Too many force parameters");
1516 for (j = c_start; (j < nrfpB); j++)
1518 p->c[nrfp+j] = pi->c[j];
1523 for (j = c_start; (j < nrfp); j++)
1531 for (j = c_start; (j < nrfp); j++)
1539 static gmx_bool default_cmap_params(t_params bondtype[],
1540 t_atoms *at, gpp_atomtype_t atype,
1541 t_param *p, gmx_bool bB,
1542 int *cmap_type, int *nparam_def)
1544 int i, j, nparam_found;
1546 gmx_bool bFound = FALSE;
1551 /* Match the current cmap angle against the list of cmap_types */
1552 for (i = 0; i < bondtype[F_CMAP].nct && !bFound; i += 6)
1561 (get_atomtype_batype(at->atom[p->a[0]].type, atype) == bondtype[F_CMAP].cmap_types[i]) &&
1562 (get_atomtype_batype(at->atom[p->a[1]].type, atype) == bondtype[F_CMAP].cmap_types[i+1]) &&
1563 (get_atomtype_batype(at->atom[p->a[2]].type, atype) == bondtype[F_CMAP].cmap_types[i+2]) &&
1564 (get_atomtype_batype(at->atom[p->a[3]].type, atype) == bondtype[F_CMAP].cmap_types[i+3]) &&
1565 (get_atomtype_batype(at->atom[p->a[4]].type, atype) == bondtype[F_CMAP].cmap_types[i+4]))
1567 /* Found cmap torsion */
1569 ct = bondtype[F_CMAP].cmap_types[i+5];
1575 /* If we did not find a matching type for this cmap torsion */
1578 gmx_fatal(FARGS, "Unknown cmap torsion between atoms %d %d %d %d %d\n",
1579 p->a[0]+1, p->a[1]+1, p->a[2]+1, p->a[3]+1, p->a[4]+1);
1582 *nparam_def = nparam_found;
1588 static gmx_bool default_params(int ftype, t_params bt[],
1589 t_atoms *at, gpp_atomtype_t atype,
1590 t_param *p, gmx_bool bB,
1591 t_param **param_def,
1594 int i, j, nparam_found;
1595 gmx_bool bFound, bSame;
1598 int nr = bt[ftype].nr;
1599 int nral = NRAL(ftype);
1600 int nrfpA = interaction_function[ftype].nrfpA;
1601 int nrfpB = interaction_function[ftype].nrfpB;
1603 if ((!bB && nrfpA == 0) || (bB && nrfpB == 0))
1609 /* We allow wildcards now. The first type (with or without wildcards) that
1610 * fits is used, so you should probably put the wildcarded bondtypes
1611 * at the end of each section.
1615 /* OPLS uses 1000s of dihedraltypes, so in order to speed up the scanning we have a
1616 * special case for this. Check for B state outside loop to speed it up.
1618 if (ftype == F_PDIHS || ftype == F_RBDIHS || ftype == F_IDIHS || ftype == F_PIDIHS)
1622 for (i = 0; ((i < nr) && !bFound); i++)
1624 pi = &(bt[ftype].param[i]);
1627 ((pi->AI == -1) || (get_atomtype_batype(at->atom[p->AI].typeB, atype) == pi->AI)) &&
1628 ((pi->AJ == -1) || (get_atomtype_batype(at->atom[p->AJ].typeB, atype) == pi->AJ)) &&
1629 ((pi->AK == -1) || (get_atomtype_batype(at->atom[p->AK].typeB, atype) == pi->AK)) &&
1630 ((pi->AL == -1) || (get_atomtype_batype(at->atom[p->AL].typeB, atype) == pi->AL))
1637 for (i = 0; ((i < nr) && !bFound); i++)
1639 pi = &(bt[ftype].param[i]);
1642 ((pi->AI == -1) || (get_atomtype_batype(at->atom[p->AI].type, atype) == pi->AI)) &&
1643 ((pi->AJ == -1) || (get_atomtype_batype(at->atom[p->AJ].type, atype) == pi->AJ)) &&
1644 ((pi->AK == -1) || (get_atomtype_batype(at->atom[p->AK].type, atype) == pi->AK)) &&
1645 ((pi->AL == -1) || (get_atomtype_batype(at->atom[p->AL].type, atype) == pi->AL))
1649 /* Find additional matches for this dihedral - necessary for ftype==9 which is used e.g. for charmm.
1650 * The rules in that case is that additional matches HAVE to be on adjacent lines!
1656 /* Continue from current i value */
1657 for (j = i+1; j < nr && bSame; j += 2)
1659 pj = &(bt[ftype].param[j]);
1660 bSame = (pi->AI == pj->AI && pi->AJ == pj->AJ && pi->AK == pj->AK && pi->AL == pj->AL);
1665 /* nparam_found will be increased as long as the numbers match */
1669 else /* Not a dihedral */
1671 for (i = 0; ((i < nr) && !bFound); i++)
1673 pi = &(bt[ftype].param[i]);
1676 for (j = 0; ((j < nral) &&
1677 (get_atomtype_batype(at->atom[p->a[j]].typeB, atype) == pi->a[j])); j++)
1684 for (j = 0; ((j < nral) &&
1685 (get_atomtype_batype(at->atom[p->a[j]].type, atype) == pi->a[j])); j++)
1690 bFound = (j == nral);
1699 *nparam_def = nparam_found;
1706 void push_bond(directive d, t_params bondtype[], t_params bond[],
1707 t_atoms *at, gpp_atomtype_t atype, char *line,
1708 gmx_bool bBonded, gmx_bool bGenPairs, real fudgeQQ,
1709 gmx_bool bZero, gmx_bool *bWarn_copy_A_B,
1712 const char *aaformat[MAXATOMLIST] = {
1720 const char *asformat[MAXATOMLIST] = {
1725 "%*s%*s%*s%*s%*s%*s",
1726 "%*s%*s%*s%*s%*s%*s%*s"
1728 const char *ccformat = "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf";
1729 int nr, i, j, nral, nral_fmt, nread, ftype;
1730 char format[STRLEN];
1731 /* One force parameter more, so we can check if we read too many */
1732 double cc[MAXFORCEPARAM+1];
1733 int aa[MAXATOMLIST+1];
1734 t_param param, paramB, *param_defA, *param_defB;
1735 gmx_bool bFoundA = FALSE, bFoundB = FALSE, bDef, bPert, bSwapParity = FALSE;
1736 int nparam_defA, nparam_defB;
1739 nparam_defA = nparam_defB = 0;
1741 ftype = ifunc_index(d, 1);
1743 for (j = 0; j < MAXATOMLIST; j++)
1747 bDef = (NRFP(ftype) > 0);
1749 if (ftype == F_SETTLE)
1751 /* SETTLE acts on 3 atoms, but the topology format only specifies
1752 * the first atom (for historical reasons).
1761 nread = sscanf(line, aaformat[nral_fmt-1],
1762 &aa[0], &aa[1], &aa[2], &aa[3], &aa[4], &aa[5]);
1764 if (ftype == F_SETTLE)
1771 if (nread < nral_fmt)
1776 else if (nread > nral_fmt)
1778 /* this is a hack to allow for virtual sites with swapped parity */
1779 bSwapParity = (aa[nral] < 0);
1782 aa[nral] = -aa[nral];
1784 ftype = ifunc_index(d, aa[nral]);
1793 gmx_fatal(FARGS, "Negative function types only allowed for %s and %s",
1794 interaction_function[F_VSITE3FAD].longname,
1795 interaction_function[F_VSITE3OUT].longname);
1801 /* Check for double atoms and atoms out of bounds */
1802 for (i = 0; (i < nral); i++)
1804 if (aa[i] < 1 || aa[i] > at->nr)
1806 gmx_fatal(FARGS, "[ file %s, line %d ]:\n"
1807 "Atom index (%d) in %s out of bounds (1-%d).\n"
1808 "This probably means that you have inserted topology section \"%s\"\n"
1809 "in a part belonging to a different molecule than you intended to.\n"
1810 "In that case move the \"%s\" section to the right molecule.",
1811 get_warning_file(wi), get_warning_line(wi),
1812 aa[i], dir2str(d), at->nr, dir2str(d), dir2str(d));
1814 for (j = i+1; (j < nral); j++)
1818 sprintf(errbuf, "Duplicate atom index (%d) in %s", aa[i], dir2str(d));
1819 warning(wi, errbuf);
1824 /* default force parameters */
1825 for (j = 0; (j < MAXATOMLIST); j++)
1827 param.a[j] = aa[j]-1;
1829 for (j = 0; (j < MAXFORCEPARAM); j++)
1834 /* Get force params for normal and free energy perturbation
1835 * studies, as determined by types!
1840 bFoundA = default_params(ftype, bondtype, at, atype, ¶m, FALSE, ¶m_defA, &nparam_defA);
1843 /* Copy the A-state and B-state default parameters. */
1844 assert(NRFPA(ftype)+NRFPB(ftype) <= MAXFORCEPARAM);
1845 for (j = 0; (j < NRFPA(ftype)+NRFPB(ftype)); j++)
1847 param.c[j] = param_defA->c[j];
1850 bFoundB = default_params(ftype, bondtype, at, atype, ¶m, TRUE, ¶m_defB, &nparam_defB);
1853 /* Copy only the B-state default parameters */
1854 for (j = NRFPA(ftype); (j < NRFP(ftype)); j++)
1856 param.c[j] = param_defB->c[j];
1860 else if (ftype == F_LJ14)
1862 bFoundA = default_nb_params(ftype, bondtype, at, ¶m, 0, FALSE, bGenPairs);
1863 bFoundB = default_nb_params(ftype, bondtype, at, ¶m, 0, TRUE, bGenPairs);
1865 else if (ftype == F_LJC14_Q)
1867 param.c[0] = fudgeQQ;
1868 /* Fill in the A-state charges as default parameters */
1869 param.c[1] = at->atom[param.a[0]].q;
1870 param.c[2] = at->atom[param.a[1]].q;
1871 /* The default LJ parameters are the standard 1-4 parameters */
1872 bFoundA = default_nb_params(F_LJ14, bondtype, at, ¶m, 3, FALSE, bGenPairs);
1875 else if (ftype == F_LJC_PAIRS_NB)
1877 /* Defaults are not supported here */
1883 gmx_incons("Unknown function type in push_bond");
1886 if (nread > nral_fmt)
1888 /* Manually specified parameters - in this case we discard multiple torsion info! */
1890 strcpy(format, asformat[nral_fmt-1]);
1891 strcat(format, ccformat);
1893 nread = sscanf(line, format, &cc[0], &cc[1], &cc[2], &cc[3], &cc[4], &cc[5],
1894 &cc[6], &cc[7], &cc[8], &cc[9], &cc[10], &cc[11], &cc[12]);
1896 if ((nread == NRFPA(ftype)) && (NRFPB(ftype) != 0))
1898 /* We only have to issue a warning if these atoms are perturbed! */
1900 for (j = 0; (j < nral); j++)
1902 bPert = bPert || PERTURBED(at->atom[param.a[j]]);
1905 if (bPert && *bWarn_copy_A_B)
1908 "Some parameters for bonded interaction involving perturbed atoms are specified explicitly in state A, but not B - copying A to B");
1909 warning(wi, errbuf);
1910 *bWarn_copy_A_B = FALSE;
1913 /* If only the A parameters were specified, copy them to the B state */
1914 /* The B-state parameters correspond to the first nrfpB
1915 * A-state parameters.
1917 for (j = 0; (j < NRFPB(ftype)); j++)
1919 cc[nread++] = cc[j];
1923 /* If nread was 0 or EOF, no parameters were read => use defaults.
1924 * If nread was nrfpA we copied above so nread=nrfp.
1925 * If nread was nrfp we are cool.
1926 * For F_LJC14_Q we allow supplying fudgeQQ only.
1927 * Anything else is an error!
1929 if ((nread != 0) && (nread != EOF) && (nread != NRFP(ftype)) &&
1930 !(ftype == F_LJC14_Q && nread == 1))
1932 gmx_fatal(FARGS, "Incorrect number of parameters - found %d, expected %d or %d for %s.",
1933 nread, NRFPA(ftype), NRFP(ftype),
1934 interaction_function[ftype].longname);
1937 for (j = 0; (j < nread); j++)
1942 /* Check whether we have to use the defaults */
1943 if (nread == NRFP(ftype))
1952 /* nread now holds the number of force parameters read! */
1957 /* When we have multiple terms it would be very dangerous to allow perturbations to a different atom type! */
1958 if (ftype == F_PDIHS)
1960 if ((nparam_defA != nparam_defB) || ((nparam_defA > 1 || nparam_defB > 1) && (param_defA != param_defB)))
1963 "Cannot automatically perturb a torsion with multiple terms to different form.\n"
1964 "Please specify perturbed parameters manually for this torsion in your topology!");
1965 warning_error(wi, errbuf);
1969 if (nread > 0 && nread < NRFPA(ftype))
1971 /* Issue an error, do not use defaults */
1972 sprintf(errbuf, "Not enough parameters, there should be at least %d (or 0 for defaults)", NRFPA(ftype));
1973 warning_error(wi, errbuf);
1976 if (nread == 0 || nread == EOF)
1980 if (interaction_function[ftype].flags & IF_VSITE)
1982 /* set them to NOTSET, will be calculated later */
1983 for (j = 0; (j < MAXFORCEPARAM); j++)
1985 param.c[j] = NOTSET;
1990 param.C1 = -1; /* flag to swap parity of vsite construction */
1997 fprintf(stderr, "NOTE: No default %s types, using zeroes\n",
1998 interaction_function[ftype].longname);
2002 sprintf(errbuf, "No default %s types", interaction_function[ftype].longname);
2003 warning_error(wi, errbuf);
2014 param.C0 = 360 - param.C0;
2017 param.C2 = -param.C2;
2024 /* We only have to issue a warning if these atoms are perturbed! */
2026 for (j = 0; (j < nral); j++)
2028 bPert = bPert || PERTURBED(at->atom[param.a[j]]);
2033 sprintf(errbuf, "No default %s types for perturbed atoms, "
2034 "using normal values", interaction_function[ftype].longname);
2035 warning(wi, errbuf);
2041 if ((ftype == F_PDIHS || ftype == F_ANGRES || ftype == F_ANGRESZ)
2042 && param.c[5] != param.c[2])
2044 gmx_fatal(FARGS, "[ file %s, line %d ]:\n"
2045 " %s multiplicity can not be perturbed %f!=%f",
2046 get_warning_file(wi), get_warning_line(wi),
2047 interaction_function[ftype].longname,
2048 param.c[2], param.c[5]);
2051 if (IS_TABULATED(ftype) && param.c[2] != param.c[0])
2053 gmx_fatal(FARGS, "[ file %s, line %d ]:\n"
2054 " %s table number can not be perturbed %d!=%d",
2055 get_warning_file(wi), get_warning_line(wi),
2056 interaction_function[ftype].longname,
2057 (int)(param.c[0]+0.5), (int)(param.c[2]+0.5));
2060 /* Dont add R-B dihedrals where all parameters are zero (no interaction) */
2061 if (ftype == F_RBDIHS)
2064 for (i = 0; i < NRFP(ftype); i++)
2066 if (param.c[i] != 0)
2077 /* Put the values in the appropriate arrays */
2078 add_param_to_list (&bond[ftype], ¶m);
2080 /* Push additional torsions from FF for ftype==9 if we have them.
2081 * We have already checked that the A/B states do not differ in this case,
2082 * so we do not have to double-check that again, or the vsite stuff.
2083 * In addition, those torsions cannot be automatically perturbed.
2085 if (bDef && ftype == F_PDIHS)
2087 for (i = 1; i < nparam_defA; i++)
2089 /* Advance pointer! */
2091 for (j = 0; (j < NRFPA(ftype)+NRFPB(ftype)); j++)
2093 param.c[j] = param_defA->c[j];
2095 /* And push the next term for this torsion */
2096 add_param_to_list (&bond[ftype], ¶m);
2101 void push_cmap(directive d, t_params bondtype[], t_params bond[],
2102 t_atoms *at, gpp_atomtype_t atype, char *line,
2105 const char *aaformat[MAXATOMLIST+1] =
2116 int i, j, nr, ftype, nral, nread, ncmap_params;
2118 int aa[MAXATOMLIST+1];
2121 t_param param, paramB, *param_defA, *param_defB;
2123 ftype = ifunc_index(d, 1);
2125 nr = bondtype[ftype].nr;
2128 nread = sscanf(line, aaformat[nral-1],
2129 &aa[0], &aa[1], &aa[2], &aa[3], &aa[4], &aa[5]);
2136 else if (nread == nral)
2138 ftype = ifunc_index(d, 1);
2141 /* Check for double atoms and atoms out of bounds */
2142 for (i = 0; i < nral; i++)
2144 if (aa[i] < 1 || aa[i] > at->nr)
2146 gmx_fatal(FARGS, "[ file %s, line %d ]:\n"
2147 "Atom index (%d) in %s out of bounds (1-%d).\n"
2148 "This probably means that you have inserted topology section \"%s\"\n"
2149 "in a part belonging to a different molecule than you intended to.\n"
2150 "In that case move the \"%s\" section to the right molecule.",
2151 get_warning_file(wi), get_warning_line(wi),
2152 aa[i], dir2str(d), at->nr, dir2str(d), dir2str(d));
2155 for (j = i+1; (j < nral); j++)
2159 sprintf(errbuf, "Duplicate atom index (%d) in %s", aa[i], dir2str(d));
2160 warning(wi, errbuf);
2165 /* default force parameters */
2166 for (j = 0; (j < MAXATOMLIST); j++)
2168 param.a[j] = aa[j]-1;
2170 for (j = 0; (j < MAXFORCEPARAM); j++)
2175 /* Get the cmap type for this cmap angle */
2176 bFound = default_cmap_params(bondtype, at, atype, ¶m, FALSE, &cmap_type, &ncmap_params);
2178 /* We want exactly one parameter (the cmap type in state A (currently no state B) back */
2179 if (bFound && ncmap_params == 1)
2181 /* Put the values in the appropriate arrays */
2182 param.c[0] = cmap_type;
2183 add_param_to_list(&bond[ftype], ¶m);
2187 /* This is essentially the same check as in default_cmap_params() done one more time */
2188 gmx_fatal(FARGS, "Unable to assign a cmap type to torsion %d %d %d %d and %d\n",
2189 param.a[0]+1, param.a[1]+1, param.a[2]+1, param.a[3]+1, param.a[4]+1);
2195 void push_vsitesn(directive d, t_params bond[],
2196 t_atoms *at, char *line,
2200 int type, ftype, j, n, ret, nj, a;
2202 double *weight = NULL, weight_tot;
2205 /* default force parameters */
2206 for (j = 0; (j < MAXATOMLIST); j++)
2208 param.a[j] = NOTSET;
2210 for (j = 0; (j < MAXFORCEPARAM); j++)
2216 ret = sscanf(ptr, "%d%n", &a, &n);
2220 gmx_fatal(FARGS, "[ file %s, line %d ]:\n"
2221 " Expected an atom index in section \"%s\"",
2222 get_warning_file(wi), get_warning_line(wi),
2228 ret = sscanf(ptr, "%d%n", &type, &n);
2230 ftype = ifunc_index(d, type);
2236 ret = sscanf(ptr, "%d%n", &a, &n);
2243 srenew(weight, nj+20);
2252 /* Here we use the A-state mass as a parameter.
2253 * Note that the B-state mass has no influence.
2255 weight[nj] = at->atom[atc[nj]].m;
2259 ret = sscanf(ptr, "%lf%n", &(weight[nj]), &n);
2263 gmx_fatal(FARGS, "[ file %s, line %d ]:\n"
2264 " No weight or negative weight found for vsiten constructing atom %d (atom index %d)",
2265 get_warning_file(wi), get_warning_line(wi),
2270 gmx_fatal(FARGS, "Unknown vsiten type %d", type);
2272 weight_tot += weight[nj];
2280 gmx_fatal(FARGS, "[ file %s, line %d ]:\n"
2281 " Expected more than one atom index in section \"%s\"",
2282 get_warning_file(wi), get_warning_line(wi),
2286 if (weight_tot == 0)
2288 gmx_fatal(FARGS, "[ file %s, line %d ]:\n"
2289 " The total mass of the construting atoms is zero",
2290 get_warning_file(wi), get_warning_line(wi));
2293 for (j = 0; j < nj; j++)
2295 param.a[1] = atc[j];
2297 param.c[1] = weight[j]/weight_tot;
2298 /* Put the values in the appropriate arrays */
2299 add_param_to_list (&bond[ftype], ¶m);
2306 void push_mol(int nrmols, t_molinfo mols[], char *pline, int *whichmol,
2314 if (sscanf(pline, "%s%d", type, &copies) != 2)
2320 /* search moleculename */
2321 for (i = 0; ((i < nrmols) && gmx_strcasecmp(type, *(mols[i].name))); i++)
2333 gmx_fatal(FARGS, "No such moleculetype %s", type);
2337 void init_block2(t_block2 *b2, int natom)
2342 snew(b2->nra, b2->nr);
2343 snew(b2->a, b2->nr);
2344 for (i = 0; (i < b2->nr); i++)
2350 void done_block2(t_block2 *b2)
2356 for (i = 0; (i < b2->nr); i++)
2366 void push_excl(char *line, t_block2 *b2)
2370 char base[STRLEN], format[STRLEN];
2372 if (sscanf(line, "%d", &i) == 0)
2377 if ((1 <= i) && (i <= b2->nr))
2385 fprintf(debug, "Unbound atom %d\n", i-1);
2389 strcpy(base, "%*d");
2392 strcpy(format, base);
2393 strcat(format, "%d");
2394 n = sscanf(line, format, &j);
2397 if ((1 <= j) && (j <= b2->nr))
2400 srenew(b2->a[i], ++(b2->nra[i]));
2401 b2->a[i][b2->nra[i]-1] = j;
2402 /* also add the reverse exclusion! */
2403 srenew(b2->a[j], ++(b2->nra[j]));
2404 b2->a[j][b2->nra[j]-1] = i;
2405 strcat(base, "%*d");
2409 gmx_fatal(FARGS, "Invalid Atomnr j: %d, b2->nr: %d\n", j, b2->nr);
2416 void b_to_b2(t_blocka *b, t_block2 *b2)
2421 for (i = 0; (i < b->nr); i++)
2423 for (j = b->index[i]; (j < b->index[i+1]); j++)
2426 srenew(b2->a[i], ++b2->nra[i]);
2427 b2->a[i][b2->nra[i]-1] = a;
2432 void b2_to_b(t_block2 *b2, t_blocka *b)
2438 for (i = 0; (i < b2->nr); i++)
2441 for (j = 0; (j < b2->nra[i]); j++)
2443 b->a[nra+j] = b2->a[i][j];
2447 /* terminate list */
2451 static int icomp(const void *v1, const void *v2)
2453 return (*((atom_id *) v1))-(*((atom_id *) v2));
2456 void merge_excl(t_blocka *excl, t_block2 *b2)
2466 else if (b2->nr != excl->nr)
2468 gmx_fatal(FARGS, "DEATH HORROR: b2->nr = %d, while excl->nr = %d",
2473 fprintf(debug, "Entering merge_excl\n");
2476 /* First copy all entries from excl to b2 */
2479 /* Count and sort the exclusions */
2481 for (i = 0; (i < b2->nr); i++)
2485 /* remove double entries */
2486 qsort(b2->a[i], (size_t)b2->nra[i], (size_t)sizeof(b2->a[i][0]), icomp);
2488 for (j = 1; (j < b2->nra[i]); j++)
2490 if (b2->a[i][j] != b2->a[i][k-1])
2492 b2->a[i][k] = b2->a[i][j];
2501 srenew(excl->a, excl->nra);
2506 int add_atomtype_decoupled(t_symtab *symtab, gpp_atomtype_t at,
2507 t_nbparam ***nbparam, t_nbparam ***pair)
2513 /* Define an atom type with all parameters set to zero (no interactions) */
2516 /* Type for decoupled atoms could be anything,
2517 * this should be changed automatically later when required.
2519 atom.ptype = eptAtom;
2520 for (i = 0; (i < MAXFORCEPARAM); i++)
2525 nr = add_atomtype(at, symtab, &atom, "decoupled", ¶m, -1, 0.0, 0.0, 0.0, 0, 0, 0);
2527 /* Add space in the non-bonded parameters matrix */
2528 realloc_nb_params(at, nbparam, pair);
2533 static void convert_pairs_to_pairsQ(t_params *plist,
2534 real fudgeQQ, t_atoms *atoms)
2536 t_param *paramp1, *paramp2, *paramnew;
2537 int i, j, p1nr, p2nr, p2newnr;
2539 /* Add the pair list to the pairQ list */
2540 p1nr = plist[F_LJ14].nr;
2541 p2nr = plist[F_LJC14_Q].nr;
2542 p2newnr = p1nr + p2nr;
2543 snew(paramnew, p2newnr);
2545 paramp1 = plist[F_LJ14].param;
2546 paramp2 = plist[F_LJC14_Q].param;
2548 /* Fill in the new F_LJC14_Q array with the old one. NOTE:
2549 it may be possible to just ADD the converted F_LJ14 array
2550 to the old F_LJC14_Q array, but since we have to create
2551 a new sized memory structure, better just to deep copy it all.
2554 for (i = 0; i < p2nr; i++)
2556 /* Copy over parameters */
2557 for (j = 0; j < 5; j++) /* entries are 0-4 for F_LJC14_Q */
2559 paramnew[i].c[j] = paramp2[i].c[j];
2562 /* copy over atoms */
2563 for (j = 0; j < 2; j++)
2565 paramnew[i].a[j] = paramp2[i].a[j];
2569 for (i = p2nr; i < p2newnr; i++)
2573 /* Copy over parameters */
2574 paramnew[i].c[0] = fudgeQQ;
2575 paramnew[i].c[1] = atoms->atom[paramp1[j].a[0]].q;
2576 paramnew[i].c[2] = atoms->atom[paramp1[j].a[1]].q;
2577 paramnew[i].c[3] = paramp1[j].c[0];
2578 paramnew[i].c[4] = paramp1[j].c[1];
2580 /* copy over atoms */
2581 paramnew[i].a[0] = paramp1[j].a[0];
2582 paramnew[i].a[1] = paramp1[j].a[1];
2585 /* free the old pairlists */
2586 sfree(plist[F_LJC14_Q].param);
2587 sfree(plist[F_LJ14].param);
2589 /* now assign the new data to the F_LJC14_Q structure */
2590 plist[F_LJC14_Q].param = paramnew;
2591 plist[F_LJC14_Q].nr = p2newnr;
2593 /* Empty the LJ14 pairlist */
2594 plist[F_LJ14].nr = 0;
2595 plist[F_LJ14].param = NULL;
2598 static void generate_LJCpairsNB(t_molinfo *mol, int nb_funct, t_params *nbp)
2600 int n, ntype, i, j, k;
2607 atom = mol->atoms.atom;
2609 ntype = sqrt(nbp->nr);
2611 for (i = 0; i < MAXATOMLIST; i++)
2613 param.a[i] = NOTSET;
2615 for (i = 0; i < MAXFORCEPARAM; i++)
2617 param.c[i] = NOTSET;
2620 /* Add a pair interaction for all non-excluded atom pairs */
2622 for (i = 0; i < n; i++)
2624 for (j = i+1; j < n; j++)
2627 for (k = excl->index[i]; k < excl->index[i+1]; k++)
2629 if (excl->a[k] == j)
2636 if (nb_funct != F_LJ)
2638 gmx_fatal(FARGS, "Can only generate non-bonded pair interactions for Van der Waals type Lennard-Jones");
2642 param.c[0] = atom[i].q;
2643 param.c[1] = atom[j].q;
2644 param.c[2] = nbp->param[ntype*atom[i].type+atom[j].type].c[0];
2645 param.c[3] = nbp->param[ntype*atom[i].type+atom[j].type].c[1];
2646 add_param_to_list(&mol->plist[F_LJC_PAIRS_NB], ¶m);
2652 static void set_excl_all(t_blocka *excl)
2656 /* Get rid of the current exclusions and exclude all atom pairs */
2658 excl->nra = nat*nat;
2659 srenew(excl->a, excl->nra);
2661 for (i = 0; i < nat; i++)
2664 for (j = 0; j < nat; j++)
2669 excl->index[nat] = k;
2672 static void decouple_atoms(t_atoms *atoms, int atomtype_decouple,
2673 int couple_lam0, int couple_lam1)
2677 for (i = 0; i < atoms->nr; i++)
2679 if (couple_lam0 == ecouplamNONE || couple_lam0 == ecouplamVDW)
2681 atoms->atom[i].q = 0.0;
2683 if (couple_lam0 == ecouplamNONE || couple_lam0 == ecouplamQ)
2685 atoms->atom[i].type = atomtype_decouple;
2687 if (couple_lam1 == ecouplamNONE || couple_lam1 == ecouplamVDW)
2689 atoms->atom[i].qB = 0.0;
2691 if (couple_lam1 == ecouplamNONE || couple_lam1 == ecouplamQ)
2693 atoms->atom[i].typeB = atomtype_decouple;
2698 void convert_moltype_couple(t_molinfo *mol, int atomtype_decouple, real fudgeQQ,
2699 int couple_lam0, int couple_lam1,
2700 gmx_bool bCoupleIntra, int nb_funct, t_params *nbp)
2702 convert_pairs_to_pairsQ(mol->plist, fudgeQQ, &mol->atoms);
2705 generate_LJCpairsNB(mol, nb_funct, nbp);
2706 set_excl_all(&mol->excls);
2708 decouple_atoms(&mol->atoms, atomtype_decouple, couple_lam0, couple_lam1);