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.
37 /* This file is completely threadsafe - keep it that way! */
48 #include "gmx_fatal.h"
53 #include "gpp_atomtype.h"
54 #include "gromacs/math/utilities.h"
56 static int round_check(real r, int limit, int ftype, const char *name)
69 if (r-i > 0.01 || r-i < -0.01)
71 gmx_fatal(FARGS, "A non-integer value (%f) was supplied for '%s' in %s",
72 r, name, interaction_function[ftype].longname);
77 gmx_fatal(FARGS, "Value of '%s' in %s is %d, which is smaller than the minimum of %d",
78 name, interaction_function[ftype].longname, i, limit);
84 static void set_ljparams(int comb, double reppow, real v, real w,
87 if (comb == eCOMB_ARITHMETIC || comb == eCOMB_GEOM_SIG_EPS)
91 *c6 = 4*w*pow(v, 6.0);
92 *c12 = 4*w*pow(v, reppow);
96 /* Interpret negative sigma as c6=0 and c12 with -sigma */
98 *c12 = 4*w*pow(-v, reppow);
108 /* A return value of 0 means parameters were assigned successfully,
109 * returning -1 means this is an all-zero interaction that should not be added.
112 assign_param(t_functype ftype, t_iparams *newparam,
113 real old[MAXFORCEPARAM], int comb, double reppow)
117 gmx_bool all_param_zero = TRUE;
120 for (j = 0; (j < MAXFORCEPARAM); j++)
122 newparam->generic.buf[j] = 0.0;
123 /* If all parameters are zero we might not add some interaction types (selected below).
124 * We cannot apply this to ALL interactions, since many have valid reasons for having
125 * zero parameters (e.g. an index to a Cmap interaction, or LJ parameters), but
126 * we use it for angles and torsions that are typically generated automatically.
128 all_param_zero = (all_param_zero == TRUE) && fabs(old[j]) < GMX_REAL_MIN;
131 if (all_param_zero == TRUE)
133 if (IS_ANGLE(ftype) || IS_RESTRAINT_TYPE(ftype) || ftype == F_IDIHS ||
134 ftype == F_PDIHS || ftype == F_PIDIHS || ftype == F_RBDIHS || ftype == F_FOURDIHS)
143 /* Post processing of input data: store cosine iso angle itself */
144 newparam->harmonic.rA = cos(old[0]*DEG2RAD);
145 newparam->harmonic.krA = old[1];
146 newparam->harmonic.rB = cos(old[2]*DEG2RAD);
147 newparam->harmonic.krB = old[3];
150 /* Post processing of input data: store square of length itself */
151 newparam->harmonic.rA = sqr(old[0]);
152 newparam->harmonic.krA = old[1];
153 newparam->harmonic.rB = sqr(old[2]);
154 newparam->harmonic.krB = old[3];
157 newparam->fene.bm = old[0];
158 newparam->fene.kb = old[1];
161 newparam->restraint.lowA = old[0];
162 newparam->restraint.up1A = old[1];
163 newparam->restraint.up2A = old[2];
164 newparam->restraint.kA = old[3];
165 newparam->restraint.lowB = old[4];
166 newparam->restraint.up1B = old[5];
167 newparam->restraint.up2B = old[6];
168 newparam->restraint.kB = old[7];
174 newparam->tab.table = round_check(old[0], 0, ftype, "table index");
175 newparam->tab.kA = old[1];
176 newparam->tab.kB = old[3];
178 case F_CROSS_BOND_BONDS:
179 newparam->cross_bb.r1e = old[0];
180 newparam->cross_bb.r2e = old[1];
181 newparam->cross_bb.krr = old[2];
183 case F_CROSS_BOND_ANGLES:
184 newparam->cross_ba.r1e = old[0];
185 newparam->cross_ba.r2e = old[1];
186 newparam->cross_ba.r3e = old[2];
187 newparam->cross_ba.krt = old[3];
190 newparam->u_b.thetaA = old[0];
191 newparam->u_b.kthetaA = old[1];
192 newparam->u_b.r13A = old[2];
193 newparam->u_b.kUBA = old[3];
194 newparam->u_b.thetaB = old[4];
195 newparam->u_b.kthetaB = old[5];
196 newparam->u_b.r13B = old[6];
197 newparam->u_b.kUBB = old[7];
199 case F_QUARTIC_ANGLES:
200 newparam->qangle.theta = old[0];
201 for (i = 0; i < 5; i++)
203 newparam->qangle.c[i] = old[i+1];
206 case F_LINEAR_ANGLES:
207 newparam->linangle.aA = old[0];
208 newparam->linangle.klinA = old[1];
209 newparam->linangle.aB = old[2];
210 newparam->linangle.klinB = old[3];
216 newparam->harmonic.rA = old[0];
217 newparam->harmonic.krA = old[1];
218 newparam->harmonic.rB = old[2];
219 newparam->harmonic.krB = old[3];
222 newparam->morse.b0A = old[0];
223 newparam->morse.cbA = old[1];
224 newparam->morse.betaA = old[2];
225 newparam->morse.b0B = old[3];
226 newparam->morse.cbB = old[4];
227 newparam->morse.betaB = old[5];
230 newparam->cubic.b0 = old[0];
231 newparam->cubic.kb = old[1];
232 newparam->cubic.kcub = old[2];
237 newparam->polarize.alpha = old[0];
240 newparam->anharm_polarize.alpha = old[0];
241 newparam->anharm_polarize.drcut = old[1];
242 newparam->anharm_polarize.khyp = old[2];
245 newparam->wpol.al_x = old[0];
246 newparam->wpol.al_y = old[1];
247 newparam->wpol.al_z = old[2];
248 newparam->wpol.rOH = old[3];
249 newparam->wpol.rHH = old[4];
250 newparam->wpol.rOD = old[5];
253 newparam->thole.a = old[0];
254 newparam->thole.alpha1 = old[1];
255 newparam->thole.alpha2 = old[2];
256 if ((old[1] > 0) && (old[2] > 0))
258 newparam->thole.rfac = old[0]*pow(old[1]*old[2], -1.0/6.0);
262 newparam->thole.rfac = 1;
266 newparam->bham.a = old[0];
267 newparam->bham.b = old[1];
268 newparam->bham.c = old[2];
271 set_ljparams(comb, reppow, old[0], old[1], &newparam->lj14.c6A, &newparam->lj14.c12A);
272 set_ljparams(comb, reppow, old[2], old[3], &newparam->lj14.c6B, &newparam->lj14.c12B);
275 newparam->ljc14.fqq = old[0];
276 newparam->ljc14.qi = old[1];
277 newparam->ljc14.qj = old[2];
278 set_ljparams(comb, reppow, old[3], old[4], &newparam->ljc14.c6, &newparam->ljc14.c12);
281 newparam->ljcnb.qi = old[0];
282 newparam->ljcnb.qj = old[1];
283 set_ljparams(comb, reppow, old[2], old[3], &newparam->ljcnb.c6, &newparam->ljcnb.c12);
286 set_ljparams(comb, reppow, old[0], old[1], &newparam->lj.c6, &newparam->lj.c12);
292 newparam->pdihs.phiA = old[0];
293 newparam->pdihs.cpA = old[1];
295 /* Change 20100720: Amber occasionally uses negative multiplicities (mathematically OK),
296 * so I have changed the lower limit to -99 /EL
298 newparam->pdihs.phiB = old[3];
299 newparam->pdihs.cpB = old[4];
300 /* If both force constants are zero there is no interaction. Return -1 to signal
301 * this entry should NOT be added.
303 if (fabs(newparam->pdihs.cpA) < GMX_REAL_MIN && fabs(newparam->pdihs.cpB) < GMX_REAL_MIN)
308 newparam->pdihs.mult = round_check(old[2], -99, ftype, "multiplicity");
312 newparam->posres.fcA[XX] = old[0];
313 newparam->posres.fcA[YY] = old[1];
314 newparam->posres.fcA[ZZ] = old[2];
315 newparam->posres.fcB[XX] = old[3];
316 newparam->posres.fcB[YY] = old[4];
317 newparam->posres.fcB[ZZ] = old[5];
318 newparam->posres.pos0A[XX] = old[6];
319 newparam->posres.pos0A[YY] = old[7];
320 newparam->posres.pos0A[ZZ] = old[8];
321 newparam->posres.pos0B[XX] = old[9];
322 newparam->posres.pos0B[YY] = old[10];
323 newparam->posres.pos0B[ZZ] = old[11];
326 newparam->fbposres.geom = round_check(old[0], 0, ftype, "geometry");
327 if (!(newparam->fbposres.geom > efbposresZERO && newparam->fbposres.geom < efbposresNR))
329 gmx_fatal(FARGS, "Invalid geometry for flat-bottomed position restraint.\n"
330 "Expected number between 1 and %d. Found %d\n", efbposresNR-1,
331 newparam->fbposres.geom);
333 newparam->fbposres.r = old[1];
334 newparam->fbposres.k = old[2];
335 newparam->fbposres.pos0[XX] = old[3];
336 newparam->fbposres.pos0[YY] = old[4];
337 newparam->fbposres.pos0[ZZ] = old[5];
340 newparam->disres.label = round_check(old[0], 0, ftype, "label");
341 newparam->disres.type = round_check(old[1], 1, ftype, "type'");
342 newparam->disres.low = old[2];
343 newparam->disres.up1 = old[3];
344 newparam->disres.up2 = old[4];
345 newparam->disres.kfac = old[5];
348 newparam->orires.ex = round_check(old[0], 1, ftype, "experiment") - 1;
349 newparam->orires.label = round_check(old[1], 1, ftype, "label");
350 newparam->orires.power = round_check(old[2], 0, ftype, "power");
351 newparam->orires.c = old[3];
352 newparam->orires.obs = old[4];
353 newparam->orires.kfac = old[5];
356 newparam->dihres.phiA = old[0];
357 newparam->dihres.dphiA = old[1];
358 newparam->dihres.kfacA = old[2];
359 newparam->dihres.phiB = old[3];
360 newparam->dihres.dphiB = old[4];
361 newparam->dihres.kfacB = old[5];
364 for (i = 0; (i < NR_RBDIHS); i++)
366 newparam->rbdihs.rbcA[i] = old[i];
367 newparam->rbdihs.rbcB[i] = old[NR_RBDIHS+i];
371 /* Read the dihedral parameters to temporary arrays,
372 * and convert them to the computationally faster
373 * Ryckaert-Bellemans form.
375 /* Use conversion formula for OPLS to Ryckaert-Bellemans: */
376 newparam->rbdihs.rbcA[0] = old[1]+0.5*(old[0]+old[2]);
377 newparam->rbdihs.rbcA[1] = 0.5*(3.0*old[2]-old[0]);
378 newparam->rbdihs.rbcA[2] = 4.0*old[3]-old[1];
379 newparam->rbdihs.rbcA[3] = -2.0*old[2];
380 newparam->rbdihs.rbcA[4] = -4.0*old[3];
381 newparam->rbdihs.rbcA[5] = 0.0;
383 newparam->rbdihs.rbcB[0] = old[NR_FOURDIHS+1]+0.5*(old[NR_FOURDIHS+0]+old[NR_FOURDIHS+2]);
384 newparam->rbdihs.rbcB[1] = 0.5*(3.0*old[NR_FOURDIHS+2]-old[NR_FOURDIHS+0]);
385 newparam->rbdihs.rbcB[2] = 4.0*old[NR_FOURDIHS+3]-old[NR_FOURDIHS+1];
386 newparam->rbdihs.rbcB[3] = -2.0*old[NR_FOURDIHS+2];
387 newparam->rbdihs.rbcB[4] = -4.0*old[NR_FOURDIHS+3];
388 newparam->rbdihs.rbcB[5] = 0.0;
392 newparam->constr.dA = old[0];
393 newparam->constr.dB = old[1];
396 newparam->settle.doh = old[0];
397 newparam->settle.dhh = old[1];
405 newparam->vsite.a = old[0];
406 newparam->vsite.b = old[1];
407 newparam->vsite.c = old[2];
408 newparam->vsite.d = old[3];
409 newparam->vsite.e = old[4];
410 newparam->vsite.f = old[5];
413 newparam->vsite.a = old[1] * cos(DEG2RAD * old[0]);
414 newparam->vsite.b = old[1] * sin(DEG2RAD * old[0]);
415 newparam->vsite.c = old[2];
416 newparam->vsite.d = old[3];
417 newparam->vsite.e = old[4];
418 newparam->vsite.f = old[5];
421 newparam->vsiten.n = round_check(old[0], 1, ftype, "number of atoms");
422 newparam->vsiten.a = old[1];
425 newparam->cmap.cmapA = old[0];
426 newparam->cmap.cmapB = old[1];
431 newparam->gb.sar = old[0];
432 newparam->gb.st = old[1];
433 newparam->gb.pi = old[2];
434 newparam->gb.gbr = old[3];
435 newparam->gb.bmlt = old[4];
438 gmx_fatal(FARGS, "unknown function type %d in %s line %d",
439 ftype, __FILE__, __LINE__);
444 static int enter_params(gmx_ffparams_t *ffparams, t_functype ftype,
445 real forceparams[MAXFORCEPARAM], int comb, real reppow,
446 int start, gmx_bool bAppend)
452 if ( (rc = assign_param(ftype, &newparam, forceparams, comb, reppow)) < 0)
454 /* -1 means this interaction is all-zero and should not be added */
460 for (type = start; (type < ffparams->ntypes); type++)
462 if (ffparams->functype[type] == ftype)
466 /* Occasionally, the way the 1-3 reference distance is
467 * computed can lead to non-binary-identical results, but I
469 if ((gmx_within_tol(newparam.gb.sar, ffparams->iparams[type].gb.sar, 1e-6)) &&
470 (gmx_within_tol(newparam.gb.st, ffparams->iparams[type].gb.st, 1e-6)) &&
471 (gmx_within_tol(newparam.gb.pi, ffparams->iparams[type].gb.pi, 1e-6)) &&
472 (gmx_within_tol(newparam.gb.gbr, ffparams->iparams[type].gb.gbr, 1e-6)) &&
473 (gmx_within_tol(newparam.gb.bmlt, ffparams->iparams[type].gb.bmlt, 1e-6)))
480 if (memcmp(&newparam, &ffparams->iparams[type], (size_t)sizeof(newparam)) == 0)
490 type = ffparams->ntypes;
494 fprintf(debug, "copying newparam to ffparams->iparams[%d] (ntypes=%d)\n",
495 type, ffparams->ntypes);
497 memcpy(&ffparams->iparams[type], &newparam, (size_t)sizeof(newparam));
500 ffparams->functype[type] = ftype;
505 static void append_interaction(t_ilist *ilist,
506 int type, int nral, atom_id a[MAXATOMLIST])
513 ilist->iatoms[where1++] = type;
514 for (i = 0; (i < nral); i++)
516 ilist->iatoms[where1++] = a[i];
520 static void enter_function(t_params *p, t_functype ftype, int comb, real reppow,
521 gmx_ffparams_t *ffparams, t_ilist *il,
523 gmx_bool bNB, gmx_bool bAppend)
525 int k, type, nr, nral, delta, start;
527 start = ffparams->ntypes;
530 for (k = 0; k < nr; k++)
532 if (*maxtypes <= ffparams->ntypes)
535 srenew(ffparams->functype, *maxtypes);
536 srenew(ffparams->iparams, *maxtypes);
539 fprintf(debug, "%s, line %d: srenewed idef->functype and idef->iparams to %d\n",
540 __FILE__, __LINE__, *maxtypes);
543 type = enter_params(ffparams, ftype, p->param[k].c, comb, reppow, start, bAppend);
544 /* Type==-1 is used as a signal that this interaction is all-zero and should not be added. */
545 if (!bNB && type >= 0)
549 srenew(il->iatoms, il->nr+delta);
550 append_interaction(il, type, nral, p->param[k].a);
555 void convert_params(int atnr, t_params nbtypes[],
556 t_molinfo *mi, int comb, double reppow, real fudgeQQ,
559 int i, j, maxtypes, mt;
567 ffp = &mtop->ffparams;
570 ffp->functype = NULL;
572 ffp->reppow = reppow;
574 enter_function(&(nbtypes[F_LJ]), (t_functype)F_LJ, comb, reppow, ffp, NULL,
575 &maxtypes, TRUE, TRUE);
576 enter_function(&(nbtypes[F_BHAM]), (t_functype)F_BHAM, comb, reppow, ffp, NULL,
577 &maxtypes, TRUE, TRUE);
579 for (mt = 0; mt < mtop->nmoltype; mt++)
581 molt = &mtop->moltype[mt];
582 for (i = 0; (i < F_NRE); i++)
584 molt->ilist[i].nr = 0;
585 molt->ilist[i].iatoms = NULL;
587 plist = mi[mt].plist;
589 flags = interaction_function[i].flags;
590 if ((i != F_LJ) && (i != F_BHAM) && ((flags & IF_BOND) ||
591 (flags & IF_VSITE) ||
592 (flags & IF_CONSTRAINT)))
594 enter_function(&(plist[i]), (t_functype)i, comb, reppow,
595 ffp, &molt->ilist[i],
596 &maxtypes, FALSE, (i == F_POSRES || i == F_FBPOSRES));
602 fprintf(debug, "%s, line %d: There are %d functypes in idef\n",
603 __FILE__, __LINE__, ffp->ntypes);
606 ffp->fudgeQQ = fudgeQQ;