constexpr int c_subblockINumPreEntries = 2;
/* reset the delta_h list to prepare it for new values */
-static void mde_delta_h_reset(t_mde_delta_h *dh)
+static void mde_delta_h_reset(t_mde_delta_h* dh)
{
dh->ndh = 0;
dh->written = FALSE;
}
/* initialize the delta_h list */
-static void mde_delta_h_init(t_mde_delta_h *dh, int nbins,
- double dx, unsigned int ndhmax,
- int type, int derivative, int nlambda,
- const double *lambda)
+static void mde_delta_h_init(t_mde_delta_h* dh,
+ int nbins,
+ double dx,
+ unsigned int ndhmax,
+ int type,
+ int derivative,
+ int nlambda,
+ const double* lambda)
{
int i;
}
- snew(dh->subblock_meta_d, dh->nlambda+1);
+ snew(dh->subblock_meta_d, dh->nlambda + 1);
- dh->ndhmax = ndhmax+2;
+ dh->ndhmax = ndhmax + 2;
for (i = 0; i < 2; i++)
{
dh->bin[i] = nullptr;
snew(dh->dh, dh->ndhmax);
snew(dh->dhf, dh->ndhmax);
- if (nbins <= 0 || dx < GMX_REAL_EPS*10)
+ if (nbins <= 0 || dx < GMX_REAL_EPS * 10)
{
dh->nhist = 0;
}
mde_delta_h_reset(dh);
}
-static void done_mde_delta_h(t_mde_delta_h *dh)
+static void done_mde_delta_h(t_mde_delta_h* dh)
{
sfree(dh->lambda);
sfree(dh->subblock_meta_d);
}
/* Add a value to the delta_h list */
-static void mde_delta_h_add_dh(t_mde_delta_h *dh, double delta_h)
+static void mde_delta_h_add_dh(t_mde_delta_h* dh, double delta_h)
{
if (dh->ndh >= dh->ndhmax)
{
}
/* construct histogram with index hi */
-static void mde_delta_h_make_hist(t_mde_delta_h *dh, int hi, gmx_bool invert)
+static void mde_delta_h_make_hist(t_mde_delta_h* dh, int hi, gmx_bool invert)
{
double min_dh = FLT_MAX;
double max_dh = -FLT_MAX;
double max_dh_hist; /* maximum binnable dh value */
double min_dh_hist; /* minimum binnable dh value */
double dx = dh->dx;
- double f; /* energy mult. factor */
+ double f; /* energy mult. factor */
/* by applying a -1 scaling factor on the energies we get the same as
having a negative dx, but we don't need to fix the min/max values
/* first find min and max */
for (i = 0; i < dh->ndh; i++)
{
- if (f*dh->dh[i] < min_dh)
+ if (f * dh->dh[i] < min_dh)
{
- min_dh = f*dh->dh[i];
+ min_dh = f * dh->dh[i];
}
- if (f*dh->dh[i] > max_dh)
+ if (f * dh->dh[i] > max_dh)
{
- max_dh = f*dh->dh[i];
+ max_dh = f * dh->dh[i];
}
}
Get this start value in number of histogram dxs from zero,
as an integer.*/
- dh->x0[hi] = static_cast<int64_t>(floor(min_dh/dx));
+ dh->x0[hi] = static_cast<int64_t>(floor(min_dh / dx));
- min_dh_hist = (dh->x0[hi])*dx;
- max_dh_hist = (dh->x0[hi] + dh->nbins + 1)*dx;
+ min_dh_hist = (dh->x0[hi]) * dx;
+ max_dh_hist = (dh->x0[hi] + dh->nbins + 1) * dx;
/* and fill the histogram*/
for (i = 0; i < dh->ndh; i++)
add it to the last bin.
We check the max_dh_int range because converting to integers
might lead to overflow with unpredictable results.*/
- if ( (f*dh->dh[i] >= min_dh_hist) && (f*dh->dh[i] <= max_dh_hist ) )
+ if ((f * dh->dh[i] >= min_dh_hist) && (f * dh->dh[i] <= max_dh_hist))
{
- bin = static_cast<unsigned int>( (f*dh->dh[i] - min_dh_hist)/dx );
+ bin = static_cast<unsigned int>((f * dh->dh[i] - min_dh_hist) / dx);
}
else
{
- bin = dh->nbins-1;
+ bin = dh->nbins - 1;
}
/* double-check here because of possible round-off errors*/
if (bin >= dh->nbins)
{
- bin = dh->nbins-1;
+ bin = dh->nbins - 1;
}
if (bin > dh->maxbin[hi])
{
/* make sure we include a bin with 0 if we didn't use the full
histogram width. This can then be used as an indication that
all the data was binned. */
- if (dh->maxbin[hi] < dh->nbins-1)
+ if (dh->maxbin[hi] < dh->nbins - 1)
{
dh->maxbin[hi] += 1;
}
}
-static void mde_delta_h_handle_block(t_mde_delta_h *dh, t_enxblock *blk)
+static void mde_delta_h_handle_block(t_mde_delta_h* dh, t_enxblock* blk)
{
/* first check which type we should use: histogram or raw data */
if (dh->nhist == 0)
applicable (in indices
starting from first coord in
the main delta_h_coll) */
- blk->sub[0].nr = 2;
- blk->sub[0].type = xdr_datatype_int;
- blk->sub[0].ival = dh->subblock_meta_i;
+ blk->sub[0].nr = 2;
+ blk->sub[0].type = xdr_datatype_int;
+ blk->sub[0].ival = dh->subblock_meta_i;
/* subblock 2 */
for (i = 0; i < dh->nlambda; i++)
nhist_written++;
/* check whether this histogram contains all data: if the
last bin is 0, it does */
- if (dh->bin[i][dh->nbins-1] == 0)
+ if (dh->bin[i][dh->nbins - 1] == 0)
{
prev_complete = TRUE;
}
/* A histogram consists of 2, 3 or 4 subblocks:
the foreign lambda value + histogram spacing, the starting point,
and the histogram data (0, 1 or 2 blocks). */
- add_subblocks_enxblock(blk, nhist_written+2);
+ add_subblocks_enxblock(blk, nhist_written + 2);
blk->id = enxDHHIST;
/* subblock 1: the lambda value + the histogram spacing */
dh->subblock_meta_d[0] = -1;
for (i = 0; i < dh->nlambda; i++)
{
- dh->subblock_meta_d[2+i] = dh->lambda[i];
+ dh->subblock_meta_d[2 + i] = dh->lambda[i];
}
}
dh->subblock_meta_d[1] = dh->dx;
- blk->sub[0].nr = 2+ ((dh->nlambda > 1) ? dh->nlambda : 0);
+ blk->sub[0].nr = 2 + ((dh->nlambda > 1) ? dh->nlambda : 0);
blk->sub[0].type = xdr_datatype_double;
blk->sub[0].dval = dh->subblock_meta_d;
/* subblock 2: the starting point(s) as a long integer */
dh->subblock_meta_l[0] = nhist_written;
dh->subblock_meta_l[1] = dh->type; /*dh->derivative ? 1 : 0;*/
- k = 2;
+ k = 2;
for (i = 0; i < nhist_written; i++)
{
dh->subblock_meta_l[k++] = dh->x0[i];
/* append the derivative data */
dh->subblock_meta_l[k++] = dh->derivative;
- blk->sub[1].nr = nhist_written+3;
+ blk->sub[1].nr = nhist_written + 3;
blk->sub[1].type = xdr_datatype_int64;
blk->sub[1].lval = dh->subblock_meta_l;
/* subblock 3 + 4 : the histogram data */
for (i = 0; i < nhist_written; i++)
{
- blk->sub[i+2].nr = dh->maxbin[i]+1; /* it's +1 because size=index+1
- in C */
- blk->sub[i+2].type = xdr_datatype_int;
- blk->sub[i+2].ival = dh->bin[i];
+ blk->sub[i + 2].nr = dh->maxbin[i] + 1; /* it's +1 because size=index+1
+ in C */
+ blk->sub[i + 2].type = xdr_datatype_int;
+ blk->sub[i + 2].ival = dh->bin[i];
}
}
}
/* initialize the collection*/
-void mde_delta_h_coll_init(t_mde_delta_h_coll *dhc, const t_inputrec *ir)
+void mde_delta_h_coll_init(t_mde_delta_h_coll* dhc, const t_inputrec* ir)
{
int i, j, n;
- double *lambda_vec;
- int ndhmax = ir->nstenergy/ir->nstcalcenergy;
- t_lambda *fep = ir->fepvals;
+ double* lambda_vec;
+ int ndhmax = ir->nstenergy / ir->nstcalcenergy;
+ t_lambda* fep = ir->fepvals;
dhc->temperature = ir->opts.ref_t[0]; /* only store system temperature */
dhc->start_time = 0.;
- dhc->delta_time = ir->delta_t*ir->fepvals->nstdhdl;
+ dhc->delta_time = ir->delta_t * ir->fepvals->nstdhdl;
dhc->start_time_set = FALSE;
/* this is the compatibility lambda value. If it is >=0, it is valid,
and there is either an old-style lambda or a slow growth simulation. */
dhc->start_lambda = ir->fepvals->init_lambda;
/* for continuous change of lambda values */
- dhc->delta_lambda = ir->fepvals->delta_lambda*ir->fepvals->nstdhdl;
+ dhc->delta_lambda = ir->fepvals->delta_lambda * ir->fepvals->nstdhdl;
if (dhc->start_lambda < 0)
{
if (fep->separate_dvdl[i])
{
dhc->native_lambda_components[j] = i;
- if (fep->init_fep_state >= 0 &&
- fep->init_fep_state < fep->n_lambda)
+ if (fep->init_fep_state >= 0 && fep->init_fep_state < fep->n_lambda)
{
- dhc->native_lambda_vec[j] =
- fep->all_lambda[i][fep->init_fep_state];
+ dhc->native_lambda_vec[j] = fep->all_lambda[i][fep->init_fep_state];
}
else
{
{
if (ir->fepvals->separate_dvdl[i])
{
- dhc->ndh += 1;
+ dhc->ndh += 1;
dhc->ndhdl += 1;
}
}
}
/* add the lambdas */
dhc->nlambda = ir->fepvals->lambda_stop_n - ir->fepvals->lambda_start_n;
- dhc->ndh += dhc->nlambda;
+ dhc->ndh += dhc->nlambda;
/* another compatibility check */
if (dhc->start_lambda < 0)
{
if (ir->fepvals->edHdLPrintEnergy != edHdLPrintEnergyNO)
{
dhc->ndh += 1;
- bEnergy = TRUE;
+ bEnergy = TRUE;
}
if (ir->epc > epcNO)
{
- dhc->ndh += 1; /* include pressure-volume work */
- bPV = TRUE;
+ dhc->ndh += 1; /* include pressure-volume work */
+ bPV = TRUE;
}
}
/* allocate them */
n = 0;
if (bExpanded)
{
- dhc->dh_expanded = dhc->dh+n;
- mde_delta_h_init(dhc->dh+n, ir->fepvals->dh_hist_size,
- ir->fepvals->dh_hist_spacing, ndhmax,
- dhbtEXPANDED, 0, 0, nullptr);
+ dhc->dh_expanded = dhc->dh + n;
+ mde_delta_h_init(dhc->dh + n, ir->fepvals->dh_hist_size, ir->fepvals->dh_hist_spacing,
+ ndhmax, dhbtEXPANDED, 0, 0, nullptr);
n++;
}
if (bEnergy)
{
- dhc->dh_energy = dhc->dh+n;
- mde_delta_h_init(dhc->dh+n, ir->fepvals->dh_hist_size,
- ir->fepvals->dh_hist_spacing, ndhmax,
- dhbtEN, 0, 0, nullptr);
+ dhc->dh_energy = dhc->dh + n;
+ mde_delta_h_init(dhc->dh + n, ir->fepvals->dh_hist_size, ir->fepvals->dh_hist_spacing,
+ ndhmax, dhbtEN, 0, 0, nullptr);
n++;
}
/* add the dhdl's */
if (ir->fepvals->separate_dvdl[i])
{
/* we give it init_lambda for compatibility */
- mde_delta_h_init(dhc->dh+n, ir->fepvals->dh_hist_size,
- ir->fepvals->dh_hist_spacing, ndhmax,
- dhbtDHDL, n_lambda_components, 1,
- &(fep->init_lambda));
+ mde_delta_h_init(dhc->dh + n, ir->fepvals->dh_hist_size, ir->fepvals->dh_hist_spacing,
+ ndhmax, dhbtDHDL, n_lambda_components, 1, &(fep->init_lambda));
n++;
n_lambda_components++;
}
n_lambda_components++; /* count the components */
}
}
-
}
/* add the lambdas */
dhc->dh_du = dhc->dh + n;
}
}
- mde_delta_h_init(dhc->dh+n, ir->fepvals->dh_hist_size,
- ir->fepvals->dh_hist_spacing, ndhmax,
- dhbtDH, 0, n_lambda_components, lambda_vec);
+ mde_delta_h_init(dhc->dh + n, ir->fepvals->dh_hist_size, ir->fepvals->dh_hist_spacing,
+ ndhmax, dhbtDH, 0, n_lambda_components, lambda_vec);
n++;
}
sfree(lambda_vec);
if (bPV)
{
- dhc->dh_pv = dhc->dh+n;
- mde_delta_h_init(dhc->dh+n, ir->fepvals->dh_hist_size,
- ir->fepvals->dh_hist_spacing, ndhmax,
- dhbtPV, 0, 0, nullptr);
+ dhc->dh_pv = dhc->dh + n;
+ mde_delta_h_init(dhc->dh + n, ir->fepvals->dh_hist_size, ir->fepvals->dh_hist_spacing,
+ ndhmax, dhbtPV, 0, 0, nullptr);
n++;
}
}
}
-void done_mde_delta_h_coll(t_mde_delta_h_coll *dhc)
+void done_mde_delta_h_coll(t_mde_delta_h_coll* dhc)
{
if (dhc == nullptr)
{
}
/* add a bunch of samples - note fep_state is double to allow for better data storage */
-void mde_delta_h_coll_add_dh(t_mde_delta_h_coll *dhc,
+void mde_delta_h_coll_add_dh(t_mde_delta_h_coll* dhc,
double fep_state,
double energy,
double pV,
- double *dhdl,
- double *foreign_dU,
+ double* dhdl,
+ double* foreign_dU,
double time)
{
int i;
for (i = 0; i < dhc->ndhdl; i++)
{
- mde_delta_h_add_dh(dhc->dh_dhdl+i, dhdl[i]);
+ mde_delta_h_add_dh(dhc->dh_dhdl + i, dhdl[i]);
}
for (i = 0; i < dhc->nlambda; i++)
{
- mde_delta_h_add_dh(dhc->dh_du+i, foreign_dU[i]);
+ mde_delta_h_add_dh(dhc->dh_du + i, foreign_dU[i]);
}
if (dhc->dh_pv != nullptr)
{
{
mde_delta_h_add_dh(dhc->dh_expanded, fep_state);
}
-
}
/* write the metadata associated with all the du blocks, and call
handle_block to write out all the du blocks */
-void mde_delta_h_coll_handle_block(t_mde_delta_h_coll *dhc,
- t_enxframe *fr, int nblock)
+void mde_delta_h_coll_handle_block(t_mde_delta_h_coll* dhc, t_enxframe* fr, int nblock)
{
int i;
- t_enxblock *blk;
+ t_enxblock* blk;
/* add one block with one subblock as the collection's own data */
nblock++;
add_blocks_enxframe(fr, nblock);
- blk = fr->block + (nblock-1);
+ blk = fr->block + (nblock - 1);
/* only allocate lambda vector component blocks if they must be written out
for backward compatibility */
{
nblock++;
add_blocks_enxframe(fr, nblock);
- blk = fr->block + (nblock-1);
+ blk = fr->block + (nblock - 1);
- mde_delta_h_handle_block(dhc->dh+i, blk);
+ mde_delta_h_handle_block(dhc->dh + i, blk);
}
}
/* reset the data for a new round */
-void mde_delta_h_coll_reset(t_mde_delta_h_coll *dhc)
+void mde_delta_h_coll_reset(t_mde_delta_h_coll* dhc)
{
int i;
for (i = 0; i < dhc->ndh; i++)
}
/* set the energyhistory variables to save state */
-void mde_delta_h_coll_update_energyhistory(const t_mde_delta_h_coll *dhc,
- energyhistory_t *enerhist)
+void mde_delta_h_coll_update_energyhistory(const t_mde_delta_h_coll* dhc, energyhistory_t* enerhist)
{
if (enerhist->deltaHForeignLambdas == nullptr)
{
enerhist->deltaHForeignLambdas->dh.resize(dhc->ndh);
}
- delta_h_history_t * const deltaH = enerhist->deltaHForeignLambdas.get();
+ delta_h_history_t* const deltaH = enerhist->deltaHForeignLambdas.get();
- GMX_RELEASE_ASSERT(deltaH->dh.size() == static_cast<size_t>(dhc->ndh), "energy history number of delta_h histograms should match inputrec's number");
+ GMX_RELEASE_ASSERT(
+ deltaH->dh.size() == static_cast<size_t>(dhc->ndh),
+ "energy history number of delta_h histograms should match inputrec's number");
for (int i = 0; i < dhc->ndh; i++)
{
- std::vector<real> &dh = deltaH->dh[i];
+ std::vector<real>& dh = deltaH->dh[i];
dh.resize(dhc->dh[i].ndh);
std::copy(dh.begin(), dh.end(), dhc->dh[i].dh);
}
}
-
/* restore the variables from an energyhistory */
-void mde_delta_h_coll_restore_energyhistory(t_mde_delta_h_coll *dhc,
- const delta_h_history_t *deltaH)
+void mde_delta_h_coll_restore_energyhistory(t_mde_delta_h_coll* dhc, const delta_h_history_t* deltaH)
{
GMX_RELEASE_ASSERT(dhc, "Should have delta_h histograms");
GMX_RELEASE_ASSERT(deltaH, "Should have delta_h histograms in energy history");
- GMX_RELEASE_ASSERT(deltaH->dh.size() == static_cast<size_t>(dhc->ndh), "energy history number of delta_h histograms should match inputrec's number");
+ GMX_RELEASE_ASSERT(
+ deltaH->dh.size() == static_cast<size_t>(dhc->ndh),
+ "energy history number of delta_h histograms should match inputrec's number");
for (gmx::index i = 0; i < gmx::ssize(deltaH->dh); i++)
{