Index: src/molecule.cpp
===================================================================
--- src/molecule.cpp	(revision 5f612eea044e919bffc18a83cd7ddd35f981c765)
+++ src/molecule.cpp	(revision 8cbb9792c39564b3033f03b7e9dc61143585d5f4)
@@ -26,4 +26,7 @@
 #include "vector.hpp"
 #include "World.hpp"
+#include "Plane.hpp"
+#include "Exceptions/LinearDependenceException.hpp"
+
 
 /************************************* Functions for class molecule *********************************/
@@ -218,6 +221,5 @@
 //  Log() << Verbose(3) << "Begin of AddHydrogenReplacementAtom." << endl;
   // create vector in direction of bond
-  InBondvector.CopyVector(&TopReplacement->x);
-  InBondvector.SubtractVector(&TopOrigin->x);
+  InBondvector = TopReplacement->x - TopOrigin->x;
   bondlength = InBondvector.Norm();
 
@@ -231,12 +233,12 @@
     Orthovector1.Zero();
     for (int i=NDIM;i--;) {
-      l = TopReplacement->x.x[i] - TopOrigin->x.x[i];
+      l = TopReplacement->x[i] - TopOrigin->x[i];
       if (fabs(l) > BondDistance) { // is component greater than bond distance
-        Orthovector1.x[i] = (l < 0) ? -1. : +1.;
+        Orthovector1[i] = (l < 0) ? -1. : +1.;
       } // (signs are correct, was tested!)
     }
     matrix = ReturnFullMatrixforSymmetric(cell_size);
     Orthovector1.MatrixMultiplication(matrix);
-    InBondvector.SubtractVector(&Orthovector1); // subtract just the additional translation
+    InBondvector -= Orthovector1; // subtract just the additional translation
     Free(&matrix);
     bondlength = InBondvector.Norm();
@@ -263,5 +265,5 @@
       FirstOtherAtom = World::getInstance().createAtom();    // new atom
       FirstOtherAtom->type = elemente->FindElement(1);  // element is Hydrogen
-      FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
+      FirstOtherAtom->v = TopReplacement->v; // copy velocity
       FirstOtherAtom->FixedIon = TopReplacement->FixedIon;
       if (TopReplacement->type->Z == 1) { // neither rescale nor replace if it's already hydrogen
@@ -271,7 +273,7 @@
         FirstOtherAtom->father = NULL;  // if we replace hydrogen, we mark it as our father, otherwise we are just an added hydrogen with no father
       }
-      InBondvector.Scale(&BondRescale);   // rescale the distance vector to Hydrogen bond length
-      FirstOtherAtom->x.CopyVector(&TopOrigin->x); // set coordination to origin ...
-      FirstOtherAtom->x.AddVector(&InBondvector);  // ... and add distance vector to replacement atom
+      InBondvector *= BondRescale;   // rescale the distance vector to Hydrogen bond length
+      FirstOtherAtom->x = TopOrigin->x; // set coordination to origin ...
+      FirstOtherAtom->x = InBondvector;  // ... and add distance vector to replacement atom
       AllWentWell = AllWentWell && AddAtom(FirstOtherAtom);
 //      Log() << Verbose(4) << "Added " << *FirstOtherAtom << " at: ";
@@ -305,7 +307,14 @@
 
         // determine the plane of these two with the *origin
-        AllWentWell = AllWentWell && Orthovector1.MakeNormalVector(&TopOrigin->x, &FirstOtherAtom->x, &SecondOtherAtom->x);
+        try {
+          Orthovector1 =Plane(TopOrigin->x, FirstOtherAtom->x, SecondOtherAtom->x).getNormal();
+        }
+        catch(LinearDependenceException &excp){
+          Log() << Verbose(0) << excp;
+          // TODO: figure out what to do with the Orthovector in this case
+          AllWentWell = false;
+        }
       } else {
-        Orthovector1.GetOneNormalVector(&InBondvector);
+        Orthovector1.GetOneNormalVector(InBondvector);
       }
       //Log() << Verbose(3)<< "Orthovector1: ";
@@ -313,5 +322,5 @@
       //Log() << Verbose(0) << endl;
       // orthogonal vector and bond vector between origin and replacement form the new plane
-      Orthovector1.MakeNormalVector(&InBondvector);
+      Orthovector1.MakeNormalTo(InBondvector);
       Orthovector1.Normalize();
       //Log() << Verbose(3) << "ReScaleCheck: " << Orthovector1.Norm() << " and " << InBondvector.Norm() << "." << endl;
@@ -322,7 +331,7 @@
       FirstOtherAtom->type = elemente->FindElement(1);
       SecondOtherAtom->type = elemente->FindElement(1);
-      FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
+      FirstOtherAtom->v = TopReplacement->v; // copy velocity
       FirstOtherAtom->FixedIon = TopReplacement->FixedIon;
-      SecondOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
+      SecondOtherAtom->v = TopReplacement->v; // copy velocity
       SecondOtherAtom->FixedIon = TopReplacement->FixedIon;
       FirstOtherAtom->father = NULL;  // we are just an added hydrogen with no father
@@ -345,13 +354,13 @@
       SecondOtherAtom->x.Zero();
       for(int i=NDIM;i--;) { // rotate by half the bond angle in both directions (InBondvector is bondangle = 0 direction)
-        FirstOtherAtom->x.x[i] = InBondvector.x[i] * cos(bondangle) + Orthovector1.x[i] * (sin(bondangle));
-        SecondOtherAtom->x.x[i] = InBondvector.x[i] * cos(bondangle) + Orthovector1.x[i] * (-sin(bondangle));
-      }
-      FirstOtherAtom->x.Scale(&BondRescale);  // rescale by correct BondDistance
-      SecondOtherAtom->x.Scale(&BondRescale);
+        FirstOtherAtom->x[i] = InBondvector[i] * cos(bondangle) + Orthovector1[i] * (sin(bondangle));
+        SecondOtherAtom->x[i] = InBondvector[i] * cos(bondangle) + Orthovector1[i] * (-sin(bondangle));
+      }
+      FirstOtherAtom->x *= BondRescale;  // rescale by correct BondDistance
+      SecondOtherAtom->x *= BondRescale;
       //Log() << Verbose(3) << "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << "." << endl;
       for(int i=NDIM;i--;) { // and make relative to origin atom
-        FirstOtherAtom->x.x[i] += TopOrigin->x.x[i];
-        SecondOtherAtom->x.x[i] += TopOrigin->x.x[i];
+        FirstOtherAtom->x[i] += TopOrigin->x[i];
+        SecondOtherAtom->x[i] += TopOrigin->x[i];
       }
       // ... and add to molecule
@@ -379,9 +388,9 @@
       SecondOtherAtom->type = elemente->FindElement(1);
       ThirdOtherAtom->type = elemente->FindElement(1);
-      FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
+      FirstOtherAtom->v = TopReplacement->v; // copy velocity
       FirstOtherAtom->FixedIon = TopReplacement->FixedIon;
-      SecondOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
+      SecondOtherAtom->v = TopReplacement->v; // copy velocity
       SecondOtherAtom->FixedIon = TopReplacement->FixedIon;
-      ThirdOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
+      ThirdOtherAtom->v = TopReplacement->v; // copy velocity
       ThirdOtherAtom->FixedIon = TopReplacement->FixedIon;
       FirstOtherAtom->father = NULL;  //  we are just an added hydrogen with no father
@@ -390,9 +399,15 @@
 
       // we need to vectors orthonormal the InBondvector
-      AllWentWell = AllWentWell && Orthovector1.GetOneNormalVector(&InBondvector);
+      AllWentWell = AllWentWell && Orthovector1.GetOneNormalVector(InBondvector);
 //      Log() << Verbose(3) << "Orthovector1: ";
 //      Orthovector1.Output(out);
 //      Log() << Verbose(0) << endl;
-      AllWentWell = AllWentWell && Orthovector2.MakeNormalVector(&InBondvector, &Orthovector1);
+      try{
+        Orthovector2 = Plane(InBondvector, Orthovector1,0).getNormal();
+      }
+      catch(LinearDependenceException &excp) {
+        Log() << Verbose(0) << excp;
+        AllWentWell = false;
+      }
 //      Log() << Verbose(3) << "Orthovector2: ";
 //      Orthovector2.Output(out);
@@ -411,10 +426,10 @@
       factors[1] = f;
       factors[2] = 0.;
-      FirstOtherAtom->x.LinearCombinationOfVectors(&InBondvector, &Orthovector1, &Orthovector2, factors);
+      FirstOtherAtom->x.LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);
       factors[1] = -0.5*f;
       factors[2] = g;
-      SecondOtherAtom->x.LinearCombinationOfVectors(&InBondvector, &Orthovector1, &Orthovector2, factors);
+      SecondOtherAtom->x.LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);
       factors[2] = -g;
-      ThirdOtherAtom->x.LinearCombinationOfVectors(&InBondvector, &Orthovector1, &Orthovector2, factors);
+      ThirdOtherAtom->x.LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);
 
       // rescale each to correct BondDistance
@@ -424,7 +439,7 @@
 
       // and relative to *origin atom
-      FirstOtherAtom->x.AddVector(&TopOrigin->x);
-      SecondOtherAtom->x.AddVector(&TopOrigin->x);
-      ThirdOtherAtom->x.AddVector(&TopOrigin->x);
+      FirstOtherAtom->x += TopOrigin->x;
+      SecondOtherAtom->x += TopOrigin->x;
+      ThirdOtherAtom->x += TopOrigin->x;
 
       // ... and add to molecule
@@ -514,8 +529,8 @@
     }
     for(j=NDIM;j--;) {
-      Walker->x.x[j] = x[j];
-      Walker->Trajectory.R.at(MDSteps-1).x[j] = x[j];
-      Walker->Trajectory.U.at(MDSteps-1).x[j] = 0;
-      Walker->Trajectory.F.at(MDSteps-1).x[j] = 0;
+      Walker->x[j] = x[j];
+      Walker->Trajectory.R.at(MDSteps-1)[j] = x[j];
+      Walker->Trajectory.U.at(MDSteps-1)[j] = 0;
+      Walker->Trajectory.F.at(MDSteps-1)[j] = 0;
     }
     AddAtom(Walker);  // add to molecule
@@ -662,10 +677,10 @@
 {
   double * const cell_size = World::getInstance().getDomain();
-  cell_size[0] = dim->x[0];
+  cell_size[0] = dim->at(0);
   cell_size[1] = 0.;
-  cell_size[2] = dim->x[1];
+  cell_size[2] = dim->at(1);
   cell_size[3] = 0.;
   cell_size[4] = 0.;
-  cell_size[5] = dim->x[2];
+  cell_size[5] = dim->at(2);
 };
 
@@ -757,5 +772,5 @@
   for (int i=0;i<NDIM;i++) {
     j += i+1;
-    result = result && ((x->x[i] >= 0) && (x->x[i] < cell_size[j]));
+    result = result && ((x->at(i) >= 0) && (x->at(i) < cell_size[j]));
   }
   //return result;
@@ -1007,10 +1022,7 @@
     DeterminePeriodicCenter(CenterOfGravity);
     OtherMolecule->DeterminePeriodicCenter(OtherCenterOfGravity);
-    DoLog(5) && (Log() << Verbose(5) << "Center of Gravity: ");
-    CenterOfGravity.Output();
-    DoLog(0) && (Log() << Verbose(0) << endl << Verbose(5) << "Other Center of Gravity: ");
-    OtherCenterOfGravity.Output();
-    DoLog(0) && (Log() << Verbose(0) << endl);
-    if (CenterOfGravity.DistanceSquared(&OtherCenterOfGravity) > threshold*threshold) {
+    DoLog(5) && (Log() << Verbose(5) << "Center of Gravity: " << CenterOfGravity << endl);
+    DoLog(5) && (Log() << Verbose(5) << "Other Center of Gravity: " << OtherCenterOfGravity << endl);
+    if (CenterOfGravity.DistanceSquared(OtherCenterOfGravity) > threshold*threshold) {
       DoLog(4) && (Log() << Verbose(4) << "Centers of gravity don't match." << endl);
       result = false;
