Index: src/Actions/MoleculeAction/StretchBondAction.cpp
===================================================================
--- src/Actions/MoleculeAction/StretchBondAction.cpp	(revision 3a51bd61d13a71ec61cf8dd25196d15612bdfe3e)
+++ src/Actions/MoleculeAction/StretchBondAction.cpp	(revision 3a51bd61d13a71ec61cf8dd25196d15612bdfe3e)
@@ -0,0 +1,144 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2012 University of Bonn. 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/>.
+ */
+
+/*
+ * StretchBondAction.cpp
+ *
+ *  Created on: Sep 26, 2012
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include "Actions/MoleculeAction/StretchBondAction.hpp"
+
+#include "CodePatterns/Log.hpp"
+#include "CodePatterns/Verbose.hpp"
+
+#include "LinearAlgebra/Plane.hpp"
+
+#include "Atom/atom.hpp"
+#include "Bond/bond.hpp"
+#include "molecule.hpp"
+#include "World.hpp"
+
+using namespace MoleCuilder;
+
+// and construct the stuff
+#include "StretchBondAction.def"
+#include "Action_impl_pre.hpp"
+/** =========== define the function ====================== */
+Action::state_ptr MoleculeStretchBondAction::performCall()
+{
+  // check preconditions
+  const std::vector< atom *> atoms = World::getInstance().getSelectedAtoms();
+  if (atoms.size() != 2) {
+    ELOG(1, "Exactly two atoms must be selected.");
+    return Action::failure;
+  }
+  const molecule *mol = atoms[0]->getMolecule();
+  if (mol != atoms[1]->getMolecule()) {
+    ELOG(1, "The two selected atoms must belong to the same molecule.");
+    return Action::failure;
+  }
+  // gather undo information
+  const double olddistance = atoms[0]->getPosition().distance(atoms[1]->getPosition());
+  const double newdistance = params.bonddistance.get();
+  LOG(1, "INFO: Old bond distance is " << olddistance << ", stretching to " << newdistance << ".");
+
+  // create the bond plane and mid-distance
+  const Vector NormalVector = (atoms[0]->getPosition() - atoms[1]->getPosition())* (1./olddistance);
+  const Vector OffsetVector = 0.5*(atoms[0]->getPosition() + atoms[1]->getPosition());
+  Plane bondplane(NormalVector, OffsetVector);
+  // go through the molecule and stretch each atom relative two plane
+  const double shift = 0.5*(newdistance - olddistance);
+  const Vector PositiveShift = shift * NormalVector;
+  const Vector NegativeShift = -shift * NormalVector;
+  Box &domain = World::getInstance().getDomain();
+  for (molecule::iterator iter = mol->begin(); iter != mol->end(); ++iter) {
+    const Vector &position = (*iter)->getPosition();
+    // for each atom determine on which side of plane it is and shift accordingly
+    if (bondplane.SignedDistance(position) > 0) {
+      (*iter)->setPosition( domain.enforceBoundaryConditions(position+PositiveShift) );
+    } else {
+      (*iter)->setPosition( domain.enforceBoundaryConditions(position+NegativeShift) );
+    }
+  }
+
+  MoleculeStretchBondState *UndoState = new MoleculeStretchBondState(shift, bondplane, mol, params);
+  return Action::state_ptr(UndoState);
+}
+
+Action::state_ptr MoleculeStretchBondAction::performUndo(Action::state_ptr _state) {
+  MoleculeStretchBondState *state = assert_cast<MoleculeStretchBondState*>(_state.get());
+
+  // use given plane to undo
+  const Vector PositiveShift = state->shift * state->bondplane.getNormal();
+  const Vector NegativeShift = -state->shift * state->bondplane.getNormal();
+  Box &domain = World::getInstance().getDomain();
+  for (molecule::iterator iter = state->mol->begin();
+      iter != state->mol->end(); ++iter) {
+    const Vector &position = (*iter)->getPosition();
+    // for each atom determine on which side of plane it is and shift accordingly
+    if (state->bondplane.SignedDistance(position) < 0) {
+      (*iter)->setPosition( domain.enforceBoundaryConditions(position+PositiveShift) );
+    } else {
+      (*iter)->setPosition( domain.enforceBoundaryConditions(position+NegativeShift) );
+    }
+  }
+
+  return Action::state_ptr(_state);
+}
+
+Action::state_ptr MoleculeStretchBondAction::performRedo(Action::state_ptr _state){
+  MoleculeStretchBondState *state = assert_cast<MoleculeStretchBondState*>(_state.get());
+
+  // use given plane to undo
+  const Vector PositiveShift = state->shift * state->bondplane.getNormal();
+  const Vector NegativeShift = -state->shift * state->bondplane.getNormal();
+  Box &domain = World::getInstance().getDomain();
+  for (molecule::iterator iter = state->mol->begin();
+      iter != state->mol->end(); ++iter) {
+    const Vector &position = (*iter)->getPosition();
+    // for each atom determine on which side of plane it is and shift accordingly
+    if (state->bondplane.SignedDistance(position) > 0) {
+      (*iter)->setPosition( domain.enforceBoundaryConditions(position+PositiveShift) );
+    } else {
+      (*iter)->setPosition( domain.enforceBoundaryConditions(position+NegativeShift) );
+    }
+  }
+  return Action::state_ptr(_state);
+}
+
+bool MoleculeStretchBondAction::canUndo() {
+  return true;
+}
+
+bool MoleculeStretchBondAction::shouldUndo() {
+  return true;
+}
+/** =========== end of function ====================== */
Index: src/Actions/MoleculeAction/StretchBondAction.def
===================================================================
--- src/Actions/MoleculeAction/StretchBondAction.def	(revision 3a51bd61d13a71ec61cf8dd25196d15612bdfe3e)
+++ src/Actions/MoleculeAction/StretchBondAction.def	(revision 3a51bd61d13a71ec61cf8dd25196d15612bdfe3e)
@@ -0,0 +1,36 @@
+/*
+ * StretchBondAction.def
+ *
+ *  Created on: Sep 26, 2012
+ *      Author: heber
+ */
+
+// all includes and forward declarations necessary for non-integral types below
+
+#include "Parameters/Validators/RangeValidator.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 (double)
+#define paramtokens ("stretch-bond")
+#define paramdescriptions ("new bond distance")
+#define paramdefaults (NOPARAM_DEFAULT)
+#define paramreferences (bonddistance)
+#define paramvalids \
+(RangeValidator< double >(0., 10.))
+
+#define statetypes (const double)(const Plane)(const molecule *)
+#define statereferences (shift)(bondplane)(mol)
+
+// some defines for all the names, you may use ACTION, STATE and PARAMS
+#define CATEGORY Molecule
+#define MENUNAME "molecule"
+#define MENUPOSITION 10
+#define ACTIONNAME StretchBond
+#define TOKEN "stretch-bond"
+
+
+// finally the information stored in the ActionTrait specialization
+#define DESCRIPTION "stretch a specific given bond while keeping the rest of the molecule invariant "
+#undef SHORTFORM
Index: src/Actions/MoleculeAction/StretchBondAction.hpp
===================================================================
--- src/Actions/MoleculeAction/StretchBondAction.hpp	(revision 3a51bd61d13a71ec61cf8dd25196d15612bdfe3e)
+++ src/Actions/MoleculeAction/StretchBondAction.hpp	(revision 3a51bd61d13a71ec61cf8dd25196d15612bdfe3e)
@@ -0,0 +1,22 @@
+/*
+ * StretchBondAction.hpp
+ *
+ *  Created on: Sep 26, 2012
+ *      Author: heber
+ */
+
+#ifndef STRETCHBONDACTION_HPP
+#define STRETCHBONDACTION_HPP
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include "Actions/Action.hpp"
+
+#include "StretchBondAction.def"
+#include "Action_impl_header.hpp"
+
+#endif // STRETCHBONDACTION_HPP
