1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*- */
5 * This source code is part of
9 * GROningen MAchine for Chemical Simulations
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2008, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
34 * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
44 #include "gmx_fatal.h"
46 static gmx_bool ip_pert(int ftype, const t_iparams *ip)
51 if (NRFPB(ftype) == 0)
64 bPert = (ip->harmonic.rA != ip->harmonic.rB ||
65 ip->harmonic.krA != ip->harmonic.krB);
68 bPert = (ip->morse.b0A != ip->morse.b0B ||
69 ip->morse.cbA != ip->morse.cbB ||
70 ip->morse.betaA != ip->morse.betaB);
73 bPert = (ip->restraint.lowA != ip->restraint.lowB ||
74 ip->restraint.up1A != ip->restraint.up1B ||
75 ip->restraint.up2A != ip->restraint.up2B ||
76 ip->restraint.kA != ip->restraint.kB);
82 bPert = (ip->pdihs.phiA != ip->pdihs.phiB ||
83 ip->pdihs.cpA != ip->pdihs.cpB);
87 for (i = 0; i < NR_RBDIHS; i++)
89 if (ip->rbdihs.rbcA[i] != ip->rbdihs.rbcB[i])
99 bPert = (ip->tab.kA != ip->tab.kB);
103 for (i = 0; i < DIM; i++)
105 if (ip->posres.pos0A[i] != ip->posres.pos0B[i] ||
106 ip->posres.fcA[i] != ip->posres.fcB[i])
113 bPert = ((ip->dihres.phiA != ip->dihres.phiB) ||
114 (ip->dihres.dphiA != ip->dihres.dphiB) ||
115 (ip->dihres.kfacA != ip->dihres.kfacB));
118 bPert = (ip->lj14.c6A != ip->lj14.c6B ||
119 ip->lj14.c12A != ip->lj14.c12B);
126 gmx_fatal(FARGS, "Function type %s not implemented in ip_pert",
127 interaction_function[ftype].longname);
133 static gmx_bool ip_q_pert(int ftype, const t_iatom *ia,
134 const t_iparams *ip, const real *qA, const real *qB)
136 /* 1-4 interactions do not have the charges stored in the iparams list,
137 * so we need a separate check for those.
139 return (ip_pert(ftype, ip+ia[0]) ||
140 (ftype == F_LJ14 && (qA[ia[1]] != qB[ia[1]] ||
141 qA[ia[2]] != qB[ia[2]])));
144 gmx_bool gmx_mtop_bondeds_free_energy(const gmx_mtop_t *mtop)
146 const gmx_ffparams_t *ffparams;
154 ffparams = &mtop->ffparams;
156 /* Loop over all the function types and compare the A/B parameters */
158 for (i = 0; i < ffparams->ntypes; i++)
160 ftype = ffparams->functype[i];
161 if (interaction_function[ftype].flags & IF_BOND)
163 if (ip_pert(ftype, &ffparams->iparams[i]))
170 /* Check perturbed charges for 1-4 interactions */
171 for (mb = 0; mb < mtop->nmolblock; mb++)
173 atom = mtop->moltype[mtop->molblock[mb].type].atoms.atom;
174 il = &mtop->moltype[mtop->molblock[mb].type].ilist[F_LJ14];
176 for (i = 0; i < il->nr; i += 3)
178 if (atom[ia[i+1]].q != atom[ia[i+1]].qB ||
179 atom[ia[i+2]].q != atom[ia[i+2]].qB)
186 return (bPert ? ilsortFE_UNSORTED : ilsortNO_FE);
189 void gmx_sort_ilist_fe(t_idef *idef, const real *qA, const real *qB)
191 int ftype, nral, i, ic, ib, a;
207 iparams = idef->iparams;
209 for (ftype = 0; ftype < F_NRE; ftype++)
211 if (interaction_function[ftype].flags & IF_BOND)
213 ilist = &idef->il[ftype];
214 iatoms = ilist->iatoms;
219 while (i < ilist->nr)
221 /* Check if this interaction is perturbed */
222 if (ip_q_pert(ftype, iatoms+i, iparams, qA, qB))
224 /* Copy to the perturbed buffer */
225 if (ib + 1 + nral > iabuf_nalloc)
227 iabuf_nalloc = over_alloc_large(ib+1+nral);
228 srenew(iabuf, iabuf_nalloc);
230 for (a = 0; a < 1+nral; a++)
232 iabuf[ib++] = iatoms[i++];
238 for (a = 0; a < 1+nral; a++)
240 iatoms[ic++] = iatoms[i++];
244 /* Now we now the number of non-perturbed interactions */
245 ilist->nr_nonperturbed = ic;
247 /* Copy the buffer with perturbed interactions to the ilist */
248 for (a = 0; a < ib; a++)
250 iatoms[ic++] = iabuf[a];
255 fprintf(debug, "%s non-pert %d pert %d\n",
256 interaction_function[ftype].longname,
257 ilist->nr_nonperturbed,
258 ilist->nr-ilist->nr_nonperturbed);
265 idef->ilsort = ilsortFE_SORTED;