1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*- */
4 * This file is part of the GROMACS molecular simulation package.
6 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
7 * Copyright (c) 2001-2008, The GROMACS development team,
8 * check out http://www.gromacs.org for more information.
9 * Copyright (c) 2012,2013, by the GROMACS development team, led by
10 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
11 * others, as listed in the AUTHORS file in the top-level source
12 * directory and at http://www.gromacs.org.
14 * GROMACS is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public License
16 * as published by the Free Software Foundation; either version 2.1
17 * of the License, or (at your option) any later version.
19 * GROMACS is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with GROMACS; if not, see
26 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
27 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 * If you want to redistribute modifications to GROMACS, please
30 * consider that scientific software is very special. Version
31 * control is crucial - bugs must be traceable. We will be happy to
32 * consider code for inclusion in the official distribution, but
33 * derived work must not be called official GROMACS. Details are found
34 * in the README & COPYING files - if they are missing, get the
35 * official version at http://www.gromacs.org.
37 * To help us fund GROMACS development, we humbly ask that you cite
38 * the research papers on the package. Check out http://www.gromacs.org.
48 #include "gmx_fatal.h"
50 static gmx_bool ip_pert(int ftype, const t_iparams *ip)
55 if (NRFPB(ftype) == 0)
68 bPert = (ip->harmonic.rA != ip->harmonic.rB ||
69 ip->harmonic.krA != ip->harmonic.krB);
72 bPert = (ip->morse.b0A != ip->morse.b0B ||
73 ip->morse.cbA != ip->morse.cbB ||
74 ip->morse.betaA != ip->morse.betaB);
77 bPert = (ip->restraint.lowA != ip->restraint.lowB ||
78 ip->restraint.up1A != ip->restraint.up1B ||
79 ip->restraint.up2A != ip->restraint.up2B ||
80 ip->restraint.kA != ip->restraint.kB);
83 bPert = (ip->u_b.thetaA != ip->u_b.thetaB ||
84 ip->u_b.kthetaA != ip->u_b.kthetaB ||
85 ip->u_b.r13A != ip->u_b.r13B ||
86 ip->u_b.kUBA != ip->u_b.kUBB);
92 bPert = (ip->pdihs.phiA != ip->pdihs.phiB ||
93 ip->pdihs.cpA != ip->pdihs.cpB);
97 for (i = 0; i < NR_RBDIHS; i++)
99 if (ip->rbdihs.rbcA[i] != ip->rbdihs.rbcB[i])
109 bPert = (ip->tab.kA != ip->tab.kB);
113 for (i = 0; i < DIM; i++)
115 if (ip->posres.pos0A[i] != ip->posres.pos0B[i] ||
116 ip->posres.fcA[i] != ip->posres.fcB[i])
123 bPert = ((ip->dihres.phiA != ip->dihres.phiB) ||
124 (ip->dihres.dphiA != ip->dihres.dphiB) ||
125 (ip->dihres.kfacA != ip->dihres.kfacB));
128 bPert = (ip->lj14.c6A != ip->lj14.c6B ||
129 ip->lj14.c12A != ip->lj14.c12B);
136 gmx_fatal(FARGS, "Function type %s not implemented in ip_pert",
137 interaction_function[ftype].longname);
143 static gmx_bool ip_q_pert(int ftype, const t_iatom *ia,
144 const t_iparams *ip, const real *qA, const real *qB)
146 /* 1-4 interactions do not have the charges stored in the iparams list,
147 * so we need a separate check for those.
149 return (ip_pert(ftype, ip+ia[0]) ||
150 (ftype == F_LJ14 && (qA[ia[1]] != qB[ia[1]] ||
151 qA[ia[2]] != qB[ia[2]])));
154 gmx_bool gmx_mtop_bondeds_free_energy(const gmx_mtop_t *mtop)
156 const gmx_ffparams_t *ffparams;
164 ffparams = &mtop->ffparams;
166 /* Loop over all the function types and compare the A/B parameters */
168 for (i = 0; i < ffparams->ntypes; i++)
170 ftype = ffparams->functype[i];
171 if (interaction_function[ftype].flags & IF_BOND)
173 if (ip_pert(ftype, &ffparams->iparams[i]))
180 /* Check perturbed charges for 1-4 interactions */
181 for (mb = 0; mb < mtop->nmolblock; mb++)
183 atom = mtop->moltype[mtop->molblock[mb].type].atoms.atom;
184 il = &mtop->moltype[mtop->molblock[mb].type].ilist[F_LJ14];
186 for (i = 0; i < il->nr; i += 3)
188 if (atom[ia[i+1]].q != atom[ia[i+1]].qB ||
189 atom[ia[i+2]].q != atom[ia[i+2]].qB)
199 void gmx_sort_ilist_fe(t_idef *idef, const real *qA, const real *qB)
201 int ftype, nral, i, ic, ib, a;
217 iparams = idef->iparams;
219 for (ftype = 0; ftype < F_NRE; ftype++)
221 if (interaction_function[ftype].flags & IF_BOND)
223 ilist = &idef->il[ftype];
224 iatoms = ilist->iatoms;
229 while (i < ilist->nr)
231 /* Check if this interaction is perturbed */
232 if (ip_q_pert(ftype, iatoms+i, iparams, qA, qB))
234 /* Copy to the perturbed buffer */
235 if (ib + 1 + nral > iabuf_nalloc)
237 iabuf_nalloc = over_alloc_large(ib+1+nral);
238 srenew(iabuf, iabuf_nalloc);
240 for (a = 0; a < 1+nral; a++)
242 iabuf[ib++] = iatoms[i++];
248 for (a = 0; a < 1+nral; a++)
250 iatoms[ic++] = iatoms[i++];
254 /* Now we now the number of non-perturbed interactions */
255 ilist->nr_nonperturbed = ic;
257 /* Copy the buffer with perturbed interactions to the ilist */
258 for (a = 0; a < ib; a++)
260 iatoms[ic++] = iabuf[a];
265 fprintf(debug, "%s non-pert %d pert %d\n",
266 interaction_function[ftype].longname,
267 ilist->nr_nonperturbed,
268 ilist->nr-ilist->nr_nonperturbed);
275 idef->ilsort = ilsortFE_SORTED;