2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2009 Christoph Junghans, Brad Lambeth.
5 * Copyright (c) 2011,2012,2013,2014,2015, by the GROMACS development team, led by
6 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 * and including many others, as listed in the AUTHORS file in the
8 * top-level source directory and at http://www.gromacs.org.
10 * GROMACS is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1
13 * of the License, or (at your option) any later version.
15 * GROMACS is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with GROMACS; if not, see
22 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * If you want to redistribute modifications to GROMACS, please
26 * consider that scientific software is very special. Version
27 * control is crucial - bugs must be traceable. We will be happy to
28 * consider code for inclusion in the official distribution, but
29 * derived work must not be called official GROMACS. Details are found
30 * in the README & COPYING files - if they are missing, get the
31 * official version at http://www.gromacs.org.
33 * To help us fund GROMACS development, we humbly ask that you cite
34 * the research papers on the package. Check out http://www.gromacs.org.
43 #include "gromacs/legacyheaders/typedefs.h"
44 #include "gromacs/legacyheaders/types/simple.h"
45 #include "gromacs/math/utilities.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/pbcutil/pbc.h"
48 #include "gromacs/utility/fatalerror.h"
60 real l2 = adressr+adressw;
69 pbc_dx(pbc, (*ref), x, dx);
73 rvec_sub((*ref), x, dx);
79 /* default to explicit simulation */
82 /* constant value for weighting function = adressw */
83 return fr->adress_const_wf;
85 /* plane through center of ref, varies in x direction */
89 /* point at center of ref, assuming cubic geometry */
90 for (i = 0; i < 3; i++)
92 sqr_dl += dx[i]*dx[i];
96 /* default to explicit simulation */
100 dl = std::sqrt(sqr_dl);
102 /* molecule is coarse grained */
107 /* molecule is explicit */
108 else if (dl < adressr)
115 tmp = std::cos((dl-adressr)*M_PI/2/adressw);
121 update_adress_weights_com(FILE gmx_unused * fplog,
130 int icg, k, k0, k1, d;
131 real nrcg, inv_ncg, mtot, inv_mtot;
135 real adressr, adressw;
141 int n_hyb, n_ex, n_cg;
147 adresstype = fr->adress_type;
148 adressr = fr->adress_ex_width;
149 adressw = fr->adress_hy_width;
150 massT = mdatoms->massT;
152 ref = &(fr->adress_refs);
155 /* Since this is center of mass AdResS, the vsite is not guaranteed
156 * to be on the same node as the constructing atoms. Therefore we
157 * loop over the charge groups, calculate their center of mass,
158 * then use this to calculate wf for each atom. This wastes vsite
159 * construction, but it's the only way to assure that the explicit
160 * atoms have the same wf as their vsite. */
163 fprintf(fplog, "Calculating center of mass for charge groups %d to %d\n",
166 cgindex = cgs->index;
168 /* Compute the center of mass for all charge groups */
169 for (icg = cg0; (icg < cg1); icg++)
176 wf[k0] = adress_weight(x[k0], adresstype, adressr, adressw, ref, pbc, fr);
181 else if (wf[k0] == 1)
193 for (k = k0; (k < k1); k++)
202 for (k = k0; (k < k1); k++)
204 for (d = 0; (d < DIM); d++)
206 ix[d] += x[k][d]*massT[k];
209 for (d = 0; (d < DIM); d++)
214 /* Calculate the center of gravity if the charge group mtot=0 (only vsites) */
220 for (k = k0; (k < k1); k++)
222 for (d = 0; (d < DIM); d++)
227 for (d = 0; (d < DIM); d++)
233 /* Set wf of all atoms in charge group equal to wf of com */
234 wf[k0] = adress_weight(ix, adresstype, adressr, adressw, ref, pbc, fr);
240 else if (wf[k0] == 1)
249 for (k = (k0+1); (k < k1); k++)
257 void update_adress_weights_atom_per_atom(
269 real adressr, adressw;
274 int n_hyb, n_ex, n_cg;
280 adresstype = fr->adress_type;
281 adressr = fr->adress_ex_width;
282 adressw = fr->adress_hy_width;
284 ref = &(fr->adress_refs);
286 cgindex = cgs->index;
288 /* Weighting function is determined for each atom individually.
289 * This is an approximation
290 * as in the theory requires an interpolation based on the center of masses.
291 * Should be used with caution */
293 for (icg = cg0; (icg < cg1); icg++)
296 k1 = cgindex[icg + 1];
298 for (k = (k0); (k < k1); k++)
300 wf[k] = adress_weight(x[k], adresstype, adressr, adressw, ref, pbc, fr);
319 update_adress_weights_cog(t_iparams ip[],
326 int i, j, nr, nra, inc;
327 int ftype, adresstype;
328 t_iatom avsite, ai, aj, ak, al;
330 real adressr, adressw;
333 int n_hyb, n_ex, n_cg;
335 adresstype = fr->adress_type;
336 adressr = fr->adress_ex_width;
337 adressw = fr->adress_hy_width;
339 ref = &(fr->adress_refs);
347 /* Since this is center of geometry AdResS, we know the vsite
348 * is in the same charge group node as the constructing atoms.
349 * Loop over vsite types, calculate the weight of the vsite,
350 * then assign that weight to the constructing atoms. */
352 for (ftype = 0; (ftype < F_NRE); ftype++)
354 if (interaction_function[ftype].flags & IF_VSITE)
356 nra = interaction_function[ftype].nratoms;
357 nr = ilist[ftype].nr;
358 ia = ilist[ftype].iatoms;
360 for (i = 0; (i < nr); )
362 /* The vsite and first constructing atom */
365 wf[avsite] = adress_weight(x[avsite], adresstype, adressr, adressw, ref, pbc, fr);
372 else if (wf[ai] == 1)
381 /* Assign the vsite wf to rest of constructing atoms depending on type */
430 inc = 3*ip[ia[0]].vsiten.n;
431 for (j = 3; j < inc; j += 3)
438 gmx_fatal(FARGS, "No such vsite type %d in %s, line %d",
439 ftype, __FILE__, __LINE__);
442 /* Increment loop variables */
451 update_adress_weights_atom(int cg0,
462 real adressr, adressw;
466 adresstype = fr->adress_type;
467 adressr = fr->adress_ex_width;
468 adressw = fr->adress_hy_width;
470 ref = &(fr->adress_refs);
471 cgindex = cgs->index;
473 /* Only use first atom in charge group.
474 * We still can't be sure that the vsite and constructing
475 * atoms are on the same processor, so we must calculate
476 * in the same way as com adress. */
478 for (icg = cg0; (icg < cg1); icg++)
482 wf[k0] = adress_weight(x[k0], adresstype, adressr, adressw, ref, pbc, fr);
484 /* Set wf of all atoms in charge group equal to wf of first atom in charge group*/
485 for (k = (k0+1); (k < k1); k++)
493 adress_thermo_force(int start,
501 int iatom, n0, nnn, i;
503 unsigned short * ptype;
508 real wt, rinv, sqr_dl, dl;
509 real eps, eps2, F, Geps, Heps2, Fp, fscal;
511 adresstype = fr->adress_type;
512 ptype = mdatoms->ptype;
513 ref = &(fr->adress_refs);
515 for (iatom = start; (iatom < start+homenr); iatom++)
517 if (egp_coarsegrained(fr, mdatoms->cENER[iatom]))
519 if (ptype[iatom] == eptVSite)
521 /* is it hybrid or apply the thermodynamics force everywhere?*/
522 if (mdatoms->tf_table_index[iatom] != NO_TF_TABLE)
524 if (fr->n_adress_tf_grps > 0)
526 /* multi component tf is on, select the right table */
527 ATFtab = fr->atf_tabs[mdatoms->tf_table_index[iatom]].data;
528 tabscale = fr->atf_tabs[mdatoms->tf_table_index[iatom]].scale;
532 /* just on component*/
533 ATFtab = fr->atf_tabs[DEFAULT_TF_TABLE].data;
534 tabscale = fr->atf_tabs[DEFAULT_TF_TABLE].scale;
539 pbc_dx(pbc, (*ref), x[iatom], dr);
543 rvec_sub((*ref), x[iatom], dr);
549 /* calculate distace to adress center again */
554 /* plane through center of ref, varies in x direction */
555 sqr_dl = dr[0]*dr[0];
556 rinv = gmx_invsqrt(dr[0]*dr[0]);
559 /* point at center of ref, assuming cubic geometry */
560 for (i = 0; i < 3; i++)
562 sqr_dl += dr[i]*dr[i];
564 rinv = gmx_invsqrt(sqr_dl);
567 /* This case should not happen */
571 dl = std::sqrt(sqr_dl);
572 /* table origin is adress center */
574 n0 = static_cast<int>(wt);
579 Geps = eps*ATFtab[nnn+2];
580 Heps2 = eps2*ATFtab[nnn+3];
582 F = (Fp+Geps+2.0*Heps2)*tabscale;
586 f[iatom][0] += fscal*dr[0];
587 if (adresstype != eAdressXSplit)
589 f[iatom][1] += fscal*dr[1];
590 f[iatom][2] += fscal*dr[2];
598 gmx_bool egp_explicit(t_forcerec * fr, int egp_nr)
600 return fr->adress_group_explicit[egp_nr];
603 gmx_bool egp_coarsegrained(t_forcerec * fr, int egp_nr)
605 return !fr->adress_group_explicit[egp_nr];