Merge branch release-2021
[alexxy/gromacs.git] / api / nblib / topology.cpp
index ca5b3df8c223e96f6473be3f1a1a26b5d1d020ab..acaea4999f2a25cce5fc775f78aa112c10122f55 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2020, by the GROMACS development team, led by
+ * Copyright (c) 2020,2021, 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.
@@ -42,6 +42,7 @@
  * \author Sebastian Keller <keller@cscs.ch>
  * \author Artem Zhmurov <zhmurov@gmail.com>
  */
+#include <algorithm>
 #include <numeric>
 
 #include "gromacs/topology/exclusionblocks.h"
 #include "gromacs/utility/smalloc.h"
 #include "nblib/exception.h"
 #include "nblib/particletype.h"
+#include "nblib/sequencing.hpp"
 #include "nblib/topology.h"
-#include "nblib/util/internal.h"
+#include "nblib/util/util.hpp"
+#include "nblib/topologyhelpers.h"
 
 namespace nblib
 {
 
 TopologyBuilder::TopologyBuilder() : numParticles_(0) {}
 
-gmx::ListOfLists<int> TopologyBuilder::createExclusionsListOfLists() const
+ExclusionLists<int> TopologyBuilder::createExclusionsLists() const
 {
     const auto& moleculesList = molecules_;
 
@@ -76,14 +79,12 @@ gmx::ListOfLists<int> TopologyBuilder::createExclusionsListOfLists() const
                 "No exclusions found in the " + molecule.name().value() + " molecule.";
         assert((!exclusions.empty() && message.c_str()));
 
-        std::vector<gmx::ExclusionBlock> exclusionBlockPerMolecule =
-                detail::toGmxExclusionBlock(exclusions);
+        std::vector<gmx::ExclusionBlock> exclusionBlockPerMolecule = toGmxExclusionBlock(exclusions);
 
         // duplicate the exclusionBlockPerMolecule for the number of Molecules of (numMols)
         for (size_t i = 0; i < numMols; ++i)
         {
-            auto offsetExclusions =
-                    detail::offsetGmxBlock(exclusionBlockPerMolecule, particleNumberOffset);
+            auto offsetExclusions = offsetGmxBlock(exclusionBlockPerMolecule, particleNumberOffset);
 
             std::copy(std::begin(offsetExclusions),
                       std::end(offsetExclusions),
@@ -99,10 +100,18 @@ gmx::ListOfLists<int> TopologyBuilder::createExclusionsListOfLists() const
         exclusionsListOfListsGlobal.pushBack(block.atomNumber);
     }
 
-    return exclusionsListOfListsGlobal;
+    std::vector<int>    listRanges(exclusionsListOfListsGlobal.listRangesView().begin(),
+                                exclusionsListOfListsGlobal.listRangesView().end());
+    std::vector<int>    listElements(exclusionsListOfListsGlobal.elementsView().begin(),
+                                  exclusionsListOfListsGlobal.elementsView().end());
+    ExclusionLists<int> exclusionListsGlobal;
+    exclusionListsGlobal.ListRanges   = std::move(listRanges);
+    exclusionListsGlobal.ListElements = std::move(listElements);
+
+    return exclusionListsGlobal;
 }
 
-ListedInteractionData TopologyBuilder::createInteractionData(const detail::ParticleSequencer& particleSequencer)
+ListedInteractionData TopologyBuilder::createInteractionData(const ParticleSequencer& particleSequencer)
 {
     ListedInteractionData interactionData;
 
@@ -194,11 +203,9 @@ Topology TopologyBuilder::buildTopology()
     }
     topology_.numParticles_ = numParticles_;
 
-    topology_.exclusions_ = createExclusionsListOfLists();
-    topology_.charges_    = extractParticleTypeQuantity<real>([](const auto& data, auto& map) {
-        ignore_unused(map);
-        return data.charge_;
-    });
+    topology_.exclusionLists_ = createExclusionsLists();
+    topology_.charges_        = extractParticleTypeQuantity<real>(
+            [](const auto& data, [[maybe_unused]] auto& map) { return data.charge_; });
 
     // map unique ParticleTypes to IDs
     std::unordered_map<std::string, int> nameToId;
@@ -209,12 +216,11 @@ Topology TopologyBuilder::buildTopology()
     }
 
     topology_.particleTypeIdOfAllParticles_ =
-            extractParticleTypeQuantity<int>([&nameToId](const auto& data, auto& map) {
-                ignore_unused(map);
+            extractParticleTypeQuantity<int>([&nameToId](const auto& data, [[maybe_unused]] auto& map) {
                 return nameToId[data.particleTypeName_];
             });
 
-    detail::ParticleSequencer particleSequencer;
+    ParticleSequencer particleSequencer;
     particleSequencer.build(molecules_);
     topology_.particleSequencer_ = std::move(particleSequencer);
 
@@ -322,9 +328,9 @@ CombinationRule Topology::getCombinationRule() const
     return combinationRule_;
 }
 
-gmx::ListOfLists<int> Topology::getGmxExclusions() const
+ExclusionLists<int> Topology::exclusionLists() const
 {
-    return exclusions_;
+    return exclusionLists_;
 }
 
 } // namespace nblib