2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2009 Christoph Junghans, Brad Lambeth.
5 * Copyright (c) 2012,2013, by the GROMACS development team, led by
6 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
7 * others, as listed in the AUTHORS file in the top-level source
8 * 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.
40 #include "types/simple.h"
54 real l2 = adressr+adressw;
63 pbc_dx(pbc,(*ref),x,dx);
67 rvec_sub((*ref),x,dx);
73 /* default to explicit simulation */
76 /* constant value for weighting function = adressw */
77 return fr->adress_const_wf;
79 /* plane through center of ref, varies in x direction */
83 /* point at center of ref, assuming cubic geometry */
85 sqr_dl += dx[i]*dx[i];
89 /* default to explicit simulation */
95 /* molecule is coarse grained */
100 /* molecule is explicit */
101 else if (dl < adressr)
108 tmp=cos((dl-adressr)*M_PI/2/adressw);
114 update_adress_weights_com(FILE * fplog,
124 real nrcg,inv_ncg,mtot,inv_mtot;
128 real adressr,adressw;
134 int n_hyb, n_ex, n_cg;
140 adresstype = fr->adress_type;
141 adressr = fr->adress_ex_width;
142 adressw = fr->adress_hy_width;
143 massT = mdatoms->massT;
145 ref = &(fr->adress_refs);
148 /* Since this is center of mass AdResS, the vsite is not guaranteed
149 * to be on the same node as the constructing atoms. Therefore we
150 * loop over the charge groups, calculate their center of mass,
151 * then use this to calculate wf for each atom. This wastes vsite
152 * construction, but it's the only way to assure that the explicit
153 * atoms have the same wf as their vsite. */
156 fprintf(fplog,"Calculating center of mass for charge groups %d to %d\n",
159 cgindex = cgs->index;
161 /* Compute the center of mass for all charge groups */
162 for(icg=cg0; (icg<cg1); icg++)
169 wf[k0] = adress_weight(x[k0],adresstype,adressr,adressw,ref,pbc,fr);
170 if (wf[k0]==0){ n_cg++;}
171 else if (wf[k0]==1){ n_ex++;}
177 for(k=k0; (k<k1); k++)
186 for(k=k0; (k<k1); k++)
188 for(d=0; (d<DIM); d++)
190 ix[d] += x[k][d]*massT[k];
193 for(d=0; (d<DIM); d++)
198 /* Calculate the center of gravity if the charge group mtot=0 (only vsites) */
204 for(k=k0; (k<k1); k++)
206 for(d=0; (d<DIM); d++)
211 for(d=0; (d<DIM); d++)
217 /* Set wf of all atoms in charge group equal to wf of com */
218 wf[k0] = adress_weight(ix,adresstype,adressr,adressw,ref,pbc, fr);
220 if (wf[k0]==0){ n_cg++;}
221 else if (wf[k0]==1){ n_ex++;}
224 for(k=(k0+1); (k<k1); k++)
232 void update_adress_weights_atom_per_atom(
242 real nrcg,inv_ncg,mtot,inv_mtot;
246 real adressr,adressw;
252 int n_hyb, n_ex, n_cg;
258 adresstype = fr->adress_type;
259 adressr = fr->adress_ex_width;
260 adressw = fr->adress_hy_width;
261 massT = mdatoms->massT;
263 ref = &(fr->adress_refs);
265 cgindex = cgs->index;
267 /* Weighting function is determined for each atom individually.
268 * This is an approximation
269 * as in the theory requires an interpolation based on the center of masses.
270 * Should be used with caution */
272 for (icg = cg0; (icg < cg1); icg++) {
274 k1 = cgindex[icg + 1];
277 for (k = (k0); (k < k1); k++) {
278 wf[k] = adress_weight(x[k], adresstype, adressr, adressw, ref, pbc, fr);
281 } else if (wf[k] == 1) {
292 update_adress_weights_cog(t_iparams ip[],
299 int i,j,k,nr,nra,inc;
300 int ftype,adresstype;
301 t_iatom avsite,ai,aj,ak,al;
303 real adressr,adressw;
306 int n_hyb, n_ex, n_cg;
308 adresstype = fr->adress_type;
309 adressr = fr->adress_ex_width;
310 adressw = fr->adress_hy_width;
312 ref = &(fr->adress_refs);
320 /* Since this is center of geometry AdResS, we know the vsite
321 * is in the same charge group node as the constructing atoms.
322 * Loop over vsite types, calculate the weight of the vsite,
323 * then assign that weight to the constructing atoms. */
325 for(ftype=0; (ftype<F_NRE); ftype++)
327 if (interaction_function[ftype].flags & IF_VSITE)
329 nra = interaction_function[ftype].nratoms;
330 nr = ilist[ftype].nr;
331 ia = ilist[ftype].iatoms;
335 /* The vsite and first constructing atom */
338 wf[avsite] = adress_weight(x[avsite],adresstype,adressr,adressw,ref,pbc,fr);
343 } else if (wf[ai] == 1) {
349 /* Assign the vsite wf to rest of constructing atoms depending on type */
397 inc = 3*ip[ia[0]].vsiten.n;
398 for(j=3; j<inc; j+=3)
405 gmx_fatal(FARGS,"No such vsite type %d in %s, line %d",
406 ftype,__FILE__,__LINE__);
409 /* Increment loop variables */
418 update_adress_weights_atom(int cg0,
429 real adressr,adressw;
434 adresstype = fr->adress_type;
435 adressr = fr->adress_ex_width;
436 adressw = fr->adress_hy_width;
437 massT = mdatoms->massT;
439 ref = &(fr->adress_refs);
440 cgindex = cgs->index;
442 /* Only use first atom in charge group.
443 * We still can't be sure that the vsite and constructing
444 * atoms are on the same processor, so we must calculate
445 * in the same way as com adress. */
447 for(icg=cg0; (icg<cg1); icg++)
451 wf[k0] = adress_weight(x[k0],adresstype,adressr,adressw,ref,pbc,fr);
453 /* Set wf of all atoms in charge group equal to wf of first atom in charge group*/
454 for(k=(k0+1); (k<k1); k++)
462 adress_thermo_force(int start,
471 int iatom,n0,nnn,nrcg, i;
473 real adressw, adressr;
475 unsigned short * ptype;
481 real w,wsq,wmin1,wmin1sq,wp,wt,rinv, sqr_dl, dl;
482 real eps,eps2,F,Geps,Heps2,Fp,dmu_dwp,dwp_dr,fscal;
484 adresstype = fr->adress_type;
485 adressw = fr->adress_hy_width;
486 adressr = fr->adress_ex_width;
487 cgindex = cgs->index;
488 ptype = mdatoms->ptype;
489 ref = &(fr->adress_refs);
492 for(iatom=start; (iatom<start+homenr); iatom++)
494 if (egp_coarsegrained(fr, mdatoms->cENER[iatom]))
496 if (ptype[iatom] == eptVSite)
499 /* is it hybrid or apply the thermodynamics force everywhere?*/
500 if ( mdatoms->tf_table_index[iatom] != NO_TF_TABLE)
502 if (fr->n_adress_tf_grps > 0 ){
503 /* multi component tf is on, select the right table */
504 ATFtab = fr->atf_tabs[mdatoms->tf_table_index[iatom]].data;
505 tabscale = fr->atf_tabs[mdatoms->tf_table_index[iatom]].scale;
508 /* just on component*/
509 ATFtab = fr->atf_tabs[DEFAULT_TF_TABLE].data;
510 tabscale = fr->atf_tabs[DEFAULT_TF_TABLE].scale;
516 pbc_dx(pbc,(*ref),x[iatom],dr);
520 rvec_sub((*ref),x[iatom],dr);
526 /* calculate distace to adress center again */
531 /* plane through center of ref, varies in x direction */
532 sqr_dl = dr[0]*dr[0];
533 rinv = gmx_invsqrt(dr[0]*dr[0]);
536 /* point at center of ref, assuming cubic geometry */
538 sqr_dl += dr[i]*dr[i];
540 rinv = gmx_invsqrt(sqr_dl);
543 /* This case should not happen */
548 /* table origin is adress center */
555 Geps = eps*ATFtab[nnn+2];
556 Heps2 = eps2*ATFtab[nnn+3];
558 F = (Fp+Geps+2.0*Heps2)*tabscale;
562 f[iatom][0] += fscal*dr[0];
563 if (adresstype != eAdressXSplit)
565 f[iatom][1] += fscal*dr[1];
566 f[iatom][2] += fscal*dr[2];
574 gmx_bool egp_explicit(t_forcerec * fr, int egp_nr)
576 return fr->adress_group_explicit[egp_nr];
579 gmx_bool egp_coarsegrained(t_forcerec * fr, int egp_nr)
581 return !fr->adress_group_explicit[egp_nr];