From e49cba3a5b4dbb296db7f9f21227c7b1b51e3300 Mon Sep 17 00:00:00 2001
From: Gareth Tribello <gareth.tribello@gmail.com>
Date: Thu, 12 Dec 2013 07:32:19 +0000
Subject: [PATCH] Fixed a bug in multicolvar that appears when base cvs use
 many atoms

---
 src/multicolvar/MultiColvar.cpp     | 10 +++++++---
 src/multicolvar/MultiColvarBase.cpp | 14 ++++++++------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/multicolvar/MultiColvar.cpp b/src/multicolvar/MultiColvar.cpp
index 72af3386b..7449a90b0 100644
--- a/src/multicolvar/MultiColvar.cpp
+++ b/src/multicolvar/MultiColvar.cpp
@@ -98,9 +98,13 @@ void MultiColvar::readAtomsLikeKeyword( const std::string & key, int& natoms ){
   if( all_atoms.fullSize()>0 ){
      current_atoms.resize( natoms ); nblock=ablocks[0].size();
      for(unsigned i=0;i<nblock;++i){
-         unsigned cvcode=0, tmpc=1;
-         for(unsigned j=0;j<natoms;++j){ cvcode += i*tmpc; tmpc *= nblock; }
-         addTaskToList( cvcode );  
+         if( natoms<4 ){
+            unsigned cvcode=0, tmpc=1;
+            for(unsigned j=0;j<natoms;++j){ cvcode += i*tmpc; tmpc *= nblock; }
+            addTaskToList( cvcode );  
+         } else {
+            addTaskToList( i );
+         }
      }
   }
 }
diff --git a/src/multicolvar/MultiColvarBase.cpp b/src/multicolvar/MultiColvarBase.cpp
index 9f2d6c216..d609ed732 100644
--- a/src/multicolvar/MultiColvarBase.cpp
+++ b/src/multicolvar/MultiColvarBase.cpp
@@ -81,11 +81,10 @@ void MultiColvarBase::copyActiveAtomsToFunction( MultiColvarBase* myfunction, co
 
 void MultiColvarBase::setupMultiColvarBase(){
   // Setup decoder array
-  if( !usespecies ){
+  if( !usespecies && ablocks.size()<4 ){
      decoder.resize( ablocks.size() ); unsigned code=1;
      for(unsigned i=0;i<ablocks.size();++i){ decoder[ablocks.size()-1-i]=code; code *= nblock; } 
-  } else if( ablocks.size()>0 ) {
-     plumed_assert( ablocks.size()==1 );
+  } else if( ablocks.size()==1 ) {
      // Setup coordination sphere
      csphere_atoms.resize( getFullNumberOfTasks() ); unsigned nflags=0;
      for(unsigned i=0;i<getFullNumberOfTasks();++i){
@@ -97,7 +96,7 @@ void MultiColvarBase::setupMultiColvarBase(){
         csphere_atoms[i].activateAll();
      } 
      csphere_flags.resize( nflags, 0 );
-  }
+  } 
   // Do an initial task list update
   finishTaskListUpdate();
   // Setup underlying ActionWithVessel
@@ -158,7 +157,7 @@ bool MultiColvarBase::setupCurrentAtomList( const unsigned& taskCode ){
         }
      }
      if( natomsper==1 ) return isDensity();
-  } else {
+  } else if( current_atoms.size()<4 ){
      natomsper=current_atoms.size();
      unsigned scode = taskCode;
      for(unsigned i=0;i<ablocks.size();++i){
@@ -166,7 +165,10 @@ bool MultiColvarBase::setupCurrentAtomList( const unsigned& taskCode ){
         current_atoms[i]=getBaseQuantityIndex( ablocks[i][ind] );
         scode -= ind*decoder[i]; 
      }
-  }  
+  } else {
+     natomsper=current_atoms.size(); 
+     for(unsigned i=0;i<ablocks.size();++i) current_atoms[i]=getBaseQuantityIndex( ablocks[i][taskCode] );
+  } 
   return true;
 }
 
-- 
GitLab