From 9a2ec42910fcbe66a8b20b3609e9e52c671fa3f0 Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Mon, 18 Jul 2011 19:30:13 +0200 Subject: [PATCH] Small cleanup in WholeMolecules * Eliminated a possible tricky method to modify atom by relative index * Eliminated duplicates in requested atom list I also added a operators to AtomNumber, so it can be sorted with STL algorithms --- src/AtomNumber.h | 12 ++++++++++++ src/GenericWholeMolecules.cpp | 7 ++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/AtomNumber.h b/src/AtomNumber.h index 65e17bc7d..5b55e4fdd 100644 --- a/src/AtomNumber.h +++ b/src/AtomNumber.h @@ -20,6 +20,8 @@ public: void setIndex(unsigned); static AtomNumber serial(unsigned); static AtomNumber index(unsigned); + friend bool operator<(const AtomNumber&,const AtomNumber&); + friend bool operator==(const AtomNumber&,const AtomNumber&); }; inline @@ -62,6 +64,16 @@ AtomNumber AtomNumber::index(unsigned i){ return a; } +inline +bool operator<(const AtomNumber&a,const AtomNumber&b){ + return a.index_<b.index_; +} + +inline +bool operator==(const AtomNumber&a,const AtomNumber&b){ + return a.index_==b.index_; +} + } diff --git a/src/GenericWholeMolecules.cpp b/src/GenericWholeMolecules.cpp index bc35b9240..fead5982b 100644 --- a/src/GenericWholeMolecules.cpp +++ b/src/GenericWholeMolecules.cpp @@ -3,6 +3,7 @@ #include "ActionRegister.h" #include "Vector.h" #include "AtomNumber.h" +#include "Tools.h" #include <vector> #include <string> @@ -56,11 +57,6 @@ Vector & GenericWholeMolecules::modifyPosition(AtomNumber i){ return plumed.getAtoms().positions[i.index()]; } -inline -Vector & GenericWholeMolecules::modifyPosition(unsigned i){ - return plumed.getAtoms().positions[getAbsoluteIndex(i).index()]; -} - GenericWholeMolecules::GenericWholeMolecules(const ActionOptions&ao): Action(ao), ActionPilot(ao), @@ -77,6 +73,7 @@ ActionAtomistic(ao) merge.insert(merge.end(),group.begin(),group.end()); } checkRead(); + Tools::removeDuplicates(merge); requestAtoms(merge); } -- GitLab