Index: src/Jobs/ChargeSmearer.cpp
===================================================================
--- src/Jobs/ChargeSmearer.cpp	(revision cceb8cfe148cf346613694b5f15bde9f95e63393)
+++ src/Jobs/ChargeSmearer.cpp	(revision cceb8cfe148cf346613694b5f15bde9f95e63393)
@@ -0,0 +1,113 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2015 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/>.
+ */
+
+/*
+ * ChargeSmearer.cpp
+ *
+ *  Created on: Sep 2, 2015
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include "ChargeSmearer.hpp"
+
+#include "CodePatterns/Singleton_impl.hpp"
+
+#include <base/helper.hpp>
+#include <base/index.hpp>
+#include <units/particle/bspline.hpp>
+
+ChargeSmearer::ChargeSmearer() :
+  nfc(0),
+  meshwidth(0.),
+  vals(NULL),
+  int_val(0.)
+{}
+
+ChargeSmearer::~ChargeSmearer()
+{
+  delete[] vals;
+}
+
+void ChargeSmearer::initializeSplineArray(
+    const VMG::Particle::BSpline &_spl,
+    const unsigned int _nfc,
+    const double _meshwidth)
+{
+  // check whether it is changed, if not, do nothing
+  if ((nfc == _nfc) && (meshwidth == _meshwidth))
+    return;
+  nfc = _nfc;
+  meshwidth = _meshwidth;
+
+  // reallocate memory for spline values
+  delete[] vals;
+  double *vals = new double[VMG::Helper::intpow(2*nfc+1,3)];
+
+  // recalculate spline values
+  unsigned int c=0;
+  int_val = 0.;
+  for (double dir_x=-1*nfc*meshwidth; dir_x<=nfc*meshwidth; dir_x+=meshwidth) {
+    for (double dir_y=-1*nfc*meshwidth; dir_y<=nfc*meshwidth; dir_y+=meshwidth) {
+      for (double dir_z=-1*nfc*meshwidth; dir_z<=nfc*meshwidth; dir_z+=meshwidth) {
+
+        // Compute distance from grid point to particle
+        const double distance = std::sqrt(dir_x*dir_x+dir_y*dir_y+dir_z*dir_z);
+        const double temp_val = _spl.EvaluateSpline(distance);
+        vals[c++] = temp_val;
+        int_val += temp_val;
+      }
+    }
+  }
+
+  /// then integrate
+  int_val = 1.0 / (int_val * meshwidth * meshwidth * meshwidth);
+}
+
+void ChargeSmearer::operator()(
+    VMG::Grid& _grid,
+    const VMG::GridIterator &_iter,
+    const double _charge) const
+{
+  /// prepare bounds
+  std::pair<int, int> bounds[3];
+  for (int dim=0;dim<3;++dim) {
+    bounds[dim].first = std::max(_iter.GetBegin()[dim], _iter.GetIndex()[dim] - (int)nfc);
+    bounds[dim].second = std::min(_iter.GetEnd()[dim], _iter.GetIndex()[dim] + (int)nfc);
+  }
+
+  /// then transfer to grid in bounded window
+  unsigned int c = 0;
+  for (int i=bounds[0].first; i<=bounds[0].second; ++i)
+    for (int j=bounds[1].first; j<=bounds[1].second; ++j)
+      for (int k=bounds[2].first; k<=bounds[2].second; ++k)
+        _grid(i,j,k) += vals[c++] * int_val * _charge;
+  assert( c == (unsigned int)VMG::Helper::intpow(2*nfc+1,3) );
+}
+
+CONSTRUCT_SINGLETON(ChargeSmearer)
Index: src/Jobs/ChargeSmearer.hpp
===================================================================
--- src/Jobs/ChargeSmearer.hpp	(revision cceb8cfe148cf346613694b5f15bde9f95e63393)
+++ src/Jobs/ChargeSmearer.hpp	(revision cceb8cfe148cf346613694b5f15bde9f95e63393)
@@ -0,0 +1,125 @@
+/*
+ * ChargeSmearer.hpp
+ *
+ *  Created on: Sep 2, 2015
+ *      Author: heber
+ */
+
+#ifndef CHARGESMEARER_HPP_
+#define CHARGESMEARER_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/Singleton.hpp"
+
+namespace VMG {
+  class Grid;
+  class GridIterator;
+
+  namespace Particle {
+    class BSpline;
+  }
+}
+
+/** This class smears out a given (peak-like) charge value by using a radial
+ * b-spline of compile-defined degree and runtime-defined width ("near field
+ * cells").
+ *
+ * This is used to smear out the electronic charge distribution in the same
+ * way as is done with the (point-like) nuclei charge distribution to increase
+ * accuracy for the long-range calculations.
+ *
+ * The trick relies on two distant and non-overlapping charge distributions
+ * behave actually as two point charges and vice versa. Core electron charge
+ * distributions are strongly peaked and hence almost appear like the point-like
+ * nuclei charge distributions. Hence, we perform the same trick as is done
+ * with the nuclei. The charges are smeared out to such a degree that charge
+ * distributions do not overlap except within a single fragment. Within
+ * fragments the short-range Coulomb energy and forces is calculated accurately.
+ * In between fragments the long-range calculations via vmg is used and hence
+ * charges there may not overlap. The maximum distance allowed and hence the
+ * maximum near field cells can be obtained from the Interfragmenter class.
+ *
+ * This class is a singleton as we only need to precalculate the spline values
+ * for a given nfc once and then may use of all FragmentJobs.
+ *
+ * The code here is taken from vmg's units/particles/bspline.cpp::SetSpline().
+ */
+class ChargeSmearer : public Singleton<ChargeSmearer>
+{
+  friend class Singleton<ChargeSmearer>;
+
+private:
+  /** Private cstor for ChargeSmearer.
+   *
+   * Must be private as is singleton.
+   *
+   */
+  ChargeSmearer();
+
+  /** Dstor for ChargeSmearer.
+   *
+   */
+  ~ChargeSmearer();
+
+public:
+  /** Setter for the values defining the grid and the spline extent.
+   *
+   * This function recalculates the spline values but only if the
+   * values have changed with respect to the old ones.
+   *
+   * \param _spl spline to evaluate
+   * \param _nfc near field cells
+   * \param _meshwdith mesh spacing
+   */
+  void initializeSplineArray(
+      const VMG::Particle::BSpline &_spl,
+      const unsigned int _nfc,
+      const double _meshwidth);
+
+  /** Getter for the width of the smearing area, i.e. number of near field
+   * cells.
+   *
+   * \return number of near field cells, i.e. 2nfc+1 equals width of array
+   */
+  unsigned int getNearFielCells() const
+  { return nfc; }
+
+  /** Getter for the meshwidth.
+   *
+   * \return meshwidth
+   */
+  unsigned int getMeshwidth() const
+  { return meshwidth; }
+
+  /** Smears out the given charge \a _value with the current \a nfc and bspline
+   * on the \a _grid.
+   *
+   * \param _grid grid to smear out charge on
+   * \param _iter central node on grid where to add smearing
+   * \param _charge charge to smear out
+   */
+  void operator()(
+      VMG::Grid& _grid,
+      const VMG::GridIterator &_iter,
+      const double _charge) const;
+
+private:
+  //!> near field radius for bspline
+  unsigned int nfc;
+
+  //!> mesh width of the grid
+  double meshwidth;
+
+  //!> contains the array of pre-compiled spline values
+  double *vals;
+
+  //!> integrated value of spline array for normalization
+  double int_val;
+};
+
+
+#endif /* CHARGESMEARER_HPP_ */
Index: src/Jobs/Makefile.am
===================================================================
--- src/Jobs/Makefile.am	(revision 7537d191a569f0b72f4ef6db9b9ae70d575a463f)
+++ src/Jobs/Makefile.am	(revision cceb8cfe148cf346613694b5f15bde9f95e63393)
@@ -17,4 +17,5 @@
 if CONDVMG
 JOBSSOURCE += \
+	Jobs/ChargeSmearer.cpp \
 	Jobs/InterfaceVMGDebugGridJob.cpp \
 	Jobs/InterfaceVMGJob.cpp \
@@ -43,4 +44,5 @@
 if CONDVMG
 JOBSHEADER += \
+	Jobs/ChargeSmearer.hpp \
 	Jobs/InterfaceVMGDebugGridJob.hpp \
 	Jobs/InterfaceVMGJob.hpp \
