Index: src/Actions/AtomAction/RemoveAction.def
===================================================================
--- src/Actions/AtomAction/RemoveAction.def	(revision 1e45f1fb84ae30e44c393f19156012e19f962ac3)
+++ src/Actions/AtomAction/RemoveAction.def	(revision 1a48d2c8c2b6ea08ac53c8fc5998d19145e4eeb8)
@@ -7,7 +7,4 @@
 
 // all includes and forward declarations necessary for non-integral types below
-
-
-#include "Parameters/Validators/DummyValidator.hpp"
 
 // i.e. there is an integer with variable name Z that can be found in
Index: src/Actions/GlobalListOfActions.hpp
===================================================================
--- src/Actions/GlobalListOfActions.hpp	(revision 1e45f1fb84ae30e44c393f19156012e19f962ac3)
+++ src/Actions/GlobalListOfActions.hpp	(revision 1a48d2c8c2b6ea08ac53c8fc5998d19145e4eeb8)
@@ -69,4 +69,5 @@
   (MoleculeFillWithMolecule) \
   (MoleculeFillVoidWithMolecule) \
+  (MoleculeForceAnnealing) \
   (MoleculeLinearInterpolationofTrajectories) \
   (MoleculeLoad) \
Index: src/Actions/Makefile.am
===================================================================
--- src/Actions/Makefile.am	(revision 1e45f1fb84ae30e44c393f19156012e19f962ac3)
+++ src/Actions/Makefile.am	(revision 1a48d2c8c2b6ea08ac53c8fc5998d19145e4eeb8)
@@ -278,4 +278,5 @@
   Actions/MoleculeAction/FillWithMoleculeAction.cpp \
   Actions/MoleculeAction/FillVoidWithMoleculeAction.cpp \
+  Actions/MoleculeAction/ForceAnnealingAction.cpp \
   Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.cpp \
   Actions/MoleculeAction/LoadAction.cpp \
@@ -296,4 +297,5 @@
   Actions/MoleculeAction/FillWithMoleculeAction.hpp \
   Actions/MoleculeAction/FillVoidWithMoleculeAction.hpp \
+  Actions/MoleculeAction/ForceAnnealingAction.hpp \
   Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.hpp \
   Actions/MoleculeAction/LoadAction.hpp \
@@ -314,4 +316,5 @@
   Actions/MoleculeAction/FillWithMoleculeAction.def \
   Actions/MoleculeAction/FillVoidWithMoleculeAction.def \
+  Actions/MoleculeAction/ForceAnnealingAction.def \
   Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.def \
   Actions/MoleculeAction/LoadAction.def \
Index: src/Actions/MoleculeAction/ForceAnnealingAction.cpp
===================================================================
--- src/Actions/MoleculeAction/ForceAnnealingAction.cpp	(revision 1a48d2c8c2b6ea08ac53c8fc5998d19145e4eeb8)
+++ src/Actions/MoleculeAction/ForceAnnealingAction.cpp	(revision 1a48d2c8c2b6ea08ac53c8fc5998d19145e4eeb8)
@@ -0,0 +1,166 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2014 Frederik Heber. All rights reserved.
+ * 
+ *
+ *   This file is part of MoleCuilder.
+ *
+ *    MoleCuilder is free software: you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation, either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    MoleCuilder is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * ForceAnnealingAction.cpp
+ *
+ *  Created on: Aug 02, 2014
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include "Actions/UndoRedoHelpers.hpp"
+#include "Atom/atom.hpp"
+#include "Atom/AtomicInfo.hpp"
+#include "Atom/AtomSet.hpp"
+#include "CodePatterns/Log.hpp"
+#include "CodePatterns/Verbose.hpp"
+#include "Dynamics/ForceAnnealing.hpp"
+#include "molecule.hpp"
+#include "World.hpp"
+#include "WorldTime.hpp"
+
+#include <vector>
+#include <iostream>
+#include <fstream>
+#include <string>
+
+#include "Actions/MoleculeAction/ForceAnnealingAction.hpp"
+
+using namespace MoleCuilder;
+
+enum VectorIndexType {
+  PositionIndex=0,
+  VelocityIndex=1,
+  ForceIndex=2
+};
+
+// and construct the stuff
+#include "ForceAnnealingAction.def"
+#include "Action_impl_pre.hpp"
+/** =========== define the function ====================== */
+ActionState::ptr MoleculeForceAnnealingAction::performCall() {
+  AtomSetMixin<std::vector<atom *> > set(World::getInstance().getSelectedAtoms());
+  if (set.empty()) {
+    STATUS("No atoms selected.");
+    return Action::failure;
+  }
+  // we always operate relative to current time step, except on single debug output
+  size_t CurrentStep = WorldTime::getInstance().getTime();
+  if (params.DoOutput.get()) {
+    // copy current time step to new one and and proceed on this one
+    for (World::AtomSelectionIterator iter = World::getInstance().beginAtomSelection();
+        iter != World::getInstance().endAtomSelection();
+        ++iter) {
+      atom * const Walker = iter->second;
+      Walker->UpdateSteps();
+      Walker->setPositionAtStep(CurrentStep+1,
+          Walker->getPositionAtStep(CurrentStep));
+      Walker->setAtomicVelocityAtStep(CurrentStep+1,
+          Walker->getAtomicVelocityAtStep(CurrentStep));
+      Walker->setAtomicForceAtStep(CurrentStep+1,
+          Walker->getAtomicForceAtStep(CurrentStep));
+    }
+    // increment to next time step: re-creates bond graph
+    ++CurrentStep;
+    World::getInstance().setTime(CurrentStep);
+  }
+  ForceAnnealing<std::vector<atom *> > optimizer(
+      set,
+      params.Deltat.get(),
+      true,
+      params.steps.get());
+  // parse forces into next step
+  if (!params.forcesfile.get().string().empty()) {
+    LOG(1, "Parsing forces file.");
+    if (!optimizer.parseForcesFile(params.forcesfile.get().string().c_str(), CurrentStep))
+      LOG(2, "File " << params.forcesfile.get() << " not found.");
+    else
+      LOG(2, "File " << params.forcesfile.get() << " found and parsed.");
+  }
+
+  // create undo state for all selected atoms (undo info)
+  std::vector<AtomicInfo> UndoInfo;
+  UndoInfo.reserve(set.size());
+  {
+    for (World::AtomSelectionConstIterator iter = World::getInstance().beginAtomSelection();
+        iter != World::getInstance().endAtomSelection();
+        ++iter)
+      UndoInfo.push_back(AtomicInfo(*(iter->second)));
+  }
+
+  // perform optimization step
+  LOG(1, "Structural optimization.");
+  optimizer(CurrentStep, 1);
+  STATUS("Successfully optimized structure by one step.");
+
+//  // increment to next time step
+//  World::getInstance().setTime(CurrentStep+1);
+
+  std::vector<AtomicInfo> RedoInfo;
+  RedoInfo.reserve(set.size());
+  {
+    for (World::AtomSelectionConstIterator iter = World::getInstance().beginAtomSelection();
+        iter != World::getInstance().endAtomSelection();
+        ++iter)
+      RedoInfo.push_back(AtomicInfo(*(iter->second)));
+  }
+  MoleculeForceAnnealingState *UndoState =
+    new MoleculeForceAnnealingState(UndoInfo, RedoInfo, params);
+
+  return ActionState::ptr(UndoState);
+}
+
+ActionState::ptr MoleculeForceAnnealingAction::performUndo(ActionState::ptr _state) {
+  MoleculeForceAnnealingState *state =
+      assert_cast<MoleculeForceAnnealingState*>(_state.get());
+
+  // set stored old state
+  SetAtomsFromAtomicInfo(state->UndoInfo);
+
+  return ActionState::ptr(_state);
+}
+
+ActionState::ptr MoleculeForceAnnealingAction::performRedo(ActionState::ptr _state){
+  MoleculeForceAnnealingState *state =
+      assert_cast<MoleculeForceAnnealingState*>(_state.get());
+
+  // set stored new state
+  SetAtomsFromAtomicInfo(state->RedoInfo);
+
+  return ActionState::ptr(_state);
+}
+
+bool MoleculeForceAnnealingAction::canUndo() {
+  return true;
+}
+
+bool MoleculeForceAnnealingAction::shouldUndo() {
+  return true;
+}
+/** =========== end of function ====================== */
Index: src/Actions/MoleculeAction/ForceAnnealingAction.def
===================================================================
--- src/Actions/MoleculeAction/ForceAnnealingAction.def	(revision 1a48d2c8c2b6ea08ac53c8fc5998d19145e4eeb8)
+++ src/Actions/MoleculeAction/ForceAnnealingAction.def	(revision 1a48d2c8c2b6ea08ac53c8fc5998d19145e4eeb8)
@@ -0,0 +1,40 @@
+/*
+ * ForceAnnealingAction.def
+ *
+ *  Created on: Aug 02, 2014
+ *      Author: heber
+ */
+
+// all includes and forward declarations necessary for non-integral types below
+#include "Parameters/Validators/DummyValidator.hpp"
+#include "Parameters/Validators/GenericValidators.hpp"
+#include "Parameters/Validators/Ops_Validator.hpp"
+#include "Parameters/Validators/Specific/FilePresentValidator.hpp"
+
+// i.e. there is an integer with variable name Z that can be found in
+// ValueStorage by the token "Z" -> first column: int, Z, "Z"
+// "undefine" if no parameters are required, use (NOPARAM_DEFAULT) for each (undefined) default value
+#define paramtypes (boost::filesystem::path)(double)(unsigned int)(bool)
+#define paramtokens ("forces-file")("deltat")("steps")("output-every-step")
+#define paramdescriptions ("file containing")("time step width")("fixed number of optimization steps to be performed")("whether WorldTime should be increased and output written after every step, useful if optimization might hang")
+#define paramdefaults (PARAM_DEFAULT(""))(PARAM_DEFAULT(0.1))(NOPARAM_DEFAULT)(PARAM_DEFAULT("0"))
+#define paramreferences (forcesfile)(Deltat)(steps)(DoOutput)
+#define paramvalids \
+(DummyValidator< boost::filesystem::path >()) \
+(PositiveValidator< double >()) \
+(NotZeroValidator< unsigned int >()) \
+(DummyValidator<bool>())
+
+#define statetypes (std::vector<AtomicInfo>)(std::vector<AtomicInfo>)
+#define statereferences (UndoInfo)(RedoInfo)
+
+// some defines for all the names, you may use ACTION, STATE and PARAMS
+#define CATEGORY Molecule
+#define MENUNAME "molecule"
+#define MENUPOSITION 12
+#define ACTIONNAME ForceAnnealing
+#define TOKEN "force-annealing"
+
+// finally the information stored in the ActionTrait specialization
+#define DESCRIPTION "perform a single step optimizing the current forces acting on the atoms"
+#undef SHORTFORM
Index: src/Actions/MoleculeAction/ForceAnnealingAction.hpp
===================================================================
--- src/Actions/MoleculeAction/ForceAnnealingAction.hpp	(revision 1a48d2c8c2b6ea08ac53c8fc5998d19145e4eeb8)
+++ src/Actions/MoleculeAction/ForceAnnealingAction.hpp	(revision 1a48d2c8c2b6ea08ac53c8fc5998d19145e4eeb8)
@@ -0,0 +1,22 @@
+/*
+ * ForceAnnealingAction.hpp
+ *
+ *  Created on: Aug 02, 2014
+ *      Author: heber
+ */
+
+#ifndef FORCEANNEALINGACTION_HPP
+#define FORCEANNEALINGACTION_HPP
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include "Actions/Action.hpp"
+
+#include "ForceAnnealingAction.def"
+#include "Action_impl_header.hpp"
+
+#endif // FORCEANNEALINGACTION_HPP
Index: src/Actions/MoleculeAction/VerletIntegrationAction.cpp
===================================================================
--- src/Actions/MoleculeAction/VerletIntegrationAction.cpp	(revision 1e45f1fb84ae30e44c393f19156012e19f962ac3)
+++ src/Actions/MoleculeAction/VerletIntegrationAction.cpp	(revision 1a48d2c8c2b6ea08ac53c8fc5998d19145e4eeb8)
@@ -98,5 +98,5 @@
   Verlet(CurrentStep+1, 1, 0, params.FixedCenterOfMass.get());
   LOG(0, "STATUS: Successfully performed updates on velocity and position.");
-  // increment to next time step
+  // increment to next time step: re-creates bond graph
   World::getInstance().setTime(CurrentStep+1);
 
Index: src/Dynamics/ForceAnnealing.hpp
===================================================================
--- src/Dynamics/ForceAnnealing.hpp	(revision 1a48d2c8c2b6ea08ac53c8fc5998d19145e4eeb8)
+++ src/Dynamics/ForceAnnealing.hpp	(revision 1a48d2c8c2b6ea08ac53c8fc5998d19145e4eeb8)
@@ -0,0 +1,150 @@
+/*
+ * ForceAnnealing.hpp
+ *
+ *  Created on: Aug 02, 2014
+ *      Author: heber
+ */
+
+#ifndef FORCEANNEALING_HPP_
+#define FORCEANNEALING_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "Atom/atom.hpp"
+#include "Atom/AtomSet.hpp"
+#include "CodePatterns/Assert.hpp"
+#include "CodePatterns/Info.hpp"
+#include "CodePatterns/Log.hpp"
+#include "CodePatterns/Verbose.hpp"
+#include "Dynamics/AtomicForceManipulator.hpp"
+#include "Fragmentation/ForceMatrix.hpp"
+#include "Helpers/helpers.hpp"
+#include "Helpers/defs.hpp"
+#include "LinearAlgebra/Vector.hpp"
+#include "Thermostats/ThermoStatContainer.hpp"
+#include "Thermostats/Thermostat.hpp"
+#include "World.hpp"
+
+/** This class is the essential build block for performing structual optimization.
+ *
+ * Sadly, we have to use some static instances as so far values cannot be passed
+ * between actions. Hence, we need to store the current step and the adaptive
+ * step width (we cannot perform a linesearch, as we have no control over the
+ * calculation of the forces).
+ */
+template <class T>
+class ForceAnnealing : public AtomicForceManipulator<T>
+{
+public:
+  /** Constructor of class ForceAnnealing.
+   *
+   * \param _atoms set of atoms to integrate
+   * \param _Deltat time step width in atomic units
+   * \param _IsAngstroem whether length units are in angstroem or bohr radii
+   * \param _maxSteps number of optimization steps to perform
+   */
+  ForceAnnealing(
+      AtomSetMixin<T> &_atoms,
+      double _Deltat,
+      bool _IsAngstroem,
+      const size_t _maxSteps) :
+    AtomicForceManipulator<T>(_atoms, _Deltat, _IsAngstroem),
+    maxSteps(_maxSteps)
+  {}
+  /** Destructor of class ForceAnnealing.
+   *
+   */
+  ~ForceAnnealing()
+  {}
+
+  /** Performs Gradient optimization.
+   *
+   * We assume that forces have just been calculated.
+   *
+   *
+   * \param NextStep current time step (i.e. \f$ t + \Delta t \f$ in the sense of the velocity verlet)
+   * \param offset offset in matrix file to the first force component
+   * \todo This is not yet checked if it is correctly working with DoConstrainedMD set >0.
+   */
+  void operator()(const int NextStep, const size_t offset)
+  {
+    // make sum of forces equal zero
+    AtomicForceManipulator<T>::correctForceMatrixForFixedCenterOfMass(offset,NextStep);
+
+    // are we in initial step? Then set static entities
+    if (currentStep == 0) {
+      currentDeltat = AtomicForceManipulator<T>::Deltat;
+      currentStep = 1;
+      LOG(2, "DEBUG: Initial step, setting values, current step is #" << currentStep);
+    } else {
+      ++currentStep;
+      LOG(2, "DEBUG: current step is #" << currentStep);
+    }
+
+    // are we in initial step? Then don't check against velocity
+    for(typename AtomSetMixin<T>::iterator iter = AtomicForceManipulator<T>::atoms.begin();
+        iter != AtomicForceManipulator<T>::atoms.end(); ++iter) {
+      // atom's force vector gives steepest descent direction
+      const Vector currentPosition = (*iter)->getPosition();
+      const Vector currentGradient = (*iter)->getAtomicForce();
+      LOG(4, "DEBUG: Force for atom " << **iter << " is " << currentGradient);
+      Vector PositionUpdate = currentDeltat * currentGradient;
+      LOG(3, "DEBUG: Update would be " << PositionUpdate);
+
+      // update with currentDelta tells us how the current gradient relates to
+      // the last one: If it has become larger, reduce currentDelta
+      if ((currentStep > 1) && (!(*iter)->getAtomicVelocity().IsZero()))
+        if ((PositionUpdate.ScalarProduct((*iter)->getAtomicVelocity()) < 0)
+            && (currentDeltat > MinimumDeltat)) {
+          currentDeltat = .5*currentDeltat;
+          LOG(2, "DEBUG: Upgrade in other direction: " << PositionUpdate.NormSquared()
+              << " > " << (*iter)->getAtomicVelocity().NormSquared()
+              << ", decreasing deltat: " << currentDeltat);
+          PositionUpdate = currentDeltat * currentGradient;
+        }
+
+      // finally set new values
+      (*iter)->setPosition(currentPosition + PositionUpdate);
+      (*iter)->setAtomicVelocity(PositionUpdate);
+      //std::cout << "Id of atom is " << (*iter)->getId() << std::endl;
+//        (*iter)->VelocityVerletUpdateU((*iter)->getId(), NextStep-1, Deltat, IsAngstroem);
+
+      // reset force vector for next step except on final one
+      if (currentStep != maxSteps)
+        (*iter)->setAtomicForce(zeroVec);
+    }
+
+    // are we in final step? Remember to reset static entities
+    if (currentStep == maxSteps) {
+      LOG(2, "DEBUG: Final step, resetting values");
+      currentDeltat = 0.;
+      currentStep = 0;
+
+      // reset (artifical) velocities
+      for(typename AtomSetMixin<T>::iterator iter = AtomicForceManipulator<T>::atoms.begin();
+          iter != AtomicForceManipulator<T>::atoms.end(); ++iter)
+        (*iter)->setAtomicVelocity(zeroVec);
+    }
+  }
+
+private:
+  //!> contains the current step in relation to maxsteps
+  static size_t currentStep;
+  //!> contains the maximum number of steps, determines initial and final step with currentStep
+  size_t maxSteps;
+  static double currentDeltat;
+  //!> minimum deltat for internal while loop (adaptive step width)
+  static double MinimumDeltat;
+};
+
+template <class T>
+double ForceAnnealing<T>::currentDeltat = 0.;
+template <class T>
+size_t ForceAnnealing<T>::currentStep = 0;
+template <class T>
+double ForceAnnealing<T>::MinimumDeltat = 1e-8;
+
+#endif /* FORCEANNEALING_HPP_ */
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 1e45f1fb84ae30e44c393f19156012e19f962ac3)
+++ src/Makefile.am	(revision 1a48d2c8c2b6ea08ac53c8fc5998d19145e4eeb8)
@@ -123,4 +123,5 @@
 DYNAMICSHEADER = \
 	Dynamics/AtomicForceManipulator.hpp \
+	Dynamics/ForceAnnealing.hpp \
 	Dynamics/LinearInterpolationBetweenSteps.hpp \
 	Dynamics/MinimiseConstrainedPotential.hpp \
