4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Copyright (c) 1991-2001, University of Groningen, The Netherlands
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * If you want to redistribute modifications, please consider that
18 * scientific software is very special. Version control is crucial -
19 * bugs must be traceable. We will be happy to consider code for
20 * inclusion in the official distribution, but derived work must not
21 * be called official GROMACS. Details are found in the README & COPYING
22 * files - if they are missing, get the official version at www.gromacs.org.
24 * To help us fund GROMACS development, we humbly ask that you cite
25 * the papers on the package - you can find them in the top README file.
27 * For more info, check our website at http://www.gromacs.org
30 * GROningen Mixture of Alchemy and Childrens' Stories
32 static char *SRCID_md_c
= "$Id$";
65 volatile bool bGotTermSignal
= FALSE
, bGotUsr1Signal
= FALSE
;
67 static RETSIGTYPE
signal_handler(int n
)
71 bGotTermSignal
= TRUE
;
74 bGotUsr1Signal
= TRUE
;
81 void mdrunner(t_commrec
*cr
,t_commrec
*mcr
,int nfile
,t_filenm fnm
[],
82 bool bVerbose
,bool bCompact
,
83 int nDlb
,int nstepout
,t_edsamyn
*edyn
,
86 double nodetime
=0,realtime
;
88 rvec
*buf
,*f
,*vold
,*v
,*vt
,*x
,box_size
;
100 bool bDummies
,bParDummies
;
101 t_comm_dummies dummycomm
;
105 /* Initiate everything (snew sets to zero!) */
112 snew(nrnb
,cr
->nnodes
);
114 if (bVerbose
&& MASTER(cr
))
115 fprintf(stderr
,"Getting Loaded...\n");
118 /* The master thread on the master node reads from disk, then passes everything
119 * around the ring, and finally frees the stuff
122 distribute_parts(cr
->left
,cr
->right
,cr
->nodeid
,cr
->nnodes
,parm
,
123 ftp2fn(efTPX
,nfile
,fnm
),nDlb
);
125 /* Every node (including the master) reads the data from the ring */
126 init_parts(stdlog
,cr
,
127 parm
,top
,&x
,&v
,&mdatoms
,nsb
,
128 MASTER(cr
) ? LIST_SCALARS
| LIST_PARM
: 0,
129 &bParDummies
,&dummycomm
);
132 init_single(stdlog
,parm
,ftp2fn(efTPX
,nfile
,fnm
),top
,&x
,&v
,&mdatoms
,nsb
);
135 snew(buf
,nsb
->natoms
);
137 snew(vt
,nsb
->natoms
);
138 snew(vold
,nsb
->natoms
);
140 if (bVerbose
&& MASTER(cr
))
141 fprintf(stderr
,"Loaded with Money\n\n");
143 /* Index numbers for parallellism... */
144 nsb
->nodeid
= cr
->nodeid
;
145 top
->idef
.nodeid
= cr
->nodeid
;
147 /* Group stuff (energies etc) */
148 init_groups(stdlog
,mdatoms
,&(parm
->ir
.opts
),grps
);
149 /* Copy the cos acceleration to the groups struct */
150 grps
->cosacc
.cos_accel
= parm
->ir
.cos_accel
;
152 /* Periodicity stuff */
153 graph
=mk_graph(&(top
->idef
),top
->atoms
.nr
,FALSE
,FALSE
);
155 p_graph(debug
,"Initial graph",graph
);
157 /* Distance Restraints */
158 init_disres(stdlog
,top
->idef
.il
[F_DISRES
].nr
,top
->idef
.il
[F_DISRES
].iatoms
,
159 top
->idef
.iparams
,&(parm
->ir
),mcr
,fcd
);
161 /* Orientation restraints */
162 init_orires(stdlog
,top
->idef
.il
[F_ORIRES
].nr
,top
->idef
.il
[F_ORIRES
].iatoms
,
163 top
->idef
.iparams
,x
,mdatoms
,&(parm
->ir
),mcr
,fcd
);
165 /* check if there are dummies */
167 for(i
=0; (i
<F_NRE
) && !bDummies
; i
++)
168 bDummies
= ((interaction_function
[i
].flags
& IF_DUMMY
) &&
169 (top
->idef
.il
[i
].nr
> 0));
172 please_cite(stdlog
,"Feenstra99");
174 /* Initiate forcerecord */
176 init_forcerec(stdlog
,fr
,&(parm
->ir
),top
,cr
,mdatoms
,nsb
,parm
->box
,FALSE
,
177 opt2fn("-table",nfile
,fnm
),FALSE
);
178 fr
->bSepDVDL
= ((Flags
& MD_SEPDVDL
) == MD_SEPDVDL
);
180 for(m
=0; (m
<DIM
); m
++)
181 box_size
[m
]=parm
->box
[m
][m
];
183 /* Initiate PPPM if necessary */
184 if (fr
->eeltype
== eelPPPM
)
185 init_pppm(stdlog
,cr
,nsb
,FALSE
,TRUE
,box_size
,getenv("GMXGHAT"),&parm
->ir
);
186 if (fr
->eeltype
== eelPME
)
187 init_pme(stdlog
,cr
,parm
->ir
.nkx
,parm
->ir
.nky
,parm
->ir
.nkz
,parm
->ir
.pme_order
,
188 HOMENR(nsb
),parm
->ir
.bOptFFT
,parm
->ir
.ewald_geometry
);
190 /* Now do whatever the user wants us to do (how flexible...) */
191 switch (parm
->ir
.eI
) {
195 start_t
=do_md(stdlog
,cr
,mcr
,nfile
,fnm
,
196 bVerbose
,bCompact
,bDummies
,
197 bParDummies
? &dummycomm
: NULL
,
198 nstepout
,parm
,grps
,top
,ener
,fcd
,x
,vold
,v
,vt
,f
,buf
,
199 mdatoms
,nsb
,nrnb
,graph
,edyn
,fr
,box_size
,Flags
);
202 start_t
=do_cg(stdlog
,nfile
,fnm
,parm
,top
,grps
,nsb
,
203 x
,f
,buf
,mdatoms
,parm
->ekin
,ener
,fcd
,
204 nrnb
,bVerbose
,bDummies
,
205 bParDummies
? &dummycomm
: NULL
,
206 cr
,mcr
,graph
,fr
,box_size
);
209 start_t
=do_steep(stdlog
,nfile
,fnm
,parm
,top
,grps
,nsb
,
210 x
,f
,buf
,mdatoms
,parm
->ekin
,ener
,fcd
,
211 nrnb
,bVerbose
,bDummies
,
212 bParDummies
? &dummycomm
: NULL
,
213 cr
,mcr
,graph
,fr
,box_size
);
216 start_t
=do_nm(stdlog
,cr
,nfile
,fnm
,
217 bVerbose
,bCompact
,nstepout
,parm
,grps
,
218 top
,ener
,fcd
,x
,vold
,v
,vt
,f
,buf
,
219 mdatoms
,nsb
,nrnb
,graph
,edyn
,fr
,box_size
);
222 fatal_error(0,"Invalid integrator (%d)...\n",parm
->ir
.eI
);
225 /* Some timing stats */
227 realtime
=difftime(time(NULL
),start_t
);
228 if ((nodetime
=node_time()) == 0)
234 /* Convert back the atoms */
235 md2atoms(mdatoms
,&(top
->atoms
),TRUE
);
237 /* Finish up, write some stuff
238 * if rerunMD, don't write last frame again
240 finish_run(stdlog
,cr
,ftp2fn(efSTO
,nfile
,fnm
),
241 nsb
,top
,parm
,nrnb
,nodetime
,realtime
,parm
->ir
.nsteps
,
242 parm
->ir
.eI
==eiMD
|| parm
->ir
.eI
==eiSD
|| parm
->ir
.eI
==eiBD
);
244 /* Does what it says */
245 print_date_and_time(stdlog
,cr
->nodeid
,"Finished mdrun");
248 time_t do_md(FILE *log
,t_commrec
*cr
,t_commrec
*mcr
,int nfile
,t_filenm fnm
[],
249 bool bVerbose
,bool bCompact
,
250 bool bDummies
, t_comm_dummies
*dummycomm
,
251 int stepout
,t_parm
*parm
,t_groups
*grps
,t_topology
*top
,
252 real ener
[],t_fcdata
*fcd
,
253 rvec x
[],rvec vold
[],rvec v
[],rvec vt
[],rvec f
[],
254 rvec buf
[],t_mdatoms
*mdatoms
,t_nsborder
*nsb
,t_nrnb nrnb
[],
255 t_graph
*graph
,t_edsamyn
*edyn
,t_forcerec
*fr
,rvec box_size
,
259 int fp_ene
=0,fp_trn
=0,step
;
262 real t
,lambda
,t0
,lam0
,SAfactor
;
263 bool bNS
,bStopCM
,bTYZ
,bRerunMD
,bNotLastFrame
=FALSE
,
264 bFirstStep
,bLastStep
,bNEMD
,do_log
,bRerunWarnNoV
=TRUE
;
265 tensor force_vir
,pme_vir
,shake_vir
;
267 char *traj
,*xtc_traj
; /* normal and compressed trajectory filename */
273 t_pull pulldata
; /* for pull code */
274 /* A boolean (disguised as a real) to terminate mdrun */
277 /* XMDRUN stuff: shell, general coupling etc. */
279 int nshell
,nshell_tot
,count
,nconverged
=0;
280 t_shell
*shells
=NULL
;
283 bool bShell
,bIonize
=FALSE
,bGlas
=FALSE
;
284 bool bTCR
=FALSE
,bConverged
=TRUE
,bOK
;
289 t_coupl_rec
*tcr
=NULL
;
291 /* End of XMDRUN stuff */
293 /* Turn on signal handling */
294 signal(SIGTERM
,signal_handler
);
295 signal(SIGUSR1
,signal_handler
);
297 /* Check for special mdrun options */
298 bRerunMD
= (Flags
& MD_RERUN
) == MD_RERUN
;
299 bIonize
= (Flags
& MD_IONIZE
) == MD_IONIZE
;
300 bGlas
= (Flags
& MD_GLAS
) == MD_GLAS
;
301 bFFscan
= (Flags
& MD_FFSCAN
) == MD_FFSCAN
;
304 init_md(cr
,&parm
->ir
,parm
->box
,&t
,&t0
,&lambda
,&lam0
,&SAfactor
,
306 nfile
,fnm
,&traj
,&xtc_traj
,&fp_ene
,&fp_dgdl
,&mdebin
,grps
,
307 force_vir
,pme_vir
,shake_vir
,mdatoms
,mu_tot
,&bNEMD
,&vcm
,nsb
);
310 /* Check for polarizable models */
311 shells
= init_shells(log
,START(nsb
),HOMENR(nsb
),&top
->idef
,
315 gmx_sumi(1,&nshell_tot
,cr
);
316 bShell
= nshell_tot
> 0;
318 /* Check whether we have to do dipole stuff */
319 if (opt2bSet("-dn",nfile
,fnm
))
320 rd_index(opt2fn("-dn",nfile
,fnm
),1,&gnx
,&grpindex
,&grpname
);
322 gnx
= top
->blocks
[ebMOLS
].nr
;
324 for(i
=0; (i
<gnx
); i
++)
328 /* Check whether we have to GCT stuff */
329 bTCR
= ftp2bSet(efGCT
,nfile
,fnm
);
330 if (MASTER(cr
) && bTCR
)
331 fprintf(stderr
,"Will do General Coupling Theory!\n");
333 /* Remove periodicity */
334 if (fr
->ePBC
!= epbcNONE
)
335 do_pbc_first(log
,parm
,box_size
,fr
,graph
,x
);
338 /* Initialize pull code */
339 init_pull(log
,nfile
,fnm
,&pulldata
,x
,mdatoms
,parm
->box
);
340 if (pulldata
.bPull
&& cr
->nnodes
>1 && !pulldata
.runtype
==eUmbrella
)
341 fatal_error(0,"Can not pull in parallel");
343 if (!parm
->ir
.bUncStart
)
344 do_shakefirst(log
,bTYZ
,lambda
,ener
,parm
,nsb
,mdatoms
,x
,vold
,buf
,f
,v
,
345 graph
,cr
,&mynrnb
,grps
,fr
,top
,edyn
,&pulldata
);
348 /* Compute initial EKin for all.. */
349 if (grps
->cosacc
.cos_accel
== 0)
350 calc_ke_part(TRUE
,parm
->ir
.eI
==eiSD
,
351 START(nsb
),HOMENR(nsb
),vold
,v
,vt
,&(parm
->ir
.opts
),
352 mdatoms
,grps
,&mynrnb
,lambda
,&ener
[F_DVDLKIN
]);
354 calc_ke_part_visc(TRUE
,START(nsb
),HOMENR(nsb
),
355 parm
->box
,x
,vold
,v
,vt
,&(parm
->ir
.opts
),
356 mdatoms
,grps
,&mynrnb
,lambda
,&ener
[F_DVDLKIN
]);
360 global_stat(log
,cr
,ener
,force_vir
,shake_vir
,
361 &(parm
->ir
.opts
),grps
,&mynrnb
,nrnb
,vcm
,&terminate
);
364 /* Calculate Temperature coupling parameters lambda */
365 ener
[F_TEMP
] = sum_ekin(&(parm
->ir
.opts
),grps
,parm
->ekin
,bTYZ
);
366 if(parm
->ir
.etc
==etcBERENDSEN
)
367 berendsen_tcoupl(&(parm
->ir
.opts
),grps
,
368 parm
->ir
.delta_t
,SAfactor
);
369 else if(parm
->ir
.etc
==etcNOSEHOOVER
)
370 nosehoover_tcoupl(&(parm
->ir
.opts
),grps
,
371 parm
->ir
.delta_t
,SAfactor
);
374 /* Initiate data for the special cases */
376 snew(xcopy
,nsb
->natoms
);
377 for(ii
=0; (ii
<nsb
->natoms
); ii
++)
378 copy_rvec(x
[ii
],xcopy
[ii
]);
381 /* Write start time and temperature */
382 start_t
=print_date_and_time(log
,cr
->nodeid
,"Started mdrun");
385 fprintf(log
,"Initial temperature: %g K\n",ener
[F_TEMP
]);
387 fprintf(stderr
,"starting md rerun '%s', reading coordinates from"
388 " input trajectory '%s'\n\n",
389 *(top
->name
),opt2fn("-rerun",nfile
,fnm
));
391 fprintf(stderr
,"Calculated time to finish depends on nsteps from "
392 "run input file,\nwhich may not correspond to the time "
393 "needed to process input trajectory.\n\n");
395 fprintf(stderr
,"starting mdrun '%s'\n%d steps, %8.1f ps.\n\n",
396 *(top
->name
),parm
->ir
.nsteps
,parm
->ir
.nsteps
*parm
->ir
.delta_t
);
398 /* Set the node time counter to 0 after initialisation */
401 /***********************************************************
405 ************************************************************/
407 /* if rerunMD then read coordinates and velocities from input trajectory */
409 bNotLastFrame
= read_first_frame(&status
,opt2fn("-rerun",nfile
,fnm
),
410 &rerun_fr
,TRX_NEED_X
| TRX_READ_V
);
411 if (rerun_fr
.natoms
!= mdatoms
->nr
)
412 fatal_error(0,"Number of atoms in trajectory (%d) does not match the "
413 "run input file (%d)\n",rerun_fr
.natoms
,mdatoms
->nr
);
416 /* loop over MD steps or if rerunMD to end of input trajectory */
419 while ((!bRerunMD
&& (step
<=parm
->ir
.nsteps
)) ||
420 (bRerunMD
&& bNotLastFrame
)) {
424 step
= rerun_fr
.step
;
429 for(i
=0; i
<mdatoms
->nr
; i
++)
430 copy_rvec(rerun_fr
.x
[i
],x
[i
]);
432 for(i
=0; i
<mdatoms
->nr
; i
++)
433 copy_rvec(rerun_fr
.v
[i
],v
[i
]);
435 for(i
=0; i
<mdatoms
->nr
; i
++)
438 fprintf(stderr
,"\nWARNING: Some frames do not contain velocities.\n"
439 " Ekin, temperature and pressure are incorrect,\n"
440 " the virial will be incorrect when constraints are present.\n"
442 bRerunWarnNoV
= FALSE
;
445 copy_mat(rerun_fr
.box
,parm
->box
);
447 /* for rerun MD always do Neighbour Searching */
448 bNS
= ((parm
->ir
.nstlist
!=0) || bFirstStep
);
450 /* Determine whether or not to do Neighbour Searching */
451 bNS
= ((parm
->ir
.nstlist
&& (step
% parm
->ir
.nstlist
==0)) || bFirstStep
);
453 bLastStep
=(step
==parm
->ir
.nsteps
);
455 do_log
= do_per_step(step
,parm
->ir
.nstlog
) || bLastStep
;
457 /* Stop Center of Mass motion */
458 bStopCM
= do_per_step(step
,abs(parm
->ir
.nstcomm
));
460 /* Copy back starting coordinates in case we're doing a forcefield scan */
462 for(ii
=0; (ii
<nsb
->natoms
); ii
++)
463 copy_rvec(xcopy
[ii
],x
[ii
]);
467 shift_self(graph
,parm
->box
,x
);
469 construct_dummies(log
,x
,&mynrnb
,parm
->ir
.delta_t
,v
,&top
->idef
,
470 graph
,cr
,parm
->box
,dummycomm
);
472 unshift_self(graph
,parm
->box
,x
);
477 /* Set values for invmass etc. This routine not parallellized, but hardly
478 * ever used, only when doing free energy calculations.
480 init_mdatoms(mdatoms
,lambda
,bFirstStep
);
482 clear_mat(force_vir
);
484 /* Ionize the atoms if necessary */
486 ionize(log
,mdatoms
,top
->atoms
.atomname
,t
,&parm
->ir
,x
,v
,
487 START(nsb
),START(nsb
)+HOMENR(nsb
),parm
->box
,cr
);
489 /* Update force field in ffscan program */
491 update_forcefield(nfile
,fnm
,fr
);
494 /* Now is the time to relax the shells */
495 count
=relax_shells(log
,cr
,mcr
,bVerbose
,step
,parm
,bNS
,bStopCM
,top
,
496 ener
,fcd
,x
,vold
,v
,vt
,f
,buf
,mdatoms
,nsb
,&mynrnb
,graph
,
497 grps
,force_vir
,pme_vir
,bShell
,
498 nshell
,shells
,fr
,traj
,t
,lambda
,mu_tot
,
499 nsb
->natoms
,parm
->box
,&bConverged
);
506 /* The coordinates (x) are shifted (to get whole molecules) in do_force
507 * This is parallellized as well, and does communication too.
508 * Check comments in sim_util.c
510 do_force(log
,cr
,mcr
,parm
,nsb
,force_vir
,pme_vir
,step
,&mynrnb
,
511 top
,grps
,x
,v
,f
,buf
,mdatoms
,ener
,fcd
,bVerbose
&& !PAR(cr
),
512 lambda
,graph
,bNS
,FALSE
,fr
,mu_tot
,FALSE
);
516 mu_aver
=calc_mu_aver(cr
,nsb
,x
,mdatoms
->chargeA
,mu_tot
,top
,mdatoms
,
520 do_glas(log
,START(nsb
),HOMENR(nsb
),x
,f
,
521 fr
,mdatoms
,top
->idef
.atnr
,&parm
->ir
,ener
);
523 if (bTCR
&& (step
== 0)) {
524 tcr
=init_coupling(log
,nfile
,fnm
,cr
,fr
,mdatoms
,&(top
->idef
));
525 fprintf(log
,"Done init_coupling\n");
529 /* Now we have the energies and forces corresponding to the
530 * coordinates at time t. We must output all of this before
532 * for RerunMD t is read from input trajectory
535 t
= t0
+ step
*parm
->ir
.delta_t
;
537 if (parm
->ir
.efep
!= efepNO
) {
538 if (bRerunMD
&& rerun_fr
.bLambda
)
539 lambda
= rerun_fr
.lambda
;
541 lambda
= lam0
+ step
*parm
->ir
.delta_lambda
;
543 if (parm
->ir
.bSimAnn
) {
544 SAfactor
= 1.0 - t
/parm
->ir
.zero_temp_time
;
549 if (MASTER(cr
) && do_log
&& !bFFscan
)
550 print_ebin_header(log
,step
,t
,lambda
,SAfactor
);
553 spread_dummy_f(log
,x
,f
,&mynrnb
,&top
->idef
,dummycomm
,cr
);
555 /* Calculation of the virial must be done after dummies! */
556 /* Question: Is it correct to do the PME forces after this? */
557 calc_virial(log
,START(nsb
),HOMENR(nsb
),x
,f
,
558 force_vir
,pme_vir
,graph
,parm
->box
,&mynrnb
,fr
,FALSE
);
560 /* Spread the LR force on dummy particle to the other particles...
561 * This is parallellized. MPI communication is performed
562 * if the constructing atoms aren't local.
564 if (bDummies
&& fr
->bEwald
)
565 spread_dummy_f(log
,x
,fr
->f_pme
,&mynrnb
,&top
->idef
,dummycomm
,cr
);
567 sum_lrforces(f
,fr
,START(nsb
),HOMENR(nsb
));
569 xx
= (do_per_step(step
,parm
->ir
.nstxout
) || bLastStep
) ? x
: NULL
;
570 vv
= (do_per_step(step
,parm
->ir
.nstvout
) || bLastStep
) ? v
: NULL
;
571 ff
= (do_per_step(step
,parm
->ir
.nstfout
)) ? f
: NULL
;
573 fp_trn
= write_traj(log
,cr
,traj
,nsb
,step
,t
,lambda
,
574 nrnb
,nsb
->natoms
,xx
,vv
,ff
,parm
->box
);
577 /* don't write xtc and last structure for rerunMD */
578 if (!bRerunMD
&& !bFFscan
) {
579 if (do_per_step(step
,parm
->ir
.nstxtcout
))
580 write_xtc_traj(log
,cr
,xtc_traj
,nsb
,mdatoms
,
581 step
,t
,x
,parm
->box
,parm
->ir
.xtcprec
);
582 if (bLastStep
&& MASTER(cr
)) {
583 fprintf(stderr
,"Writing final coordinates.\n");
584 write_sto_conf(ftp2fn(efSTO
,nfile
,fnm
),
585 *top
->name
, &(top
->atoms
),x
,v
,parm
->box
);
589 clear_mat(shake_vir
);
591 /* Afm and Umbrella type pulling happens before the update,
592 * other types in update
594 if (pulldata
.bPull
&&
595 (pulldata
.runtype
== eAfm
|| pulldata
.runtype
== eUmbrella
||
596 pulldata
.runtype
== eTest
))
597 pull(&pulldata
,x
,f
,parm
->box
,top
,parm
->ir
.delta_t
,step
,
598 mdatoms
->nr
,mdatoms
,START(nsb
),HOMENR(nsb
));
601 clear_rvecs(nsb
->natoms
,buf
);
603 /* This is also parallellized, but check code in update.c */
604 /* bOK = update(nsb->natoms,START(nsb),HOMENR(nsb),step,lambda,&ener[F_DVDL], */
606 update(nsb
->natoms
,START(nsb
),HOMENR(nsb
),step
,lambda
,&ener
[F_DVDL
],
607 parm
,SAfactor
,mdatoms
,x
,graph
,f
,buf
,vold
,vt
,v
,
608 top
,grps
,shake_vir
,cr
,&mynrnb
,bTYZ
,TRUE
,edyn
,&pulldata
,bNEMD
);
609 if (!bOK
&& !bFFscan
)
610 fatal_error(0,"Constraint error: Shake, Lincs or Settle could not solve the constrains");
612 /* The coordinates (x) were unshifted in update */
613 if (bFFscan
&& (!bShell
|| bConverged
))
614 print_forcefield(log
,ener
[F_EPOT
],HOMENR(nsb
),f
,buf
,xcopy
,
615 &(top
->blocks
[ebMOLS
]),mdatoms
->massT
);
617 if (parm
->ir
.epc
!=epcNO
)
618 correct_box(parm
->box
,fr
,graph
);
619 /* (un)shifting should NOT be done after this,
620 * since the box vectors might have changed
623 /* Non-equilibrium MD: this is parallellized, but only does communication
624 * when there really is NEMD.
626 if (PAR(cr
) && bNEMD
)
627 accumulate_u(cr
,&(parm
->ir
.opts
),grps
);
630 if (grps
->cosacc
.cos_accel
== 0)
631 calc_ke_part(FALSE
,parm
->ir
.eI
==eiSD
,
632 START(nsb
),HOMENR(nsb
),vold
,v
,vt
,&(parm
->ir
.opts
),
633 mdatoms
,grps
,&mynrnb
,lambda
,&ener
[F_DVDLKIN
]);
635 calc_ke_part_visc(FALSE
,START(nsb
),HOMENR(nsb
),
636 parm
->box
,x
,vold
,v
,vt
,&(parm
->ir
.opts
),
637 mdatoms
,grps
,&mynrnb
,lambda
,&ener
[F_DVDLKIN
]);
640 /* Calculate center of mass velocity if necessary, also parallellized */
641 if (bStopCM
&& !bFFscan
)
642 calc_vcm_grp(log
,START(nsb
),HOMENR(nsb
),mdatoms
->massT
,x
,v
,vcm
);
644 /* Check whether everything is still allright */
645 if (bGotTermSignal
|| bGotUsr1Signal
) {
650 fprintf(log
,"\n\nReceived the %s signal\n\n",
651 bGotTermSignal
? "TERM" : "USR1");
654 fprintf(stderr
,"\n\nReceived the %s signal\n\n",
655 bGotTermSignal
? "TERM" : "USR1");
658 bGotTermSignal
= FALSE
;
659 bGotUsr1Signal
= FALSE
;
663 /* Globally (over all NODEs) sum energy, virial etc.
664 * This includes communication
666 global_stat(log
,cr
,ener
,force_vir
,shake_vir
,
667 &(parm
->ir
.opts
),grps
,&mynrnb
,nrnb
,vcm
,&terminate
);
668 /* Correct for double counting energies, should be moved to
671 if (fr
->bTwinRange
&& !bNS
)
672 for(i
=0; (i
<grps
->estat
.nn
); i
++) {
673 grps
->estat
.ee
[egLR
][i
] /= cr
->nnodes
;
674 grps
->estat
.ee
[egLJLR
][i
] /= cr
->nnodes
;
678 cp_nrnb(&(nrnb
[0]),&mynrnb
);
680 /* This is just for testing. Nothing is actually done to Ekin
681 * since that would require extra communication.
683 if (!bNEMD
&& debug
&& (vcm
->nr
> 0))
684 correct_ekin(debug
,START(nsb
),START(nsb
)+HOMENR(nsb
),v
,
686 mdatoms
->massT
,mdatoms
->tmass
,parm
->ekin
);
688 if ((terminate
!= 0) && (step
< parm
->ir
.nsteps
)) {
689 if (terminate
<0 && parm
->ir
.nstxout
)
690 /* this is the USR1 signal and we are writing x to trr,
691 stop at next x frame in trr */
692 parm
->ir
.nsteps
= (step
/ parm
->ir
.nstxout
+ 1) * parm
->ir
.nstxout
;
694 parm
->ir
.nsteps
= step
+1;
695 fprintf(log
,"\nSetting nsteps to %d\n\n",parm
->ir
.nsteps
);
698 fprintf(stderr
,"\nSetting nsteps to %d\n\n",parm
->ir
.nsteps
);
701 /* erase the terminate signal */
705 /* Do center of mass motion removal */
706 if (bStopCM
&& !bFFscan
) {
707 check_cm_grp(log
,vcm
);
708 do_stopcm_grp(log
,START(nsb
),HOMENR(nsb
),x
,v
,vcm
);
709 inc_nrnb(&mynrnb
,eNR_STOPCM
,HOMENR(nsb
));
711 calc_vcm_grp(log,START(nsb),HOMENR(nsb),mdatoms->massT,x,v,vcm);
712 check_cm_grp(log,vcm);
713 do_stopcm_grp(log,START(nsb),HOMENR(nsb),x,v,vcm);
714 check_cm_grp(log,vcm);
718 /* Add force and shake contribution to the virial */
719 m_add(force_vir
,shake_vir
,parm
->vir
);
721 /* Sum the potential energy terms from group contributions */
722 sum_epot(&(parm
->ir
.opts
),grps
,ener
);
724 /* Calculate the amplitude of the cosine velocity profile */
725 grps
->cosacc
.vcos
= grps
->cosacc
.mvcos
/mdatoms
->tmass
;
727 /* Sum the kinetic energies of the groups & calc temp */
728 ener
[F_TEMP
]=sum_ekin(&(parm
->ir
.opts
),grps
,parm
->ekin
,bTYZ
);
729 ener
[F_EKIN
]=trace(parm
->ekin
);
730 ener
[F_ETOT
]=ener
[F_EPOT
]+ener
[F_EKIN
];
732 /* Check for excessively large energies */
733 if (bIonize
&& fabs(ener
[F_ETOT
]) > 1e18
) {
734 fprintf(stderr
,"Energy too large (%g), giving up\n",ener
[F_ETOT
]);
738 /* Calculate Temperature coupling parameters lambda and adjust
739 * target temp when doing simulated annealing
741 if(parm
->ir
.etc
==etcBERENDSEN
)
742 berendsen_tcoupl(&(parm
->ir
.opts
),grps
,parm
->ir
.delta_t
,SAfactor
);
743 else if(parm
->ir
.etc
==etcNOSEHOOVER
)
744 nosehoover_tcoupl(&(parm
->ir
.opts
),grps
,parm
->ir
.delta_t
,SAfactor
);
746 /* Calculate pressure and apply LR correction if PPPM is used */
747 calc_pres(fr
->ePBC
,parm
->box
,parm
->ekin
,parm
->vir
,parm
->pres
,
748 (fr
->eeltype
==eelPPPM
) ? ener
[F_LR
] : 0.0);
750 /* Calculate long range corrections to pressure and energy */
752 set_avcsix(log
,fr
,mdatoms
);
754 /* Calculate long range corrections to pressure and energy */
755 calc_dispcorr(log
,parm
->ir
.eDispCorr
,
756 fr
,mdatoms
->nr
,parm
->box
,parm
->pres
,parm
->vir
,ener
);
759 /* Only do GCT when the relaxation of shells (minimization) has converged,
760 * otherwise we might be coupling to bogus energies.
761 * In parallel we must always do this, because the other sims might
764 do_coupling(log
,nfile
,fnm
,tcr
,t
,step
,ener
,fr
,
765 &(parm
->ir
),MASTER(cr
),
766 mdatoms
,&(top
->idef
),mu_aver
,
767 top
->blocks
[ebMOLS
].nr
,(mcr
!=NULL
) ? mcr
: cr
,
768 parm
->box
,parm
->vir
,parm
->pres
,
769 mu_tot
,x
,f
,bConverged
);
773 /* Time for performance */
774 if (((step
% 10) == 0) || bLastStep
)
778 if (MASTER(cr
) && !bFFscan
) {
779 bool do_ene
,do_dr
,do_or
;
781 upd_mdebin(mdebin
,fp_dgdl
,mdatoms
->tmass
,step
,t
,ener
,parm
->box
,shake_vir
,
782 force_vir
,parm
->vir
,parm
->pres
,grps
,mu_tot
,
783 (parm
->ir
.etc
==etcNOSEHOOVER
));
784 do_ene
= do_per_step(step
,parm
->ir
.nstenergy
) || bLastStep
;
785 do_dr
= do_per_step(step
,parm
->ir
.nstdisreout
) || bLastStep
;
786 do_or
= do_per_step(step
,parm
->ir
.nstorireout
) || bLastStep
;
787 print_ebin(fp_ene
,do_ene
,do_dr
,do_or
,do_log
?log
:NULL
,step
,t
,
788 eprNORMAL
,bCompact
,mdebin
,fcd
,&(top
->atoms
));
793 /* Remaining runtime */
794 if (MASTER(cr
) && bVerbose
&& ( ((step
% stepout
)==0) || bLastStep
)) {
796 fprintf(stderr
,"\n");
797 print_time(stderr
,start_t
,step
,&parm
->ir
);
803 /* read next frame from input trajectory */
804 bNotLastFrame
= read_next_frame(status
,&rerun_fr
);
806 if (!bRerunMD
|| !rerun_fr
.bStep
)
807 /* increase the MD step number */
810 /* End of main MD loop */
813 /* Dump the NODE time to the log file on each node */
815 double *ct
,ctmax
,ctsum
;
818 ct
[cr
->nodeid
] = node_time();
819 gmx_sumd(cr
->nnodes
,ct
,cr
);
822 for(i
=1; (i
<cr
->nodeid
); i
++) {
823 ctmax
= max(ctmax
,ct
[i
]);
827 fprintf(log
,"\nTotal NODE time on node %d: %g\n",cr
->nodeid
,ct
[cr
->nodeid
]);
828 fprintf(log
,"Average NODE time: %g\n",ctsum
);
829 fprintf(log
,"Load imbalance reduced performance to %3d%% of max\n",
830 (int) (100.0*ctmax
/ctsum
));
834 print_ebin(fp_ene
,FALSE
,FALSE
,FALSE
,log
,step
,t
,
835 eprAVER
,FALSE
,mdebin
,fcd
,&(top
->atoms
));
836 print_ebin(fp_ene
,FALSE
,FALSE
,FALSE
,log
,step
,t
,
837 eprRMS
,FALSE
,mdebin
,fcd
,&(top
->atoms
));
839 if (!bRerunMD
&& parm
->ir
.nstxtcout
)
848 fprintf(log
,"Fraction of iterations that converged: %.2f %%\n",
849 (nconverged
*100.0)/(parm
->ir
.nsteps
+1));
850 fprintf(log
,"Average number of force evaluations per MD step: %.2f\n",
851 tcount
/(parm
->ir
.nsteps
+1));