Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / selection / sm_merge.cpp
index c2ecf33a1b83ac316986cdd61f925704f5bf1eb0..9c8d2e3041d188cb7d6936a48bf825b7f1b52446 100644 (file)
@@ -1,51 +1,54 @@
 /*
+ * This file is part of the GROMACS molecular simulation package.
  *
- *                This source code is part of
+ * 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.
  *
- *                 G   R   O   M   A   C   S
+ * 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.
  *
- *          GROningen MAchine for Chemical Simulations
+ * 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.
  *
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * 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, 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 www.gromacs.org.
+ * 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 papers on the package - you can find them in the top README file.
- *
- * For more info, check our website at http://www.gromacs.org
+ * the research papers on the package. Check out http://www.gromacs.org.
  */
 /*! \internal \file
  * \brief
  * Implements the \p merge and \p plus selection modifiers.
  *
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_selection
  */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "macros.h"
-#include "smalloc.h"
-#include "vec.h"
+#include "gmxpre.h"
 
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/math/vec.h"
 #include "gromacs/selection/position.h"
-#include "gromacs/selection/selmethod.h"
+#include "gromacs/utility/common.h"
 #include "gromacs/utility/exceptions.h"
+#include "gromacs/utility/smalloc.h"
+
+#include "selmethod.h"
 
 /*! \internal \brief
  * Data structure for the merging selection modifiers.
@@ -56,8 +59,6 @@ typedef struct
     gmx_ana_pos_t    p1;
     /** Other input positions. */
     gmx_ana_pos_t    p2;
-    /** Group to store the output atom indices. */
-    gmx_ana_index_t  g;
     /** Stride for merging (\c stride values from \c p1 for each in \c p2). */
     int              stride;
 } t_methoddata_merge;
@@ -65,7 +66,15 @@ typedef struct
 /** Allocates data for the merging selection modifiers. */
 static void *
 init_data_merge(int npar, gmx_ana_selparam_t *param);
-/** Initializes data for the merging selection modifiers. */
+/*! \brief
+ * Initializes data for the merging selection modifiers.
+ *
+ * \param[in] top   Not used.
+ * \param[in] npar  Not used (should be 2 or 3).
+ * \param[in] param Method parameters (should point to \ref smparams_merge).
+ * \param[in] data  Should point to a \p t_methoddata_merge.
+ * \returns   0 if everything is successful, -1 on error.
+ */
 static void
 init_merge(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
 /** Initializes output for the \p merge selection modifier. */
@@ -77,14 +86,32 @@ init_output_plus(t_topology *top, gmx_ana_selvalue_t *out, void *data);
 /** Frees the memory allocated for the merging selection modifiers. */
 static void
 free_data_merge(void *data);
-/** Evaluates the \p merge selection modifier. */
+/*! \brief
+ * Evaluates the \p merge selection modifier.
+ *
+ * \param[in]  top   Not used.
+ * \param[in]  fr    Not used.
+ * \param[in]  pbc   Not used.
+ * \param[in]  p     Positions to merge (should point to \p data->p1).
+ * \param[out] out   Output data structure (\p out->u.p is used).
+ * \param[in]  data  Should point to a \p t_methoddata_merge.
+ */
 static void
 evaluate_merge(t_topology *top, t_trxframe *fr, t_pbc *pbc,
-               gmx_ana_pos_t *p, gmx_ana_selvalue_t *out, void *data);
-/** Evaluates the \p plus selection modifier. */
+               gmx_ana_pos_t * p, gmx_ana_selvalue_t *out, void *data);
+/*! \brief
+ * Evaluates the \p plus selection modifier.
+ *
+ * \param[in]  top   Not used.
+ * \param[in]  fr    Not used.
+ * \param[in]  pbc   Not used.
+ * \param[in]  p     Positions to merge (should point to \p data->p1).
+ * \param[out] out   Output data structure (\p out->u.p is used).
+ * \param[in]  data  Should point to a \p t_methoddata_merge.
+ */
 static void
 evaluate_plus(t_topology *top, t_trxframe *fr, t_pbc *pbc,
-              gmx_ana_pos_t *p, gmx_ana_selvalue_t *out, void *data);
+              gmx_ana_pos_t * p, gmx_ana_selvalue_t *out, void *data);
 
 /** Parameters for the merging selection modifiers. */
 static gmx_ana_selparam_t smparams_merge[] = {
@@ -119,7 +146,7 @@ static const char *help_merge[] = {
     "subexpressions.",
 };
 
-/** \internal Selection method data for the \p plus modifier. */
+/** Selection method data for the \p plus modifier. */
 gmx_ana_selmethod_t sm_merge = {
     "merge", POS_VALUE, SMETH_MODIFIER,
     asize(smparams_merge), smparams_merge,
@@ -134,7 +161,7 @@ gmx_ana_selmethod_t sm_merge = {
     {"merge POSEXPR", asize(help_merge), help_merge},
 };
 
-/** \internal Selection method data for the \p plus modifier. */
+/** Selection method data for the \p plus modifier. */
 gmx_ana_selmethod_t sm_plus = {
     "plus", POS_VALUE, SMETH_MODIFIER,
     asize(smparams_merge)-1, smparams_merge,
@@ -160,10 +187,8 @@ gmx_ana_selmethod_t sm_plus = {
 static void *
 init_data_merge(int npar, gmx_ana_selparam_t *param)
 {
-    t_methoddata_merge *data;
-
-    snew(data, 1);
-    data->stride = 0;
+    t_methoddata_merge *data = new t_methoddata_merge();
+    data->stride     = 0;
     param[0].val.u.p = &data->p1;
     param[1].val.u.p = &data->p2;
     if (npar > 2)
@@ -173,15 +198,8 @@ init_data_merge(int npar, gmx_ana_selparam_t *param)
     return data;
 }
 
-/*!
- * \param[in] top   Not used.
- * \param[in] npar  Not used (should be 2 or 3).
- * \param[in] param Method parameters (should point to \ref smparams_merge).
- * \param[in] data  Should point to a \p t_methoddata_merge.
- * \returns   0 if everything is successful, -1 on error.
- */
 static void
-init_merge(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
+init_merge(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t * /* param */, void *data)
 {
     t_methoddata_merge *d = (t_methoddata_merge *)data;
 
@@ -192,17 +210,12 @@ init_merge(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
     /* If no stride given, deduce it from the input sizes */
     if (d->stride == 0)
     {
-        d->stride = d->p1.nr / d->p2.nr;
+        d->stride = d->p1.count() / d->p2.count();
     }
-    if (d->p1.nr != d->stride*d->p2.nr)
+    if (d->p1.count() != d->stride*d->p2.count())
     {
         GMX_THROW(gmx::InconsistentInputError("The number of positions to be merged are not compatible"));
     }
-    /* We access the m.b.nra field instead of g->isize in the position
-     * data structures to handle cases where g is NULL
-     * (this occurs with constant positions. */
-    gmx_ana_index_reserve(&d->g, d->p1.m.b.nra + d->p2.m.b.nra);
-    d->g.isize = d->p1.m.b.nra + d->p2.m.b.nra;
 }
 
 /*! \brief
@@ -217,6 +230,7 @@ init_output_common(t_topology *top, gmx_ana_selvalue_t *out, void *data)
 {
     t_methoddata_merge *d = (t_methoddata_merge *)data;
 
+    GMX_UNUSED_VALUE(top);
     if (d->p1.m.type != d->p2.m.type)
     {
         /* TODO: Maybe we could pick something else here? */
@@ -226,18 +240,10 @@ init_output_common(t_topology *top, gmx_ana_selvalue_t *out, void *data)
     {
         out->u.p->m.type = d->p1.m.type;
     }
-    gmx_ana_pos_reserve(out->u.p, d->p1.nr + d->p2.nr, d->g.isize);
-    if (d->p1.v)
-    {
-        gmx_ana_pos_reserve_velocities(out->u.p);
-    }
-    if (d->p1.f)
-    {
-        gmx_ana_pos_reserve_forces(out->u.p);
-    }
-    gmx_ana_pos_set_evalgrp(out->u.p, &d->g);
+    gmx_ana_pos_reserve_for_append(out->u.p, d->p1.count() + d->p2.count(),
+                                   d->p1.m.b.nra + d->p2.m.b.nra,
+                                   d->p1.v != NULL, d->p1.f != NULL);
     gmx_ana_pos_empty_init(out->u.p);
-    d->g.isize = 0;
 }
 
 /*!
@@ -252,13 +258,13 @@ init_output_merge(t_topology *top, gmx_ana_selvalue_t *out, void *data)
     int                 i, j;
 
     init_output_common(top, out, data);
-    for (i = 0; i < d->p2.nr; ++i)
+    for (i = 0; i < d->p2.count(); ++i)
     {
         for (j = 0; j < d->stride; ++j)
         {
-            gmx_ana_pos_append_init(out->u.p, &d->g, &d->p1, d->stride*i+j);
+            gmx_ana_pos_append_init(out->u.p, &d->p1, d->stride * i + j);
         }
-        gmx_ana_pos_append_init(out->u.p, &d->g, &d->p2, i);
+        gmx_ana_pos_append_init(out->u.p, &d->p2, i);
     }
 }
 
@@ -274,13 +280,13 @@ init_output_plus(t_topology *top, gmx_ana_selvalue_t *out, void *data)
     int                 i;
 
     init_output_common(top, out, data);
-    for (i = 0; i < d->p1.nr; ++i)
+    for (i = 0; i < d->p1.count(); ++i)
     {
-        gmx_ana_pos_append_init(out->u.p, &d->g, &d->p1, i);
+        gmx_ana_pos_append_init(out->u.p, &d->p1, i);
     }
-    for (i = 0; i < d->p2.nr; ++i)
+    for (i = 0; i < d->p2.count(); ++i)
     {
-        gmx_ana_pos_append_init(out->u.p, &d->g, &d->p2, i);
+        gmx_ana_pos_append_init(out->u.p, &d->p2, i);
     }
 }
 
@@ -293,34 +299,23 @@ static void
 free_data_merge(void *data)
 {
     t_methoddata_merge *d = (t_methoddata_merge *)data;
-
-    gmx_ana_index_deinit(&d->g);
-    sfree(d);
+    delete d;
 }
 
-/*!
- * \param[in]  top   Not used.
- * \param[in]  fr    Not used.
- * \param[in]  pbc   Not used.
- * \param[in]  p     Positions to merge (should point to \p data->p1).
- * \param[out] out   Output data structure (\p out->u.p is used).
- * \param[in]  data  Should point to a \p t_methoddata_merge.
- */
 static void
-evaluate_merge(t_topology *top, t_trxframe *fr, t_pbc *pbc,
-               gmx_ana_pos_t *p, gmx_ana_selvalue_t *out, void *data)
+evaluate_merge(t_topology * /* top */, t_trxframe * /* fr */, t_pbc * /* pbc */,
+               gmx_ana_pos_t * /* p */, gmx_ana_selvalue_t *out, void *data)
 {
     t_methoddata_merge *d = (t_methoddata_merge *)data;
     int                 i, j;
     int                 refid;
 
-    if (d->p1.nr != d->stride*d->p2.nr)
+    if (d->p1.count() != d->stride*d->p2.count())
     {
         GMX_THROW(gmx::InconsistentInputError("The number of positions to be merged are not compatible"));
     }
-    d->g.isize = 0;
     gmx_ana_pos_empty(out->u.p);
-    for (i = 0; i < d->p2.nr; ++i)
+    for (i = 0; i < d->p2.count(); ++i)
     {
         for (j = 0; j < d->stride; ++j)
         {
@@ -329,45 +324,36 @@ evaluate_merge(t_topology *top, t_trxframe *fr, t_pbc *pbc,
             {
                 refid = (d->stride+1) * (refid / d->stride) + (refid % d->stride);
             }
-            gmx_ana_pos_append(out->u.p, &d->g, &d->p1, d->stride*i+j, refid);
+            gmx_ana_pos_append(out->u.p, &d->p1, d->stride*i+j, refid);
         }
-        refid = (d->stride+1)*d->p2.m.refid[i]+d->stride;
-        gmx_ana_pos_append(out->u.p, &d->g, &d->p2, i, refid);
+        refid = (d->stride+1)*d->p2.m.refid[i] + d->stride;
+        gmx_ana_pos_append(out->u.p, &d->p2, i, refid);
     }
     gmx_ana_pos_append_finish(out->u.p);
 }
 
-/*!
- * \param[in]  top   Not used.
- * \param[in]  fr    Not used.
- * \param[in]  pbc   Not used.
- * \param[in]  p     Positions to merge (should point to \p data->p1).
- * \param[out] out   Output data structure (\p out->u.p is used).
- * \param[in]  data  Should point to a \p t_methoddata_merge.
- */
 static void
-evaluate_plus(t_topology *top, t_trxframe *fr, t_pbc *pbc,
-              gmx_ana_pos_t *p, gmx_ana_selvalue_t *out, void *data)
+evaluate_plus(t_topology * /* top */, t_trxframe * /* fr */, t_pbc * /* pbc */,
+              gmx_ana_pos_t * /* p */, gmx_ana_selvalue_t *out, void *data)
 {
     t_methoddata_merge *d = (t_methoddata_merge *)data;
     int                 i;
     int                 refid;
 
-    d->g.isize = 0;
     gmx_ana_pos_empty(out->u.p);
-    for (i = 0; i < d->p1.nr; ++i)
+    for (i = 0; i < d->p1.count(); ++i)
     {
         refid = d->p1.m.refid[i];
-        gmx_ana_pos_append(out->u.p, &d->g, &d->p1, i, refid);
+        gmx_ana_pos_append(out->u.p, &d->p1, i, refid);
     }
-    for (i = 0; i < d->p2.nr; ++i)
+    for (i = 0; i < d->p2.count(); ++i)
     {
         refid = d->p2.m.refid[i];
         if (refid != -1)
         {
             refid += d->p1.m.b.nr;
         }
-        gmx_ana_pos_append(out->u.p, &d->g, &d->p2, i, refid);
+        gmx_ana_pos_append(out->u.p, &d->p2, i, refid);
     }
     gmx_ana_pos_append_finish(out->u.p);
 }