/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012,2013, by the GROMACS development team, led by
- * David van der Spoel, Berk Hess, Erik Lindahl, and including many
- * others, as listed in the AUTHORS file in the top-level source
- * directory and at http://www.gromacs.org.
+ * Copyright (c) 2009,2010,2011,2012,2013,2014, 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
* \author Teemu Murtola <teemu.murtola@gmail.com>
* \ingroup module_selection
*/
-#include "gromacs/selection/indexutil.h"
+#include "gmxpre.h"
+#include "indexutil.h"
+
+#include <cstdlib>
#include <cstring>
+#include <algorithm>
#include <string>
#include <vector>
-#include "gromacs/legacyheaders/index.h"
-#include "gromacs/legacyheaders/gmx_fatal.h"
-#include "gromacs/legacyheaders/smalloc.h"
-#include "gromacs/legacyheaders/typedefs.h"
-
+#include "gromacs/topology/block.h"
+#include "gromacs/topology/index.h"
+#include "gromacs/topology/topology.h"
+#include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/smalloc.h"
/********************************************************************
* gmx_ana_indexgrps_t functions
int n = find_group(const_cast<char *>(name), src->nr,
const_cast<char **>(names));
sfree(names);
- if (n == NOTSET)
+ if (n < 0)
{
dest->isize = 0;
return false;
{
for (int i = 0; i < g->nr; ++i)
{
- fprintf(fp, " Group %2d \"%s\" ", i + 1, g->names[i].c_str());
+ fprintf(fp, " Group %2d \"%s\" ", i, g->names[i].c_str());
gmx_ana_index_dump(fp, &g->g[i], maxn);
}
}
fprintf(fp, "\n");
}
+int
+gmx_ana_index_get_max_index(gmx_ana_index_t *g)
+{
+ if (g->isize == 0)
+ {
+ return 0;
+ }
+ else
+ {
+ return *std::max_element(g->index, g->index + g->isize);
+ }
+}
+
/*!
* \param[in] g Index group to check.
* \returns true if the index group is sorted and has no duplicates,
return true;
}
+bool
+gmx_ana_index_check_range(gmx_ana_index_t *g, int natoms)
+{
+ for (int i = 0; i < g->isize; ++i)
+ {
+ if (g->index[i] < 0 || g->index[i] >= natoms)
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
/********************************************************************
* Set operations
********************************************************************/
void
gmx_ana_index_sort(gmx_ana_index_t *g)
{
- qsort(g->index, g->isize, sizeof(*g->index), cmp_atomid);
+ std::qsort(g->index, g->isize, sizeof(*g->index), cmp_atomid);
}
/*!
break;
default: /* Should not be reached */
- gmx_bug("internal error");
+ GMX_RELEASE_ASSERT(false, "Unreachable code was reached");
break;
}
}
gmx_ana_indexmap_clear(gmx_ana_indexmap_t *m)
{
m->type = INDEX_UNKNOWN;
- m->nr = 0;
m->refid = NULL;
m->mapid = NULL;
m->mapb.nr = 0;
m->type = type;
gmx_ana_index_make_block(&m->b, top, g, type, false);
gmx_ana_indexmap_reserve(m, m->b.nr, m->b.nra);
- m->nr = m->b.nr;
- for (i = mi = 0; i < m->nr; ++i)
+ for (i = mi = 0; i < m->b.nr; ++i)
{
ii = (type == INDEX_UNKNOWN ? 0 : m->b.a[m->b.index[i]]);
switch (type)
break;
}
}
- for (i = 0; i < m->nr; ++i)
+ for (i = 0; i < m->b.nr; ++i)
{
m->refid[i] = i;
m->mapid[i] = m->orgid[i];
}
- m->mapb.nr = m->nr;
+ m->mapb.nr = m->b.nr;
m->mapb.nra = m->b.nra;
m->mapb.a = m->b.a;
- std::memcpy(m->mapb.index, m->b.index, (m->nr+1)*sizeof(*(m->mapb.index)));
+ std::memcpy(m->mapb.index, m->b.index, (m->b.nr+1)*sizeof(*(m->mapb.index)));
m->bStatic = true;
}
std::memcpy(dest->b.index, src->b.index, (dest->b.nr+1)*sizeof(*dest->b.index));
std::memcpy(dest->b.a, src->b.a, dest->b.nra*sizeof(*dest->b.a));
}
- dest->nr = src->nr;
dest->mapb.nr = src->mapb.nr;
dest->mapb.nra = src->mapb.nra;
if (src->mapb.nalloc_a > 0)
{
dest->mapb.a = src->mapb.a;
}
- std::memcpy(dest->refid, src->refid, dest->nr*sizeof(*dest->refid));
- std::memcpy(dest->mapid, src->mapid, dest->nr*sizeof(*dest->mapid));
+ std::memcpy(dest->refid, src->refid, dest->mapb.nr*sizeof(*dest->refid));
+ std::memcpy(dest->mapid, src->mapid, dest->mapb.nr*sizeof(*dest->mapid));
std::memcpy(dest->mapb.index, src->mapb.index, (dest->mapb.nr+1)*sizeof(*dest->mapb.index));
dest->bStatic = src->bStatic;
}
}
}
set_atoms(m, m->b.nra, m->b.a);
- m->nr = m->mapb.nr = m->b.nr;
+ m->mapb.nr = m->b.nr;
}
/* Exit immediately if the group is static */
if (bToFull)
if (bMaskOnly)
{
- m->nr = m->b.nr;
for (i = j = bj = 0; i < g->isize; ++i, ++j)
{
/* Find the next atom in the block */
}
/* Update the number of blocks */
m->mapb.index[bi] = g->isize;
- m->nr = bi;
+ m->mapb.nr = bi;
}
- m->mapb.nr = m->nr;
m->bStatic = false;
}