Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_geometry.cpp

    r112b09 r0632c5  
    55 *      Author: heber
    66 */
     7
     8#ifdef HAVE_CONFIG_H
     9#include <config.h>
     10#endif
    711
    812#include "Helpers/MemDebug.hpp"
     
    1418#include "helpers.hpp"
    1519#include "leastsquaremin.hpp"
     20#include "verbose.hpp"
    1621#include "log.hpp"
    17 #include "memoryallocator.hpp"
    1822#include "molecule.hpp"
    1923#include "World.hpp"
    2024#include "Plane.hpp"
     25#include "Matrix.hpp"
     26#include "Box.hpp"
    2127#include <boost/foreach.hpp>
     28
     29#include <gsl/gsl_eigen.h>
     30#include <gsl/gsl_multimin.h>
    2231
    2332
     
    3342  const Vector *Center = DetermineCenterOfAll();
    3443  const Vector *CenterBox = DetermineCenterOfBox();
    35   double * const cell_size = World::getInstance().getDomain();
    36   double *M = ReturnFullMatrixforSymmetric(cell_size);
    37   double *Minv = InverseMatrix(M);
     44  Box &domain = World::getInstance().getDomain();
    3845
    3946  // go through all atoms
    4047  ActOnAllVectors( &Vector::SubtractVector, *Center);
    4148  ActOnAllVectors( &Vector::SubtractVector, *CenterBox);
    42   ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
    43 
    44   delete[](M);
    45   delete[](Minv);
     49  atoms.transformNodes(boost::bind(&Box::WrapPeriodically,domain,_1));
     50
    4651  delete(Center);
     52  delete(CenterBox);
    4753  return status;
    4854};
     
    5561{
    5662  bool status = true;
    57   double * const cell_size = World::getInstance().getDomain();
    58   double *M = ReturnFullMatrixforSymmetric(cell_size);
    59   double *Minv = InverseMatrix(M);
    60 
    61   // go through all atoms
    62   ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
    63 
    64   delete[](M);
    65   delete[](Minv);
     63  Box &domain = World::getInstance().getDomain();
     64
     65  atoms.transformNodes(boost::bind(&Box::WrapPeriodically,domain,_1));
     66
    6667  return status;
    6768};
     
    119120      Center += (*iter)->x;
    120121    }
    121     Center.Scale(-1./Num); // divide through total number (and sign for direction)
     122    Center.Scale(-1./(double)Num); // divide through total number (and sign for direction)
    122123    Translate(&Center);
    123124    Center.Zero();
     
    141142      (*a) += (*iter)->x;
    142143    }
    143     a->Scale(1./Num); // divide through total mass (and sign for direction)
     144    a->Scale(1./(double)Num); // divide through total mass (and sign for direction)
    144145  }
    145146  return a;
     
    152153{
    153154  Vector *a = new Vector(0.5,0.5,0.5);
    154 
    155   const double *cell_size = World::getInstance().getDomain();
    156   double *M = ReturnFullMatrixforSymmetric(cell_size);
    157   a->MatrixMultiplication(M);
    158   delete[](M);
    159 
     155  const Matrix &M = World::getInstance().getDomain().getM();
     156  (*a) *= M;
    160157  return a;
    161158};
     
    180177      (*a) += tmp;
    181178    }
    182     a->Scale(1./Num); // divide through total mass (and sign for direction)
     179    a->Scale(1./Num); // divide through total mass
    183180  }
    184181//  Log() << Verbose(1) << "Resulting center of gravity: ";
     
    243240void molecule::TranslatePeriodically(const Vector *trans)
    244241{
    245   double * const cell_size = World::getInstance().getDomain();
    246   double *M = ReturnFullMatrixforSymmetric(cell_size);
    247   double *Minv = InverseMatrix(M);
     242  Box &domain = World::getInstance().getDomain();
    248243
    249244  // go through all atoms
    250245  ActOnAllVectors( &Vector::AddVector, *trans);
    251   ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
    252 
    253   delete[](M);
    254   delete[](Minv);
     246  atoms.transformNodes(boost::bind(&Box::WrapPeriodically,domain,_1));
     247
    255248};
    256249
     
    263256  OBSERVE;
    264257  Plane p(*n,0);
    265   BOOST_FOREACH( atom* iter, atoms ){
    266     (*iter->node) = p.mirrorVector(*iter->node);
    267   }
     258  atoms.transformNodes(boost::bind(&Plane::mirrorVector,p,_1));
    268259};
    269260
     
    273264void molecule::DeterminePeriodicCenter(Vector &center)
    274265{
    275   double * const cell_size = World::getInstance().getDomain();
    276   double *matrix = ReturnFullMatrixforSymmetric(cell_size);
    277   double *inversematrix = InverseMatrix(matrix);
     266  const Matrix &matrix = World::getInstance().getDomain().getM();
     267  const Matrix &inversematrix = World::getInstance().getDomain().getM();
    278268  double tmp;
    279269  bool flag;
     
    287277      if ((*iter)->type->Z != 1) {
    288278#endif
    289         Testvector = (*iter)->x;
    290         Testvector.MatrixMultiplication(inversematrix);
     279        Testvector = inversematrix * (*iter)->x;
    291280        Translationvector.Zero();
    292281        for (BondList::const_iterator Runner = (*iter)->ListOfBonds.begin(); Runner != (*iter)->ListOfBonds.end(); (++Runner)) {
     
    305294        }
    306295        Testvector += Translationvector;
    307         Testvector.MatrixMultiplication(matrix);
     296        Testvector *= matrix;
    308297        Center += Testvector;
    309298        Log() << Verbose(1) << "vector is: " << Testvector << endl;
     
    312301        for (BondList::const_iterator Runner = (*iter)->ListOfBonds.begin(); Runner != (*iter)->ListOfBonds.end(); (++Runner)) {
    313302          if ((*Runner)->GetOtherAtom((*iter))->type->Z == 1) {
    314             Testvector = (*Runner)->GetOtherAtom((*iter))->x;
    315             Testvector.MatrixMultiplication(inversematrix);
     303            Testvector = inversematrix * (*Runner)->GetOtherAtom((*iter))->x;
    316304            Testvector += Translationvector;
    317             Testvector.MatrixMultiplication(matrix);
     305            Testvector *= matrix;
    318306            Center += Testvector;
    319307            Log() << Verbose(1) << "Hydrogen vector is: " << Testvector << endl;
     
    324312    }
    325313  } while (!flag);
    326   delete[](matrix);
    327   delete[](inversematrix);
    328314
    329315  Center.Scale(1./static_cast<double>(getAtomCount()));
     
    387373    DoLog(1) && (Log() << Verbose(1) << "Transforming molecule into PAS ... ");
    388374    // the eigenvectors specify the transformation matrix
    389     ActOnAllVectors( &Vector::MatrixMultiplication, (const double *) evec->data );
     375    Matrix M = Matrix(evec->data);
     376
     377    BOOST_FOREACH(atom* iter, atoms){
     378      (*iter->node) *= M;
     379    }
    390380    DoLog(0) && (Log() << Verbose(0) << "done." << endl);
    391381
Note: See TracChangeset for help on using the changeset viewer.