#include "gromacs/fileio/trx.h"
#include "gromacs/fileio/xdr_datatype.h"
#include "gromacs/fileio/xdrf.h"
+#include "gromacs/gmxlib/energyhistory.h"
#include "gromacs/legacyheaders/copyrite.h"
#include "gromacs/legacyheaders/names.h"
#include "gromacs/legacyheaders/network.h"
}
flags_enh = 0;
- if (state->enerhist.nsum > 0 || state->enerhist.nsum_sim > 0)
+ if (state->enerhist->nsum > 0 || state->enerhist->nsum_sim > 0)
{
flags_enh |= (1<<eenhENERGY_N) | (1<<eenhENERGY_NSTEPS) | (1<<eenhENERGY_NSTEPS_SIM);
- if (state->enerhist.nsum > 0)
+ if (state->enerhist->nsum > 0)
{
flags_enh |= ((1<<eenhENERGY_AVER) | (1<<eenhENERGY_SUM) |
(1<<eenhENERGY_NSUM));
}
- if (state->enerhist.nsum_sim > 0)
+ if (state->enerhist->nsum_sim > 0)
{
flags_enh |= ((1<<eenhENERGY_SUM_SIM) | (1<<eenhENERGY_NSUM_SIM));
}
- if (state->enerhist.dht)
+ if (state->enerhist->dht)
{
flags_enh |= ( (1<< eenhENERGY_DELTA_H_NN) |
(1<< eenhENERGY_DELTA_H_LIST) |
if ((do_cpt_state(gmx_fio_getxdr(fp), FALSE, state->flags, state, NULL) < 0) ||
(do_cpt_ekinstate(gmx_fio_getxdr(fp), flags_eks, &state->ekinstate, NULL) < 0) ||
- (do_cpt_enerhist(gmx_fio_getxdr(fp), FALSE, flags_enh, &state->enerhist, NULL) < 0) ||
+ (do_cpt_enerhist(gmx_fio_getxdr(fp), FALSE, flags_enh, state->enerhist, NULL) < 0) ||
(do_cpt_df_hist(gmx_fio_getxdr(fp), flags_dfh, &state->dfhist, NULL) < 0) ||
(do_cpt_EDstate(gmx_fio_getxdr(fp), FALSE, &state->edsamstate, NULL) < 0) ||
(do_cpt_swapstate(gmx_fio_getxdr(fp), FALSE, &state->swapstate, NULL) < 0) ||
((flags_eks & (1<<eeksEKINSCALEF)) | (flags_eks & (1<<eeksEKINSCALEH)) | (flags_eks & (1<<eeksVSCALE))));
ret = do_cpt_enerhist(gmx_fio_getxdr(fp), TRUE,
- flags_enh, &state->enerhist, NULL);
+ flags_enh, state->enerhist, NULL);
if (ret)
{
cp_error();
{
fprintf(fplog, "\nWARNING: %s\n\n", warn);
}
- state->enerhist.nsum = *step;
- state->enerhist.nsum_sim = *step;
+ state->enerhist->nsum = *step;
+ state->enerhist->nsum_sim = *step;
}
ret = do_cpt_df_hist(gmx_fio_getxdr(fp), flags_dfh, &state->dfhist, NULL);
cp_error();
}
ret = do_cpt_enerhist(gmx_fio_getxdr(fp), TRUE,
- flags_enh, &state->enerhist, NULL);
+ flags_enh, state->enerhist, NULL);
if (ret)
{
cp_error();
cp_error();
}
ret = do_cpt_enerhist(gmx_fio_getxdr(fp), TRUE,
- flags_enh, &state.enerhist, out);
+ flags_enh, state.enerhist, out);
if (ret == 0)
{
--- /dev/null
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/* This file is completely threadsafe - keep it that way! */
+#include "gmxpre.h"
+
+#include "energyhistory.h"
+
+#include <cstring>
+
+#include <algorithm>
+
+#include "gromacs/math/vec.h"
+#include "gromacs/pbcutil/pbc.h"
+#include "gromacs/random/random.h"
+#include "gromacs/utility/smalloc.h"
+
+static void done_delta_h_history(delta_h_history_t *dht)
+{
+ int i;
+
+ for (i = 0; i < dht->nndh; i++)
+ {
+ sfree(dht->dh[i]);
+ }
+ sfree(dht->dh);
+ sfree(dht->ndh);
+}
+
+void init_energyhistory(energyhistory_t * enerhist)
+{
+ enerhist->nener = 0;
+
+ enerhist->ener_ave = NULL;
+ enerhist->ener_sum = NULL;
+ enerhist->ener_sum_sim = NULL;
+ enerhist->dht = NULL;
+
+ enerhist->nsteps = 0;
+ enerhist->nsum = 0;
+ enerhist->nsteps_sim = 0;
+ enerhist->nsum_sim = 0;
+
+ enerhist->dht = NULL;
+}
+
+void done_energyhistory(energyhistory_t * enerhist)
+{
+ sfree(enerhist->ener_ave);
+ sfree(enerhist->ener_sum);
+ sfree(enerhist->ener_sum_sim);
+
+ if (enerhist->dht != NULL)
+ {
+ done_delta_h_history(enerhist->dht);
+ sfree(enerhist->dht);
+ }
+}
--- /dev/null
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#ifndef GMX_MDLIB_ENERGYHISTORY_H
+#define GMX_MDLIB_ENERGYHISTORY_H
+
+#include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/real.h"
+
+/* energy history for delta_h histograms */
+typedef struct delta_h_history_t
+{
+ int nndh; /* the number of energy difference lists */
+ int *ndh; /* the number in each energy difference list */
+ real **dh; /* the energy difference lists */
+
+ double start_time; /* the start time of these energy diff blocks */
+ double start_lambda; /* lambda at start time */
+
+ gmx_bool start_lambda_set; /* whether the lambda value is set. Here
+ For backward-compatibility. */
+} delta_h_history_t;
+
+
+typedef struct energyhistory_t
+{
+ gmx_int64_t nsteps; /* The number of steps in the history */
+ gmx_int64_t nsum; /* The nr. of steps in the ener_ave and ener_sum */
+ double * ener_ave; /* Energy term history sum to get fluctuations */
+ double * ener_sum; /* Energy term history sum to get fluctuations */
+ int nener; /* Number of energy terms in two previous arrays */
+ gmx_int64_t nsteps_sim; /* The number of steps in ener_sum_sim */
+ gmx_int64_t nsum_sim; /* The number of frames in ener_sum_sim */
+ double * ener_sum_sim; /* Energy term history sum of the whole sim */
+
+ delta_h_history_t *dht; /* The BAR energy differences */
+}
+energyhistory_t;
+
+/* \brief Initialize an energy history structure
+ */
+void init_energyhistory(energyhistory_t * enerhist);
+
+/* \brief Destroy an energy history structure
+ */
+void done_energyhistory(energyhistory_t * enerhist);
+
+#endif
#include <algorithm>
+#include "gromacs/gmxlib/energyhistory.h"
#include "gromacs/math/vec.h"
#include "gromacs/pbcutil/pbc.h"
#include "gromacs/random/random.h"
swapstate->xc_old_whole_p[eChan1] = NULL;
}
-void init_energyhistory(energyhistory_t * enerhist)
-{
- enerhist->nener = 0;
-
- enerhist->ener_ave = NULL;
- enerhist->ener_sum = NULL;
- enerhist->ener_sum_sim = NULL;
- enerhist->dht = NULL;
-
- enerhist->nsteps = 0;
- enerhist->nsum = 0;
- enerhist->nsteps_sim = 0;
- enerhist->nsum_sim = 0;
-
- enerhist->dht = NULL;
-}
-
-static void done_delta_h_history(delta_h_history_t *dht)
-{
- int i;
-
- for (i = 0; i < dht->nndh; i++)
- {
- sfree(dht->dh[i]);
- }
- sfree(dht->dh);
- sfree(dht->ndh);
-}
-
-void done_energyhistory(energyhistory_t * enerhist)
-{
- sfree(enerhist->ener_ave);
- sfree(enerhist->ener_sum);
- sfree(enerhist->ener_sum_sim);
-
- if (enerhist->dht != NULL)
- {
- done_delta_h_history(enerhist->dht);
- sfree(enerhist->dht);
- }
-}
-
void init_gtc_state(t_state *state, int ngtc, int nnhpres, int nhchainlength)
{
int i, j;
state->cg_p = NULL;
zero_history(&state->hist);
zero_ekinstate(&state->ekinstate);
- init_energyhistory(&state->enerhist);
+ snew(state->enerhist, 1);
+ init_energyhistory(state->enerhist);
init_df_history(&state->dfhist, nlambda);
init_swapstate(&state->swapstate);
state->ddp_count = 0;
/* Functions to initiate and delete structures *
* These functions are defined in gmxlib/typedefs.c
*/
-void init_energyhistory(energyhistory_t * enerhist);
-void done_energyhistory(energyhistory_t * enerhist);
void init_gtc_state(t_state *state, int ngtc, int nnhpres, int nhchainlength);
void init_state(t_state *state, int natoms, int ngtc, int nnhpres, int nhchainlength, int nlambda);
t_state *serial_init_local_state(t_state *state_global);
#include "gromacs/utility/basedefinitions.h"
#include "gromacs/utility/real.h"
+struct energyhistory_t;
+
#ifdef __cplusplus
extern "C" {
#endif
real mvcos;
} ekinstate_t;
-/* energy history for delta_h histograms */
-typedef struct
-{
- int nndh; /* the number of energy difference lists */
- int *ndh; /* the number in each energy difference list */
- real **dh; /* the energy difference lists */
-
- double start_time; /* the start time of these energy diff blocks */
- double start_lambda; /* lambda at start time */
-
- gmx_bool start_lambda_set; /* whether the lambda value is set. Here
- For backward-compatibility. */
-} delta_h_history_t;
-
typedef struct
{
int nlambda; /* total number of lambda states - for history*/
} df_history_t;
-typedef struct
-{
- gmx_int64_t nsteps; /* The number of steps in the history */
- gmx_int64_t nsum; /* The nr. of steps in the ener_ave and ener_sum */
- double * ener_ave; /* Energy term history sum to get fluctuations */
- double * ener_sum; /* Energy term history sum to get fluctuations */
- int nener; /* Number of energy terms in two previous arrays */
- gmx_int64_t nsteps_sim; /* The number of steps in ener_sum_sim */
- gmx_int64_t nsum_sim; /* The number of frames in ener_sum_sim */
- double * ener_sum_sim; /* Energy term history sum of the whole sim */
-
- delta_h_history_t *dht; /* The BAR energy differences */
-}
-energyhistory_t;
-
typedef struct
{
/* If one uses essential dynamics or flooding on a group of atoms from
typedef struct t_state
{
- int natoms;
- int ngtc;
- int nnhpres;
- int nhchainlength; /* number of nose-hoover chains */
- int flags; /* Flags telling which entries are present */
- int fep_state; /* indicates which of the alchemical states we are in */
- real *lambda; /* lambda vector */
- matrix box; /* box vector coordinates */
- matrix box_rel; /* Relitaive box vectors to preserve shape */
- matrix boxv; /* box velocitites for Parrinello-Rahman pcoupl */
- matrix pres_prev; /* Pressure of the previous step for pcoupl */
- matrix svir_prev; /* Shake virial for previous step for pcoupl */
- matrix fvir_prev; /* Force virial of the previous step for pcoupl */
- double *nosehoover_xi; /* for Nose-Hoover tcoupl (ngtc) */
- double *nosehoover_vxi; /* for N-H tcoupl (ngtc) */
- double *nhpres_xi; /* for Nose-Hoover pcoupl for barostat */
- double *nhpres_vxi; /* for Nose-Hoover pcoupl for barostat */
- double *therm_integral; /* for N-H/V-rescale tcoupl (ngtc) */
- real veta; /* trotter based isotropic P-coupling */
- real vol0; /* initial volume,required for computing NPT conserverd quantity */
- int nalloc; /* Allocation size for x, v and sd_x when !=NULL*/
- rvec *x; /* the coordinates (natoms) */
- rvec *v; /* the velocities (natoms) */
- rvec *sd_X; /* random part of the x update for stoch. dyn. */
- rvec *cg_p; /* p vector for conjugate gradient minimization */
-
- history_t hist; /* Time history for restraints */
-
- ekinstate_t ekinstate; /* The state of the kinetic energy data */
-
- energyhistory_t enerhist; /* Energy history for statistics */
- swapstate_t swapstate; /* Position swapping */
- df_history_t dfhist; /*Free energy history for free energy analysis */
- edsamstate_t edsamstate; /* Essential dynamics / flooding history */
-
- int ddp_count; /* The DD partitioning count for this state */
- int ddp_count_cg_gl; /* The DD part. count for index_gl */
- int ncg_gl; /* The number of local charge groups */
- int *cg_gl; /* The global cg number of the local cgs */
- int cg_gl_nalloc; /* Allocation size of cg_gl; */
+ int natoms;
+ int ngtc;
+ int nnhpres;
+ int nhchainlength; /* number of nose-hoover chains */
+ int flags; /* Flags telling which entries are present */
+ int fep_state; /* indicates which of the alchemical states we are in */
+ real *lambda; /* lambda vector */
+ matrix box; /* box vector coordinates */
+ matrix box_rel; /* Relitaive box vectors to preserve shape */
+ matrix boxv; /* box velocitites for Parrinello-Rahman pcoupl */
+ matrix pres_prev; /* Pressure of the previous step for pcoupl */
+ matrix svir_prev; /* Shake virial for previous step for pcoupl */
+ matrix fvir_prev; /* Force virial of the previous step for pcoupl */
+ double *nosehoover_xi; /* for Nose-Hoover tcoupl (ngtc) */
+ double *nosehoover_vxi; /* for N-H tcoupl (ngtc) */
+ double *nhpres_xi; /* for Nose-Hoover pcoupl for barostat */
+ double *nhpres_vxi; /* for Nose-Hoover pcoupl for barostat */
+ double *therm_integral; /* for N-H/V-rescale tcoupl (ngtc) */
+ real veta; /* trotter based isotropic P-coupling */
+ real vol0; /* initial volume,required for computing NPT conserverd quantity */
+ int nalloc; /* Allocation size for x, v and sd_x when !=NULL*/
+ rvec *x; /* the coordinates (natoms) */
+ rvec *v; /* the velocities (natoms) */
+ rvec *sd_X; /* random part of the x update for stoch. dyn. */
+ rvec *cg_p; /* p vector for conjugate gradient minimization */
+
+ history_t hist; /* Time history for restraints */
+
+ ekinstate_t ekinstate; /* The state of the kinetic energy data */
+
+ struct energyhistory_t *enerhist; /* Energy history for statistics */
+ swapstate_t swapstate; /* Position swapping */
+ df_history_t dfhist; /*Free energy history for free energy analysis */
+ edsamstate_t edsamstate; /* Essential dynamics / flooding history */
+
+ int ddp_count; /* The DD partitioning count for this state */
+ int ddp_count_cg_gl; /* The DD part. count for index_gl */
+ int ncg_gl; /* The number of local charge groups */
+ int *cg_gl; /* The global cg number of the local cgs */
+ int cg_gl_nalloc; /* Allocation size of cg_gl; */
} t_state;
typedef struct
#include "gromacs/domdec/domdec.h"
#include "gromacs/fileio/trx.h"
+#include "gromacs/gmxlib/energyhistory.h"
#include "gromacs/gmxlib/md_logging.h"
#include "gromacs/legacyheaders/names.h"
#include "gromacs/legacyheaders/nrnb.h"
init_gtc_state(state, state->ngtc, state->nnhpres, ir->opts.nhchainlength); /* allocate the space for nose-hoover chains */
init_ekinstate(&state->ekinstate, ir);
-
- init_energyhistory(&state->enerhist);
+ snew(state->enerhist, 1);
+ init_energyhistory(state->enerhist);
init_df_history(&state->dfhist, ir->fepvals->n_lambda);
state->swapstate.eSwapCoords = ir->eSwapCoords;
}
#include "gromacs/fileio/gmxfio.h"
#include "gromacs/fileio/xvgr.h"
#include "gromacs/gmxlib/disre.h"
+#include "gromacs/gmxlib/energyhistory.h"
#include "gromacs/gmxlib/orires.h"
#include "gromacs/legacyheaders/names.h"
#include "gromacs/legacyheaders/network.h"
/* This is the collection of energy averages collected during mdrun, and to
be written out to the .edr file. */
-typedef struct {
+typedef struct t_mdebin {
double delta_t;
t_ebin *ebin;
int ie, iconrmsd, ib, ivol, idens, ipv, ienthalpy;
#include <string.h>
#include "gromacs/fileio/enxio.h"
+#include "gromacs/gmxlib/energyhistory.h"
#include "gromacs/legacyheaders/typedefs.h"
#include "gromacs/mdlib/mdebin.h"
#include "gromacs/utility/fatalerror.h"
#include "trajectory_writing.h"
#include "gromacs/fileio/confio.h"
+#include "gromacs/gmxlib/energyhistory.h"
#include "gromacs/legacyheaders/typedefs.h"
#include "gromacs/legacyheaders/types/commrec.h"
#include "gromacs/math/vec.h"
update_ekinstate(&state_global->ekinstate, ekind);
state_global->ekinstate.bUpToDate = TRUE;
}
- update_energyhistory(&state_global->enerhist, mdebin);
+ update_energyhistory(state_global->enerhist, mdebin);
}
}
mdoutf_write_to_trajectory_files(fplog, cr, outf, mdof_flags, top_global,
#include "gromacs/fileio/filenm.h"
#include "gromacs/fileio/trx.h"
#include "gromacs/fileio/trxio.h"
+#include "gromacs/gmxlib/energyhistory.h"
#include "gromacs/gmxlib/md_logging.h"
#include "gromacs/gmxlib/sighandler.h"
#include "gromacs/imd/imd.h"
/* Update mdebin with energy history if appending to output files */
if (Flags & MD_APPENDFILES)
{
- restore_energyhistory_from_state(mdebin, &state_global->enerhist);
+ restore_energyhistory_from_state(mdebin, state_global->enerhist);
}
else
{
/* We might have read an energy history from checkpoint,
* free the allocated memory and reset the counts.
*/
- done_energyhistory(&state_global->enerhist);
- init_energyhistory(&state_global->enerhist);
+ done_energyhistory(state_global->enerhist);
+ init_energyhistory(state_global->enerhist);
}
}
/* Set the initial energy history in state by updating once */
- update_energyhistory(&state_global->enerhist, mdebin);
+ update_energyhistory(state_global->enerhist, mdebin);
}
/* Initialize constraints */