4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-2001
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * Do check out http://www.gromacs.org , or mail us at gromacs@gromacs.org .
34 * Gromacs Runs On Most of All Computer Systems
36 static char *SRCID_glasmd_c = "$Id$";
75 time_t do_md(FILE *log,t_commrec *cr,int nfile,t_filenm fnm[],
76 bool bVerbose,bool bCompact,int stepout,
77 t_parm *parm,t_groups *grps,
78 t_topology *top,real ener[],
79 rvec x[],rvec vold[],rvec v[],rvec vt[],rvec f[],
80 rvec buf[],t_mdatoms *mdatoms,
81 t_nsborder *nsb,t_nrnb nrnb[],
89 real t,lambda,t0,lam0,SAfactor;
90 bool bNS,bStopCM,bTYZ,bLR,bBHAM,b14;
91 tensor force_vir,shake_vir;
94 char *xtc_traj; /* compressed trajectory filename */
100 t0 = parm->ir.init_t;
101 if (parm->ir.bPert) {
102 lam0 = parm->ir.init_lambda;
111 /* Check Environment variables */
112 bTYZ=getenv("TYZ") != NULL;
117 init_forcerec(log,fr,&(parm->ir),&(top->blocks[ebMOLS]),cr,
118 &(top->blocks[ebCGS]),&(top->idef),mdatoms,parm->box,FALSE);
119 for(m=0; (m<DIM); m++)
120 box_size[m]=parm->box[m][m];
121 calc_shifts(parm->box,box_size,fr->shift_vec,FALSE);
123 fprintf(log,"Removing pbc first time\n");
124 mk_mshift(log,graph,parm->box,x);
125 shift_self(graph,fr->shift_vec,x);
126 fprintf(log,"Done rmpbc\n");
128 traj=ftp2fn(efTRJ,nfile,fnm);
129 xtc_traj=ftp2fn(efXTC,nfile,fnm);
133 ene=ftp2FILE(efENE,nfile,fnm,"w");
138 bLR=(parm->ir.rlong > parm->ir.rshort);
139 bBHAM=(top->idef.functype[0]==F_BHAM);
140 b14=(top->idef.il[F_LJ14].nr > 0);
141 mdebin=init_mdebin(ene,grps,&(top->atoms),bLR,bBHAM,b14);
146 /* Set initial values for invmass etc. */
147 init_mdatoms(mdatoms,lambda,TRUE);
150 if (parm->ir.bShakeFirst)
151 do_shakefirst(log,bTYZ,lambda,ener,parm,nsb,mdatoms,x,vold,buf,f,v,
152 graph,cr,nrnb,grps,fr,top);
155 /* Compute initial EKin for all.. */
156 calc_ke_part(TRUE,0,top->atoms.nr,
157 vold,v,vt,&(parm->ir.opts),
158 mdatoms,grps,&mynrnb,
159 lambda,&ener[F_DVDLKIN]);
161 /* Calculate Temperature coupling parameters lambda */
162 ener[F_TEMP]=sum_ekin(&(parm->ir.opts),grps,parm->ekin,bTYZ);
163 tcoupl(parm->ir.btc,&(parm->ir.opts),grps,parm->ir.delta_t,SAfactor);
166 /* Write start time and temperature */
167 start_t=print_date_and_time(log,cr->pid,"Started mdrun");
169 fprintf(log,"Initial temperature: %g K\n",ener[F_TEMP]);
170 fprintf(stderr,"starting mdrun '%s'\n%d steps, %8.1f ps.\n\n",*(top->name),
171 parm->ir.nsteps,parm->ir.nsteps*parm->ir.delta_t);
173 /***********************************************************
177 ************************************************************/
178 for (step=0; (step<parm->ir.nsteps); step++) {
179 /* Stop Center of Mass motion */
180 bStopCM=do_per_step(step,parm->ir.nstcomm);
182 /* Determine whether or not to do Neighbour Searching */
183 bNS=((parm->ir.nstlist && ((step % parm->ir.nstlist)==0)) || (step==0));
185 /* Construct dummy particles */
186 construct_dummies(log,x,&mynrnb,parm->ir.delta_t,v,&top->idef);
188 /* Set values for invmass etc. */
189 init_mdatoms(mdatoms,lambda,FALSE);
191 /*init_forcerec(log,fr,&(parm->ir),&(top->blocks[ebMOLS]),cr,
192 &(top->blocks[ebCGS]),&(top->idef),mdatoms,parm->box,FALSE);
194 clear_mat(force_vir);
195 do_force(log,cr,parm,nsb,force_vir,step,&mynrnb,
196 top,grps,x,v,f,buf,mdatoms,ener,bVerbose && !PAR(cr),
197 lambda,graph,bNS,FALSE,fr);
199 do_glas(log,START(nsb),HOMENR(nsb),x,f,fr,mdatoms,top->idef.atnr,
202 /* Now we have the energies and forces corresponding to the
203 * coordinates at time t. We must output all of this before
206 t = t0 + step*parm->ir.delta_t;
208 lambda = lam0 + step*parm->ir.delta_lambda;
209 SAfactor = 1.0 - step*parm->ir.delta_t*parm->ir.cooling_rate;
211 /* Spread the force on dummy particle to the other particles... */
212 spread_dummy_f(log,x,f,&mynrnb,&top->idef);
214 if (do_per_step(step,parm->ir.nstxout)) xx=x; else xx=NULL;
215 if (do_per_step(step,parm->ir.nstvout)) vv=v; else vv=NULL;
216 if (do_per_step(step,parm->ir.nstfout)) ff=f; else ff=NULL;
217 write_traj(log,cr,traj,
218 nsb,step,t,lambda,nrnb,nsb->natoms,xx,vv,ff,parm->box);
221 if (do_per_step(step,parm->ir.nstxtcout)) {
222 write_xtc_traj(log,cr,xtc_traj,nsb,
223 step,t,nsb->natoms,x,parm->box,parm->ir.xtcprec);
228 clear_mat(shake_vir);
229 update(nsb->natoms,START(nsb),HOMENR(nsb),step,lambda,&ener[F_DVDL],
230 &(parm->ir),FALSE,mdatoms,x,graph,
231 fr->shift_vec,f,buf,vold,v,vt,parm->pres,parm->box,
232 top,grps,shake_vir,cr,&mynrnb,bTYZ,TRUE);
234 accumulate_u(cr,&(parm->ir.opts),grps);
237 /* Calculate partial Kinetic Energy (for this processor)
240 calc_ke_part(FALSE,START(nsb),HOMENR(nsb),
241 vold,v,vt,&(parm->ir.opts),
242 mdatoms,grps,&mynrnb,
243 lambda,&ener[F_DVDL]);
246 calc_vcm(log,HOMENR(nsb),START(nsb),mdatoms->massT,v,vcm);
249 global_stat(log,cr,ener,force_vir,shake_vir,
250 &(parm->ir.opts),grps,&mynrnb,nrnb,vcm);
252 for(i=0; (i<grps->estat.nn); i++)
253 grps->estat.ee[egLR][i] /= cr->nprocs;
256 cp_nrnb(&(nrnb[0]),&mynrnb);
259 check_cm(log,vcm,mdatoms->tmass);
260 do_stopcm(log,HOMENR(nsb),START(nsb),v,vcm,mdatoms->tmass);
261 inc_nrnb(&mynrnb,eNR_STOPCM,HOMENR(nsb));
264 /* Add force and shake contribution to the virial */
265 m_add(force_vir,shake_vir,parm->vir);
267 /* Sum the potential energy terms from group contributions */
268 sum_epot(&(parm->ir.opts),grps,ener);
270 /* Sum the kinetic energies of the groups & calc temp */
271 ener[F_TEMP]=sum_ekin(&(parm->ir.opts),grps,parm->ekin,bTYZ);
272 ener[F_EKIN]=trace(parm->ekin);
273 ener[F_ETOT]=ener[F_EPOT]+ener[F_EKIN];
275 /* Calculate Temperature coupling parameters lambda */
276 tcoupl(parm->ir.btc,&(parm->ir.opts),grps,parm->ir.delta_t,SAfactor);
278 /* Calculate pressure ! */
279 calc_pres(parm->box,parm->ekin,parm->vir,parm->pres);
281 /* Calculate long range corrections to pressure and energy */
282 calc_ljcorr(log,parm->ir.userint1,
283 fr,mdatoms->nr,parm->box,parm->pres,ener);
285 upd_mdebin(mdebin,mdatoms->tmass,step,ener,parm->box,shake_vir,
286 force_vir,parm->vir,parm->pres,grps);
289 if ((MASTER(cr) && do_per_step(step,parm->ir.nstprint))) {
290 print_ebin(ene,log,step,t,lambda,SAfactor,
291 eprNORMAL,bCompact,mdebin,grps,&(top->atoms));
296 if ((step % 10) == 0)
298 if (MASTER(cr) && bVerbose && ((step % stepout)==0))
299 print_time(stderr,start_t,step,&parm->ir);
302 if (parm->ir.nstprint > 1)
303 print_ebin(ene,log,step-1,t,lambda,SAfactor,
304 eprNORMAL,bCompact,mdebin,grps,&(top->atoms));
306 print_ebin(NULL,log,step,t,lambda,SAfactor,
307 eprAVER,FALSE,mdebin,grps,&(top->atoms));
308 print_ebin(NULL,log,step,t,lambda,SAfactor,
309 eprRMS,FALSE,mdebin,grps,&(top->atoms));
314 /* Construct dummy particles, for last output frame */
315 construct_dummies(log,x,&mynrnb,parm->ir.delta_t,v,&top->idef);
317 /*free_nslist(log);*/
322 int main(int argc,char *argv[])
324 static char *desc[] = {
325 "The mdrun program performs Molecular Dynamics simulations.",
326 "It reads the binary topology (.tpb) file and distributes the",
327 "topology over processors if needed. The coordinates are passed",
328 "around, so that computations can begin.",
329 "First a neighbourlist is made, then the forces are computed.",
330 "The forces are globally summed, and the velocities and",
331 "positions are updated. If necessary shake is performed to constrain",
332 "bond lengths and/or bond angles.",
333 "Temperature and Pressure can be controlled using weak coupling to a",
335 "A number of environment variables can be set to influence the behaviour",
336 "of the mdrun program. Most of these are for debugging purposes, but they",
337 "sometimes come in handy when porting the software to an",
338 "unsupported platform as well. These environment variables",
339 "are listed elsewhere in the manual.[PAR]",
340 "The mdrun produces three output file, plus one log file per processor.",
341 "The first file is the trajectory, containing coordinates, velocities",
342 "etc. The second file contains the coordinates and velocities at the end",
343 "of the run plus the computational box. The third file contains energies.",
344 "In the log file from processor 0 the energies, temperature, etc. are printed.[PAR]",
345 "When run on a parallel computer or with PVM on a cluster of workstations",
346 "the [BB]-np[bb] option must be given to indicate the number of",
347 "processors. Note that at current PVM does work, but it may launch",
348 "multiple processes on a single processor, which is not very sensible."
352 static t_filenm fnm[] = {
353 { efTPB, NULL, NULL, ffREAD },
354 { efTRJ, "-o", NULL, ffWRITE },
355 { efXTC, "-x", NULL, ffOPTWR },
356 { efGRO, "-c", "confout", ffWRITE },
357 { efENE, "-e", "ener", ffWRITE },
358 { efLOG, "-g", "md", ffWRITE },
360 #define NFILE asize(fnm)
362 /* Command line options ! */
363 static bool bVerbose=FALSE,bCompact=TRUE;
364 static int nprocs=1,nDLB=0,nstepout=10;
365 static t_pargs pa[] = {
366 { "-np", FALSE, etINT, &nprocs,
367 "Number of processors, must be the same as used for grompp. THIS SHOULD BE THE FIRST ARGUMENT ON THE COMMAND LINE FOR MPI" },
368 { "-v", FALSE, etBOOL,&bVerbose, "Verbose mode" },
369 { "-compact", FALSE, etBOOL,&bCompact,
370 "Write a compact log file, i.e. do not write full virial and energy group matrix (these are also in the energy file, so this is redundant) " },
371 { "-dlb", FALSE, etINT, &nDLB,
372 "Use dynamic load balancing every ... step. BUGGY do not use" },
373 { "-stepout", FALSE, etINT, &nstepout,
374 "Frequency of writing the remaining runtime" }
377 get_pargs(argc,argv,asize(pa),pa);
378 cr = init_par(nprocs,argv);
379 bVerbose = bVerbose && MASTER(cr);
382 CopyRight(stderr,argv[0]);
383 parse_common_args(&argc,argv,PCA_KEEP_ARGS,TRUE,
384 NFILE,fnm,0,NULL,asize(desc),desc,0,NULL);
385 print_pargs(stderr,asize(pa),pa);
387 open_log(ftp2fn(efLOG,NFILE,fnm),cr);
390 CopyRight(stdlog,argv[0]);
391 please_cite(stdlog,eCITEGMX);
394 mdrunner(cr,NFILE,fnm,bVerbose,bCompact,nDLB,FALSE,nstepout);