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, 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.
38 #include "gromacs/math/utilities.h"
39 #include "gromacs/pbcutil/pbc.h"
40 #include "types/simple.h"
42 #include "gromacs/math/vec.h"
44 #include "gromacs/utility/fatalerror.h"
56 real l2 = adressr+adressw;
65 pbc_dx(pbc, (*ref), x, dx);
69 rvec_sub((*ref), x, dx);
75 /* default to explicit simulation */
78 /* constant value for weighting function = adressw */
79 return fr->adress_const_wf;
81 /* plane through center of ref, varies in x direction */
85 /* point at center of ref, assuming cubic geometry */
86 for (i = 0; i < 3; i++)
88 sqr_dl += dx[i]*dx[i];
92 /* default to explicit simulation */
98 /* molecule is coarse grained */
103 /* molecule is explicit */
104 else if (dl < adressr)
111 tmp = cos((dl-adressr)*M_PI/2/adressw);
117 update_adress_weights_com(FILE gmx_unused * fplog,
126 int icg, k, k0, k1, d;
127 real nrcg, inv_ncg, mtot, inv_mtot;
131 real adressr, adressw;
137 int n_hyb, n_ex, n_cg;
143 adresstype = fr->adress_type;
144 adressr = fr->adress_ex_width;
145 adressw = fr->adress_hy_width;
146 massT = mdatoms->massT;
148 ref = &(fr->adress_refs);
151 /* Since this is center of mass AdResS, the vsite is not guaranteed
152 * to be on the same node as the constructing atoms. Therefore we
153 * loop over the charge groups, calculate their center of mass,
154 * then use this to calculate wf for each atom. This wastes vsite
155 * construction, but it's the only way to assure that the explicit
156 * atoms have the same wf as their vsite. */
159 fprintf(fplog, "Calculating center of mass for charge groups %d to %d\n",
162 cgindex = cgs->index;
164 /* Compute the center of mass for all charge groups */
165 for (icg = cg0; (icg < cg1); icg++)
172 wf[k0] = adress_weight(x[k0], adresstype, adressr, adressw, ref, pbc, fr);
177 else if (wf[k0] == 1)
189 for (k = k0; (k < k1); k++)
198 for (k = k0; (k < k1); k++)
200 for (d = 0; (d < DIM); d++)
202 ix[d] += x[k][d]*massT[k];
205 for (d = 0; (d < DIM); d++)
210 /* Calculate the center of gravity if the charge group mtot=0 (only vsites) */
216 for (k = k0; (k < k1); k++)
218 for (d = 0; (d < DIM); d++)
223 for (d = 0; (d < DIM); d++)
229 /* Set wf of all atoms in charge group equal to wf of com */
230 wf[k0] = adress_weight(ix, adresstype, adressr, adressw, ref, pbc, fr);
236 else if (wf[k0] == 1)
245 for (k = (k0+1); (k < k1); k++)
253 void update_adress_weights_atom_per_atom(
262 int icg, k, k0, k1, d;
263 real nrcg, inv_ncg, mtot, inv_mtot;
267 real adressr, adressw;
273 int n_hyb, n_ex, n_cg;
279 adresstype = fr->adress_type;
280 adressr = fr->adress_ex_width;
281 adressw = fr->adress_hy_width;
282 massT = mdatoms->massT;
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];
299 for (k = (k0); (k < k1); k++)
301 wf[k] = adress_weight(x[k], adresstype, adressr, adressw, ref, pbc, fr);
320 update_adress_weights_cog(t_iparams ip[],
327 int i, j, k, nr, nra, inc;
328 int ftype, adresstype;
329 t_iatom avsite, ai, aj, ak, al;
331 real adressr, adressw;
334 int n_hyb, n_ex, n_cg;
336 adresstype = fr->adress_type;
337 adressr = fr->adress_ex_width;
338 adressw = fr->adress_hy_width;
340 ref = &(fr->adress_refs);
348 /* Since this is center of geometry AdResS, we know the vsite
349 * is in the same charge group node as the constructing atoms.
350 * Loop over vsite types, calculate the weight of the vsite,
351 * then assign that weight to the constructing atoms. */
353 for (ftype = 0; (ftype < F_NRE); ftype++)
355 if (interaction_function[ftype].flags & IF_VSITE)
357 nra = interaction_function[ftype].nratoms;
358 nr = ilist[ftype].nr;
359 ia = ilist[ftype].iatoms;
361 for (i = 0; (i < nr); )
363 /* The vsite and first constructing atom */
366 wf[avsite] = adress_weight(x[avsite], adresstype, adressr, adressw, ref, pbc, fr);
373 else if (wf[ai] == 1)
382 /* Assign the vsite wf to rest of constructing atoms depending on type */
431 inc = 3*ip[ia[0]].vsiten.n;
432 for (j = 3; j < inc; j += 3)
439 gmx_fatal(FARGS, "No such vsite type %d in %s, line %d",
440 ftype, __FILE__, __LINE__);
443 /* Increment loop variables */
452 update_adress_weights_atom(int cg0,
463 real adressr, adressw;
468 adresstype = fr->adress_type;
469 adressr = fr->adress_ex_width;
470 adressw = fr->adress_hy_width;
471 massT = mdatoms->massT;
473 ref = &(fr->adress_refs);
474 cgindex = cgs->index;
476 /* Only use first atom in charge group.
477 * We still can't be sure that the vsite and constructing
478 * atoms are on the same processor, so we must calculate
479 * in the same way as com adress. */
481 for (icg = cg0; (icg < cg1); icg++)
485 wf[k0] = adress_weight(x[k0], adresstype, adressr, adressw, ref, pbc, fr);
487 /* Set wf of all atoms in charge group equal to wf of first atom in charge group*/
488 for (k = (k0+1); (k < k1); k++)
496 adress_thermo_force(int start,
505 int iatom, n0, nnn, nrcg, i;
507 real adressw, adressr;
509 unsigned short * ptype;
515 real w, wsq, wmin1, wmin1sq, wp, wt, rinv, sqr_dl, dl;
516 real eps, eps2, F, Geps, Heps2, Fp, dmu_dwp, dwp_dr, fscal;
518 adresstype = fr->adress_type;
519 adressw = fr->adress_hy_width;
520 adressr = fr->adress_ex_width;
521 cgindex = cgs->index;
522 ptype = mdatoms->ptype;
523 ref = &(fr->adress_refs);
526 for (iatom = start; (iatom < start+homenr); iatom++)
528 if (egp_coarsegrained(fr, mdatoms->cENER[iatom]))
530 if (ptype[iatom] == eptVSite)
533 /* is it hybrid or apply the thermodynamics force everywhere?*/
534 if (mdatoms->tf_table_index[iatom] != NO_TF_TABLE)
536 if (fr->n_adress_tf_grps > 0)
538 /* multi component tf is on, select the right table */
539 ATFtab = fr->atf_tabs[mdatoms->tf_table_index[iatom]].data;
540 tabscale = fr->atf_tabs[mdatoms->tf_table_index[iatom]].scale;
544 /* just on component*/
545 ATFtab = fr->atf_tabs[DEFAULT_TF_TABLE].data;
546 tabscale = fr->atf_tabs[DEFAULT_TF_TABLE].scale;
552 pbc_dx(pbc, (*ref), x[iatom], dr);
556 rvec_sub((*ref), x[iatom], dr);
562 /* calculate distace to adress center again */
567 /* plane through center of ref, varies in x direction */
568 sqr_dl = dr[0]*dr[0];
569 rinv = gmx_invsqrt(dr[0]*dr[0]);
572 /* point at center of ref, assuming cubic geometry */
573 for (i = 0; i < 3; i++)
575 sqr_dl += dr[i]*dr[i];
577 rinv = gmx_invsqrt(sqr_dl);
580 /* This case should not happen */
585 /* table origin is adress center */
592 Geps = eps*ATFtab[nnn+2];
593 Heps2 = eps2*ATFtab[nnn+3];
595 F = (Fp+Geps+2.0*Heps2)*tabscale;
599 f[iatom][0] += fscal*dr[0];
600 if (adresstype != eAdressXSplit)
602 f[iatom][1] += fscal*dr[1];
603 f[iatom][2] += fscal*dr[2];
611 gmx_bool egp_explicit(t_forcerec * fr, int egp_nr)
613 return fr->adress_group_explicit[egp_nr];
616 gmx_bool egp_coarsegrained(t_forcerec * fr, int egp_nr)
618 return !fr->adress_group_explicit[egp_nr];