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 *enthalpy_nm
[] = {"Enthalpy" };
73 static const char *boxvel_nm
[] = {
74 "Box-Vel-XX", "Box-Vel-YY", "Box-Vel-ZZ",
75 "Box-Vel-YX", "Box-Vel-ZX", "Box-Vel-ZY"
78 #define NBOXS asize(boxs_nm)
79 #define NTRICLBOXS asize(tricl_boxs_nm)
81 static bool bTricl
,bDynBox
;
82 static int f_nre
=0,epc
,etc
,nCrmsd
;
84 t_mdebin
*init_mdebin(ener_file_t fp_ene
,
85 const gmx_mtop_t
*mtop
,
88 const char *ener_nm
[F_NRE
];
89 static const char *vir_nm
[] = {
90 "Vir-XX", "Vir-XY", "Vir-XZ",
91 "Vir-YX", "Vir-YY", "Vir-YZ",
92 "Vir-ZX", "Vir-ZY", "Vir-ZZ"
94 static const char *sv_nm
[] = {
95 "ShakeVir-XX", "ShakeVir-XY", "ShakeVir-XZ",
96 "ShakeVir-YX", "ShakeVir-YY", "ShakeVir-YZ",
97 "ShakeVir-ZX", "ShakeVir-ZY", "ShakeVir-ZZ"
99 static const char *fv_nm
[] = {
100 "ForceVir-XX", "ForceVir-XY", "ForceVir-XZ",
101 "ForceVir-YX", "ForceVir-YY", "ForceVir-YZ",
102 "ForceVir-ZX", "ForceVir-ZY", "ForceVir-ZZ"
104 static const char *pres_nm
[] = {
105 "Pres-XX","Pres-XY","Pres-XZ",
106 "Pres-YX","Pres-YY","Pres-YZ",
107 "Pres-ZX","Pres-ZY","Pres-ZZ"
109 static const char *surft_nm
[] = {
112 static const char *mu_nm
[] = {
113 "Mu-X", "Mu-Y", "Mu-Z"
115 static const char *vcos_nm
[] = {
118 static const char *visc_nm
[] = {
121 static const char *baro_nm
[] = {
126 const gmx_groups_t
*groups
;
131 int i
,j
,ni
,nj
,n
,nh
,k
,kk
,ncon
,nset
;
132 bool bBHAM
,bNoseHoover
,b14
;
136 groups
= &mtop
->groups
;
138 bBHAM
= (mtop
->ffparams
.functype
[0] == F_BHAM
);
139 b14
= (gmx_mtop_ftype_count(mtop
,F_LJ14
) > 0 ||
140 gmx_mtop_ftype_count(mtop
,F_LJC14_Q
) > 0);
142 ncon
= gmx_mtop_ftype_count(mtop
,F_CONSTR
);
143 nset
= gmx_mtop_ftype_count(mtop
,F_SETTLE
);
144 md
->bConstr
= (ncon
> 0 || nset
> 0);
145 md
->bConstrVir
= FALSE
;
147 if (ncon
> 0 && ir
->eConstrAlg
== econtLINCS
) {
153 md
->bConstrVir
= (getenv("GMX_CONSTRAINTVIR") != NULL
);
158 /* Energy monitoring */
164 for(i
=0; i
<F_NRE
; i
++) {
165 md
->bEner
[i
] = FALSE
;
167 md
->bEner
[i
] = !bBHAM
;
168 else if (i
== F_BHAM
)
169 md
->bEner
[i
] = bBHAM
;
171 md
->bEner
[i
] = ir
->bQMMM
;
172 else if (i
== F_COUL_LR
)
173 md
->bEner
[i
] = (ir
->rcoulomb
> ir
->rlist
);
174 else if (i
== F_LJ_LR
)
175 md
->bEner
[i
] = (!bBHAM
&& ir
->rvdw
> ir
->rlist
);
176 else if (i
== F_BHAM_LR
)
177 md
->bEner
[i
] = (bBHAM
&& ir
->rvdw
> ir
->rlist
);
178 else if (i
== F_RF_EXCL
)
179 md
->bEner
[i
] = (EEL_RF(ir
->coulombtype
) && ir
->coulombtype
!= eelRF_NEC
);
180 else if (i
== F_COUL_RECIP
)
181 md
->bEner
[i
] = EEL_FULL(ir
->coulombtype
);
182 else if (i
== F_LJ14
)
184 else if (i
== F_COUL14
)
186 else if (i
== F_LJC14_Q
|| i
== F_LJC_PAIRS_NB
)
187 md
->bEner
[i
] = FALSE
;
188 else if ((i
== F_DVDL
) || (i
== F_DKDL
))
189 md
->bEner
[i
] = (ir
->efep
!= efepNO
);
190 else if (i
== F_DHDL_CON
)
191 md
->bEner
[i
] = (ir
->efep
!= efepNO
&& md
->bConstr
);
192 else if ((interaction_function
[i
].flags
& IF_VSITE
) ||
193 (i
== F_CONSTR
) || (i
== F_CONSTRNC
) || (i
== F_SETTLE
))
194 md
->bEner
[i
] = FALSE
;
195 else if ((i
== F_COUL_SR
) || (i
== F_EPOT
) || (i
== F_PRES
) || (i
==F_EQM
))
197 else if ((i
== F_ETOT
) || (i
== F_EKIN
) || (i
== F_TEMP
))
198 md
->bEner
[i
] = EI_DYNAMICS(ir
->eI
);
200 md
->bEner
[i
] = (EI_DYNAMICS(ir
->eI
) && getenv("GMX_VIRIAL_TEMPERATURE"));
201 else if (i
== F_DISPCORR
|| i
== F_PDISPCORR
)
202 md
->bEner
[i
] = (ir
->eDispCorr
!= edispcNO
);
203 else if (i
== F_DISRESVIOL
)
204 md
->bEner
[i
] = (gmx_mtop_ftype_count(mtop
,F_DISRES
) > 0);
205 else if (i
== F_ORIRESDEV
)
206 md
->bEner
[i
] = (gmx_mtop_ftype_count(mtop
,F_ORIRES
) > 0);
207 else if (i
== F_CONNBONDS
)
208 md
->bEner
[i
] = FALSE
;
209 else if (i
== F_COM_PULL
)
210 md
->bEner
[i
] = (ir
->ePull
== epullUMBRELLA
|| ir
->ePull
== epullCONST_F
);
211 else if (i
== F_ECONSERVED
)
212 md
->bEner
[i
] = ((ir
->etc
== etcNOSEHOOVER
|| ir
->etc
== etcVRESCALE
) &&
213 (ir
->epc
== epcNO
|| ir
->epc
==epcMTTK
));
215 md
->bEner
[i
] = (gmx_mtop_ftype_count(mtop
,i
) > 0);
219 for(i
=0; i
<F_NRE
; i
++)
223 /* FIXME: The constness should not be cast away */
224 /*ener_nm[f_nre]=(char *)interaction_function[i].longname;*/
225 ener_nm
[md
->f_nre
]=interaction_function
[i
].longname
;
235 md
->ref_p
[i
][j
] = ir
->ref_p
[i
][j
];
238 md
->bTricl
= TRICLINIC(ir
->compress
) || TRICLINIC(ir
->deform
);
239 md
->bDynBox
= DYNAMIC_BOX(*ir
);
241 md
->bNHC_trotter
= IR_NVT_TROTTER(ir
);
242 md
->bMTTK
= IR_NPT_TROTTER(ir
);
244 md
->ebin
= mk_ebin();
245 /* Pass NULL for unit to let get_ebin_space determine the units
246 * for interaction_function[i].longname
248 md
->ie
= get_ebin_space(md
->ebin
,md
->f_nre
,ener_nm
,NULL
);
251 /* This should be called directly after the call for md->ie,
252 * such that md->iconrmsd follows directly in the list.
254 md
->iconrmsd
= get_ebin_space(md
->ebin
,md
->nCrmsd
,conrmsd_nm
,"");
258 md
->ib
= get_ebin_space(md
->ebin
, md
->bTricl
? NTRICLBOXS
:
259 NBOXS
, md
->bTricl
? tricl_boxs_nm
: boxs_nm
,
261 md
->ivol
= get_ebin_space(md
->ebin
, 1, vol_nm
, unit_volume
);
262 md
->idens
= get_ebin_space(md
->ebin
, 1, dens_nm
, unit_density_SI
);
263 md
->ipv
= get_ebin_space(md
->ebin
, 1, pv_nm
, unit_energy
);
264 md
->ienthalpy
= get_ebin_space(md
->ebin
, 1, enthalpy_nm
, unit_energy
);
268 md
->isvir
= get_ebin_space(md
->ebin
,asize(sv_nm
),sv_nm
,unit_energy
);
269 md
->ifvir
= get_ebin_space(md
->ebin
,asize(fv_nm
),fv_nm
,unit_energy
);
271 md
->ivir
= get_ebin_space(md
->ebin
,asize(vir_nm
),vir_nm
,unit_energy
);
272 md
->ipres
= get_ebin_space(md
->ebin
,asize(pres_nm
),pres_nm
,unit_pres_bar
);
273 md
->isurft
= get_ebin_space(md
->ebin
,asize(surft_nm
),surft_nm
,
275 if (md
->epc
== epcPARRINELLORAHMAN
|| md
->epc
== epcMTTK
)
277 md
->ipc
= get_ebin_space(md
->ebin
,md
->bTricl
? 6 : 3,
280 md
->imu
= get_ebin_space(md
->ebin
,asize(mu_nm
),mu_nm
,unit_dipole_D
);
281 if (ir
->cos_accel
!= 0)
283 md
->ivcos
= get_ebin_space(md
->ebin
,asize(vcos_nm
),vcos_nm
,unit_vel
);
284 md
->ivisc
= get_ebin_space(md
->ebin
,asize(visc_nm
),visc_nm
,
288 /* Energy monitoring */
291 md
->bEInd
[i
] = FALSE
;
293 md
->bEInd
[egCOULSR
] = TRUE
;
294 md
->bEInd
[egLJSR
] = TRUE
;
296 if (ir
->rcoulomb
> ir
->rlist
)
298 md
->bEInd
[egCOULLR
] = TRUE
;
302 if (ir
->rvdw
> ir
->rlist
)
304 md
->bEInd
[egLJLR
] = TRUE
;
309 md
->bEInd
[egLJSR
] = FALSE
;
310 md
->bEInd
[egBHAMSR
] = TRUE
;
311 if (ir
->rvdw
> ir
->rlist
)
313 md
->bEInd
[egBHAMLR
] = TRUE
;
318 md
->bEInd
[egLJ14
] = TRUE
;
319 md
->bEInd
[egCOUL14
] = TRUE
;
322 for(i
=0; (i
<egNR
); i
++)
330 n
=groups
->grps
[egcENER
].nr
;
333 snew(md
->igrp
,md
->nE
);
338 for(k
=0; (k
<md
->nEc
); k
++)
342 for(i
=0; (i
<groups
->grps
[egcENER
].nr
); i
++)
344 ni
=groups
->grps
[egcENER
].nm_ind
[i
];
345 for(j
=i
; (j
<groups
->grps
[egcENER
].nr
); j
++)
347 nj
=groups
->grps
[egcENER
].nm_ind
[j
];
348 for(k
=kk
=0; (k
<egNR
); k
++)
352 sprintf(gnm
[kk
],"%s:%s-%s",egrp_nm
[k
],
353 *(groups
->grpname
[ni
]),*(groups
->grpname
[nj
]));
357 md
->igrp
[n
]=get_ebin_space(md
->ebin
,md
->nEc
,
358 (const char **)gnm
,unit_energy
);
362 for(k
=0; (k
<md
->nEc
); k
++)
370 gmx_incons("Number of energy terms wrong");
375 md
->nTC
=groups
->grps
[egcTC
].nr
;
376 md
->nNHC
= ir
->opts
.nhchainlength
; /* shorthand for number of NH chains */
379 md
->nTCP
= 1; /* assume only one possible coupling system for barostat for now */
386 if (md
->etc
== etcNOSEHOOVER
) {
387 if (md
->bNHC_trotter
) {
388 md
->mde_n
= 2*md
->nNHC
*md
->nTC
;
392 md
->mde_n
= 2*md
->nTC
;
394 if (md
->epc
== epcMTTK
)
396 md
->mdeb_n
= 2*md
->nNHC
*md
->nTCP
;
403 snew(md
->tmp_r
,md
->mde_n
);
404 snew(md
->tmp_v
,md
->mde_n
);
405 snew(md
->grpnms
,md
->mde_n
);
408 for(i
=0; (i
<md
->nTC
); i
++)
410 ni
=groups
->grps
[egcTC
].nm_ind
[i
];
411 sprintf(buf
,"T-%s",*(groups
->grpname
[ni
]));
412 grpnms
[i
]=strdup(buf
);
414 md
->itemp
=get_ebin_space(md
->ebin
,md
->nTC
,(const char **)grpnms
,
417 bNoseHoover
= (getenv("GMX_NOSEHOOVER_CHAINS") != NULL
); /* whether to print Nose-Hoover chains */
419 if (md
->etc
== etcNOSEHOOVER
)
423 if (md
->bNHC_trotter
)
425 for(i
=0; (i
<md
->nTC
); i
++)
427 ni
=groups
->grps
[egcTC
].nm_ind
[i
];
428 bufi
= *(groups
->grpname
[ni
]);
429 for(j
=0; (j
<md
->nNHC
); j
++)
431 sprintf(buf
,"Xi-%d-%s",j
,bufi
);
432 grpnms
[2*(i
*md
->nNHC
+j
)]=strdup(buf
);
433 sprintf(buf
,"vXi-%d-%s",j
,bufi
);
434 grpnms
[2*(i
*md
->nNHC
+j
)+1]=strdup(buf
);
437 md
->itc
=get_ebin_space(md
->ebin
,md
->mde_n
,(const char **)grpnms
,unit_invtime
);
440 for(i
=0; (i
<md
->nTCP
); i
++)
442 bufi
= baro_nm
[0]; /* All barostat DOF's together for now. */
443 for(j
=0; (j
<md
->nNHC
); j
++)
445 sprintf(buf
,"Xi-%d-%s",j
,bufi
);
446 grpnms
[2*(i
*md
->nNHC
+j
)]=strdup(buf
);
447 sprintf(buf
,"vXi-%d-%s",j
,bufi
);
448 grpnms
[2*(i
*md
->nNHC
+j
)+1]=strdup(buf
);
451 md
->itcb
=get_ebin_space(md
->ebin
,md
->mdeb_n
,(const char **)grpnms
,unit_invtime
);
456 for(i
=0; (i
<md
->nTC
); i
++)
458 ni
=groups
->grps
[egcTC
].nm_ind
[i
];
459 bufi
= *(groups
->grpname
[ni
]);
460 sprintf(buf
,"Xi-%s",bufi
);
461 grpnms
[2*i
]=strdup(buf
);
462 sprintf(buf
,"vXi-%s",bufi
);
463 grpnms
[2*i
+1]=strdup(buf
);
465 md
->itc
=get_ebin_space(md
->ebin
,md
->mde_n
,(const char **)grpnms
,unit_invtime
);
469 else if (md
->etc
== etcBERENDSEN
|| md
->etc
== etcYES
||
470 md
->etc
== etcVRESCALE
)
472 for(i
=0; (i
<md
->nTC
); i
++)
474 ni
=groups
->grps
[egcTC
].nm_ind
[i
];
475 sprintf(buf
,"Lamb-%s",*(groups
->grpname
[ni
]));
476 grpnms
[i
]=strdup(buf
);
478 md
->itc
=get_ebin_space(md
->ebin
,md
->mde_n
,(const char **)grpnms
,"");
484 md
->nU
=groups
->grps
[egcACC
].nr
;
487 snew(grpnms
,3*md
->nU
);
488 for(i
=0; (i
<md
->nU
); i
++)
490 ni
=groups
->grps
[egcACC
].nm_ind
[i
];
491 sprintf(buf
,"Ux-%s",*(groups
->grpname
[ni
]));
492 grpnms
[3*i
+XX
]=strdup(buf
);
493 sprintf(buf
,"Uy-%s",*(groups
->grpname
[ni
]));
494 grpnms
[3*i
+YY
]=strdup(buf
);
495 sprintf(buf
,"Uz-%s",*(groups
->grpname
[ni
]));
496 grpnms
[3*i
+ZZ
]=strdup(buf
);
498 md
->iu
=get_ebin_space(md
->ebin
,3*md
->nU
,(const char **)grpnms
,unit_vel
);
504 do_enxnms(fp_ene
,&md
->ebin
->nener
,&md
->ebin
->enm
);
507 md
->print_grpnms
=NULL
;
512 FILE *open_dhdl(const char *filename
,const t_inputrec
*ir
,
513 const output_env_t oenv
)
516 const char *dhdl
="dH/d\\lambda",*deltag
="\\DeltaH",*lambda
="\\lambda";
517 char title
[STRLEN
],label_x
[STRLEN
],label_y
[STRLEN
];
519 char **setname
,buf
[STRLEN
];
521 sprintf(label_x
,"%s (%s)","Time",unit_time
);
522 if (ir
->n_flambda
== 0)
524 sprintf(title
,"%s",dhdl
);
525 sprintf(label_y
,"%s (%s %s)",
526 dhdl
,unit_energy
,"[\\lambda]\\S-1\\N");
530 sprintf(title
,"%s, %s",dhdl
,deltag
);
531 sprintf(label_y
,"(%s)",unit_energy
);
533 fp
= xvgropen(filename
,title
,label_x
,label_y
,oenv
);
535 sprintf(buf
,"T = %g (K)",ir
->opts
.ref_t
[0]);
536 xvgr_subtitle(fp
,buf
,oenv
);
538 if (ir
->n_flambda
> 0)
540 /* g_bar has to determine the lambda values used in this simulation
541 * from this xvg legend.
543 nsets
= 1 + ir
->n_flambda
;
545 sprintf(buf
,"%s %s %g",dhdl
,lambda
,ir
->init_lambda
);
546 setname
[0] = strdup(buf
);
547 for(s
=1; s
<nsets
; s
++)
549 sprintf(buf
,"%s %s %g",deltag
,lambda
,ir
->flambda
[s
-1]);
550 setname
[s
] = strdup(buf
);
552 xvgr_legend(fp
,nsets
,setname
,oenv
);
554 for(s
=0; s
<nsets
; s
++)
564 static void copy_energy(t_mdebin
*md
, real e
[],real ecpy
[])
568 for(i
=j
=0; (i
<F_NRE
); i
++)
572 gmx_incons("Number of energy terms wrong");
575 void upd_mdebin(t_mdebin
*md
,FILE *fp_dhdl
,
579 gmx_enerdata_t
*enerd
,
586 gmx_ekindata_t
*ekind
,
590 int i
,j
,k
,kk
,m
,n
,gid
;
591 real crmsd
[2],tmp6
[6];
592 real bs
[NTRICLBOXS
],vol
,dens
,pv
,enthalpy
;
598 /* Do NOT use the box in the state variable, but the separate box provided
599 * as an argument. This is because we sometimes need to write the box from
600 * the last timestep to match the trajectory frames.
602 copy_energy(md
, enerd
->term
,ecopy
);
603 add_ebin(md
->ebin
,md
->ie
,md
->f_nre
,ecopy
,bSum
);
606 crmsd
[0] = constr_rmsd(constr
,FALSE
);
609 crmsd
[1] = constr_rmsd(constr
,TRUE
);
611 add_ebin(md
->ebin
,md
->iconrmsd
,md
->nCrmsd
,crmsd
,FALSE
);
630 vol
= box
[XX
][XX
]*box
[YY
][YY
]*box
[ZZ
][ZZ
];
631 dens
= (tmass
*AMU
)/(vol
*NANO
*NANO
*NANO
);
633 /* This is pV (in kJ/mol). The pressure is the reference pressure,
634 not the instantaneous pressure */
642 pv
+= box
[i
][j
]*md
->ref_p
[i
][j
]/PRESFAC
;
646 pv
+= box
[j
][i
]*md
->ref_p
[j
][i
]/PRESFAC
;
650 add_ebin(md
->ebin
,md
->ib
,NBOXS
,bs
,bSum
);
651 add_ebin(md
->ebin
,md
->ivol
,1 ,&vol
,bSum
);
652 add_ebin(md
->ebin
,md
->idens
,1 ,&dens
,bSum
);
653 add_ebin(md
->ebin
,md
->ipv
,1 ,&pv
,bSum
);
654 enthalpy
= pv
+ enerd
->term
[F_ETOT
];
655 add_ebin(md
->ebin
,md
->ienthalpy
,1 ,&enthalpy
,bSum
);
659 add_ebin(md
->ebin
,md
->isvir
,9,svir
[0],bSum
);
660 add_ebin(md
->ebin
,md
->ifvir
,9,fvir
[0],bSum
);
662 add_ebin(md
->ebin
,md
->ivir
,9,vir
[0],bSum
);
663 add_ebin(md
->ebin
,md
->ipres
,9,pres
[0],bSum
);
664 tmp
= (pres
[ZZ
][ZZ
]-(pres
[XX
][XX
]+pres
[YY
][YY
])*0.5)*box
[ZZ
][ZZ
];
665 add_ebin(md
->ebin
,md
->isurft
,1,&tmp
,bSum
);
666 if (md
->epc
== epcPARRINELLORAHMAN
|| md
->epc
== epcMTTK
)
668 tmp6
[0] = state
->boxv
[XX
][XX
];
669 tmp6
[1] = state
->boxv
[YY
][YY
];
670 tmp6
[2] = state
->boxv
[ZZ
][ZZ
];
671 tmp6
[3] = state
->boxv
[YY
][XX
];
672 tmp6
[4] = state
->boxv
[ZZ
][XX
];
673 tmp6
[5] = state
->boxv
[ZZ
][YY
];
674 add_ebin(md
->ebin
,md
->ipc
,md
->bTricl
? 6 : 3,tmp6
,bSum
);
676 add_ebin(md
->ebin
,md
->imu
,3,mu_tot
,bSum
);
677 if (ekind
&& ekind
->cosacc
.cos_accel
!= 0)
679 vol
= box
[XX
][XX
]*box
[YY
][YY
]*box
[ZZ
][ZZ
];
680 dens
= (tmass
*AMU
)/(vol
*NANO
*NANO
*NANO
);
681 add_ebin(md
->ebin
,md
->ivcos
,1,&(ekind
->cosacc
.vcos
),bSum
);
682 /* 1/viscosity, unit 1/(kg m^-1 s^-1) */
683 tmp
= 1/(ekind
->cosacc
.cos_accel
/(ekind
->cosacc
.vcos
*PICO
)
684 *vol
*sqr(box
[ZZ
][ZZ
]*NANO
/(2*M_PI
)));
685 add_ebin(md
->ebin
,md
->ivisc
,1,&tmp
,bSum
);
690 for(i
=0; (i
<md
->nEg
); i
++)
692 for(j
=i
; (j
<md
->nEg
); j
++)
694 gid
=GID(i
,j
,md
->nEg
);
695 for(k
=kk
=0; (k
<egNR
); k
++)
699 eee
[kk
++] = enerd
->grpp
.ener
[k
][gid
];
702 add_ebin(md
->ebin
,md
->igrp
[n
],md
->nEc
,eee
,bSum
);
710 for(i
=0; (i
<md
->nTC
); i
++)
712 md
->tmp_r
[i
] = ekind
->tcstat
[i
].T
;
714 add_ebin(md
->ebin
,md
->itemp
,md
->nTC
,md
->tmp_r
,bSum
);
716 bNoseHoover
= (getenv("GMX_NOSEHOOVER_CHAINS") != NULL
); /* whether to print Nose-Hoover chains */
718 if (md
->etc
== etcNOSEHOOVER
)
722 if (md
->bNHC_trotter
)
724 for(i
=0; (i
<md
->nTC
); i
++)
726 for (j
=0;j
<md
->nNHC
;j
++)
729 md
->tmp_r
[2*k
] = state
->nosehoover_xi
[k
];
730 md
->tmp_r
[2*k
+1] = state
->nosehoover_vxi
[k
];
733 add_ebin(md
->ebin
,md
->itc
,md
->mde_n
,md
->tmp_r
,bSum
);
736 for(i
=0; (i
<md
->nTCP
); i
++)
738 for (j
=0;j
<md
->nNHC
;j
++)
741 md
->tmp_r
[2*k
] = state
->nhpres_xi
[k
];
742 md
->tmp_r
[2*k
+1] = state
->nhpres_vxi
[k
];
745 add_ebin(md
->ebin
,md
->itcb
,md
->mdeb_n
,md
->tmp_r
,bSum
);
751 for(i
=0; (i
<md
->nTC
); i
++)
753 md
->tmp_r
[2*i
] = state
->nosehoover_xi
[i
];
754 md
->tmp_r
[2*i
+1] = state
->nosehoover_vxi
[i
];
756 add_ebin(md
->ebin
,md
->itc
,md
->mde_n
,md
->tmp_r
,bSum
);
760 else if (md
->etc
== etcBERENDSEN
|| md
->etc
== etcYES
|| md
->etc
== etcVRESCALE
)
762 for(i
=0; (i
<md
->nTC
); i
++)
764 md
->tmp_r
[i
] = ekind
->tcstat
[i
].lambda
;
766 add_ebin(md
->ebin
,md
->itc
,md
->nTC
,md
->tmp_r
,bSum
);
770 if (ekind
&& md
->nU
> 1)
772 for(i
=0; (i
<md
->nU
); i
++)
774 copy_rvec(ekind
->grpstat
[i
].u
,md
->tmp_v
[i
]);
776 add_ebin(md
->ebin
,md
->iu
,3*md
->nU
,md
->tmp_v
[0],bSum
);
779 ebin_increase_count(md
->ebin
,bSum
);
783 fprintf(fp_dhdl
,"%.4f %g",
785 enerd
->term
[F_DVDL
]+enerd
->term
[F_DKDL
]+enerd
->term
[F_DHDL_CON
]);
786 for(i
=1; i
<enerd
->n_lambda
; i
++)
788 fprintf(fp_dhdl
," %g",
789 enerd
->enerpart_lambda
[i
]-enerd
->enerpart_lambda
[0]);
791 fprintf(fp_dhdl
,"\n");
795 void upd_mdebin_step(t_mdebin
*md
)
797 ebin_increase_count(md
->ebin
,FALSE
);
800 static void npr(FILE *log
,int n
,char c
)
802 for(; (n
>0); n
--) fprintf(log
,"%c",c
);
805 static void pprint(FILE *log
,const char *s
,t_mdebin
*md
)
809 char buf1
[22],buf2
[22];
812 fprintf(log
,"\t<====== ");
814 fprintf(log
," ==>\n");
815 fprintf(log
,"\t<==== %s ====>\n",s
);
816 fprintf(log
,"\t<== ");
818 fprintf(log
," ======>\n\n");
820 fprintf(log
,"\tStatistics over %s steps using %s frames\n",
821 gmx_step_str(md
->ebin
->nsteps_sim
,buf1
),
822 gmx_step_str(md
->ebin
->nsum_sim
,buf2
));
826 void print_ebin_header(FILE *log
,gmx_large_int_t steps
,double time
,real lamb
)
830 fprintf(log
," %12s %12s %12s\n"
831 " %12s %12.5f %12.5f\n\n",
832 "Step","Time","Lambda",gmx_step_str(steps
,buf
),time
,lamb
);
835 void print_ebin(ener_file_t fp_ene
,bool bEne
,bool bDR
,bool bOR
,
837 gmx_large_int_t step
,double time
,
838 int mode
,bool bCompact
,
839 t_mdebin
*md
,t_fcdata
*fcd
,
840 gmx_groups_t
*groups
,t_grpopts
*opts
)
842 /*static char **grpnms=NULL;*/
844 int i
,j
,n
,ni
,nj
,ndr
,nor
;
854 fr
.nsteps
= md
->ebin
->nsteps
;
855 fr
.nsum
= md
->ebin
->nsum
;
856 fr
.nre
= (bEne
) ? md
->ebin
->nener
: 0;
857 fr
.ener
= md
->ebin
->e
;
858 fr
.ndisre
= bDR
? fcd
->disres
.npair
: 0;
859 fr
.disre_rm3tav
= fcd
->disres
.rm3tav
;
860 fr
.disre_rt
= fcd
->disres
.rt
;
861 /* Optional additional blocks */
862 for(i
=0; i
<enxNR
; i
++)
866 if (fcd
->orires
.nr
> 0 && bOR
)
868 diagonalize_orires_tensors(&(fcd
->orires
));
869 nr
[enxOR
] = fcd
->orires
.nr
;
870 block
[enxOR
] = fcd
->orires
.otav
;
871 nr
[enxORI
] = (fcd
->orires
.oinsl
!= fcd
->orires
.otav
) ?
873 block
[enxORI
] = fcd
->orires
.oinsl
;
874 nr
[enxORT
] = fcd
->orires
.nex
*12;
875 block
[enxORT
] = fcd
->orires
.eig
;
878 for(i
=0; i
<enxNR
; i
++)
887 if (fr
.nre
|| fr
.ndisre
|| fr
.nr
[enxOR
] || fr
.nr
[enxORI
])
890 gmx_fio_check_file_position(enx_file_pointer(fp_ene
));
893 /* We have stored the sums, so reset the sum history */
894 reset_ebin_sums(md
->ebin
);
901 pprint(log
,"A V E R A G E S",md
);
907 pprint(log
,"R M S - F L U C T U A T I O N S",md
);
911 gmx_fatal(FARGS
,"Invalid print mode (%d)",mode
);
916 for(i
=0;i
<opts
->ngtc
;i
++)
918 if(opts
->annealing
[i
]!=eannNO
)
920 fprintf(log
,"Current ref_t for group %s: %8.1f\n",
921 *(groups
->grpname
[groups
->grps
[egcTC
].nm_ind
[i
]]),
925 if (mode
==eprNORMAL
&& fcd
->orires
.nr
>0)
927 print_orires_log(log
,&(fcd
->orires
));
929 fprintf(log
," Energies (%s)\n",unit_energy
);
930 pr_ebin(log
,md
->ebin
,md
->ie
,md
->f_nre
+md
->nCrmsd
,5,mode
,TRUE
);
937 pr_ebin(log
,md
->ebin
,md
->ib
, md
->bTricl
? NTRICLBOXS
: NBOXS
,5,
943 fprintf(log
," Constraint Virial (%s)\n",unit_energy
);
944 pr_ebin(log
,md
->ebin
,md
->isvir
,9,3,mode
,FALSE
);
946 fprintf(log
," Force Virial (%s)\n",unit_energy
);
947 pr_ebin(log
,md
->ebin
,md
->ifvir
,9,3,mode
,FALSE
);
950 fprintf(log
," Total Virial (%s)\n",unit_energy
);
951 pr_ebin(log
,md
->ebin
,md
->ivir
,9,3,mode
,FALSE
);
953 fprintf(log
," Pressure (%s)\n",unit_pres_bar
);
954 pr_ebin(log
,md
->ebin
,md
->ipres
,9,3,mode
,FALSE
);
956 fprintf(log
," Total Dipole (%s)\n",unit_dipole_D
);
957 pr_ebin(log
,md
->ebin
,md
->imu
,3,3,mode
,FALSE
);
962 if (md
->print_grpnms
==NULL
)
964 snew(md
->print_grpnms
,md
->nE
);
966 for(i
=0; (i
<md
->nEg
); i
++)
968 ni
=groups
->grps
[egcENER
].nm_ind
[i
];
969 for(j
=i
; (j
<md
->nEg
); j
++)
971 nj
=groups
->grps
[egcENER
].nm_ind
[j
];
972 sprintf(buf
,"%s-%s",*(groups
->grpname
[ni
]),
973 *(groups
->grpname
[nj
]));
974 md
->print_grpnms
[n
++]=strdup(buf
);
978 sprintf(buf
,"Epot (%s)",unit_energy
);
979 fprintf(log
,"%15s ",buf
);
980 for(i
=0; (i
<egNR
); i
++)
984 fprintf(log
,"%12s ",egrp_nm
[i
]);
988 for(i
=0; (i
<md
->nE
); i
++)
990 fprintf(log
,"%15s",md
->print_grpnms
[i
]);
991 pr_ebin(log
,md
->ebin
,md
->igrp
[i
],md
->nEc
,md
->nEc
,mode
,
998 pr_ebin(log
,md
->ebin
,md
->itemp
,md
->nTC
,4,mode
,TRUE
);
1003 fprintf(log
,"%15s %12s %12s %12s\n",
1004 "Group","Ux","Uy","Uz");
1005 for(i
=0; (i
<md
->nU
); i
++)
1007 ni
=groups
->grps
[egcACC
].nm_ind
[i
];
1008 fprintf(log
,"%15s",*groups
->grpname
[ni
]);
1009 pr_ebin(log
,md
->ebin
,md
->iu
+3*i
,3,3,mode
,FALSE
);
1019 init_energyhistory(energyhistory_t
* enerhist
)
1021 enerhist
->nener
= 0;
1023 enerhist
->ener_ave
= NULL
;
1024 enerhist
->ener_sum
= NULL
;
1025 enerhist
->ener_sum_sim
= NULL
;
1027 enerhist
->nsteps
= 0;
1029 enerhist
->nsteps_sim
= 0;
1030 enerhist
->nsum_sim
= 0;
1034 update_energyhistory(energyhistory_t
* enerhist
,t_mdebin
* mdebin
)
1038 enerhist
->nsteps
= mdebin
->ebin
->nsteps
;
1039 enerhist
->nsum
= mdebin
->ebin
->nsum
;
1040 enerhist
->nsteps_sim
= mdebin
->ebin
->nsteps_sim
;
1041 enerhist
->nsum_sim
= mdebin
->ebin
->nsum_sim
;
1042 enerhist
->nener
= mdebin
->ebin
->nener
;
1044 if (mdebin
->ebin
->nsum
> 0)
1046 /* Check if we need to allocate first */
1047 if(enerhist
->ener_ave
== NULL
)
1049 snew(enerhist
->ener_ave
,enerhist
->nener
);
1050 snew(enerhist
->ener_sum
,enerhist
->nener
);
1053 for(i
=0;i
<enerhist
->nener
;i
++)
1055 enerhist
->ener_ave
[i
] = mdebin
->ebin
->e
[i
].eav
;
1056 enerhist
->ener_sum
[i
] = mdebin
->ebin
->e
[i
].esum
;
1060 if (mdebin
->ebin
->nsum_sim
> 0)
1062 /* Check if we need to allocate first */
1063 if(enerhist
->ener_sum_sim
== NULL
)
1065 snew(enerhist
->ener_sum_sim
,enerhist
->nener
);
1068 for(i
=0;i
<enerhist
->nener
;i
++)
1070 enerhist
->ener_sum_sim
[i
] = mdebin
->ebin
->e_sim
[i
].esum
;
1076 restore_energyhistory_from_state(t_mdebin
* mdebin
,energyhistory_t
* enerhist
)
1080 if ((enerhist
->nsum
> 0 || enerhist
->nsum_sim
> 0) &&
1081 mdebin
->ebin
->nener
!= enerhist
->nener
)
1083 gmx_fatal(FARGS
,"Mismatch between number of energies in run input (%d) and checkpoint file (%d).",
1084 mdebin
->ebin
->nener
,enerhist
->nener
);
1087 mdebin
->ebin
->nsteps
= enerhist
->nsteps
;
1088 mdebin
->ebin
->nsum
= enerhist
->nsum
;
1089 mdebin
->ebin
->nsteps_sim
= enerhist
->nsteps_sim
;
1090 mdebin
->ebin
->nsum_sim
= enerhist
->nsum_sim
;
1092 for(i
=0; i
<mdebin
->ebin
->nener
; i
++)
1094 mdebin
->ebin
->e
[i
].eav
=
1095 (enerhist
->nsum
> 0 ? enerhist
->ener_ave
[i
] : 0);
1096 mdebin
->ebin
->e
[i
].esum
=
1097 (enerhist
->nsum
> 0 ? enerhist
->ener_sum
[i
] : 0);
1098 mdebin
->ebin
->e_sim
[i
].esum
=
1099 (enerhist
->nsum_sim
> 0 ? enerhist
->ener_sum_sim
[i
] : 0);