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-2004, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012, 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.
46 #include "types/commrec.h"
57 #include "gmx_random.h"
71 #include "gmx_wallcycle.h"
72 #include "gmx_omp_nthreads.h"
74 /*For debugging, start at v(-dt/2) for velolcity verlet -- uncomment next line */
75 /*#define STARTFROMDT2*/
95 /* The random state */
101 gmx_sd_sigma_t *sdsig;
104 /* andersen temperature control stuff */
105 gmx_bool *randomize_group;
109 typedef struct gmx_update
112 /* xprime for constraint algorithms */
116 /* variable size arrays for andersen */
119 gmx_bool randatom_list_init;
121 /* Variables for the deform algorithm */
122 gmx_large_int_t deformref_step;
123 matrix deformref_box;
127 static void do_update_md(int start,int nrend,double dt,
128 t_grp_tcstat *tcstat,
130 gmx_bool bNEMD,t_grp_acc *gstat,rvec accel[],
133 unsigned short ptype[],unsigned short cFREEZE[],
134 unsigned short cACC[],unsigned short cTC[],
135 rvec x[],rvec xprime[],rvec v[],
137 gmx_bool bNH,gmx_bool bPR)
142 real vn,vv,va,vb,vnrel;
148 /* Update with coupling to extended ensembles, used for
149 * Nose-Hoover and Parrinello-Rahman coupling
150 * Nose-Hoover uses the reversible leap-frog integrator from
151 * Holian et al. Phys Rev E 52(3) : 2338, 1995
153 for(n=start; n<nrend; n++)
168 lg = tcstat[gt].lambda;
172 rvec_sub(v[n],gstat[ga].u,vrel);
176 if((ptype[n] != eptVSite) && (ptype[n] != eptShell) && !nFreeze[gf][d])
178 vnrel = (lg*vrel[d] + dt*(imass*f[n][d] - 0.5*vxi*vrel[d]
179 - iprod(M[d],vrel)))/(1 + 0.5*vxi*dt);
180 /* do not scale the mean velocities u */
181 vn = gstat[ga].u[d] + accel[ga][d]*dt + vnrel;
183 xprime[n][d] = x[n][d]+vn*dt;
188 xprime[n][d] = x[n][d];
193 else if (cFREEZE != NULL ||
194 nFreeze[0][XX] || nFreeze[0][YY] || nFreeze[0][ZZ] ||
197 /* Update with Berendsen/v-rescale coupling and freeze or NEMD */
198 for(n=start; n<nrend; n++)
200 w_dt = invmass[n]*dt;
213 lg = tcstat[gt].lambda;
218 if((ptype[n] != eptVSite) && (ptype[n] != eptShell) && !nFreeze[gf][d])
220 vv = lg*vn + f[n][d]*w_dt;
222 /* do not scale the mean velocities u */
224 va = vv + accel[ga][d]*dt;
225 vb = va + (1.0-lg)*u;
227 xprime[n][d] = x[n][d]+vb*dt;
232 xprime[n][d] = x[n][d];
239 /* Plain update with Berendsen/v-rescale coupling */
240 for(n=start; n<nrend; n++)
242 if ((ptype[n] != eptVSite) && (ptype[n] != eptShell))
244 w_dt = invmass[n]*dt;
249 lg = tcstat[gt].lambda;
253 vn = lg*v[n][d] + f[n][d]*w_dt;
255 xprime[n][d] = x[n][d] + vn*dt;
263 xprime[n][d] = x[n][d];
270 static void do_update_vv_vel(int start,int nrend,double dt,
271 t_grp_tcstat *tcstat,t_grp_acc *gstat,
272 rvec accel[],ivec nFreeze[],real invmass[],
273 unsigned short ptype[],unsigned short cFREEZE[],
274 unsigned short cACC[],rvec v[],rvec f[],
275 gmx_bool bExtended, real veta, real alpha)
280 real u,vn,vv,va,vb,vnrel;
286 g = 0.25*dt*veta*alpha;
288 mv2 = series_sinhx(g);
295 for(n=start; n<nrend; n++)
297 w_dt = invmass[n]*dt;
309 if((ptype[n] != eptVSite) && (ptype[n] != eptShell) && !nFreeze[gf][d])
311 v[n][d] = mv1*(mv1*v[n][d] + 0.5*(w_dt*mv2*f[n][d]))+0.5*accel[ga][d]*dt;
319 } /* do_update_vv_vel */
321 static void do_update_vv_pos(int start,int nrend,double dt,
322 t_grp_tcstat *tcstat,t_grp_acc *gstat,
323 rvec accel[],ivec nFreeze[],real invmass[],
324 unsigned short ptype[],unsigned short cFREEZE[],
325 rvec x[],rvec xprime[],rvec v[],
326 rvec f[],gmx_bool bExtended, real veta, real alpha)
333 /* Would it make more sense if Parrinello-Rahman was put here? */
338 mr2 = series_sinhx(g);
344 for(n=start; n<nrend; n++) {
353 if ((ptype[n] != eptVSite) && (ptype[n] != eptShell) && !nFreeze[gf][d])
355 xprime[n][d] = mr1*(mr1*x[n][d]+mr2*dt*v[n][d]);
359 xprime[n][d] = x[n][d];
363 }/* do_update_vv_pos */
365 static void do_update_visc(int start,int nrend,double dt,
366 t_grp_tcstat *tcstat,
369 unsigned short ptype[],unsigned short cTC[],
370 rvec x[],rvec xprime[],rvec v[],
371 rvec f[],matrix M,matrix box,real
373 gmx_bool bNH,gmx_bool bPR)
383 fac = 2*M_PI/(box[ZZ][ZZ]);
386 /* Update with coupling to extended ensembles, used for
387 * Nose-Hoover and Parrinello-Rahman coupling
389 for(n=start; n<nrend; n++) {
395 lg = tcstat[gt].lambda;
396 cosz = cos(fac*x[n][ZZ]);
398 copy_rvec(v[n],vrel);
410 if((ptype[n] != eptVSite) && (ptype[n] != eptShell))
412 vn = (lg*vrel[d] + dt*(imass*f[n][d] - 0.5*vxi*vrel[d]
413 - iprod(M[d],vrel)))/(1 + 0.5*vxi*dt);
416 vn += vc + dt*cosz*cos_accel;
419 xprime[n][d] = x[n][d]+vn*dt;
423 xprime[n][d] = x[n][d];
430 /* Classic version of update, used with berendsen coupling */
431 for(n=start; n<nrend; n++)
433 w_dt = invmass[n]*dt;
438 lg = tcstat[gt].lambda;
439 cosz = cos(fac*x[n][ZZ]);
445 if((ptype[n] != eptVSite) && (ptype[n] != eptShell))
450 /* Do not scale the cosine velocity profile */
451 vv = vc + lg*(vn - vc + f[n][d]*w_dt);
452 /* Add the cosine accelaration profile */
453 vv += dt*cosz*cos_accel;
457 vv = lg*(vn + f[n][d]*w_dt);
460 xprime[n][d] = x[n][d]+vv*dt;
465 xprime[n][d] = x[n][d];
472 static gmx_stochd_t *init_stochd(FILE *fplog,t_inputrec *ir)
481 /* Initiate random number generator for langevin type dynamics,
482 * for BD, SD or velocity rescaling temperature coupling.
484 sd->gaussrand = gmx_rng_init(ir->ld_seed);
486 ngtc = ir->opts.ngtc;
490 snew(sd->bd_rf,ngtc);
492 else if (EI_SD(ir->eI))
495 snew(sd->sdsig,ngtc);
498 for(n=0; n<ngtc; n++)
500 if (ir->opts.tau_t[n] > 0)
502 sdc[n].gdt = ir->delta_t/ir->opts.tau_t[n];
503 sdc[n].eph = exp(sdc[n].gdt/2);
504 sdc[n].emh = exp(-sdc[n].gdt/2);
505 sdc[n].em = exp(-sdc[n].gdt);
509 /* No friction and noise on this group */
515 if (sdc[n].gdt >= 0.05)
517 sdc[n].b = sdc[n].gdt*(sdc[n].eph*sdc[n].eph - 1)
518 - 4*(sdc[n].eph - 1)*(sdc[n].eph - 1);
519 sdc[n].c = sdc[n].gdt - 3 + 4*sdc[n].emh - sdc[n].em;
520 sdc[n].d = 2 - sdc[n].eph - sdc[n].emh;
525 /* Seventh order expansions for small y */
526 sdc[n].b = y*y*y*y*(1/3.0+y*(1/3.0+y*(17/90.0+y*7/9.0)));
527 sdc[n].c = y*y*y*(2/3.0+y*(-1/2.0+y*(7/30.0+y*(-1/12.0+y*31/1260.0))));
528 sdc[n].d = y*y*(-1+y*y*(-1/12.0-y*y/360.0));
531 fprintf(debug,"SD const tc-grp %d: b %g c %g d %g\n",
532 n,sdc[n].b,sdc[n].c,sdc[n].d);
535 else if (ETC_ANDERSEN(ir->etc))
544 snew(sd->randomize_group,ngtc);
545 snew(sd->boltzfac,ngtc);
547 /* for now, assume that all groups, if randomized, are randomized at the same rate, i.e. tau_t is the same. */
548 /* since constraint groups don't necessarily match up with temperature groups! This is checked in readir.c */
550 for (n=0;n<ngtc;n++) {
551 reft = max(0.0,opts->ref_t[n]);
552 if ((opts->tau_t[n] > 0) && (reft > 0)) /* tau_t or ref_t = 0 means that no randomization is done */
554 sd->randomize_group[n] = TRUE;
555 sd->boltzfac[n] = BOLTZ*opts->ref_t[n];
557 sd->randomize_group[n] = FALSE;
564 void get_stochd_state(gmx_update_t upd,t_state *state)
566 gmx_rng_get_state(upd->sd->gaussrand,state->ld_rng,state->ld_rngi);
569 void set_stochd_state(gmx_update_t upd,t_state *state)
571 gmx_rng_set_state(upd->sd->gaussrand,state->ld_rng,state->ld_rngi[0]);
574 gmx_update_t init_update(FILE *fplog,t_inputrec *ir)
580 if (ir->eI == eiBD || EI_SD(ir->eI) || ir->etc == etcVRESCALE || ETC_ANDERSEN(ir->etc))
582 upd->sd = init_stochd(fplog,ir);
587 upd->randatom = NULL;
588 upd->randatom_list = NULL;
589 upd->randatom_list_init = FALSE; /* we have not yet cleared the data structure at this point */
594 static void do_update_sd1(gmx_stochd_t *sd,
595 int start,int homenr,double dt,
596 rvec accel[],ivec nFreeze[],
597 real invmass[],unsigned short ptype[],
598 unsigned short cFREEZE[],unsigned short cACC[],
599 unsigned short cTC[],
600 rvec x[],rvec xprime[],rvec v[],rvec f[],
602 int ngtc,real tau_t[],real ref_t[])
614 if (homenr > sd->sd_V_nalloc)
616 sd->sd_V_nalloc = over_alloc_dd(homenr);
617 srenew(sd->sd_V,sd->sd_V_nalloc);
619 gaussrand = sd->gaussrand;
621 for(n=0; n<ngtc; n++)
624 /* The mass is encounted for later, since this differs per atom */
625 sig[n].V = sqrt(kT*(1 - sdc[n].em*sdc[n].em));
628 for(n=start; n<start+homenr; n++)
630 ism = sqrt(invmass[n]);
646 if((ptype[n] != eptVSite) && (ptype[n] != eptShell) && !nFreeze[gf][d])
648 sd_V = ism*sig[gt].V*gmx_rng_gaussian_table(gaussrand);
650 v[n][d] = v[n][d]*sdc[gt].em
651 + (invmass[n]*f[n][d] + accel[ga][d])*tau_t[gt]*(1 - sdc[gt].em)
654 xprime[n][d] = x[n][d] + v[n][d]*dt;
659 xprime[n][d] = x[n][d];
665 static void do_update_sd2(gmx_stochd_t *sd,gmx_bool bInitStep,
666 int start,int homenr,
667 rvec accel[],ivec nFreeze[],
668 real invmass[],unsigned short ptype[],
669 unsigned short cFREEZE[],unsigned short cACC[],
670 unsigned short cTC[],
671 rvec x[],rvec xprime[],rvec v[],rvec f[],
673 int ngtc,real tau_t[],real ref_t[],
678 /* The random part of the velocity update, generated in the first
679 * half of the update, needs to be remembered for the second half.
691 if (homenr > sd->sd_V_nalloc)
693 sd->sd_V_nalloc = over_alloc_dd(homenr);
694 srenew(sd->sd_V,sd->sd_V_nalloc);
697 gaussrand = sd->gaussrand;
701 for (n=0; n<ngtc; n++)
704 /* The mass is encounted for later, since this differs per atom */
705 sig[n].V = sqrt(kT*(1-sdc[n].em));
706 sig[n].X = sqrt(kT*sqr(tau_t[n])*sdc[n].c);
707 sig[n].Yv = sqrt(kT*sdc[n].b/sdc[n].c);
708 sig[n].Yx = sqrt(kT*sqr(tau_t[n])*sdc[n].b/(1-sdc[n].em));
712 for (n=start; n<start+homenr; n++)
714 ism = sqrt(invmass[n]);
734 if((ptype[n] != eptVSite) && (ptype[n] != eptShell) && !nFreeze[gf][d])
740 sd_X[n][d] = ism*sig[gt].X*gmx_rng_gaussian_table(gaussrand);
742 Vmh = sd_X[n][d]*sdc[gt].d/(tau_t[gt]*sdc[gt].c)
743 + ism*sig[gt].Yv*gmx_rng_gaussian_table(gaussrand);
744 sd_V[n-start][d] = ism*sig[gt].V*gmx_rng_gaussian_table(gaussrand);
746 v[n][d] = vn*sdc[gt].em
747 + (invmass[n]*f[n][d] + accel[ga][d])*tau_t[gt]*(1 - sdc[gt].em)
748 + sd_V[n-start][d] - sdc[gt].em*Vmh;
750 xprime[n][d] = x[n][d] + v[n][d]*tau_t[gt]*(sdc[gt].eph - sdc[gt].emh);
755 /* Correct the velocities for the constraints.
756 * This operation introduces some inaccuracy,
757 * since the velocity is determined from differences in coordinates.
760 (xprime[n][d] - x[n][d])/(tau_t[gt]*(sdc[gt].eph - sdc[gt].emh));
762 Xmh = sd_V[n-start][d]*tau_t[gt]*sdc[gt].d/(sdc[gt].em-1)
763 + ism*sig[gt].Yx*gmx_rng_gaussian_table(gaussrand);
764 sd_X[n][d] = ism*sig[gt].X*gmx_rng_gaussian_table(gaussrand);
766 xprime[n][d] += sd_X[n][d] - Xmh;
775 xprime[n][d] = x[n][d];
782 static void do_update_bd(int start,int nrend,double dt,
784 real invmass[],unsigned short ptype[],
785 unsigned short cFREEZE[],unsigned short cTC[],
786 rvec x[],rvec xprime[],rvec v[],
787 rvec f[],real friction_coefficient,
788 int ngtc,real tau_t[],real ref_t[],
789 real *rf,gmx_rng_t gaussrand)
791 /* note -- these appear to be full step velocities . . . */
797 if (friction_coefficient != 0)
799 invfr = 1.0/friction_coefficient;
800 for(n=0; n<ngtc; n++)
802 rf[n] = sqrt(2.0*BOLTZ*ref_t[n]/(friction_coefficient*dt));
807 for(n=0; n<ngtc; n++)
809 rf[n] = sqrt(2.0*BOLTZ*ref_t[n]);
812 for(n=start; (n<nrend); n++)
822 for(d=0; (d<DIM); d++)
824 if((ptype[n]!=eptVSite) && (ptype[n]!=eptShell) && !nFreeze[gf][d])
826 if (friction_coefficient != 0) {
827 vn = invfr*f[n][d] + rf[gt]*gmx_rng_gaussian_table(gaussrand);
831 /* NOTE: invmass = 2/(mass*friction_constant*dt) */
832 vn = 0.5*invmass[n]*f[n][d]*dt
833 + sqrt(0.5*invmass[n])*rf[gt]*gmx_rng_gaussian_table(gaussrand);
837 xprime[n][d] = x[n][d]+vn*dt;
842 xprime[n][d] = x[n][d];
848 static void dump_it_all(FILE *fp,const char *title,
849 int natoms,rvec x[],rvec xp[],rvec v[],rvec f[])
854 fprintf(fp,"%s\n",title);
855 pr_rvecs(fp,0,"x",x,natoms);
856 pr_rvecs(fp,0,"xp",xp,natoms);
857 pr_rvecs(fp,0,"v",v,natoms);
858 pr_rvecs(fp,0,"f",f,natoms);
863 static void calc_ke_part_normal(rvec v[], t_grpopts *opts,t_mdatoms *md,
864 gmx_ekindata_t *ekind,t_nrnb *nrnb,gmx_bool bEkinAveVel,
865 gmx_bool bSaveEkinOld)
868 t_grp_tcstat *tcstat=ekind->tcstat;
869 t_grp_acc *grpstat=ekind->grpstat;
872 /* three main: VV with AveVel, vv with AveEkin, leap with AveEkin. Leap with AveVel is also
873 an option, but not supported now. Additionally, if we are doing iterations.
874 bEkinAveVel: If TRUE, we sum into ekin, if FALSE, into ekinh.
875 bSavEkinOld: If TRUE (in the case of iteration = bIterate is TRUE), we don't copy over the ekinh_old.
876 If FALSE, we overrwrite it.
879 /* group velocities are calculated in update_ekindata and
880 * accumulated in acumulate_groups.
881 * Now the partial global and groups ekin.
883 for(g=0; (g<opts->ngtc); g++)
887 copy_mat(tcstat[g].ekinh,tcstat[g].ekinh_old);
890 clear_mat(tcstat[g].ekinf);
892 clear_mat(tcstat[g].ekinh);
895 tcstat[g].ekinscalef_nhc = 1.0; /* need to clear this -- logic is complicated! */
898 ekind->dekindl_old = ekind->dekindl;
900 nthread = gmx_omp_nthreads_get(emntUpdate);
902 #pragma omp parallel for num_threads(nthread) schedule(static)
903 for(thread=0; thread<nthread; thread++)
913 start_t = md->start + ((thread+0)*md->homenr)/nthread;
914 end_t = md->start + ((thread+1)*md->homenr)/nthread;
916 ekin_sum = ekind->ekin_work[thread];
917 dekindl_sum = &ekind->ekin_work[thread][opts->ngtc][0][0];
919 for(gt=0; gt<opts->ngtc; gt++)
921 clear_mat(ekin_sum[gt]);
926 for(n=start_t; n<end_t; n++)
936 hm = 0.5*md->massT[n];
938 for(d=0; (d<DIM); d++)
940 v_corrt[d] = v[n][d] - grpstat[ga].u[d];
942 for(d=0; (d<DIM); d++)
944 for (m=0;(m<DIM); m++)
946 /* if we're computing a full step velocity, v_corrt[d] has v(t). Otherwise, v(t+dt/2) */
947 ekin_sum[gt][m][d] += hm*v_corrt[m]*v_corrt[d];
950 if (md->nMassPerturbed && md->bPerturbed[n])
953 0.5*(md->massB[n] - md->massA[n])*iprod(v_corrt,v_corrt);
959 for(thread=0; thread<nthread; thread++)
961 for(g=0; g<opts->ngtc; g++)
965 m_add(tcstat[g].ekinf,ekind->ekin_work[thread][g],
970 m_add(tcstat[g].ekinh,ekind->ekin_work[thread][g],
975 ekind->dekindl += ekind->ekin_work[thread][opts->ngtc][0][0];
978 inc_nrnb(nrnb,eNR_EKIN,md->homenr);
981 static void calc_ke_part_visc(matrix box,rvec x[],rvec v[],
982 t_grpopts *opts,t_mdatoms *md,
983 gmx_ekindata_t *ekind,
984 t_nrnb *nrnb, gmx_bool bEkinAveVel, gmx_bool bSaveEkinOld)
986 int start=md->start,homenr=md->homenr;
990 t_grp_tcstat *tcstat=ekind->tcstat;
991 t_cos_acc *cosacc=&(ekind->cosacc);
996 for(g=0; g<opts->ngtc; g++)
998 copy_mat(ekind->tcstat[g].ekinh,ekind->tcstat[g].ekinh_old);
999 clear_mat(ekind->tcstat[g].ekinh);
1001 ekind->dekindl_old = ekind->dekindl;
1003 fac = 2*M_PI/box[ZZ][ZZ];
1006 for(n=start; n<start+homenr; n++)
1012 hm = 0.5*md->massT[n];
1014 /* Note that the times of x and v differ by half a step */
1015 /* MRS -- would have to be changed for VV */
1016 cosz = cos(fac*x[n][ZZ]);
1017 /* Calculate the amplitude of the new velocity profile */
1018 mvcos += 2*cosz*md->massT[n]*v[n][XX];
1020 copy_rvec(v[n],v_corrt);
1021 /* Subtract the profile for the kinetic energy */
1022 v_corrt[XX] -= cosz*cosacc->vcos;
1023 for (d=0; (d<DIM); d++)
1025 for (m=0; (m<DIM); m++)
1027 /* if we're computing a full step velocity, v_corrt[d] has v(t). Otherwise, v(t+dt/2) */
1030 tcstat[gt].ekinf[m][d]+=hm*v_corrt[m]*v_corrt[d];
1034 tcstat[gt].ekinh[m][d]+=hm*v_corrt[m]*v_corrt[d];
1038 if(md->nPerturbed && md->bPerturbed[n])
1040 dekindl -= 0.5*(md->massB[n] - md->massA[n])*iprod(v_corrt,v_corrt);
1043 ekind->dekindl = dekindl;
1044 cosacc->mvcos = mvcos;
1046 inc_nrnb(nrnb,eNR_EKIN,homenr);
1049 void calc_ke_part(t_state *state,t_grpopts *opts,t_mdatoms *md,
1050 gmx_ekindata_t *ekind,t_nrnb *nrnb, gmx_bool bEkinAveVel, gmx_bool bSaveEkinOld)
1052 if (ekind->cosacc.cos_accel == 0)
1054 calc_ke_part_normal(state->v,opts,md,ekind,nrnb,bEkinAveVel,bSaveEkinOld);
1058 calc_ke_part_visc(state->box,state->x,state->v,opts,md,ekind,nrnb,bEkinAveVel,bSaveEkinOld);
1062 extern void init_ekinstate(ekinstate_t *ekinstate,const t_inputrec *ir)
1064 ekinstate->ekin_n = ir->opts.ngtc;
1065 snew(ekinstate->ekinh,ekinstate->ekin_n);
1066 snew(ekinstate->ekinf,ekinstate->ekin_n);
1067 snew(ekinstate->ekinh_old,ekinstate->ekin_n);
1068 snew(ekinstate->ekinscalef_nhc,ekinstate->ekin_n);
1069 snew(ekinstate->ekinscaleh_nhc,ekinstate->ekin_n);
1070 snew(ekinstate->vscale_nhc,ekinstate->ekin_n);
1071 ekinstate->dekindl = 0;
1072 ekinstate->mvcos = 0;
1075 void update_ekinstate(ekinstate_t *ekinstate,gmx_ekindata_t *ekind)
1079 for(i=0;i<ekinstate->ekin_n;i++)
1081 copy_mat(ekind->tcstat[i].ekinh,ekinstate->ekinh[i]);
1082 copy_mat(ekind->tcstat[i].ekinf,ekinstate->ekinf[i]);
1083 copy_mat(ekind->tcstat[i].ekinh_old,ekinstate->ekinh_old[i]);
1084 ekinstate->ekinscalef_nhc[i] = ekind->tcstat[i].ekinscalef_nhc;
1085 ekinstate->ekinscaleh_nhc[i] = ekind->tcstat[i].ekinscaleh_nhc;
1086 ekinstate->vscale_nhc[i] = ekind->tcstat[i].vscale_nhc;
1089 copy_mat(ekind->ekin,ekinstate->ekin_total);
1090 ekinstate->dekindl = ekind->dekindl;
1091 ekinstate->mvcos = ekind->cosacc.mvcos;
1095 void restore_ekinstate_from_state(t_commrec *cr,
1096 gmx_ekindata_t *ekind,ekinstate_t *ekinstate)
1102 for(i=0;i<ekinstate->ekin_n;i++)
1104 copy_mat(ekinstate->ekinh[i],ekind->tcstat[i].ekinh);
1105 copy_mat(ekinstate->ekinf[i],ekind->tcstat[i].ekinf);
1106 copy_mat(ekinstate->ekinh_old[i],ekind->tcstat[i].ekinh_old);
1107 ekind->tcstat[i].ekinscalef_nhc = ekinstate->ekinscalef_nhc[i];
1108 ekind->tcstat[i].ekinscaleh_nhc = ekinstate->ekinscaleh_nhc[i];
1109 ekind->tcstat[i].vscale_nhc = ekinstate->vscale_nhc[i];
1112 copy_mat(ekinstate->ekin_total,ekind->ekin);
1114 ekind->dekindl = ekinstate->dekindl;
1115 ekind->cosacc.mvcos = ekinstate->mvcos;
1116 n = ekinstate->ekin_n;
1121 gmx_bcast(sizeof(n),&n,cr);
1124 gmx_bcast(DIM*DIM*sizeof(ekind->tcstat[i].ekinh[0][0]),
1125 ekind->tcstat[i].ekinh[0],cr);
1126 gmx_bcast(DIM*DIM*sizeof(ekind->tcstat[i].ekinf[0][0]),
1127 ekind->tcstat[i].ekinf[0],cr);
1128 gmx_bcast(DIM*DIM*sizeof(ekind->tcstat[i].ekinh_old[0][0]),
1129 ekind->tcstat[i].ekinh_old[0],cr);
1131 gmx_bcast(sizeof(ekind->tcstat[i].ekinscalef_nhc),
1132 &(ekind->tcstat[i].ekinscalef_nhc),cr);
1133 gmx_bcast(sizeof(ekind->tcstat[i].ekinscaleh_nhc),
1134 &(ekind->tcstat[i].ekinscaleh_nhc),cr);
1135 gmx_bcast(sizeof(ekind->tcstat[i].vscale_nhc),
1136 &(ekind->tcstat[i].vscale_nhc),cr);
1138 gmx_bcast(DIM*DIM*sizeof(ekind->ekin[0][0]),
1141 gmx_bcast(sizeof(ekind->dekindl),&ekind->dekindl,cr);
1142 gmx_bcast(sizeof(ekind->cosacc.mvcos),&ekind->cosacc.mvcos,cr);
1146 void set_deform_reference_box(gmx_update_t upd,gmx_large_int_t step,matrix box)
1148 upd->deformref_step = step;
1149 copy_mat(box,upd->deformref_box);
1152 static void deform(gmx_update_t upd,
1153 int start,int homenr,rvec x[],matrix box,matrix *scale_tot,
1154 const t_inputrec *ir,gmx_large_int_t step)
1156 matrix bnew,invbox,mu;
1160 elapsed_time = (step + 1 - upd->deformref_step)*ir->delta_t;
1162 for(i=0; i<DIM; i++)
1164 for(j=0; j<DIM; j++)
1166 if (ir->deform[i][j] != 0)
1169 upd->deformref_box[i][j] + elapsed_time*ir->deform[i][j];
1173 /* We correct the off-diagonal elements,
1174 * which can grow indefinitely during shearing,
1175 * so the shifts do not get messed up.
1177 for(i=1; i<DIM; i++)
1179 for(j=i-1; j>=0; j--)
1181 while (bnew[i][j] - box[i][j] > 0.5*bnew[j][j])
1183 rvec_dec(bnew[i],bnew[j]);
1185 while (bnew[i][j] - box[i][j] < -0.5*bnew[j][j])
1187 rvec_inc(bnew[i],bnew[j]);
1191 m_inv_ur0(box,invbox);
1193 mmul_ur0(box,invbox,mu);
1195 for(i=start; i<start+homenr; i++)
1197 x[i][XX] = mu[XX][XX]*x[i][XX]+mu[YY][XX]*x[i][YY]+mu[ZZ][XX]*x[i][ZZ];
1198 x[i][YY] = mu[YY][YY]*x[i][YY]+mu[ZZ][YY]*x[i][ZZ];
1199 x[i][ZZ] = mu[ZZ][ZZ]*x[i][ZZ];
1203 /* The transposes of the scaling matrices are stored,
1204 * so we need to do matrix multiplication in the inverse order.
1206 mmul_ur0(*scale_tot,mu,*scale_tot);
1210 static void combine_forces(int nstcalclr,
1211 gmx_constr_t constr,
1212 t_inputrec *ir,t_mdatoms *md,t_idef *idef,
1214 gmx_large_int_t step,
1215 t_state *state,gmx_bool bMolPBC,
1216 int start,int nrend,
1217 rvec f[],rvec f_lr[],
1222 /* f contains the short-range forces + the long range forces
1223 * which are stored separately in f_lr.
1226 if (constr != NULL && !(ir->eConstrAlg == econtSHAKE && ir->epc == epcNO))
1228 /* We need to constrain the LR forces separately,
1229 * because due to the different pre-factor for the SR and LR
1230 * forces in the update algorithm, we can not determine
1231 * the constraint force for the coordinate constraining.
1232 * Constrain only the additional LR part of the force.
1234 /* MRS -- need to make sure this works with trotter integration -- the constraint calls may not be right.*/
1235 constrain(NULL,FALSE,FALSE,constr,idef,ir,NULL,cr,step,0,md,
1236 state->x,f_lr,f_lr,bMolPBC,state->box,state->lambda[efptBONDED],NULL,
1237 NULL,NULL,nrnb,econqForce,ir->epc==epcMTTK,state->veta,state->veta);
1240 /* Add nstcalclr-1 times the LR force to the sum of both forces
1241 * and store the result in forces_lr.
1243 nm1 = nstcalclr - 1;
1244 for(i=start; i<nrend; i++)
1246 for(d=0; d<DIM; d++)
1248 f_lr[i][d] = f[i][d] + nm1*f_lr[i][d];
1253 void update_tcouple(FILE *fplog,
1254 gmx_large_int_t step,
1255 t_inputrec *inputrec,
1257 gmx_ekindata_t *ekind,
1258 gmx_wallcycle_t wcycle,
1264 gmx_bool bTCouple=FALSE;
1266 int i,start,end,homenr,offset;
1268 /* if using vv with trotter decomposition methods, we do this elsewhere in the code */
1269 if (inputrec->etc != etcNO &&
1270 !(IR_NVT_TROTTER(inputrec) || IR_NPT_TROTTER(inputrec) || IR_NPH_TROTTER(inputrec)))
1272 /* We should only couple after a step where energies were determined (for leapfrog versions)
1273 or the step energies are determined, for velocity verlet versions */
1275 if (EI_VV(inputrec->eI)) {
1280 bTCouple = (inputrec->nsttcouple == 1 ||
1281 do_per_step(step+inputrec->nsttcouple-offset,
1282 inputrec->nsttcouple));
1287 dttc = inputrec->nsttcouple*inputrec->delta_t;
1289 switch (inputrec->etc)
1294 berendsen_tcoupl(inputrec,ekind,dttc);
1297 nosehoover_tcoupl(&(inputrec->opts),ekind,dttc,
1298 state->nosehoover_xi,state->nosehoover_vxi,MassQ);
1301 vrescale_tcoupl(inputrec,ekind,dttc,
1302 state->therm_integral,upd->sd->gaussrand);
1305 /* rescale in place here */
1306 if (EI_VV(inputrec->eI))
1308 rescale_velocities(ekind,md,md->start,md->start+md->homenr,state->v);
1313 /* Set the T scaling lambda to 1 to have no scaling */
1314 for(i=0; (i<inputrec->opts.ngtc); i++)
1316 ekind->tcstat[i].lambda = 1.0;
1321 void update_pcouple(FILE *fplog,
1322 gmx_large_int_t step,
1323 t_inputrec *inputrec,
1327 gmx_wallcycle_t wcycle,
1331 gmx_bool bPCouple=FALSE;
1335 /* if using Trotter pressure, we do this in coupling.c, so we leave it false. */
1336 if (inputrec->epc != epcNO && (!(IR_NPT_TROTTER(inputrec) || IR_NPH_TROTTER(inputrec))))
1338 /* We should only couple after a step where energies were determined */
1339 bPCouple = (inputrec->nstpcouple == 1 ||
1340 do_per_step(step+inputrec->nstpcouple-1,
1341 inputrec->nstpcouple));
1344 clear_mat(pcoupl_mu);
1345 for(i=0; i<DIM; i++)
1347 pcoupl_mu[i][i] = 1.0;
1354 dtpc = inputrec->nstpcouple*inputrec->delta_t;
1356 switch (inputrec->epc)
1358 /* We can always pcoupl, even if we did not sum the energies
1359 * the previous step, since state->pres_prev is only updated
1360 * when the energies have been summed.
1364 case (epcBERENDSEN):
1367 berendsen_pcoupl(fplog,step,inputrec,dtpc,state->pres_prev,state->box,
1371 case (epcPARRINELLORAHMAN):
1372 parrinellorahman_pcoupl(fplog,step,inputrec,dtpc,state->pres_prev,
1373 state->box,state->box_rel,state->boxv,
1374 M,pcoupl_mu,bInitStep);
1382 static rvec *get_xprime(const t_state *state,gmx_update_t upd)
1384 if (state->nalloc > upd->xp_nalloc)
1386 upd->xp_nalloc = state->nalloc;
1387 srenew(upd->xp,upd->xp_nalloc);
1393 void update_constraints(FILE *fplog,
1394 gmx_large_int_t step,
1395 real *dvdlambda, /* the contribution to be added to the bonded interactions */
1396 t_inputrec *inputrec, /* input record and box stuff */
1397 gmx_ekindata_t *ekind,
1402 rvec force[], /* forces on home particles */
1405 tensor vir, /* tensors for virial and ekin, needed for computing */
1408 gmx_wallcycle_t wcycle,
1410 gmx_constr_t constr,
1412 gmx_bool bFirstHalf,
1416 gmx_bool bExtended,bLastStep,bLog=FALSE,bEner=FALSE,bDoConstr=FALSE;
1419 int start,homenr,nrend,i,n,m,g,d;
1421 rvec *vbuf,*xprime=NULL;
1423 if (constr) {bDoConstr=TRUE;}
1424 if (bFirstHalf && !EI_VV(inputrec->eI)) {bDoConstr=FALSE;}
1426 /* for now, SD update is here -- though it really seems like it
1427 should be reformulated as a velocity verlet method, since it has two parts */
1430 homenr = md->homenr;
1431 nrend = start+homenr;
1433 dt = inputrec->delta_t;
1438 * APPLY CONSTRAINTS:
1441 * When doing PR pressure coupling we have to constrain the
1442 * bonds in each iteration. If we are only using Nose-Hoover tcoupling
1443 * it is enough to do this once though, since the relative velocities
1444 * after this will be normal to the bond vector
1449 /* clear out constraints before applying */
1450 clear_mat(vir_part);
1452 xprime = get_xprime(state,upd);
1454 bLastStep = (step == inputrec->init_step+inputrec->nsteps);
1455 bLog = (do_per_step(step,inputrec->nstlog) || bLastStep || (step < 0));
1456 bEner = (do_per_step(step,inputrec->nstenergy) || bLastStep);
1457 /* Constrain the coordinates xprime */
1458 wallcycle_start(wcycle,ewcCONSTR);
1459 if (EI_VV(inputrec->eI) && bFirstHalf)
1461 constrain(NULL,bLog,bEner,constr,idef,
1462 inputrec,ekind,cr,step,1,md,
1463 state->x,state->v,state->v,
1465 state->lambda[efptBONDED],dvdlambda,
1466 NULL,bCalcVir ? &vir_con : NULL,nrnb,econqVeloc,
1467 inputrec->epc==epcMTTK,state->veta,vetanew);
1471 constrain(NULL,bLog,bEner,constr,idef,
1472 inputrec,ekind,cr,step,1,md,
1473 state->x,xprime,NULL,
1475 state->lambda[efptBONDED],dvdlambda,
1476 state->v,bCalcVir ? &vir_con : NULL ,nrnb,econqCoord,
1477 inputrec->epc==epcMTTK,state->veta,state->veta);
1479 wallcycle_stop(wcycle,ewcCONSTR);
1483 dump_it_all(fplog,"After Shake",
1484 state->natoms,state->x,xprime,state->v,force);
1488 if (inputrec->eI == eiSD2)
1490 /* A correction factor eph is needed for the SD constraint force */
1491 /* Here we can, unfortunately, not have proper corrections
1492 * for different friction constants, so we use the first one.
1494 for(i=0; i<DIM; i++)
1496 for(m=0; m<DIM; m++)
1498 vir_part[i][m] += upd->sd->sdc[0].eph*vir_con[i][m];
1504 m_add(vir_part,vir_con,vir_part);
1508 pr_rvecs(debug,0,"constraint virial",vir_part,DIM);
1514 if ((inputrec->eI == eiSD2) && !(bFirstHalf))
1516 xprime = get_xprime(state,upd);
1518 /* The second part of the SD integration */
1519 do_update_sd2(upd->sd,FALSE,start,homenr,
1520 inputrec->opts.acc,inputrec->opts.nFreeze,
1521 md->invmass,md->ptype,
1522 md->cFREEZE,md->cACC,md->cTC,
1523 state->x,xprime,state->v,force,state->sd_X,
1524 inputrec->opts.ngtc,inputrec->opts.tau_t,
1525 inputrec->opts.ref_t,FALSE);
1526 inc_nrnb(nrnb, eNR_UPDATE, homenr);
1530 /* Constrain the coordinates xprime */
1531 wallcycle_start(wcycle,ewcCONSTR);
1532 constrain(NULL,bLog,bEner,constr,idef,
1533 inputrec,NULL,cr,step,1,md,
1534 state->x,xprime,NULL,
1536 state->lambda[efptBONDED],dvdlambda,
1537 NULL,NULL,nrnb,econqCoord,FALSE,0,0);
1538 wallcycle_stop(wcycle,ewcCONSTR);
1542 /* We must always unshift after updating coordinates; if we did not shake
1543 x was shifted in do_force */
1545 if (!(bFirstHalf)) /* in the first half of vv, no shift. */
1547 if (graph && (graph->nnodes > 0))
1549 unshift_x(graph,state->box,state->x,upd->xp);
1550 if (TRICLINIC(state->box))
1552 inc_nrnb(nrnb,eNR_SHIFTX,2*graph->nnodes);
1556 inc_nrnb(nrnb,eNR_SHIFTX,graph->nnodes);
1561 #pragma omp parallel for num_threads(gmx_omp_nthreads_get(emntUpdate)) schedule(static)
1562 for(i=start; i<nrend; i++)
1564 copy_rvec(upd->xp[i],state->x[i]);
1568 dump_it_all(fplog,"After unshift",
1569 state->natoms,state->x,upd->xp,state->v,force);
1571 /* ############# END the update of velocities and positions ######### */
1574 void update_box(FILE *fplog,
1575 gmx_large_int_t step,
1576 t_inputrec *inputrec, /* input record and box stuff */
1580 rvec force[], /* forces on home particles */
1584 gmx_wallcycle_t wcycle,
1587 gmx_bool bFirstHalf)
1589 gmx_bool bExtended,bLastStep,bLog=FALSE,bEner=FALSE;
1592 int start,homenr,nrend,i,n,m,g;
1596 homenr = md->homenr;
1597 nrend = start+homenr;
1600 (inputrec->etc == etcNOSEHOOVER) ||
1601 (inputrec->epc == epcPARRINELLORAHMAN) ||
1602 (inputrec->epc == epcMTTK);
1604 dt = inputrec->delta_t;
1608 /* now update boxes */
1609 switch (inputrec->epc) {
1612 case (epcBERENDSEN):
1613 berendsen_pscale(inputrec,pcoupl_mu,state->box,state->box_rel,
1614 start,homenr,state->x,md->cFREEZE,nrnb);
1616 case (epcPARRINELLORAHMAN):
1617 /* The box velocities were updated in do_pr_pcoupl in the update
1618 * iteration, but we dont change the box vectors until we get here
1619 * since we need to be able to shift/unshift above.
1625 state->box[i][m] += dt*state->boxv[i][m];
1628 preserve_box_shape(inputrec,state->box_rel,state->box);
1630 /* Scale the coordinates */
1631 for(n=start; (n<start+homenr); n++)
1633 tmvmul_ur0(pcoupl_mu,state->x[n],state->x[n]);
1637 switch (inputrec->epct)
1639 case (epctISOTROPIC):
1640 /* DIM * eta = ln V. so DIM*eta_new = DIM*eta_old + DIM*dt*veta =>
1641 ln V_new = ln V_old + 3*dt*veta => V_new = V_old*exp(3*dt*veta) =>
1642 Side length scales as exp(veta*dt) */
1644 msmul(state->box,exp(state->veta*dt),state->box);
1646 /* Relate veta to boxv. veta = d(eta)/dT = (1/DIM)*1/V dV/dT.
1647 o If we assume isotropic scaling, and box length scaling
1648 factor L, then V = L^DIM (det(M)). So dV/dt = DIM
1649 L^(DIM-1) dL/dt det(M), and veta = (1/L) dL/dt. The
1650 determinant of B is L^DIM det(M), and the determinant
1651 of dB/dt is (dL/dT)^DIM det (M). veta will be
1652 (det(dB/dT)/det(B))^(1/3). Then since M =
1653 B_new*(vol_new)^(1/3), dB/dT_new = (veta_new)*B(new). */
1655 msmul(state->box,state->veta,state->boxv);
1665 if ((!(IR_NPT_TROTTER(inputrec) || IR_NPH_TROTTER(inputrec))) && scale_tot)
1667 /* The transposes of the scaling matrices are stored,
1668 * therefore we need to reverse the order in the multiplication.
1670 mmul_ur0(*scale_tot,pcoupl_mu,*scale_tot);
1673 if (DEFORM(*inputrec))
1675 deform(upd,start,homenr,state->x,state->box,scale_tot,inputrec,step);
1678 dump_it_all(fplog,"After update",
1679 state->natoms,state->x,upd->xp,state->v,force);
1682 void update_coords(FILE *fplog,
1683 gmx_large_int_t step,
1684 t_inputrec *inputrec, /* input record and box stuff */
1688 rvec *f, /* forces on home particles */
1692 gmx_ekindata_t *ekind,
1694 gmx_wallcycle_t wcycle,
1698 t_commrec *cr, /* these shouldn't be here -- need to think about it */
1700 gmx_constr_t constr,
1703 gmx_bool bNH,bPR,bLastStep,bLog=FALSE,bEner=FALSE;
1705 real *imass,*imassin;
1708 int start,homenr,nrend,i,j,d,n,m,g;
1709 int blen0,blen1,iatom,jatom,nshake,nsettle,nconstr,nexpand;
1712 rvec *vcom,*xcom,*vall,*xall,*xin,*vin,*forcein,*fall,*xpall,*xprimein,*xprime;
1715 /* Running the velocity half does nothing except for velocity verlet */
1716 if ((UpdatePart == etrtVELOCITY1 || UpdatePart == etrtVELOCITY2) &&
1717 !EI_VV(inputrec->eI))
1719 gmx_incons("update_coords called for velocity without VV integrator");
1723 homenr = md->homenr;
1724 nrend = start+homenr;
1726 xprime = get_xprime(state,upd);
1728 dt = inputrec->delta_t;
1731 /* We need to update the NMR restraint history when time averaging is used */
1732 if (state->flags & (1<<estDISRE_RM3TAV))
1734 update_disres_history(fcd,&state->hist);
1736 if (state->flags & (1<<estORIRE_DTAV))
1738 update_orires_history(fcd,&state->hist);
1742 bNH = inputrec->etc == etcNOSEHOOVER;
1743 bPR = ((inputrec->epc == epcPARRINELLORAHMAN) || (inputrec->epc == epcMTTK));
1745 if (bDoLR && inputrec->nstcalclr > 1 && !EI_VV(inputrec->eI)) /* get this working with VV? */
1747 /* Store the total force + nstcalclr-1 times the LR force
1748 * in forces_lr, so it can be used in a normal update algorithm
1749 * to produce twin time stepping.
1751 /* is this correct in the new construction? MRS */
1752 combine_forces(inputrec->nstcalclr,constr,inputrec,md,idef,cr,
1754 start,nrend,f,f_lr,nrnb);
1762 /* ############# START The update of velocities and positions ######### */
1764 dump_it_all(fplog,"Before update",
1765 state->natoms,state->x,xprime,state->v,force);
1767 if (EI_RANDOM(inputrec->eI))
1769 /* We still need to take care of generating random seeds properly
1770 * when multi-threading.
1776 nth = gmx_omp_nthreads_get(emntUpdate);
1779 # pragma omp parallel for num_threads(nth) schedule(static) private(alpha)
1780 for(th=0; th<nth; th++)
1782 int start_th,end_th;
1784 start_th = start + ((nrend-start)* th )/nth;
1785 end_th = start + ((nrend-start)*(th+1))/nth;
1787 switch (inputrec->eI) {
1789 if (ekind->cosacc.cos_accel == 0)
1791 do_update_md(start_th,end_th,dt,
1792 ekind->tcstat,state->nosehoover_vxi,
1793 ekind->bNEMD,ekind->grpstat,inputrec->opts.acc,
1794 inputrec->opts.nFreeze,
1795 md->invmass,md->ptype,
1796 md->cFREEZE,md->cACC,md->cTC,
1797 state->x,xprime,state->v,force,M,
1802 do_update_visc(start_th,end_th,dt,
1803 ekind->tcstat,state->nosehoover_vxi,
1804 md->invmass,md->ptype,
1805 md->cTC,state->x,xprime,state->v,force,M,
1807 ekind->cosacc.cos_accel,
1813 do_update_sd1(upd->sd,start,homenr,dt,
1814 inputrec->opts.acc,inputrec->opts.nFreeze,
1815 md->invmass,md->ptype,
1816 md->cFREEZE,md->cACC,md->cTC,
1817 state->x,xprime,state->v,force,state->sd_X,
1818 inputrec->opts.ngtc,inputrec->opts.tau_t,inputrec->opts.ref_t);
1821 /* The SD update is done in 2 parts, because an extra constraint step
1824 do_update_sd2(upd->sd,bInitStep,start,homenr,
1825 inputrec->opts.acc,inputrec->opts.nFreeze,
1826 md->invmass,md->ptype,
1827 md->cFREEZE,md->cACC,md->cTC,
1828 state->x,xprime,state->v,force,state->sd_X,
1829 inputrec->opts.ngtc,inputrec->opts.tau_t,inputrec->opts.ref_t,
1833 do_update_bd(start,nrend,dt,
1834 inputrec->opts.nFreeze,md->invmass,md->ptype,
1835 md->cFREEZE,md->cTC,
1836 state->x,xprime,state->v,force,
1838 inputrec->opts.ngtc,inputrec->opts.tau_t,inputrec->opts.ref_t,
1839 upd->sd->bd_rf,upd->sd->gaussrand);
1843 alpha = 1.0 + DIM/((double)inputrec->opts.nrdf[0]); /* assuming barostat coupled to group 0. */
1844 switch (UpdatePart) {
1847 do_update_vv_vel(start_th,end_th,dt,
1848 ekind->tcstat,ekind->grpstat,
1849 inputrec->opts.acc,inputrec->opts.nFreeze,
1850 md->invmass,md->ptype,
1851 md->cFREEZE,md->cACC,
1853 (bNH || bPR),state->veta,alpha);
1856 do_update_vv_pos(start_th,end_th,dt,
1857 ekind->tcstat,ekind->grpstat,
1858 inputrec->opts.acc,inputrec->opts.nFreeze,
1859 md->invmass,md->ptype,md->cFREEZE,
1860 state->x,xprime,state->v,force,
1861 (bNH || bPR),state->veta,alpha);
1866 gmx_fatal(FARGS,"Don't know how to update coordinates");
1874 void correct_ekin(FILE *log,int start,int end,rvec v[],rvec vcm,real mass[],
1875 real tmass,tensor ekin)
1878 * This is a debugging routine. It should not be called for production code
1880 * The kinetic energy should calculated according to:
1881 * Ekin = 1/2 m (v-vcm)^2
1882 * However the correction is not always applied, since vcm may not be
1883 * known in time and we compute
1884 * Ekin' = 1/2 m v^2 instead
1885 * This can be corrected afterwards by computing
1886 * Ekin = Ekin' + 1/2 m ( -2 v vcm + vcm^2)
1888 * Ekin = Ekin' - m v vcm + 1/2 m vcm^2
1895 /* Local particles */
1898 /* Processor dependent part. */
1900 for(i=start; (i<end); i++)
1904 for(j=0; (j<DIM); j++)
1910 svmul(1/tmass,vcm,vcm);
1911 svmul(0.5,vcm,hvcm);
1913 for(j=0; (j<DIM); j++)
1915 for(k=0; (k<DIM); k++)
1917 dekin[j][k] += vcm[k]*(tm*hvcm[j]-mv[j]);
1920 pr_rvecs(log,0,"dekin",dekin,DIM);
1921 pr_rvecs(log,0," ekin", ekin,DIM);
1922 fprintf(log,"dekin = %g, ekin = %g vcm = (%8.4f %8.4f %8.4f)\n",
1923 trace(dekin),trace(ekin),vcm[XX],vcm[YY],vcm[ZZ]);
1924 fprintf(log,"mv = (%8.4f %8.4f %8.4f)\n",
1925 mv[XX],mv[YY],mv[ZZ]);
1928 extern gmx_bool update_randomize_velocities(t_inputrec *ir, gmx_large_int_t step, t_mdatoms *md, t_state *state, gmx_update_t upd, t_idef *idef, gmx_constr_t constr) {
1931 real rate = (ir->delta_t)/ir->opts.tau_t[0];
1932 /* proceed with andersen if 1) it's fixed probability per
1933 particle andersen or 2) it's massive andersen and it's tau_t/dt */
1934 if ((ir->etc==etcANDERSEN) || do_per_step(step,(int)(1.0/rate)))
1936 srenew(upd->randatom,state->nalloc);
1937 srenew(upd->randatom_list,state->nalloc);
1938 if (upd->randatom_list_init == FALSE) {
1939 for (i=0;i<state->nalloc;i++) {
1940 upd->randatom[i] = FALSE;
1941 upd->randatom_list[i] = 0;
1943 upd->randatom_list_init = TRUE;
1945 andersen_tcoupl(ir,md,state,upd->sd->gaussrand,rate,
1946 (ir->etc==etcANDERSEN)?idef:NULL,
1947 constr?get_nblocks(constr):0,
1948 constr?get_sblock(constr):NULL,
1949 upd->randatom,upd->randatom_list,
1950 upd->sd->randomize_group,upd->sd->boltzfac);