``dynamic_cast``. For emphasizing type (e.g. intentional integer division)
use constructor syntax. For creating real constants use the user-defined literal
_real (e.g. 2.5_real instead of static_cast<real>(2.5)).
+* Use signed integers for arithmetic (including loop indices). Use ssize
+ (available as free function and member of ArrayRef) to avoid casting.
* Avoid overloading functions unless all variants really do the same
thing, just with different types. Instead, consider making the
function names more descriptive.
void BiasState::getPmf(gmx::ArrayRef<float> pmf) const
{
- GMX_ASSERT(pmf.size() == index(points_.size()), "pmf should have the size of the bias grid");
+ GMX_ASSERT(pmf.size() == points_.size(), "pmf should have the size of the bias grid");
/* The PMF is just the negative of the log of the sampled PMF histogram.
* Points with zero target weight are ignored, they will mostly contain noise.
/* Take log again to get (non-normalized) PMF */
double normFac = 1.0/numSharedUpdate;
- for (gmx::index i = 0; i < pointState.size(); i++)
+ for (gmx::index i = 0; i < pointState.ssize(); i++)
{
if (pointState[i].inTargetRegion())
{
at steps when the reference value has been moved. E.g. if the ref. value
is set every step to (coord dvalue +/- delta) would give zero force.
*/
- for (gmx::index d = 0; d < biasForce.size(); d++)
+ for (gmx::index d = 0; d < biasForce.ssize(); d++)
{
/* Average of the current and new force */
biasForce[d] = 0.5*(biasForce[d] + newForce[d]);
int coverRadius,
gmx::ArrayRef<int> covered)
{
- GMX_ASSERT(covered.size() >= numPoints, "covered should be at least as large as the grid");
+ GMX_ASSERT(covered.ssize() >= numPoints, "covered should be at least as large as the grid");
bool haveFirstNotVisited = false;
int firstNotVisited = -1;
break;
case Normalization::FreeEnergy:
/* Normalize free energy values by subtracting the minimum value */
- for (gmx::index index = 0; index < data.size(); index++)
+ for (gmx::index index = 0; index < data.ssize(); index++)
{
if (bias.state().points()[index].inTargetRegion() && data[index] < minValue)
{
minValue = data[index];
}
}
- for (gmx::index index = 0; index < data.size(); index++)
+ for (gmx::index index = 0; index < data.ssize(); index++)
{
if (bias.state().points()[index].inTargetRegion())
{
const Bias &bias)
{
gmx::ArrayRef<float> data = block_[getVarStartBlock(AwhOutputEntryType::MetaData)].data();
- GMX_ASSERT(metaDataIndex < data.size(), "Attempt to transfer AWH meta data to block for index out of range");
+ GMX_ASSERT(metaDataIndex < data.ssize(), "Attempt to transfer AWH meta data to block for index out of range");
/* Transfer the point data of this variable to the right block(s) */
switch (metaDataType)
cumulativeDistribution[0] = distr[0];
- for (gmx::index i = 1; i < distr.size(); i++)
+ for (gmx::index i = 1; i < distr.ssize(); i++)
{
cumulativeDistribution[i] = cumulativeDistribution[i - 1] + distr[i];
}
}
}
- GMX_RELEASE_ASSERT(bufferIndex == blockDataBuffer.size(), "We should store exactly as many elements as the buffer size");
+ GMX_RELEASE_ASSERT(bufferIndex == blockDataBuffer.ssize(), "We should store exactly as many elements as the buffer size");
}
void CorrelationBlockData::restoreFromHistory(const CorrelationBlockDataHistory &blockHistory,
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,2018,2019, 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.
void addData(double weight,
gmx::ArrayRef<const double> data)
{
- GMX_ASSERT(data.size() == gmx::index(coordData_.size()), "Size of data should match the size of coordData");
+ GMX_ASSERT(data.size() == coordData_.size(), "Size of data should match the size of coordData");
blockSumWeight_ += weight;
blockSumSquareWeight_ += weight*weight;
* The target is (index + 1)/120.
*/
double msdPmf = 0;
- for (index i = 0; i < points.size(); i++)
+ for (index i = 0; i < points.ssize(); i++)
{
msdPmf += gmx::square(points[i].logPmfSum() - points[0].logPmfSum() + 0.5*i) / points.size();
EXPECT_DOUBLE_EQ(points[i].target(), (i + 1)/120.0);
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, 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.
fprintf(debug, "Initial charge group distribution: ");
for (int rank = 0; rank < dd->nnodes; rank++)
{
- fprintf(debug, " %td", ma->domainGroups[rank].atomGroups.size());
+ fprintf(debug, " %td", ma->domainGroups[rank].atomGroups.ssize());
}
fprintf(debug, "\n");
}
dest->nalloc_a = over_alloc_large(dest->nra+na);
srenew(dest->a, dest->nalloc_a);
}
- for (gmx::index s = 1; s < src.size(); s++)
+ for (gmx::index s = 1; s < src.ssize(); s++)
{
for (int i = dest->nr + 1; i < src[s].excl.nr + 1; i++)
{
for (ftype = 0; ftype < F_NRE; ftype++)
{
int n = 0;
- for (gmx::index s = 1; s < src.size(); s++)
+ for (gmx::index s = 1; s < src.ssize(); s++)
{
n += src[s].idef.il[ftype].nr;
}
const int nral1 = 1 + NRAL(ftype);
const int ftv = ftype - c_ftypeVsiteStart;
- for (gmx::index s = 1; s < src.size(); s++)
+ for (gmx::index s = 1; s < src.ssize(); s++)
{
const t_ilist &ils = src[s].idef.il[ftype];
}
/* Set nposres to the number of original position restraints in dest */
- for (gmx::index s = 1; s < src.size(); s++)
+ for (gmx::index s = 1; s < src.ssize(); s++)
{
nposres -= src[s].idef.il[ftype].nr/2;
}
- for (gmx::index s = 1; s < src.size(); s++)
+ for (gmx::index s = 1; s < src.ssize(); s++)
{
const t_iparams *iparams_src = (ftype == F_POSRES ? src[s].idef.iparams_posres : src[s].idef.iparams_fbposres);
if (isExcludedAtom)
{
- if (n + intermolecularExclusionGroup.size() > lexcls->nalloc_a)
+ if (n + intermolecularExclusionGroup.ssize() > lexcls->nalloc_a)
{
lexcls->nalloc_a =
over_alloc_large(n + intermolecularExclusionGroup.size());
/* Copy back the global charge group indices from state
* and rebuild the local charge group to atom index.
*/
- for (gmx::index i = 0; i < atomGroupsState.size(); i++)
+ for (gmx::index i = 0; i < atomGroupsState.ssize(); i++)
{
const int atomGroupGlobal = atomGroupsState[i];
const int groupSize = gcgs_index[atomGroupGlobal + 1] - gcgs_index[atomGroupGlobal];
gmx::ArrayRef<T> vectorToSort,
std::vector<T> *workVector)
{
- if (gmx::index(workVector->size()) < sort.size())
+ if (gmx::index(workVector->size()) < sort.ssize())
{
workVector->resize(sort.size());
}
/* Reorder the state */
gmx::ArrayRef<const gmx_cgsort_t> cgsort = sort->sorted;
- GMX_RELEASE_ASSERT(cgsort.size() == dd->ncg_home, "We should sort all the home atom groups");
+ GMX_RELEASE_ASSERT(cgsort.ssize() == dd->ncg_home, "We should sort all the home atom groups");
if (state->flags & (1 << estX))
{
else
{
/* Copy the sorted ns cell indices back to the ns grid struct */
- for (gmx::index i = 0; i < cgsort.size(); i++)
+ for (gmx::index i = 0; i < cgsort.ssize(); i++)
{
fr->ns->grid->cell_index[i] = cgsort[i].nsc;
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, 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.
{
int pos_vec[DIM*2] = { 0 };
- for (int g = 0; g < move.size(); g++)
+ for (int g = 0; g < move.ssize(); g++)
{
const auto atomGroup = atomGroups.block(g);
/* Skip moved atoms */
{
int pos_vec[DIM*2] = { 0 };
- for (int g = 0; g < move.size(); g++)
+ for (int g = 0; g < move.ssize(); g++)
{
const auto atomGroup = atomGroups.block(g);
/* Skip moved atoms */
{
int pos_vec[DIM*2] = { 0 };
- for (int g = 0; g < move.size(); g++)
+ for (int g = 0; g < move.ssize(); g++)
{
/* Skip moved atoms */
const int m = move[g];
char *bLocalCG,
int *cell_index)
{
- for (int g = 0; g < move.size(); g++)
+ for (int g = 0; g < move.ssize(); g++)
{
if (move[g] >= 0)
{
)
{
const index atomCount = coordinates.size();
- GMX_RELEASE_ASSERT(atomCount == charges.size(), "Mismatch in atom data");
+ GMX_RELEASE_ASSERT(atomCount == charges.ssize(), "Mismatch in atom data");
PmeSafePointer pmeSafe = pmeInitInternal(inputRec, mode, gpuInfo, pmeGpuProgram, atomCount, box);
pme_atomcomm_t *atc = nullptr;
{
pme_atomcomm_t *atc = &(pme->atc[0]);
const index atomCount = atc->n;
- GMX_RELEASE_ASSERT(forces.size() == atomCount, "Invalid force buffer size");
+ GMX_RELEASE_ASSERT(forces.ssize() == atomCount, "Invalid force buffer size");
const bool forceReductionWithInput = (inputTreatment == PmeForceOutputHandling::ReduceWithInput);
const real scale = 1.0;
const size_t threadIndex = 0;
const index atomCount = atc->n;
const index pmeOrder = pme->pme_order;
const index dimSize = pmeOrder * atomCount;
- GMX_RELEASE_ASSERT(dimSize == splineValues.size(), "Mismatch in spline data");
+ GMX_RELEASE_ASSERT(dimSize == splineValues.ssize(), "Mismatch in spline data");
real *splineBuffer = pmeGetSplineDataInternal(pme, type, dimIndex);
switch (mode)
{
const pme_atomcomm_t *atc = &(pme->atc[0]);
const index atomCount = atc->n;
- GMX_RELEASE_ASSERT(atomCount == gridLineIndices.size(), "Mismatch in gridline indices size");
+ GMX_RELEASE_ASSERT(atomCount == gridLineIndices.ssize(), "Mismatch in gridline indices size");
IVec paddedGridSizeUnused, gridSize(0, 0, 0);
pmeGetRealGridSizesInternal(pme, mode, gridSize, paddedGridSizeUnused);
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
{
return -1;
}
- for (gmx::index i = 0; i < inp.size(); i++)
+ for (gmx::index i = 0; i < inp.ssize(); i++)
{
if (gmx_strcasecmp_min(name, inp[i].name_.c_str()) == 0)
{
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2013,2014,2015,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2018,2019, 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.
tng_num_particles_get(tng, &nAtoms);
- if (nAtoms == ind.size())
+ if (nAtoms == ind.ssize())
{
return;
}
{
tng_molecule_num_atoms_get(tng, mol, &nAtoms);
tng_molecule_cnt_get(tng, mol, &cnt);
- if (nAtoms == ind.size())
+ if (nAtoms == ind.ssize())
{
stat = TNG_SUCCESS;
}
tng_molecule_name_set(tng, mol, name);
tng_molecule_chain_add(tng, mol, "", &chain);
- for (int i = 0; i < ind.size(); i++)
+ for (int i = 0; i < ind.ssize(); i++)
{
char temp_name[256], temp_type[256];
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, 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.
gmx::ArrayRef<const std::string> graphFiles = opt2fns("-og", NFILE, fnm);
if (graphFiles.size() != 2)
{
- gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", graphFiles.size());
+ gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", graphFiles.ssize());
}
writesurftoxpms(surf1, surf2, tblock, xslices, yslices, zslices, binw, binwz, graphFiles, zslices);
}
gmx::ArrayRef<const std::string> rawFiles = opt2fns("-or", NFILE, fnm);
if (rawFiles.size() != 2)
{
- gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", rawFiles.size());
+ gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", rawFiles.ssize());
}
writeraw(surf1, surf2, tblock, xslices, yslices, rawFiles, oenv);
}
if (spectra.size() != 2)
{
gmx_fatal(FARGS, "No or not correct number (2) of output-file-series: %td",
- spectra.size());
+ spectra.ssize());
}
powerspectavg_intf(surf1, surf2, tblock, xslices, yslices, spectra);
}
static void sort_files(gmx::ArrayRef<std::string> files, real *settime)
{
- for (gmx::index i = 0; i < files.size(); i++)
+ for (gmx::index i = 0; i < files.ssize(); i++)
{
gmx::index minidx = i;
- for (gmx::index j = i + 1; j < files.size(); j++)
+ for (gmx::index j = i + 1; j < files.ssize(); j++)
{
if (settime[j] < settime[minidx])
{
fprintf(stderr, " File Current start New start\n"
"---------------------------------------------------------\n");
- for (gmx::index i = 0; i < files.size(); i++)
+ for (gmx::index i = 0; i < files.ssize(); i++)
{
fprintf(stderr, "%25s %10.3f ", files[i].c_str(), readtime[i]);
ok = FALSE;
}
else
{
- for (gmx::index i = 0; i < files.size(); i++)
+ for (gmx::index i = 0; i < files.ssize(); i++)
{
settime[i] = readtime[i];
}
fprintf(stderr, "\nSummary of files and start times used:\n\n"
" File Start time\n"
"-----------------------------------------\n");
- for (gmx::index i = 0; i < files.size(); i++)
+ for (gmx::index i = 0; i < files.ssize(); i++)
{
switch (cont_type[i])
{
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2017,2018,2019, 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.
gmx::ArrayRef<const std::string> intfn = opt2fns("-o", NFILE, fnm);
if (intfn.size() != 2)
{
- gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", intfn.size());
+ gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", intfn.ssize());
}
calc_tetra_order_interface(ndxfnm, tpsfnm, trxfnm, binwidth, nsttblock, &frames, &xslices, &yslices, sg1, sg2, &intfpos, oenv);
writesurftoxpms(intfpos, frames, xslices, yslices, binwidth, intfn, nlevels);
gmx::ArrayRef<const std::string> spectra = opt2fns("-Spect", NFILE, fnm);
if (spectra.size() != 2)
{
- gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", spectra.size());
+ gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", spectra.ssize());
}
powerspectavg(intfpos, frames, xslices, yslices, spectra);
}
gmx::ArrayRef<const std::string> raw = opt2fns("-or", NFILE, fnm);
if (raw.size() != 2)
{
- gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", raw.size());
+ gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", raw.ssize());
}
writeraw(intfpos, frames, xslices, yslices, raw);
}
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016,2017,2018,2019, 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.
/* read input file(s) */
block = new_blocka();
gnames = nullptr;
- printf("Going to read %td old index file(s)\n", ndxInFiles.size());
+ printf("Going to read %td old index file(s)\n", ndxInFiles.ssize());
if (!ndxInFiles.empty())
{
for (const std::string &ndxInFile : ndxInFiles)
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
if (bM)
{
- for (int i = 0; (i < atom_index.size()); i++)
+ for (int i = 0; (i < atom_index.ssize()); i++)
{
size_t ai = atom_index[i];
for (size_t j = 0; (j < DIM); j++)
{
- for (int k = 0; (k < atom_index.size()); k++)
+ for (int k = 0; (k < atom_index.ssize()); k++)
{
size_t ak = atom_index[k];
mass_fac = gmx::invsqrt(top->atoms.atom[ai].m*top->atoms.atom[ak].m);
{
for (int i = 0; i < (end-begin+1); i++)
{
- for (int j = 0; j < atom_index.size(); j++)
+ for (int j = 0; j < atom_index.ssize(); j++)
{
size_t aj = atom_index[j];
mass_fac = gmx::invsqrt(top->atoms.atom[aj].m);
if (bM)
{
- for (int iatom = 0; (iatom < atom_index.size()); iatom++)
+ for (int iatom = 0; (iatom < atom_index.ssize()); iatom++)
{
size_t ai = atom_index[iatom];
for (size_t j = 0; (j < DIM); j++)
{
for (i = 0; i < neig; i++)
{
- for (int j = 0; j < atom_index.size(); j++)
+ for (int j = 0; j < atom_index.ssize(); j++)
{
size_t aj = atom_index[j];
mass_fac = gmx::invsqrt(top->atoms.atom[aj].m);
t_trxframe fr;
bool ok;
- for (gmx::index i = 0; i < files.size(); i++)
+ for (gmx::index i = 0; i < files.ssize(); i++)
{
ok = read_first_frame(oenv, &status, files[i].c_str(), &fr, FLAGS);
static void sort_files(gmx::ArrayRef<std::string> files, real *settime)
{
- for (gmx::index i = 0; i < files.size(); i++)
+ for (gmx::index i = 0; i < files.ssize(); i++)
{
gmx::index minidx = i;
- for (gmx::index j = i + 1; j < files.size(); j++)
+ for (gmx::index j = i + 1; j < files.ssize(); j++)
{
if (settime[j] < settime[minidx])
{
"---------------------------------------------------------\n",
timeUnit.c_str(), timeUnit.c_str());
- for (gmx::index i = 0; i < files.size(); i++)
+ for (gmx::index i = 0; i < files.ssize(); i++)
{
fprintf(stderr, "%25s %10.3f %s ", files[i].c_str(),
output_env_conv_time(oenv, readtime[i]), timeUnit.c_str());
}
else
{
- for (gmx::index i = 0; i < files.size(); i++)
+ for (gmx::index i = 0; i < files.ssize(); i++)
{
settime[i] = readtime[i];
}
fprintf(stderr, "\nSummary of files and start times used:\n\n"
" File Start time Time step\n"
"---------------------------------------------------------\n");
- for (gmx::index i = 0; i < files.size(); i++)
+ for (gmx::index i = 0; i < files.ssize(); i++)
{
switch (cont_type[i])
{
snew(bSet, inFiles.size());
natoms = -1;
t = -1;
- for (gmx::index i = 0; i < inFiles.size(); i++)
+ for (gmx::index i = 0; i < inFiles.ssize(); i++)
{
read_first_frame(oenv, &(fp_in[i]), inFiles[i].c_str(), &(trx[i]),
TRX_NEED_X);
}
snew(fp_out, inFiles.size());
- for (gmx::index i = 0; i < inFiles.size(); i++)
+ for (gmx::index i = 0; i < inFiles.ssize(); i++)
{
fp_out[i] = open_trx(outFiles[i].c_str(), "w");
}
{
fprintf(debug, "trx[0].time = %g, time[k] = %g\n", trx[0].time, time[k]);
}
- for (gmx::index i = 0; i < inFiles.size(); i++)
+ for (gmx::index i = 0; i < inFiles.ssize(); i++)
{
bSet[i] = FALSE;
}
- for (gmx::index i = 0; i < inFiles.size(); i++)
+ for (gmx::index i = 0; i < inFiles.ssize(); i++)
{
int j = gmx::roundToInt(value[i][k]);
range_check(j, 0, inFiles.size());
}
bCont = (k < nval);
- for (gmx::index i = 0; i < inFiles.size(); i++)
+ for (gmx::index i = 0; i < inFiles.ssize(); i++)
{
bCont = bCont && read_next_frame(oenv, fp_in[i], &trx[i]);
}
}
while (bCont);
- for (gmx::index i = 0; i < inFiles.size(); i++)
+ for (gmx::index i = 0; i < inFiles.ssize(); i++)
{
close_trx(fp_in[i]);
close_trx(fp_out[i]);
if (bDeMux && ssize(inFiles) != nset)
{
- gmx_fatal(FARGS, "You have specified %td files and %d entries in the demux table", inFiles.size(), nset);
+ gmx_fatal(FARGS, "You have specified %td files and %d entries in the demux table", inFiles.ssize(), nset);
}
ftpin = fn2ftp(inFiles[0].c_str());
}
else if (bDeMux && ssize(outFiles) != nset && outFiles.size() != 1)
{
- gmx_fatal(FARGS, "Number of output files should be 1 or %d (#input files), not %td", nset, outFiles.size());
+ gmx_fatal(FARGS, "Number of output files should be 1 or %d (#input files), not %td", nset, outFiles.ssize());
}
if (bDeMux)
{
size_t nskip = linear ? 5 : 6;
double Evib = 0;
double hbar = PLANCK1/(2*M_PI);
- for (gmx::index i = nskip; i < eigval.size(); i++)
+ for (gmx::index i = nskip; i < eigval.ssize(); i++)
{
if (eigval[i] > 0)
{
size_t nskip = linear ? 5 : 6;
double cv = 0;
double hbar = PLANCK1/(2*M_PI);
- for (gmx::index i = nskip; i < eigval.size(); i++)
+ for (gmx::index i = nskip; i < eigval.ssize(); i++)
{
if (eigval[i] > 0)
{
size_t nskip = bLinear ? 5 : 6;
double S = 0;
double hbar = PLANCK1/(2*M_PI);
- for (gmx::index i = nskip; (i < eigval.size()); i++)
+ for (gmx::index i = nskip; (i < eigval.ssize()); i++)
{
if (eigval[i] > 0)
{
ssize(eigval), kteh, evcorr);
}
double deter = 0;
- for (gmx::index i = nskip; i < eigval.size(); i++)
+ for (gmx::index i = nskip; i < eigval.ssize(); i++)
{
double dd = 1+kteh*eigval[i]*evcorr;
deter += std::log(dd);
}
snew(grps->nm_ind, groupsFromMdpFile.size()+1); /* +1 for possible rest group */
- for (int i = 0; i != groupsFromMdpFile.size(); ++i)
+ for (int i = 0; i != groupsFromMdpFile.ssize(); ++i)
{
/* Lookup the group name in the block structure */
gid = search_string(groupsFromMdpFile[i].c_str(), block->nr, gnames);
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, 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.
ArrayRef<T> output)
{
ASSERT_EQ(input.size(), output.size());
- for (index i = 0; i != input.size(); ++i)
+ for (index i = 0; i != input.ssize(); ++i)
{
EXPECT_EQ(input[i], output[i]) << "for index " << i;
}
ArrayRef < BasicVector < T>> output)
{
ASSERT_EQ(input.size(), output.size());
- for (index i = 0; i != input.size(); ++i)
+ for (index i = 0; i != input.ssize(); ++i)
{
EXPECT_EQ(input[i][XX], output[i][XX]) << "for index " << i;
EXPECT_EQ(input[i][YY], output[i][YY]) << "for index " << i;
// Here add up the contribution of all atom pairs in the system to
// (estimated) energy drift by looping over all atom type pairs.
- for (int i = 0; i < att.size(); i++)
+ for (int i = 0; i < att.ssize(); i++)
{
// Get the thermal displacement variance for the i-atom type
const atom_nonbonded_kinetic_prop_t *prop_i = &att[i].prop;
real s2i_2d, s2i_3d;
get_atom_sigma2(kT_fac, prop_i, &s2i_2d, &s2i_3d);
- for (int j = i; j < att.size(); j++)
+ for (int j = i; j < att.ssize(); j++)
{
// Get the thermal displacement variance for the j-atom type
const atom_nonbonded_kinetic_prop_t *prop_j = &att[j].prop;
{
GMX_ASSERT(!att.empty(), "We should have at least one type");
real smallestMass = att[0].prop.mass;
- for (int i = 1; i < att.size(); i++)
+ for (int i = 1; i < att.ssize(); i++)
{
smallestMass = std::min(smallestMass, att[i].prop.mass);
}
real kT_fac,
real cellSize)
{
- GMX_RELEASE_ASSERT(static_cast<size_t>(updateGrouping.size()) == mtop.moltype.size(),
+ GMX_RELEASE_ASSERT(updateGrouping.size() == mtop.moltype.size(),
"The update groups should match the topology");
real chance = 0;
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
gmx::ArrayRef<const int> iatom_constrnc,
int con)
{
- if (con*3 < iatom_constr.size())
+ if (con*3 < iatom_constr.ssize())
{
return iatom_constr.data() + con*3;
}
double &enerpart_lambda = enerd->enerpart_lambda[i + 1];
- for (gmx::index j = 0; j < lambda.size(); j++)
+ for (gmx::index j = 0; j < lambda.ssize(); j++)
{
/* Note that this loop is over all dhdl components, not just the separated ones */
const double dlam = fepvals->all_lambda[j][i] - lambda[j];
// being recognized and used for table 1.
std::string patternToFind = gmx::formatString("_%s%d.%s", tabext, i, ftp2ext(efXVG));
bool madeTable = false;
- for (gmx::index j = 0; j < tabbfnm.size() && !madeTable; ++j)
+ for (gmx::index j = 0; j < tabbfnm.ssize() && !madeTable; ++j)
{
if (gmx::endsWith(tabbfnm[j], patternToFind))
{
void removeQmmmAtomCharges(gmx_mtop_t *mtop, gmx::ArrayRef<const int> qmmmAtoms)
{
int molb = 0;
- for (int i = 0; i < qmmmAtoms.size(); i++)
+ for (int i = 0; i < qmmmAtoms.ssize(); i++)
{
int indexInMolecule;
mtopGetMolblockIndex(mtop, qmmmAtoms[i], &molb, nullptr, &indexInMolecule);
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, 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.
return 0;
}
- GMX_RELEASE_ASSERT(static_cast<size_t>(updateGroups.size()) == mtop.moltype.size(),
+ GMX_RELEASE_ASSERT(updateGroups.size() == mtop.moltype.size(),
"We need one update group entry per moleculetype");
real maxRadius = 0;
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, 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.
const int localAtomBegin = cogIndices_.size();
const size_t cogBegin = cogs_.size();
- GMX_RELEASE_ASSERT(globalAtomIndices.size() >= localAtomBegin,
+ GMX_RELEASE_ASSERT(globalAtomIndices.ssize() >= localAtomBegin,
"addCogs should only be called to add COGs to the list that is already present (which could be empty)");
cogIndices_.reserve(globalAtomIndices.size());
int moleculeBlock = 0;
- for (int localAtom = localAtomBegin; localAtom < globalAtomIndices.size(); localAtom++)
+ for (int localAtom = localAtomBegin; localAtom < globalAtomIndices.ssize(); localAtom++)
{
const int globalAtom = globalAtomIndices[localAtom];
int moleculeIndex;
void constructVsitesGlobal(const gmx_mtop_t &mtop,
gmx::ArrayRef<gmx::RVec> x)
{
- GMX_ASSERT(x.size() >= static_cast<gmx::index>(mtop.natoms), "x should contain the whole system");
+ GMX_ASSERT(x.ssize() >= mtop.natoms, "x should contain the whole system");
GMX_ASSERT(!mtop.moleculeBlockIndices.empty(), "molblock indices are needed in constructVsitesGlobal");
for (size_t mb = 0; mb < mtop.molblock.size(); mb++)
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, 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.
MPI_Comm_size(comm, &numRanks);
if (numRanks % multidirs.size() != 0)
{
- gmx_fatal(FARGS, "The number of ranks (%d) is not a multiple of the number of simulations (%td)", numRanks, multidirs.size());
+ gmx_fatal(FARGS, "The number of ranks (%d) is not a multiple of the number of simulations (%td)", numRanks, multidirs.ssize());
}
int numRanksPerSim = numRanks/multidirs.size();
if (debug)
{
- fprintf(debug, "We have %td simulations, %d ranks per simulation, local simulation is %d\n", multidirs.size(), numRanksPerSim, rankWithinComm/numRanksPerSim);
+ fprintf(debug, "We have %td simulations, %d ranks per simulation, local simulation is %d\n", multidirs.ssize(), numRanksPerSim, rankWithinComm/numRanksPerSim);
}
ms = new gmx_multisim_t;
rvec *makeRvecArray(gmx::ArrayRef<const gmx::RVec> v,
gmx::index n)
{
- GMX_ASSERT(v.size() >= n, "We can't copy more elements than the vector size");
+ GMX_ASSERT(v.ssize() >= n, "We can't copy more elements than the vector size");
rvec *dest;
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
if (TRICLINIC(box))
{
- for (gmx::index i = 0; (i < x.size()); ++i)
+ for (gmx::index i = 0; (i < x.ssize()); ++i)
{
for (m = npbcdim-1; m >= 0; m--)
{
}
else
{
- for (gmx::index i = 0; (i < x.size()); ++i)
+ for (gmx::index i = 0; (i < x.ssize()); ++i)
{
for (d = 0; d < npbcdim; d++)
{
shift_center[1] = shm12*shift_center[2];
shift_center[2] = 0;
- for (gmx::index i = 0; (i < x.size()); ++i)
+ for (gmx::index i = 0; (i < x.ssize()); ++i)
{
for (m = DIM-1; m >= 0; m--)
{
}
calc_box_center(ecenter, box, box_center);
- for (gmx::index i = 0; (i < x.size()); ++i)
+ for (gmx::index i = 0; (i < x.ssize()); ++i)
{
pbc_dx(&pbc, x[i], box_center, dx);
rvec_add(box_center, dx, x[i]);
/* update the atom positions */
auto localAtomIndices = pgrp->atomSet.localIndex();
copy_dvec(dr, tmp);
- for (gmx::index j = 0; j < localAtomIndices.size(); j++)
+ for (gmx::index j = 0; j < localAtomIndices.ssize(); j++)
{
ii = localAtomIndices[j];
if (!pgrp->localWeights.empty())
gmx_enfrotgrp *erg = &ergRef;
Vrot += erg->V; /* add the local parts from the nodes */
const auto &localRotationGroupIndex = erg->atomSet->localIndex();
- for (gmx::index l = 0; l < localRotationGroupIndex.size(); l++)
+ for (gmx::index l = 0; l < localRotationGroupIndex.ssize(); l++)
{
/* Get the right index of the local force */
int ii = localRotationGroupIndex[l];
const auto &localRotationGroupIndex = erg->atomSet->localIndex();
const auto &collectiveRotationGroupIndex = erg->atomSet->collectiveIndex();
- for (gmx::index j = 0; j < localRotationGroupIndex.size(); j++)
+ for (gmx::index j = 0; j < localRotationGroupIndex.ssize(); j++)
{
/* Local index of a rotation group atom */
ii = localRotationGroupIndex[j];
const auto &localRotationGroupIndex = erg->atomSet->localIndex();
const auto &collectiveRotationGroupIndex = erg->atomSet->collectiveIndex();
- for (gmx::index j = 0; j < localRotationGroupIndex.size(); j++)
+ for (gmx::index j = 0; j < localRotationGroupIndex.ssize(); j++)
{
/* Local index of a rotation group atom */
int ii = localRotationGroupIndex[j];
/* Each process calculates the forces on its local atoms */
const auto &localRotationGroupIndex = erg->atomSet->localIndex();
const auto &collectiveRotationGroupIndex = erg->atomSet->collectiveIndex();
- for (gmx::index j = 0; j < localRotationGroupIndex.size(); j++)
+ for (gmx::index j = 0; j < localRotationGroupIndex.ssize(); j++)
{
/* Local index of a rotation group atom */
int ii = localRotationGroupIndex[j];
/* Each process calculates the forces on its local atoms */
const auto &localRotationGroupIndex = erg->atomSet->localIndex();
const auto &collectiveRotationGroupIndex = erg->atomSet->collectiveIndex();
- for (gmx::index j = 0; j < localRotationGroupIndex.size(); j++)
+ for (gmx::index j = 0; j < localRotationGroupIndex.ssize(); j++)
{
if (bPF)
{
matrix box, int npbcdim)
{
const auto &localRotationGroupIndex = erg->atomSet->localIndex();
- for (gmx::index i = 0; i < localRotationGroupIndex.size(); i++)
+ for (gmx::index i = 0; i < localRotationGroupIndex.ssize(); i++)
{
/* Index of a rotation group atom */
int ii = localRotationGroupIndex[i];
if (bNS)
{
const auto &collectiveRotationGroupIndex = erg->atomSet->collectiveIndex();
- for (gmx::index i = 0; i < collectiveRotationGroupIndex.size(); i++)
+ for (gmx::index i = 0; i < collectiveRotationGroupIndex.ssize(); i++)
{
/* Index of local atom w.r.t. the collective rotation group */
int ii = collectiveRotationGroupIndex[i];
pdyna.dv.resize(localAtomIndices.size());
/* loop over all atoms in the main ref group */
- for (gmx::index indexInSet = 0; indexInSet < localAtomIndices.size(); indexInSet++)
+ for (gmx::index indexInSet = 0; indexInSet < localAtomIndices.ssize(); indexInSet++)
{
int atomIndex = localAtomIndices[indexInSet];
rvec dx;
}
auto localAtomIndices = group.atomSet.localIndex();
- for (gmx::index indexInSet = 0; indexInSet < localAtomIndices.size(); indexInSet++)
+ for (gmx::index indexInSet = 0; indexInSet < localAtomIndices.ssize(); indexInSet++)
{
rvec dx;
pbc_dx(&pbc, x[localAtomIndices[indexInSet]], x_pbc, dx);
TestReferenceChecker compound(checker_.checkCompound("ParsedSelections", "Parsed"));
size_t varcount = 0;
count_ = 0;
- for (gmx::index i = 0; i < selections.size(); ++i)
+ for (gmx::index i = 0; i < selections.ssize(); ++i)
{
SCOPED_TRACE(std::string("Parsing selection \"")
+ selections[i] + "\"");
index j = 0;
for (int i = 0; i < atoms.nr; ++i, ++j)
{
- if (j == types.size())
+ if (j == types.ssize())
{
j = 0;
}
(*gnames)[b->nr] = gmx_strdup(name.c_str());
srenew(b->a, b->nra+a.size());
- for (int i = 0; (i < a.size()); i++)
+ for (int i = 0; (i < a.ssize()); i++)
{
b->a[b->nra++] = a[i];
}
gmx_fatal(FARGS, "no such index group %d in t_blocka (nr=%d)", index, b->nr);
}
/* compare sizes */
- if (a.size() != b->index[index+1] - b->index[index])
+ if (a.ssize() != b->index[index+1] - b->index[index])
{
return FALSE;
}
- for (int i = 0; i < a.size(); i++)
+ for (int i = 0; i < a.ssize(); i++)
{
if (a[i] != b->a[b->index[index]+i])
{
}
);
- for (int i = 0; (i < typenames.size()); i++)
+ for (int i = 0; (i < typenames.ssize()); i++)
{
if (counter[i] > 0)
{
for (int k = 0; k < inter_excl.nr; ++k)
{
inter_excl.index[k] = prev_index;
- for (long i = 0; i < ids.size(); i++)
+ for (long i = 0; i < ids.ssize(); i++)
{
if (k != ids[i])
{
{
fprintf(fp, "comparing molecule types\n");
cmp_int(fp, "moltype size", -1, mt1.size(), mt2.size());
- for (int i = 0; i < std::min(mt1.size(), mt2.size()); i++)
+ for (int i = 0; i < std::min(mt1.ssize(), mt2.ssize()); i++)
{
cmp_str(fp, "Name", i, *mt1[i].name, *mt2[i].name);
compareAtoms(fp, &mt1[i].atoms, &mt2[i].atoms, relativeTolerance, absoluteTolerance);
static void compareMoletypeAB(FILE *fp, gmx::ArrayRef<const gmx_moltype_t> mt1, real relativeTolerance, real absoluteTolerance)
{
fprintf(fp, "comparing free energy molecule types\n");
- for (int i = 0; i < mt1.size(); i++)
+ for (int i = 0; i < mt1.ssize(); i++)
{
compareAtoms(fp, &mt1[i].atoms, nullptr, relativeTolerance, absoluteTolerance);
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016,2017,2018,2019, 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.
//! Type of values stored in the reference.
typedef T value_type;
//! Type for representing size of the reference.
- typedef index size_type;
+ typedef size_t size_type;
//! Type for representing difference between two indices.
typedef ptrdiff_t difference_type;
//! Const reference to an element.
//! Returns an iterator to the reverse end of the reference.
reverse_iterator rend() const { return reverse_iterator(begin()); }
- //! Returns the size of the reference.
+ /*! \brief Returns the size of the reference.
+ *
+ * \note Use ssize for any expression involving arithmetic operations
+ (including loop indices).
+ */
size_type size() const { return end_ - begin_; }
+ //! Returns the signed size of the reference.
+ index ssize() const { return size(); }
//! Identical to size().
size_type capacity() const { return end_ - begin_; }
//! Whether the reference refers to no memory.