Index: src/Actions/MoleculeAction/SaveTemperatureAction.cpp
===================================================================
--- src/Actions/MoleculeAction/SaveTemperatureAction.cpp	(revision 20943bae7a201e8b438123cacbc942e875e959a9)
+++ src/Actions/MoleculeAction/SaveTemperatureAction.cpp	(revision 8009ce8388c713891077297db7c3f7b0aa88b397)
@@ -20,7 +20,10 @@
 #include "CodePatterns/MemDebug.hpp"
 
+#include "atom.hpp"
+#include "AtomSet.hpp"
 #include "CodePatterns/Log.hpp"
+#include "CodePatterns/Verbose.hpp"
+#include "Dynamics/OutputTemperature.hpp"
 #include "molecule.hpp"
-#include "CodePatterns/Verbose.hpp"
 #include "World.hpp"
 
@@ -28,4 +31,5 @@
 #include <fstream>
 #include <string>
+#include <vector>
 
 using namespace std;
@@ -38,20 +42,18 @@
 /** =========== define the function ====================== */
 Action::state_ptr MoleculeSaveTemperatureAction::performCall() {
-  molecule *mol = NULL;
-
   // obtain information
   getParametersfromValueStorage();
 
-  for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
-    mol = iter->second;
-    DoLog(1) && (Log() << Verbose(1) << "Storing temperatures in " << params.temperaturefile << "." << endl);
-    ofstream output;
-    output.open(params.temperaturefile.string().c_str(), ios::trunc);
-    if (output.fail() || !mol->OutputTemperatureFromTrajectories((ofstream * const) &output, 0, mol->MDSteps))
-      DoLog(2) && (Log() << Verbose(2) << "File could not be written." << endl);
-    else
-      DoLog(2) && (Log() << Verbose(2) << "File stored." << endl);
-    output.close();
-  }
+  DoLog(1) && (Log() << Verbose(1) << "Storing temperatures in " << params.temperaturefile << "." << endl);
+  ofstream output;
+  output.open(params.temperaturefile.string().c_str(), ios::trunc);
+  AtomSetMixin<std::vector<atom *> > set(World::getInstance().getSelectedAtoms());
+  const size_t MDSteps = set.getMaxTrajectorySize();
+  OutputTemperature<std::vector<atom *> > writer(set);
+  if (output.fail() || !writer((ofstream * const) &output, 0, MDSteps))
+    DoLog(2) && (Log() << Verbose(2) << "File could not be written." << endl);
+  else
+    DoLog(2) && (Log() << Verbose(2) << "File stored." << endl);
+  output.close();
   return Action::success;
 }
Index: src/Actions/MoleculeAction/SaveTemperatureAction.def
===================================================================
--- src/Actions/MoleculeAction/SaveTemperatureAction.def	(revision 20943bae7a201e8b438123cacbc942e875e959a9)
+++ src/Actions/MoleculeAction/SaveTemperatureAction.def	(revision 8009ce8388c713891077297db7c3f7b0aa88b397)
@@ -31,3 +31,3 @@
 // finally the information stored in the ActionTrait specialization
 #define DESCRIPTION "save the temperature per time step to file"
-#define SHORTFORM "S"
+#undef SHORTFORM
Index: src/AtomSet.hpp
===================================================================
--- src/AtomSet.hpp	(revision 20943bae7a201e8b438123cacbc942e875e959a9)
+++ src/AtomSet.hpp	(revision 8009ce8388c713891077297db7c3f7b0aa88b397)
@@ -72,4 +72,6 @@
   Vector totalMomentumAtStep(unsigned int step) const;
 
+  size_t getMaxTrajectorySize() const;
+
 private:
   template<class Function>
@@ -90,4 +92,22 @@
     T operator+(AtomInfo *atom){
       return value + (atom->*f)();
+    }
+    T operator=(T _value){
+      value = _value;
+      return value;
+    }
+    T (AtomInfo::*f)() const;
+    T value;
+  };
+
+  template<class T>
+  struct valueMax {
+    valueMax(T (AtomInfo::*_f)() const,T startValue) :
+      f(_f),
+      value(startValue)
+    {}
+    T operator+(AtomInfo *atom){
+      const T temp = (atom->*f)();
+      return value < temp ? temp : value;
     }
     T operator=(T _value){
@@ -157,4 +177,12 @@
           class iterator_type,
           class const_iterator_type>
+inline size_t AtomSetMixin<container_type,iterator_type,const_iterator_type>::getMaxTrajectorySize() const
+{
+  return accumulate(this->begin(),this->end(),valueMax<size_t>(&AtomInfo::getTrajectorySize,(size_t)1)).value;
+}
+
+template <class container_type,
+          class iterator_type,
+          class const_iterator_type>
 inline double AtomSetMixin<container_type,iterator_type,const_iterator_type>::totalTemperatureAtStep(unsigned int step) const{
   return accumulate(this->begin(),this->end(),stepValueSum<double>(step,&AtomInfo::getKineticEnergy,0)).value;
Index: src/Dynamics/OutputTemperature.hpp
===================================================================
--- src/Dynamics/OutputTemperature.hpp	(revision 8009ce8388c713891077297db7c3f7b0aa88b397)
+++ src/Dynamics/OutputTemperature.hpp	(revision 8009ce8388c713891077297db7c3f7b0aa88b397)
@@ -0,0 +1,53 @@
+/*
+ * OutputTemperature.hpp
+ *
+ *  Created on: Feb 23, 2011
+ *      Author: heber
+ */
+
+#ifndef OUTPUTTEMPERATURE_HPP_
+#define OUTPUTTEMPERATURE_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+template <class T>
+class OutputTemperature
+{
+public:
+  OutputTemperature(AtomSetMixin<T> &_atoms) :
+    atoms(_atoms)
+  {}
+  ~OutputTemperature()
+  {}
+
+  /** Stores the temperature evaluated from velocities in molecule::Trajectories.
+   * We simply use the formula equivaleting temperature and kinetic energy:
+   * \f$k_B T = \sum_i m_i v_i^2\f$
+   * \param *output output stream of temperature file
+   * \param startstep first MD step in molecule::Trajectories
+   * \param endstep last plus one MD step in molecule::Trajectories
+   * \return file written (true), failure on writing file (false)
+   */
+  bool operator()(ofstream * const output, int startstep, int endstep)
+  {
+    double temperature;
+    // test stream
+    if (output == NULL)
+      return false;
+    else
+      *output << "# Step Temperature [K] Temperature [a.u.]" << endl;
+    for (int step=startstep;step < endstep; step++) { // loop over all time steps
+      temperature = atoms.totalTemperatureAtStep(step);
+      *output << step << "\t" << temperature*AtomicEnergyToKelvin << "\t" << temperature << endl;
+    }
+    return true;
+  };
+
+private:
+  AtomSetMixin<T> atoms;
+};
+
+#endif /* OUTPUTTEMPERATURE_HPP_ */
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 20943bae7a201e8b438123cacbc942e875e959a9)
+++ src/Makefile.am	(revision 8009ce8388c713891077297db7c3f7b0aa88b397)
@@ -124,5 +124,6 @@
 DYNAMICSHEADER = \
 	Dynamics/LinearInterpolationBetweenSteps.hpp \
-	Dynamics/MinimiseConstrainedPotential.hpp
+	Dynamics/MinimiseConstrainedPotential.hpp \
+	Dynamics/OutputTemperature.hpp
 
 GRAPHSOURCE = \
Index: src/molecule.cpp
===================================================================
--- src/molecule.cpp	(revision 20943bae7a201e8b438123cacbc942e875e959a9)
+++ src/molecule.cpp	(revision 8009ce8388c713891077297db7c3f7b0aa88b397)
@@ -1076,26 +1076,4 @@
 };
 
-/** Stores the temperature evaluated from velocities in molecule::Trajectories.
- * We simply use the formula equivaleting temperature and kinetic energy:
- * \f$k_B T = \sum_i m_i v_i^2\f$
- * \param *output output stream of temperature file
- * \param startstep first MD step in molecule::Trajectories
- * \param endstep last plus one MD step in molecule::Trajectories
- * \return file written (true), failure on writing file (false)
- */
-bool molecule::OutputTemperatureFromTrajectories(ofstream * const output, int startstep, int endstep)
-{
-  double temperature;
-  // test stream
-  if (output == NULL)
-    return false;
-  else
-    *output << "# Step Temperature [K] Temperature [a.u.]" << endl;
-  for (int step=startstep;step < endstep; step++) { // loop over all time steps
-    temperature = atoms.totalTemperatureAtStep(step);
-    *output << step << "\t" << temperature*AtomicEnergyToKelvin << "\t" << temperature << endl;
-  }
-  return true;
-};
 
 void molecule::flipActiveFlag(){
Index: src/molecule.hpp
===================================================================
--- src/molecule.hpp	(revision 20943bae7a201e8b438123cacbc942e875e959a9)
+++ src/molecule.hpp	(revision 8009ce8388c713891077297db7c3f7b0aa88b397)
@@ -237,5 +237,4 @@
   bool OutputTrajectoriesXYZ(ofstream * const output);
   bool Checkout(ofstream * const output) const;
-  bool OutputTemperatureFromTrajectories(ofstream * const output, int startstep, int endstep);
 
   // Manipulation routines
Index: tests/regression/Molecules/SaveTemperature/testsuite-molecules-save-temperature.at
===================================================================
--- tests/regression/Molecules/SaveTemperature/testsuite-molecules-save-temperature.at	(revision 20943bae7a201e8b438123cacbc942e875e959a9)
+++ tests/regression/Molecules/SaveTemperature/testsuite-molecules-save-temperature.at	(revision 8009ce8388c713891077297db7c3f7b0aa88b397)
@@ -4,5 +4,5 @@
 AT_KEYWORDS([Molecules])
 AT_CHECK([/bin/cp -f ${abs_top_srcdir}/${AUTOTEST_PATH}/Molecules/SaveTemperature/pre/test.conf .], 0)
-AT_CHECK([../../molecuilder -i test.conf  --select-molecule-by-id 0 -S test.ekin], 0, [stdout], [stderr])
+AT_CHECK([../../molecuilder -i test.conf  --select-all-atoms --save-temperature test.ekin], 0, [stdout], [stderr])
 AT_CHECK([file=test.ekin; diff $file ${abs_top_srcdir}/${AUTOTEST_PATH}/Molecules/SaveTemperature/post/$file], 0, [ignore], [ignore])
 AT_CLEANUP
