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, 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);
86 bPert = (ip->pdihs.phiA != ip->pdihs.phiB ||
87 ip->pdihs.cpA != ip->pdihs.cpB);
91 for(i=0; i<NR_RBDIHS; i++)
93 if (ip->rbdihs.rbcA[i] != ip->rbdihs.rbcB[i])
103 bPert = (ip->tab.kA != ip->tab.kB);
109 if (ip->posres.pos0A[i] != ip->posres.pos0B[i] ||
110 ip->posres.fcA[i] != ip->posres.fcB[i])
117 bPert = ((ip->dihres.phiA != ip->dihres.phiB) ||
118 (ip->dihres.dphiA != ip->dihres.dphiB) ||
119 (ip->dihres.kfacA != ip->dihres.kfacB));
122 bPert = (ip->lj14.c6A != ip->lj14.c6B ||
123 ip->lj14.c12A != ip->lj14.c12B);
130 gmx_fatal(FARGS,"Function type %s not implemented in ip_pert",
131 interaction_function[ftype].longname);
137 static gmx_bool ip_q_pert(int ftype,const t_iatom *ia,
138 const t_iparams *ip,const real *qA,const real *qB)
140 /* 1-4 interactions do not have the charges stored in the iparams list,
141 * so we need a separate check for those.
143 return (ip_pert(ftype,ip+ia[0]) ||
144 (ftype == F_LJ14 && (qA[ia[1]] != qB[ia[1]] ||
145 qA[ia[2]] != qB[ia[2]])));
148 gmx_bool gmx_mtop_bondeds_free_energy(const gmx_mtop_t *mtop)
150 const gmx_ffparams_t *ffparams;
158 ffparams = &mtop->ffparams;
160 /* Loop over all the function types and compare the A/B parameters */
162 for(i=0; i<ffparams->ntypes; i++)
164 ftype = ffparams->functype[i];
165 if (interaction_function[ftype].flags & IF_BOND)
167 if (ip_pert(ftype,&ffparams->iparams[i]))
174 /* Check perturbed charges for 1-4 interactions */
175 for(mb=0; mb<mtop->nmolblock; mb++)
177 atom = mtop->moltype[mtop->molblock[mb].type].atoms.atom;
178 il = &mtop->moltype[mtop->molblock[mb].type].ilist[F_LJ14];
180 for(i=0; i<il->nr; i+=3)
182 if (atom[ia[i+1]].q != atom[ia[i+1]].qB ||
183 atom[ia[i+2]].q != atom[ia[i+2]].qB)
190 return (bPert ? ilsortFE_UNSORTED : ilsortNO_FE);
193 void gmx_sort_ilist_fe(t_idef *idef,const real *qA,const real *qB)
195 int ftype,nral,i,ic,ib,a;
211 iparams = idef->iparams;
213 for(ftype=0; ftype<F_NRE; ftype++)
215 if (interaction_function[ftype].flags & IF_BOND)
217 ilist = &idef->il[ftype];
218 iatoms = ilist->iatoms;
223 while (i < ilist->nr)
225 /* Check if this interaction is perturbed */
226 if (ip_q_pert(ftype,iatoms+i,iparams,qA,qB))
228 /* Copy to the perturbed buffer */
229 if (ib + 1 + nral > iabuf_nalloc)
231 iabuf_nalloc = over_alloc_large(ib+1+nral);
232 srenew(iabuf,iabuf_nalloc);
234 for(a=0; a<1+nral; a++)
236 iabuf[ib++] = iatoms[i++];
242 for(a=0; a<1+nral; a++)
244 iatoms[ic++] = iatoms[i++];
248 /* Now we now the number of non-perturbed interactions */
249 ilist->nr_nonperturbed = ic;
251 /* Copy the buffer with perturbed interactions to the ilist */
254 iatoms[ic++] = iabuf[a];
259 fprintf(debug,"%s non-pert %d pert %d\n",
260 interaction_function[ftype].longname,
261 ilist->nr_nonperturbed,
262 ilist->nr-ilist->nr_nonperturbed);
269 idef->ilsort = ilsortFE_SORTED;