3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
42 #include <sys/syscall.h>
57 #include "checkpoint.h"
82 #include "mpelogging.h"
90 #include "checkpoint.h"
91 #include "mtop_util.h"
94 #include "sighandler.h"
100 #ifdef GMX_THREAD_MPI
111 /* We use the same defines as in mvdata.c here */
112 #define block_bc(cr, d) gmx_bcast( sizeof(d), &(d),(cr))
113 #define nblock_bc(cr,nr,d) gmx_bcast((nr)*sizeof((d)[0]), (d),(cr))
114 #define snew_bc(cr,d,nr) { if (!MASTER(cr)) snew((d),(nr)); }
116 /* The following two variables and the signal_handler function
117 * is used from pme.c as well
146 int natoms; /*nr of atoms per lipid*/
147 int mol1; /*id of the first lipid molecule*/
168 int search_string(char *s,int ng,char ***gn)
172 for(i=0; (i<ng); i++)
173 if (gmx_strcasecmp(s,*gn[i]) == 0)
176 gmx_fatal(FARGS,"Group %s not found in indexfile.\nMaybe you have non-default groups in your mdp file, while not using the '-n' option of grompp.\nIn that case use the '-n' option.\n",s);
181 int get_mol_id(int at,int nmblock,gmx_molblock_t *mblock, int *type, int *block)
186 for(i=0;i<nmblock;i++)
188 if(at<(mblock[i].nmol*mblock[i].natoms_mol))
190 mol_id+=at/mblock[i].natoms_mol;
191 *type = mblock[i].type;
195 at-= mblock[i].nmol*mblock[i].natoms_mol;
196 mol_id+=mblock[i].nmol;
200 gmx_fatal(FARGS,"Something is wrong in mol ids, at %d, mol_id %d",at,mol_id);
205 int get_block(int mol_id,int nmblock,gmx_molblock_t *mblock)
210 for(i=0;i<nmblock;i++)
212 nmol+=mblock[i].nmol;
217 gmx_fatal(FARGS,"mol_id %d larger than total number of molecules %d.\n",mol_id,nmol);
222 int get_tpr_version(const char *infile)
229 fio = open_tpx(infile,"r");
230 gmx_fio_checktype(fio);
232 precision = sizeof(real);
234 gmx_fio_do_string(fio,buf);
235 if (strncmp(buf,"VERSION",7))
236 gmx_fatal(FARGS,"Can not read file %s,\n"
237 " this file is from a Gromacs version which is older than 2.0\n"
238 " Make a new one with grompp or use a gro or pdb file, if possible",
239 gmx_fio_getname(fio));
240 gmx_fio_do_int(fio,precision);
241 bDouble = (precision == sizeof(double));
242 if ((precision != sizeof(float)) && !bDouble)
243 gmx_fatal(FARGS,"Unknown precision in file %s: real is %d bytes "
244 "instead of %d or %d",
245 gmx_fio_getname(fio),precision,sizeof(float),sizeof(double));
246 gmx_fio_setprecision(fio,bDouble);
247 fprintf(stderr,"Reading file %s, %s (%s precision)\n",
248 gmx_fio_getname(fio),buf,bDouble ? "double" : "single");
250 gmx_fio_do_int(fio,fver);
257 void set_inbox(int natom, rvec *x)
262 tmp[XX]=tmp[YY]=tmp[ZZ]=0.0;
265 if(x[i][XX]<tmp[XX]) tmp[XX]=x[i][XX];
266 if(x[i][YY]<tmp[YY]) tmp[YY]=x[i][YY];
267 if(x[i][ZZ]<tmp[ZZ]) tmp[ZZ]=x[i][ZZ];
274 int get_mtype_list(t_block *at, gmx_mtop_t *mtop, t_block *tlist)
281 snew(tlist->index,at->nr);
282 for (i=0;i<at->nr;i++)
285 mol_id = get_mol_id(at->index[i],mtop->nmolblock,mtop->molblock,&type,&block);
288 if(tlist->index[j]==type)
293 tlist->index[nr]=type;
298 srenew(tlist->index,nr);
302 void check_types(t_block *ins_at,t_block *rest_at,gmx_mtop_t *mtop)
304 t_block *ins_mtype,*rest_mtype;
309 ins_mtype->nr = get_mtype_list(ins_at , mtop, ins_mtype );
310 rest_mtype->nr = get_mtype_list(rest_at, mtop, rest_mtype);
312 for(i=0;i<ins_mtype->nr;i++)
314 for(j=0;j<rest_mtype->nr;j++)
316 if(ins_mtype->index[i]==rest_mtype->index[j])
317 gmx_fatal(FARGS,"Moleculetype %s is found both in the group to insert and the rest of the system.\n"
318 "Because we need to exclude all interactions between the atoms in the group to\n"
319 "insert, the same moleculetype can not be used in both groups. Change the\n"
320 "moleculetype of the molecules %s in the inserted group. Do not forget to provide\n"
321 "an appropriate *.itp file",*(mtop->moltype[rest_mtype->index[j]].name),
322 *(mtop->moltype[rest_mtype->index[j]].name));
326 sfree(ins_mtype->index);
327 sfree(rest_mtype->index);
332 int init_ins_at(t_block *ins_at,t_block *rest_at,t_state *state, pos_ins_t *pos_ins,gmx_groups_t *groups,int ins_grp_id, real xy_max)
335 real x,xmin,xmax,y,ymin,ymax,z,zmin,zmax;
337 snew(rest_at->index,state->natoms);
339 xmin=xmax=state->x[ins_at->index[0]][XX];
340 ymin=ymax=state->x[ins_at->index[0]][YY];
341 zmin=zmax=state->x[ins_at->index[0]][ZZ];
343 for(i=0;i<state->natoms;i++)
345 gid = groups->grpnr[egcFREEZE][i];
346 if(groups->grps[egcFREEZE].nm_ind[gid]==ins_grp_id)
364 srenew(rest_at->index,c);
368 pos_ins->xmin[XX]=xmin-((xmax-xmin)*xy_max-(xmax-xmin))/2;
369 pos_ins->xmin[YY]=ymin-((ymax-ymin)*xy_max-(ymax-ymin))/2;
371 pos_ins->xmax[XX]=xmax+((xmax-xmin)*xy_max-(xmax-xmin))/2;
372 pos_ins->xmax[YY]=ymax+((ymax-ymin)*xy_max-(ymax-ymin))/2;
374 pos_ins->xmin[XX]=xmin;
375 pos_ins->xmin[YY]=ymin;
377 pos_ins->xmax[XX]=xmax;
378 pos_ins->xmax[YY]=ymax;
381 /* 6.0 is estimated thickness of bilayer */
382 if( (zmax-zmin) < 6.0 )
384 pos_ins->xmin[ZZ]=zmin+(zmax-zmin)/2.0-3.0;
385 pos_ins->xmax[ZZ]=zmin+(zmax-zmin)/2.0+3.0;
387 pos_ins->xmin[ZZ]=zmin;
388 pos_ins->xmax[ZZ]=zmax;
394 real est_prot_area(pos_ins_t *pos_ins,rvec *r,t_block *ins_at, mem_t *mem_p)
396 real x,y,dx=0.15,dy=0.15,area=0.0;
400 for(x=pos_ins->xmin[XX];x<pos_ins->xmax[XX];x+=dx)
402 for(y=pos_ins->xmin[YY];y<pos_ins->xmax[YY];y+=dy)
409 if ( (r[at][XX]>=x) && (r[at][XX]<x+dx) &&
410 (r[at][YY]>=y) && (r[at][YY]<y+dy) &&
411 (r[at][ZZ]>mem_p->zmin+1.0) && (r[at][ZZ]<mem_p->zmax-1.0) )
414 } while ( (c<ins_at->nr) && (add<0.5) );
423 void init_lip(matrix box, gmx_mtop_t *mtop, lip_t *lip)
429 mem_area = box[XX][XX]*box[YY][YY]-box[XX][YY]*box[YY][XX];
430 for(i=0;i<mtop->nmolblock;i++)
432 if(mtop->molblock[i].type == lip->id)
434 lip->nr=mtop->molblock[i].nmol;
435 lip->natoms=mtop->molblock[i].natoms_mol;
438 lip->area=2.0*mem_area/(double)lip->nr;
440 for (i=0;i<lip->id;i++)
441 mol1+=mtop->molblock[i].nmol;
445 int init_mem_at(mem_t *mem_p, gmx_mtop_t *mtop, rvec *r, matrix box, pos_ins_t *pos_ins)
447 int i,j,at,mol,nmol,nmolbox,count;
449 real z,zmin,zmax,mem_area;
455 mem_a=&(mem_p->mem_at);
456 snew(mol_id,mem_a->nr);
457 /* snew(index,mem_a->nr); */
458 zmin=pos_ins->xmax[ZZ];
459 zmax=pos_ins->xmin[ZZ];
460 for(i=0;i<mem_a->nr;i++)
463 if( (r[at][XX]>pos_ins->xmin[XX]) && (r[at][XX]<pos_ins->xmax[XX]) &&
464 (r[at][YY]>pos_ins->xmin[YY]) && (r[at][YY]<pos_ins->xmax[YY]) &&
465 (r[at][ZZ]>pos_ins->xmin[ZZ]) && (r[at][ZZ]<pos_ins->xmax[ZZ]) )
467 mol = get_mol_id(at,mtop->nmolblock,mtop->molblock,&type,&block);
484 /* index[count]=at;*/
491 mem_p->mol_id=mol_id;
492 /* srenew(index,count);*/
493 /* mem_p->mem_at.nr=count;*/
494 /* sfree(mem_p->mem_at.index);*/
495 /* mem_p->mem_at.index=index;*/
497 if((zmax-zmin)>(box[ZZ][ZZ]-0.5))
498 gmx_fatal(FARGS,"Something is wrong with your membrane. Max and min z values are %f and %f.\n"
499 "Maybe your membrane is not centered in the box, but located at the box edge in the z-direction,\n"
500 "so that one membrane is distributed over two periodic box images. Another possibility is that\n"
501 "your water layer is not thick enough.\n",zmax,zmin);
504 mem_p->zmed=(zmax-zmin)/2+zmin;
506 /*number of membrane molecules in protein box*/
507 nmolbox = count/mtop->molblock[block].natoms_mol;
508 /*mem_area = box[XX][XX]*box[YY][YY]-box[XX][YY]*box[YY][XX];
509 mem_p->lip_area = 2.0*mem_area/(double)mem_p->nmol;*/
510 mem_area = (pos_ins->xmax[XX]-pos_ins->xmin[XX])*(pos_ins->xmax[YY]-pos_ins->xmin[YY]);
511 mem_p->lip_area = 2.0*mem_area/(double)nmolbox;
513 return mem_p->mem_at.nr;
516 void init_resize(t_block *ins_at,rvec *r_ins,pos_ins_t *pos_ins,mem_t *mem_p,rvec *r, gmx_bool bALLOW_ASYMMETRY)
518 int i,j,at,c,outsidesum,gctr=0;
522 for (i=0;i<pos_ins->pieces;i++)
523 idxsum+=pos_ins->nidx[i];
524 if (idxsum!=ins_at->nr)
525 gmx_fatal(FARGS,"Piecewise sum of inserted atoms not same as size of group selected to insert.");
527 snew(pos_ins->geom_cent,pos_ins->pieces);
528 for (i=0;i<pos_ins->pieces;i++)
533 pos_ins->geom_cent[i][j]=0;
536 pos_ins->geom_cent[i][j]=0;
537 for (j=0;j<pos_ins->nidx[i];j++)
539 at=pos_ins->subindex[i][j];
540 copy_rvec(r[at],r_ins[gctr]);
541 if( (r_ins[gctr][ZZ]<mem_p->zmax) && (r_ins[gctr][ZZ]>mem_p->zmin) )
543 rvec_inc(pos_ins->geom_cent[i],r_ins[gctr]);
551 svmul(1/(double)c,pos_ins->geom_cent[i],pos_ins->geom_cent[i]);
552 if (!bALLOW_ASYMMETRY)
553 pos_ins->geom_cent[i][ZZ]=mem_p->zmed;
555 fprintf(stderr,"Embedding piece %d with center of geometry: %f %f %f\n",i,pos_ins->geom_cent[i][XX],pos_ins->geom_cent[i][YY],pos_ins->geom_cent[i][ZZ]);
557 fprintf(stderr,"\n");
560 void resize(t_block *ins_at, rvec *r_ins, rvec *r, pos_ins_t *pos_ins,rvec fac)
563 for (k=0;k<pos_ins->pieces;k++)
564 for(i=0;i<pos_ins->nidx[k];i++)
566 at=pos_ins->subindex[k][i];
568 r[at][j]=pos_ins->geom_cent[k][j]+fac[j]*(r_ins[c][j]-pos_ins->geom_cent[k][j]);
573 int gen_rm_list(rmm_t *rm_p,t_block *ins_at,t_block *rest_at,t_pbc *pbc, gmx_mtop_t *mtop,
574 rvec *r, rvec *r_ins, mem_t *mem_p, pos_ins_t *pos_ins, real probe_rad, int low_up_rm, gmx_bool bALLOW_ASYMMETRY)
576 int i,j,k,l,at,at2,mol_id;
578 int nrm,nupper,nlower;
579 real r_min_rad,z_lip,min_norm;
585 r_min_rad=probe_rad*probe_rad;
586 snew(rm_p->mol,mtop->mols.nr);
587 snew(rm_p->block,mtop->mols.nr);
590 for(i=0;i<ins_at->nr;i++)
593 for(j=0;j<rest_at->nr;j++)
595 at2=rest_at->index[j];
596 pbc_dx(pbc,r[at],r[at2],dr);
598 if(norm2(dr)<r_min_rad)
600 mol_id = get_mol_id(at2,mtop->nmolblock,mtop->molblock,&type,&block);
603 if(rm_p->mol[l]==mol_id)
607 /*fprintf(stderr,"%d wordt toegevoegd\n",mol_id);*/
608 rm_p->mol[nrm]=mol_id;
609 rm_p->block[nrm]=block;
612 for(l=0;l<mem_p->nmol;l++)
614 if(mol_id==mem_p->mol_id[l])
616 for(k=mtop->mols.index[mol_id];k<mtop->mols.index[mol_id+1];k++)
618 z_lip/=mtop->molblock[block].natoms_mol;
619 if(z_lip<mem_p->zmed)
630 /*make sure equal number of lipids from upper and lower layer are removed */
631 if( (nupper!=nlower) && (!bALLOW_ASYMMETRY) )
633 snew(dist,mem_p->nmol);
634 snew(order,mem_p->nmol);
635 for(i=0;i<mem_p->nmol;i++)
637 at = mtop->mols.index[mem_p->mol_id[i]];
638 pbc_dx(pbc,r[at],pos_ins->geom_cent[0],dr);
639 if (pos_ins->pieces>1)
643 for (k=1;k<pos_ins->pieces;k++)
645 pbc_dx(pbc,r[at],pos_ins->geom_cent[k],dr_tmp);
646 if (norm2(dr_tmp) < min_norm)
648 min_norm=norm2(dr_tmp);
649 copy_rvec(dr_tmp,dr);
653 dist[i]=dr[XX]*dr[XX]+dr[YY]*dr[YY];
655 while (j>=0 && dist[i]<dist[order[j]])
664 while(nupper!=nlower)
666 mol_id=mem_p->mol_id[order[i]];
667 block=get_block(mol_id,mtop->nmolblock,mtop->molblock);
671 if(rm_p->mol[l]==mol_id)
676 for(k=mtop->mols.index[mol_id];k<mtop->mols.index[mol_id+1];k++)
678 z_lip/=mtop->molblock[block].natoms_mol;
679 if(nupper>nlower && z_lip<mem_p->zmed)
681 rm_p->mol[nrm]=mol_id;
682 rm_p->block[nrm]=block;
686 else if (nupper<nlower && z_lip>mem_p->zmed)
688 rm_p->mol[nrm]=mol_id;
689 rm_p->block[nrm]=block;
697 gmx_fatal(FARGS,"Trying to remove more lipid molecules than there are in the membrane");
704 srenew(rm_p->mol,nrm);
705 srenew(rm_p->block,nrm);
707 return nupper+nlower;
710 void rm_group(t_inputrec *ir, gmx_groups_t *groups, gmx_mtop_t *mtop, rmm_t *rm_p, t_state *state, t_block *ins_at, pos_ins_t *pos_ins)
712 int i,j,k,n,rm,mol_id,at,block;
714 atom_id *list,*new_mols;
715 unsigned char *new_egrp[egcNR];
718 snew(list,state->natoms);
720 for(i=0;i<rm_p->nr;i++)
723 at=mtop->mols.index[mol_id];
724 block =rm_p->block[i];
725 mtop->molblock[block].nmol--;
726 for(j=0;j<mtop->molblock[block].natoms_mol;j++)
732 mtop->mols.index[mol_id]=-1;
735 mtop->mols.nr-=rm_p->nr;
736 mtop->mols.nalloc_index-=rm_p->nr;
737 snew(new_mols,mtop->mols.nr);
738 for(i=0;i<mtop->mols.nr+rm_p->nr;i++)
741 if(mtop->mols.index[i]!=-1)
743 new_mols[j]=mtop->mols.index[i];
747 sfree(mtop->mols.index);
748 mtop->mols.index=new_mols;
753 state->nalloc=state->natoms;
754 snew(x_tmp,state->nalloc);
755 snew(v_tmp,state->nalloc);
759 if(groups->grpnr[i]!=NULL)
761 groups->ngrpnr[i]=state->natoms;
762 snew(new_egrp[i],state->natoms);
767 for (i=0;i<state->natoms+n;i++)
783 if(groups->grpnr[j]!=NULL)
785 new_egrp[j][i-rm]=groups->grpnr[j][i];
788 copy_rvec(state->x[i],x_tmp[i-rm]);
789 copy_rvec(state->v[i],v_tmp[i-rm]);
790 for(j=0;j<ins_at->nr;j++)
792 if (i==ins_at->index[j])
793 ins_at->index[j]=i-rm;
795 for(j=0;j<pos_ins->pieces;j++)
797 for(k=0;k<pos_ins->nidx[j];k++)
799 if (i==pos_ins->subindex[j][k])
800 pos_ins->subindex[j][k]=i-rm;
812 if(groups->grpnr[i]!=NULL)
814 sfree(groups->grpnr[i]);
815 groups->grpnr[i]=new_egrp[i];
820 int rm_bonded(t_block *ins_at, gmx_mtop_t *mtop)
823 int type,natom,nmol,at,atom1=0,rm_at=0;
825 /*this routine lives dangerously by assuming that all molecules of a given type are in order in the structure*/
826 /*this routine does not live as dangerously as it seems. There is namely a check in mdrunner_membed to make
827 *sure that g_membed exits with a warning when there are molecules of the same type not in the
828 *ins_at index group. MGWolf 050710 */
831 snew(bRM,mtop->nmoltype);
832 for (i=0;i<mtop->nmoltype;i++)
837 for (i=0;i<mtop->nmolblock;i++)
839 /*loop over molecule blocks*/
840 type =mtop->molblock[i].type;
841 natom =mtop->molblock[i].natoms_mol;
842 nmol =mtop->molblock[i].nmol;
844 for(j=0;j<natom*nmol && bRM[type]==TRUE;j++)
846 /*loop over atoms in the block*/
847 at=j+atom1; /*atom index = block index + offset*/
850 for (m=0;(m<ins_at->nr) && (bINS==FALSE);m++)
852 /*loop over atoms in insertion index group to determine if we're inserting one*/
853 if(at==ins_at->index[m])
860 atom1+=natom*nmol; /*update offset*/
863 rm_at+=natom*nmol; /*increment bonded removal counter by # atoms in block*/
867 for(i=0;i<mtop->nmoltype;i++)
873 mtop->moltype[i].ilist[j].nr=0;
875 for(j=F_POSRES;j<=F_VSITEN;j++)
877 mtop->moltype[i].ilist[j].nr=0;
886 void top_update(const char *topfile, char *ins, rmm_t *rm_p, gmx_mtop_t *mtop)
888 #define TEMP_FILENM "temp.top"
891 char buf[STRLEN],buf2[STRLEN],*temp;
892 int i,*nmol_rm,nmol,line;
894 fpin = ffopen(topfile,"r");
895 fpout = ffopen(TEMP_FILENM,"w");
897 snew(nmol_rm,mtop->nmoltype);
898 for(i=0;i<rm_p->nr;i++)
899 nmol_rm[rm_p->block[i]]++;
902 while(fgets(buf,STRLEN,fpin))
908 if ((temp=strchr(buf2,'\n')) != NULL)
915 if ((temp=strchr(buf2,'\n')) != NULL)
918 if (buf2[strlen(buf2)-1]==']')
920 buf2[strlen(buf2)-1]='\0';
923 if (gmx_strcasecmp(buf2,"molecules")==0)
926 fprintf(fpout,"%s",buf);
927 } else if (bMolecules==1)
929 for(i=0;i<mtop->nmolblock;i++)
931 nmol=mtop->molblock[i].nmol;
932 sprintf(buf,"%-15s %5d\n",*(mtop->moltype[mtop->molblock[i].type].name),nmol);
933 fprintf(fpout,"%s",buf);
936 } else if (bMolecules==2)
941 fprintf(fpout,"%s",buf);
945 fprintf(fpout,"%s",buf);
950 /* use ffopen to generate backup of topinout */
951 fpout=ffopen(topfile,"w");
953 rename(TEMP_FILENM,topfile);
957 double do_md_membed(FILE *fplog,t_commrec *cr,int nfile,const t_filenm fnm[],
958 const output_env_t oenv, gmx_bool bVerbose,gmx_bool bCompact,
960 gmx_vsite_t *vsite,gmx_constr_t constr,
961 int stepout,t_inputrec *ir,
962 gmx_mtop_t *top_global,
964 t_state *state_global,
966 t_nrnb *nrnb,gmx_wallcycle_t wcycle,
967 gmx_edsam_t ed,t_forcerec *fr,
968 int repl_ex_nst,int repl_ex_seed,
969 real cpt_period,real max_hours,
970 const char *deviceOptions,
972 gmx_runtime_t *runtime,
973 rvec fac, rvec *r_ins, pos_ins_t *pos_ins, t_block *ins_at,
974 real xy_step, real z_step, int it_xy, int it_z)
977 gmx_large_int_t step,step_rel;
980 gmx_bool bGStatEveryStep,bGStat,bNstEner,bCalcEnerPres;
981 gmx_bool bNS,bNStList,bSimAnn,bStopCM,bRerunMD,bNotLastFrame=FALSE,
982 bFirstStep,bStateFromTPX,bInitStep,bLastStep,
983 bBornRadii,bStartingFromCpt;
984 gmx_bool bDoDHDL=FALSE;
985 gmx_bool do_ene,do_log,do_verbose,bRerunWarnNoV=TRUE,
986 bForceUpdate=FALSE,bCPT;
988 gmx_bool bMasterState;
989 int force_flags,cglo_flags;
990 tensor force_vir,shake_vir,total_vir,tmp_vir,pres;
995 t_state *bufstate=NULL;
996 matrix *scale_tot,pcoupl_mu,M,ebox;
999 /* gmx_repl_ex_t repl_ex=NULL;*/
1002 gmx_localtop_t *top;
1003 t_mdebin *mdebin=NULL;
1004 t_state *state=NULL;
1005 rvec *f_global=NULL;
1008 gmx_enerdata_t *enerd;
1010 gmx_global_stat_t gstat;
1011 gmx_update_t upd=NULL;
1012 t_graph *graph=NULL;
1016 gmx_groups_t *groups;
1017 gmx_ekindata_t *ekind, *ekind_save;
1018 gmx_shellfc_t shellfc;
1019 int count,nconverged=0;
1022 gmx_bool bIonize=FALSE;
1023 gmx_bool bTCR=FALSE,bConverged=TRUE,bOK,bSumEkinhOld,bExchanged;
1025 gmx_bool bResetCountersHalfMaxH=FALSE;
1026 gmx_bool bVV,bIterations,bIterate,bFirstIterate,bTemp,bPres,bTrotter;
1029 rvec *xcopy=NULL,*vcopy=NULL,*cbuf=NULL;
1030 matrix boxcopy={{0}},lastbox;
1031 real veta_save,pcurr,scalevir,tracevir;
1034 real last_conserved = 0;
1038 char sbuf[STEPSTRSIZE],sbuf2[STEPSTRSIZE];
1039 int handled_stop_condition=gmx_stop_cond_none; /* compare to get_stop_condition*/
1040 gmx_iterate_t iterate;
1042 /* Temporary addition for FAHCORE checkpointing */
1046 /* Check for special mdrun options */
1047 bRerunMD = (Flags & MD_RERUN);
1048 bIonize = (Flags & MD_IONIZE);
1049 bFFscan = (Flags & MD_FFSCAN);
1050 bAppend = (Flags & MD_APPENDFILES);
1051 bGStatEveryStep = FALSE;
1052 if (Flags & MD_RESETCOUNTERSHALFWAY)
1056 /* Signal to reset the counters half the simulation steps. */
1057 wcycle_set_reset_counters(wcycle,ir->nsteps/2);
1059 /* Signal to reset the counters halfway the simulation time. */
1060 bResetCountersHalfMaxH = (max_hours > 0);
1063 /* md-vv uses averaged full step velocities for T-control
1064 md-vv-avek uses averaged half step velocities for T-control (but full step ekin for P control)
1065 md uses averaged half step kinetic energies to determine temperature unless defined otherwise by GMX_EKIN_AVE_VEL; */
1066 bVV = EI_VV(ir->eI);
1067 if (bVV) /* to store the initial velocities while computing virial */
1069 snew(cbuf,top_global->natoms);
1071 /* all the iteratative cases - only if there are constraints */
1072 bIterations = ((IR_NPT_TROTTER(ir)) && (constr) && (!bRerunMD));
1073 bTrotter = (bVV && (IR_NPT_TROTTER(ir) || (IR_NVT_TROTTER(ir))));
1077 /* Since we don't know if the frames read are related in any way,
1078 * rebuild the neighborlist at every step.
1081 ir->nstcalcenergy = 1;
1085 check_ir_old_tpx_versions(cr,fplog,ir,top_global);
1087 nstglobalcomm = check_nstglobalcomm(fplog,cr,nstglobalcomm,ir);
1088 /*bGStatEveryStep = (nstglobalcomm == 1);*/
1089 bGStatEveryStep = FALSE;
1091 if (!bGStatEveryStep && ir->nstlist == -1 && fplog != NULL)
1094 "To reduce the energy communication with nstlist = -1\n"
1095 "the neighbor list validity should not be checked at every step,\n"
1096 "this means that exact integration is not guaranteed.\n"
1097 "The neighbor list validity is checked after:\n"
1098 " <n.list life time> - 2*std.dev.(n.list life time) steps.\n"
1099 "In most cases this will result in exact integration.\n"
1100 "This reduces the energy communication by a factor of 2 to 3.\n"
1101 "If you want less energy communication, set nstlist > 3.\n\n");
1104 if (bRerunMD || bFFscan)
1108 groups = &top_global->groups;
1110 /* Initial values */
1111 init_md(fplog,cr,ir,oenv,&t,&t0,&state_global->lambda,&lam0,
1112 nrnb,top_global,&upd,
1113 nfile,fnm,&outf,&mdebin,
1114 force_vir,shake_vir,mu_tot,&bSimAnn,&vcm,state_global,Flags);
1116 clear_mat(total_vir);
1118 /* Energy terms and groups */
1120 init_enerdata(top_global->groups.grps[egcENER].nr,ir->n_flambda,enerd);
1121 if (DOMAINDECOMP(cr))
1127 snew(f,top_global->natoms);
1130 /* Kinetic energy data */
1132 init_ekindata(fplog,top_global,&(ir->opts),ekind);
1133 /* needed for iteration of constraints */
1135 init_ekindata(fplog,top_global,&(ir->opts),ekind_save);
1136 /* Copy the cos acceleration to the groups struct */
1137 ekind->cosacc.cos_accel = ir->cos_accel;
1139 gstat = global_stat_init(ir);
1142 /* Check for polarizable models and flexible constraints */
1143 shellfc = init_shell_flexcon(fplog,
1144 top_global,n_flexible_constraints(constr),
1145 (ir->bContinuation ||
1146 (DOMAINDECOMP(cr) && !MASTER(cr))) ?
1147 NULL : state_global->x);
1151 #ifdef GMX_THREAD_MPI
1152 tMPI_Thread_mutex_lock(&deform_init_box_mutex);
1154 set_deform_reference_box(upd,
1155 deform_init_init_step_tpx,
1156 deform_init_box_tpx);
1157 #ifdef GMX_THREAD_MPI
1158 tMPI_Thread_mutex_unlock(&deform_init_box_mutex);
1163 double io = compute_io(ir,top_global->natoms,groups,mdebin->ebin->nener,1);
1164 if ((io > 2000) && MASTER(cr))
1166 "\nWARNING: This run will generate roughly %.0f Mb of data\n\n",
1170 if (DOMAINDECOMP(cr)) {
1171 top = dd_init_local_top(top_global);
1174 dd_init_local_state(cr->dd,state_global,state);
1176 if (DDMASTER(cr->dd) && ir->nstfout) {
1177 snew(f_global,state_global->natoms);
1181 /* Initialize the particle decomposition and split the topology */
1182 top = split_system(fplog,top_global,ir,cr);
1184 pd_cg_range(cr,&fr->cg0,&fr->hcg);
1185 pd_at_range(cr,&a0,&a1);
1187 top = gmx_mtop_generate_local_top(top_global,ir);
1190 a1 = top_global->natoms;
1193 state = partdec_init_local_state(cr,state_global);
1196 atoms2md(top_global,ir,0,NULL,a0,a1-a0,mdatoms);
1199 set_vsite_top(vsite,top,mdatoms,cr);
1202 if (ir->ePBC != epbcNONE && !ir->bPeriodicMols) {
1203 graph = mk_graph(fplog,&(top->idef),0,top_global->natoms,FALSE,FALSE);
1207 make_local_shells(cr,mdatoms,shellfc);
1210 if (ir->pull && PAR(cr)) {
1211 dd_make_local_pull_groups(NULL,ir->pull,mdatoms);
1215 if (DOMAINDECOMP(cr))
1217 /* Distribute the charge groups over the nodes from the master node */
1218 dd_partition_system(fplog,ir->init_step,cr,TRUE,1,
1219 state_global,top_global,ir,
1220 state,&f,mdatoms,top,fr,
1221 vsite,shellfc,constr,
1225 update_mdatoms(mdatoms,state->lambda);
1229 if (opt2bSet("-cpi",nfile,fnm))
1231 /* Update mdebin with energy history if appending to output files */
1232 if ( Flags & MD_APPENDFILES )
1234 restore_energyhistory_from_state(mdebin,&state_global->enerhist);
1238 /* We might have read an energy history from checkpoint,
1239 * free the allocated memory and reset the counts.
1241 done_energyhistory(&state_global->enerhist);
1242 init_energyhistory(&state_global->enerhist);
1245 /* Set the initial energy history in state by updating once */
1246 update_energyhistory(&state_global->enerhist,mdebin);
1249 if ((state->flags & (1<<estLD_RNG)) && (Flags & MD_READ_RNG)) {
1250 /* Set the random state if we read a checkpoint file */
1251 set_stochd_state(upd,state);
1254 /* Initialize constraints */
1256 if (!DOMAINDECOMP(cr))
1257 set_constraints(constr,top,ir,mdatoms,cr);
1260 /* Check whether we have to GCT stuff */
1261 /* bTCR = ftp2bSet(efGCT,nfile,fnm);
1264 fprintf(stderr,"Will do General Coupling Theory!\n");
1266 gnx = top_global->mols.nr;
1268 for(i=0; (i<gnx); i++) {
1273 /* if (repl_ex_nst > 0 && MASTER(cr))
1274 repl_ex = init_replica_exchange(fplog,cr->ms,state_global,ir,
1275 repl_ex_nst,repl_ex_seed);*/
1277 if (!ir->bContinuation && !bRerunMD)
1279 if (mdatoms->cFREEZE && (state->flags & (1<<estV)))
1281 /* Set the velocities of frozen particles to zero */
1282 for(i=mdatoms->start; i<mdatoms->start+mdatoms->homenr; i++)
1284 for(m=0; m<DIM; m++)
1286 if (ir->opts.nFreeze[mdatoms->cFREEZE[i]][m])
1296 /* Constrain the initial coordinates and velocities */
1297 do_constrain_first(fplog,constr,ir,mdatoms,state,f,
1298 graph,cr,nrnb,fr,top,shake_vir);
1302 /* Construct the virtual sites for the initial configuration */
1303 construct_vsites(fplog,vsite,state->x,nrnb,ir->delta_t,NULL,
1304 top->idef.iparams,top->idef.il,
1305 fr->ePBC,fr->bMolPBC,graph,cr,state->box);
1311 /* I'm assuming we need global communication the first time! MRS */
1312 cglo_flags = (CGLO_TEMPERATURE | CGLO_GSTAT
1313 | (bVV ? CGLO_PRESSURE:0)
1314 | (bVV ? CGLO_CONSTRAINT:0)
1315 | (bRerunMD ? CGLO_RERUNMD:0)
1316 | ((Flags & MD_READ_EKIN) ? CGLO_READEKIN:0));
1318 bSumEkinhOld = FALSE;
1319 compute_globals(fplog,gstat,cr,ir,fr,ekind,state,state_global,mdatoms,nrnb,vcm,
1320 wcycle,enerd,force_vir,shake_vir,total_vir,pres,mu_tot,
1321 constr,NULL,FALSE,state->box,
1322 top_global,&pcurr,top_global->natoms,&bSumEkinhOld,cglo_flags);
1323 if (ir->eI == eiVVAK) {
1324 /* a second call to get the half step temperature initialized as well */
1325 /* we do the same call as above, but turn the pressure off -- internally, this
1326 is recognized as a velocity verlet half-step kinetic energy calculation.
1327 This minimized excess variables, but perhaps loses some logic?*/
1329 compute_globals(fplog,gstat,cr,ir,fr,ekind,state,state_global,mdatoms,nrnb,vcm,
1330 wcycle,enerd,force_vir,shake_vir,total_vir,pres,mu_tot,
1331 constr,NULL,FALSE,state->box,
1332 top_global,&pcurr,top_global->natoms,&bSumEkinhOld,
1333 cglo_flags &~ CGLO_PRESSURE);
1336 /* Calculate the initial half step temperature, and save the ekinh_old */
1337 if (!(Flags & MD_STARTFROMCPT))
1339 for(i=0; (i<ir->opts.ngtc); i++)
1341 copy_mat(ekind->tcstat[i].ekinh,ekind->tcstat[i].ekinh_old);
1346 enerd->term[F_TEMP] *= 2; /* result of averages being done over previous and current step,
1347 and there is no previous step */
1349 temp0 = enerd->term[F_TEMP];
1351 /* if using an iterative algorithm, we need to create a working directory for the state. */
1354 bufstate = init_bufstate(state);
1358 snew(xcopy,state->natoms);
1359 snew(vcopy,state->natoms);
1360 copy_rvecn(state->x,xcopy,0,state->natoms);
1361 copy_rvecn(state->v,vcopy,0,state->natoms);
1362 copy_mat(state->box,boxcopy);
1365 /* need to make an initiation call to get the Trotter variables set, as well as other constants for non-trotter
1366 temperature control */
1367 trotter_seq = init_npt_vars(ir,state,&MassQ,bTrotter);
1371 if (constr && !ir->bContinuation && ir->eConstrAlg == econtLINCS)
1374 "RMS relative constraint deviation after constraining: %.2e\n",
1375 constr_rmsd(constr,FALSE));
1377 fprintf(fplog,"Initial temperature: %g K\n",enerd->term[F_TEMP]);
1380 fprintf(stderr,"starting md rerun '%s', reading coordinates from"
1381 " input trajectory '%s'\n\n",
1382 *(top_global->name),opt2fn("-rerun",nfile,fnm));
1385 fprintf(stderr,"Calculated time to finish depends on nsteps from "
1386 "run input file,\nwhich may not correspond to the time "
1387 "needed to process input trajectory.\n\n");
1393 fprintf(stderr,"starting mdrun '%s'\n",
1394 *(top_global->name));
1395 if (ir->nsteps >= 0)
1397 sprintf(tbuf,"%8.1f",(ir->init_step+ir->nsteps)*ir->delta_t);
1401 sprintf(tbuf,"%s","infinite");
1403 if (ir->init_step > 0)
1405 fprintf(stderr,"%s steps, %s ps (continuing from step %s, %8.1f ps).\n",
1406 gmx_step_str(ir->init_step+ir->nsteps,sbuf),tbuf,
1407 gmx_step_str(ir->init_step,sbuf2),
1408 ir->init_step*ir->delta_t);
1412 fprintf(stderr,"%s steps, %s ps.\n",
1413 gmx_step_str(ir->nsteps,sbuf),tbuf);
1416 fprintf(fplog,"\n");
1419 /* Set and write start time */
1420 runtime_start(runtime);
1421 print_date_and_time(fplog,cr->nodeid,"Started mdrun",runtime);
1422 wallcycle_start(wcycle,ewcRUN);
1424 fprintf(fplog,"\n");
1426 /* safest point to do file checkpointing is here. More general point would be immediately before integrator call */
1427 /*#ifdef GMX_FAHCORE
1428 chkpt_ret=fcCheckPointParallel( cr->nodeid,
1430 if ( chkpt_ret == 0 )
1431 gmx_fatal( 3,__FILE__,__LINE__, "Checkpoint error on step %d\n", 0 );
1435 /***********************************************************
1437 * Loop over MD steps
1439 ************************************************************/
1441 /* if rerunMD then read coordinates and velocities from input trajectory */
1444 if (getenv("GMX_FORCE_UPDATE"))
1446 bForceUpdate = TRUE;
1449 bNotLastFrame = read_first_frame(oenv,&status,
1450 opt2fn("-rerun",nfile,fnm),
1451 &rerun_fr,TRX_NEED_X | TRX_READ_V);
1452 if (rerun_fr.natoms != top_global->natoms)
1455 "Number of atoms in trajectory (%d) does not match the "
1456 "run input file (%d)\n",
1457 rerun_fr.natoms,top_global->natoms);
1459 if (ir->ePBC != epbcNONE)
1463 gmx_fatal(FARGS,"Rerun trajectory frame step %d time %f does not contain a box, while pbc is used",rerun_fr.step,rerun_fr.time);
1465 if (max_cutoff2(ir->ePBC,rerun_fr.box) < sqr(fr->rlistlong))
1467 gmx_fatal(FARGS,"Rerun trajectory frame step %d time %f has too small box dimensions",rerun_fr.step,rerun_fr.time);
1470 /* Set the shift vectors.
1471 * Necessary here when have a static box different from the tpr box.
1473 calc_shifts(rerun_fr.box,fr->shift_vec);
1477 /* loop over MD steps or if rerunMD to end of input trajectory */
1479 /* Skip the first Nose-Hoover integration when we get the state from tpx */
1480 bStateFromTPX = !opt2bSet("-cpi",nfile,fnm);
1481 bInitStep = bFirstStep && (bStateFromTPX || bVV);
1482 bStartingFromCpt = (Flags & MD_STARTFROMCPT) && bInitStep;
1484 bSumEkinhOld = FALSE;
1487 init_global_signals(&gs,cr,ir,repl_ex_nst);
1489 step = ir->init_step;
1492 if (ir->nstlist == -1)
1494 init_nlistheuristics(&nlh,bGStatEveryStep,step);
1497 bLastStep = (bRerunMD || (ir->nsteps >= 0 && step_rel > ir->nsteps));
1498 while (!bLastStep || (bRerunMD && bNotLastFrame)) {
1500 wallcycle_start(wcycle,ewcSTEP);
1502 GMX_MPE_LOG(ev_timestep1);
1505 if (rerun_fr.bStep) {
1506 step = rerun_fr.step;
1507 step_rel = step - ir->init_step;
1509 if (rerun_fr.bTime) {
1519 bLastStep = (step_rel == ir->nsteps);
1520 t = t0 + step*ir->delta_t;
1523 if (ir->efep != efepNO)
1525 if (bRerunMD && rerun_fr.bLambda && (ir->delta_lambda!=0))
1527 state_global->lambda = rerun_fr.lambda;
1531 state_global->lambda = lam0 + step*ir->delta_lambda;
1533 state->lambda = state_global->lambda;
1534 bDoDHDL = do_per_step(step,ir->nstdhdl);
1539 update_annealing_target_temp(&(ir->opts),t);
1544 if (!(DOMAINDECOMP(cr) && !MASTER(cr)))
1546 for(i=0; i<state_global->natoms; i++)
1548 copy_rvec(rerun_fr.x[i],state_global->x[i]);
1552 for(i=0; i<state_global->natoms; i++)
1554 copy_rvec(rerun_fr.v[i],state_global->v[i]);
1559 for(i=0; i<state_global->natoms; i++)
1561 clear_rvec(state_global->v[i]);
1565 fprintf(stderr,"\nWARNING: Some frames do not contain velocities.\n"
1566 " Ekin, temperature and pressure are incorrect,\n"
1567 " the virial will be incorrect when constraints are present.\n"
1569 bRerunWarnNoV = FALSE;
1573 copy_mat(rerun_fr.box,state_global->box);
1574 copy_mat(state_global->box,state->box);
1576 if (vsite && (Flags & MD_RERUN_VSITE))
1578 if (DOMAINDECOMP(cr))
1580 gmx_fatal(FARGS,"Vsite recalculation with -rerun is not implemented for domain decomposition, use particle decomposition");
1584 /* Following is necessary because the graph may get out of sync
1585 * with the coordinates if we only have every N'th coordinate set
1587 mk_mshift(fplog,graph,fr->ePBC,state->box,state->x);
1588 shift_self(graph,state->box,state->x);
1590 construct_vsites(fplog,vsite,state->x,nrnb,ir->delta_t,state->v,
1591 top->idef.iparams,top->idef.il,
1592 fr->ePBC,fr->bMolPBC,graph,cr,state->box);
1595 unshift_self(graph,state->box,state->x);
1600 /* Stop Center of Mass motion */
1601 bStopCM = (ir->comm_mode != ecmNO && do_per_step(step,ir->nstcomm));
1603 /* Copy back starting coordinates in case we're doing a forcefield scan */
1606 for(ii=0; (ii<state->natoms); ii++)
1608 copy_rvec(xcopy[ii],state->x[ii]);
1609 copy_rvec(vcopy[ii],state->v[ii]);
1611 copy_mat(boxcopy,state->box);
1616 /* for rerun MD always do Neighbour Searching */
1617 bNS = (bFirstStep || ir->nstlist != 0);
1622 /* Determine whether or not to do Neighbour Searching and LR */
1623 bNStList = (ir->nstlist > 0 && step % ir->nstlist == 0);
1625 bNS = (bFirstStep || bExchanged || bNStList ||
1626 (ir->nstlist == -1 && nlh.nabnsb > 0));
1628 if (bNS && ir->nstlist == -1)
1630 set_nlistheuristics(&nlh,bFirstStep || bExchanged,step);
1634 /* < 0 means stop at next step, > 0 means stop at next NS step */
1635 if ( (gs.set[eglsSTOPCOND] < 0 ) ||
1636 ( (gs.set[eglsSTOPCOND] > 0 ) && ( bNS || ir->nstlist==0)) )
1641 /* Determine whether or not to update the Born radii if doing GB */
1642 bBornRadii=bFirstStep;
1643 if (ir->implicit_solvent && (step % ir->nstgbradii==0))
1648 do_log = do_per_step(step,ir->nstlog) || bFirstStep || bLastStep;
1649 do_verbose = bVerbose &&
1650 (step % stepout == 0 || bFirstStep || bLastStep);
1652 if (bNS && !(bFirstStep && ir->bContinuation && !bRerunMD))
1656 bMasterState = TRUE;
1660 bMasterState = FALSE;
1661 /* Correct the new box if it is too skewed */
1662 if (DYNAMIC_BOX(*ir))
1664 if (correct_box(fplog,step,state->box,graph))
1666 bMasterState = TRUE;
1669 if (DOMAINDECOMP(cr) && bMasterState)
1671 dd_collect_state(cr->dd,state,state_global);
1675 if (DOMAINDECOMP(cr))
1677 /* Repartition the domain decomposition */
1678 wallcycle_start(wcycle,ewcDOMDEC);
1679 dd_partition_system(fplog,step,cr,
1680 bMasterState,nstglobalcomm,
1681 state_global,top_global,ir,
1682 state,&f,mdatoms,top,fr,
1683 vsite,shellfc,constr,
1684 nrnb,wcycle,do_verbose);
1685 wallcycle_stop(wcycle,ewcDOMDEC);
1686 /* If using an iterative integrator, reallocate space to match the decomposition */
1690 if (MASTER(cr) && do_log && !bFFscan)
1692 print_ebin_header(fplog,step,t,state->lambda);
1695 if (ir->efep != efepNO)
1697 update_mdatoms(mdatoms,state->lambda);
1700 if (bRerunMD && rerun_fr.bV)
1703 /* We need the kinetic energy at minus the half step for determining
1704 * the full step kinetic energy and possibly for T-coupling.*/
1705 /* This may not be quite working correctly yet . . . . */
1706 compute_globals(fplog,gstat,cr,ir,fr,ekind,state,state_global,mdatoms,nrnb,vcm,
1707 wcycle,enerd,NULL,NULL,NULL,NULL,mu_tot,
1708 constr,NULL,FALSE,state->box,
1709 top_global,&pcurr,top_global->natoms,&bSumEkinhOld,
1710 CGLO_RERUNMD | CGLO_GSTAT | CGLO_TEMPERATURE);
1712 clear_mat(force_vir);
1714 /* Ionize the atoms if necessary */
1717 ionize(fplog,oenv,mdatoms,top_global,t,ir,state->x,state->v,
1718 mdatoms->start,mdatoms->start+mdatoms->homenr,state->box,cr);
1721 /* Update force field in ffscan program */
1724 if (update_forcefield(fplog,
1726 mdatoms->nr,state->x,state->box)) {
1727 if (gmx_parallel_env_initialized())
1735 GMX_MPE_LOG(ev_timestep2);
1737 /* We write a checkpoint at this MD step when:
1738 * either at an NS step when we signalled through gs,
1739 * or at the last step (but not when we do not want confout),
1740 * but never at the first step or with rerun.
1742 /* bCPT = (((gs.set[eglsCHKPT] && bNS) ||
1743 (bLastStep && (Flags & MD_CONFOUT))) &&
1744 step > ir->init_step && !bRerunMD);
1747 gs.set[eglsCHKPT] = 0;
1750 /* Determine the energy and pressure:
1751 * at nstcalcenergy steps and at energy output steps (set below).
1753 bNstEner = (bGStatEveryStep || do_per_step(step,ir->nstcalcenergy));
1754 bCalcEnerPres = bNstEner;
1756 /* Do we need global communication ? */
1757 bGStat = (bCalcEnerPres || bStopCM ||
1758 (ir->nstlist == -1 && !bRerunMD && step >= nlh.step_nscheck));
1760 do_ene = (do_per_step(step,ir->nstenergy) || bLastStep);
1762 if (do_ene || do_log)
1764 bCalcEnerPres = TRUE;
1768 /* these CGLO_ options remain the same throughout the iteration */
1769 cglo_flags = ((bRerunMD ? CGLO_RERUNMD : 0) |
1770 (bStopCM ? CGLO_STOPCM : 0) |
1771 (bGStat ? CGLO_GSTAT : 0)
1774 force_flags = (GMX_FORCE_STATECHANGED |
1775 ((DYNAMIC_BOX(*ir) || bRerunMD) ? GMX_FORCE_DYNAMICBOX : 0) |
1776 GMX_FORCE_ALLFORCES |
1777 (bNStList ? GMX_FORCE_DOLR : 0) |
1779 (bCalcEnerPres ? GMX_FORCE_VIRIAL : 0) |
1780 (bDoDHDL ? GMX_FORCE_DHDL : 0)
1785 /* Now is the time to relax the shells */
1786 count=relax_shell_flexcon(fplog,cr,bVerbose,bFFscan ? step+1 : step,
1788 bStopCM,top,top_global,
1790 state,f,force_vir,mdatoms,
1791 nrnb,wcycle,graph,groups,
1792 shellfc,fr,bBornRadii,t,mu_tot,
1793 state->natoms,&bConverged,vsite,
1804 /* The coordinates (x) are shifted (to get whole molecules)
1806 * This is parallellized as well, and does communication too.
1807 * Check comments in sim_util.c
1810 do_force(fplog,cr,ir,step,nrnb,wcycle,top,top_global,groups,
1811 state->box,state->x,&state->hist,
1812 f,force_vir,mdatoms,enerd,fcd,
1813 state->lambda,graph,
1814 fr,vsite,mu_tot,t,outf->fp_field,ed,bBornRadii,
1815 (bNS ? GMX_FORCE_NS : 0) | force_flags);
1818 GMX_BARRIER(cr->mpi_comm_mygroup);
1822 mu_aver = calc_mu_aver(cr,state->x,mdatoms->chargeA,
1823 mu_tot,&top_global->mols,mdatoms,gnx,grpindex);
1826 if (bTCR && bFirstStep)
1828 tcr=init_coupling(fplog,nfile,fnm,cr,fr,mdatoms,&(top->idef));
1829 fprintf(fplog,"Done init_coupling\n");
1833 /* ############### START FIRST UPDATE HALF-STEP ############### */
1835 if (bVV && !bStartingFromCpt && !bRerunMD)
1841 /* if using velocity verlet with full time step Ekin,
1842 * take the first half step only to compute the
1843 * virial for the first step. From there,
1844 * revert back to the initial coordinates
1845 * so that the input is actually the initial step.
1847 copy_rvecn(state->v,cbuf,0,state->natoms); /* should make this better for parallelizing? */
1850 /* this is for NHC in the Ekin(t+dt/2) version of vv */
1853 trotter_update(ir,step,ekind,enerd,state,total_vir,mdatoms,&MassQ,trotter_seq,ettTSEQ2);
1856 if (ir->eI == eiVVAK)
1858 update_tcouple(fplog,step,ir,state,ekind,wcycle,upd,&MassQ,mdatoms);
1861 update_coords(fplog,step,ir,mdatoms,state,
1862 f,fr->bTwinRange && bNStList,fr->f_twin,fcd,
1863 ekind,M,wcycle,upd,bInitStep,etrtVELOCITY1,
1864 cr,nrnb,constr,&top->idef);
1868 gmx_iterate_init(&iterate,bIterations && !bInitStep);
1870 /* for iterations, we save these vectors, as we will be self-consistently iterating
1872 /*#### UPDATE EXTENDED VARIABLES IN TROTTER FORMULATION */
1874 /* save the state */
1875 if (bIterations && iterate.bIterate) {
1876 copy_coupling_state(state,bufstate,ekind,ekind_save,&(ir->opts));
1880 bFirstIterate = TRUE;
1881 while (bFirstIterate || (bIterations && iterate.bIterate))
1883 if (bIterations && iterate.bIterate)
1885 copy_coupling_state(bufstate,state,ekind_save,ekind,&(ir->opts));
1886 if (bFirstIterate && bTrotter)
1888 /* The first time through, we need a decent first estimate
1889 of veta(t+dt) to compute the constraints. Do
1890 this by computing the box volume part of the
1891 trotter integration at this time. Nothing else
1892 should be changed by this routine here. If
1893 !(first time), we start with the previous value
1896 veta_save = state->veta;
1897 trotter_update(ir,step,ekind,enerd,state,total_vir,mdatoms,&MassQ,trotter_seq,ettTSEQ0);
1898 vetanew = state->veta;
1899 state->veta = veta_save;
1904 if ( !bRerunMD || rerun_fr.bV || bForceUpdate) { /* Why is rerun_fr.bV here? Unclear. */
1907 update_constraints(fplog,step,&dvdl,ir,ekind,mdatoms,state,graph,f,
1908 &top->idef,shake_vir,NULL,
1909 cr,nrnb,wcycle,upd,constr,
1910 bInitStep,TRUE,bCalcEnerPres,vetanew);
1912 if (!bOK && !bFFscan)
1914 gmx_fatal(FARGS,"Constraint error: Shake, Lincs or Settle could not solve the constrains");
1919 { /* Need to unshift here if a do_force has been
1920 called in the previous step */
1921 unshift_self(graph,state->box,state->x);
1926 /* if VV, compute the pressure and constraints */
1927 /* if VV2, the pressure and constraints only if using pressure control.*/
1928 bPres = (ir->eI==eiVV || IR_NPT_TROTTER(ir));
1929 bTemp = ((ir->eI==eiVV &&(!bInitStep)) || (ir->eI==eiVVAK && IR_NPT_TROTTER(ir)));
1930 compute_globals(fplog,gstat,cr,ir,fr,ekind,state,state_global,mdatoms,nrnb,vcm,
1931 wcycle,enerd,force_vir,shake_vir,total_vir,pres,mu_tot,
1932 constr,NULL,FALSE,state->box,
1933 top_global,&pcurr,top_global->natoms,&bSumEkinhOld,
1936 | (bTemp ? CGLO_TEMPERATURE:0)
1937 | (bPres ? CGLO_PRESSURE : 0)
1938 | (bPres ? CGLO_CONSTRAINT : 0)
1939 | (iterate.bIterate ? CGLO_ITERATE : 0)
1940 | (bFirstIterate ? CGLO_FIRSTITERATE : 0)
1944 /* explanation of above:
1945 a) We compute Ekin at the full time step
1946 if 1) we are using the AveVel Ekin, and it's not the
1947 initial step, or 2) if we are using AveEkin, but need the full
1948 time step kinetic energy for the pressure.
1949 b) If we are using EkinAveEkin for the kinetic energy for the temperture control, we still feed in
1950 EkinAveVel because it's needed for the pressure */
1952 /* temperature scaling and pressure scaling to produce the extended variables at t+dt */
1953 if (bVV && !bInitStep)
1955 trotter_update(ir,step,ekind,enerd,state,total_vir,mdatoms,&MassQ, trotter_seq,ettTSEQ2);
1959 done_iterating(cr,fplog,step,&iterate,bFirstIterate,
1960 state->veta,&vetanew))
1964 bFirstIterate = FALSE;
1967 if (bTrotter && !bInitStep) {
1968 copy_mat(shake_vir,state->svir_prev);
1969 copy_mat(force_vir,state->fvir_prev);
1970 if (IR_NVT_TROTTER(ir) && ir->eI==eiVV) {
1971 /* update temperature and kinetic energy now that step is over - this is the v(t+dt) point */
1972 enerd->term[F_TEMP] = sum_ekin(&(ir->opts),ekind,NULL,(ir->eI==eiVV),FALSE,FALSE);
1973 enerd->term[F_EKIN] = trace(ekind->ekin);
1976 /* if it's the initial step, we performed this first step just to get the constraint virial */
1977 if (bInitStep && ir->eI==eiVV) {
1978 copy_rvecn(cbuf,state->v,0,state->natoms);
1981 if (fr->bSepDVDL && fplog && do_log)
1983 fprintf(fplog,sepdvdlformat,"Constraint",0.0,dvdl);
1985 enerd->term[F_DHDL_CON] += dvdl;
1987 GMX_MPE_LOG(ev_timestep1);
1991 /* MRS -- now done iterating -- compute the conserved quantity */
1994 if (IR_NVT_TROTTER(ir) || IR_NPT_TROTTER(ir))
1997 NPT_energy(ir,state,&MassQ);
1998 if ((ir->eDispCorr != edispcEnerPres) && (ir->eDispCorr != edispcAllEnerPres))
2000 last_conserved -= enerd->term[F_DISPCORR];
2004 last_ekin = enerd->term[F_EKIN]; /* does this get preserved through checkpointing? */
2008 /* ######## END FIRST UPDATE STEP ############## */
2009 /* ######## If doing VV, we now have v(dt) ###### */
2011 /* ################## START TRAJECTORY OUTPUT ################# */
2013 /* Now we have the energies and forces corresponding to the
2014 * coordinates at time t. We must output all of this before
2016 * for RerunMD t is read from input trajectory
2018 GMX_MPE_LOG(ev_output_start);
2021 if (do_per_step(step,ir->nstxout)) { mdof_flags |= MDOF_X; }
2022 if (do_per_step(step,ir->nstvout)) { mdof_flags |= MDOF_V; }
2023 if (do_per_step(step,ir->nstfout)) { mdof_flags |= MDOF_F; }
2024 if (do_per_step(step,ir->nstxtcout)) { mdof_flags |= MDOF_XTC; }
2025 /* if (bCPT) { mdof_flags |= MDOF_CPT; };*/
2029 fcReportProgress( ir->nsteps, step );
2033 /* Enforce writing positions and velocities at end of run */
2034 mdof_flags |= (MDOF_X | MDOF_V);
2036 /* sync bCPT and fc record-keeping */
2037 /* if (bCPT && MASTER(cr))
2038 fcRequestCheckPoint();*/
2041 if (mdof_flags != 0)
2043 wallcycle_start(wcycle,ewcTRAJ);
2046 if (state->flags & (1<<estLD_RNG))
2048 get_stochd_state(upd,state);
2054 state_global->ekinstate.bUpToDate = FALSE;
2058 update_ekinstate(&state_global->ekinstate,ekind);
2059 state_global->ekinstate.bUpToDate = TRUE;
2061 update_energyhistory(&state_global->enerhist,mdebin);
2064 write_traj(fplog,cr,outf,mdof_flags,top_global,
2065 step,t,state,state_global,f,f_global,&n_xtc,&x_xtc);
2072 if (bLastStep && step_rel == ir->nsteps &&
2073 (Flags & MD_CONFOUT) && MASTER(cr) &&
2074 !bRerunMD && !bFFscan)
2076 /* x and v have been collected in write_traj,
2077 * because a checkpoint file will always be written
2080 fprintf(stderr,"\nWriting final coordinates.\n");
2081 if (ir->ePBC != epbcNONE && !ir->bPeriodicMols &&
2084 /* Make molecules whole only for confout writing */
2085 do_pbc_mtop(fplog,ir->ePBC,state->box,top_global,state_global->x);
2087 /* write_sto_conf_mtop(ftp2fn(efSTO,nfile,fnm),
2088 *top_global->name,top_global,
2089 state_global->x,state_global->v,
2090 ir->ePBC,state->box);*/
2093 wallcycle_stop(wcycle,ewcTRAJ);
2095 GMX_MPE_LOG(ev_output_finish);
2097 /* kludge -- virial is lost with restart for NPT control. Must restart */
2098 if (bStartingFromCpt && bVV)
2100 copy_mat(state->svir_prev,shake_vir);
2101 copy_mat(state->fvir_prev,force_vir);
2103 /* ################## END TRAJECTORY OUTPUT ################ */
2105 /* Determine the pressure:
2106 * always when we want exact averages in the energy file,
2107 * at ns steps when we have pressure coupling,
2108 * otherwise only at energy output steps (set below).
2111 bNstEner = (bGStatEveryStep || do_per_step(step,ir->nstcalcenergy));
2112 bCalcEnerPres = bNstEner;
2114 /* Do we need global communication ? */
2115 bGStat = (bGStatEveryStep || bStopCM || bNS ||
2116 (ir->nstlist == -1 && !bRerunMD && step >= nlh.step_nscheck));
2118 do_ene = (do_per_step(step,ir->nstenergy) || bLastStep);
2120 if (do_ene || do_log)
2122 bCalcEnerPres = TRUE;
2126 /* Determine the wallclock run time up till now */
2127 run_time = gmx_gettime() - (double)runtime->real;
2129 /* Check whether everything is still allright */
2130 if (((int)gmx_get_stop_condition() > handled_stop_condition)
2131 #ifdef GMX_THREAD_MPI
2136 /* this is just make gs.sig compatible with the hack
2137 of sending signals around by MPI_Reduce with together with
2139 if ( gmx_get_stop_condition() == gmx_stop_cond_next_ns )
2140 gs.sig[eglsSTOPCOND]=1;
2141 if ( gmx_get_stop_condition() == gmx_stop_cond_next )
2142 gs.sig[eglsSTOPCOND]=-1;
2143 /* < 0 means stop at next step, > 0 means stop at next NS step */
2147 "\n\nReceived the %s signal, stopping at the next %sstep\n\n",
2148 gmx_get_signal_name(),
2149 gs.sig[eglsSTOPCOND]==1 ? "NS " : "");
2153 "\n\nReceived the %s signal, stopping at the next %sstep\n\n",
2154 gmx_get_signal_name(),
2155 gs.sig[eglsSTOPCOND]==1 ? "NS " : "");
2157 handled_stop_condition=(int)gmx_get_stop_condition();
2159 else if (MASTER(cr) && (bNS || ir->nstlist <= 0) &&
2160 (max_hours > 0 && run_time > max_hours*60.0*60.0*0.99) &&
2161 gs.sig[eglsSTOPCOND] == 0 && gs.set[eglsSTOPCOND] == 0)
2163 /* Signal to terminate the run */
2164 gs.sig[eglsSTOPCOND] = 1;
2167 fprintf(fplog,"\nStep %s: Run time exceeded %.3f hours, will terminate the run\n",gmx_step_str(step,sbuf),max_hours*0.99);
2169 fprintf(stderr, "\nStep %s: Run time exceeded %.3f hours, will terminate the run\n",gmx_step_str(step,sbuf),max_hours*0.99);
2172 if (bResetCountersHalfMaxH && MASTER(cr) &&
2173 run_time > max_hours*60.0*60.0*0.495)
2175 gs.sig[eglsRESETCOUNTERS] = 1;
2178 if (ir->nstlist == -1 && !bRerunMD)
2180 /* When bGStatEveryStep=FALSE, global_stat is only called
2181 * when we check the atom displacements, not at NS steps.
2182 * This means that also the bonded interaction count check is not
2183 * performed immediately after NS. Therefore a few MD steps could
2184 * be performed with missing interactions.
2185 * But wrong energies are never written to file,
2186 * since energies are only written after global_stat
2189 if (step >= nlh.step_nscheck)
2191 nlh.nabnsb = natoms_beyond_ns_buffer(ir,fr,&top->cgs,
2192 nlh.scale_tot,state->x);
2196 /* This is not necessarily true,
2197 * but step_nscheck is determined quite conservatively.
2203 /* In parallel we only have to check for checkpointing in steps
2204 * where we do global communication,
2205 * otherwise the other nodes don't know.
2207 if (MASTER(cr) && ((bGStat || !PAR(cr)) &&
2210 run_time >= nchkpt*cpt_period*60.0)) &&
2211 gs.set[eglsCHKPT] == 0)
2213 gs.sig[eglsCHKPT] = 1;
2218 gmx_iterate_init(&iterate,bIterations);
2221 /* for iterations, we save these vectors, as we will be redoing the calculations */
2222 if (bIterations && iterate.bIterate)
2224 copy_coupling_state(state,bufstate,ekind,ekind_save,&(ir->opts));
2226 bFirstIterate = TRUE;
2227 while (bFirstIterate || (bIterations && iterate.bIterate))
2229 /* We now restore these vectors to redo the calculation with improved extended variables */
2232 copy_coupling_state(bufstate,state,ekind_save,ekind,&(ir->opts));
2235 /* We make the decision to break or not -after- the calculation of Ekin and Pressure,
2236 so scroll down for that logic */
2238 /* ######### START SECOND UPDATE STEP ################# */
2239 GMX_MPE_LOG(ev_update_start);
2241 if (!bRerunMD || rerun_fr.bV || bForceUpdate)
2243 wallcycle_start(wcycle,ewcUPDATE);
2245 /* Box is changed in update() when we do pressure coupling,
2246 * but we should still use the old box for energy corrections and when
2247 * writing it to the energy file, so it matches the trajectory files for
2248 * the same timestep above. Make a copy in a separate array.
2250 copy_mat(state->box,lastbox);
2251 /* UPDATE PRESSURE VARIABLES IN TROTTER FORMULATION WITH CONSTRAINTS */
2254 if (bIterations && iterate.bIterate)
2262 /* we use a new value of scalevir to converge the iterations faster */
2263 scalevir = tracevir/trace(shake_vir);
2265 msmul(shake_vir,scalevir,shake_vir);
2266 m_add(force_vir,shake_vir,total_vir);
2267 clear_mat(shake_vir);
2269 trotter_update(ir,step,ekind,enerd,state,total_vir,mdatoms,&MassQ, trotter_seq,ettTSEQ3);
2271 /* We can only do Berendsen coupling after we have summed
2272 * the kinetic energy or virial. Since the happens
2273 * in global_state after update, we should only do it at
2274 * step % nstlist = 1 with bGStatEveryStep=FALSE.
2277 if (ir->eI != eiVVAK)
2279 update_tcouple(fplog,step,ir,state,ekind,wcycle,upd,&MassQ,mdatoms);
2281 update_pcouple(fplog,step,ir,state,pcoupl_mu,M,wcycle,
2286 /* velocity half-step update */
2287 update_coords(fplog,step,ir,mdatoms,state,f,fr->bTwinRange && bNStList,fr->f_twin,fcd,
2288 ekind,M,wcycle,upd,FALSE,etrtVELOCITY2,cr,nrnb,constr,&top->idef);
2291 /* Above, initialize just copies ekinh into ekin,
2292 * it doesn't copy position (for VV),
2293 * and entire integrator for MD.
2298 copy_rvecn(state->x,cbuf,0,state->natoms);
2301 update_coords(fplog,step,ir,mdatoms,state,f,fr->bTwinRange && bNStList,fr->f_twin,fcd,
2302 ekind,M,wcycle,upd,bInitStep,etrtPOSITION,cr,nrnb,constr,&top->idef);
2303 wallcycle_stop(wcycle,ewcUPDATE);
2305 update_constraints(fplog,step,&dvdl,ir,ekind,mdatoms,state,graph,f,
2306 &top->idef,shake_vir,force_vir,
2307 cr,nrnb,wcycle,upd,constr,
2308 bInitStep,FALSE,bCalcEnerPres,state->veta);
2312 /* erase F_EKIN and F_TEMP here? */
2313 /* just compute the kinetic energy at the half step to perform a trotter step */
2314 compute_globals(fplog,gstat,cr,ir,fr,ekind,state,state_global,mdatoms,nrnb,vcm,
2315 wcycle,enerd,force_vir,shake_vir,total_vir,pres,mu_tot,
2316 constr,NULL,FALSE,lastbox,
2317 top_global,&pcurr,top_global->natoms,&bSumEkinhOld,
2318 cglo_flags | CGLO_TEMPERATURE | CGLO_CONSTRAINT
2320 wallcycle_start(wcycle,ewcUPDATE);
2321 trotter_update(ir,step,ekind,enerd,state,total_vir,mdatoms,&MassQ, trotter_seq,ettTSEQ4);
2322 /* now we know the scaling, we can compute the positions again again */
2323 copy_rvecn(cbuf,state->x,0,state->natoms);
2325 update_coords(fplog,step,ir,mdatoms,state,f,fr->bTwinRange && bNStList,fr->f_twin,fcd,
2326 ekind,M,wcycle,upd,bInitStep,etrtPOSITION,cr,nrnb,constr,&top->idef);
2327 wallcycle_stop(wcycle,ewcUPDATE);
2329 /* do we need an extra constraint here? just need to copy out of state->v to upd->xp? */
2330 /* are the small terms in the shake_vir here due
2331 * to numerical errors, or are they important
2332 * physically? I'm thinking they are just errors, but not completely sure.
2333 * For now, will call without actually constraining, constr=NULL*/
2334 update_constraints(fplog,step,&dvdl,ir,ekind,mdatoms,state,graph,f,
2335 &top->idef,tmp_vir,force_vir,
2336 cr,nrnb,wcycle,upd,NULL,
2337 bInitStep,FALSE,bCalcEnerPres,state->veta);
2339 if (!bOK && !bFFscan)
2341 gmx_fatal(FARGS,"Constraint error: Shake, Lincs or Settle could not solve the constrains");
2344 if (fr->bSepDVDL && fplog && do_log)
2346 fprintf(fplog,sepdvdlformat,"Constraint",0.0,dvdl);
2348 enerd->term[F_DHDL_CON] += dvdl;
2352 /* Need to unshift here */
2353 unshift_self(graph,state->box,state->x);
2356 GMX_BARRIER(cr->mpi_comm_mygroup);
2357 GMX_MPE_LOG(ev_update_finish);
2361 wallcycle_start(wcycle,ewcVSITECONSTR);
2364 shift_self(graph,state->box,state->x);
2366 construct_vsites(fplog,vsite,state->x,nrnb,ir->delta_t,state->v,
2367 top->idef.iparams,top->idef.il,
2368 fr->ePBC,fr->bMolPBC,graph,cr,state->box);
2372 unshift_self(graph,state->box,state->x);
2374 wallcycle_stop(wcycle,ewcVSITECONSTR);
2377 /* ############## IF NOT VV, Calculate globals HERE, also iterate constraints ############ */
2378 if (ir->nstlist == -1 && bFirstIterate)
2380 gs.sig[eglsNABNSB] = nlh.nabnsb;
2382 compute_globals(fplog,gstat,cr,ir,fr,ekind,state,state_global,mdatoms,nrnb,vcm,
2383 wcycle,enerd,force_vir,shake_vir,total_vir,pres,mu_tot,
2385 bFirstIterate ? &gs : NULL,(step % gs.nstms == 0),
2387 top_global,&pcurr,top_global->natoms,&bSumEkinhOld,
2389 | (!EI_VV(ir->eI) ? CGLO_ENERGY : 0)
2390 | (!EI_VV(ir->eI) ? CGLO_TEMPERATURE : 0)
2391 | (!EI_VV(ir->eI) || bRerunMD ? CGLO_PRESSURE : 0)
2392 | (bIterations && iterate.bIterate ? CGLO_ITERATE : 0)
2393 | (bFirstIterate ? CGLO_FIRSTITERATE : 0)
2396 if (ir->nstlist == -1 && bFirstIterate)
2398 nlh.nabnsb = gs.set[eglsNABNSB];
2399 gs.set[eglsNABNSB] = 0;
2401 /* bIterate is set to keep it from eliminating the old ekin kinetic energy terms */
2402 /* ############# END CALC EKIN AND PRESSURE ################# */
2404 /* Note: this is OK, but there are some numerical precision issues with using the convergence of
2405 the virial that should probably be addressed eventually. state->veta has better properies,
2406 but what we actually need entering the new cycle is the new shake_vir value. Ideally, we could
2407 generate the new shake_vir, but test the veta value for convergence. This will take some thought. */
2410 done_iterating(cr,fplog,step,&iterate,bFirstIterate,
2411 trace(shake_vir),&tracevir))
2415 bFirstIterate = FALSE;
2418 update_box(fplog,step,ir,mdatoms,state,graph,f,
2419 ir->nstlist==-1 ? &nlh.scale_tot : NULL,pcoupl_mu,nrnb,wcycle,upd,bInitStep,FALSE);
2421 /* ################# END UPDATE STEP 2 ################# */
2422 /* #### We now have r(t+dt) and v(t+dt/2) ############# */
2424 /* The coordinates (x) were unshifted in update */
2425 /* if (bFFscan && (shellfc==NULL || bConverged))
2427 if (print_forcefield(fplog,enerd->term,mdatoms->homenr,
2429 &(top_global->mols),mdatoms->massT,pres))
2431 if (gmx_parallel_env_initialized())
2435 fprintf(stderr,"\n");
2441 /* We will not sum ekinh_old,
2442 * so signal that we still have to do it.
2444 bSumEkinhOld = TRUE;
2449 /* Only do GCT when the relaxation of shells (minimization) has converged,
2450 * otherwise we might be coupling to bogus energies.
2451 * In parallel we must always do this, because the other sims might
2455 /* Since this is called with the new coordinates state->x, I assume
2456 * we want the new box state->box too. / EL 20040121
2458 /* do_coupling(fplog,oenv,nfile,fnm,tcr,t,step,enerd->term,fr,
2460 mdatoms,&(top->idef),mu_aver,
2461 top_global->mols.nr,cr,
2462 state->box,total_vir,pres,
2463 mu_tot,state->x,f,bConverged);
2467 /* ######### BEGIN PREPARING EDR OUTPUT ########### */
2469 sum_dhdl(enerd,state->lambda,ir);
2470 /* use the directly determined last velocity, not actually the averaged half steps */
2471 if (bTrotter && ir->eI==eiVV)
2473 enerd->term[F_EKIN] = last_ekin;
2475 enerd->term[F_ETOT] = enerd->term[F_EPOT] + enerd->term[F_EKIN];
2484 if (IR_NVT_TROTTER(ir)) {
2485 enerd->term[F_ECONSERVED] = enerd->term[F_ETOT] + last_conserved;
2487 enerd->term[F_ECONSERVED] = enerd->term[F_ETOT] +
2488 NPT_energy(ir,state,&MassQ);
2492 enerd->term[F_ECONSERVED] =
2493 enerd->term[F_ETOT] + vrescale_energy(&(ir->opts),
2494 state->therm_integral);
2500 /* Check for excessively large energies */
2504 real etot_max = 1e200;
2506 real etot_max = 1e30;
2508 if (fabs(enerd->term[F_ETOT]) > etot_max)
2510 fprintf(stderr,"Energy too large (%g), giving up\n",
2511 enerd->term[F_ETOT]);
2514 /* ######### END PREPARING EDR OUTPUT ########### */
2516 /* Time for performance */
2517 if (((step % stepout) == 0) || bLastStep)
2519 runtime_upd_proc(runtime);
2525 gmx_bool do_dr,do_or;
2527 if (!(bStartingFromCpt && (EI_VV(ir->eI))))
2531 upd_mdebin(mdebin,bDoDHDL,TRUE,
2532 t,mdatoms->tmass,enerd,state,lastbox,
2533 shake_vir,force_vir,total_vir,pres,
2534 ekind,mu_tot,constr);
2538 upd_mdebin_step(mdebin);
2541 do_dr = do_per_step(step,ir->nstdisreout);
2542 do_or = do_per_step(step,ir->nstorireout);
2544 print_ebin(outf->fp_ene,do_ene,do_dr,do_or,do_log?fplog:NULL,
2546 eprNORMAL,bCompact,mdebin,fcd,groups,&(ir->opts));
2548 if (ir->ePull != epullNO)
2550 pull_print_output(ir->pull,step,t);
2553 if (do_per_step(step,ir->nstlog))
2555 if(fflush(fplog) != 0)
2557 gmx_fatal(FARGS,"Cannot flush logfile - maybe you are out of disk space?");
2563 /* Remaining runtime */
2564 if (MULTIMASTER(cr) && (do_verbose || gmx_got_usr_signal() ))
2568 fprintf(stderr,"\n");
2570 print_time(stderr,runtime,step,ir,cr);
2573 /* Set new positions for the group to embed */
2579 } else if (step_rel<=(it_xy+it_z))
2583 resize(ins_at,r_ins,state_global->x,pos_ins,fac);
2586 /* Replica exchange */
2587 /* bExchanged = FALSE;
2588 if ((repl_ex_nst > 0) && (step > 0) && !bLastStep &&
2589 do_per_step(step,repl_ex_nst))
2591 bExchanged = replica_exchange(fplog,cr,repl_ex,
2592 state_global,enerd->term,
2595 if (bExchanged && PAR(cr))
2597 if (DOMAINDECOMP(cr))
2599 dd_partition_system(fplog,step,cr,TRUE,1,
2600 state_global,top_global,ir,
2601 state,&f,mdatoms,top,fr,
2602 vsite,shellfc,constr,
2607 bcast_state(cr,state,FALSE);
2613 bStartingFromCpt = FALSE;
2615 /* ####### SET VARIABLES FOR NEXT ITERATION IF THEY STILL NEED IT ###### */
2616 /* With all integrators, except VV, we need to retain the pressure
2617 * at the current step for coupling at the next step.
2619 if ((state->flags & (1<<estPRES_PREV)) &&
2621 (ir->nstpcouple > 0 && step % ir->nstpcouple == 0)))
2623 /* Store the pressure in t_state for pressure coupling
2624 * at the next MD step.
2626 copy_mat(pres,state->pres_prev);
2629 /* ####### END SET VARIABLES FOR NEXT ITERATION ###### */
2633 /* read next frame from input trajectory */
2634 bNotLastFrame = read_next_frame(oenv,status,&rerun_fr);
2637 if (!bRerunMD || !rerun_fr.bStep)
2639 /* increase the MD step number */
2644 cycles = wallcycle_stop(wcycle,ewcSTEP);
2645 if (DOMAINDECOMP(cr) && wcycle)
2647 dd_cycles_add(cr->dd,cycles,ddCyclStep);
2650 if (step_rel == wcycle_get_reset_counters(wcycle) ||
2651 gs.set[eglsRESETCOUNTERS] != 0)
2653 /* Reset all the counters related to performance over the run */
2654 reset_all_counters(fplog,cr,step,&step_rel,ir,wcycle,nrnb,runtime);
2655 wcycle_set_reset_counters(wcycle,-1);
2656 bResetCountersHalfMaxH = FALSE;
2657 gs.set[eglsRESETCOUNTERS] = 0;
2660 /* End of main MD loop */
2662 write_sto_conf_mtop(ftp2fn(efSTO,nfile,fnm),
2663 *top_global->name,top_global,
2664 state_global->x,state_global->v,
2665 ir->ePBC,state->box);
2668 runtime_end(runtime);
2675 if (!(cr->duty & DUTY_PME))
2677 /* Tell the PME only node to finish */
2683 if (ir->nstcalcenergy > 0 && !bRerunMD)
2685 print_ebin(outf->fp_ene,FALSE,FALSE,FALSE,fplog,step,t,
2686 eprAVER,FALSE,mdebin,fcd,groups,&(ir->opts));
2694 if (ir->nstlist == -1 && nlh.nns > 0 && fplog)
2696 fprintf(fplog,"Average neighborlist lifetime: %.1f steps, std.dev.: %.1f steps\n",nlh.s1/nlh.nns,sqrt(nlh.s2/nlh.nns - sqr(nlh.s1/nlh.nns)));
2697 fprintf(fplog,"Average number of atoms that crossed the half buffer length: %.1f\n\n",nlh.ab/nlh.nns);
2700 if (shellfc && fplog)
2702 fprintf(fplog,"Fraction of iterations that converged: %.2f %%\n",
2703 (nconverged*100.0)/step_rel);
2704 fprintf(fplog,"Average number of force evaluations per MD step: %.2f\n\n",
2708 /* if (repl_ex_nst > 0 && MASTER(cr))
2710 print_replica_exchange_statistics(fplog,repl_ex);
2713 runtime->nsteps_done = step_rel;
2719 int mdrunner_membed(FILE *fplog,t_commrec *cr,int nfile,const t_filenm fnm[],
2720 const output_env_t oenv, gmx_bool bVerbose,gmx_bool bCompact,
2722 ivec ddxyz,int dd_node_order,real rdd,real rconstr,
2723 const char *dddlb_opt,real dlb_scale,
2724 const char *ddcsx,const char *ddcsy,const char *ddcsz,
2725 int nstepout,int resetstep,int nmultisim,int repl_ex_nst,int repl_ex_seed,
2726 real pforce,real cpt_period,real max_hours,
2727 const char *deviceOptions,
2728 unsigned long Flags,
2729 real xy_fac, real xy_max, real z_fac, real z_max,
2730 int it_xy, int it_z, real probe_rad, int low_up_rm,
2731 int pieces, gmx_bool bALLOW_ASYMMETRY, int maxwarn)
2733 double nodetime=0,realtime;
2734 t_inputrec *inputrec;
2735 t_state *state=NULL;
2738 int npme_major,npme_minor;
2741 gmx_mtop_t *mtop=NULL;
2742 t_mdatoms *mdatoms=NULL;
2743 t_forcerec *fr=NULL;
2746 gmx_pme_t *pmedata=NULL;
2747 gmx_vsite_t *vsite=NULL;
2748 gmx_constr_t constr;
2749 int i,m,nChargePerturbed=-1,status,nalloc;
2751 gmx_wallcycle_t wcycle;
2752 gmx_bool bReadRNG,bReadEkin;
2754 gmx_runtime_t runtime;
2756 gmx_large_int_t reset_counters;
2757 gmx_edsam_t ed=NULL;
2758 t_commrec *cr_old=cr;
2759 int nthreads=1,nthreads_requested=1;
2760 int omp_nthreads = 1;
2763 int rm_bonded_at,fr_id,fr_i=0,tmp_id,warn=0;
2764 int ng,j,max_lip_rm,ins_grp_id,ins_nat,mem_nat,ntype,lip_rm,tpr_version;
2765 real xy_step=0,z_step=0;
2767 rvec *r_ins=NULL,fac;
2768 t_block *ins_at,*rest_at;
2772 gmx_groups_t *groups;
2773 gmx_bool bExcl=FALSE;
2776 char **piecename=NULL;
2778 /* CAUTION: threads may be started later on in this function, so
2779 cr doesn't reflect the final parallel state right now */
2783 if (bVerbose && SIMMASTER(cr))
2785 fprintf(stderr,"Getting Loaded...\n");
2788 if (Flags & MD_APPENDFILES)
2796 /* Read (nearly) all data required for the simulation */
2797 read_tpx_state(ftp2fn(efTPX,nfile,fnm),inputrec,state,NULL,mtop);
2799 /* NOW the threads will be started: */
2800 #ifdef GMX_THREAD_MPI
2803 /* END OF CAUTION: cr is now reliable */
2807 /* now broadcast everything to the non-master nodes/threads: */
2808 init_parallel(fplog, cr, inputrec, mtop);
2810 /* now make sure the state is initialized and propagated */
2811 set_state_entries(state,inputrec,cr->nnodes);
2813 if (can_use_allvsall(inputrec,mtop,TRUE,cr,fplog))
2815 /* All-vs-all loops do not work with domain decomposition */
2816 Flags |= MD_PARTDEC;
2819 if (!EEL_PME(inputrec->coulombtype) || (Flags & MD_PARTDEC))
2828 tpr_version = get_tpr_version(ftp2fn(efTPX,nfile,fnm));
2830 gmx_fatal(FARGS,"Version of *.tpr file to old (%d). Rerun grompp with gromacs VERSION 4.0.3 or newer.\n",tpr_version);
2832 if( inputrec->eI != eiMD )
2833 gmx_input("Change integrator to md in mdp file.");
2836 gmx_input("Sorry, parallel g_membed is not yet fully functrional.");
2838 groups=&(mtop->groups);
2840 atoms=gmx_mtop_global_atoms(mtop);
2842 fprintf(stderr,"\nSelect a group to embed in the membrane:\n");
2843 get_index(&atoms,ftp2fn_null(efNDX,nfile,fnm),1,&(ins_at->nr),&(ins_at->index),&ins);
2844 ins_grp_id = search_string(ins,groups->ngrpname,(groups->grpname));
2845 fprintf(stderr,"\nSelect a group to embed %s into (e.g. the membrane):\n",ins);
2846 get_index(&atoms,ftp2fn_null(efNDX,nfile,fnm),1,&(mem_p->mem_at.nr),&(mem_p->mem_at.index),&(mem_p->name));
2848 pos_ins->pieces=pieces;
2849 snew(pos_ins->nidx,pieces);
2850 snew(pos_ins->subindex,pieces);
2851 snew(piecename,pieces);
2854 fprintf(stderr,"\nSelect pieces to embed:\n");
2855 get_index(&atoms,ftp2fn_null(efNDX,nfile,fnm),pieces,pos_ins->nidx,pos_ins->subindex,piecename);
2859 /*use whole embedded group*/
2860 snew(pos_ins->nidx,1);
2861 snew(pos_ins->subindex,1);
2862 pos_ins->nidx[0]=ins_at->nr;
2863 pos_ins->subindex[0]=ins_at->index;
2866 if(probe_rad<0.2199999)
2869 fprintf(stderr,"\nWarning %d:\nA probe radius (-rad) smaller than 0.2 can result in overlap between waters "
2870 "and the group to embed, which will result in Lincs errors etc.\nIf you are sure, you can increase maxwarn.\n\n",warn);
2873 if(xy_fac<0.09999999)
2876 fprintf(stderr,"\nWarning %d:\nThe initial size of %s is probably too smal.\n"
2877 "If you are sure, you can increase maxwarn.\n\n",warn,ins);
2883 fprintf(stderr,"\nWarning %d;\nThe number of steps used to grow the xy-coordinates of %s (%d) is probably too small.\n"
2884 "Increase -nxy or, if you are sure, you can increase maxwarn.\n\n",warn,ins,it_xy);
2887 if( (it_z<100) && ( z_fac<0.99999999 || z_fac>1.0000001) )
2890 fprintf(stderr,"\nWarning %d;\nThe number of steps used to grow the z-coordinate of %s (%d) is probably too small.\n"
2891 "Increase -nz or, if you are sure, you can increase maxwarn.\n\n",warn,ins,it_z);
2894 if(it_xy+it_z>inputrec->nsteps)
2897 fprintf(stderr,"\nWarning %d:\nThe number of growth steps (-nxy + -nz) is larger than the number of steps in the tpr.\n"
2898 "If you are sure, you can increase maxwarn.\n\n",warn);
2902 if( inputrec->opts.ngfrz==1)
2903 gmx_fatal(FARGS,"You did not specify \"%s\" as a freezegroup.",ins);
2904 for(i=0;i<inputrec->opts.ngfrz;i++)
2906 tmp_id = mtop->groups.grps[egcFREEZE].nm_ind[i];
2907 if(ins_grp_id==tmp_id)
2914 gmx_fatal(FARGS,"\"%s\" not as freezegroup defined in the mdp-file.",ins);
2917 if( inputrec->opts.nFreeze[fr_i][i] != 1)
2918 gmx_fatal(FARGS,"freeze dimensions for %s are not Y Y Y\n",ins);
2920 ng = groups->grps[egcENER].nr;
2922 gmx_input("No energy groups defined. This is necessary for energy exclusion in the freeze group");
2928 if (inputrec->opts.egp_flags[ng*i+j] == EGP_EXCL)
2931 if ( (groups->grps[egcENER].nm_ind[i] != ins_grp_id) || (groups->grps[egcENER].nm_ind[j] != ins_grp_id) )
2932 gmx_fatal(FARGS,"Energy exclusions \"%s\" and \"%s\" do not match the group to embed \"%s\"",
2933 *groups->grpname[groups->grps[egcENER].nm_ind[i]],
2934 *groups->grpname[groups->grps[egcENER].nm_ind[j]],ins);
2939 gmx_input("No energy exclusion groups defined. This is necessary for energy exclusion in the freeze group");
2941 /* Set all atoms in box*/
2942 /*set_inbox(state->natoms,state->x);*/
2944 /* Guess the area the protein will occupy in the membrane plane Calculate area per lipid*/
2946 ins_nat = init_ins_at(ins_at,rest_at,state,pos_ins,groups,ins_grp_id,xy_max);
2947 /* Check moleculetypes in insertion group */
2948 check_types(ins_at,rest_at,mtop);
2950 mem_nat = init_mem_at(mem_p,mtop,state->x,state->box,pos_ins);
2952 prot_area = est_prot_area(pos_ins,state->x,ins_at,mem_p);
2953 if ( (prot_area>7.5) && ( (state->box[XX][XX]*state->box[YY][YY]-state->box[XX][YY]*state->box[YY][XX])<50) )
2956 fprintf(stderr,"\nWarning %d:\nThe xy-area is very small compared to the area of the protein.\n"
2957 "This might cause pressure problems during the growth phase. Just try with\n"
2958 "current setup (-maxwarn + 1), but if pressure problems occur, lower the\n"
2959 "compressibility in the mdp-file or use no pressure coupling at all.\n\n",warn);
2962 gmx_fatal(FARGS,"Too many warnings.\n");
2964 printf("The estimated area of the protein in the membrane is %.3f nm^2\n",prot_area);
2965 printf("\nThere are %d lipids in the membrane part that overlaps the protein.\nThe area per lipid is %.4f nm^2.\n",mem_p->nmol,mem_p->lip_area);
2967 /* Maximum number of lipids to be removed*/
2968 max_lip_rm=(int)(2*prot_area/mem_p->lip_area);
2969 printf("Maximum number of lipids that will be removed is %d.\n",max_lip_rm);
2971 printf("\nWill resize the protein by a factor of %.3f in the xy plane and %.3f in the z direction.\n"
2972 "This resizing will be done with respect to the geometrical center of all protein atoms\n"
2973 "that span the membrane region, i.e. z between %.3f and %.3f\n\n",xy_fac,z_fac,mem_p->zmin,mem_p->zmax);
2975 /* resize the protein by xy and by z if necessary*/
2976 snew(r_ins,ins_at->nr);
2977 init_resize(ins_at,r_ins,pos_ins,mem_p,state->x,bALLOW_ASYMMETRY);
2978 fac[0]=fac[1]=xy_fac;
2981 xy_step =(xy_max-xy_fac)/(double)(it_xy);
2982 z_step =(z_max-z_fac)/(double)(it_z-1);
2984 resize(ins_at,r_ins,state->x,pos_ins,fac);
2986 /* remove overlapping lipids and water from the membrane box*/
2987 /*mark molecules to be removed*/
2989 set_pbc(pbc,inputrec->ePBC,state->box);
2992 lip_rm = gen_rm_list(rm_p,ins_at,rest_at,pbc,mtop,state->x, r_ins, mem_p,pos_ins,probe_rad,low_up_rm,bALLOW_ASYMMETRY);
2993 lip_rm -= low_up_rm;
2996 for(i=0;i<rm_p->nr;i++)
2997 fprintf(fplog,"rm mol %d\n",rm_p->mol[i]);
2999 for(i=0;i<mtop->nmolblock;i++)
3002 for(j=0;j<rm_p->nr;j++)
3003 if(rm_p->block[j]==i)
3005 printf("Will remove %d %s molecules\n",ntype,*(mtop->moltype[mtop->molblock[i].type].name));
3008 if(lip_rm>max_lip_rm)
3011 fprintf(stderr,"\nWarning %d:\nTrying to remove a larger lipid area than the estimated protein area\n"
3012 "Try making the -xyinit resize factor smaller. If you are sure about this increase maxwarn.\n\n",warn);
3015 /*remove all lipids and waters overlapping and update all important structures*/
3016 rm_group(inputrec,groups,mtop,rm_p,state,ins_at,pos_ins);
3018 rm_bonded_at = rm_bonded(ins_at,mtop);
3019 if (rm_bonded_at != ins_at->nr)
3021 fprintf(stderr,"Warning: The number of atoms for which the bonded interactions are removed is %d, "
3022 "while %d atoms are embedded. Make sure that the atoms to be embedded are not in the same"
3023 "molecule type as atoms that are not to be embedded.\n",rm_bonded_at,ins_at->nr);
3027 gmx_fatal(FARGS,"Too many warnings.\nIf you are sure these warnings are harmless, you can increase -maxwarn");
3031 if (ftp2bSet(efTOP,nfile,fnm))
3032 top_update(opt2fn("-p",nfile,fnm),ins,rm_p,mtop);
3040 fcRegisterSteps(inputrec->nsteps,inputrec->init_step);
3043 /* NMR restraints must be initialized before load_checkpoint,
3044 * since with time averaging the history is added to t_state.
3045 * For proper consistency check we therefore need to extend
3047 * So the PME-only nodes (if present) will also initialize
3048 * the distance restraints.
3052 /* This needs to be called before read_checkpoint to extend the state */
3053 init_disres(fplog,mtop,inputrec,cr,Flags & MD_PARTDEC,fcd,state);
3055 if (gmx_mtop_ftype_count(mtop,F_ORIRES) > 0)
3057 if (PAR(cr) && !(Flags & MD_PARTDEC))
3059 gmx_fatal(FARGS,"Orientation restraints do not work (yet) with domain decomposition, use particle decomposition (mdrun option -pd)");
3061 /* Orientation restraints */
3064 init_orires(fplog,mtop,state->x,inputrec,cr->ms,&(fcd->orires),
3069 if (DEFORM(*inputrec))
3071 /* Store the deform reference box before reading the checkpoint */
3074 copy_mat(state->box,box);
3078 gmx_bcast(sizeof(box),box,cr);
3080 /* Because we do not have the update struct available yet
3081 * in which the reference values should be stored,
3082 * we store them temporarily in static variables.
3083 * This should be thread safe, since they are only written once
3084 * and with identical values.
3086 /* deform_init_init_step_tpx = inputrec->init_step;*/
3087 /* copy_mat(box,deform_init_box_tpx);*/
3090 if (opt2bSet("-cpi",nfile,fnm))
3092 /* Check if checkpoint file exists before doing continuation.
3093 * This way we can use identical input options for the first and subsequent runs...
3095 if( gmx_fexist_master(opt2fn_master("-cpi",nfile,fnm,cr),cr) )
3097 load_checkpoint(opt2fn_master("-cpi",nfile,fnm,cr),&fplog,
3098 cr,Flags & MD_PARTDEC,ddxyz,
3099 inputrec,state,&bReadRNG,&bReadEkin,
3100 (Flags & MD_APPENDFILES));
3104 Flags |= MD_READ_RNG;
3108 Flags |= MD_READ_EKIN;
3113 if ((MASTER(cr) || (Flags & MD_SEPPOT)) && (Flags & MD_APPENDFILES))
3115 gmx_log_open(ftp2fn(efLOG,nfile,fnm),cr,!(Flags & MD_SEPPOT),
3121 copy_mat(state->box,box);
3126 gmx_bcast(sizeof(box),box,cr);
3129 if (bVerbose && SIMMASTER(cr))
3131 fprintf(stderr,"Loaded with Money\n\n");
3134 if (PAR(cr) && !((Flags & MD_PARTDEC) || EI_TPI(inputrec->eI)))
3136 cr->dd = init_domain_decomposition(fplog,cr,Flags,ddxyz,rdd,rconstr,
3137 dddlb_opt,dlb_scale,
3141 &ddbox,&npme_major,&npme_minor);
3143 make_dd_communicators(fplog,cr,dd_node_order);
3145 /* Set overallocation to avoid frequent reallocation of arrays */
3146 set_over_alloc_dd(TRUE);
3150 /* PME, if used, is done on all nodes with 1D decomposition */
3152 cr->duty = (DUTY_PP | DUTY_PME);
3153 npme_major = cr->nnodes;
3156 if (inputrec->ePBC == epbcSCREW)
3159 "pbc=%s is only implemented with domain decomposition",
3160 epbc_names[inputrec->ePBC]);
3166 /* After possible communicator splitting in make_dd_communicators.
3167 * we can set up the intra/inter node communication.
3169 gmx_setup_nodecomm(fplog,cr);
3172 /* get number of OpenMP/PME threads
3173 * env variable should be read only on one node to make sure it is identical everywhere */
3175 if (EEL_PME(inputrec->coulombtype))
3180 omp_nthreads = omp_get_max_threads();
3181 if ((ptr=getenv("GMX_PME_NTHREADS")) != NULL)
3183 sscanf(ptr,"%d",&omp_nthreads);
3187 fprintf(fplog,"Using %d threads for PME\n",omp_nthreads);
3192 gmx_bcast_sim(sizeof(omp_nthreads),&omp_nthreads,cr);
3197 wcycle = wallcycle_init(fplog,resetstep,cr, omp_nthreads);
3200 /* Master synchronizes its value of reset_counters with all nodes
3201 * including PME only nodes */
3202 reset_counters = wcycle_get_reset_counters(wcycle);
3203 gmx_bcast_sim(sizeof(reset_counters),&reset_counters,cr);
3204 wcycle_set_reset_counters(wcycle, reset_counters);
3209 if (cr->duty & DUTY_PP)
3211 /* For domain decomposition we allocate dynamically
3212 * in dd_partition_system.
3214 if (DOMAINDECOMP(cr))
3216 bcast_state_setup(cr,state);
3226 bcast_state(cr,state,TRUE);
3230 /* Dihedral Restraints */
3231 if (gmx_mtop_ftype_count(mtop,F_DIHRES) > 0)
3233 init_dihres(fplog,mtop,inputrec,fcd);
3236 /* Initiate forcerecord */
3238 init_forcerec(fplog,oenv,fr,fcd,inputrec,mtop,cr,box,FALSE,
3239 opt2fn("-table",nfile,fnm),
3240 opt2fn("-tabletf",nfile,fnm),
3241 opt2fn("-tablep",nfile,fnm),
3242 opt2fn("-tableb",nfile,fnm),FALSE,pforce);
3244 /* version for PCA_NOT_READ_NODE (see md.c) */
3245 /*init_forcerec(fplog,fr,fcd,inputrec,mtop,cr,box,FALSE,
3246 "nofile","nofile","nofile","nofile",FALSE,pforce);
3248 fr->bSepDVDL = ((Flags & MD_SEPPOT) == MD_SEPPOT);
3250 /* Initialize QM-MM */
3253 init_QMMMrec(cr,box,mtop,inputrec,fr);
3256 /* Initialize the mdatoms structure.
3257 * mdatoms is not filled with atom data,
3258 * as this can not be done now with domain decomposition.
3260 mdatoms = init_mdatoms(fplog,mtop,inputrec->efep!=efepNO);
3262 /* Initialize the virtual site communication */
3263 vsite = init_vsite(mtop,cr);
3265 calc_shifts(box,fr->shift_vec);
3267 /* With periodic molecules the charge groups should be whole at start up
3268 * and the virtual sites should not be far from their proper positions.
3270 if (!inputrec->bContinuation && MASTER(cr) &&
3271 !(inputrec->ePBC != epbcNONE && inputrec->bPeriodicMols))
3273 /* Make molecules whole at start of run */
3274 if (fr->ePBC != epbcNONE)
3276 do_pbc_first_mtop(fplog,inputrec->ePBC,box,mtop,state->x);
3280 /* Correct initial vsite positions are required
3281 * for the initial distribution in the domain decomposition
3282 * and for the initial shell prediction.
3284 construct_vsites_mtop(fplog,vsite,mtop,state->x);
3288 /* Initiate PPPM if necessary */
3289 if (fr->eeltype == eelPPPM)
3291 if (mdatoms->nChargePerturbed)
3293 gmx_fatal(FARGS,"Free energy with %s is not implemented",
3294 eel_names[fr->eeltype]);
3296 status = gmx_pppm_init(fplog,cr,oenv,FALSE,TRUE,box,
3297 getenv("GMXGHAT"),inputrec, (Flags & MD_REPRODUCIBLE));
3300 gmx_fatal(FARGS,"Error %d initializing PPPM",status);
3304 if (EEL_PME(fr->eeltype))
3306 ewaldcoeff = fr->ewaldcoeff;
3307 pmedata = &fr->pmedata;
3316 /* This is a PME only node */
3318 /* We don't need the state */
3321 ewaldcoeff = calc_ewaldcoeff(inputrec->rcoulomb, inputrec->ewald_rtol);
3325 /* Initiate PME if necessary,
3326 * either on all nodes or on dedicated PME nodes only. */
3327 if (EEL_PME(inputrec->coulombtype))
3331 nChargePerturbed = mdatoms->nChargePerturbed;
3333 if (cr->npmenodes > 0)
3335 /* The PME only nodes need to know nChargePerturbed */
3336 gmx_bcast_sim(sizeof(nChargePerturbed),&nChargePerturbed,cr);
3340 /*set CPU affinity*/
3346 MPI_Comm comm_intra; /*intra communicator (but different to nc.comm_intra includes PME nodes)*/
3347 MPI_Comm_split(MPI_COMM_WORLD,gmx_hostname_num(),gmx_node_rank(),&comm_intra);
3348 int local_omp_nthreads = (cr->duty & DUTY_PME) ? omp_nthreads : 1; /*threads on this node*/
3349 MPI_Scan(&local_omp_nthreads,&core, 1, MPI_INT, MPI_SUM, comm_intra);
3350 core-=local_omp_nthreads; /*make exclusive scan*/
3351 #pragma omp parallel firstprivate(core) num_threads(local_omp_nthreads)
3355 core+=omp_get_thread_num();
3356 CPU_SET(core,&mask);
3357 sched_setaffinity((pid_t) syscall (SYS_gettid),sizeof(cpu_set_t),&mask);
3362 #endif /*GMX_OPENMP*/
3364 if (cr->duty & DUTY_PME)
3366 status = gmx_pme_init(pmedata,cr,npme_major,npme_minor,inputrec,
3367 mtop ? mtop->natoms : 0,nChargePerturbed,
3368 (Flags & MD_REPRODUCIBLE),omp_nthreads);
3371 gmx_fatal(FARGS,"Error %d initializing PME",status);
3377 /* if (integrator[inputrec->eI].func == do_md
3380 integrator[inputrec->eI].func == do_md_openmm
3384 /* Turn on signal handling on all nodes */
3386 * (A user signal from the PME nodes (if any)
3387 * is communicated to the PP nodes.
3389 signal_handler_install();
3392 if (cr->duty & DUTY_PP)
3394 if (inputrec->ePull != epullNO)
3396 /* Initialize pull code */
3397 init_pull(fplog,inputrec,nfile,fnm,mtop,cr,oenv,
3398 EI_DYNAMICS(inputrec->eI) && MASTER(cr),Flags);
3401 constr = init_constraints(fplog,mtop,inputrec,ed,state,cr);
3403 if (DOMAINDECOMP(cr))
3405 dd_init_bondeds(fplog,cr->dd,mtop,vsite,constr,inputrec,
3406 Flags & MD_DDBONDCHECK,fr->cginfo_mb);
3408 set_dd_parameters(fplog,cr->dd,dlb_scale,inputrec,fr,&ddbox);
3410 setup_dd_grid(fplog,cr->dd);
3413 /* Now do whatever the user wants us to do (how flexible...) */
3414 do_md_membed(fplog,cr,nfile,fnm,
3415 oenv,bVerbose,bCompact,
3418 nstepout,inputrec,mtop,
3420 mdatoms,nrnb,wcycle,ed,fr,
3421 repl_ex_nst,repl_ex_seed,
3422 cpt_period,max_hours,
3426 fac, r_ins, pos_ins, ins_at,
3427 xy_step, z_step, it_xy, it_z);
3429 if (inputrec->ePull != epullNO)
3431 finish_pull(fplog,inputrec->pull);
3437 gmx_pmeonly(*pmedata,cr,nrnb,wcycle,ewaldcoeff,FALSE,inputrec);
3440 if (EI_DYNAMICS(inputrec->eI) || EI_TPI(inputrec->eI))
3442 /* Some timing stats */
3445 if (runtime.proc == 0)
3447 runtime.proc = runtime.real;
3456 wallcycle_stop(wcycle,ewcRUN);
3458 /* Finish up, write some stuff
3459 * if rerunMD, don't write last frame again
3461 finish_run(fplog,cr,ftp2fn(efSTO,nfile,fnm),
3462 inputrec,nrnb,wcycle,&runtime,
3463 EI_DYNAMICS(inputrec->eI) && !MULTISIM(cr));
3465 /* Does what it says */
3466 print_date_and_time(fplog,cr->nodeid,"Finished mdrun",&runtime);
3468 /* Close logfile already here if we were appending to it */
3469 if (MASTER(cr) && (Flags & MD_APPENDFILES))
3471 gmx_log_close(fplog);
3479 rc=(int)gmx_get_stop_condition();
3484 int gmx_membed(int argc,char *argv[])
3486 const char *desc[] = {
3487 "[TT]g_membed[tt] embeds a membrane protein into an equilibrated lipid bilayer at the position",
3488 "and orientation specified by the user.[PAR]",
3489 "SHORT MANUAL[BR]------------[BR]",
3490 "The user should merge the structure files of the protein and membrane (+solvent), creating a",
3491 "single structure file with the protein overlapping the membrane at the desired position and",
3492 "orientation. The box size is taken from the membrane structure file. The corresponding topology",
3493 "files should also be merged. Consecutively, create a [TT].tpr[tt] file (input for [TT]g_membed[tt]) from these files,"
3494 "with the following options included in the [TT].mdp[tt] file.[BR]",
3495 " - [TT]integrator = md[tt][BR]",
3496 " - [TT]energygrp = Protein[tt] (or other group that you want to insert)[BR]",
3497 " - [TT]freezegrps = Protein[tt][BR]",
3498 " - [TT]freezedim = Y Y Y[tt][BR]",
3499 " - [TT]energygrp_excl = Protein Protein[tt][BR]",
3500 "The output is a structure file containing the protein embedded in the membrane. If a topology",
3501 "file is provided, the number of lipid and ",
3502 "solvent molecules will be updated to match the new structure file.[BR]",
3503 "For a more extensive manual see Wolf et al, J Comp Chem 31 (2010) 2169-2174, Appendix.[PAR]",
3504 "SHORT METHOD DESCRIPTION[BR]",
3505 "------------------------[BR]",
3506 "1. The protein is resized around its center of mass by a factor [TT]-xy[tt] in the xy-plane",
3507 "(the membrane plane) and a factor [TT]-z[tt] in the [IT]z[it]-direction (if the size of the",
3508 "protein in the z-direction is the same or smaller than the width of the membrane, a",
3509 "[TT]-z[tt] value larger than 1 can prevent that the protein will be enveloped by the lipids).[BR]",
3510 "2. All lipid and solvent molecules overlapping with the resized protein are removed. All",
3511 "intraprotein interactions are turned off to prevent numerical issues for small values of [TT]-xy[tt]",
3512 " or [TT]-z[tt][BR]",
3513 "3. One md step is performed.[BR]",
3514 "4. The resize factor ([TT]-xy[tt] or [TT]-z[tt]) is incremented by a small amount ((1-xy)/nxy or (1-z)/nz) and the",
3515 "protein is resized again around its center of mass. The resize factor for the xy-plane",
3516 "is incremented first. The resize factor for the z-direction is not changed until the [TT]-xy[tt] factor",
3517 "is 1 (thus after [TT]-nxy[tt] iterations).[BR]",
3518 "5. Repeat step 3 and 4 until the protein reaches its original size ([TT]-nxy[tt] + [TT]-nz[tt] iterations).[BR]",
3519 "For a more extensive method description see Wolf et al, J Comp Chem, 31 (2010) 2169-2174.[PAR]",
3521 " - Protein can be any molecule you want to insert in the membrane.[BR]",
3522 " - It is recommended to perform a short equilibration run after the embedding",
3523 "(see Wolf et al, J Comp Chem 31 (2010) 2169-2174), to re-equilibrate the membrane. Clearly",
3524 "protein equilibration might require longer.[PAR]"
3528 { efTPX, "-f", "into_mem", ffREAD },
3529 { efNDX, "-n", "index", ffOPTRD },
3530 { efTOP, "-p", "topol", ffOPTRW },
3531 { efTRN, "-o", NULL, ffWRITE },
3532 { efXTC, "-x", NULL, ffOPTWR },
3533 { efCPT, "-cpi", NULL, ffOPTRD },
3534 { efCPT, "-cpo", NULL, ffOPTWR },
3535 { efSTO, "-c", "membedded", ffWRITE },
3536 { efEDR, "-e", "ener", ffWRITE },
3537 { efLOG, "-g", "md", ffWRITE },
3538 { efEDI, "-ei", "sam", ffOPTRD },
3539 { efTRX, "-rerun", "rerun", ffOPTRD },
3540 { efXVG, "-table", "table", ffOPTRD },
3541 { efXVG, "-tablep", "tablep", ffOPTRD },
3542 { efXVG, "-tableb", "table", ffOPTRD },
3543 { efXVG, "-dhdl", "dhdl", ffOPTWR },
3544 { efXVG, "-field", "field", ffOPTWR },
3545 { efXVG, "-table", "table", ffOPTRD },
3546 { efXVG, "-tablep", "tablep", ffOPTRD },
3547 { efXVG, "-tableb", "table", ffOPTRD },
3548 { efTRX, "-rerun", "rerun", ffOPTRD },
3549 { efXVG, "-tpi", "tpi", ffOPTWR },
3550 { efXVG, "-tpid", "tpidist", ffOPTWR },
3551 { efEDI, "-ei", "sam", ffOPTRD },
3552 { efEDO, "-eo", "sam", ffOPTWR },
3553 { efGCT, "-j", "wham", ffOPTRD },
3554 { efGCT, "-jo", "bam", ffOPTWR },
3555 { efXVG, "-ffout", "gct", ffOPTWR },
3556 { efXVG, "-devout", "deviatie", ffOPTWR },
3557 { efXVG, "-runav", "runaver", ffOPTWR },
3558 { efXVG, "-px", "pullx", ffOPTWR },
3559 { efXVG, "-pf", "pullf", ffOPTWR },
3560 { efMTX, "-mtx", "nm", ffOPTWR },
3561 { efNDX, "-dn", "dipole", ffOPTWR },
3562 { efRND, "-multidir",NULL, ffOPTRDMULT}
3564 #define NFILE asize(fnm)
3566 /* Command line options ! */
3567 gmx_bool bCart = FALSE;
3568 gmx_bool bPPPME = FALSE;
3569 gmx_bool bPartDec = FALSE;
3570 gmx_bool bDDBondCheck = TRUE;
3571 gmx_bool bDDBondComm = TRUE;
3572 gmx_bool bVerbose = FALSE;
3573 gmx_bool bCompact = TRUE;
3574 gmx_bool bSepPot = FALSE;
3575 gmx_bool bRerunVSite = FALSE;
3576 gmx_bool bIonize = FALSE;
3577 gmx_bool bConfout = TRUE;
3578 gmx_bool bReproducible = FALSE;
3582 int nstglobalcomm=-1;
3584 int repl_ex_seed=-1;
3586 int nthreads=0; /* set to determine # of threads automatically */
3589 rvec realddxyz={0,0,0};
3590 const char *ddno_opt[ddnoNR+1] =
3591 { NULL, "interleave", "pp_pme", "cartesian", NULL };
3592 const char *dddlb_opt[] =
3593 { NULL, "auto", "no", "yes", NULL };
3594 real rdd=0.0,rconstr=0.0,dlb_scale=0.8,pforce=-1;
3595 char *ddcsx=NULL,*ddcsy=NULL,*ddcsz=NULL;
3596 real cpt_period=15.0,max_hours=-1;
3597 gmx_bool bAppendFiles=TRUE,bAddPart=TRUE;
3598 gmx_bool bResetCountersHalfWay=FALSE;
3599 output_env_t oenv=NULL;
3600 const char *deviceOptions = "";
3608 real probe_rad = 0.22;
3612 gmx_bool bALLOW_ASYMMETRY=FALSE;
3615 /* arguments relevant to OPENMM only*/
3617 gmx_input("g_membed not functional in openmm");
3621 { "-xyinit", FALSE, etREAL, {&xy_fac}, "Resize factor for the protein in the xy dimension before starting embedding" },
3622 { "-xyend", FALSE, etREAL, {&xy_max}, "Final resize factor in the xy dimension" },
3623 { "-zinit", FALSE, etREAL, {&z_fac}, "Resize factor for the protein in the z dimension before starting embedding" },
3624 { "-zend", FALSE, etREAL, {&z_max}, "Final resize faction in the z dimension" },
3625 { "-nxy", FALSE, etINT, {&it_xy}, "Number of iteration for the xy dimension" },
3626 { "-nz", FALSE, etINT, {&it_z}, "Number of iterations for the z dimension" },
3627 { "-rad", FALSE, etREAL, {&probe_rad}, "Probe radius to check for overlap between the group to embed and the membrane"},
3628 { "-pieces", FALSE, etINT, {&pieces}, "Perform piecewise resize. Select parts of the group to insert and resize these with respect to their own geometrical center." },
3629 { "-asymmetry",FALSE, etBOOL,{&bALLOW_ASYMMETRY}, "Allow asymmetric insertion, i.e. the number of lipids removed from the upper and lower leaflet will not be checked." },
3630 { "-ndiff" , FALSE, etINT, {&low_up_rm}, "Number of lipids that will additionally be removed from the lower (negative number) or upper (positive number) membrane leaflet." },
3631 { "-maxwarn", FALSE, etINT, {&maxwarn}, "Maximum number of warning allowed" },
3632 { "-pd", FALSE, etBOOL,{&bPartDec},
3633 "HIDDENUse particle decompostion" },
3634 { "-dd", FALSE, etRVEC,{&realddxyz},
3635 "HIDDENDomain decomposition grid, 0 is optimize" },
3636 { "-nt", FALSE, etINT, {&nthreads},
3637 "HIDDENNumber of threads to start (0 is guess)" },
3638 { "-npme", FALSE, etINT, {&npme},
3639 "HIDDENNumber of separate nodes to be used for PME, -1 is guess" },
3640 { "-ddorder", FALSE, etENUM, {ddno_opt},
3641 "HIDDENDD node order" },
3642 { "-ddcheck", FALSE, etBOOL, {&bDDBondCheck},
3643 "HIDDENCheck for all bonded interactions with DD" },
3644 { "-ddbondcomm", FALSE, etBOOL, {&bDDBondComm},
3645 "HIDDENUse special bonded atom communication when [TT]-rdd[tt] > cut-off" },
3646 { "-rdd", FALSE, etREAL, {&rdd},
3647 "HIDDENThe maximum distance for bonded interactions with DD (nm), 0 is determine from initial coordinates" },
3648 { "-rcon", FALSE, etREAL, {&rconstr},
3649 "HIDDENMaximum distance for P-LINCS (nm), 0 is estimate" },
3650 { "-dlb", FALSE, etENUM, {dddlb_opt},
3651 "HIDDENDynamic load balancing (with DD)" },
3652 { "-dds", FALSE, etREAL, {&dlb_scale},
3653 "HIDDENMinimum allowed dlb scaling of the DD cell size" },
3654 { "-ddcsx", FALSE, etSTR, {&ddcsx},
3655 "HIDDENThe DD cell sizes in x" },
3656 { "-ddcsy", FALSE, etSTR, {&ddcsy},
3657 "HIDDENThe DD cell sizes in y" },
3658 { "-ddcsz", FALSE, etSTR, {&ddcsz},
3659 "HIDDENThe DD cell sizes in z" },
3660 { "-gcom", FALSE, etINT,{&nstglobalcomm},
3661 "HIDDENGlobal communication frequency" },
3662 { "-compact", FALSE, etBOOL,{&bCompact},
3663 "Write a compact log file" },
3664 { "-seppot", FALSE, etBOOL, {&bSepPot},
3665 "HIDDENWrite separate V and dVdl terms for each interaction type and node to the log file(s)" },
3666 { "-pforce", FALSE, etREAL, {&pforce},
3667 "HIDDENPrint all forces larger than this (kJ/mol nm)" },
3668 { "-reprod", FALSE, etBOOL,{&bReproducible},
3669 "HIDDENTry to avoid optimizations that affect binary reproducibility" },
3670 { "-multi", FALSE, etINT,{&nmultisim},
3671 "HIDDENDo multiple simulations in parallel" },
3672 { "-replex", FALSE, etINT, {&repl_ex_nst},
3673 "HIDDENAttempt replica exchange periodically with this period (steps)" },
3674 { "-reseed", FALSE, etINT, {&repl_ex_seed},
3675 "HIDDENSeed for replica exchange, -1 is generate a seed" },
3676 { "-rerunvsite", FALSE, etBOOL, {&bRerunVSite},
3677 "HIDDENRecalculate virtual site coordinates with [TT]-rerun[tt]" },
3678 { "-ionize", FALSE, etBOOL,{&bIonize},
3679 "HIDDENDo a simulation including the effect of an X-Ray bombardment on your system" },
3680 { "-confout", TRUE, etBOOL, {&bConfout},
3681 "HIDDENWrite the last configuration with [TT]-c[tt] and force checkpointing at the last step" },
3682 { "-stepout", FALSE, etINT, {&nstepout},
3683 "HIDDENFrequency of writing the remaining runtime" },
3684 { "-resetstep", FALSE, etINT, {&resetstep},
3685 "HIDDENReset cycle counters after these many time steps" },
3686 { "-resethway", FALSE, etBOOL, {&bResetCountersHalfWay},
3687 "HIDDENReset the cycle counters after half the number of steps or halfway [TT]-maxh[tt]" },
3688 { "-v", FALSE, etBOOL,{&bVerbose},
3689 "Be loud and noisy" },
3690 { "-maxh", FALSE, etREAL, {&max_hours},
3691 "HIDDENTerminate after 0.99 times this time (hours)" },
3692 { "-cpt", FALSE, etREAL, {&cpt_period},
3693 "HIDDENCheckpoint interval (minutes)" },
3694 { "-append", FALSE, etBOOL, {&bAppendFiles},
3695 "HIDDENAppend to previous output files when continuing from checkpoint" },
3696 { "-addpart", FALSE, etBOOL, {&bAddPart},
3697 "HIDDENAdd the simulation part number to all output files when continuing from checkpoint" },
3700 unsigned long Flags, PCA_Flags;
3703 gmx_bool HaveCheckpoint;
3704 FILE *fplog,*fptest;
3705 int sim_part,sim_part_fn;
3706 const char *part_suffix=".part";
3707 char suffix[STRLEN];
3709 char **multidir=NULL;
3711 cr = init_par(&argc,&argv);
3713 PCA_Flags = (PCA_KEEP_ARGS | PCA_NOEXIT_ON_ARGS | PCA_CAN_SET_DEFFNM
3714 | (MASTER(cr) ? 0 : PCA_QUIET));
3717 /* Comment this in to do fexist calls only on master
3718 * works not with rerun or tables at the moment
3719 * also comment out the version of init_forcerec in md.c
3720 * with NULL instead of opt2fn
3725 PCA_Flags |= PCA_NOT_READ_NODE;
3729 parse_common_args(&argc,argv,PCA_Flags, NFILE,fnm,asize(pa),pa,
3730 asize(desc),desc,0,NULL, &oenv);
3732 /* we set these early because they might be used in init_multisystem()
3733 Note that there is the potential for npme>nnodes until the number of
3734 threads is set later on, if there's thread parallelization. That shouldn't
3735 lead to problems. */
3736 dd_node_order = nenum(ddno_opt);
3737 cr->npmenodes = npme;
3739 #ifdef GMX_THREAD_MPI
3740 /* now determine the number of threads automatically. The threads are
3741 only started at mdrunner_threads, though. */
3744 nthreads=tMPI_Thread_get_hw_number();
3750 /* now check the -multi and -multidir option */
3751 if (opt2bSet("-multidir", NFILE, fnm))
3756 gmx_fatal(FARGS, "mdrun -multi and -multidir options are mutually exclusive.");
3758 nmultisim = opt2fns(&multidir, "-multidir", NFILE, fnm);
3762 if (repl_ex_nst != 0 && nmultisim < 2)
3763 gmx_fatal(FARGS,"Need at least two replicas for replica exchange (option -multi)");
3765 if (nmultisim > 1) {
3766 #ifndef GMX_THREAD_MPI
3767 gmx_bool bParFn = (multidir == NULL);
3768 init_multisystem(cr,nmultisim,multidir,NFILE,fnm,TRUE);
3770 gmx_fatal(FARGS,"mdrun -multi is not supported with the thread library.Please compile GROMACS with MPI support");
3774 /* Check if there is ANY checkpoint file available */
3776 sim_part_fn = sim_part;
3777 if (opt2bSet("-cpi",NFILE,fnm))
3780 read_checkpoint_simulation_part(opt2fn_master("-cpi", NFILE,fnm,cr),
3781 &sim_part_fn,NULL,cr,
3782 bAppendFiles,NFILE,fnm,
3783 part_suffix,&bAddPart);
3784 if (sim_part_fn==0 && MASTER(cr))
3786 fprintf(stdout,"No previous checkpoint file present, assuming this is a new run.\n");
3790 sim_part = sim_part_fn + 1;
3795 bAppendFiles = FALSE;
3800 sim_part_fn = sim_part;
3803 if (bAddPart && sim_part_fn > 1)
3805 /* This is a continuation run, rename trajectory output files
3806 (except checkpoint files) */
3807 /* create new part name first (zero-filled) */
3808 sprintf(suffix,"%s%04d",part_suffix,sim_part_fn);
3810 add_suffix_to_output_names(fnm,NFILE,suffix);
3811 fprintf(stdout,"Checkpoint file is from part %d, new output files will be suffixed '%s'.\n",sim_part-1,suffix);
3814 Flags = opt2bSet("-rerun",NFILE,fnm) ? MD_RERUN : 0;
3815 Flags = Flags | (bSepPot ? MD_SEPPOT : 0);
3816 Flags = Flags | (bIonize ? MD_IONIZE : 0);
3817 Flags = Flags | (bPartDec ? MD_PARTDEC : 0);
3818 Flags = Flags | (bDDBondCheck ? MD_DDBONDCHECK : 0);
3819 Flags = Flags | (bDDBondComm ? MD_DDBONDCOMM : 0);
3820 Flags = Flags | (bConfout ? MD_CONFOUT : 0);
3821 Flags = Flags | (bRerunVSite ? MD_RERUN_VSITE : 0);
3822 Flags = Flags | (bReproducible ? MD_REPRODUCIBLE : 0);
3823 Flags = Flags | (bAppendFiles ? MD_APPENDFILES : 0);
3824 Flags = Flags | (sim_part>1 ? MD_STARTFROMCPT : 0);
3825 Flags = Flags | (bResetCountersHalfWay ? MD_RESETCOUNTERSHALFWAY : 0);
3828 /* We postpone opening the log file if we are appending, so we can
3829 first truncate the old log file and append to the correct position
3831 if ((MASTER(cr) || bSepPot) && !bAppendFiles)
3833 gmx_log_open(ftp2fn(efLOG,NFILE,fnm),cr,!bSepPot,Flags,&fplog);
3834 CopyRight(fplog,argv[0]);
3835 please_cite(fplog,"Hess2008b");
3836 please_cite(fplog,"Spoel2005a");
3837 please_cite(fplog,"Lindahl2001a");
3838 please_cite(fplog,"Berendsen95a");
3845 ddxyz[XX] = (int)(realddxyz[XX] + 0.5);
3846 ddxyz[YY] = (int)(realddxyz[YY] + 0.5);
3847 ddxyz[ZZ] = (int)(realddxyz[ZZ] + 0.5);
3849 /* even if nthreads = 1, we still call this one */
3851 rc = mdrunner_membed(fplog, cr, NFILE, fnm, oenv, bVerbose, bCompact,
3853 ddxyz, dd_node_order, rdd, rconstr, dddlb_opt[0], dlb_scale,
3854 ddcsx, ddcsy, ddcsz, nstepout, resetstep, nmultisim, repl_ex_nst,
3855 repl_ex_seed, pforce, cpt_period, max_hours, deviceOptions, Flags,
3856 xy_fac,xy_max,z_fac,z_max,
3857 it_xy,it_z,probe_rad,low_up_rm,
3858 pieces,bALLOW_ASYMMETRY,maxwarn);
3860 if (gmx_parallel_env_initialized())
3863 if (MULTIMASTER(cr)) {
3867 /* Log file has to be closed in mdrunner if we are appending to it
3868 (fplog not set here) */
3869 fprintf(stderr,"Please cite:\nWolf et al, J Comp Chem 31 (2010) 2169-2174.\n");
3871 if (MASTER(cr) && !bAppendFiles)
3873 gmx_log_close(fplog);