Index: src/molecules.cpp
===================================================================
--- src/molecules.cpp	(revision 1907a789609146bbdebfeff09de44cb4ba21b808)
+++ src/molecules.cpp	(revision 21c0171a2ffa8aa89b2345abf037899c7dbedf2b)
@@ -629,48 +629,51 @@
 /** Centers the molecule in the box whose lengths are defined by vector \a *BoxLengths.
  * \param *out output stream for debugging
- * \param *BoxLengths box lengths
- */
-bool molecule::CenterInBox(ofstream *out, Vector *BoxLengths)
+ */
+bool molecule::CenterInBox(ofstream *out)
 {
 	bool status = true;
 	atom *ptr = NULL;
-	Vector *min = new Vector;
-	Vector *max = new Vector;
-
-	// gather min and max for each axis
-	ptr = start->next;	// start at first in list
-	if (ptr != end) {	 //list not empty?
-		for (int i=NDIM;i--;) {
-			max->x[i] = ptr->x.x[i];
-			min->x[i] = ptr->x.x[i];
-		}
-		while (ptr->next != end) {	// continue with second if present
-			ptr = ptr->next;
-			//ptr->Output(1,1,out);
-			for (int i=NDIM;i--;) {
-				max->x[i] = (max->x[i] < ptr->x.x[i]) ? ptr->x.x[i] : max->x[i];
-				min->x[i] = (min->x[i] > ptr->x.x[i]) ? ptr->x.x[i] : min->x[i];
-			}
-		}
-	}
-	// sanity check
-	for(int i=NDIM;i--;) {
-		if (max->x[i] - min->x[i] > BoxLengths->x[i])
-			status = false;
-	}
-	// warn if check failed
-	if (!status)
-		*out << "WARNING: molecule is bigger than defined box!" << endl;
-	else {	// else center in box
-		max->AddVector(min);
-		max->Scale(-1.);
-		max->AddVector(BoxLengths);
-		max->Scale(0.5);
-		Translate(max);
-	}
-
-	// free and exit
-	delete(min);
-	delete(max);
+	Vector x;
+	double *M = ReturnFullMatrixforSymmetric(cell_size);
+  double *Minv = x.InverseMatrix(M);
+	double value;
+
+//	cout << "The box matrix is :" << endl;
+//  for (int i=0;i<NDIM;++i) {
+//    for (int j=0;j<NDIM;++j)
+//      cout << M[i*NDIM+j] << "\t";
+//    cout << endl;
+//  }
+//  cout << "And its inverse is :" << endl;
+//  for (int i=0;i<NDIM;++i) {
+//    for (int j=0;j<NDIM;++j)
+//      cout << Minv[i*NDIM+j] << "\t";
+//    cout << endl;
+//  }
+	// go through all atoms
+  ptr = start->next;  // start at first in list
+  if (ptr != end) {  //list not empty?
+    while (ptr->next != end) {  // continue with second if present
+      ptr = ptr->next;
+      //ptr->Output(1,1,out);
+      // multiply its vector with matrix inverse
+      x.CopyVector(&ptr->x);
+      x.MatrixMultiplication(Minv);
+      // truncate to [0,1] for each axis
+      for (int i=0;i<NDIM;i++) {
+        value = floor(x.x[i]);  // next lower integer
+        if (x.x[i] >=0) {
+          x.x[i] -= value;
+        } else {
+          x.x[i] += value+1;
+        }
+      }
+      // matrix multiply
+      x.MatrixMultiplication(M);
+      ptr->x.CopyVector(&x);
+    }
+  }
+  delete(M);
+  delete(Minv);
 	return status;
 };
@@ -836,4 +839,61 @@
 	}
 };
+
+/** Translate the molecule periodically in the box.
+ * \param trans[] translation vector.
+ */
+void molecule::TranslatePeriodically(const Vector *trans)
+{
+  atom *ptr = NULL;
+  Vector x;
+  double *M = ReturnFullMatrixforSymmetric(cell_size);
+  double *Minv = x.InverseMatrix(M);
+  double value;
+
+  // go through all atoms
+  ptr = start->next;  // start at first in list
+  if (ptr != end) {  //list not empty?
+    while (ptr->next != end) {  // continue with second if present
+      ptr = ptr->next;
+      //ptr->Output(1,1,out);
+      // multiply its vector with matrix inverse
+      x.CopyVector(&ptr->x);
+      x.Translate(trans);
+      x.MatrixMultiplication(Minv);
+      // truncate to [0,1] for each axis
+      for (int i=0;i<NDIM;i++) {
+        value = floor(fabs(x.x[i]));  // next lower integer
+        if (x.x[i] >=0) {
+          x.x[i] -= value;
+        } else {
+          x.x[i] += value+1;
+        }
+      }
+      // matrix multiply
+      x.MatrixMultiplication(M);
+      ptr->x.CopyVector(&x);
+      for (int j=0;j<MDSteps;j++) {
+        x.CopyVector(&Trajectories[ptr].R.at(j));
+        x.Translate(trans);
+        x.MatrixMultiplication(Minv);
+        // truncate to [0,1] for each axis
+        for (int i=0;i<NDIM;i++) {
+          value = floor(x.x[i]);  // next lower integer
+          if (x.x[i] >=0) {
+            x.x[i] -= value;
+          } else {
+            x.x[i] += value+1;
+          }
+        }
+        // matrix multiply
+        x.MatrixMultiplication(M);
+        Trajectories[ptr].R.at(j).CopyVector(&x);
+      }
+    }
+  }
+  delete(M);
+  delete(Minv);
+};
+
 
 /** Mirrors all atoms against a given plane.
@@ -4130,9 +4190,9 @@
 	matrix[0] = symm[0];
 	matrix[1] = symm[1];
-	matrix[2] = symm[3];
+	matrix[2] = symm[2];
 	matrix[3] = symm[1];
-	matrix[4] = symm[2];
+	matrix[4] = symm[3];
 	matrix[5] = symm[4];
-	matrix[6] = symm[3];
+	matrix[6] = symm[2];
 	matrix[7] = symm[4];
 	matrix[8] = symm[5];
