Index: src/builder.cpp
===================================================================
--- src/builder.cpp	(revision 8cd903035b3501b8a0e39153bb9c28f97d662d5f)
+++ src/builder.cpp	(revision f7f7a4e1d7ef4e1b6442660248ec41c73e743f8f)
@@ -1017,9 +1017,10 @@
       cin >> nr;
       count = 1;
-      for( MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
+      for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
         if (nr == (*ListRunner)->IndexNr) {
           mol = *ListRunner;
           molecules->ListOfMolecules.erase(ListRunner);
           delete(mol);
+          break;
         }
       break;
@@ -1074,5 +1075,20 @@
 
     case 'e':
-      cout << Verbose(0) << "Not implemented yet." << endl;
+      {
+        int src, dest;
+        molecule *srcmol = NULL, *destmol = NULL;
+        do {
+          cout << Verbose(0) << "Enter index of matrix molecule (the variable one): ";
+          cin >> src;
+          srcmol = molecules->ReturnIndex(src);
+        } while ((srcmol == NULL) && (src != -1));
+        do {
+          cout << Verbose(0) << "Enter index of molecule to merge into (the fixed one): ";
+          cin >> dest;
+          destmol = molecules->ReturnIndex(dest);
+        } while ((destmol == NULL) && (dest != -1));
+        if ((src != -1) && (dest != -1))
+          molecules->EmbedMerge(destmol, srcmol);
+      }
       break;
 
@@ -1625,10 +1641,10 @@
                 cout << Verbose(0) << "Evaluating non-convex envelope.";
                 cout << Verbose(1) << "Using rolling ball of radius " << atof(argv[argptr]) << " and storing tecplot data in " << argv[argptr+1] << "." << endl;
-          	start = clock();
+                start = clock();
                 LinkedCell LCList(mol, atof(argv[argptr])*2.);
-                FindNonConvexBorder((ofstream *)&cout, mol, &LCList, argv[argptr+1], atof(argv[argptr]));
+                FindNonConvexBorder((ofstream *)&cout, mol, &LCList, atof(argv[argptr]), argv[argptr+1]);
                 //FindDistributionOfEllipsoids((ofstream *)&cout, &T, &LCList, N, number, filename.c_str());
-          	end = clock();
-          	cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
+                end = clock();
+                cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
                 argptr+=2;
               }
@@ -1653,11 +1669,18 @@
             case 'L':
               ExitFlag = 1;
-              SaveFlag = true;
-              cout << Verbose(1) << "Linear interpolation between configuration " << argv[argptr] << " and " << argv[argptr+1] << "." << endl;
-              if (!mol->LinearInterpolationBetweenConfiguration((ofstream *)&cout, atoi(argv[argptr]), atoi(argv[argptr+1]), argv[argptr+2], configuration))
-                cout << Verbose(2) << "Could not store " << argv[argptr+2] << " files." << endl;
-              else
-                cout << Verbose(2) << "Steps created and " << argv[argptr+2] << " files stored." << endl;
-              argptr+=3;
+              if ((argptr >= argc) || (argv[argptr][0] == '-')) {
+                ExitFlag = 255;
+                cerr << "Not enough or invalid arguments given for storing tempature: -L <step0> <step1> <prefix> <identity mapping?>" << endl;
+              } else {
+                SaveFlag = true;
+                cout << Verbose(1) << "Linear interpolation between configuration " << argv[argptr] << " and " << argv[argptr+1] << "." << endl;
+                if (atoi(argv[argptr+3]) == 1)
+                  cout << Verbose(1) << "Using Identity for the permutation map." << endl;
+                if (!mol->LinearInterpolationBetweenConfiguration((ofstream *)&cout, atoi(argv[argptr]), atoi(argv[argptr+1]), argv[argptr+2], configuration, atoi(argv[argptr+3])) == 1 ? true : false)
+                  cout << Verbose(2) << "Could not store " << argv[argptr+2] << " files." << endl;
+                else
+                  cout << Verbose(2) << "Steps created and " << argv[argptr+2] << " files stored." << endl;
+                argptr+=4;
+              }
               break;
             case 'P':
@@ -1709,5 +1732,5 @@
                 ExitFlag = 1;
                 SaveFlag = true;
-                cout << Verbose(1) << "Translating all ions to new origin." << endl;
+                cout << Verbose(1) << "Translating all ions by given vector." << endl;
                 for (int i=NDIM;i--;)
                   x.x[i] = atof(argv[argptr+i]);
@@ -1715,4 +1738,5 @@
                 argptr+=3;
               }
+              break;
             case 'T':
               ExitFlag = 1;
@@ -1723,5 +1747,5 @@
                 ExitFlag = 1;
                 SaveFlag = true;
-                cout << Verbose(1) << "Translating all ions periodically to new origin." << endl;
+                cout << Verbose(1) << "Translating all ions periodically by given vector." << endl;
                 for (int i=NDIM;i--;)
                   x.x[i] = atof(argv[argptr+i]);
@@ -1864,19 +1888,20 @@
             case 'o':
               ExitFlag = 1;
-              if ((argptr >= argc) || (argv[argptr][0] == '-')){
+              if ((argptr+1 >= argc) || (argv[argptr][0] == '-')){
                 ExitFlag = 255;
-                cerr << "Not enough or invalid arguments given for convex envelope: -o <tecplot output file>" << endl;
+                cerr << "Not enough or invalid arguments given for convex envelope: -o <convex output file> <non-convex output file>" << endl;
               } else {
                 cout << Verbose(0) << "Evaluating volume of the convex envelope.";
-                cout << Verbose(1) << "Storing tecplot data in " << argv[argptr] << "." << endl;
+                cout << Verbose(1) << "Storing tecplot convex data in " << argv[argptr] << "." << endl;
+                cout << Verbose(1) << "Storing tecplot non-convex data in " << argv[argptr+1] << "." << endl;
                 LinkedCell LCList(mol, 10.);
                 //FindConvexBorder((ofstream *)&cout, mol, &LCList, argv[argptr]);
-                FindNonConvexBorder((ofstream *)&cout, mol, &LCList, argv[argptr], 10.);
-                RemoveAllBoundaryPoints((ofstream *)&cout, mol->TesselStruct, mol, argv[argptr]);
-//                double volumedifference = ConvexizeNonconvexEnvelope((ofstream *)&cout, mol->TesselStruct, mol, argv[argptr]);
-//                double clustervolume = VolumeOfConvexEnvelope((ofstream *)&cout, mol->TesselStruct, &configuration);
-//                cout << Verbose(0) << "The tesselated volume area is " << clustervolume << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl;
-//                cout << Verbose(0) << "The non-convex tesselated volume area is " << clustervolume-volumedifference << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl;
-                argptr+=1;
+                FindNonConvexBorder((ofstream *)&cout, mol, &LCList, 5., argv[argptr+1]);
+//                RemoveAllBoundaryPoints((ofstream *)&cout, mol->TesselStruct, mol, argv[argptr]);
+                double volumedifference = ConvexizeNonconvexEnvelope((ofstream *)&cout, mol->TesselStruct, mol, argv[argptr]);
+                double clustervolume = VolumeOfConvexEnvelope((ofstream *)&cout, mol->TesselStruct, &configuration);
+                cout << Verbose(0) << "The tesselated volume area is " << clustervolume << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl;
+                cout << Verbose(0) << "The non-convex tesselated volume area is " << clustervolume-volumedifference << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl;
+                argptr+=2;
               }
               break;
Index: src/moleculelist.cpp
===================================================================
--- src/moleculelist.cpp	(revision 8cd903035b3501b8a0e39153bb9c28f97d662d5f)
+++ src/moleculelist.cpp	(revision f7f7a4e1d7ef4e1b6442660248ec41c73e743f8f)
@@ -5,4 +5,5 @@
  */
 
+#include "boundary.hpp"
 #include "config.hpp"
 #include "molecules.hpp"
@@ -291,20 +292,56 @@
 /** Embedding merge of a given set of molecules into one.
  * Embedding merge inserts one molecule into the other.
- * \param *mol destination molecule
- * \param *srcmol source molecule
- * \return true - merge successful, false - merge failed (probably due to non-existant indices
- * \TODO find embedding center
+ * \param *mol destination molecule (fixed one)
+ * \param *srcmol source molecule (variable one, where atoms are taken from)
+ * \return true - merge successful, false - merge failed (probably due to non-existant indices)
+ * \TODO linked cell dimensions for boundary points has to be as big as inner diameter!
  */
 bool MoleculeListClass::EmbedMerge(molecule *mol, molecule *srcmol)
 {
-  if (srcmol == NULL)
+  if ((srcmol == NULL) || (mol == NULL)) {
+    cout << Verbose(1) << "ERROR: Either fixed or variable molecule is given as NULL." << endl;
     return false;
-
-  // calculate center for merge
-  srcmol->Center.CopyVector(mol->FindEmbeddingHole((ofstream *)&cout, srcmol));
-  srcmol->Center.Zero();
-
-  // perform simple merge
-  SimpleMerge(mol, srcmol);
+  }
+
+  // calculate envelope for *mol
+  LinkedCell *LCList = new LinkedCell(mol, 8.);
+  FindNonConvexBorder((ofstream *)&cout, mol, LCList, 4., NULL);
+  if (mol->TesselStruct == NULL) {
+    cout << Verbose(1) << "ERROR: Could not tesselate the fixed molecule." << endl;
+    return false;
+  }
+  delete(LCList);
+  LCList = new LinkedCell(mol->TesselStruct, 8.);  // re-create with boundary points only!
+
+  // prepare index list for bonds
+  srcmol->CountAtoms((ofstream *)&cout);
+  atom ** CopyAtoms = new atom*[srcmol->AtomCount];
+  for(int i=0;i<srcmol->AtomCount;i++)
+    CopyAtoms[i] = NULL;
+
+  // for each of the source atoms check whether we are in- or outside and add copy atom
+  atom *Walker = srcmol->start;
+  int nr=0;
+  while (Walker->next != srcmol->end) {
+    Walker = Walker->next;
+    cout << Verbose(2) << "INFO: Current Walker is " << *Walker << "." << endl;
+    if (!mol->TesselStruct->IsInnerPoint((ofstream *)&cout, Walker->x, LCList)) {
+      CopyAtoms[Walker->nr] = new atom(Walker);
+      mol->AddAtom(CopyAtoms[Walker->nr]);
+      nr++;
+    } else {
+      // do nothing
+    }
+  }
+  cout << Verbose(1) << nr << " of " << srcmol->AtomCount << " atoms have been merged.";
+
+  // go through all bonds and add as well
+  bond *Binder = srcmol->first;
+  while(Binder->next != srcmol->last) {
+    Binder = Binder->next;
+    cout << Verbose(3) << "Adding Bond between " << *CopyAtoms[Binder->leftatom->nr] << " and " << *CopyAtoms[Binder->rightatom->nr]<< "." << endl;
+    mol->AddBond(CopyAtoms[Binder->leftatom->nr], CopyAtoms[Binder->rightatom->nr], Binder->BondDegree);
+  }
+  delete(LCList);
   return true;
 };
Index: src/molecules.cpp
===================================================================
--- src/molecules.cpp	(revision 8cd903035b3501b8a0e39153bb9c28f97d662d5f)
+++ src/molecules.cpp	(revision f7f7a4e1d7ef4e1b6442660248ec41c73e743f8f)
@@ -662,5 +662,9 @@
 {
   int length = 0;
-  char *molname = strrchr(filename, '/')+sizeof(char);  // search for filename without dirs
+  const char *molname = strrchr(filename, '/');
+  if (molname != NULL)
+    molname += sizeof(char);  // search for filename without dirs
+  else
+    molname = filename; // contains no slashes
   char *endname = strchr(molname, '.');
   if ((endname == NULL) || (endname < molname))
@@ -1562,7 +1566,8 @@
  * \param endstep stating final configuration in molecule::Trajectories
  * \param &config configuration structure
+ * \param MapByIdentity if true we just use the identity to map atoms in start config to end config, if not we find mapping by \sa MinimiseConstrainedPotential()
  * \return true - success in writing step files, false - error writing files or only one step in molecule::Trajectories
  */
-bool molecule::LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration) 
+bool molecule::LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration, bool MapByIdentity)
 {
   molecule *mol = NULL;
@@ -1573,5 +1578,14 @@
   atom **PermutationMap = NULL;
   atom *Walker = NULL, *Sprinter = NULL;
-  MinimiseConstrainedPotential(out, PermutationMap, startstep, endstep, configuration.GetIsAngstroem());
+  if (!MapByIdentity)
+    MinimiseConstrainedPotential(out, PermutationMap, startstep, endstep, configuration.GetIsAngstroem());
+  else {
+    PermutationMap = (atom **) Malloc(AtomCount*sizeof(atom *), "molecule::LinearInterpolationBetweenConfiguration: **PermutationMap");
+    Walker = start;
+    while (Walker->next != end) {
+      Walker = Walker->next;
+      PermutationMap[Walker->nr] = Walker;   // always pick target with the smallest distance
+    }
+  }
 
   // check whether we have sufficient space in Trajectories for each atom
Index: src/molecules.hpp
===================================================================
--- src/molecules.hpp	(revision 8cd903035b3501b8a0e39153bb9c28f97d662d5f)
+++ src/molecules.hpp	(revision f7f7a4e1d7ef4e1b6442660248ec41c73e743f8f)
@@ -182,5 +182,5 @@
   double MinimiseConstrainedPotential(ofstream *out, atom **&permutation, int startstep, int endstep, bool IsAngstroem);
   void EvaluateConstrainedForces(ofstream *out, int startstep, int endstep, atom **PermutationMap, ForceMatrix *Force);
-  bool LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration); 
+  bool LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration, bool MapByIdentity);
 	
   bool CheckBounds(const Vector *x) const;
