diff --git a/Makefile b/Makefile
index 9070e68666fd8ac46b373e0fc5d327aaa2926b8d..13b9f23f5b0e0605abd947b6e339cd6851cfc717 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
 
 
 SRCDIRS = src extensions test
-SUBDIRS = $(SRCDIRS) user-doc developer-doc imd regtest
+SUBDIRS = $(SRCDIRS) user-doc developer-doc regtest
 
 SUBDIRSCLEAN=$(addsuffix .clean,$(SUBDIRS))
 
diff --git a/configure.sh b/configure.sh
index 7b9e3f2ab0206c7b74d87811990c62b9f86db317..7868a39dd38af3cc86548d61c4d46b10bde80497 100755
--- a/configure.sh
+++ b/configure.sh
@@ -35,11 +35,11 @@ case "$conf" in
   SOEXT=so
 esac
 
-echo 'export PATH="$PATH:'"$PWD"'/src/"' >> sourceme.sh
+echo 'export PATH="$PATH:'"$PWD"'/src/lib/"' >> sourceme.sh
 # this is just for mac:
-echo 'export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:'"$PWD"'/src/"' >> sourceme.sh
+echo 'export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:'"$PWD"'/src/lib/"' >> sourceme.sh
 
 cat << EOF >> sourceme.sh
-export PLUMED_KERNEL="$PWD/src/libplumedKernel.$SOEXT"
+export PLUMED_KERNEL="$PWD/src/lib/libplumedKernel.$SOEXT"
 EOF
 
diff --git a/developer-doc/.gitignore b/developer-doc/.gitignore
index 9a6b1538130646a7d61100d7beb59b4c3a0d1bbc..ad4cccefa7c615d8a11648649b50d960e6f0291a 100644
--- a/developer-doc/.gitignore
+++ b/developer-doc/.gitignore
@@ -4,4 +4,5 @@
 /automatic
 /*PP.txt
 /links-to-user-manual.txt
+/Doxyfile
 
diff --git a/developer-doc/Doxyfile b/developer-doc/Doxyfile.in
similarity index 99%
rename from developer-doc/Doxyfile
rename to developer-doc/Doxyfile.in
index d804b6833235ca793688d341fa7ccb38907e742e..92ade93ed76c3015da7d70c95bbc04ef8fa58a98 100644
--- a/developer-doc/Doxyfile
+++ b/developer-doc/Doxyfile.in
@@ -464,7 +464,7 @@ INPUT                  = ./Intro.txt \
                          ./plmdIntro.txt \
                          ./usingDoxygen.txt \
                          ./parsing.txt \
-                         ../src \
+                         @SRCDIR@ \
                          ./links-to-user-manual.txt \
                          ./AddingAColvar.txt \
                          ./AddingAFunction.txt \
diff --git a/developer-doc/Makefile b/developer-doc/Makefile
index 711ccafca727a30c547f7c38e71b9569c4b8d413..e3cae84a3577d0d1a281ceac25fd7715ff9d65de 100644
--- a/developer-doc/Makefile
+++ b/developer-doc/Makefile
@@ -6,4 +6,4 @@ all:
 	doxygen
 
 clean:
-	rm -fr automatic html latex *~ links-to-user-manual.txt
+	rm -fr automatic html latex *~ links-to-user-manual.txt Doxyfile
diff --git a/developer-doc/extract b/developer-doc/extract
index 8cf320aa125d7e5ad03421a4b23882f5d1d4ef41..3f06ceff70b0f1ee877665bf14c57d9ea8a72466 100755
--- a/developer-doc/extract
+++ b/developer-doc/extract
@@ -1,6 +1,8 @@
 #!/bin/bash
 
-cat ../src/*cpp | grep PLUMED_REGISTER_ACTION |
+sed s:@SRCDIR@:"$(echo ../src/*)": Doxyfile.in > Doxyfile
+
+cat ../src/*/*cpp | grep PLUMED_REGISTER_ACTION |
   sed '
    s/PLUMED_REGISTER_ACTION(/ /
    s/,"/ /
diff --git a/extensions/DoNothing.cpp b/extensions/DoNothing.cpp
index 23ce08409e9542df1b63a87c359556a2acaab770..7cd78ff4fba8ca81d8f525eb7b8396d53befac78 100644
--- a/extensions/DoNothing.cpp
+++ b/extensions/DoNothing.cpp
@@ -1,5 +1,5 @@
-#include "../src/ActionRegister.h"
-#include "../src/ActionSetup.h"
+#include "../src/basic/ActionRegister.h"
+#include "../src/basic/ActionSetup.h"
 
 using namespace std;
 
diff --git a/include/Plumed.h b/include/Plumed.h
index ac9a3c49a3cef796bb952f718380456585fc625c..4c2cd0d93d9cd1a3290556a2f8f29c0dacae48dd 100644
--- a/include/Plumed.h
+++ b/include/Plumed.h
@@ -1 +1 @@
-#include "../src/Plumed.h"
+#include "../src/wrapper/Plumed.h"
diff --git a/patches/patch.sh b/patches/patch.sh
index b0313d424b8d020bd0558b423dffe58a3d8f5337..aac150a7a5bec964fd57a56951e8915671ff27af 100755
--- a/patches/patch.sh
+++ b/patches/patch.sh
@@ -197,9 +197,9 @@ case "$action" in
       echo "ERROR: you have likely already patched. Revert first (-r)"
       exit
     fi
-    if [ ! -f "$PLUMED_ROOT/src/Plumed.inc" ]
+    if [ ! -f "$PLUMED_ROOT/src/lib/Plumed.inc" ]
     then
-      echo "ERROR: cannot find $PLUMED_ROOT/src/Plumed.inc file"
+      echo "ERROR: cannot find $PLUMED_ROOT/src/lib/Plumed.inc file"
       echo "Compile plumed before patching"
       exit
     fi
@@ -208,8 +208,8 @@ case "$action" in
       plumed_before_patch
     fi
     echo "Linking Plumed.h and Plumed.inc ($mode mode)"
-    ln -s "$PLUMED_ROOT/src/Plumed.h"
-    ln -s "$PLUMED_ROOT/src/Plumed.inc.$mode" Plumed.inc
+    ln -s "$PLUMED_ROOT/src/lib/Plumed.h"
+    ln -s "$PLUMED_ROOT/src/lib/Plumed.inc.$mode" Plumed.inc
     bash "$diff"
     if type -t plumed_after_patch 1>/dev/null ; then
       echo "Executing plumed_after_patch function"
diff --git a/scripts/mklib.sh b/scripts/mklib.sh
index 1d80972ae246196182715e5058f5ce10e50af075..843cd16eb56b5a88efa239d401c0bd4deb456302 100755
--- a/scripts/mklib.sh
+++ b/scripts/mklib.sh
@@ -1,6 +1,6 @@
 #! /bin/bash
 
-source $PLUMED_ROOT/src/compile_options.sh
+source $PLUMED_ROOT/src/config/compile_options.sh
 
 if [ "$1" = --description ] ; then
   echo "compile a .cpp file into a shared library"
diff --git a/scripts/newcv.sh b/scripts/newcv.sh
index d279703aaeecf8cbb21a5dfafed889be9d186068..12da44ae55db25bbc783e8b38f9c9e677306f88c 100755
--- a/scripts/newcv.sh
+++ b/scripts/newcv.sh
@@ -17,5 +17,5 @@ directive=$1
 cvname=$2
 
 sed "s/TEMPLATE/$directive/g
-     s/Template/$cvname/g" $PLUMED_ROOT/src/ColvarTemplate.cpp > Colvar${cvname}.cpp
+     s/Template/$cvname/g" $PLUMED_ROOT/src/basic/ColvarTemplate.cpp > Colvar${cvname}.cpp
 
diff --git a/src/.gitignore b/src/.gitignore
index 4775d2b48fb3b4687db24042ce5d69444e6792e3..89df105e5ddd61e0c354bc0cc022644352609bce 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,8 +1,3 @@
-Plumed.inc*
-PlumedConfig.h
-/compile_options.sh
-/plumed-static
-/plumed-shared
-/plumed-runtime
-/plumed
 *.xxd
+/*.on
+/*.off
diff --git a/src/Makefile b/src/Makefile
index 72eabe17e2250a2a6630602d9006a279b46b883b..b14fa766f2f1954e954b77db171ca8f132a7a988 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,175 +1,24 @@
 
-# include the machine dependent configuration
--include ../Makefile.conf
-
-# if machine dependent configuration has been found:
-ifdef GCCDEP
-
-# source for plumed wrapper
-SRC_WRAPPER=PlumedStatic.cpp
-
-# source for plumed dynamic wrapper
-SRC_DYNAMIC_WRAPPER=Plumed.c
-
-# source for plumed main program
-# this should not be linked into libraries
-SRC_MAIN=main.cpp
-
-# source for plumed kernel
-# everything else
-SRC_KERNEL=$(filter-out $(SRC_MAIN) $(SRC_WRAPPER),$(wildcard *.cpp))
-
-# all sources
-ALL_SRC=$(SRC_KERNEL) $(SRC_WRAPPER) $(SRC_DYNAMIC_WRAPPER) $(SRC_MAIN)
-
-# corresponding objects:
-OBJ_WRAPPER=PlumedStatic.o
-OBJ_DYNAMIC_WRAPPER=Plumed.o
-OBJ_MAIN=$(SRC_MAIN:.cpp=.o)
-OBJ_KERNEL=$(SRC_KERNEL:.cpp=.o)
-ALL_OBJ=$(OBJ_KERNEL) $(OBJ_WRAPPER) $(OBJ_DYNAMIC_WRAPPER) $(OBJ_MAIN)
-
-# dependency files for all c++ sources
-CPP_SRC=$(wildcard *.cpp)
-ALL_DEP=$(addprefix deps/,$(CPP_SRC:.cpp=.d))
-
-# plumed kernel
-PLUMED_KERNEL=libplumedKernel.$(SOEXT)
-
-# plumed library (kernel + wrapper)
-PLUMED_SHARED_OBJ=libplumed.$(SOEXT)
-
-# plumed main exec
-PLUMED_MAIN_STATIC=plumed
-PLUMED_MAIN_SHARED=plumed-shared
-PLUMED_MAIN_RUNTIME=plumed-runtime
-
-# default target
-.PHONY: all
-all: $(PLUMED_KERNEL) $(PLUMED_SHARED_OBJ) $(OBJ_WRAPPER) \
-     $(PLUMED_MAIN_STATIC) $(PLUMED_MAIN_SHARED) $(PLUMED_MAIN_RUNTIME) \
-     Plumed.inc Plumed.inc.runtime Plumed.inc.shared Plumed.inc.static \
-     compile_options.sh
-
-$(PLUMED_KERNEL):$(OBJ_KERNEL)
-	$(LDSO) -o $@ $^ $(DYNAMIC_LIBS)
-
-$(PLUMED_SHARED_OBJ): $(OBJ_KERNEL) $(OBJ_WRAPPER)
-	$(LDSO) -o $@ $^ $(DYNAMIC_LIBS)
-
-$(PLUMED_MAIN_STATIC): $(OBJ_MAIN) $(OBJ_KERNEL) $(OBJ_WRAPPER)
-	$(LD) $(LDFLAGS) $^ -o $@ $(LIBS) $(DYNAMIC_LIBS)
-	
-$(PLUMED_MAIN_SHARED): $(OBJ_MAIN) $(PLUMED_SHARED_OBJ)
-	$(LD) $(LDFLAGS) $(OBJ_MAIN) $(realpath $(PLUMED_SHARED_OBJ)) -o $@ $(LIBS)
-
-$(PLUMED_MAIN_RUNTIME): $(OBJ_MAIN) $(OBJ_DYNAMIC_WRAPPER)
-	$(LD) $(LDFLAGS) $^ -o $@ $(LIBS)
-
-Plumed.inc: $(OBJ_KERNEL) $(OBJ_WRAPPER) $(PLUMED_SHARED_OBJ) $(OBJ_DYNAMIC_WRAPPER)
-	@echo Building Plumed.inc
-	@echo "PLUMED_INCLUDE="-I$(realpath ../include) > $@
-	@echo "PLUMED_RUNTIME_LOAD=" $(realpath $(OBJ_DYNAMIC_WRAPPER)) $(LIBS) $(LDFLAGS) >> $@
-	@echo "PLUMED_STATIC_LOAD=" $(realpath $(OBJ_KERNEL)) $(realpath $(OBJ_WRAPPER)) $(LIBS) $(DYNAMIC_LIBS) $(LDFLAGS) >> $@
-	@echo "PLUMED_SHARED_LOAD=" $(realpath $(PLUMED_SHARED_OBJ)) $(LIBS) $(LDFLAGS) >> $@
-	@echo "PLUMED_RUNTIME_DEPENDENCIES="   >> $@
-	@echo "PLUMED_STATIC_DEPENDENCIES=" $(realpath $(OBJ_KERNEL)) $(realpath $(OBJ_WRAPPER))  >> $@
-	@echo "PLUMED_SHARED_DEPENDENCIES=" $(realpath $(PLUMED_SHARED_OBJ))  >> $@
-
-Plumed.inc.runtime: Plumed.inc
-	@echo Building Plumed.inc, runtime-linking version
-	@echo "# PLUMED: runtime installation" > $@
-	@cat $< >> $@
-	@echo PLUMED_LOAD= '$$(PLUMED_RUNTIME_LOAD)' >> $@
-	@echo PLUMED_DEPENDENCIES= '$$(PLUMED_RUNTIME_DEPENDENCIES)' >> $@
-
-Plumed.inc.static: Plumed.inc
-	@echo Building Plumed.inc, static version
-	@echo "# PLUMED: static installation" > $@
-	@cat $< >> $@
-	@echo PLUMED_LOAD= '$$(PLUMED_STATIC_LOAD)' >> $@
-	@echo PLUMED_DEPENDENCIES= '$$(PLUMED_STATIC_DEPENDENCIES)' >> $@
-
-Plumed.inc.shared: Plumed.inc
-	@echo Building Plumed.inc, shared version
-	@echo "# PLUMED: shared installation" > $@
-	@cat $< >> $@
-	@echo PLUMED_LOAD= '$$(PLUMED_SHARED_LOAD)' >> $@
-	@echo PLUMED_DEPENDENCIES= '$$(PLUMED_SHARED_DEPENDENCIES)' >> $@
-
-$(ALL_DEP): PlumedConfig.h Makefile.conf.xxd
-
-# this compiler is used for dependencies generation
-# if unset, use normal CXX
-ifndef CXXDEP
-CXXDEP=$(CXX)
-endif
-
-# rule for c++
-%.o: %.cpp
-	$(CXXDEP) -c -MM -MF$*.d $(CPPFLAGS) $(CXXFLAGS) $*.cpp
-	@cp -f $*.d $*.d.tmp
-	@-test -d deps || mkdir deps
-	@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
-	 sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
-	@mv $*.d deps/$*.d
-	@rm -f $*.d.tmp
-ifndef XLF
-	$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $*.cpp -o $*.o
-endif
-
-# rule for c
-%.o: %.c
-	$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c -o $*.o
-
-# there is a single C file here, and this is its dependency:
-Plumed.o: Plumed.c Plumed.h
-
-# file to import compilation options inside c++
-PlumedConfig.h: PlumedConfig.h.in ../Makefile.conf
-	@echo Building PlumedConfig.h, an includable c++ header with some compilation options
-	@sed "s/@SOEXT@/$(SOEXT)/g" $< | \
-         sed "s|@PLUMED_ROOT@|$(PWD:src=)|g" > $@
-
-# file to import compilation options inside a bash script
-compile_options.sh:
-	@echo Building compile_options.sh, a sourceable bash script with some compilation options
-	@echo "compile='"$(CXX) -c -I$(realpath .) $(CPPFLAGS) $(CXXFLAGS) -o"'" > $@
-	@echo "link='"$(LDSO) -o"'" >> $@
-	@echo "soext='"$(SOEXT)"'" >> $@
-
-Makefile.conf.xxd: ../Makefile.conf
-	cat ../Makefile.conf | xxd -i > Makefile.conf.xxd
-
-# Individual dependencies
-
--include $(ALL_DEP)
-
-# if machine dependent configuration has not been found:
-else
-
-.PHONY: error
-error:
-	@echo No configuration available
-	@echo First run ./configure.sh in the root directory
-endif
-
-# this target is available anyway
-
-.PHONY: clean
-clean:
-	rm -f *.o
-	rm -f *.d
-	rm -fr deps
-	rm -f *.cdep
-	rm -f *.cppdep
-	rm -f PlumedConfig.h
-	rm -f Plumed.inc*
-	rm -f *~
-	rm -f *.tmp
-	rm -f *.so
-	rm -f *.dylib
-	rm -f *.xxd
-	rm -f compile_options.sh
-	rm -f $(PLUMED_MAIN_STATIC) $(PLUMED_MAIN_SHARED) $(PLUMED_MAIN_RUNTIME)
+.PHONY: all clean
+
+# by default we compile the lib directory, which in turn requests all the needeed modules
+all: 
+	$(MAKE) -C lib
+     
+# list of all the contained directories which can be cleaned
+SUBDIRS =$(subst /Makefile,,$(wildcard */Makefile))
+SUBDIRSCLEAN=$(addsuffix .clean,$(SUBDIRS))
+.PHONY: $(SUBDIRS)
+
+# this is cleaning all subdirectories
+clean: $(SUBDIRSCLEAN)
+
+$(SUBDIRSCLEAN): %.clean:
+	$(MAKE) -C $* clean
+
+.PHONY: help
+help:
+	@echo "Available targets are"
+	@echo "  all: compile everything (default)"
+	@echo "  clean: clean everything"
 
diff --git a/src/README b/src/README
new file mode 100644
index 0000000000000000000000000000000000000000..2a6d046277a0ce91221da1045dd0bbd5ed4bcc13
--- /dev/null
+++ b/src/README
@@ -0,0 +1,18 @@
+This directory contains many subdirectories
+
+lib/ after compilation contains all plumed files which should be in the path
+maketools/ contains some tool necessary for compilation
+
+Then these directories are built and linked using special rules:
+config/  contains some files generated based on system configuration
+main/    contains the main() program for plumed executable
+wrapper/ contains the wrappers for MD codes
+
+All the other directories are "modules". Modules are of three type:
+* always compiled (necessary for plumed to properly link)
+* default on, can be switched off touching a file modulename.off in the src/ directory
+* default off, can be switched on touching a file modulename.on in the src/ directory
+Notice that these .on and .off files are not to be distributed/included in git,
+as they reflect local wishes!
+
+The type of the module can be set by adding a file module.type (see e.g. basic/module.type)
diff --git a/src/basic/.gitignore b/src/basic/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..4888552338441b5d99a97ec7a2cb2ce448e9e4e6
--- /dev/null
+++ b/src/basic/.gitignore
@@ -0,0 +1,9 @@
+/*
+# in this directory, only accept source, Makefile and README
+!/.gitignore
+!/*.c
+!/*.cpp
+!/*.h
+!/Makefile
+!/README
+!/module.type
diff --git a/src/Action.cpp b/src/basic/Action.cpp
similarity index 99%
rename from src/Action.cpp
rename to src/basic/Action.cpp
index af4aeb54c52386f2e788b93615ed9d6727dd061a..d31212dd8a75165451069150c9a2a05c944e89a9 100644
--- a/src/Action.cpp
+++ b/src/basic/Action.cpp
@@ -22,8 +22,8 @@
 #include "Action.h"
 #include "ActionWithValue.h"
 #include "PlumedMain.h"
-#include "Log.h"
-#include "PlumedException.h"
+#include "tools/Log.h"
+#include "tools/PlumedException.h"
 #include "Atoms.h"
 #include "ActionSet.h"
 #include <iostream>
diff --git a/src/Action.h b/src/basic/Action.h
similarity index 99%
rename from src/Action.h
rename to src/basic/Action.h
index 5717c0f1ba0fd85adc1015dce2f3f97597acadc6..fdb0ffd9dc9b64cca4be1e1189c886c1b31ca29f 100644
--- a/src/Action.h
+++ b/src/basic/Action.h
@@ -24,10 +24,10 @@
 #include <vector>
 #include <string>
 #include <set>
-#include "Keywords.h"
+#include "tools/Keywords.h"
 #include "Value.h"
-#include "Tools.h"
-#include "Log.h"
+#include "tools/Tools.h"
+#include "tools/Log.h"
 
 namespace PLMD{
 
diff --git a/src/ActionAtomistic.cpp b/src/basic/ActionAtomistic.cpp
similarity index 98%
rename from src/ActionAtomistic.cpp
rename to src/basic/ActionAtomistic.cpp
index ae8a11a46f4257d455f89822b14419a58c610ca4..aa54b740dcbfcb8ef510e98febc45ca291b5cc00 100644
--- a/src/ActionAtomistic.cpp
+++ b/src/basic/ActionAtomistic.cpp
@@ -27,10 +27,10 @@
 #include "ActionWithValue.h"
 #include "Colvar.h"
 #include "ActionWithVirtualAtom.h"
-#include "PlumedException.h"
+#include "tools/PlumedException.h"
 #include "Atoms.h"
-#include "Pbc.h"
-#include "PDB.h"
+#include "tools/Pbc.h"
+#include "tools/PDB.h"
 
 using namespace std;
 using namespace PLMD;
diff --git a/src/ActionAtomistic.h b/src/basic/ActionAtomistic.h
similarity index 99%
rename from src/ActionAtomistic.h
rename to src/basic/ActionAtomistic.h
index a4ceeef2a14c50e62a2380bf7bb27586d1324d33..f05cfe2d74695210a9fe2d926529b9f77569d6f7 100644
--- a/src/ActionAtomistic.h
+++ b/src/basic/ActionAtomistic.h
@@ -23,7 +23,7 @@
 #define __PLUMED_ActionAtomistic_h
 
 #include "Action.h"
-#include "Tensor.h"
+#include "tools/Tensor.h"
 #include <vector>
 #include <set>
 
diff --git a/src/ActionPilot.cpp b/src/basic/ActionPilot.cpp
similarity index 100%
rename from src/ActionPilot.cpp
rename to src/basic/ActionPilot.cpp
diff --git a/src/ActionPilot.h b/src/basic/ActionPilot.h
similarity index 100%
rename from src/ActionPilot.h
rename to src/basic/ActionPilot.h
diff --git a/src/ActionRegister.cpp b/src/basic/ActionRegister.cpp
similarity index 99%
rename from src/ActionRegister.cpp
rename to src/basic/ActionRegister.cpp
index 3f0aff40bfbc861c5e34db8759f3fcac1e690dd8..7c5532d4a7fa9fecbb4f23d52e403ee39c9bd200 100644
--- a/src/ActionRegister.cpp
+++ b/src/basic/ActionRegister.cpp
@@ -20,7 +20,7 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "ActionRegister.h"
-#include "Tools.h"
+#include "tools/Tools.h"
 #include "Action.h"
 #include <algorithm>
 #include <iostream>
diff --git a/src/ActionRegister.h b/src/basic/ActionRegister.h
similarity index 99%
rename from src/ActionRegister.h
rename to src/basic/ActionRegister.h
index 7f09635a7a2bfe27c4dec959dce8a16a337de012..7fab120c8a2a85f378bf88e18486083c6e421e8c 100644
--- a/src/ActionRegister.h
+++ b/src/basic/ActionRegister.h
@@ -26,7 +26,7 @@
 #include <map>
 #include <set>
 #include <iosfwd>
-#include "Keywords.h"
+#include "tools/Keywords.h"
 
 namespace PLMD{
 
diff --git a/src/ActionSet.cpp b/src/basic/ActionSet.cpp
similarity index 100%
rename from src/ActionSet.cpp
rename to src/basic/ActionSet.cpp
diff --git a/src/ActionSet.h b/src/basic/ActionSet.h
similarity index 100%
rename from src/ActionSet.h
rename to src/basic/ActionSet.h
diff --git a/src/ActionSetup.cpp b/src/basic/ActionSetup.cpp
similarity index 97%
rename from src/ActionSetup.cpp
rename to src/basic/ActionSetup.cpp
index 0e950f0593fdf42f69a5a1a90fee85e4b22a2865..52118174be8ff30a654c10c330079e54e5512407 100644
--- a/src/ActionSetup.cpp
+++ b/src/basic/ActionSetup.cpp
@@ -22,7 +22,7 @@
 #include "ActionSetup.h"
 #include "PlumedMain.h"
 #include "ActionSet.h"
-#include "PlumedException.h"
+#include "tools/PlumedException.h"
 
 using namespace PLMD;
 
diff --git a/src/ActionSetup.h b/src/basic/ActionSetup.h
similarity index 100%
rename from src/ActionSetup.h
rename to src/basic/ActionSetup.h
diff --git a/src/ActionVolume.cpp b/src/basic/ActionVolume.cpp
similarity index 100%
rename from src/ActionVolume.cpp
rename to src/basic/ActionVolume.cpp
diff --git a/src/ActionVolume.h b/src/basic/ActionVolume.h
similarity index 98%
rename from src/ActionVolume.h
rename to src/basic/ActionVolume.h
index 065b9f44297c59ccf4a0f1c9e9ead84acd6e5f77..eca6352472d37968a4a3102d9e549b3e082a4d5d 100644
--- a/src/ActionVolume.h
+++ b/src/basic/ActionVolume.h
@@ -23,7 +23,7 @@
 #define __PLUMED_ActionVolume_h
 
 #include "ActionAtomistic.h"
-#include "HistogramBead.h"
+#include "tools/HistogramBead.h"
 
 namespace PLMD {
 
diff --git a/src/ActionWithArguments.cpp b/src/basic/ActionWithArguments.cpp
similarity index 100%
rename from src/ActionWithArguments.cpp
rename to src/basic/ActionWithArguments.cpp
diff --git a/src/ActionWithArguments.h b/src/basic/ActionWithArguments.h
similarity index 100%
rename from src/ActionWithArguments.h
rename to src/basic/ActionWithArguments.h
diff --git a/src/ActionWithValue.cpp b/src/basic/ActionWithValue.cpp
similarity index 99%
rename from src/ActionWithValue.cpp
rename to src/basic/ActionWithValue.cpp
index 54ab93388241c883e683fe764442092378ff28d7..92f4b28a3eed8aef315f64fb9fbaec84fda98fca 100644
--- a/src/ActionWithValue.cpp
+++ b/src/basic/ActionWithValue.cpp
@@ -20,7 +20,7 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "ActionWithValue.h"
-#include "PlumedException.h"
+#include "tools/PlumedException.h"
 
 using namespace std;
 using namespace PLMD;
diff --git a/src/ActionWithValue.h b/src/basic/ActionWithValue.h
similarity index 99%
rename from src/ActionWithValue.h
rename to src/basic/ActionWithValue.h
index 98cb04e701d3249c5fa46e8b1a4c6db1269419a3..95e0fffa64f0a4761ac9fc61109a2fc7085cb928 100644
--- a/src/ActionWithValue.h
+++ b/src/basic/ActionWithValue.h
@@ -24,7 +24,7 @@
 
 #include "Action.h"
 #include "Value.h"
-#include "PlumedException.h"
+#include "tools/PlumedException.h"
 #include <vector>
 
 namespace PLMD{
diff --git a/src/ActionWithVirtualAtom.cpp b/src/basic/ActionWithVirtualAtom.cpp
similarity index 100%
rename from src/ActionWithVirtualAtom.cpp
rename to src/basic/ActionWithVirtualAtom.cpp
diff --git a/src/ActionWithVirtualAtom.h b/src/basic/ActionWithVirtualAtom.h
similarity index 97%
rename from src/ActionWithVirtualAtom.h
rename to src/basic/ActionWithVirtualAtom.h
index c3913867fd72d2241b002f5ba485336d648209f6..5e008467df4d9d71368af7ff8b6482fc6c525d66 100644
--- a/src/ActionWithVirtualAtom.h
+++ b/src/basic/ActionWithVirtualAtom.h
@@ -23,9 +23,9 @@
 #define __PLUMED_ActionWithVirtualAtom_h
 
 #include "ActionAtomistic.h"
-#include "AtomNumber.h"
-#include "Vector.h"
-#include "Tensor.h"
+#include "tools/AtomNumber.h"
+#include "tools/Vector.h"
+#include "tools/Tensor.h"
 #include "Atoms.h"
 
 namespace PLMD{
diff --git a/src/Angle.cpp b/src/basic/Angle.cpp
similarity index 98%
rename from src/Angle.cpp
rename to src/basic/Angle.cpp
index 64900ec43d1b964c48f9301b06cf2696b684f49d..91e5191d710f740232188ed5b1d7a23c1bc52e62 100644
--- a/src/Angle.cpp
+++ b/src/basic/Angle.cpp
@@ -20,7 +20,7 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "Angle.h"
-#include "Tools.h"
+#include "tools/Tools.h"
 #include <cmath>
 
 using namespace PLMD;
diff --git a/src/Angle.h b/src/basic/Angle.h
similarity index 98%
rename from src/Angle.h
rename to src/basic/Angle.h
index 9f0784dbdc320e7d5e0be4b1f5131289431a2156..6ef8ddd944785ddf86216c3b4696bf8473dc7866 100644
--- a/src/Angle.h
+++ b/src/basic/Angle.h
@@ -22,7 +22,7 @@
 #ifndef __PLUMED_Angle_h
 #define __PLUMED_Angle_h
 
-#include "Vector.h"
+#include "tools/Vector.h"
 
 namespace PLMD{
 
diff --git a/src/Atoms.cpp b/src/basic/Atoms.cpp
similarity index 100%
rename from src/Atoms.cpp
rename to src/basic/Atoms.cpp
diff --git a/src/Atoms.h b/src/basic/Atoms.h
similarity index 97%
rename from src/Atoms.h
rename to src/basic/Atoms.h
index 363f49903e41d27b3c1b14b213565537f3a8fd4c..b775ddc05be42ccec43f24dd73fa86948baa7008 100644
--- a/src/Atoms.h
+++ b/src/basic/Atoms.h
@@ -22,11 +22,11 @@
 #ifndef __PLUMED_Atoms_h
 #define __PLUMED_Atoms_h
 
-#include "PlumedCommunicator.h"
-#include "Tensor.h"
+#include "tools/PlumedCommunicator.h"
+#include "tools/Tensor.h"
 #include "Units.h"
-#include "PlumedException.h"
-#include "AtomNumber.h"
+#include "tools/PlumedException.h"
+#include "tools/AtomNumber.h"
 #include <vector>
 #include <set>
 #include <map>
diff --git a/src/Bias.cpp b/src/basic/Bias.cpp
similarity index 100%
rename from src/Bias.cpp
rename to src/basic/Bias.cpp
diff --git a/src/Bias.h b/src/basic/Bias.h
similarity index 100%
rename from src/Bias.h
rename to src/basic/Bias.h
diff --git a/src/BiasExternal.cpp b/src/basic/BiasExternal.cpp
similarity index 98%
rename from src/BiasExternal.cpp
rename to src/basic/BiasExternal.cpp
index dbcb79f581af697a69b601d51cd6ca5712f7041e..5f803f4cff251cd70d06b640479b45c2e85a462b 100644
--- a/src/BiasExternal.cpp
+++ b/src/basic/BiasExternal.cpp
@@ -21,8 +21,8 @@
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "Bias.h"
 #include "ActionRegister.h"
-#include "Grid.h"
-#include "PlumedException.h"
+#include "tools/Grid.h"
+#include "tools/PlumedException.h"
 
 
 using namespace std;
diff --git a/src/BiasLWalls.cpp b/src/basic/BiasLWalls.cpp
similarity index 100%
rename from src/BiasLWalls.cpp
rename to src/basic/BiasLWalls.cpp
diff --git a/src/BiasMetaD.cpp b/src/basic/BiasMetaD.cpp
similarity index 99%
rename from src/BiasMetaD.cpp
rename to src/basic/BiasMetaD.cpp
index 06c0e28d63aaf72118f414efcafaf96fa31410dd..a0c55dd2b3a3db10c82dd51ee5278bedd98ab36c 100644
--- a/src/BiasMetaD.cpp
+++ b/src/basic/BiasMetaD.cpp
@@ -21,16 +21,16 @@
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "Bias.h"
 #include "ActionRegister.h"
-#include "Grid.h"
+#include "tools/Grid.h"
 #include "PlumedMain.h"
 #include "Atoms.h"
-#include "PlumedException.h"
+#include "tools/PlumedException.h"
 #include "FlexibleBin.h"
-#include "Matrix.h"
-#include "Random.h"
+#include "tools/Matrix.h"
+#include "tools/Random.h"
 #include <string>
 #include <cstring>
-#include "PlumedFile.h"
+#include "tools/PlumedFile.h"
 #include "time.h"
 #include <iostream>
 
diff --git a/src/BiasMovingRestraint.cpp b/src/basic/BiasMovingRestraint.cpp
similarity index 100%
rename from src/BiasMovingRestraint.cpp
rename to src/basic/BiasMovingRestraint.cpp
diff --git a/src/BiasRatchet.cpp b/src/basic/BiasRatchet.cpp
similarity index 99%
rename from src/BiasRatchet.cpp
rename to src/basic/BiasRatchet.cpp
index 89109976acb575ee0e7ee84f9bfe046456b636e9..391b987d9f516521fc4db7e13c56d6bb6aade75a 100644
--- a/src/BiasRatchet.cpp
+++ b/src/basic/BiasRatchet.cpp
@@ -20,7 +20,7 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "Bias.h"
-#include "Random.h"
+#include "tools/Random.h"
 #include "ActionRegister.h"
 #include <cassert>
 #include <ctime>
diff --git a/src/BiasRestraint.cpp b/src/basic/BiasRestraint.cpp
similarity index 100%
rename from src/BiasRestraint.cpp
rename to src/basic/BiasRestraint.cpp
diff --git a/src/BiasUWalls.cpp b/src/basic/BiasUWalls.cpp
similarity index 100%
rename from src/BiasUWalls.cpp
rename to src/basic/BiasUWalls.cpp
diff --git a/src/BiasValue.cpp b/src/basic/BiasValue.cpp
similarity index 100%
rename from src/BiasValue.cpp
rename to src/basic/BiasValue.cpp
diff --git a/src/CLTool.cpp b/src/basic/CLTool.cpp
similarity index 100%
rename from src/CLTool.cpp
rename to src/basic/CLTool.cpp
diff --git a/src/CLTool.h b/src/basic/CLTool.h
similarity index 98%
rename from src/CLTool.h
rename to src/basic/CLTool.h
index d98691443de3952956343fa151a17cb7e978e74a..16ca6b166a3eed70445636625679b0a9b7d5e0a9 100644
--- a/src/CLTool.h
+++ b/src/basic/CLTool.h
@@ -26,8 +26,8 @@
 #include <vector>
 #include <string>
 #include <cstdio>
-#include "Tools.h"
-#include "Keywords.h"
+#include "tools/Tools.h"
+#include "tools/Keywords.h"
 
 namespace PLMD{
 
diff --git a/src/CLToolMain.cpp b/src/basic/CLToolMain.cpp
similarity index 97%
rename from src/CLToolMain.cpp
rename to src/basic/CLToolMain.cpp
index 7c9040022c87a643f4202ef31acfac1058d5ece2..968048fd0e30b08ffdb0e7820302b6b6a65ff38d 100644
--- a/src/CLToolMain.cpp
+++ b/src/basic/CLToolMain.cpp
@@ -19,14 +19,14 @@
    You should have received a copy of the GNU Lesser General Public License
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
-#include "PlumedConfig.h"
-#include "PlumedException.h"
-#include "PlumedCommunicator.h"
+#include "config/PlumedConfig.h"
+#include "tools/PlumedException.h"
+#include "tools/PlumedCommunicator.h"
 #include "CLTool.h"
 #include "CLToolMain.h"
 #include "CLToolRegister.h"
-#include "Tools.h"
-#include "DLLoader.h"
+#include "tools/Tools.h"
+#include "tools/DLLoader.h"
 #include <string>
 #include <cstdlib>
 #include <cstdio>
diff --git a/src/CLToolMain.h b/src/basic/CLToolMain.h
similarity index 100%
rename from src/CLToolMain.h
rename to src/basic/CLToolMain.h
diff --git a/src/CLToolRegister.cpp b/src/basic/CLToolRegister.cpp
similarity index 99%
rename from src/CLToolRegister.cpp
rename to src/basic/CLToolRegister.cpp
index b382de20d5b5d7063318035bc913fd6a8d2a7cff..7e2ca117300b3df0613b79bccf2591b6409e43d1 100644
--- a/src/CLToolRegister.cpp
+++ b/src/basic/CLToolRegister.cpp
@@ -20,7 +20,7 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "CLToolRegister.h"
-#include "Tools.h"
+#include "tools/Tools.h"
 #include "CLTool.h"
 #include <algorithm>
 #include <iostream>
diff --git a/src/CLToolRegister.h b/src/basic/CLToolRegister.h
similarity index 99%
rename from src/CLToolRegister.h
rename to src/basic/CLToolRegister.h
index 7c13314612e0313201be2d6584c29f1e31c8e3d1..739acb19e37fed0b6713d8d3bda8893d2b5943e9 100644
--- a/src/CLToolRegister.h
+++ b/src/basic/CLToolRegister.h
@@ -27,7 +27,7 @@
 #include <set>
 #include <vector>
 #include <iosfwd>
-#include "Keywords.h"
+#include "tools/Keywords.h"
 
 namespace PLMD{
 
diff --git a/src/Colvar.cpp b/src/basic/Colvar.cpp
similarity index 100%
rename from src/Colvar.cpp
rename to src/basic/Colvar.cpp
diff --git a/src/Colvar.h b/src/basic/Colvar.h
similarity index 100%
rename from src/Colvar.h
rename to src/basic/Colvar.h
diff --git a/src/ColvarAngle.cpp b/src/basic/ColvarAngle.cpp
similarity index 100%
rename from src/ColvarAngle.cpp
rename to src/basic/ColvarAngle.cpp
diff --git a/src/ColvarContactMap.cpp b/src/basic/ColvarContactMap.cpp
similarity index 98%
rename from src/ColvarContactMap.cpp
rename to src/basic/ColvarContactMap.cpp
index 9a9a0e4ce86d5288b117cd95edbc8a01f9966ba3..2c0e759c40d32ba37c975c70150b65e6f8e0d241 100644
--- a/src/ColvarContactMap.cpp
+++ b/src/basic/ColvarContactMap.cpp
@@ -20,9 +20,9 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "Colvar.h"
-#include "NeighborList.h"
+#include "tools/NeighborList.h"
 #include "ActionRegister.h"
-#include "SwitchingFunction.h"
+#include "tools/SwitchingFunction.h"
 
 #include <string>
 #include <cmath>
diff --git a/src/ColvarCoordination.cpp b/src/basic/ColvarCoordination.cpp
similarity index 98%
rename from src/ColvarCoordination.cpp
rename to src/basic/ColvarCoordination.cpp
index ebfa87d1bec38ce14babab5a53419059cc9b0c7b..6abe031b363cab676864919fae888f5657efad9d 100644
--- a/src/ColvarCoordination.cpp
+++ b/src/basic/ColvarCoordination.cpp
@@ -19,11 +19,11 @@
    You should have received a copy of the GNU Lesser General Public License
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
-#include "SwitchingFunction.h"
+#include "tools/SwitchingFunction.h"
 #include "Colvar.h"
 #include "ActionRegister.h"
-#include "NeighborList.h"
-#include "PlumedCommunicator.h"
+#include "tools/NeighborList.h"
+#include "tools/PlumedCommunicator.h"
 
 #include <string>
 #include <cmath>
diff --git a/src/ColvarDRMSD.cpp b/src/basic/ColvarDRMSD.cpp
similarity index 99%
rename from src/ColvarDRMSD.cpp
rename to src/basic/ColvarDRMSD.cpp
index 16462d1212d80489d20d4dbc20cea584e47964d9..577ef0c5b0e1c6e5be02fce8cb34809761ee12ce 100644
--- a/src/ColvarDRMSD.cpp
+++ b/src/basic/ColvarDRMSD.cpp
@@ -22,8 +22,8 @@
 #include "Colvar.h"
 #include "PlumedMain.h"
 #include "ActionRegister.h"
-#include "PDB.h"
-#include "DRMSD.h"
+#include "tools/PDB.h"
+#include "tools/DRMSD.h"
 #include "Atoms.h"
 
 using namespace std;
diff --git a/src/ColvarDipole.cpp b/src/basic/ColvarDipole.cpp
similarity index 100%
rename from src/ColvarDipole.cpp
rename to src/basic/ColvarDipole.cpp
diff --git a/src/ColvarDistance.cpp b/src/basic/ColvarDistance.cpp
similarity index 100%
rename from src/ColvarDistance.cpp
rename to src/basic/ColvarDistance.cpp
diff --git a/src/ColvarEnergy.cpp b/src/basic/ColvarEnergy.cpp
similarity index 100%
rename from src/ColvarEnergy.cpp
rename to src/basic/ColvarEnergy.cpp
diff --git a/src/ColvarGyration.cpp b/src/basic/ColvarGyration.cpp
similarity index 99%
rename from src/ColvarGyration.cpp
rename to src/basic/ColvarGyration.cpp
index 5c54da4a1fd5ff5982bfe851f2f81e9b5e57d1f4..dfa0a39ee4451f76aa78a4797547326b7aa9c695 100644
--- a/src/ColvarGyration.cpp
+++ b/src/basic/ColvarGyration.cpp
@@ -22,7 +22,7 @@
 #include "Colvar.h"
 #include "ActionRegister.h"
 #include "PlumedMain.h"
-#include "Matrix.h"
+#include "tools/Matrix.h"
 
 #include <string>
 #include <cmath>
diff --git a/src/ColvarPathMSD.cpp b/src/basic/ColvarPathMSD.cpp
similarity index 100%
rename from src/ColvarPathMSD.cpp
rename to src/basic/ColvarPathMSD.cpp
diff --git a/src/ColvarPathMSDBase.cpp b/src/basic/ColvarPathMSDBase.cpp
similarity index 98%
rename from src/ColvarPathMSDBase.cpp
rename to src/basic/ColvarPathMSDBase.cpp
index 56108be103cd2810c675c26129e41281a3e8e2b5..603bdbe6a48205aa53aebe05793d97ba0a526e98 100644
--- a/src/ColvarPathMSDBase.cpp
+++ b/src/basic/ColvarPathMSDBase.cpp
@@ -29,10 +29,10 @@
 #include <cstring>
 #include <cassert>
 #include <iostream>
-#include "PDB.h"
-#include "RMSD.h"
+#include "tools/PDB.h"
+#include "tools/RMSD.h"
 #include "Atoms.h"
-#include "Tools.h"
+#include "tools/Tools.h"
 
 using namespace std;
 
diff --git a/src/ColvarPathMSDBase.h b/src/basic/ColvarPathMSDBase.h
similarity index 97%
rename from src/ColvarPathMSDBase.h
rename to src/basic/ColvarPathMSDBase.h
index e3767007b1d7957cccee0fe2ab88eece8100f10d..cb2764fc63583dd1e1fb3c34ba1bc4d148348ae5 100644
--- a/src/ColvarPathMSDBase.h
+++ b/src/basic/ColvarPathMSDBase.h
@@ -33,10 +33,10 @@
 #include <cstring>
 #include <cassert>
 #include <iostream>
-#include "PDB.h"
-#include "RMSD.h"
+#include "tools/PDB.h"
+#include "tools/RMSD.h"
 #include "Atoms.h"
-#include "Tools.h"
+#include "tools/Tools.h"
 
 using namespace std;
 
diff --git a/src/ColvarPropertyMap.cpp b/src/basic/ColvarPropertyMap.cpp
similarity index 100%
rename from src/ColvarPropertyMap.cpp
rename to src/basic/ColvarPropertyMap.cpp
diff --git a/src/ColvarRMSD.cpp b/src/basic/ColvarRMSD.cpp
similarity index 99%
rename from src/ColvarRMSD.cpp
rename to src/basic/ColvarRMSD.cpp
index c1a87bb927a7051398129bf752996a319f2c1b0c..28d5397e6ca77c6bdb37144f806a9d323362ff16 100644
--- a/src/ColvarRMSD.cpp
+++ b/src/basic/ColvarRMSD.cpp
@@ -22,8 +22,8 @@
 #include "Colvar.h"
 #include "PlumedMain.h"
 #include "ActionRegister.h"
-#include "PDB.h"
-#include "RMSD.h"
+#include "tools/PDB.h"
+#include "tools/RMSD.h"
 #include "Atoms.h"
 
 
diff --git a/src/ColvarTemplate.cpp b/src/basic/ColvarTemplate.cpp
similarity index 100%
rename from src/ColvarTemplate.cpp
rename to src/basic/ColvarTemplate.cpp
diff --git a/src/ColvarTorsion.cpp b/src/basic/ColvarTorsion.cpp
similarity index 99%
rename from src/ColvarTorsion.cpp
rename to src/basic/ColvarTorsion.cpp
index bf614551f4bd181a3e09ba09aab03bb2394c137f..56134dee1bfdd7b1e837cf16990380b6a8de2433 100644
--- a/src/ColvarTorsion.cpp
+++ b/src/basic/ColvarTorsion.cpp
@@ -21,7 +21,7 @@
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "Colvar.h"
 #include "ActionRegister.h"
-#include "Torsion.h"
+#include "tools/Torsion.h"
 
 #include <string>
 #include <cmath>
diff --git a/src/ColvarVolume.cpp b/src/basic/ColvarVolume.cpp
similarity index 100%
rename from src/ColvarVolume.cpp
rename to src/basic/ColvarVolume.cpp
diff --git a/src/CubicInterpolation.cpp b/src/basic/CubicInterpolation.cpp
similarity index 100%
rename from src/CubicInterpolation.cpp
rename to src/basic/CubicInterpolation.cpp
diff --git a/src/CubicInterpolation.h b/src/basic/CubicInterpolation.h
similarity index 99%
rename from src/CubicInterpolation.h
rename to src/basic/CubicInterpolation.h
index cb17cda298581b6244d30366fef8264f153e86c4..9a42d9eb2dfc8449a456f64220414e59e2272432 100644
--- a/src/CubicInterpolation.h
+++ b/src/basic/CubicInterpolation.h
@@ -23,7 +23,7 @@
 #define __PLUMED_CubitInterpolation_h
 
 #include <vector>
-#include "Matrix.h"
+#include "tools/Matrix.h"
 #include "Value.h"
 
 namespace PLMD {
diff --git a/src/ExchangePatterns.cpp b/src/basic/ExchangePatterns.cpp
similarity index 98%
rename from src/ExchangePatterns.cpp
rename to src/basic/ExchangePatterns.cpp
index 3f3692f54b57d7a9c7f0b7763e3be1245ada3f18..c940084c92179d769bd81cd570d9b36d870b6d02 100644
--- a/src/ExchangePatterns.cpp
+++ b/src/basic/ExchangePatterns.cpp
@@ -20,7 +20,7 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "ExchangePatterns.h"
-#include "Random.h"
+#include "tools/Random.h"
 
 using namespace std;
 
diff --git a/src/ExchangePatterns.h b/src/basic/ExchangePatterns.h
similarity index 100%
rename from src/ExchangePatterns.h
rename to src/basic/ExchangePatterns.h
diff --git a/src/FlexibleBin.cpp b/src/basic/FlexibleBin.cpp
similarity index 99%
rename from src/FlexibleBin.cpp
rename to src/basic/FlexibleBin.cpp
index 0ad7e3ce3921993820c194af426f4f9a05f861db..a91ffea78cc85d07bd38e8566e73ad968c8a98b6 100644
--- a/src/FlexibleBin.cpp
+++ b/src/basic/FlexibleBin.cpp
@@ -24,7 +24,7 @@
 #include <cmath>
 #include <iostream>
 #include <vector>
-#include "Matrix.h"
+#include "tools/Matrix.h"
 
 using namespace std;
 using namespace PLMD;
diff --git a/src/FlexibleBin.h b/src/basic/FlexibleBin.h
similarity index 100%
rename from src/FlexibleBin.h
rename to src/basic/FlexibleBin.h
diff --git a/src/Function.cpp b/src/basic/Function.cpp
similarity index 100%
rename from src/Function.cpp
rename to src/basic/Function.cpp
diff --git a/src/Function.h b/src/basic/Function.h
similarity index 100%
rename from src/Function.h
rename to src/basic/Function.h
diff --git a/src/FunctionCombine.cpp b/src/basic/FunctionCombine.cpp
similarity index 100%
rename from src/FunctionCombine.cpp
rename to src/basic/FunctionCombine.cpp
diff --git a/src/FunctionFuncPathMSD.cpp b/src/basic/FunctionFuncPathMSD.cpp
similarity index 99%
rename from src/FunctionFuncPathMSD.cpp
rename to src/basic/FunctionFuncPathMSD.cpp
index 086e8df3d51b97d8aa48ec88fe8fa21dce26d316..2d239ff227cd9ff31541f9763b6ab109325c50dd 100644
--- a/src/FunctionFuncPathMSD.cpp
+++ b/src/basic/FunctionFuncPathMSD.cpp
@@ -27,7 +27,7 @@
 #include <string>
 #include <cstring>
 #include <cassert>
-//#include "ColvarRMSD.h"
+//#include "Colvartools/RMSD.h"
 #include <iostream>
 
 using namespace std;
diff --git a/src/FunctionMatheval.cpp b/src/basic/FunctionMatheval.cpp
similarity index 100%
rename from src/FunctionMatheval.cpp
rename to src/basic/FunctionMatheval.cpp
diff --git a/src/FunctionPiecewise.cpp b/src/basic/FunctionPiecewise.cpp
similarity index 100%
rename from src/FunctionPiecewise.cpp
rename to src/basic/FunctionPiecewise.cpp
diff --git a/src/FunctionSort.cpp b/src/basic/FunctionSort.cpp
similarity index 100%
rename from src/FunctionSort.cpp
rename to src/basic/FunctionSort.cpp
diff --git a/src/FunctionTarget.cpp b/src/basic/FunctionTarget.cpp
similarity index 99%
rename from src/FunctionTarget.cpp
rename to src/basic/FunctionTarget.cpp
index ddd5408c3ddd4c90e37f6f6fb131adeee7104689..2a3f2dee70dbc969965d2901cdf9c5b55f3e0787 100644
--- a/src/FunctionTarget.cpp
+++ b/src/basic/FunctionTarget.cpp
@@ -22,7 +22,7 @@
 #include "Function.h"
 #include "PlumedMain.h"
 #include "ActionRegister.h"
-#include "PDB.h"
+#include "tools/PDB.h"
 #include "TargetDist.h"
 #include "Atoms.h"
 
diff --git a/src/GREX.cpp b/src/basic/GREX.cpp
similarity index 98%
rename from src/GREX.cpp
rename to src/basic/GREX.cpp
index 42a7c408dc614d9ee949d55b5bae817efa012af5..9abf4d60ec90f2916e802395ebbbbead64427b5b 100644
--- a/src/GREX.cpp
+++ b/src/basic/GREX.cpp
@@ -22,8 +22,8 @@
 #include "GREX.h"
 #include "PlumedMain.h"
 #include "Atoms.h"
-#include "Tools.h"
-#include "PlumedCommunicator.h"
+#include "tools/Tools.h"
+#include "tools/PlumedCommunicator.h"
 #include <sstream>
 
 using namespace std;
diff --git a/src/GREX.h b/src/basic/GREX.h
similarity index 100%
rename from src/GREX.h
rename to src/basic/GREX.h
diff --git a/src/GenericCOM.cpp b/src/basic/GenericCOM.cpp
similarity index 100%
rename from src/GenericCOM.cpp
rename to src/basic/GenericCOM.cpp
diff --git a/src/GenericCenter.cpp b/src/basic/GenericCenter.cpp
similarity index 100%
rename from src/GenericCenter.cpp
rename to src/basic/GenericCenter.cpp
diff --git a/src/GenericDebug.cpp b/src/basic/GenericDebug.cpp
similarity index 100%
rename from src/GenericDebug.cpp
rename to src/basic/GenericDebug.cpp
diff --git a/src/GenericDumpAtoms.cpp b/src/basic/GenericDumpAtoms.cpp
similarity index 98%
rename from src/GenericDumpAtoms.cpp
rename to src/basic/GenericDumpAtoms.cpp
index 3343080eb1a8ee8c62f5f6e17c8c14c851d6fba2..670338e96b53483fcbb877ac2b56735c8fedcc9d 100644
--- a/src/GenericDumpAtoms.cpp
+++ b/src/basic/GenericDumpAtoms.cpp
@@ -22,8 +22,8 @@
 #include "ActionAtomistic.h"
 #include "ActionPilot.h"
 #include "ActionRegister.h"
-#include "Pbc.h"
-#include "PlumedFile.h"
+#include "tools/Pbc.h"
+#include "tools/PlumedFile.h"
 #include "PlumedMain.h"
 #include "Atoms.h"
 #include "Units.h"
diff --git a/src/GenericDumpDerivatives.cpp b/src/basic/GenericDumpDerivatives.cpp
similarity index 98%
rename from src/GenericDumpDerivatives.cpp
rename to src/basic/GenericDumpDerivatives.cpp
index f06ac6bdcbe678860d725277a865f22efa3e9755..02ff28941fdba335af35fc1d7a277ed9e7ac8661 100644
--- a/src/GenericDumpDerivatives.cpp
+++ b/src/basic/GenericDumpDerivatives.cpp
@@ -22,8 +22,8 @@
 #include "ActionPilot.h"
 #include "ActionWithArguments.h"
 #include "ActionRegister.h"
-#include "PlumedCommunicator.h"
-#include "PlumedFile.h"
+#include "tools/PlumedCommunicator.h"
+#include "tools/PlumedFile.h"
 #include <cassert>
 
 using namespace std;
diff --git a/src/GenericDumpForces.cpp b/src/basic/GenericDumpForces.cpp
similarity index 98%
rename from src/GenericDumpForces.cpp
rename to src/basic/GenericDumpForces.cpp
index a9542c5cb7b9bbb2fb05ea5f83b971eb42cbcaf6..e816e1f6ee61d0de3c475c214d01118029cd7620 100644
--- a/src/GenericDumpForces.cpp
+++ b/src/basic/GenericDumpForces.cpp
@@ -22,8 +22,8 @@
 #include "ActionPilot.h"
 #include "ActionWithArguments.h"
 #include "ActionRegister.h"
-#include "PlumedCommunicator.h"
-#include "PlumedFile.h"
+#include "tools/PlumedCommunicator.h"
+#include "tools/PlumedFile.h"
 #include <cassert>
 
 using namespace std;
diff --git a/src/GenericDumpProjections.cpp b/src/basic/GenericDumpProjections.cpp
similarity index 97%
rename from src/GenericDumpProjections.cpp
rename to src/basic/GenericDumpProjections.cpp
index 5c5457f77f56a33668331381184a906352561513..341d94983a81a01a238fbfa413670e6c06e89b15 100644
--- a/src/GenericDumpProjections.cpp
+++ b/src/basic/GenericDumpProjections.cpp
@@ -22,8 +22,8 @@
 #include "ActionPilot.h"
 #include "ActionWithArguments.h"
 #include "ActionRegister.h"
-#include "PlumedCommunicator.h"
-#include "PlumedFile.h"
+#include "tools/PlumedCommunicator.h"
+#include "tools/PlumedFile.h"
 #include <cassert>
 
 using namespace std;
diff --git a/src/GenericFlush.cpp b/src/basic/GenericFlush.cpp
similarity index 100%
rename from src/GenericFlush.cpp
rename to src/basic/GenericFlush.cpp
diff --git a/src/GenericGhostAtom.cpp b/src/basic/GenericGhostAtom.cpp
similarity index 99%
rename from src/GenericGhostAtom.cpp
rename to src/basic/GenericGhostAtom.cpp
index 29416634e45e36256cdda3ebaba564bc719372a6..9d6c9f162aa42dd1118cb486ec1bd9d0e0a35f49 100644
--- a/src/GenericGhostAtom.cpp
+++ b/src/basic/GenericGhostAtom.cpp
@@ -21,8 +21,8 @@
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "ActionWithVirtualAtom.h"
 #include "ActionRegister.h"
-#include "Vector.h"
-#include "PlumedException.h"
+#include "tools/Vector.h"
+#include "tools/PlumedException.h"
 
 using namespace std;
 
diff --git a/src/GenericGroup.cpp b/src/basic/GenericGroup.cpp
similarity index 100%
rename from src/GenericGroup.cpp
rename to src/basic/GenericGroup.cpp
diff --git a/src/GenericPrint.cpp b/src/basic/GenericPrint.cpp
similarity index 99%
rename from src/GenericPrint.cpp
rename to src/basic/GenericPrint.cpp
index 0f61eded92d302f10f026d96c141d938aeaa6d1a..eb9f967bc5728b14704e657ed079bf75bb2a7271 100644
--- a/src/GenericPrint.cpp
+++ b/src/basic/GenericPrint.cpp
@@ -22,7 +22,7 @@
 #include "ActionPilot.h"
 #include "ActionWithArguments.h"
 #include "ActionRegister.h"
-#include "PlumedCommunicator.h"
+#include "tools/PlumedCommunicator.h"
 
 using namespace std;
 
diff --git a/src/GenericTime.cpp b/src/basic/GenericTime.cpp
similarity index 100%
rename from src/GenericTime.cpp
rename to src/basic/GenericTime.cpp
diff --git a/src/GenericWholeMolecules.cpp b/src/basic/GenericWholeMolecules.cpp
similarity index 98%
rename from src/GenericWholeMolecules.cpp
rename to src/basic/GenericWholeMolecules.cpp
index a53d69c670d8d555b1a5abf7958357e5f38c58db..8673e2051d29c05ddc67b270ff48d08251634078 100644
--- a/src/GenericWholeMolecules.cpp
+++ b/src/basic/GenericWholeMolecules.cpp
@@ -22,9 +22,9 @@
 #include "ActionAtomistic.h"
 #include "ActionPilot.h"
 #include "ActionRegister.h"
-#include "Vector.h"
-#include "AtomNumber.h"
-#include "Tools.h"
+#include "tools/Vector.h"
+#include "tools/AtomNumber.h"
+#include "tools/Tools.h"
 #include "Atoms.h"
 #include "PlumedMain.h"
 #include "ActionSet.h"
diff --git a/src/MDAtoms.cpp b/src/basic/MDAtoms.cpp
similarity index 99%
rename from src/MDAtoms.cpp
rename to src/basic/MDAtoms.cpp
index 71fe0b3c23e8fe6164969c3ddd62d5926dc1765e..018529454abf497ae8b875f1d2e270fd9ff39047 100644
--- a/src/MDAtoms.cpp
+++ b/src/basic/MDAtoms.cpp
@@ -22,8 +22,8 @@
 #include <algorithm>
 #include <string>
 #include "MDAtoms.h"
-#include "Tools.h"
-#include "PlumedException.h"
+#include "tools/Tools.h"
+#include "tools/PlumedException.h"
 
 using namespace PLMD;
 using namespace std;
diff --git a/src/MDAtoms.h b/src/basic/MDAtoms.h
similarity index 98%
rename from src/MDAtoms.h
rename to src/basic/MDAtoms.h
index 85f376c3a1ab2fb670f9e2d6887a520db5718bb4..cd5b0e4d434957d9292aefef987cac9f1bd7de5c 100644
--- a/src/MDAtoms.h
+++ b/src/basic/MDAtoms.h
@@ -22,8 +22,8 @@
 #ifndef __PLUMED_MDAtoms_h
 #define __PLUMED_MDAtoms_h
 
-#include "Tensor.h"
-#include "Vector.h"
+#include "tools/Tensor.h"
+#include "tools/Vector.h"
 #include <vector>
 #include "Units.h"
 
diff --git a/src/basic/Makefile b/src/basic/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..d3405a7179df67e5a44c131fcced93e76003f3f9
--- /dev/null
+++ b/src/basic/Makefile
@@ -0,0 +1,5 @@
+USE=config tools
+BUILDAFTER=config
+
+# generic makefile
+include ../maketools/make.module
diff --git a/src/PlumedMain.cpp b/src/basic/PlumedMain.cpp
similarity index 98%
rename from src/PlumedMain.cpp
rename to src/basic/PlumedMain.cpp
index 63b9b31206bb4431b1093f562522b672a4ce405c..886e84c40b8fb28ec611dc24c316a61a3993f552 100644
--- a/src/PlumedMain.cpp
+++ b/src/basic/PlumedMain.cpp
@@ -20,7 +20,7 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "PlumedMain.h"
-#include "Tools.h"
+#include "tools/Tools.h"
 #include <cstring>
 #include "ActionPilot.h"
 #include "ActionWithValue.h"
@@ -28,20 +28,20 @@
 #include "ActionWithVirtualAtom.h"
 #include "Atoms.h"
 #include <set>
-#include "PlumedConfig.h"
+#include "config/PlumedConfig.h"
 #include "Colvar.h"
 #include <cstdlib>
 #include "ActionRegister.h"
 #include "GREX.h"
-#include "PlumedException.h"
+#include "tools/PlumedException.h"
 #include "Atoms.h"
 #include "ActionSet.h"
-#include "Log.h"
-#include "DLLoader.h"
-#include "PlumedCommunicator.h"
+#include "tools/Log.h"
+#include "tools/DLLoader.h"
+#include "tools/PlumedCommunicator.h"
 #include "CLToolMain.h"
-#include "Stopwatch.h"
-#include "Citations.h"
+#include "tools/Stopwatch.h"
+#include "tools/Citations.h"
 #include "ExchangePatterns.h"
 
 using namespace PLMD;
diff --git a/src/PlumedMain.h b/src/basic/PlumedMain.h
similarity index 99%
rename from src/PlumedMain.h
rename to src/basic/PlumedMain.h
index 1e087127a2c632c07da950233d4df15edcba7f07..b3fc8ab5c97f66d0293d889019a08bc68262a92f 100644
--- a/src/PlumedMain.h
+++ b/src/basic/PlumedMain.h
@@ -90,7 +90,7 @@ private:
   std::string MDEngine;
 /// Log stream
   Log& log;
-/// Citations holder
+/// tools/Citations.holder
   Citations& citations;
 
 /// Present step number.
diff --git a/src/PlumedMainInitializer.cpp b/src/basic/PlumedMainInitializer.cpp
similarity index 98%
rename from src/PlumedMainInitializer.cpp
rename to src/basic/PlumedMainInitializer.cpp
index a340f9314e935da7c98b17e93d817b1905a581ca..67aca0d74b8bea243546ef395256af19c00f2341 100644
--- a/src/PlumedMainInitializer.cpp
+++ b/src/basic/PlumedMainInitializer.cpp
@@ -20,7 +20,7 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "PlumedMain.h"
-#include "PlumedException.h"
+#include "tools/PlumedException.h"
 #include <cstdlib>
 
 using namespace PLMD;
diff --git a/src/SetupMolInfo.cpp b/src/basic/SetupMolInfo.cpp
similarity index 99%
rename from src/SetupMolInfo.cpp
rename to src/basic/SetupMolInfo.cpp
index 3295f8fe8b2b3be24255d94f41fae31b28c2865d..ee04b5cfdffa7ef71771c01abe1011035f47b61e 100644
--- a/src/SetupMolInfo.cpp
+++ b/src/basic/SetupMolInfo.cpp
@@ -24,7 +24,7 @@
 #include "ActionRegister.h"
 #include "ActionSet.h"
 #include "PlumedMain.h"
-#include "PDB.h"
+#include "tools/PDB.h"
 
 
 namespace PLMD {
diff --git a/src/SetupMolInfo.h b/src/basic/SetupMolInfo.h
similarity index 97%
rename from src/SetupMolInfo.h
rename to src/basic/SetupMolInfo.h
index 9452ab98c4a9db430a1fa014c4cf5e06329ace6a..57e793c10f3b14f792060014864cef4cf62d1974 100644
--- a/src/SetupMolInfo.h
+++ b/src/basic/SetupMolInfo.h
@@ -24,7 +24,7 @@
 
 #include "ActionSetup.h"
 #include "ActionAtomistic.h"
-#include "PlumedException.h"
+#include "tools/PlumedException.h"
 
 namespace PLMD {
 
diff --git a/src/SetupRestart.cpp b/src/basic/SetupRestart.cpp
similarity index 98%
rename from src/SetupRestart.cpp
rename to src/basic/SetupRestart.cpp
index 6adc3ea0c97a53b99b1d173bc244a556f03971d1..6e2d65cabbe9931222e14508a4701a7b23350938 100644
--- a/src/SetupRestart.cpp
+++ b/src/basic/SetupRestart.cpp
@@ -23,7 +23,7 @@
 #include "ActionRegister.h"
 #include "PlumedMain.h"
 #include "Atoms.h"
-#include "PlumedException.h"
+#include "tools/PlumedException.h"
 
 using namespace std;
 
diff --git a/src/SetupUnits.cpp b/src/basic/SetupUnits.cpp
similarity index 99%
rename from src/SetupUnits.cpp
rename to src/basic/SetupUnits.cpp
index a3fd7b251640399c6ba56894374a4fb158a7577c..b834063ebd5ed0cee1335b453d0c9694ecab6adc 100644
--- a/src/SetupUnits.cpp
+++ b/src/basic/SetupUnits.cpp
@@ -23,7 +23,7 @@
 #include "ActionRegister.h"
 #include "PlumedMain.h"
 #include "Atoms.h"
-#include "PlumedException.h"
+#include "tools/PlumedException.h"
 
 using namespace std;
 
diff --git a/src/TargetDist.cpp b/src/basic/TargetDist.cpp
similarity index 99%
rename from src/TargetDist.cpp
rename to src/basic/TargetDist.cpp
index 2c34f71c347f184cf9981592cd774143a5b68a7e..cc122cccc72c6f1cc3cfb3ad39f0033e8cbb2b9c 100644
--- a/src/TargetDist.cpp
+++ b/src/basic/TargetDist.cpp
@@ -20,7 +20,7 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "TargetDist.h"
-#include "PDB.h"
+#include "tools/PDB.h"
 #include "ActionWithValue.h"
 #include "Value.h"
 
diff --git a/src/TargetDist.h b/src/basic/TargetDist.h
similarity index 100%
rename from src/TargetDist.h
rename to src/basic/TargetDist.h
diff --git a/src/Units.cpp b/src/basic/Units.cpp
similarity index 98%
rename from src/Units.cpp
rename to src/basic/Units.cpp
index a5057c17d0cc7202207c00df60d201d4c8fca966..05548f13d88e71671b130a85ac12aaf2e22d2dea 100644
--- a/src/Units.cpp
+++ b/src/basic/Units.cpp
@@ -20,7 +20,7 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "Units.h"
-#include "Tools.h"
+#include "tools/Tools.h"
 
 using namespace std;
 
diff --git a/src/Units.h b/src/basic/Units.h
similarity index 100%
rename from src/Units.h
rename to src/basic/Units.h
diff --git a/src/Value.cpp b/src/basic/Value.cpp
similarity index 99%
rename from src/Value.cpp
rename to src/basic/Value.cpp
index 3c6201348cbba15049045769df023024c56a1917..3699d74f68e47203d159b5668fab82024a125307 100644
--- a/src/Value.cpp
+++ b/src/basic/Value.cpp
@@ -24,7 +24,7 @@
 #include "ActionAtomistic.h"
 #include "ActionWithArguments.h"
 #include "ActionWithVirtualAtom.h"
-#include "PlumedException.h"
+#include "tools/PlumedException.h"
 #include "Atoms.h"
 #include "PlumedMain.h"
 
diff --git a/src/Value.h b/src/basic/Value.h
similarity index 98%
rename from src/Value.h
rename to src/basic/Value.h
index 34813647a31cfb482fbe899f5a0cbc2d84485d72..23c07eec81cc536113bec6d84a7f9a1927c7149b 100644
--- a/src/Value.h
+++ b/src/basic/Value.h
@@ -25,10 +25,10 @@
 #include <vector>
 #include <string>
 #include <map>
-#include "PlumedException.h"
-#include "Tools.h"
-#include "AtomNumber.h"
-#include "Vector.h"
+#include "tools/PlumedException.h"
+#include "tools/Tools.h"
+#include "tools/AtomNumber.h"
+#include "tools/Vector.h"
 
 namespace PLMD{
 
diff --git a/src/VolumeSubcell.cpp b/src/basic/VolumeSubcell.cpp
similarity index 100%
rename from src/VolumeSubcell.cpp
rename to src/basic/VolumeSubcell.cpp
diff --git a/src/WithCmd.h b/src/basic/WithCmd.h
similarity index 100%
rename from src/WithCmd.h
rename to src/basic/WithCmd.h
diff --git a/src/basic/module.type b/src/basic/module.type
new file mode 100644
index 0000000000000000000000000000000000000000..0b31619da490b1be9c1616597c37f1034d572b68
--- /dev/null
+++ b/src/basic/module.type
@@ -0,0 +1 @@
+always
diff --git a/src/cltools/.gitignore b/src/cltools/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..4888552338441b5d99a97ec7a2cb2ce448e9e4e6
--- /dev/null
+++ b/src/cltools/.gitignore
@@ -0,0 +1,9 @@
+/*
+# in this directory, only accept source, Makefile and README
+!/.gitignore
+!/*.c
+!/*.cpp
+!/*.h
+!/Makefile
+!/README
+!/module.type
diff --git a/src/CLToolDriver.cpp b/src/cltools/CLToolDriver.cpp
similarity index 98%
rename from src/CLToolDriver.cpp
rename to src/cltools/CLToolDriver.cpp
index 6199ed834ba18cc8e1232e699cb91c8ce51d5efb..17bb9c8dc567f805c260d3e8cf7506ce5baf2cba 100644
--- a/src/CLToolDriver.cpp
+++ b/src/cltools/CLToolDriver.cpp
@@ -19,17 +19,17 @@
    You should have received a copy of the GNU Lesser General Public License
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
-#include "CLTool.h"
-#include "CLToolRegister.h"
-#include "Tools.h"
-#include "Plumed.h"
-#include "PlumedCommunicator.h"
-#include "Random.h"
+#include "basic/CLTool.h"
+#include "basic/CLToolRegister.h"
+#include "tools/Tools.h"
+#include "wrapper/Plumed.h"
+#include "tools/PlumedCommunicator.h"
+#include "tools/Random.h"
 #include <cstdio>
 #include <string>
 #include <vector>
-#include "Units.h"
-#include "PDB.h"
+#include "basic/Units.h"
+#include "tools/PDB.h"
 
 using namespace std;
 
diff --git a/src/CLToolInfo.cpp b/src/cltools/CLToolInfo.cpp
similarity index 94%
rename from src/CLToolInfo.cpp
rename to src/cltools/CLToolInfo.cpp
index 90367cfcb75d3589f4cc198ae2bdd2c175dbb183..7e4cf431d1c3138d69c26a0098e173b425438cbc 100644
--- a/src/CLToolInfo.cpp
+++ b/src/cltools/CLToolInfo.cpp
@@ -19,10 +19,10 @@
    You should have received a copy of the GNU Lesser General Public License
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
-#include "CLTool.h"
-#include "CLToolRegister.h"
-#include "Tools.h"
-#include "PlumedConfig.h"
+#include "basic/CLTool.h"
+#include "basic/CLToolRegister.h"
+#include "tools/Tools.h"
+#include "config/PlumedConfig.h"
 #include <cstdio>
 #include <string>
 #include <vector>
@@ -82,7 +82,7 @@ int CLToolInfo::main(FILE* in, FILE*out,PlumedCommunicator& pc){
 
  if(printconfiguration){
     static const unsigned char conf [] ={
-#include "Makefile.conf.xxd"
+#include "config/Makefile.conf.xxd"
     , 0x00 };
     fprintf(out,"%s",conf);
     return 0;
diff --git a/src/CLToolManual.cpp b/src/cltools/CLToolManual.cpp
similarity index 94%
rename from src/CLToolManual.cpp
rename to src/cltools/CLToolManual.cpp
index fdc92f433f42f27e81ad5ec383dabf623eb1e8e2..cddc0b4bb7e01f675f3b16245c8d38e0b78d07cd 100644
--- a/src/CLToolManual.cpp
+++ b/src/cltools/CLToolManual.cpp
@@ -19,11 +19,11 @@
    You should have received a copy of the GNU Lesser General Public License
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
-#include "CLTool.h"
-#include "CLToolRegister.h"
-#include "Tools.h"
-#include "PlumedConfig.h"
-#include "ActionRegister.h"
+#include "basic/CLTool.h"
+#include "basic/CLToolRegister.h"
+#include "tools/Tools.h"
+#include "config/PlumedConfig.h"
+#include "basic/ActionRegister.h"
 #include <cstdio>
 #include <string>
 #include <vector>
diff --git a/src/CLToolSimpleMD.cpp b/src/cltools/CLToolSimpleMD.cpp
similarity index 99%
rename from src/CLToolSimpleMD.cpp
rename to src/cltools/CLToolSimpleMD.cpp
index 687b384424c894a12f765132bdf22e0ca11a8188..d852465fa34b27d6c450c1009a20df6f2e7ff2a5 100644
--- a/src/CLToolSimpleMD.cpp
+++ b/src/cltools/CLToolSimpleMD.cpp
@@ -19,11 +19,11 @@
    You should have received a copy of the GNU Lesser General Public License
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
-#include "CLTool.h"
-#include "CLToolRegister.h"
-#include "Plumed.h"
-#include "Vector.h"
-#include "Random.h"
+#include "basic/CLTool.h"
+#include "basic/CLToolRegister.h"
+#include "wrapper/Plumed.h"
+#include "tools/Vector.h"
+#include "tools/Random.h"
 #include <string>
 #include <cstdio>
 #include <cmath>
diff --git a/src/CLToolTemplateGenerator.cpp b/src/cltools/CLToolTemplateGenerator.cpp
similarity index 95%
rename from src/CLToolTemplateGenerator.cpp
rename to src/cltools/CLToolTemplateGenerator.cpp
index d9cfcb37f3ba5a8f9dce6993ce057a3e53e92616..37d347b7e1f6b0f8fb9d1568654d5a79183c4dde 100644
--- a/src/CLToolTemplateGenerator.cpp
+++ b/src/cltools/CLToolTemplateGenerator.cpp
@@ -19,11 +19,11 @@
    You should have received a copy of the GNU Lesser General Public License
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
-#include "CLTool.h"
-#include "CLToolRegister.h"
-#include "Tools.h"
-#include "PlumedConfig.h"
-#include "ActionRegister.h"
+#include "basic/CLTool.h"
+#include "basic/CLToolRegister.h"
+#include "tools/Tools.h"
+//#include "PlumedConfig.h"
+#include "basic/ActionRegister.h"
 #include <cstdio>
 #include <string>
 #include <vector>
diff --git a/src/cltools/Makefile b/src/cltools/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..32cb268c556c3c8548998566133580ce68d8ece3
--- /dev/null
+++ b/src/cltools/Makefile
@@ -0,0 +1,5 @@
+USE=basic wrapper config tools
+BUILDAFTER=config
+
+# generic makefile
+include ../maketools/make.module
diff --git a/src/cltools/module.type b/src/cltools/module.type
new file mode 100644
index 0000000000000000000000000000000000000000..fc25731b66113b18d1a475c4aacc51104db7f883
--- /dev/null
+++ b/src/cltools/module.type
@@ -0,0 +1 @@
+default-on
diff --git a/src/config/.gitignore b/src/config/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..2ad116689535c04cb92ae67dffa1bfd1369298bb
--- /dev/null
+++ b/src/config/.gitignore
@@ -0,0 +1,2 @@
+/compile_options.sh
+/PlumedConfig.h
diff --git a/src/config/Makefile b/src/config/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..980ea530c21536c90cbe9e88522cfa0f04e615b3
--- /dev/null
+++ b/src/config/Makefile
@@ -0,0 +1,31 @@
+
+# include the machine dependent configuration
+-include ../../Makefile.conf
+
+# default target
+.PHONY: all
+all: PlumedConfig.h Makefile.conf.xxd compile_options.sh
+
+# file to import compilation options inside c++
+PlumedConfig.h: PlumedConfig.h.in ../../Makefile.conf
+	@echo Building PlumedConfig.h, an includable c++ header with some compilation options
+	@sed "s/@SOEXT@/$(SOEXT)/g" $< | \
+         sed "s|@PLUMED_ROOT@|$(CURDIR:src/config=)|g" > $@
+
+Makefile.conf.xxd: ../../Makefile.conf
+	cat ../../Makefile.conf | xxd -i > Makefile.conf.xxd
+
+# file to import compilation options inside a bash script
+compile_options.sh:
+	@echo Building compile_options.sh, a sourceable bash script with some compilation options
+	@echo "compile='"$(CXX) -c -I$(realpath .) $(CPPFLAGS) $(CXXFLAGS) -o"'" > $@
+	@echo "link='"$(LDSO) -o"'" >> $@
+	@echo "soext='"$(SOEXT)"'" >> $@
+
+.PHONY: clean
+clean:
+	rm -f PlumedConfig.h compile_options.sh
+	rm -f $(CLEANLIST)
+
+# generic makefile rules
+include ../maketools/make.rules
diff --git a/src/PlumedConfig.h.in b/src/config/PlumedConfig.h.in
similarity index 100%
rename from src/PlumedConfig.h.in
rename to src/config/PlumedConfig.h.in
diff --git a/src/header.sh b/src/header.sh
index 46f5301b64ef1112441ef8dbb3934616c21101ee..ec032aef98e9ac4b8e1022ccf48d55283af62529 100755
--- a/src/header.sh
+++ b/src/header.sh
@@ -1,7 +1,7 @@
 # This script adds a LGPL header to all the source files
 # If the header is already present, it does not touch the file
 # Please run it whenever you add a new file so as to keep copyright info there!
-for file in *.c *.cpp *.h PlumedConfig.h.in
+for file in */*.c */*.cpp */*.h */PlumedConfig.h.in
 do
 
 if [ $file == "PlumedConfig.h" ] ; then
diff --git a/imd/.gitignore b/src/imd/.gitignore
similarity index 70%
rename from imd/.gitignore
rename to src/imd/.gitignore
index a5a5805b54c189f6af8512b79d885eac832346ff..b6c9587b87db65b7e5b52417cc8d58ad830fb4b2 100644
--- a/imd/.gitignore
+++ b/src/imd/.gitignore
@@ -2,3 +2,4 @@
 /*.h
 /Makefile.conf
 /imdapi*
+!/module.type
diff --git a/imd/ActionIMD.cpp b/src/imd/ActionIMD.cpp
similarity index 93%
rename from imd/ActionIMD.cpp
rename to src/imd/ActionIMD.cpp
index 7c6507b8265145b5f56ee125a297002a624b3098..80f4805866deede649f4fbca3a088b2da3e35615 100644
--- a/imd/ActionIMD.cpp
+++ b/src/imd/ActionIMD.cpp
@@ -1,9 +1,9 @@
-#include "../src/ActionRegister.h"
-#include "../src/ActionAtomistic.h"
-#include "../src/ActionPilot.h"
-#include "../src/PlumedMain.h"
-#include "../src/Atoms.h"
-#include "../src/PlumedException.h"
+#include "../basic/ActionRegister.h"
+#include "../basic/ActionAtomistic.h"
+#include "../basic/ActionPilot.h"
+#include "../basic/PlumedMain.h"
+#include "../basic/Atoms.h"
+#include "../tools/PlumedException.h"
 #include <unistd.h>
 
 extern "C" {
@@ -229,7 +229,7 @@ void IMD::receive(){
 
 void IMD::calculate(){
   if(comm.Get_rank()==0 && connected && plumed.getStep()%transferRate==0 && vmdsock_selwrite(clientsock,0)) {
-    double scale=10.0*plumed.getAtoms().getUnits().length;
+    double scale=10.0*plumed.getAtoms().getUnits().getLength();
     Vector ref;
     for(int i=0;i<natoms;i++){
       Vector pos=getPosition(i);
@@ -246,8 +246,8 @@ void IMD::apply(){
 
   std::vector<Vector> & f(modifyForces());
    
-  const double scale=4.184/plumed.getAtoms().getUnits().energy
-             /(0.1/plumed.getAtoms().getUnits().length)*fscale;
+  const double scale=4.184/plumed.getAtoms().getUnits().getEnergy()
+             /(0.1/plumed.getAtoms().getUnits().getLength())*fscale;
    
   for(unsigned i=0;i<f.size();i++){
     f[i][0]=forces[3*i+0]*getStride()*scale;
diff --git a/imd/Makefile b/src/imd/Makefile
similarity index 85%
rename from imd/Makefile
rename to src/imd/Makefile
index 06b86b06c8a90785b5b4d223fc7ac11aa5791a9a..2d510ae4cf4ccc022b476a6a73777fc75ce589fb 100644
--- a/imd/Makefile
+++ b/src/imd/Makefile
@@ -1,9 +1,9 @@
--include ../Makefile.conf
+-include ../../Makefile.conf
 
 all: libimd.$(SOEXT)
 
 libimd.$(SOEXT): imd.o vmdsock.o ActionIMD.o
-	$(LDSO) -o $@ $^ -lnsl
+	$(LDSO) -o $@ $^ # -lnsl
 
 vmdsock.c imd.c vmdsock.h imd.h: imdapi.tar.gz
 	tar xzOf imdapi.tar.gz imdapi/$@ > $@
@@ -18,5 +18,3 @@ clean:
 	rm -fr imdapi.tar.gz *.c *.h *.$(SOEXT) *.o
 
 
-
-
diff --git a/src/imd/module.type b/src/imd/module.type
new file mode 100644
index 0000000000000000000000000000000000000000..de832730330473a1870bd368868640da677460ae
--- /dev/null
+++ b/src/imd/module.type
@@ -0,0 +1 @@
+default-off
diff --git a/src/lib/.gitignore b/src/lib/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..7256f01dec187a147fb6611712e64429ef12a160
--- /dev/null
+++ b/src/lib/.gitignore
@@ -0,0 +1,6 @@
+/Plumed.inc*
+/compile_options.sh
+/plumed-static
+/plumed-shared
+/plumed-runtime
+/plumed
diff --git a/src/lib/Makefile b/src/lib/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..6314ff9103c56c98988e65e8020a0b5c52b05df2
--- /dev/null
+++ b/src/lib/Makefile
@@ -0,0 +1,135 @@
+# here we build the list of modules to be linked in plumedKernel
+KERNEL_MODULES=$(addprefix ../,$(shell ../maketools/find_modules.sh))
+
+# This adds modules which are built anyway and linked with some ad hoc procedure
+DIRS=$(sort ../config ../wrapper ../main  $(KERNEL_MODULES))
+
+
+# include the machine dependent configuration
+-include ../../Makefile.conf
+
+# if machine dependent configuration has been found:
+ifdef GCCDEP
+
+# source for plumed wrapper
+SRC_WRAPPER=../wrapper/PlumedStatic.cpp
+
+# source for plumed dynamic wrapper
+SRC_DYNAMIC_WRAPPER=../wrapper/Plumed.c
+
+# source for plumed main program
+# this should not be linked into libraries
+SRC_MAIN=../main/main.cpp
+
+# source for plumed kernel
+# everything else
+SRC_KERNEL=$(shell for dir in $(KERNEL_MODULES) ; do ls $$dir/*.{c,cpp} 2>/dev/null ; done)
+
+# corresponding objects:
+OBJ_WRAPPER=../wrapper/PlumedStatic.o
+OBJ_DYNAMIC_WRAPPER=../wrapper/Plumed.o
+OBJ_MAIN=$(SRC_MAIN:.cpp=.o)
+XXX=$(SRC_KERNEL:.cpp=.o)
+OBJ_KERNEL=$(XXX:.c=.o)
+ALL_OBJ=$(OBJ_KERNEL) $(OBJ_WRAPPER) $(OBJ_DYNAMIC_WRAPPER) $(OBJ_MAIN)
+
+# plumed kernel
+PLUMED_KERNEL=libplumedKernel.$(SOEXT)
+
+# plumed library (kernel + wrapper)
+PLUMED_SHARED_OBJ=libplumed.$(SOEXT)
+
+# plumed main exec
+PLUMED_MAIN_STATIC=plumed
+PLUMED_MAIN_SHARED=plumed-shared
+PLUMED_MAIN_RUNTIME=plumed-runtime
+
+.PHONY: all dirs $(DIRS)
+all:
+	@echo First making other dirs $(DIRS)
+	$(MAKE) dirs
+	$(MAKE) lib
+
+dirs: $(DIRS)
+
+$(DIRS):
+	$(MAKE) -C $@
+
+
+# default target
+.PHONY: lib
+lib: $(PLUMED_KERNEL) $(PLUMED_SHARED_OBJ) $(OBJ_WRAPPER) \
+     $(PLUMED_MAIN_STATIC) $(PLUMED_MAIN_SHARED) $(PLUMED_MAIN_RUNTIME) \
+     Plumed.inc Plumed.inc.runtime Plumed.inc.shared Plumed.inc.static 
+
+$(PLUMED_KERNEL):$(OBJ_KERNEL)
+	$(LDSO) -o $@ $^ $(DYNAMIC_LIBS)
+
+$(PLUMED_SHARED_OBJ): $(OBJ_KERNEL) $(OBJ_WRAPPER)
+	$(LDSO) -o $@ $^ $(DYNAMIC_LIBS)
+
+$(PLUMED_MAIN_STATIC): $(OBJ_MAIN) $(OBJ_KERNEL) $(OBJ_WRAPPER)
+	$(LD) $(LDFLAGS) $^ -o $@ $(LIBS) $(DYNAMIC_LIBS)
+	
+$(PLUMED_MAIN_SHARED): $(OBJ_MAIN) $(PLUMED_SHARED_OBJ)
+	$(LD) $(LDFLAGS) $(OBJ_MAIN) $(realpath $(PLUMED_SHARED_OBJ)) -o $@ $(LIBS)
+
+$(PLUMED_MAIN_RUNTIME): $(OBJ_MAIN) $(OBJ_DYNAMIC_WRAPPER)
+	$(LD) $(LDFLAGS) $^ -o $@ $(LIBS)
+
+Plumed.inc: $(OBJ_KERNEL) $(OBJ_WRAPPER) $(PLUMED_SHARED_OBJ) $(OBJ_DYNAMIC_WRAPPER)
+	@echo Building Plumed.inc
+	@echo "PLUMED_INCLUDE="-I$(realpath ../../include) > $@
+	@echo "PLUMED_RUNTIME_LOAD=" $(realpath $(OBJ_DYNAMIC_WRAPPER)) $(LIBS) $(LDFLAGS) >> $@
+	@echo "PLUMED_STATIC_LOAD=" $(realpath $(OBJ_KERNEL)) $(realpath $(OBJ_WRAPPER)) $(LIBS) $(DYNAMIC_LIBS) $(LDFLAGS) >> $@
+	@echo "PLUMED_SHARED_LOAD=" $(realpath $(PLUMED_SHARED_OBJ)) $(LIBS) $(LDFLAGS) >> $@
+	@echo "PLUMED_RUNTIME_DEPENDENCIES="   >> $@
+	@echo "PLUMED_STATIC_DEPENDENCIES=" $(realpath $(OBJ_KERNEL)) $(realpath $(OBJ_WRAPPER))  >> $@
+	@echo "PLUMED_SHARED_DEPENDENCIES=" $(realpath $(PLUMED_SHARED_OBJ))  >> $@
+
+Plumed.inc.runtime: Plumed.inc
+	@echo Building Plumed.inc, runtime-linking version
+	@echo "# PLUMED: runtime installation" > $@
+	@cat $< >> $@
+	@echo PLUMED_LOAD= '$$(PLUMED_RUNTIME_LOAD)' >> $@
+	@echo PLUMED_DEPENDENCIES= '$$(PLUMED_RUNTIME_DEPENDENCIES)' >> $@
+
+Plumed.inc.static: Plumed.inc
+	@echo Building Plumed.inc, static version
+	@echo "# PLUMED: static installation" > $@
+	@cat $< >> $@
+	@echo PLUMED_LOAD= '$$(PLUMED_STATIC_LOAD)' >> $@
+	@echo PLUMED_DEPENDENCIES= '$$(PLUMED_STATIC_DEPENDENCIES)' >> $@
+
+Plumed.inc.shared: Plumed.inc
+	@echo Building Plumed.inc, shared version
+	@echo "# PLUMED: shared installation" > $@
+	@cat $< >> $@
+	@echo PLUMED_LOAD= '$$(PLUMED_SHARED_LOAD)' >> $@
+	@echo PLUMED_DEPENDENCIES= '$$(PLUMED_SHARED_DEPENDENCIES)' >> $@
+
+# Individual dependencies
+
+-include $(ALL_DEP)
+
+# if machine dependent configuration has not been found:
+else
+
+.PHONY: error
+error:
+	@echo No configuration available
+	@echo First run ./configure.sh in the root directory
+endif
+
+# this target is available anyway
+
+.PHONY: clean
+clean:
+	rm -f $(CLEANLIST)
+	rm -f $(PLUMED_MAIN_STATIC) $(PLUMED_MAIN_SHARED) $(PLUMED_MAIN_RUNTIME)
+	rm -f Plumed.inc*
+
+# generic makefile rules
+include ../maketools/make.rules
+
+
diff --git a/src/main/.gitignore b/src/main/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..8d811aa9a0c5c5a16324eb236372798c63875988
--- /dev/null
+++ b/src/main/.gitignore
@@ -0,0 +1,8 @@
+/*
+# in this directory, only accept source, Makefile and README
+!/.gitignore
+!/*.c
+!/*.cpp
+!/*.h
+!/Makefile
+!/README
diff --git a/src/main/Makefile b/src/main/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..dba875b5ad4e5c9b0d74290af8197612938f21d6
--- /dev/null
+++ b/src/main/Makefile
@@ -0,0 +1,4 @@
+USE=wrapper
+BUILDAFTER=config
+# generic makefile
+include ../maketools/make.module
diff --git a/src/main.cpp b/src/main/main.cpp
similarity index 98%
rename from src/main.cpp
rename to src/main/main.cpp
index f6824cb28131f3f94eb3dcd0fb86376204f6171e..bec8db5cf0c60b9e55db40ddd3406339f3bb097a 100644
--- a/src/main.cpp
+++ b/src/main/main.cpp
@@ -19,7 +19,7 @@
    You should have received a copy of the GNU Lesser General Public License
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
-#include "Plumed.h"
+#include "wrapper/Plumed.h"
 #include <cstring>
 
 #ifdef __PLUMED_MPI
diff --git a/src/maketools/find_modules.sh b/src/maketools/find_modules.sh
new file mode 100755
index 0000000000000000000000000000000000000000..db0938fdaa34c042b386bcf50e94a1109e355854
--- /dev/null
+++ b/src/maketools/find_modules.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+# sort ../basic ../tools $(shell for d in $(MODULES) ; do test -f ../$$d.off || echo ../$$d ; done ; for dir in ../* ; do test -d $$dir && test -e $$dir.on && echo $$dir ; done
+
+cd ../
+for dir in *
+do
+  
+  if test -f $dir/module.type
+  then
+    case "$(cat "$dir/module.type")" in
+    (always) echo $dir ;;
+    (default-on) test -f $dir.off || echo $dir ;;
+    (default-off) test -f $dir.on && echo $dir ;;
+    esac
+  fi
+done
diff --git a/src/maketools/make.common b/src/maketools/make.common
new file mode 100644
index 0000000000000000000000000000000000000000..b2c36de0378bf7fdc2393d76d099e0086c0d6686
--- /dev/null
+++ b/src/maketools/make.common
@@ -0,0 +1 @@
+TMPSUF=*~ *.tmp *.xxd *.o
diff --git a/src/maketools/make.module b/src/maketools/make.module
new file mode 100644
index 0000000000000000000000000000000000000000..e51d8ed48266ad00278472e3bb9efa9fc1321fa5
--- /dev/null
+++ b/src/maketools/make.module
@@ -0,0 +1,58 @@
+#
+# This is a generic makefile which will work for any
+# subpackage which just depends on config/
+# It just compiles objects locally
+# 
+
+# include the machine dependent configuration
+-include ../../Makefile.conf
+
+# if machine dependent configuration has been found:
+ifdef GCCDEP
+
+# source for plumed kernel
+SRC=$(wildcard *.cpp)
+
+# corresponding objects:
+OBJ=$(SRC:.cpp=.o)
+
+# dependency files for all c++ sources
+DEP=$(addprefix deps/,$(SRC:.cpp=.d))
+
+# default target
+.PHONY: all
+
+all:
+	@echo Creating links to other here to simplify .h inclusion:
+	@for dir in $(USE) ; do test -L $$dir || ln -s ../$$dir . && echo "   " $$dir ;  done
+	@echo Building dependencies
+	@for dir in $(BUILDAFTER) ; do echo "   " $$dir ; cd ../$$dir ; $(MAKE) ; cd - ; done
+	$(MAKE) obj
+
+.PHONY: obj
+obj: $(OBJ)
+
+$(DEP): ../config/PlumedConfig.h ../config/Makefile.conf.xxd
+
+-include $(DEP)
+
+# if machine dependent configuration has not been found:
+else
+
+.PHONY: error
+error:
+	@echo No configuration available
+	@echo First run ./configure.sh in the root directory
+endif
+
+# this target is available anyway
+
+.PHONY: clean
+clean:
+	for file in * ; do test -L $$file && rm $$file ; done
+	rm -fr deps
+	rm -f $(CLEANLIST)
+
+# generic makefile rules
+include ../maketools/make.rules
+
diff --git a/src/maketools/make.rules b/src/maketools/make.rules
new file mode 100644
index 0000000000000000000000000000000000000000..bb01ceb2d19fcd9e40705715651a3b79f50a1100
--- /dev/null
+++ b/src/maketools/make.rules
@@ -0,0 +1,26 @@
+# this compiler is used for dependencies generation
+# if unset, use normal CXX
+ifndef CXXDEP
+CXXDEP=$(CXX)
+endif
+
+# rule for c++
+%.o: %.cpp
+	$(CXXDEP) -c -MM -MF$*.d $(CPPFLAGS) $(CXXFLAGS) $*.cpp
+	@cp -f $*.d $*.d.tmp
+	@-test -d deps || mkdir deps
+	@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
+	 sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
+	@mv $*.d deps/$*.d
+	@rm -f $*.d.tmp
+ifndef XLF
+	$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $*.cpp -o $*.o
+endif
+
+# rule for c
+%.o: %.c
+	$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c -o $*.o
+
+#
+CLEANLIST=*~ *.tmp *.xxd *.o *.so *.dylib
+
diff --git a/src/multicolvar/.gitignore b/src/multicolvar/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..4888552338441b5d99a97ec7a2cb2ce448e9e4e6
--- /dev/null
+++ b/src/multicolvar/.gitignore
@@ -0,0 +1,9 @@
+/*
+# in this directory, only accept source, Makefile and README
+!/.gitignore
+!/*.c
+!/*.cpp
+!/*.h
+!/Makefile
+!/README
+!/module.type
diff --git a/src/ActionWithDistribution.cpp b/src/multicolvar/ActionWithDistribution.cpp
similarity index 100%
rename from src/ActionWithDistribution.cpp
rename to src/multicolvar/ActionWithDistribution.cpp
diff --git a/src/ActionWithDistribution.h b/src/multicolvar/ActionWithDistribution.h
similarity index 97%
rename from src/ActionWithDistribution.h
rename to src/multicolvar/ActionWithDistribution.h
index ca6d6a62cc7405b9d1907703a752701ae604b724..687f4039c7ed54d1ece3bf747adecf10660e1e76 100644
--- a/src/ActionWithDistribution.h
+++ b/src/multicolvar/ActionWithDistribution.h
@@ -22,10 +22,10 @@
 #ifndef __PLUMED_ActionWithDistribution_h
 #define __PLUMED_ActionWithDistribution_h
 
-#include "ActionWithValue.h"
-#include "ActionAtomistic.h"
-#include "PlumedException.h"
-#include "DynamicList.h"
+#include "basic/ActionWithValue.h"
+#include "basic/ActionAtomistic.h"
+#include "tools/PlumedException.h"
+#include "tools/DynamicList.h"
 #include <vector>
 
 namespace PLMD{
diff --git a/src/ColvarAlphaRMSD.cpp b/src/multicolvar/ColvarAlphaRMSD.cpp
similarity index 98%
rename from src/ColvarAlphaRMSD.cpp
rename to src/multicolvar/ColvarAlphaRMSD.cpp
index 18a229a971d6a690b64eabf830b8ae7c6628e84e..7403ffb1705d6df43916f62e74126f52eb617335 100644
--- a/src/ColvarAlphaRMSD.cpp
+++ b/src/multicolvar/ColvarAlphaRMSD.cpp
@@ -20,9 +20,9 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "MultiColvarSecondaryStructureRMSD.h"
-#include "ActionRegister.h"
-#include "PlumedMain.h"
-#include "Atoms.h"
+#include "basic/ActionRegister.h"
+#include "basic/PlumedMain.h"
+#include "basic/Atoms.h"
 
 namespace PLMD {
 
diff --git a/src/ColvarAntibetaRMSD.cpp b/src/multicolvar/ColvarAntibetaRMSD.cpp
similarity index 99%
rename from src/ColvarAntibetaRMSD.cpp
rename to src/multicolvar/ColvarAntibetaRMSD.cpp
index 8198b1c1e70375b0b8523fc26f594b5b9c08e629..e8ee481facd904eafec9bfdb30a835fd35120866 100644
--- a/src/ColvarAntibetaRMSD.cpp
+++ b/src/multicolvar/ColvarAntibetaRMSD.cpp
@@ -20,9 +20,9 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "MultiColvarSecondaryStructureRMSD.h"
-#include "ActionRegister.h"
-#include "PlumedMain.h"
-#include "Atoms.h"
+#include "basic/ActionRegister.h"
+#include "basic/PlumedMain.h"
+#include "basic/Atoms.h"
 
 namespace PLMD {
 
diff --git a/src/ColvarParabetaRMSD.cpp b/src/multicolvar/ColvarParabetaRMSD.cpp
similarity index 99%
rename from src/ColvarParabetaRMSD.cpp
rename to src/multicolvar/ColvarParabetaRMSD.cpp
index 109843d42f80a5485fab7e5fd8ce390f8b9331b8..af2dc853ae0c676a4e7dd68b89b5ad33ea0be0d5 100644
--- a/src/ColvarParabetaRMSD.cpp
+++ b/src/multicolvar/ColvarParabetaRMSD.cpp
@@ -20,9 +20,9 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "MultiColvarSecondaryStructureRMSD.h"
-#include "ActionRegister.h"
-#include "PlumedMain.h"
-#include "Atoms.h"
+#include "basic/ActionRegister.h"
+#include "basic/PlumedMain.h"
+#include "basic/Atoms.h"
 
 namespace PLMD {
 
diff --git a/src/FunctionVessel.cpp b/src/multicolvar/FunctionVessel.cpp
similarity index 100%
rename from src/FunctionVessel.cpp
rename to src/multicolvar/FunctionVessel.cpp
diff --git a/src/FunctionVessel.h b/src/multicolvar/FunctionVessel.h
similarity index 100%
rename from src/FunctionVessel.h
rename to src/multicolvar/FunctionVessel.h
diff --git a/src/multicolvar/Makefile b/src/multicolvar/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..ab0b34afd25289a92a0e3070cc461ab483230d0b
--- /dev/null
+++ b/src/multicolvar/Makefile
@@ -0,0 +1,5 @@
+USE=basic tools
+BUILDAFTER=config
+
+# generic makefile
+include ../maketools/make.module
diff --git a/src/MultiColvar.cpp b/src/multicolvar/MultiColvar.cpp
similarity index 99%
rename from src/MultiColvar.cpp
rename to src/multicolvar/MultiColvar.cpp
index 831e67b196b0bd4248cd53e96e9e55dcdd652287..dd95e56af642831fc04e962d664af5d102aefc70 100644
--- a/src/MultiColvar.cpp
+++ b/src/multicolvar/MultiColvar.cpp
@@ -20,11 +20,11 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "MultiColvar.h"
-#include "PlumedMain.h"
-#include "ActionSet.h"
-#include "SetupMolInfo.h"
+#include "basic/PlumedMain.h"
+#include "basic/ActionSet.h"
+#include "basic/SetupMolInfo.h"
 #include "Vessel.h"
-#include "Pbc.h"
+#include "tools/Pbc.h"
 #include <vector>
 #include <string>
 
diff --git a/src/MultiColvar.h b/src/multicolvar/MultiColvar.h
similarity index 99%
rename from src/MultiColvar.h
rename to src/multicolvar/MultiColvar.h
index 76b12a028c31e375dd46fe42314c3e9c1b310640..4fd5887ba1ff7e563d5b2693fbf5cec8eea5447e 100644
--- a/src/MultiColvar.h
+++ b/src/multicolvar/MultiColvar.h
@@ -22,8 +22,8 @@
 #ifndef __PLUMED_MultiColvar_h
 #define __PLUMED_MultiColvar_h
 
-#include "ActionAtomistic.h"
-#include "ActionWithValue.h"
+#include "basic/ActionAtomistic.h"
+#include "basic/ActionWithValue.h"
 #include "ActionWithDistribution.h"
 #include <vector>
 
diff --git a/src/MultiColvarCoordination.cpp b/src/multicolvar/MultiColvarCoordination.cpp
similarity index 98%
rename from src/MultiColvarCoordination.cpp
rename to src/multicolvar/MultiColvarCoordination.cpp
index cbd354ba04499862fd2be24bdcf7a5d7ba94f241..ca5af54e4316660d2b6a8c4a69da5fb52e882fec 100644
--- a/src/MultiColvarCoordination.cpp
+++ b/src/multicolvar/MultiColvarCoordination.cpp
@@ -20,9 +20,9 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "MultiColvar.h"
-#include "NeighborList.h"
-#include "ActionRegister.h"
-#include "SwitchingFunction.h"
+#include "tools/NeighborList.h"
+#include "basic/ActionRegister.h"
+#include "tools/SwitchingFunction.h"
 
 #include <string>
 #include <cmath>
diff --git a/src/MultiColvarDensity.cpp b/src/multicolvar/MultiColvarDensity.cpp
similarity index 98%
rename from src/MultiColvarDensity.cpp
rename to src/multicolvar/MultiColvarDensity.cpp
index ce714c96bb3e8fc3b712ff2e1e272b76eb5a8dfb..1a24e59cdf7634f3a6bf6a5cc2b37d9dcf9fadb0 100644
--- a/src/MultiColvarDensity.cpp
+++ b/src/multicolvar/MultiColvarDensity.cpp
@@ -20,7 +20,7 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "MultiColvar.h"
-#include "ActionRegister.h"
+#include "basic/ActionRegister.h"
 
 #include <string>
 #include <cmath>
diff --git a/src/MultiColvarDistance.cpp b/src/multicolvar/MultiColvarDistance.cpp
similarity index 99%
rename from src/MultiColvarDistance.cpp
rename to src/multicolvar/MultiColvarDistance.cpp
index 16aec846763cb517cc564202db6eeafe45f1c1ed..f9262651f76b8f4391fc232423dfab8b8bd1aa78 100644
--- a/src/MultiColvarDistance.cpp
+++ b/src/multicolvar/MultiColvarDistance.cpp
@@ -20,7 +20,7 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "MultiColvar.h"
-#include "ActionRegister.h"
+#include "basic/ActionRegister.h"
 
 #include <string>
 #include <cmath>
diff --git a/src/MultiColvarSecondaryStructureRMSD.cpp b/src/multicolvar/MultiColvarSecondaryStructureRMSD.cpp
similarity index 98%
rename from src/MultiColvarSecondaryStructureRMSD.cpp
rename to src/multicolvar/MultiColvarSecondaryStructureRMSD.cpp
index 9e6b9fa8d95f9d6035ae1a307e50170cfa61afe3..21322d5948d584d3243cb4ec0b28f66df76b6ade 100644
--- a/src/MultiColvarSecondaryStructureRMSD.cpp
+++ b/src/multicolvar/MultiColvarSecondaryStructureRMSD.cpp
@@ -20,10 +20,10 @@
    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "MultiColvarSecondaryStructureRMSD.h"
-#include "PlumedMain.h"
-#include "Atoms.h"
-#include "RMSD.h"
-#include "DRMSD.h"
+#include "basic/PlumedMain.h"
+#include "basic/Atoms.h"
+#include "tools/RMSD.h"
+#include "tools/DRMSD.h"
 
 namespace PLMD {
 
diff --git a/src/MultiColvarSecondaryStructureRMSD.h b/src/multicolvar/MultiColvarSecondaryStructureRMSD.h
similarity index 100%
rename from src/MultiColvarSecondaryStructureRMSD.h
rename to src/multicolvar/MultiColvarSecondaryStructureRMSD.h
diff --git a/src/Vessel.cpp b/src/multicolvar/Vessel.cpp
similarity index 97%
rename from src/Vessel.cpp
rename to src/multicolvar/Vessel.cpp
index 4f78669d844cb1eb59c19eb7ad4f54acd633b263..eb21b5da1e7fcb100fdbf04405fee3ea537fe10e 100644
--- a/src/Vessel.cpp
+++ b/src/multicolvar/Vessel.cpp
@@ -21,9 +21,9 @@
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "ActionWithDistribution.h"
 #include "Vessel.h"
-#include "PlumedException.h"
-#include "Value.h"
-#include "Log.h"
+#include "tools/PlumedException.h"
+#include "basic/Value.h"
+#include "tools/Log.h"
 
 namespace PLMD {
 
diff --git a/src/Vessel.h b/src/multicolvar/Vessel.h
similarity index 99%
rename from src/Vessel.h
rename to src/multicolvar/Vessel.h
index 3b78746bf349c0db405e246658395759b6f03c58..ce3ecbe2f74db9a38b01c3c23edcc378dc0cf4a9 100644
--- a/src/Vessel.h
+++ b/src/multicolvar/Vessel.h
@@ -25,8 +25,8 @@
 #include <string>
 #include <cstring>
 #include <vector>
-#include "PlumedException.h"
-#include "Keywords.h"
+#include "tools/PlumedException.h"
+#include "tools/Keywords.h"
 
 namespace PLMD{
 
diff --git a/src/VesselCVdens.cpp b/src/multicolvar/VesselCVdens.cpp
similarity index 98%
rename from src/VesselCVdens.cpp
rename to src/multicolvar/VesselCVdens.cpp
index 5bdbbf05e5000cb571d3b92ae5484ae107427e53..dfc1cf0d7ea51b9f86a61f285fc64b79a4089270 100644
--- a/src/VesselCVdens.cpp
+++ b/src/multicolvar/VesselCVdens.cpp
@@ -21,11 +21,11 @@
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 
 #include "FunctionVessel.h"
-#include "PlumedMain.h"
-#include "ActionSet.h"
-#include "ActionVolume.h"
+#include "basic/PlumedMain.h"
+#include "basic/ActionSet.h"
+#include "basic/ActionVolume.h"
 #include "MultiColvar.h"
-#include "HistogramBead.h"
+#include "tools/HistogramBead.h"
 
 namespace PLMD {
 
diff --git a/src/VesselLessThan.cpp b/src/multicolvar/VesselLessThan.cpp
similarity index 98%
rename from src/VesselLessThan.cpp
rename to src/multicolvar/VesselLessThan.cpp
index 056c0a89fa3e79f54d161a729df51ddc7711378e..4dd56cc55380cc127e7862854e3c9a7df76cb5cb 100644
--- a/src/VesselLessThan.cpp
+++ b/src/multicolvar/VesselLessThan.cpp
@@ -21,7 +21,7 @@
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 
 #include "FunctionVessel.h"
-#include "SwitchingFunction.h"
+#include "tools/SwitchingFunction.h"
 #include "ActionWithDistribution.h"
 
 namespace PLMD {
diff --git a/src/VesselMean.cpp b/src/multicolvar/VesselMean.cpp
similarity index 100%
rename from src/VesselMean.cpp
rename to src/multicolvar/VesselMean.cpp
diff --git a/src/VesselMin.cpp b/src/multicolvar/VesselMin.cpp
similarity index 100%
rename from src/VesselMin.cpp
rename to src/multicolvar/VesselMin.cpp
diff --git a/src/VesselMoment.cpp b/src/multicolvar/VesselMoment.cpp
similarity index 100%
rename from src/VesselMoment.cpp
rename to src/multicolvar/VesselMoment.cpp
diff --git a/src/VesselMoreThan.cpp b/src/multicolvar/VesselMoreThan.cpp
similarity index 98%
rename from src/VesselMoreThan.cpp
rename to src/multicolvar/VesselMoreThan.cpp
index c16374894cd9eabb8a8f514d2f56d55757769e0e..4d8863e38d3b9e9345e967db563e108158e79b36 100644
--- a/src/VesselMoreThan.cpp
+++ b/src/multicolvar/VesselMoreThan.cpp
@@ -21,7 +21,7 @@
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 
 #include "FunctionVessel.h"
-#include "SwitchingFunction.h"
+#include "tools/SwitchingFunction.h"
 #include "ActionWithDistribution.h"
 
 namespace PLMD {
diff --git a/src/VesselSum.cpp b/src/multicolvar/VesselSum.cpp
similarity index 100%
rename from src/VesselSum.cpp
rename to src/multicolvar/VesselSum.cpp
diff --git a/src/VesselValueAccess.cpp b/src/multicolvar/VesselValueAccess.cpp
similarity index 100%
rename from src/VesselValueAccess.cpp
rename to src/multicolvar/VesselValueAccess.cpp
diff --git a/src/VesselValueAccess.h b/src/multicolvar/VesselValueAccess.h
similarity index 99%
rename from src/VesselValueAccess.h
rename to src/multicolvar/VesselValueAccess.h
index 88bf00c8d4653f97e4330c2ca79682380c341038..04f0a1feb199c19f54e1fea89b9346b30a4cea26 100644
--- a/src/VesselValueAccess.h
+++ b/src/multicolvar/VesselValueAccess.h
@@ -26,7 +26,7 @@
 #include <cstring>
 #include <vector>
 #include "Vessel.h"
-#include "Value.h"
+#include "basic/Value.h"
 
 namespace PLMD {
 
diff --git a/src/VesselWithin.cpp b/src/multicolvar/VesselWithin.cpp
similarity index 99%
rename from src/VesselWithin.cpp
rename to src/multicolvar/VesselWithin.cpp
index 04a158156f87795b02b4be96286417c3ee35f2a9..35d05a567b8410077b7e47bd3bf08466afd2fd9f 100644
--- a/src/VesselWithin.cpp
+++ b/src/multicolvar/VesselWithin.cpp
@@ -21,7 +21,7 @@
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "FunctionVessel.h"
 #include "MultiColvar.h"
-#include "HistogramBead.h"
+#include "tools/HistogramBead.h"
 
 namespace PLMD {
 
diff --git a/src/multicolvar/module.type b/src/multicolvar/module.type
new file mode 100644
index 0000000000000000000000000000000000000000..fc25731b66113b18d1a475c4aacc51104db7f883
--- /dev/null
+++ b/src/multicolvar/module.type
@@ -0,0 +1 @@
+default-on
diff --git a/src/tools/.gitignore b/src/tools/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..4888552338441b5d99a97ec7a2cb2ce448e9e4e6
--- /dev/null
+++ b/src/tools/.gitignore
@@ -0,0 +1,9 @@
+/*
+# in this directory, only accept source, Makefile and README
+!/.gitignore
+!/*.c
+!/*.cpp
+!/*.h
+!/Makefile
+!/README
+!/module.type
diff --git a/src/AtomNumber.h b/src/tools/AtomNumber.h
similarity index 100%
rename from src/AtomNumber.h
rename to src/tools/AtomNumber.h
diff --git a/src/Citations.cpp b/src/tools/Citations.cpp
similarity index 100%
rename from src/Citations.cpp
rename to src/tools/Citations.cpp
diff --git a/src/Citations.h b/src/tools/Citations.h
similarity index 100%
rename from src/Citations.h
rename to src/tools/Citations.h
diff --git a/src/DLLoader.cpp b/src/tools/DLLoader.cpp
similarity index 100%
rename from src/DLLoader.cpp
rename to src/tools/DLLoader.cpp
diff --git a/src/DLLoader.h b/src/tools/DLLoader.h
similarity index 100%
rename from src/DLLoader.h
rename to src/tools/DLLoader.h
diff --git a/src/DRMSD.cpp b/src/tools/DRMSD.cpp
similarity index 100%
rename from src/DRMSD.cpp
rename to src/tools/DRMSD.cpp
diff --git a/src/DRMSD.h b/src/tools/DRMSD.h
similarity index 100%
rename from src/DRMSD.h
rename to src/tools/DRMSD.h
diff --git a/src/DynamicList.h b/src/tools/DynamicList.h
similarity index 100%
rename from src/DynamicList.h
rename to src/tools/DynamicList.h
diff --git a/src/Grid.cpp b/src/tools/Grid.cpp
similarity index 100%
rename from src/Grid.cpp
rename to src/tools/Grid.cpp
diff --git a/src/Grid.h b/src/tools/Grid.h
similarity index 100%
rename from src/Grid.h
rename to src/tools/Grid.h
diff --git a/src/HistogramBead.cpp b/src/tools/HistogramBead.cpp
similarity index 100%
rename from src/HistogramBead.cpp
rename to src/tools/HistogramBead.cpp
diff --git a/src/HistogramBead.h b/src/tools/HistogramBead.h
similarity index 100%
rename from src/HistogramBead.h
rename to src/tools/HistogramBead.h
diff --git a/src/Kearsley.cpp b/src/tools/Kearsley.cpp
similarity index 100%
rename from src/Kearsley.cpp
rename to src/tools/Kearsley.cpp
diff --git a/src/Kearsley.h b/src/tools/Kearsley.h
similarity index 100%
rename from src/Kearsley.h
rename to src/tools/Kearsley.h
diff --git a/src/Keywords.cpp b/src/tools/Keywords.cpp
similarity index 100%
rename from src/Keywords.cpp
rename to src/tools/Keywords.cpp
diff --git a/src/Keywords.h b/src/tools/Keywords.h
similarity index 100%
rename from src/Keywords.h
rename to src/tools/Keywords.h
diff --git a/src/Log.cpp b/src/tools/Log.cpp
similarity index 100%
rename from src/Log.cpp
rename to src/tools/Log.cpp
diff --git a/src/Log.h b/src/tools/Log.h
similarity index 100%
rename from src/Log.h
rename to src/tools/Log.h
diff --git a/src/tools/Makefile b/src/tools/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..0bd5314da0898eac2a3d9e651c0ab1f02515e3a1
--- /dev/null
+++ b/src/tools/Makefile
@@ -0,0 +1,5 @@
+USE=basic
+BUILDAFTER=config
+
+# generic makefile
+include ../maketools/make.module
diff --git a/src/Matrix.h b/src/tools/Matrix.h
similarity index 100%
rename from src/Matrix.h
rename to src/tools/Matrix.h
diff --git a/src/MatrixSquareBracketsAccess.h b/src/tools/MatrixSquareBracketsAccess.h
similarity index 100%
rename from src/MatrixSquareBracketsAccess.h
rename to src/tools/MatrixSquareBracketsAccess.h
diff --git a/src/NeighborList.cpp b/src/tools/NeighborList.cpp
similarity index 100%
rename from src/NeighborList.cpp
rename to src/tools/NeighborList.cpp
diff --git a/src/NeighborList.h b/src/tools/NeighborList.h
similarity index 100%
rename from src/NeighborList.h
rename to src/tools/NeighborList.h
diff --git a/src/OptimalAlignment.cpp b/src/tools/OptimalAlignment.cpp
similarity index 100%
rename from src/OptimalAlignment.cpp
rename to src/tools/OptimalAlignment.cpp
diff --git a/src/OptimalAlignment.h b/src/tools/OptimalAlignment.h
similarity index 100%
rename from src/OptimalAlignment.h
rename to src/tools/OptimalAlignment.h
diff --git a/src/PDB.cpp b/src/tools/PDB.cpp
similarity index 100%
rename from src/PDB.cpp
rename to src/tools/PDB.cpp
diff --git a/src/PDB.h b/src/tools/PDB.h
similarity index 100%
rename from src/PDB.h
rename to src/tools/PDB.h
diff --git a/src/Pbc.cpp b/src/tools/Pbc.cpp
similarity index 100%
rename from src/Pbc.cpp
rename to src/tools/Pbc.cpp
diff --git a/src/Pbc.h b/src/tools/Pbc.h
similarity index 100%
rename from src/Pbc.h
rename to src/tools/Pbc.h
diff --git a/src/PlumedCommunicator.cpp b/src/tools/PlumedCommunicator.cpp
similarity index 100%
rename from src/PlumedCommunicator.cpp
rename to src/tools/PlumedCommunicator.cpp
diff --git a/src/PlumedCommunicator.h b/src/tools/PlumedCommunicator.h
similarity index 100%
rename from src/PlumedCommunicator.h
rename to src/tools/PlumedCommunicator.h
diff --git a/src/PlumedException.cpp b/src/tools/PlumedException.cpp
similarity index 100%
rename from src/PlumedException.cpp
rename to src/tools/PlumedException.cpp
diff --git a/src/PlumedException.h b/src/tools/PlumedException.h
similarity index 100%
rename from src/PlumedException.h
rename to src/tools/PlumedException.h
diff --git a/src/PlumedFile.cpp b/src/tools/PlumedFile.cpp
similarity index 99%
rename from src/PlumedFile.cpp
rename to src/tools/PlumedFile.cpp
index 360b7cba06071398a04b869d040f367690f9b65a..18db9242066db9e2104a743d47e73cea4a3ed729 100644
--- a/src/PlumedFile.cpp
+++ b/src/tools/PlumedFile.cpp
@@ -21,10 +21,10 @@
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 #include "PlumedFile.h"
 #include "PlumedException.h"
-#include "Action.h"
-#include "PlumedMain.h"
+#include "basic/Action.h"
+#include "basic/PlumedMain.h"
+#include "basic/Value.h"
 #include "PlumedCommunicator.h"
-#include "Value.h"
 #include "Tools.h"
 #include <cstdarg>
 #include <cstring>
diff --git a/src/PlumedFile.h b/src/tools/PlumedFile.h
similarity index 100%
rename from src/PlumedFile.h
rename to src/tools/PlumedFile.h
diff --git a/src/RMSD.cpp b/src/tools/RMSD.cpp
similarity index 100%
rename from src/RMSD.cpp
rename to src/tools/RMSD.cpp
diff --git a/src/RMSD.h b/src/tools/RMSD.h
similarity index 100%
rename from src/RMSD.h
rename to src/tools/RMSD.h
diff --git a/src/Random.cpp b/src/tools/Random.cpp
similarity index 100%
rename from src/Random.cpp
rename to src/tools/Random.cpp
diff --git a/src/Random.h b/src/tools/Random.h
similarity index 100%
rename from src/Random.h
rename to src/tools/Random.h
diff --git a/src/Stopwatch.cpp b/src/tools/Stopwatch.cpp
similarity index 100%
rename from src/Stopwatch.cpp
rename to src/tools/Stopwatch.cpp
diff --git a/src/Stopwatch.h b/src/tools/Stopwatch.h
similarity index 100%
rename from src/Stopwatch.h
rename to src/tools/Stopwatch.h
diff --git a/src/SwitchingFunction.cpp b/src/tools/SwitchingFunction.cpp
similarity index 100%
rename from src/SwitchingFunction.cpp
rename to src/tools/SwitchingFunction.cpp
diff --git a/src/SwitchingFunction.h b/src/tools/SwitchingFunction.h
similarity index 100%
rename from src/SwitchingFunction.h
rename to src/tools/SwitchingFunction.h
diff --git a/src/Tensor.cpp b/src/tools/Tensor.cpp
similarity index 100%
rename from src/Tensor.cpp
rename to src/tools/Tensor.cpp
diff --git a/src/Tensor.h b/src/tools/Tensor.h
similarity index 100%
rename from src/Tensor.h
rename to src/tools/Tensor.h
diff --git a/src/Tools.cpp b/src/tools/Tools.cpp
similarity index 100%
rename from src/Tools.cpp
rename to src/tools/Tools.cpp
diff --git a/src/Tools.h b/src/tools/Tools.h
similarity index 100%
rename from src/Tools.h
rename to src/tools/Tools.h
diff --git a/src/Torsion.cpp b/src/tools/Torsion.cpp
similarity index 100%
rename from src/Torsion.cpp
rename to src/tools/Torsion.cpp
diff --git a/src/Torsion.h b/src/tools/Torsion.h
similarity index 100%
rename from src/Torsion.h
rename to src/tools/Torsion.h
diff --git a/src/Vector.cpp b/src/tools/Vector.cpp
similarity index 100%
rename from src/Vector.cpp
rename to src/tools/Vector.cpp
diff --git a/src/Vector.h b/src/tools/Vector.h
similarity index 100%
rename from src/Vector.h
rename to src/tools/Vector.h
diff --git a/src/tools/module.type b/src/tools/module.type
new file mode 100644
index 0000000000000000000000000000000000000000..0b31619da490b1be9c1616597c37f1034d572b68
--- /dev/null
+++ b/src/tools/module.type
@@ -0,0 +1 @@
+always
diff --git a/src/wrapper/Makefile b/src/wrapper/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..6d1cf8a127b4624246564157bccf457acc828cd3
--- /dev/null
+++ b/src/wrapper/Makefile
@@ -0,0 +1,53 @@
+
+# include the machine dependent configuration
+-include ../../Makefile.conf
+
+# if machine dependent configuration has been found:
+ifdef GCCDEP
+
+# source for plumed wrapper
+SRC_WRAPPER=PlumedStatic.cpp
+
+# source for plumed dynamic wrapper
+SRC_DYNAMIC_WRAPPER=Plumed.c
+
+# all sources
+ALL_SRC=$(SRC_WRAPPER) $(SRC_DYNAMIC_WRAPPER)
+
+# corresponding objects:
+OBJ_WRAPPER=PlumedStatic.o
+OBJ_DYNAMIC_WRAPPER=Plumed.o
+
+# dependency files for all c++ sources
+CPP_SRC=$(wildcard *.cpp)
+ALL_DEP=$(addprefix deps/,$(CPP_SRC:.cpp=.d))
+
+# default target
+.PHONY: all
+all: $(OBJ_WRAPPER) $(OBJ_DYNAMIC_WRAPPER)
+
+# there is a single C file here, and this is its dependency:
+Plumed.o: Plumed.c Plumed.h
+PlumedStatic.o: PlumedStatic.cpp Plumed.c Plumed.h
+
+# Individual dependencies
+
+# if machine dependent configuration has not been found:
+else
+
+.PHONY: error
+error:
+	@echo No configuration available
+	@echo First run ./configure.sh in the root directory
+endif
+
+# this target is available anyway
+
+.PHONY: clean
+clean:
+	rm -fr deps
+	rm -fr $(CLEANLIST)
+
+# generic makefile rules
+include ../maketools/make.rules
+
diff --git a/src/Plumed.c b/src/wrapper/Plumed.c
similarity index 100%
rename from src/Plumed.c
rename to src/wrapper/Plumed.c
diff --git a/src/Plumed.h b/src/wrapper/Plumed.h
similarity index 100%
rename from src/Plumed.h
rename to src/wrapper/Plumed.h
diff --git a/src/PlumedStatic.cpp b/src/wrapper/PlumedStatic.cpp
similarity index 100%
rename from src/PlumedStatic.cpp
rename to src/wrapper/PlumedStatic.cpp
diff --git a/test/link/Makefile b/test/link/Makefile
index 5d51b840d29132d0e5b013d5d8aa73c97cfa08e8..19c1c529df0e81648ad6f1fb0da22a9e58d2876a 100644
--- a/test/link/Makefile
+++ b/test/link/Makefile
@@ -1,6 +1,6 @@
 
 -include ../../Makefile.conf
--include ../../src/Plumed.inc
+-include ../../src/lib/Plumed.inc
 
 EXE=plumed plumedf plumedc \
     plumed-static plumedf-static plumedc-static \
diff --git a/test/link/main.cpp b/test/link/main.cpp
index 836fedfdbd2069bc4ac1888c97a7d857ca6a6f08..ba89a99b861c2335a8588cdac1a5d2621862ec2b 100644
--- a/test/link/main.cpp
+++ b/test/link/main.cpp
@@ -1,4 +1,4 @@
-#include "Plumed.h"
+#include "../../src/wrapper/Plumed.h"
 #include <cstdio>
 
 
diff --git a/test/link/mainc.c b/test/link/mainc.c
index f300789017b29589c60d07d189ffaa68d7d1a79d..7f4718cf9d7aedddee77cb56b6c14853dda04f2a 100644
--- a/test/link/mainc.c
+++ b/test/link/mainc.c
@@ -1,4 +1,4 @@
-#include "Plumed.h"
+#include "../../src/wrapper/Plumed.h"
 #include <stdlib.h>
 
 int main(int argc,char** argv){
diff --git a/test/simplemd/Makefile b/test/simplemd/Makefile
index 88158626387fa4d4846815305b61d9ff4948aa26..4b75c5453a445adacedea8a451822ebdb0fb3a72 100644
--- a/test/simplemd/Makefile
+++ b/test/simplemd/Makefile
@@ -1,6 +1,6 @@
 
 -include ../../Makefile.conf
--include ../../src/Plumed.inc
+-include ../../src/lib/Plumed.inc
 
 SRC=routines.f90 simplemd.f90 ran1.f gasdev.f
 OBJ=routines.o simplemd.o ran1.o gasdev.o
diff --git a/user-doc/extract b/user-doc/extract
index a8549ec38a829c93171fa2caf51d8bad0a66c7ef..99655490fdd8da7ae40d3643039537392e801352 100755
--- a/user-doc/extract
+++ b/user-doc/extract
@@ -4,7 +4,7 @@ mkdir automatic
 
 # Check for files that register actions with no documentation
 rm errors
-for file in ../src/*.cpp
+for file in ../src/*/*.cpp
 do
   nreg=`grep "PLUMED_REGISTER_ACTION" $file | wc -l | awk '{print $1}'`
   if [ $nreg -gt 0 ] ; then
@@ -31,7 +31,7 @@ done
 #done
 
 # Generate all the documentation pages from comments
-cat ../*/*cpp |
+cat ../*/*/*cpp |
 awk 'BEGIN{gfile="automatic/GLOSSARY1.list"}{
   if($1=="//+ENDPLUMEDOC"){
      inside=0;
@@ -82,7 +82,7 @@ for file in automatic/*.tmp
 do
   foundexample=`grep "\par Examples" $file | wc -l | awk '{print $1}'`
   flag=`echo $file | sed -e 's/.tmp//g' | sed -e 's/automatic\///g'`
-  ../src/plumed manual --action=$flag > automatic/$flag.man 2> shit
+  ../src/lib/plumed manual --action=$flag > automatic/$flag.man 2> shit
   rm shit 
   check=`wc -l automatic/$flag.man | awk '{print $1}'`
   if [ $check -eq 0 ] ; then