3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
11 * Copyright (c) 1991-1997
12 * BIOSON Research Institute, Dept. of Biophysical Chemistry
13 * University of Groningen, The Netherlands
16 * GROMACS: A message-passing parallel molecular dynamics implementation
17 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
18 * Comp. Phys. Comm. 91, 43-56 (1995)
20 * Also check out our WWW page:
21 * http://rugmd0.chem.rug.nl/~gmx
26 * GRoups of Organic Molecules in ACtion for Science
57 bool optRerunMDset (int nfile
, t_filenm fnm
[])
59 return opt2bSet("-rerun",nfile
,fnm
);
62 void get_cmparm(t_inputrec
*ir
,int step
,bool *bStopCM
,bool *bStopRot
)
64 if (ir
->nstcomm
== 0) {
67 } else if (ir
->nstcomm
> 0) {
68 *bStopCM
= do_per_step(step
,ir
->nstcomm
);
72 *bStopRot
= do_per_step(step
,-ir
->nstcomm
);
76 void set_pot_bools(t_inputrec
*ir
,t_topology
*top
,
77 bool *bLR
,bool *bLJLR
,bool *bBHAM
,bool *b14
)
79 *bLR
= (ir
->rcoulomb
> ir
->rlist
) || EEL_LR(ir
->coulombtype
);
80 *bLJLR
= (ir
->rvdw
> ir
->rlist
);
81 *bBHAM
= (top
->idef
.functype
[0]==F_BHAM
);
82 *b14
= (top
->idef
.il
[F_LJ14
].nr
> 0);
85 void finish_run(FILE *log
,t_commrec
*cr
,
91 double cputime
,double realtime
,int step
,
97 for(i
=0; (i
<eNRNB
); i
++)
99 for(i
=0; (i
<nsb
->nprocs
); i
++)
100 for(j
=0; (j
<eNRNB
); j
++)
101 ntot
.n
[j
]+=nrnb
[i
].n
[j
];
105 fprintf(stderr
,"\n\n");
106 print_perf(stderr
,cputime
,realtime
,&ntot
,nsb
->nprocs
);
109 print_nrnb(log
,&(nrnb
[nsb
->pid
]));
113 print_perf(log
,cputime
,realtime
,&ntot
,nsb
->nprocs
);
115 pr_load(log
,nsb
->nprocs
,nrnb
);
119 void mdrunner(t_commrec
*cr
,int nfile
,t_filenm fnm
[],bool bVerbose
,
120 bool bCompact
,int nDlb
,bool bNM
,int nstepout
,t_edsamyn
*edyn
)
122 double cputime
=0,realtime
;
124 rvec
*buf
,*f
,*vold
,*v
,*vt
,*x
,box_size
;
137 /* Initiate everything (snew sets to zero!) */
143 snew(nrnb
,cr
->nprocs
);
145 /* Initiate invsqrt routines */
146 init_lookup_table(stdlog
);
148 if (bVerbose
&& MASTER(cr
))
149 fprintf(stderr
,"Getting Loaded...\n");
152 /* The master processor reads from disk, then passes everything
153 * around the ring, and finally frees the stuff
156 distribute_parts(cr
->left
,cr
->right
,cr
->pid
,cr
->nprocs
,parm
,
157 ftp2fn(efTPX
,nfile
,fnm
),nDlb
);
159 /* Every processor (including the master) reads the data from the ring */
160 init_parts(stdlog
,cr
,
161 parm
,top
,&x
,&v
,&mdatoms
,nsb
,
162 MASTER(cr
) ? LIST_SCALARS
| LIST_PARM
: 0);
165 init_single(stdlog
,parm
,ftp2fn(efTPX
,nfile
,fnm
),top
,&x
,&v
,&mdatoms
,nsb
);
167 snew(buf
,nsb
->natoms
);
169 snew(vt
,nsb
->natoms
);
170 snew(vold
,nsb
->natoms
);
172 if (bVerbose
&& MASTER(cr
))
173 fprintf(stderr
,"Loaded with Money\n\n");
175 /* Index numbers for parallellism... */
177 top
->idef
.pid
= cr
->pid
;
179 /* Group stuff (energies etc) */
180 init_groups(stdlog
,mdatoms
,&(parm
->ir
.opts
),grps
);
182 /* Periodicity stuff */
183 graph
=mk_graph(&(top
->idef
),top
->atoms
.nr
,FALSE
);
185 p_graph(debug
,"Initial graph",graph
);
187 /* Distance Restraints */
188 init_disres(stdlog
,top
->idef
.il
[F_DISRES
].nr
,&(parm
->ir
));
190 /* check if there are dummies */
192 for(i
=0; (i
<F_NRE
) && !bDummies
; i
++)
193 bDummies
= ((interaction_function
[i
].flags
& IF_DUMMY
) &&
194 (top
->idef
.il
[i
].nr
> 0));
196 /* Initiate forcerecord */
198 init_forcerec(stdlog
,fr
,&(parm
->ir
),&(top
->blocks
[ebMOLS
]),cr
,
199 &(top
->blocks
[ebCGS
]),&(top
->idef
),mdatoms
,parm
->box
,FALSE
);
201 for(m
=0; (m
<DIM
); m
++)
202 box_size
[m
]=parm
->box
[m
][m
];
204 /* Initiate PPPM if necessary */
205 if (fr
->eeltype
== eelPPPM
)
206 init_pppm(stdlog
,cr
,nsb
,FALSE
,TRUE
,box_size
,ftp2fn(efHAT
,nfile
,fnm
),&parm
->ir
);
208 /* Now do whatever the user wants us to do (how flexible...) */
210 start_t
=do_nm(stdlog
,cr
,nfile
,fnm
,
211 bVerbose
,bCompact
,nstepout
,parm
,grps
,
212 top
,ener
,x
,vold
,v
,vt
,f
,buf
,
213 mdatoms
,nsb
,nrnb
,graph
,edyn
,fr
,box_size
);
216 switch (parm
->ir
.eI
) {
219 start_t
=do_md(stdlog
,cr
,nfile
,fnm
,
220 bVerbose
,bCompact
,bDummies
,nstepout
,parm
,grps
,
221 top
,ener
,x
,vold
,v
,vt
,f
,buf
,
222 mdatoms
,nsb
,nrnb
,graph
,edyn
,fr
,box_size
);
225 start_t
=do_cg(stdlog
,nfile
,fnm
,parm
,top
,grps
,nsb
,
226 x
,f
,buf
,mdatoms
,parm
->ekin
,ener
,
227 nrnb
,bVerbose
,bDummies
,cr
,graph
,fr
,box_size
);
230 start_t
=do_steep(stdlog
,nfile
,fnm
,parm
,top
,grps
,nsb
,
231 x
,f
,buf
,mdatoms
,parm
->ekin
,ener
,
232 nrnb
,bVerbose
,bDummies
,cr
,graph
,fr
,box_size
);
235 fatal_error(0,"Invalid integrator (%d)...\n",parm
->ir
.eI
);
238 /* Some timing stats */
240 print_time(stderr
,start_t
,parm
->ir
.nsteps
,&parm
->ir
);
241 realtime
=difftime(time(NULL
),start_t
);
242 if ((cputime
=cpu_time()) == 0)
248 md2atoms(mdatoms
,&(top
->atoms
),TRUE
);
250 /* Finish up, write some stuff */
252 const char *gro
=ftp2fn(efSTO
,nfile
,fnm
);
254 /* if rerunMD, don't write last frame again */
255 finish_run(stdlog
,cr
,gro
,nsb
,top
,parm
,
256 nrnb
,cputime
,realtime
,parm
->ir
.nsteps
,
257 (parm
->ir
.eI
==eiMD
) || (parm
->ir
.eI
==eiLD
));
261 /* Does what it says */
262 print_date_and_time(stdlog
,cr
->pid
,"Finished mdrun");
269 void init_md(t_commrec
*cr
,t_inputrec
*ir
,real
*t
,real
*t0
,
270 real
*lambda
,real
*lam0
,real
*SAfactor
,
271 t_nrnb
*mynrnb
,bool *bTYZ
,t_topology
*top
,
272 int nfile
,const t_filenm fnm
[],char **traj
,char **xtc_traj
,
273 ener_file_t
*fp_ene
, t_mdebin
**mdebin
,t_groups
*grps
,rvec vcm
,
274 tensor force_vir
,tensor shake_vir
,t_mdatoms
*mdatoms
)
276 bool bBHAM
,b14
,bLR
,bLJLR
;
279 *t
= *t0
= ir
->init_t
;
281 *lambda
= *lam0
= ir
->init_lambda
;
284 *lambda
= *lam0
= 0.0;
287 *SAfactor
= 1.0 - *t0
/ir
->zero_temp_time
;
295 /* Check Environment variables & other booleans */
296 *bTYZ
=getenv("TYZ") != NULL
;
297 set_pot_bools(ir
,top
,&bLR
,&bLJLR
,&bBHAM
,&b14
);
300 *traj
= ftp2fn(efTRN
,nfile
,fnm
);
301 *xtc_traj
= ftp2fn(efXTC
,nfile
,fnm
);
304 *fp_ene
= open_enx(ftp2fn(efENX
,nfile
,fnm
),"w");
305 *mdebin
= init_mdebin(*fp_ene
,grps
,&(top
->atoms
),&(top
->idef
),
306 bLR
,bLJLR
,bBHAM
,b14
,ir
->bPert
,ir
->epc
,
314 /* Initiate variables */
316 clear_mat(force_vir
);
317 clear_mat(shake_vir
);
319 /* Set initial values for invmass etc. */
320 init_mdatoms(mdatoms
,*lambda
,TRUE
);
325 void do_pbc_first(FILE *log
,t_parm
*parm
,rvec box_size
,t_forcerec
*fr
,
326 t_graph
*graph
,rvec x
[])
328 fprintf(log
,"Removing pbc first time\n");
329 calc_shifts(parm
->box
,box_size
,fr
->shift_vec
,FALSE
);
330 mk_mshift(log
,graph
,parm
->box
,x
);
331 shift_self(graph
,fr
->shift_vec
,x
);
332 fprintf(log
,"Done rmpbc\n");