*/
#include "gmxpre.h"
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
/* Generate new swapping candidates */
do
{
- iswap = 1+(nn-2)*gmx_rng_uniform_real(rng);
- jswap = 1+(nn-2)*gmx_rng_uniform_real(rng);
+ iswap = static_cast<int>(1+(nn-2)*gmx_rng_uniform_real(rng));
+ jswap = static_cast<int>(1+(nn-2)*gmx_rng_uniform_real(rng));
}
while ((iswap == jswap) || (iswap >= nn-1) || (jswap >= nn-1));
else if (kT > 0)
{
/* Try Monte Carlo step */
- prob = exp(-(enext-ecur)/(enorm*kT));
+ prob = std::exp(-(enext-ecur)/(enorm*kT));
}
if ((prob == 1) || (gmx_rng_uniform_real(rng) < prob))
}
r2 /= (isize*(isize-1))/2;
- return sqrt(r2);
+ return std::sqrt(r2);
}
static int rms_dist_comp(const void *a, const void *b)
t_dist *row;
t_clustid *c;
int **nnb;
- int i, j, k, cid, diff, max;
+ int i, j, k, cid, diff, maxval;
gmx_bool bChange;
real **mcpy = NULL;
else
{
/* Put all neighbors nearer than rmsdcut in the list */
- max = 0;
- k = 0;
+ maxval = 0;
+ k = 0;
for (j = 0; (j < n1) && (mat[i][row[j].j] < rmsdcut); j++)
{
if (row[j].j != i)
{
- if (k >= max)
+ if (k >= maxval)
{
- max += 10;
- srenew(nnb[i], max);
+ maxval += 10;
+ srenew(nnb[i], maxval);
}
nnb[i][k] = row[j].j;
k++;
}
}
- if (k == max)
+ if (k == maxval)
{
- srenew(nnb[i], max+1);
+ srenew(nnb[i], maxval+1);
}
nnb[i][k] = -1;
}
}
}
-/* Again, I don't see the point in this... (AF) */
-/* for(i=0; (i<n1); i++) { */
-/* for(j=0; (j<n1); j++) */
-/* mcpy[c[i].conf][c[j].conf] = mat[i][j]; */
-/* } */
-/* for(i=0; (i<n1); i++) { */
-/* for(j=0; (j<n1); j++) */
-/* mat[i][j] = mcpy[i][j]; */
-/* } */
done_matrix(n1, &mcpy);
sfree(c);
{
t_dist *row;
t_nnb *nnb;
- int i, j, k, j1, max;
+ int i, j, k, j1, maxval;
/* Put all neighbors nearer than rmsdcut in the list */
fprintf(stderr, "Making list of neighbors within cutoff ");
snew(row, n1);
for (i = 0; (i < n1); i++)
{
- max = 0;
- k = 0;
+ maxval = 0;
+ k = 0;
/* put all neighbors within cut-off in list */
for (j = 0; j < n1; j++)
{
if (mat[i][j] < rmsdcut)
{
- if (k >= max)
+ if (k >= maxval)
{
- max += 10;
- srenew(nnb[i].nb, max);
+ maxval += 10;
+ srenew(nnb[i].nb, maxval);
}
nnb[i].nb[k] = j;
k++;
static void mark_clusters(int nf, real **mat, real val, t_clusters *clust)
{
- int i, j, v;
+ int i, j;
for (i = 0; i < nf; i++)
{
const char *ext;
char buf[STRLEN];
- if (strchr(fn, '%'))
+ if (std::strchr(fn, '%'))
{
gmx_fatal(FARGS, "will not number filename %s containing '%c'", fn, '%');
}
/* number of digits needed in numbering */
- i = (int)(log(maxnr)/log(10)) + 1;
+ i = static_cast<int>((std::log(static_cast<real>(maxnr))/std::log(10.0)) + 1);
/* split fn and ext */
- ext = strrchr(fn, '.');
+ ext = std::strrchr(fn, '.');
if (!ext)
{
gmx_fatal(FARGS, "cannot separate extension in filename %s", fn);
ext++;
/* insert e.g. '%03d' between fn and ext */
sprintf(buf, "%s%%0%dd.%s", fn, i, ext);
- snew(fnout, strlen(buf)+1);
- strcpy(fnout, buf);
+ snew(fnout, std::strlen(buf)+1);
+ std::strcpy(fnout, buf);
return fnout;
}
ntrans[clust->cl[i-1]-1]++;
ntrans[clust->cl[i]-1]++;
trans[clust->cl[i-1]-1][clust->cl[i]-1]++;
- maxtrans = max(maxtrans, trans[clust->cl[i]-1][clust->cl[i-1]-1]);
+ maxtrans = static_cast<int>(std::max(static_cast<real>(maxtrans), trans[clust->cl[i]-1][clust->cl[i-1]-1]));
}
}
ffprintf_dd(stderr, log, buf, "Counted %d transitions in total, "
if (transfn)
{
fp = gmx_ffopen(transfn, "w");
- i = min(maxtrans+1, 80);
+ i = std::min(maxtrans+1, 80);
write_xpm(fp, 0, "Cluster Transitions", "# transitions",
"from cluster", "to cluster",
clust->ncl, clust->ncl, axis, axis, trans,
/* do we write all structures? */
if (write_ncl)
{
- trxsfn = parse_filename(trxfn, max(write_ncl, clust->ncl));
+ trxsfn = parse_filename(trxfn, std::max(write_ncl, clust->ncl));
snew(bWrite, nf);
}
ffprintf_ss(stderr, log, buf, "Writing %s structure for each cluster to %s\n",
{
do_fit(natom, mass, xtps, xav);
}
- r = cl;
write_trx(trxout, iosize, outidx, atoms, cl, time[midstr], zerobox, xav, NULL, NULL);
}
}
for (j = i; j < mat->nx; j++)
{
rms->sumrms += rms->mat[i][j];
- rms->maxrms = max(rms->maxrms, rms->mat[i][j]);
+ rms->maxrms = std::max(rms->maxrms, rms->mat[i][j]);
if (j != i)
{
- rms->minrms = min(rms->minrms, rms->mat[i][j]);
+ rms->minrms = std::min(rms->minrms, rms->mat[i][j]);
}
}
}
real *eigenvectors;
int isize = 0, ifsize = 0, iosize = 0;
- atom_id *index = NULL, *fitidx, *outidx;
+ atom_id *index = NULL, *fitidx = NULL, *outidx = NULL;
char *grpname;
real rmsd, **d1, **d2, *time = NULL, time_invfac, *mass = NULL;
char buf[STRLEN], buf1[80], title[STRLEN];
else /* !bReadMat */
{
rms = init_mat(nf, method == m_diagonalize);
- nrms = ((gmx_int64_t)nf*((gmx_int64_t)nf-1))/2;
+ nrms = (static_cast<gmx_int64_t>(nf)*static_cast<gmx_int64_t>(nf-1))/2;
if (!bRMSdist)
{
fprintf(stderr, "Computing %dx%d RMS deviation matrix\n", nf, nf);
rmsd = rmsdev(isize, mass, xx[i2], x1);
set_mat_entry(rms, i1, i2, rmsd);
}
- nrms -= (gmx_int64_t) (nf-i1-1);
- fprintf(stderr, "\r# RMSD calculations left: " "%"GMX_PRId64 " ", nrms);
+ nrms -= nf-i1-1;
+ fprintf(stderr, "\r# RMSD calculations left: " "%" GMX_PRId64 " ", nrms);
}
sfree(x1);
}
calc_dist(isize, xx[i2], d2);
set_mat_entry(rms, i1, i2, rms_dist(isize, d1, d2));
}
- nrms -= (nf-i1-1);
- fprintf(stderr, "\r# RMSD calculations left: " "%"GMX_PRId64 " ", nrms);
+ nrms -= nf-i1-1;
+ fprintf(stderr, "\r# RMSD calculations left: " "%" GMX_PRId64 " ", nrms);
}
/* Clean up work arrays */
for (i = 0; (i < isize); i++)
/* Do a diagonalization */
snew(eigenvalues, nf);
snew(eigenvectors, nf*nf);
- memcpy(eigenvectors, rms->mat[0], nf*nf*sizeof(real));
+ std::memcpy(eigenvectors, rms->mat[0], nf*nf*sizeof(real));
eigensolver(eigenvectors, nf, 0, nf, eigenvalues, rms->mat[0]);
sfree(eigenvectors);
{
useatoms.atomname[i] = top.atoms.atomname[index[i]];
useatoms.atom[i].resind = top.atoms.atom[index[i]].resind;
- useatoms.nres = max(useatoms.nres, useatoms.atom[i].resind+1);
+ useatoms.nres = std::max(useatoms.nres, useatoms.atom[i].resind+1);
copy_rvec(xtps[index[i]], usextps[i]);
}
useatoms.nr = isize;
{
write_xpm_split(fp, 0, title, "RMSD (nm)", buf, buf,
nf, nf, time, time, rms->mat, 0.0, rms->maxrms, &nlevels,
- rlo_top, rhi_top, 0.0, (real) ncluster,
+ rlo_top, rhi_top, 0.0, ncluster,
&ncluster, TRUE, rlo_bot, rhi_bot);
}
else