Index: src/builder.cpp
===================================================================
--- src/builder.cpp	(revision d671506779336470085bef0cdbe37dd74c5aaecd)
+++ src/builder.cpp	(revision 63f06e549b4f5a9f18fc5ce0a5d858955003e9c4)
@@ -282,9 +282,9 @@
 		case 'a':
 			cout << Verbose(0) << "Centering atoms in config file on origin." << endl;
-			mol->CenterOrigin((ofstream *)&cout, &x);
+			mol->CenterOrigin((ofstream *)&cout);
 			break;
 		case 'b':
 			cout << Verbose(0) << "Centering atoms in config file on center of gravity." << endl;
-			mol->CenterGravity((ofstream *)&cout, &x);
+			mol->CenterPeriodic((ofstream *)&cout);
 			break;
 		case 'c':
@@ -295,5 +295,5 @@
 			}
 			mol->CenterEdge((ofstream *)&cout, &x);	// make every coordinate positive
-			mol->Translate(&y); // translate by boundary
+			mol->Center.AddVector(&y); // translate by boundary
 			helper.CopyVector(&y);
 			helper.Scale(2.);
@@ -646,5 +646,5 @@
   cout << Verbose(0) << "all else - go back" << endl;
   cout << Verbose(0) << "===============================================" << endl;
-  if (molecules->NumberOfActiveMolecules() > 0)
+  if (molecules->NumberOfActiveMolecules() > 1)
     cout << Verbose(0) << "WARNING: There is more than one molecule active! Atoms will be added to each." << endl;
   cout << Verbose(0) << "INPUT: ";
@@ -657,5 +657,6 @@
 
     case 'a': // add atom
-      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 ((*ListRunner)->ActiveFlag) {
         mol = *ListRunner;
         cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
@@ -665,5 +666,6 @@
 
     case 'b': // scale a bond
-      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 ((*ListRunner)->ActiveFlag) {
         mol = *ListRunner;
         cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
@@ -687,5 +689,6 @@
 
     case 'c': // unit scaling of the metric
-      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 ((*ListRunner)->ActiveFlag) {
         mol = *ListRunner;
         cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
@@ -703,5 +706,6 @@
 
     case 'l': // measure distances or angles
-      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 ((*ListRunner)->ActiveFlag) {
         mol = *ListRunner;
         cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
@@ -711,5 +715,6 @@
 
     case 'r': // remove atom
-      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 ((*ListRunner)->ActiveFlag) {
         mol = *ListRunner;
         cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
@@ -719,5 +724,6 @@
 
     case 'u': // change an atom's element
-      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 ((*ListRunner)->ActiveFlag) {
         int Z;
         mol = *ListRunner;
@@ -766,5 +772,5 @@
   cout << Verbose(0) << "all else - go back" << endl;
   cout << Verbose(0) << "===============================================" << endl;
-  if (molecules->NumberOfActiveMolecules() > 0)
+  if (molecules->NumberOfActiveMolecules() > 1)
     cout << Verbose(0) << "WARNING: There is more than one molecule active! Atoms will be added to each." << endl;
   cout << Verbose(0) << "INPUT: ";
@@ -777,5 +783,6 @@
 
     case 'd': // duplicate the periodic cell along a given axis, given times
-      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 ((*ListRunner)->ActiveFlag) {
         mol = *ListRunner;
         cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
@@ -835,5 +842,6 @@
 
     case 'g': // center the atoms
-      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 ((*ListRunner)->ActiveFlag) {
         mol = *ListRunner;
         cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
@@ -843,5 +851,6 @@
 
     case 'i': // align all atoms
-      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 ((*ListRunner)->ActiveFlag) {
         mol = *ListRunner;
         cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
@@ -851,5 +860,6 @@
 
     case 'm': // mirror atoms along a given axis
-      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 ((*ListRunner)->ActiveFlag) {
         mol = *ListRunner;
         cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
@@ -859,5 +869,6 @@
 
     case 'o': // create the connection matrix
-      {
+      for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
+        if ((*ListRunner)->ActiveFlag) {
         double bonddistance;
         clock_t start,end;
@@ -873,10 +884,11 @@
 
     case 't': // translate all atoms
-     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 ((*ListRunner)->ActiveFlag) {
         mol = *ListRunner;
         cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
         cout << Verbose(0) << "Enter translation vector." << endl;
         x.AskPosition(mol->cell_size,0);
-        mol->Translate((const Vector *)&x);
+        mol->Center.AddVector((const Vector *)&x);
      }
      break;
@@ -901,17 +913,16 @@
   char choice;  // menu choice char
   bool valid;
-  Vector Center;
+  Vector center;
   int nr, count;
   molecule *mol = NULL;
   char *molname = NULL;
   int length;
-  char filename[MAXSTRINGSIZE];
-
-  cout << Verbose(0) << "==========Edit MOLECULES=====================" << endl;
+
+  cout << Verbose(0) << "==========EDIT MOLECULES=====================" << endl;
   cout << Verbose(0) << "c - create new molecule" << endl;
   cout << Verbose(0) << "l - load molecule from xyz file" << endl;
   cout << Verbose(0) << "n - change molecule's name" << endl;
   cout << Verbose(0) << "N - give molecules filename" << endl;
-  cout << Verbose(0) << "p - parse xyz file into molecule" << endl;
+  cout << Verbose(0) << "p - parse atoms in xyz file into molecule" << endl;
   cout << Verbose(0) << "r - remove a molecule" << endl;
   cout << Verbose(0) << "all else - go back" << endl;
@@ -929,58 +940,70 @@
       break;
 
-    case 'l': // laod from XYZ file
-      cout << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
-      mol = new molecule(periode);
-      do {
-        cout << Verbose(0) << "Enter file name: ";
+    case 'l': // load from XYZ file
+      {
+        char filename[MAXSTRINGSIZE];
+        cout << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
+        mol = new molecule(periode);
+        do {
+          cout << Verbose(0) << "Enter file name: ";
+          cin >> filename;
+        } while (!mol->AddXYZFile(filename));
+        mol->SetNameFromFilename(filename);
+        // center at set box dimensions
+        mol->CenterEdge((ofstream *)&cout, &center);
+        mol->cell_size[0] = center.x[0];
+        mol->cell_size[1] = 0;
+        mol->cell_size[2] = center.x[1];
+        mol->cell_size[3] = 0;
+        mol->cell_size[4] = 0;
+        mol->cell_size[5] = center.x[2];
+        molecules->insert(mol);
+      }
+      break;
+
+    case 'n':
+      {
+        char filename[MAXSTRINGSIZE];
+        do {
+          cout << Verbose(0) << "Enter index of molecule: ";
+          cin >> nr;
+          mol = molecules->ReturnIndex(nr);
+        } while (mol == NULL);
+        cout << Verbose(0) << "Enter name: ";
         cin >> filename;
-      } while (!mol->AddXYZFile(filename));
-      mol->SetNameFromFilename(filename);
-      // center at set box dimensions
-      mol->CenterEdge((ofstream *)&cout, &Center);
-      mol->cell_size[0] = Center.x[0];
-      mol->cell_size[1] = 0;
-      mol->cell_size[2] = Center.x[1];
-      mol->cell_size[3] = 0;
-      mol->cell_size[4] = 0;
-      mol->cell_size[5] = Center.x[2];
-      molecules->insert(mol);
-      break;
-
-    case 'n':
-      do {
-        cout << Verbose(0) << "Enter index of molecule: ";
-        cin >> nr;
-        mol = molecules->ReturnIndex(nr);
-      } while (mol != NULL);
-      cout << Verbose(0) << "Enter name: ";
-      cin >> filename;
-      strcpy(mol->name, filename);
+        strcpy(mol->name, filename);
+      }
       break;
 
     case 'N':
-      do {
-        cout << Verbose(0) << "Enter index of molecule: ";
-        cin >> nr;
-        mol = molecules->ReturnIndex(nr);
-      } while (mol != NULL);
-      cout << Verbose(0) << "Enter name: ";
-      cin >> filename;
-      mol->SetNameFromFilename(filename);
+      {
+        char filename[MAXSTRINGSIZE];
+        do {
+          cout << Verbose(0) << "Enter index of molecule: ";
+          cin >> nr;
+          mol = molecules->ReturnIndex(nr);
+        } while (mol == NULL);
+        cout << Verbose(0) << "Enter name: ";
+        cin >> filename;
+        mol->SetNameFromFilename(filename);
+      }
       break;
 
     case 'p': // parse XYZ file
-      mol = NULL;
-      do {
-        cout << Verbose(0) << "Enter index of molecule: ";
-        cin >> nr;
-        mol = molecules->ReturnIndex(nr);
-      } while (mol == NULL);
-      cout << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
-      do {
-        cout << Verbose(0) << "Enter file name: ";
-        cin >> filename;
-      } while (!mol->AddXYZFile(filename));
-      mol->SetNameFromFilename(filename);
+      {
+        char filename[MAXSTRINGSIZE];
+        mol = NULL;
+        do {
+          cout << Verbose(0) << "Enter index of molecule: ";
+          cin >> nr;
+          mol = molecules->ReturnIndex(nr);
+        } while (mol == NULL);
+        cout << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
+        do {
+          cout << Verbose(0) << "Enter file name: ";
+          cin >> filename;
+        } while (!mol->AddXYZFile(filename));
+        mol->SetNameFromFilename(filename);
+      }
       break;
 
@@ -989,11 +1012,10 @@
       cin >> nr;
       count = 1;
-      MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin();
-      for(; ((ListRunner != molecules->ListOfMolecules.end()) && (count < nr)); ListRunner++);
-      mol = *ListRunner;
-      if (count == nr) {
-        molecules->ListOfMolecules.erase(ListRunner);
-        delete(mol);
-      }
+      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;
   }
@@ -1011,4 +1033,5 @@
 
   cout << Verbose(0) << "===========MERGE MOLECULES=====================" << endl;
+  cout << Verbose(0) << "a - simple add of one molecule to another" << endl;
   cout << Verbose(0) << "e - embedding merge of two molecules" << endl;
   cout << Verbose(0) << "m - multi-merge of all molecules" << endl;
@@ -1025,14 +1048,73 @@
       break;
 
+    case 'a':
+      {
+        int src, dest;
+        molecule *srcmol = NULL, *destmol = NULL;
+        {
+          do {
+            cout << Verbose(0) << "Enter index of destination molecule: ";
+            cin >> dest;
+            destmol = molecules->ReturnIndex(dest);
+          } while ((destmol == NULL) && (dest != -1));
+          do {
+            cout << Verbose(0) << "Enter index of source molecule to add from: ";
+            cin >> src;
+            srcmol = molecules->ReturnIndex(src);
+          } while ((srcmol == NULL) && (src != -1));
+          if ((src != -1) && (dest != -1))
+            molecules->SimpleAdd(srcmol, destmol);
+        }
+      }
+      break;
+
     case 'e':
+      cout << Verbose(0) << "Not implemented yet." << endl;
       break;
 
     case 'm':
+      {
+        int nr;
+        molecule *mol = NULL;
+        do {
+          cout << Verbose(0) << "Enter index of molecule to merge into: ";
+          cin >> nr;
+          mol = molecules->ReturnIndex(nr);
+        } while ((mol == NULL) && (nr != -1));
+        if (nr != -1) {
+          int N = molecules->ListOfMolecules.size()-1;
+          int *src = new int(N);
+          for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
+            if ((*ListRunner)->IndexNr != nr)
+              src[N++] = (*ListRunner)->IndexNr;        
+          molecules->SimpleMultiMerge(mol, src, N);
+          delete[](src);
+        }
+      }
       break;
 
     case 's':
+      cout << Verbose(0) << "Not implemented yet." << endl;
       break;
 
     case 't':
+      {
+        int src, dest;
+        molecule *srcmol = NULL, *destmol = NULL;
+        {
+          do {
+            cout << Verbose(0) << "Enter index of destination molecule: ";
+            cin >> dest;
+            destmol = molecules->ReturnIndex(dest);
+          } while ((destmol == NULL) && (dest != -1));
+          do {
+            cout << Verbose(0) << "Enter index of source molecule to merge into: ";
+            cin >> src;
+            srcmol = molecules->ReturnIndex(src);
+          } while ((srcmol == NULL) && (src != -1));
+          if ((src != -1) && (dest != -1))
+            molecules->SimpleMerge(srcmol, destmol);
+        }
+      }
       break;
   }
@@ -1134,11 +1216,20 @@
 	molecule *mol = new molecule(periode);
 
-	// merge all molecules in MoleculeListClass into this molecule
+	// translate each to its center and merge all molecules in MoleculeListClass into this molecule
 	int N = molecules->ListOfMolecules.size();
 	int *src = new int(N);
 	N=0;
-	for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
+	for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
 	  src[N++] = (*ListRunner)->IndexNr;
+	  (*ListRunner)->Translate(&(*ListRunner)->Center);
+	}
 	molecules->SimpleMultiAdd(mol, src, N);
+	delete[](src);
+	// ... and translate back
+  for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
+    (*ListRunner)->Center.Scale(-1.);
+    (*ListRunner)->Translate(&(*ListRunner)->Center);
+    (*ListRunner)->Center.Scale(-1.);
+  }
 
 	cout << Verbose(0) << "Storing configuration ... " << endl;
@@ -1146,7 +1237,7 @@
 	mol->CalculateOrbitals(*configuration);
 	configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble;
-	strcpy(filename, ConfigFileName);
 	if (ConfigFileName != NULL) { // test the file name
-		output.open(ConfigFileName, ios::trunc);
+	  strcpy(filename, ConfigFileName);
+		output.open(filename, ios::trunc);
 	} else if (strlen(configuration->configname) != 0) {
 		strcpy(filename, configuration->configname);
@@ -1217,5 +1308,5 @@
  * \return exit code (0 - successful, all else - something's wrong)
  */
-static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode, config& configuration, char *&ConfigFileName, char *&PathToDatabases)
+static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode, config& configuration, char *ConfigFileName, char *&PathToDatabases)
 {
 	Vector x,y,z,n;	// coordinates for absolute point in cell volume
@@ -1236,4 +1327,5 @@
 	// simply create a new molecule, wherein the config file is loaded and the manipulation takes place
 	molecule *mol = new molecule(periode);
+  mol->ActiveFlag = true;
 	molecules->insert(mol);
 
@@ -1330,5 +1422,5 @@
 				} else {
 					cout << "Empty configuration file." << endl;
-					ConfigFileName = argv[1];
+					strcpy(ConfigFileName, argv[1]);
 					config_present = empty;
 					output.close();
@@ -1336,5 +1428,5 @@
 			} else {
 				test.close();
-				ConfigFileName = argv[1];
+				strcpy(ConfigFileName, argv[1]);
 				cout << Verbose(1) << "Specified config file found, parsing ... ";
 				switch (configuration.TestSyntax(ConfigFileName, periode, mol)) {
@@ -1618,6 +1710,6 @@
 							ExitFlag = 1;
 							SaveFlag = true;
-							cout << Verbose(1) << "Centering atoms in origin." << endl;
-							mol->CenterOrigin((ofstream *)&cout, &x);
+							cout << Verbose(1) << "Centering atoms on edge and setting box dimensions." << endl;
+							mol->CenterEdge((ofstream *)&cout, &x);
 							mol->SetBoxDimension(&x);
 							break;
@@ -1807,5 +1899,5 @@
 	ofstream output;
 	string line;
-	char *ConfigFileName = NULL;
+	char ConfigFileName[MAXSTRINGSIZE];
 	char *ElementsFileName = NULL;
 	int Z;
@@ -1813,4 +1905,5 @@
 
 	// =========================== PARSE COMMAND LINE OPTIONS ====================================
+	ConfigFileName[0] = '\0';
 	j = ParseCommandLineOptions(argc, argv, molecules, periode, configuration, ConfigFileName, ElementsFileName);
 	if (j == 1) return 0; // just for -v and -h options
@@ -1829,4 +1922,7 @@
     molecules->insert(mol);
 	}
+	if (strlen(ConfigFileName) == 0)
+	  strcpy(ConfigFileName, DEFAULTCONFIG);
+	  
 
 	// =========================== START INTERACTIVE SESSION ====================================
@@ -1840,5 +1936,5 @@
 		cout << Verbose(0) << "============Menu===============================" << endl;
     cout << Verbose(0) << "a - set molecule (in)active" << endl;
-    cout << Verbose(0) << "e - edit new molecules" << endl;
+    cout << Verbose(0) << "e - edit molecules (load, parse, save)" << endl;
     cout << Verbose(0) << "g - globally manipulate atoms in molecule" << endl;
     cout << Verbose(0) << "M - Merge molecules" << endl;
@@ -1859,9 +1955,7 @@
           cout << "Enter index of molecule: ";
           cin >> j;
-          count = 1;
-          MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin();
-          for(; ((ListRunner != molecules->ListOfMolecules.end()) && (count < j)); ListRunner++);
-          if (count == j)
-            (*ListRunner)->ActiveFlag = !(*ListRunner)->ActiveFlag;
+          for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
+            if ((*ListRunner)->IndexNr == j)
+              (*ListRunner)->ActiveFlag = !(*ListRunner)->ActiveFlag;
         }
 			  break;
