Removed Selection::indexGroup().
authorTeemu Murtola <teemu.murtola@gmail.com>
Wed, 11 Apr 2012 19:47:23 +0000 (22:47 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Wed, 11 Apr 2012 19:50:47 +0000 (22:50 +0300)
This method provided access to the old C structure that was used in 4.5
to expose the selected atoms to help in converting code that used
certain old C functions.  Now this structure should be considered an
implementation detail of the selection module, and the new C++ API
should be preferred.  Changed remaining uses of the method to use
alternative approaches (which actually simplified select.cpp somewhat).

Change-Id: I8806b3e080b6fafd83d7634308f39f7335021376

src/gromacs/selection/selection.h
src/gromacs/trajectoryanalysis/modules/select.cpp
src/gromacs/trajectoryanalysis/modules/select.h
src/gromacs/trajectoryanalysis/tests/test_selection.cpp

index d87b928b93c6c13167a2434e293a5a733514d699..8ba6682518e3ee94aa642ca00c91ed3b44e27263 100644 (file)
@@ -278,8 +278,6 @@ class Selection
 
         //! Deprecated method for direct access to position data.
         const gmx_ana_pos_t *positions() const { return &data().rawPositions_; }
-        //! Deprecated method for direct access to atom index data.
-        gmx_ana_index_t *indexGroup() const { return data().rawPositions_.g; }
 
         /*! \brief
          * Initializes information about covered fractions.
index 8a63af9d3fddd845a0e5bffe130c052454a58d7e..246fc8669ecc34315122908ffd889e9121ea4923 100644 (file)
@@ -47,7 +47,6 @@
 #include <vector>
 
 #include <gmxfio.h>
-#include <smalloc.h>
 
 #include "gromacs/analysisdata/analysisdata.h"
 #include "gromacs/analysisdata/dataframe.h"
@@ -235,39 +234,6 @@ void IndexFileWriterModule::dataFinished()
 } // namespace
 
 
-/********************************************************************
- * Select::ModuleData
- */
-
-class Select::ModuleData : public TrajectoryAnalysisModuleData
-{
-    public:
-        ModuleData(TrajectoryAnalysisModule *module,
-                   const AnalysisDataParallelOptions &opt,
-                   const SelectionCollection &selections)
-            : TrajectoryAnalysisModuleData(module, opt, selections),
-              _mmap(NULL)
-        {
-        }
-
-        virtual ~ModuleData()
-        {
-            if (_mmap)
-            {
-                gmx_ana_indexmap_deinit(_mmap);
-                sfree(_mmap);
-            }
-        }
-
-        virtual void finish()
-        {
-            finishDataHandles();
-        }
-
-        gmx_ana_indexmap_t  *_mmap;
-};
-
-
 /********************************************************************
  * Select
  */
@@ -275,7 +241,7 @@ class Select::ModuleData : public TrajectoryAnalysisModuleData
 Select::Select()
     : _options("select", "Selection information"),
       _bDump(false), _bTotNorm(false), _bFracNorm(false), _bResInd(false),
-      _top(NULL), _totsize(NULL)
+      _top(NULL)
 {
 }
 
@@ -384,10 +350,10 @@ Select::initAnalysis(const TrajectoryAnalysisSettings &settings,
     // TODO: For large systems, a float may not have enough precision
     _sdata.setColumnCount(_sel.size());
     registerAnalysisDataset(&_sdata, "size");
-    snew(_totsize, _sel.size());
+    _totsize.reserve(_sel.size());
     for (size_t g = 0; g < _sel.size(); ++g)
     {
-        _totsize[g] = _bTotNorm ? _sel[g].posCount() : 1;
+        _totsize.push_back(_sel[g].posCount());
     }
     if (!_fnSize.empty())
     {
@@ -477,23 +443,10 @@ Select::initAnalysis(const TrajectoryAnalysisSettings &settings,
 }
 
 
-TrajectoryAnalysisModuleDataPointer
-Select::startFrames(const AnalysisDataParallelOptions &opt,
-                    const SelectionCollection &selections)
-{
-    ModuleData *pdata = new ModuleData(this, opt, selections);
-    snew(pdata->_mmap, 1);
-    gmx_ana_indexmap_init(pdata->_mmap, pdata->parallelSelection(_sel[0]).indexGroup(),
-                          _top, _sel[0].type());
-    return TrajectoryAnalysisModuleDataPointer(pdata);
-}
-
-
 void
 Select::analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
                      TrajectoryAnalysisModuleData *pdata)
 {
-    ModuleData *d = static_cast<ModuleData *>(pdata);
     AnalysisDataHandle sdh = pdata->dataHandle(_sdata);
     AnalysisDataHandle cdh = pdata->dataHandle(_cdata);
     AnalysisDataHandle idh = pdata->dataHandle(_idata);
@@ -504,7 +457,10 @@ Select::analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
     for (size_t g = 0; g < sel.size(); ++g)
     {
         real normfac = _bFracNorm ? 1.0 / sel[g].coveredFraction() : 1.0;
-        normfac /= _totsize[g];
+        if (_bTotNorm)
+        {
+            normfac /= _totsize[g];
+        }
         sdh.setPoint(g, sel[g].posCount() * normfac);
     }
     sdh.finishFrame();
@@ -537,11 +493,16 @@ Select::analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
     }
     idh.finishFrame();
 
-    gmx_ana_indexmap_update(d->_mmap, sel[0].indexGroup(), true);
     mdh.startFrame(frnr, fr.time);
-    for (int b = 0; b < d->_mmap->nr; ++b)
+    int nextRefId = sel[0].position(0).refId();
+    for (int b = 0, i = 0; b < _totsize[0]; ++b)
     {
-        mdh.setPoint(b, d->_mmap->refid[b] == -1 ? 0 : 1);
+        mdh.setPoint(b, b == nextRefId ? 1 : 0);
+        if (b == nextRefId)
+        {
+            ++i;
+            nextRefId = sel[0].position(i).refId();
+        }
     }
     mdh.finishFrame();
 }
index 4f1295931f3867391091778311c6e2fe066e2db2..a31410e7f10830aecff4f91d87dc54d48df8b09e 100644 (file)
@@ -39,6 +39,7 @@
 #define GMX_TRAJECTORYANALYSIS_MODULES_SELECT_H
 
 #include <string>
+#include <vector>
 
 #include "../analysismodule.h"
 #include "gromacs/analysisdata/analysisdata.h"
@@ -63,9 +64,6 @@ class Select : public TrajectoryAnalysisModule
         virtual void initAnalysis(const TrajectoryAnalysisSettings &settings,
                                   const TopologyInformation &top);
 
-        virtual TrajectoryAnalysisModuleDataPointer startFrames(
-                    const AnalysisDataParallelOptions &opt,
-                    const SelectionCollection &selections);
         virtual void analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
                                   TrajectoryAnalysisModuleData *pdata);
 
@@ -73,8 +71,6 @@ class Select : public TrajectoryAnalysisModule
         virtual void writeOutput();
 
     private:
-        class ModuleData;
-
         Options                  _options;
         SelectionList            _sel;
 
@@ -90,7 +86,7 @@ class Select : public TrajectoryAnalysisModule
         std::string              _resNumberType;
 
         t_topology              *_top;
-        int                     *_totsize;
+        std::vector<int>         _totsize;
         AnalysisData             _sdata;
         AnalysisData             _cdata;
         AnalysisData             _idata;
index 9405cf466e6388c02b8c85988e416ada9cd82ea0..e0281dfdd1e0eeadde84db352bf0df34565b7840 100644 (file)
@@ -128,10 +128,27 @@ SelectionTester::analyzeFrame(int /*frnr*/, const t_trxframe &/*fr*/, t_pbc * /*
     for (size_t g = 0; g < _selections.size(); ++g)
     {
         const Selection &sel = _selections[g];
+        int n;
+
+        fprintf(stderr, "  Atoms (%d pcs):", sel.atomCount());
+        n = sel.atomCount();
+        if (_nmaxind >= 0 && n > _nmaxind)
+        {
+            n = _nmaxind;
+        }
+        ConstArrayRef<int> atoms = sel.atomIndices();
+        for (int i = 0; i < n; ++i)
+        {
+            fprintf(stderr, " %d", atoms[i]+1);
+        }
+        if (n < sel.atomCount())
+        {
+            fprintf(stderr, " ...");
+        }
+        fprintf(stderr, "\n");
 
-        gmx_ana_index_dump(stderr, sel.indexGroup(), g, _nmaxind);
         fprintf(stderr, "  Positions (%d pcs):\n", sel.posCount());
-        int n = sel.posCount();
+        n = sel.posCount();
         if (_nmaxind >= 0 && n > _nmaxind)
         {
             n = _nmaxind;