1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
34 * GROwing Monsters And Cloning Shrimps
54 #include "mtop_util.h"
58 static const char *conrmsd_nm
[] = { "Constr. rmsd", "Constr.2 rmsd" };
60 static const char *boxs_nm
[] = { "Box-X", "Box-Y", "Box-Z" };
62 static const char *tricl_boxs_nm
[] = { "Box-XX", "Box-YX", "Box-YY",
63 "Box-ZX", "Box-ZY", "Box-ZZ" };
65 static const char *vol_nm
[] = { "Volume" };
67 static const char *dens_nm
[] = {"Density" };
69 static const char *pv_nm
[] = {"pV" };
71 static const char *boxvel_nm
[] = {
72 "Box-Vel-XX", "Box-Vel-YY", "Box-Vel-ZZ",
73 "Box-Vel-YX", "Box-Vel-ZX", "Box-Vel-ZY"
76 #define NBOXS asize(boxs_nm)
77 #define NTRICLBOXS asize(tricl_boxs_nm)
79 static bool bTricl
,bDynBox
;
80 static int f_nre
=0,epc
,etc
,nCrmsd
;
82 t_mdebin
*init_mdebin(ener_file_t fp_ene
,
83 const gmx_mtop_t
*mtop
,
86 const char *ener_nm
[F_NRE
];
87 static const char *vir_nm
[] = {
88 "Vir-XX", "Vir-XY", "Vir-XZ",
89 "Vir-YX", "Vir-YY", "Vir-YZ",
90 "Vir-ZX", "Vir-ZY", "Vir-ZZ"
92 static const char *sv_nm
[] = {
93 "ShakeVir-XX", "ShakeVir-XY", "ShakeVir-XZ",
94 "ShakeVir-YX", "ShakeVir-YY", "ShakeVir-YZ",
95 "ShakeVir-ZX", "ShakeVir-ZY", "ShakeVir-ZZ"
97 static const char *fv_nm
[] = {
98 "ForceVir-XX", "ForceVir-XY", "ForceVir-XZ",
99 "ForceVir-YX", "ForceVir-YY", "ForceVir-YZ",
100 "ForceVir-ZX", "ForceVir-ZY", "ForceVir-ZZ"
102 static const char *pres_nm
[] = {
103 "Pres-XX","Pres-XY","Pres-XZ",
104 "Pres-YX","Pres-YY","Pres-YZ",
105 "Pres-ZX","Pres-ZY","Pres-ZZ"
107 static const char *surft_nm
[] = {
110 static const char *mu_nm
[] = {
111 "Mu-X", "Mu-Y", "Mu-Z"
113 static const char *vcos_nm
[] = {
116 static const char *visc_nm
[] = {
119 static char *bufbaro
[] = {
124 const gmx_groups_t
*groups
;
129 int i
,j
,ni
,nj
,n
,nh
,k
,kk
,ncon
,nset
;
130 bool bBHAM
,bNoseHoover
,b14
;
134 groups
= &mtop
->groups
;
136 bBHAM
= (mtop
->ffparams
.functype
[0] == F_BHAM
);
137 b14
= (gmx_mtop_ftype_count(mtop
,F_LJ14
) > 0 ||
138 gmx_mtop_ftype_count(mtop
,F_LJC14_Q
) > 0);
140 ncon
= gmx_mtop_ftype_count(mtop
,F_CONSTR
);
141 nset
= gmx_mtop_ftype_count(mtop
,F_SETTLE
);
142 md
->bConstr
= (ncon
> 0 || nset
> 0);
143 md
->bConstrVir
= FALSE
;
145 if (ncon
> 0 && ir
->eConstrAlg
== econtLINCS
) {
151 md
->bConstrVir
= (getenv("GMX_CONSTRAINTVIR") != NULL
);
156 /* Energy monitoring */
162 for(i
=0; i
<F_NRE
; i
++) {
163 md
->bEner
[i
] = FALSE
;
165 md
->bEner
[i
] = !bBHAM
;
166 else if (i
== F_BHAM
)
167 md
->bEner
[i
] = bBHAM
;
169 md
->bEner
[i
] = ir
->bQMMM
;
170 else if (i
== F_COUL_LR
)
171 md
->bEner
[i
] = (ir
->rcoulomb
> ir
->rlist
);
172 else if (i
== F_LJ_LR
)
173 md
->bEner
[i
] = (!bBHAM
&& ir
->rvdw
> ir
->rlist
);
174 else if (i
== F_BHAM_LR
)
175 md
->bEner
[i
] = (bBHAM
&& ir
->rvdw
> ir
->rlist
);
176 else if (i
== F_RF_EXCL
)
177 md
->bEner
[i
] = (EEL_RF(ir
->coulombtype
) && ir
->coulombtype
!= eelRF_NEC
);
178 else if (i
== F_COUL_RECIP
)
179 md
->bEner
[i
] = EEL_FULL(ir
->coulombtype
);
180 else if (i
== F_LJ14
)
182 else if (i
== F_COUL14
)
184 else if (i
== F_LJC14_Q
|| i
== F_LJC_PAIRS_NB
)
185 md
->bEner
[i
] = FALSE
;
186 else if ((i
== F_DVDL
) || (i
== F_DKDL
))
187 md
->bEner
[i
] = (ir
->efep
!= efepNO
);
188 else if (i
== F_DHDL_CON
)
189 md
->bEner
[i
] = (ir
->efep
!= efepNO
&& md
->bConstr
);
190 else if ((interaction_function
[i
].flags
& IF_VSITE
) ||
191 (i
== F_CONSTR
) || (i
== F_CONSTRNC
) || (i
== F_SETTLE
))
192 md
->bEner
[i
] = FALSE
;
193 else if ((i
== F_COUL_SR
) || (i
== F_EPOT
) || (i
== F_PRES
) || (i
==F_EQM
))
195 else if ((i
== F_ETOT
) || (i
== F_EKIN
) || (i
== F_TEMP
))
196 md
->bEner
[i
] = EI_DYNAMICS(ir
->eI
);
198 md
->bEner
[i
] = (EI_DYNAMICS(ir
->eI
) && getenv("GMX_VIRIAL_TEMPERATURE"));
199 else if (i
== F_DISPCORR
|| i
== F_PDISPCORR
)
200 md
->bEner
[i
] = (ir
->eDispCorr
!= edispcNO
);
201 else if (i
== F_DISRESVIOL
)
202 md
->bEner
[i
] = (gmx_mtop_ftype_count(mtop
,F_DISRES
) > 0);
203 else if (i
== F_ORIRESDEV
)
204 md
->bEner
[i
] = (gmx_mtop_ftype_count(mtop
,F_ORIRES
) > 0);
205 else if (i
== F_CONNBONDS
)
206 md
->bEner
[i
] = FALSE
;
207 else if (i
== F_COM_PULL
)
208 md
->bEner
[i
] = (ir
->ePull
== epullUMBRELLA
|| ir
->ePull
== epullCONST_F
|| ir
->bRot
);
209 else if (i
== F_ECONSERVED
)
210 md
->bEner
[i
] = ((ir
->etc
== etcNOSEHOOVER
|| ir
->etc
== etcVRESCALE
) &&
211 (ir
->epc
== epcNO
|| ir
->epc
==epcMTTK
));
213 md
->bEner
[i
] = (gmx_mtop_ftype_count(mtop
,i
) > 0);
217 for(i
=0; i
<F_NRE
; i
++)
221 /* FIXME: The constness should not be cast away */
222 /*ener_nm[f_nre]=(char *)interaction_function[i].longname;*/
223 ener_nm
[md
->f_nre
]=interaction_function
[i
].longname
;
233 md
->ref_p
[i
][j
] = ir
->ref_p
[i
][j
];
236 md
->bTricl
= TRICLINIC(ir
->compress
) || TRICLINIC(ir
->deform
);
237 md
->bDynBox
= DYNAMIC_BOX(*ir
);
239 md
->bNHC_trotter
= IR_NVT_TROTTER(ir
);
241 md
->ebin
= mk_ebin();
242 /* Pass NULL for unit to let get_ebin_space determine the units
243 * for interaction_function[i].longname
245 md
->ie
= get_ebin_space(md
->ebin
,md
->f_nre
,ener_nm
,NULL
);
248 /* This should be called directly after the call for md->ie,
249 * such that md->iconrmsd follows directly in the list.
251 md
->iconrmsd
= get_ebin_space(md
->ebin
,md
->nCrmsd
,conrmsd_nm
,"");
255 md
->ib
= get_ebin_space(md
->ebin
, md
->bTricl
? NTRICLBOXS
:
256 NBOXS
, md
->bTricl
? tricl_boxs_nm
: boxs_nm
,
258 md
->ivol
= get_ebin_space(md
->ebin
, 1, vol_nm
, unit_volume
);
259 md
->idens
= get_ebin_space(md
->ebin
, 1, dens_nm
, unit_density_SI
);
260 md
->ipv
= get_ebin_space(md
->ebin
, 1, pv_nm
, unit_energy
);
264 md
->isvir
= get_ebin_space(md
->ebin
,asize(sv_nm
),sv_nm
,unit_energy
);
265 md
->ifvir
= get_ebin_space(md
->ebin
,asize(fv_nm
),fv_nm
,unit_energy
);
267 md
->ivir
= get_ebin_space(md
->ebin
,asize(vir_nm
),vir_nm
,unit_energy
);
268 md
->ipres
= get_ebin_space(md
->ebin
,asize(pres_nm
),pres_nm
,unit_pres_bar
);
269 md
->isurft
= get_ebin_space(md
->ebin
,asize(surft_nm
),surft_nm
,
271 if (md
->epc
== epcPARRINELLORAHMAN
|| md
->epc
== epcMTTK
)
273 md
->ipc
= get_ebin_space(md
->ebin
,md
->bTricl
? 6 : 3,
276 md
->imu
= get_ebin_space(md
->ebin
,asize(mu_nm
),mu_nm
,unit_dipole_D
);
277 if (ir
->cos_accel
!= 0)
279 md
->ivcos
= get_ebin_space(md
->ebin
,asize(vcos_nm
),vcos_nm
,unit_vel
);
280 md
->ivisc
= get_ebin_space(md
->ebin
,asize(visc_nm
),visc_nm
,
284 /* Energy monitoring */
287 md
->bEInd
[i
] = FALSE
;
289 md
->bEInd
[egCOULSR
] = TRUE
;
290 md
->bEInd
[egLJSR
] = TRUE
;
292 if (ir
->rcoulomb
> ir
->rlist
)
294 md
->bEInd
[egCOULLR
] = TRUE
;
298 if (ir
->rvdw
> ir
->rlist
)
300 md
->bEInd
[egLJLR
] = TRUE
;
305 md
->bEInd
[egLJSR
] = FALSE
;
306 md
->bEInd
[egBHAMSR
] = TRUE
;
307 if (ir
->rvdw
> ir
->rlist
)
309 md
->bEInd
[egBHAMLR
] = TRUE
;
314 md
->bEInd
[egLJ14
] = TRUE
;
315 md
->bEInd
[egCOUL14
] = TRUE
;
318 for(i
=0; (i
<egNR
); i
++)
326 n
=groups
->grps
[egcENER
].nr
;
329 snew(md
->igrp
,md
->nE
);
334 for(k
=0; (k
<md
->nEc
); k
++)
338 for(i
=0; (i
<groups
->grps
[egcENER
].nr
); i
++)
340 ni
=groups
->grps
[egcENER
].nm_ind
[i
];
341 for(j
=i
; (j
<groups
->grps
[egcENER
].nr
); j
++)
343 nj
=groups
->grps
[egcENER
].nm_ind
[j
];
344 for(k
=kk
=0; (k
<egNR
); k
++)
348 sprintf(gnm
[kk
],"%s:%s-%s",egrp_nm
[k
],
349 *(groups
->grpname
[ni
]),*(groups
->grpname
[nj
]));
353 md
->igrp
[n
]=get_ebin_space(md
->ebin
,md
->nEc
,
354 (const char **)gnm
,unit_energy
);
358 for(k
=0; (k
<md
->nEc
); k
++)
366 gmx_incons("Number of energy terms wrong");
371 md
->nTC
=groups
->grps
[egcTC
].nr
;
372 md
->nNHC
= ir
->opts
.nhchainlength
; /* shorthand for number of NH chains */
373 if (md
->epc
== epcMTTK
)
375 md
->nTCB
= md
->nTC
+ 1; /* for barostat temperature group */
383 if (md
->etc
== etcNOSEHOOVER
) {
384 if (md
->bNHC_trotter
) {
385 md
->mde_n
= 2*md
->nNHC
*md
->nTCB
;
389 md
->mde_n
= 2*md
->nTCB
;
392 md
->mde_n
= md
->nTCB
;
395 snew(md
->tmp_r
,md
->mde_n
);
396 snew(md
->tmp_v
,md
->mde_n
);
397 snew(md
->grpnms
,md
->mde_n
);
400 for(i
=0; (i
<md
->nTC
); i
++)
402 ni
=groups
->grps
[egcTC
].nm_ind
[i
];
403 sprintf(buf
,"T-%s",*(groups
->grpname
[ni
]));
404 grpnms
[i
]=strdup(buf
);
406 md
->itemp
=get_ebin_space(md
->ebin
,md
->nTC
,(const char **)grpnms
,
409 bNoseHoover
= (getenv("GMX_NOSEHOOVER_CHAINS") != NULL
); /* whether to print Nose-Hoover chains */
411 if (md
->etc
== etcNOSEHOOVER
)
415 if (md
->bNHC_trotter
)
417 for(i
=0; (i
<md
->nTCB
); i
++)
419 ni
=groups
->grps
[egcTC
].nm_ind
[i
];
420 /* this one is a barostat thermostat */
421 if ((i
==md
->nTCB
-1) && (md
->nTCB
> md
->nTC
)) {bufi
= bufbaro
[0];} else {bufi
= *(groups
->grpname
[ni
]);}
422 for(j
=0; (j
<md
->nNHC
); j
++)
424 sprintf(buf
,"Xi-%d-%s",j
,bufi
);
425 grpnms
[2*(i
*md
->nNHC
+j
)]=strdup(buf
);
426 sprintf(buf
,"vXi-%d-%s",j
,bufi
);
427 grpnms
[2*(i
*md
->nNHC
+j
)+1]=strdup(buf
);
430 md
->itc
=get_ebin_space(md
->ebin
,md
->mde_n
,(const char **)grpnms
,unit_invtime
);
434 for(i
=0; (i
<md
->nTCB
); i
++)
436 ni
=groups
->grps
[egcTC
].nm_ind
[i
];
437 bufi
= *(groups
->grpname
[ni
]);
438 sprintf(buf
,"Xi-%s",bufi
);
439 grpnms
[2*i
]=strdup(buf
);
440 sprintf(buf
,"vXi-%s",bufi
);
441 grpnms
[2*i
+1]=strdup(buf
);
443 md
->itc
=get_ebin_space(md
->ebin
,md
->mde_n
,(const char **)grpnms
,unit_invtime
);
447 else if (md
->etc
== etcBERENDSEN
|| md
->etc
== etcYES
||
448 md
->etc
== etcVRESCALE
)
450 for(i
=0; (i
<md
->nTC
); i
++)
452 ni
=groups
->grps
[egcTC
].nm_ind
[i
];
453 sprintf(buf
,"Lamb-%s",*(groups
->grpname
[ni
]));
454 grpnms
[i
]=strdup(buf
);
456 md
->itc
=get_ebin_space(md
->ebin
,md
->mde_n
,(const char **)grpnms
,"");
462 md
->nU
=groups
->grps
[egcACC
].nr
;
465 snew(grpnms
,3*md
->nU
);
466 for(i
=0; (i
<md
->nU
); i
++)
468 ni
=groups
->grps
[egcACC
].nm_ind
[i
];
469 sprintf(buf
,"Ux-%s",*(groups
->grpname
[ni
]));
470 grpnms
[3*i
+XX
]=strdup(buf
);
471 sprintf(buf
,"Uy-%s",*(groups
->grpname
[ni
]));
472 grpnms
[3*i
+YY
]=strdup(buf
);
473 sprintf(buf
,"Uz-%s",*(groups
->grpname
[ni
]));
474 grpnms
[3*i
+ZZ
]=strdup(buf
);
476 md
->iu
=get_ebin_space(md
->ebin
,3*md
->nU
,(const char **)grpnms
,unit_vel
);
482 do_enxnms(fp_ene
,&md
->ebin
->nener
,&md
->ebin
->enm
);
485 md
->print_grpnms
=NULL
;
490 FILE *open_dhdl(const char *filename
,t_inputrec
*ir
,const output_env_t oenv
)
493 const char *dhdl
="dH/d\\8l\\4",*deltag
="\\8D\\4H",*lambda
="\\8l\\4";
494 char title
[STRLEN
],label_x
[STRLEN
],label_y
[STRLEN
];
496 char **setname
,buf
[STRLEN
];
498 sprintf(label_x
,"%s (%s)","Time",unit_time
);
499 if (ir
->n_flambda
== 0)
501 sprintf(title
,"%s",dhdl
,deltag
);
502 sprintf(label_y
,"%s (%s %s)",
503 dhdl
,unit_energy
,"[\\8l\\4]\\S-1\\N");
507 sprintf(title
,"%s, %s",dhdl
,deltag
);
508 sprintf(label_y
,"(%s)",unit_energy
);
510 fp
= xvgropen(filename
,title
,label_x
,label_y
,oenv
);
512 if (ir
->n_flambda
> 0)
514 /* g_bar has to determine the lambda values used in this simulation
515 * from this xvg legend.
517 nsets
= 1 + ir
->n_flambda
;
519 sprintf(buf
,"%s %s %g",dhdl
,lambda
,ir
->init_lambda
);
520 setname
[0] = strdup(buf
);
521 for(s
=1; s
<nsets
; s
++)
523 sprintf(buf
,"%s %s %g",deltag
,lambda
,ir
->flambda
[s
-1]);
524 setname
[s
] = strdup(buf
);
526 xvgr_legend(fp
,nsets
,setname
,oenv
);
528 for(s
=0; s
<nsets
; s
++)
538 static void copy_energy(t_mdebin
*md
, real e
[],real ecpy
[])
542 for(i
=j
=0; (i
<F_NRE
); i
++)
546 gmx_incons("Number of energy terms wrong");
549 void upd_mdebin(t_mdebin
*md
,FILE *fp_dhdl
,
553 gmx_enerdata_t
*enerd
,
560 gmx_ekindata_t
*ekind
,
564 int i
,j
,k
,kk
,m
,n
,gid
;
565 real crmsd
[2],tmp6
[6];
566 real bs
[NTRICLBOXS
],vol
,dens
,pv
;
572 /* Do NOT use the box in the state variable, but the separate box provided
573 * as an argument. This is because we sometimes need to write the box from
574 * the last timestep to match the trajectory frames.
576 copy_energy(md
, enerd
->term
,ecopy
);
577 add_ebin(md
->ebin
,md
->ie
,md
->f_nre
,ecopy
,bSum
);
580 crmsd
[0] = constr_rmsd(constr
,FALSE
);
583 crmsd
[1] = constr_rmsd(constr
,TRUE
);
585 add_ebin(md
->ebin
,md
->iconrmsd
,md
->nCrmsd
,crmsd
,FALSE
);
604 vol
= box
[XX
][XX
]*box
[YY
][YY
]*box
[ZZ
][ZZ
];
605 dens
= (tmass
*AMU
)/(vol
*NANO
*NANO
*NANO
);
607 /* This is pV (in kJ/mol). The pressure is the reference pressure,
608 not the instantaneous pressure */
616 pv
+= box
[i
][j
]*md
->ref_p
[i
][j
]/PRESFAC
;
620 pv
+= box
[j
][i
]*md
->ref_p
[j
][i
]/PRESFAC
;
624 add_ebin(md
->ebin
,md
->ib
,NBOXS
,bs
,bSum
);
625 add_ebin(md
->ebin
,md
->ivol
,1 ,&vol
,bSum
);
626 add_ebin(md
->ebin
,md
->idens
,1 ,&dens
,bSum
);
627 add_ebin(md
->ebin
,md
->ipv
,1 ,&pv
,bSum
);
631 add_ebin(md
->ebin
,md
->isvir
,9,svir
[0],bSum
);
632 add_ebin(md
->ebin
,md
->ifvir
,9,fvir
[0],bSum
);
634 add_ebin(md
->ebin
,md
->ivir
,9,vir
[0],bSum
);
635 add_ebin(md
->ebin
,md
->ipres
,9,pres
[0],bSum
);
636 tmp
= (pres
[ZZ
][ZZ
]-(pres
[XX
][XX
]+pres
[YY
][YY
])*0.5)*box
[ZZ
][ZZ
];
637 add_ebin(md
->ebin
,md
->isurft
,1,&tmp
,bSum
);
638 if (md
->epc
== epcPARRINELLORAHMAN
|| md
->epc
== epcMTTK
)
640 tmp6
[0] = state
->boxv
[XX
][XX
];
641 tmp6
[1] = state
->boxv
[YY
][YY
];
642 tmp6
[2] = state
->boxv
[ZZ
][ZZ
];
643 tmp6
[3] = state
->boxv
[YY
][XX
];
644 tmp6
[4] = state
->boxv
[ZZ
][XX
];
645 tmp6
[5] = state
->boxv
[ZZ
][YY
];
646 add_ebin(md
->ebin
,md
->ipc
,md
->bTricl
? 6 : 3,tmp6
,bSum
);
648 add_ebin(md
->ebin
,md
->imu
,3,mu_tot
,bSum
);
649 if (ekind
&& ekind
->cosacc
.cos_accel
!= 0)
651 vol
= box
[XX
][XX
]*box
[YY
][YY
]*box
[ZZ
][ZZ
];
652 dens
= (tmass
*AMU
)/(vol
*NANO
*NANO
*NANO
);
653 add_ebin(md
->ebin
,md
->ivcos
,1,&(ekind
->cosacc
.vcos
),bSum
);
654 /* 1/viscosity, unit 1/(kg m^-1 s^-1) */
655 tmp
= 1/(ekind
->cosacc
.cos_accel
/(ekind
->cosacc
.vcos
*PICO
)
656 *vol
*sqr(box
[ZZ
][ZZ
]*NANO
/(2*M_PI
)));
657 add_ebin(md
->ebin
,md
->ivisc
,1,&tmp
,bSum
);
662 for(i
=0; (i
<md
->nEg
); i
++)
664 for(j
=i
; (j
<md
->nEg
); j
++)
666 gid
=GID(i
,j
,md
->nEg
);
667 for(k
=kk
=0; (k
<egNR
); k
++)
671 eee
[kk
++] = enerd
->grpp
.ener
[k
][gid
];
674 add_ebin(md
->ebin
,md
->igrp
[n
],md
->nEc
,eee
,bSum
);
682 for(i
=0; (i
<md
->nTC
); i
++)
684 md
->tmp_r
[i
] = ekind
->tcstat
[i
].T
;
686 add_ebin(md
->ebin
,md
->itemp
,md
->nTC
,md
->tmp_r
,bSum
);
688 bNoseHoover
= (getenv("GMX_NOSEHOOVER_CHAINS") != NULL
); /* whether to print Nose-Hoover chains */
690 if (md
->etc
== etcNOSEHOOVER
)
694 if (md
->bNHC_trotter
)
697 for(i
=0; (i
<md
->nTCB
); i
++)
699 for (j
=0;j
<md
->nNHC
;j
++)
702 md
->tmp_r
[2*k
] = state
->nosehoover_xi
[k
];
703 md
->tmp_r
[2*k
+1] = state
->nosehoover_vxi
[k
];
706 add_ebin(md
->ebin
,md
->itc
,md
->mde_n
,md
->tmp_r
,bSum
);
710 for(i
=0; (i
<md
->nTC
); i
++)
712 md
->tmp_r
[2*i
] = state
->nosehoover_xi
[i
];
713 md
->tmp_r
[2*i
+1] = state
->nosehoover_vxi
[i
];
715 add_ebin(md
->ebin
,md
->itc
,md
->mde_n
,md
->tmp_r
,bSum
);
719 else if (md
->etc
== etcBERENDSEN
|| md
->etc
== etcYES
|| md
->etc
== etcVRESCALE
)
721 for(i
=0; (i
<md
->nTC
); i
++)
723 md
->tmp_r
[i
] = ekind
->tcstat
[i
].lambda
;
725 add_ebin(md
->ebin
,md
->itc
,md
->nTC
,md
->tmp_r
,bSum
);
729 if (ekind
&& md
->nU
> 1)
731 for(i
=0; (i
<md
->nU
); i
++)
733 copy_rvec(ekind
->grpstat
[i
].u
,md
->tmp_v
[i
]);
735 add_ebin(md
->ebin
,md
->iu
,3*md
->nU
,md
->tmp_v
[0],bSum
);
738 ebin_increase_count(md
->ebin
,bSum
);
742 fprintf(fp_dhdl
,"%.4f %g",
744 enerd
->term
[F_DVDL
]+enerd
->term
[F_DKDL
]+enerd
->term
[F_DHDL_CON
]);
745 for(i
=1; i
<enerd
->n_lambda
; i
++)
747 fprintf(fp_dhdl
," %g",
748 enerd
->enerpart_lambda
[i
]-enerd
->enerpart_lambda
[0]);
750 fprintf(fp_dhdl
,"\n");
754 void upd_mdebin_step(t_mdebin
*md
)
756 ebin_increase_count(md
->ebin
,FALSE
);
759 static void npr(FILE *log
,int n
,char c
)
761 for(; (n
>0); n
--) fprintf(log
,"%c",c
);
764 static void pprint(FILE *log
,const char *s
,t_mdebin
*md
)
768 char buf1
[22],buf2
[22];
771 fprintf(log
,"\t<====== ");
773 fprintf(log
," ==>\n");
774 fprintf(log
,"\t<==== %s ====>\n",s
);
775 fprintf(log
,"\t<== ");
777 fprintf(log
," ======>\n\n");
779 fprintf(log
,"\tStatistics over %s steps using %s frames\n",
780 gmx_step_str(md
->ebin
->nsteps_sim
,buf1
),
781 gmx_step_str(md
->ebin
->nsum_sim
,buf2
));
785 void print_ebin_header(FILE *log
,gmx_large_int_t steps
,double time
,real lamb
)
789 fprintf(log
," %12s %12s %12s\n"
790 " %12s %12.5f %12.5f\n\n",
791 "Step","Time","Lambda",gmx_step_str(steps
,buf
),time
,lamb
);
794 void print_ebin(ener_file_t fp_ene
,bool bEne
,bool bDR
,bool bOR
,
796 gmx_large_int_t step
,double time
,
797 int mode
,bool bCompact
,
798 t_mdebin
*md
,t_fcdata
*fcd
,
799 gmx_groups_t
*groups
,t_grpopts
*opts
)
801 /*static char **grpnms=NULL;*/
803 int i
,j
,n
,ni
,nj
,ndr
,nor
;
813 fr
.nsteps
= md
->ebin
->nsteps
;
814 fr
.nsum
= md
->ebin
->nsum
;
815 fr
.nre
= (bEne
) ? md
->ebin
->nener
: 0;
816 fr
.ener
= md
->ebin
->e
;
817 fr
.ndisre
= bDR
? fcd
->disres
.npair
: 0;
818 fr
.disre_rm3tav
= fcd
->disres
.rm3tav
;
819 fr
.disre_rt
= fcd
->disres
.rt
;
820 /* Optional additional blocks */
821 for(i
=0; i
<enxNR
; i
++)
825 if (fcd
->orires
.nr
> 0 && bOR
)
827 diagonalize_orires_tensors(&(fcd
->orires
));
828 nr
[enxOR
] = fcd
->orires
.nr
;
829 block
[enxOR
] = fcd
->orires
.otav
;
830 nr
[enxORI
] = (fcd
->orires
.oinsl
!= fcd
->orires
.otav
) ?
832 block
[enxORI
] = fcd
->orires
.oinsl
;
833 nr
[enxORT
] = fcd
->orires
.nex
*12;
834 block
[enxORT
] = fcd
->orires
.eig
;
837 for(i
=0; i
<enxNR
; i
++)
846 if (fr
.nre
|| fr
.ndisre
|| fr
.nr
[enxOR
] || fr
.nr
[enxORI
])
849 gmx_fio_check_file_position(enx_file_pointer(fp_ene
));
852 /* We have stored the sums, so reset the sum history */
853 reset_ebin_sums(md
->ebin
);
860 pprint(log
,"A V E R A G E S",md
);
866 pprint(log
,"R M S - F L U C T U A T I O N S",md
);
870 gmx_fatal(FARGS
,"Invalid print mode (%d)",mode
);
875 for(i
=0;i
<opts
->ngtc
;i
++)
877 if(opts
->annealing
[i
]!=eannNO
)
879 fprintf(log
,"Current ref_t for group %s: %8.1f\n",
880 *(groups
->grpname
[groups
->grps
[egcTC
].nm_ind
[i
]]),
884 if (mode
==eprNORMAL
&& fcd
->orires
.nr
>0)
886 print_orires_log(log
,&(fcd
->orires
));
888 fprintf(log
," Energies (%s)\n",unit_energy
);
889 pr_ebin(log
,md
->ebin
,md
->ie
,md
->f_nre
+md
->nCrmsd
,5,mode
,TRUE
);
896 pr_ebin(log
,md
->ebin
,md
->ib
, md
->bTricl
? NTRICLBOXS
: NBOXS
,5,
902 fprintf(log
," Constraint Virial (%s)\n",unit_energy
);
903 pr_ebin(log
,md
->ebin
,md
->isvir
,9,3,mode
,FALSE
);
905 fprintf(log
," Force Virial (%s)\n",unit_energy
);
906 pr_ebin(log
,md
->ebin
,md
->ifvir
,9,3,mode
,FALSE
);
909 fprintf(log
," Total Virial (%s)\n",unit_energy
);
910 pr_ebin(log
,md
->ebin
,md
->ivir
,9,3,mode
,FALSE
);
912 fprintf(log
," Pressure (%s)\n",unit_pres_bar
);
913 pr_ebin(log
,md
->ebin
,md
->ipres
,9,3,mode
,FALSE
);
915 fprintf(log
," Total Dipole (%s)\n",unit_dipole_D
);
916 pr_ebin(log
,md
->ebin
,md
->imu
,3,3,mode
,FALSE
);
921 if (md
->print_grpnms
==NULL
)
923 snew(md
->print_grpnms
,md
->nE
);
925 for(i
=0; (i
<md
->nEg
); i
++)
927 ni
=groups
->grps
[egcENER
].nm_ind
[i
];
928 for(j
=i
; (j
<md
->nEg
); j
++)
930 nj
=groups
->grps
[egcENER
].nm_ind
[j
];
931 sprintf(buf
,"%s-%s",*(groups
->grpname
[ni
]),
932 *(groups
->grpname
[nj
]));
933 md
->print_grpnms
[n
++]=strdup(buf
);
937 sprintf(buf
,"Epot (%s)",unit_energy
);
938 fprintf(log
,"%15s ",buf
);
939 for(i
=0; (i
<egNR
); i
++)
943 fprintf(log
,"%12s ",egrp_nm
[i
]);
947 for(i
=0; (i
<md
->nE
); i
++)
949 fprintf(log
,"%15s",md
->print_grpnms
[i
]);
950 pr_ebin(log
,md
->ebin
,md
->igrp
[i
],md
->nEc
,md
->nEc
,mode
,
957 pr_ebin(log
,md
->ebin
,md
->itemp
,md
->nTC
,4,mode
,TRUE
);
962 fprintf(log
,"%15s %12s %12s %12s\n",
963 "Group","Ux","Uy","Uz");
964 for(i
=0; (i
<md
->nU
); i
++)
966 ni
=groups
->grps
[egcACC
].nm_ind
[i
];
967 fprintf(log
,"%15s",*groups
->grpname
[ni
]);
968 pr_ebin(log
,md
->ebin
,md
->iu
+3*i
,3,3,mode
,FALSE
);
978 init_energyhistory(energyhistory_t
* enerhist
)
982 enerhist
->ener_ave
= NULL
;
983 enerhist
->ener_sum
= NULL
;
984 enerhist
->ener_sum_sim
= NULL
;
986 enerhist
->nsteps
= 0;
988 enerhist
->nsteps_sim
= 0;
989 enerhist
->nsum_sim
= 0;
993 update_energyhistory(energyhistory_t
* enerhist
,t_mdebin
* mdebin
)
997 enerhist
->nsteps
= mdebin
->ebin
->nsteps
;
998 enerhist
->nsum
= mdebin
->ebin
->nsum
;
999 enerhist
->nsteps_sim
= mdebin
->ebin
->nsteps_sim
;
1000 enerhist
->nsum_sim
= mdebin
->ebin
->nsum_sim
;
1001 enerhist
->nener
= mdebin
->ebin
->nener
;
1003 if (mdebin
->ebin
->nsum
> 0)
1005 /* Check if we need to allocate first */
1006 if(enerhist
->ener_ave
== NULL
)
1008 snew(enerhist
->ener_ave
,enerhist
->nener
);
1009 snew(enerhist
->ener_sum
,enerhist
->nener
);
1012 for(i
=0;i
<enerhist
->nener
;i
++)
1014 enerhist
->ener_ave
[i
] = mdebin
->ebin
->e
[i
].eav
;
1015 enerhist
->ener_sum
[i
] = mdebin
->ebin
->e
[i
].esum
;
1019 if (mdebin
->ebin
->nsum_sim
> 0)
1021 /* Check if we need to allocate first */
1022 if(enerhist
->ener_sum_sim
== NULL
)
1024 snew(enerhist
->ener_sum_sim
,enerhist
->nener
);
1027 for(i
=0;i
<enerhist
->nener
;i
++)
1029 enerhist
->ener_sum_sim
[i
] = mdebin
->ebin
->e_sim
[i
].esum
;
1035 restore_energyhistory_from_state(t_mdebin
* mdebin
,energyhistory_t
* enerhist
)
1039 if ((enerhist
->nsum
> 0 || enerhist
->nsum_sim
> 0) &&
1040 mdebin
->ebin
->nener
!= enerhist
->nener
)
1042 gmx_fatal(FARGS
,"Mismatch between number of energies in run input (%d) and checkpoint file (%d).",
1043 mdebin
->ebin
->nener
,enerhist
->nener
);
1046 mdebin
->ebin
->nsteps
= enerhist
->nsteps
;
1047 mdebin
->ebin
->nsum
= enerhist
->nsum
;
1048 mdebin
->ebin
->nsteps_sim
= enerhist
->nsteps_sim
;
1049 mdebin
->ebin
->nsum_sim
= enerhist
->nsum_sim
;
1051 for(i
=0; i
<mdebin
->ebin
->nener
; i
++)
1053 mdebin
->ebin
->e
[i
].eav
=
1054 (enerhist
->nsum
> 0 ? enerhist
->ener_ave
[i
] : 0);
1055 mdebin
->ebin
->e
[i
].esum
=
1056 (enerhist
->nsum
> 0 ? enerhist
->ener_sum
[i
] : 0);
1057 mdebin
->ebin
->e_sim
[i
].esum
=
1058 (enerhist
->nsum_sim
> 0 ? enerhist
->ener_sum_sim
[i
] : 0);