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-2008, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012,2013, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
55 void make_wall_tables(FILE *fplog, const output_env_t oenv,
56 const t_inputrec *ir, const char *tabfn,
57 const gmx_groups_t *groups,
60 int w, negp_pp, egp, i, j;
65 negp_pp = ir->opts.ngener - ir->nwall;
66 nm_ind = groups->grps[egcENER].nm_ind;
70 fprintf(fplog, "Reading user tables for %d energy groups with %d walls\n",
74 snew(fr->wall_tab, ir->nwall);
75 for (w = 0; w < ir->nwall; w++)
77 snew(fr->wall_tab[w], negp_pp);
78 for (egp = 0; egp < negp_pp; egp++)
80 /* If the energy group pair is excluded, we don't need a table */
81 if (!(fr->egp_flags[egp*ir->opts.ngener+negp_pp+w] & EGP_EXCL))
83 tab = &fr->wall_tab[w][egp];
84 sprintf(buf, "%s", tabfn);
85 sprintf(buf + strlen(tabfn) - strlen(ftp2ext(efXVG)) - 1, "_%s_%s.%s",
86 *groups->grpname[nm_ind[egp]],
87 *groups->grpname[nm_ind[negp_pp+w]],
89 *tab = make_tables(fplog, oenv, fr, FALSE, buf, 0, GMX_MAKETABLES_FORCEUSER);
90 /* Since wall have no charge, we can compress the table */
91 for (i = 0; i <= tab->n; i++)
93 for (j = 0; j < 8; j++)
95 tab->data[8*i+j] = tab->data[12*i+4+j];
103 static void wall_error(int a, rvec *x, real r)
106 "An atom is beyond the wall: coordinates %f %f %f, distance %f\n"
107 "You might want to use the mdp option wall_r_linpot",
108 x[a][XX], x[a][YY], x[a][ZZ], r);
111 real do_walls(t_inputrec *ir, t_forcerec *fr, matrix box, t_mdatoms *md,
112 rvec x[], rvec f[], real lambda, real Vlj[], t_nrnb *nrnb)
114 int nwall, w, lam, i;
115 int ntw[2], at, ntype, ngid, ggid, *egp_flags, *type;
116 real *nbfp, lamfac, fac_d[2], fac_r[2], Cd, Cr, Vtot, Fwall[2];
117 real wall_z[2], r, mr, r1, r2, r4, Vd, Vr, V = 0, Fd, Fr, F = 0, dvdlambda;
120 real tabscale, *VFtab, rt, eps, eps2, Yt, Ft, Geps, Heps, Heps2, Fp, VV, FF;
121 unsigned short *gid = md->cENER;
125 ngid = ir->opts.ngener;
128 egp_flags = fr->egp_flags;
130 for (w = 0; w < nwall; w++)
132 ntw[w] = 2*ntype*ir->wall_atomtype[w];
133 switch (ir->wall_type)
136 fac_d[w] = ir->wall_density[w]*M_PI/6;
137 fac_r[w] = ir->wall_density[w]*M_PI/45;
140 fac_d[w] = ir->wall_density[w]*M_PI/2;
141 fac_r[w] = ir->wall_density[w]*M_PI/5;
149 wall_z[1] = box[ZZ][ZZ];
154 for (lam = 0; lam < (md->nPerturbed ? 2 : 1); lam++)
174 for (i = md->start; i < md->start+md->homenr; i++)
176 for (w = 0; w < nwall; w++)
178 /* The wall energy groups are always at the end of the list */
179 ggid = gid[i]*ngid + ngid - nwall + w;
181 /* nbfp now includes the 6.0/12.0 derivative prefactors */
182 Cd = nbfp[ntw[w]+2*at]/6.0;
183 Cr = nbfp[ntw[w]+2*at+1]/12.0;
184 if (!((Cd == 0 && Cr == 0) || (egp_flags[ggid] & EGP_EXCL)))
192 r = wall_z[1] - x[i][ZZ];
194 if (r < ir->wall_r_linpot)
196 mr = ir->wall_r_linpot - r;
197 r = ir->wall_r_linpot;
203 switch (ir->wall_type)
210 tab = &(fr->wall_tab[w][gid[i]]);
211 tabscale = tab->scale;
218 /* Beyond the table range, set V and F to zero */
230 Geps = VFtab[nnn+2]*eps;
231 Heps2 = VFtab[nnn+3]*eps2;
232 Fp = Ft + Geps + Heps2;
234 FF = Fp + Geps + 2.0*Heps2;
241 Geps = VFtab[nnn+2]*eps;
242 Heps2 = VFtab[nnn+3]*eps2;
243 Fp = Ft + Geps + Heps2;
245 FF = Fp + Geps + 2.0*Heps2;
249 F = -lamfac*(Fd + Fr)*tabscale;
260 Vd = fac_d[w]*Cd*r2*r1;
261 Vr = fac_r[w]*Cr*r4*r4*r1;
263 F = lamfac*(9*Vr - 3*Vd)*r1;
274 Vr = fac_r[w]*Cr*r4*r4*r2;
276 F = lamfac*(10*Vr - 4*Vd)*r1;
289 F = lamfac*(12*Vr - 6*Vd)*r1;
302 Vlj[ggid] += lamfac*V;
305 /* Because of the single sum virial calculation we need
306 * to add the full virial contribution of the walls.
307 * Since the force only has a z-component, there is only
308 * a contribution to the z component of the virial tensor.
309 * We could also determine the virial contribution directly,
310 * which would be cheaper here, but that would require extra
311 * communication for f_novirsum for with virtual sites
314 xf_z[XX] -= x[i][XX]*F;
315 xf_z[YY] -= x[i][YY]*F;
316 xf_z[ZZ] -= wall_z[w]*F;
322 dvdlambda += (lam == 0 ? -1 : 1)*Vtot;
325 inc_nrnb(nrnb, eNR_WALLS, md->homenr);
328 for (i = 0; i < DIM; i++)
330 fr->vir_wall_z[i] = -0.5*xf_z[i];