From 888f4f7c5a8e59c8a14cdfe5d1896e3100f84783 Mon Sep 17 00:00:00 2001
From: Giovanni Bussi <giovanni.bussi@gmail.com>
Date: Mon, 28 May 2018 17:06:54 +0200
Subject: [PATCH] Fixed problem with mapping/virtual atoms

backport of 4a96057e4fef8ca9c02cfcfa7a58707dce008f9b
---
 src/mapping/Mapping.cpp | 26 ++++----------------------
 src/mapping/Mapping.h   |  2 --
 2 files changed, 4 insertions(+), 24 deletions(-)

diff --git a/src/mapping/Mapping.cpp b/src/mapping/Mapping.cpp
index df771be10..0e83e3407 100644
--- a/src/mapping/Mapping.cpp
+++ b/src/mapping/Mapping.cpp
@@ -103,8 +103,10 @@ Mapping::Mapping(const ActionOptions&ao):
   // Get the arguments and atoms that are required
   std::vector<AtomNumber> atoms; std::vector<std::string> args;
   mymap->getAtomAndArgumentRequirements( atoms, args );
-  requestAtoms( atoms ); std::vector<Value*> req_args;
-  interpretArgumentList( args, req_args ); requestArguments( req_args );
+  std::vector<Value*> req_args; interpretArgumentList( args, req_args );
+  if( req_args.size()>0 && atoms.size()>0 ) error("cannot mix atoms and arguments");
+  if( req_args.size()>0 ) requestArguments( req_args );
+  if( atoms.size()>0 ) requestAtoms( atoms );
   // Duplicate all frames (duplicates are used by sketch-map)
   mymap->duplicateFrameList();
   // fframes.resize( 2*nfram, 0.0 ); dfframes.resize( 2*nfram, 0.0 );
@@ -128,26 +130,6 @@ Mapping::~Mapping() {
   delete mymap;
 }
 
-void Mapping::prepare() {
-  if( mymap->mappingNeedsSetup() ) {
-    // Get the arguments and atoms that are required
-    std::vector<AtomNumber> atoms; std::vector<std::string> args;
-    mymap->getAtomAndArgumentRequirements( atoms, args );
-    requestAtoms( atoms ); std::vector<Value*> req_args;
-    interpretArgumentList( args, req_args ); requestArguments( req_args );
-    // Duplicate all frames (duplicates are used by sketch-map)
-    mymap->duplicateFrameList();
-    // Get the number of frames in the path
-    // unsigned nfram=getNumberOfReferencePoints();
-    // fframes.resize( 2*nfram, 0.0 ); dfframes.resize( 2*nfram, 0.0 );
-    plumed_assert( !mymap->mappingNeedsSetup() );
-    // Resize all derivative arrays
-    // mymap->setNumberOfAtomsAndArguments( atoms.size(), args.size() );
-    // Resize forces array
-    forcesToApply.resize( 3*getNumberOfAtoms() + 9 + getNumberOfArguments() );
-  }
-}
-
 unsigned Mapping::getPropertyIndex( const std::string& name ) const {
   return mymap->getPropertyIndex( name );
 }
diff --git a/src/mapping/Mapping.h b/src/mapping/Mapping.h
index 83b7eec99..02670d7a5 100644
--- a/src/mapping/Mapping.h
+++ b/src/mapping/Mapping.h
@@ -90,8 +90,6 @@ public:
   std::string getArgumentName( unsigned& iarg );
 /// Get the value of the ith property for the current frame
   double getPropertyValue( const unsigned& current, const unsigned& iprop ) const ;
-/// Stuff to do before we do the calculation
-  void prepare();
 /// Apply the forces
   void apply();
 };
-- 
GitLab