Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / selection / selection.cpp
index ea476706647ade23ae96ae20b22d1d1afbb6bb39..99bd2abd5ca4c5e5c6c1942bde16c7cb264f6cd4 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * 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 "gmxpre.h"
+
 #include "selection.h"
 
-#include "nbsearch.h"
-#include "position.h"
+#include "gromacs/selection/nbsearch.h"
+#include "gromacs/selection/position.h"
+#include "gromacs/topology/topology.h"
+
 #include "selelem.h"
 #include "selvalue.h"
 
@@ -63,8 +67,6 @@ SelectionData::SelectionData(SelectionTreeElement *elem,
       coveredFraction_(1.0), averageCoveredFraction_(1.0),
       bDynamic_(false), bDynamicCoveredFraction_(false)
 {
-    gmx_ana_pos_clear(&rawPositions_);
-
     if (elem->child->type == SEL_CONST)
     {
         // TODO: This is not exception-safe if any called function throws.
@@ -107,7 +109,6 @@ SelectionData::SelectionData(SelectionTreeElement *elem,
 
 SelectionData::~SelectionData()
 {
-    gmx_ana_pos_deinit(&rawPositions_);
 }
 
 
@@ -153,13 +154,13 @@ void computeMassesAndCharges(const t_topology *top, const gmx_ana_pos_t &pos,
     GMX_ASSERT(top != NULL, "Should not have been called with NULL topology");
     masses->clear();
     charges->clear();
-    for (int b = 0; b < pos.nr; ++b)
+    for (int b = 0; b < pos.count(); ++b)
     {
         real mass   = 0.0;
         real charge = 0.0;
         for (int i = pos.m.mapb.index[b]; i < pos.m.mapb.index[b+1]; ++i)
         {
-            int index = pos.g->index[i];
+            const int index = pos.m.mapb.a[i];
             mass   += top->atoms.atom[index].m;
             charge += top->atoms.atom[index].q;
         }
@@ -234,9 +235,8 @@ SelectionData::restoreOriginalPositions(const t_topology *top)
     if (isDynamic())
     {
         gmx_ana_pos_t &p = rawPositions_;
-        gmx_ana_index_copy(p.g, rootElement().v.u.g, false);
-        gmx_ana_indexmap_update(&p.m, p.g, hasFlag(gmx::efSelection_DynamicMask));
-        p.nr = p.m.nr;
+        gmx_ana_indexmap_update(&p.m, rootElement().v.u.g,
+                                hasFlag(gmx::efSelection_DynamicMask));
         refreshMassesAndCharges(top);
     }
 }
@@ -249,8 +249,13 @@ SelectionData::restoreOriginalPositions(const t_topology *top)
 
 Selection::operator AnalysisNeighborhoodPositions() const
 {
-    return AnalysisNeighborhoodPositions(data().rawPositions_.x,
-                                         data().rawPositions_.nr);
+    AnalysisNeighborhoodPositions pos(data().rawPositions_.x,
+                                      data().rawPositions_.count());
+    if (hasOnlyAtoms())
+    {
+        pos.exclusionIds(atomIndices());
+    }
+    return pos;
 }
 
 
@@ -273,7 +278,9 @@ Selection::printDebugInfo(FILE *fp, int nmaxind) const
     fprintf(fp, "  ");
     printInfo(fp);
     fprintf(fp, "    Group ");
-    gmx_ana_index_dump(fp, p.g, nmaxind);
+    gmx_ana_index_t g;
+    gmx_ana_index_set(&g, p.m.mapb.nra, p.m.mapb.a, 0);
+    gmx_ana_index_dump(fp, &g, nmaxind);
 
     fprintf(fp, "    Block (size=%d):", p.m.mapb.nr);
     if (!p.m.mapb.index)
@@ -347,9 +354,15 @@ Selection::printDebugInfo(FILE *fp, int nmaxind) const
 
 SelectionPosition::operator AnalysisNeighborhoodPositions() const
 {
-    return AnalysisNeighborhoodPositions(sel_->rawPositions_.x,
-                                         sel_->rawPositions_.nr)
-               .selectSingleFromArray(i_);
+    AnalysisNeighborhoodPositions pos(sel_->rawPositions_.x,
+                                      sel_->rawPositions_.count());
+    if (sel_->hasOnlyAtoms())
+    {
+        // TODO: Move atomIndices() such that it can be reused here as well.
+        pos.exclusionIds(constArrayRefFromArray<int>(sel_->rawPositions_.m.mapb.a,
+                                                     sel_->rawPositions_.m.mapb.nra));
+    }
+    return pos.selectSingleFromArray(i_);
 }
 
 } // namespace gmx