Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_geometry.cpp

    rbdc91e raafd77  
    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  BOOST_FOREACH(atom* iter, atoms){
     50    *iter->node = domain.WrapPeriodically(*iter->node);
     51  }
     52
    4653  delete(Center);
    4754  delete(CenterBox);
     
    5663{
    5764  bool status = true;
    58   double * const cell_size = World::getInstance().getDomain();
    59   double *M = ReturnFullMatrixforSymmetric(cell_size);
    60   double *Minv = InverseMatrix(M);
     65  Box &domain = World::getInstance().getDomain();
    6166
    6267  // go through all atoms
    63   ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
    64 
    65   delete[](M);
    66   delete[](Minv);
     68  BOOST_FOREACH(atom* iter, atoms){
     69    *iter->node = domain.WrapPeriodically(*iter->node);
     70  }
     71
    6772  return status;
    6873};
     
    120125      Center += (*iter)->x;
    121126    }
    122     Center.Scale(-1./(double)Num); // divide through total number (and sign for direction)
     127    Center.Scale(-1./Num); // divide through total number (and sign for direction)
    123128    Translate(&Center);
    124129    Center.Zero();
     
    142147      (*a) += (*iter)->x;
    143148    }
    144     a->Scale(1./(double)Num); // divide through total mass (and sign for direction)
     149    a->Scale(1./Num); // divide through total mass (and sign for direction)
    145150  }
    146151  return a;
     
    153158{
    154159  Vector *a = new Vector(0.5,0.5,0.5);
    155 
    156   const double *cell_size = World::getInstance().getDomain();
    157   double *M = ReturnFullMatrixforSymmetric(cell_size);
    158   a->MatrixMultiplication(M);
    159   delete[](M);
    160 
     160  const Matrix &M = World::getInstance().getDomain().getM();
     161  (*a) *= M;
    161162  return a;
    162163};
     
    181182      (*a) += tmp;
    182183    }
    183     a->Scale(1./Num); // divide through total mass
     184    a->Scale(1./Num); // divide through total mass (and sign for direction)
    184185  }
    185186//  Log() << Verbose(1) << "Resulting center of gravity: ";
     
    244245void molecule::TranslatePeriodically(const Vector *trans)
    245246{
    246   double * const cell_size = World::getInstance().getDomain();
    247   double *M = ReturnFullMatrixforSymmetric(cell_size);
    248   double *Minv = InverseMatrix(M);
     247  Box &domain = World::getInstance().getDomain();
    249248
    250249  // go through all atoms
    251250  ActOnAllVectors( &Vector::AddVector, *trans);
    252   ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
    253 
    254   delete[](M);
    255   delete[](Minv);
     251  BOOST_FOREACH(atom* iter, atoms){
     252    *iter->node = domain.WrapPeriodically(*iter->node);
     253  }
     254
    256255};
    257256
     
    264263  OBSERVE;
    265264  Plane p(*n,0);
    266   BOOST_FOREACH( atom* iter, atoms ){
     265  BOOST_FOREACH(atom* iter, atoms ){
    267266    (*iter->node) = p.mirrorVector(*iter->node);
    268267  }
     
    274273void molecule::DeterminePeriodicCenter(Vector &center)
    275274{
    276   double * const cell_size = World::getInstance().getDomain();
    277   double *matrix = ReturnFullMatrixforSymmetric(cell_size);
    278   double *inversematrix = InverseMatrix(matrix);
     275  const Matrix &matrix = World::getInstance().getDomain().getM();
     276  const Matrix &inversematrix = World::getInstance().getDomain().getM();
    279277  double tmp;
    280278  bool flag;
     
    288286      if ((*iter)->type->Z != 1) {
    289287#endif
    290         Testvector = (*iter)->x;
    291         Testvector.MatrixMultiplication(inversematrix);
     288        Testvector = inversematrix * (*iter)->x;
    292289        Translationvector.Zero();
    293290        for (BondList::const_iterator Runner = (*iter)->ListOfBonds.begin(); Runner != (*iter)->ListOfBonds.end(); (++Runner)) {
     
    306303        }
    307304        Testvector += Translationvector;
    308         Testvector.MatrixMultiplication(matrix);
     305        Testvector *= matrix;
    309306        Center += Testvector;
    310307        Log() << Verbose(1) << "vector is: " << Testvector << endl;
     
    313310        for (BondList::const_iterator Runner = (*iter)->ListOfBonds.begin(); Runner != (*iter)->ListOfBonds.end(); (++Runner)) {
    314311          if ((*Runner)->GetOtherAtom((*iter))->type->Z == 1) {
    315             Testvector = (*Runner)->GetOtherAtom((*iter))->x;
    316             Testvector.MatrixMultiplication(inversematrix);
     312            Testvector = inversematrix * (*Runner)->GetOtherAtom((*iter))->x;
    317313            Testvector += Translationvector;
    318             Testvector.MatrixMultiplication(matrix);
     314            Testvector *= matrix;
    319315            Center += Testvector;
    320316            Log() << Verbose(1) << "Hydrogen vector is: " << Testvector << endl;
     
    325321    }
    326322  } while (!flag);
    327   delete[](matrix);
    328   delete[](inversematrix);
    329323
    330324  Center.Scale(1./static_cast<double>(getAtomCount()));
     
    388382    DoLog(1) && (Log() << Verbose(1) << "Transforming molecule into PAS ... ");
    389383    // the eigenvectors specify the transformation matrix
    390     ActOnAllVectors( &Vector::MatrixMultiplication, (const double *) evec->data );
     384    Matrix M = Matrix(evec->data);
     385    BOOST_FOREACH(atom* iter, atoms){
     386      (*iter->node) *= M;
     387    }
    391388    DoLog(0) && (Log() << Verbose(0) << "done." << endl);
    392389
Note: See TracChangeset for help on using the changeset viewer.