Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_geometry.cpp

    r4bb63c r83f176  
     1/*
     2 * Project: MoleCuilder
     3 * Description: creates and alters molecular systems
     4 * Copyright (C)  2010 University of Bonn. All rights reserved.
     5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
     6 */
     7
    18/*
    29 * molecule_geometry.cpp
     
    613 */
    714
     15// include config.h
    816#ifdef HAVE_CONFIG_H
    917#include <config.h>
    1018#endif
    1119
     20#include "Helpers/MemDebug.hpp"
     21
    1222#include "Helpers/helpers.hpp"
    1323#include "Helpers/Log.hpp"
    14 #include "Helpers/MemDebug.hpp"
    1524#include "Helpers/Verbose.hpp"
    1625#include "LinearAlgebra/Line.hpp"
     
    4857
    4958  // go through all atoms
    50   ActOnAllVectors( &Vector::SubtractVector, *Center);
    51   ActOnAllVectors( &Vector::SubtractVector, *CenterBox);
     59  BOOST_FOREACH(atom* iter, atoms){
     60    *iter -= *Center;
     61    *iter -= *CenterBox;
     62  }
    5263  atoms.transformNodes(boost::bind(&Box::WrapPeriodically,domain,_1));
    5364
     
    6677  Box &domain = World::getInstance().getDomain();
    6778
     79  // go through all atoms
    6880  atoms.transformNodes(boost::bind(&Box::WrapPeriodically,domain,_1));
    6981
     
    8395  if (iter != end()) { //list not empty?
    8496    for (int i=NDIM;i--;) {
    85       max->at(i) = (*iter)->x[i];
    86       min->at(i) = (*iter)->x[i];
     97      max->at(i) = (*iter)->at(i);
     98      min->at(i) = (*iter)->at(i);
    8799    }
    88100    for (; iter != end(); ++iter) {// continue with second if present
    89101      //(*iter)->Output(1,1,out);
    90102      for (int i=NDIM;i--;) {
    91         max->at(i) = (max->at(i) < (*iter)->x[i]) ? (*iter)->x[i] : max->at(i);
    92         min->at(i) = (min->at(i) > (*iter)->x[i]) ? (*iter)->x[i] : min->at(i);
     103        max->at(i) = (max->at(i) < (*iter)->at(i)) ? (*iter)->at(i) : max->at(i);
     104        min->at(i) = (min->at(i) > (*iter)->at(i)) ? (*iter)->at(i) : min->at(i);
    93105      }
    94106    }
     
    101113    (*max) += (*min);
    102114    Translate(min);
    103     Center.Zero();
    104115  }
    105116  delete(min);
     
    115126  int Num = 0;
    116127  molecule::const_iterator iter = begin();  // start at first in list
     128  Vector Center;
    117129
    118130  Center.Zero();
    119 
    120131  if (iter != end()) {   //list not empty?
    121132    for (; iter != end(); ++iter) {  // continue with second if present
    122133      Num++;
    123       Center += (*iter)->x;
     134      Center += (*iter)->getPosition();
    124135    }
    125136    Center.Scale(-1./(double)Num); // divide through total number (and sign for direction)
    126137    Translate(&Center);
    127     Center.Zero();
    128138  }
    129139};
     
    143153    for (; iter != end(); ++iter) {  // continue with second if present
    144154      Num++;
    145       (*a) += (*iter)->x;
     155      (*a) += (*iter)->getPosition();
    146156    }
    147157    a->Scale(1./(double)Num); // divide through total mass (and sign for direction)
     
    176186  if (iter != end()) {   //list not empty?
    177187    for (; iter != end(); ++iter) {  // continue with second if present
    178       Num += (*iter)->type->mass;
    179       tmp = (*iter)->type->mass * (*iter)->x;
     188      Num += (*iter)->getType()->getMass();
     189      tmp = (*iter)->getType()->getMass() * (*iter)->getPosition();
    180190      (*a) += tmp;
    181191    }
     
    194204void molecule::CenterPeriodic()
    195205{
    196   DeterminePeriodicCenter(Center);
     206  Vector NewCenter;
     207  DeterminePeriodicCenter(NewCenter);
     208  // go through all atoms
     209  BOOST_FOREACH(atom* iter, atoms){
     210    *iter -= NewCenter;
     211  }
    197212};
    198213
     
    204219void molecule::CenterAtVector(Vector *newcenter)
    205220{
    206   Center = *newcenter;
     221  // go through all atoms
     222  BOOST_FOREACH(atom* iter, atoms){
     223    *iter -= *newcenter;
     224  }
    207225};
    208226
     
    221239    for (int j=0;j<MDSteps;j++)
    222240      (*iter)->Trajectory.R.at(j).ScaleAll(*factor);
    223     (*iter)->x.ScaleAll(*factor);
     241    (*iter)->ScaleAll(*factor);
    224242  }
    225243};
     
    233251    for (int j=0;j<MDSteps;j++)
    234252      (*iter)->Trajectory.R.at(j) += (*trans);
    235     (*iter)->x += (*trans);
     253    *(*iter) += (*trans);
    236254  }
    237255};
     
    246264
    247265  // go through all atoms
    248   ActOnAllVectors( &Vector::AddVector, *trans);
     266  BOOST_FOREACH(atom* iter, atoms){
     267    *iter += *trans;
     268  }
    249269  atoms.transformNodes(boost::bind(&Box::WrapPeriodically,domain,_1));
    250270
     
    272292  bool flag;
    273293  Vector Testvector, Translationvector;
     294  Vector Center;
    274295
    275296  do {
     
    278299    for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    279300#ifdef ADDHYDROGEN
    280       if ((*iter)->type->Z != 1) {
     301      if ((*iter)->getType()->getAtomicNumber() != 1) {
    281302#endif
    282         Testvector = inversematrix * (*iter)->x;
     303        Testvector = inversematrix * (*iter)->getPosition();
    283304        Translationvector.Zero();
    284305        for (BondList::const_iterator Runner = (*iter)->ListOfBonds.begin(); Runner != (*iter)->ListOfBonds.end(); (++Runner)) {
    285306         if ((*iter)->nr < (*Runner)->GetOtherAtom((*iter))->nr) // otherwise we shift one to, the other fro and gain nothing
    286307            for (int j=0;j<NDIM;j++) {
    287               tmp = (*iter)->x[j] - (*Runner)->GetOtherAtom(*iter)->x[j];
     308              tmp = (*iter)->at(j) - (*Runner)->GetOtherAtom(*iter)->at(j);
    288309              if ((fabs(tmp)) > BondDistance) {
    289310                flag = false;
     
    303324        // now also change all hydrogens
    304325        for (BondList::const_iterator Runner = (*iter)->ListOfBonds.begin(); Runner != (*iter)->ListOfBonds.end(); (++Runner)) {
    305           if ((*Runner)->GetOtherAtom((*iter))->type->Z == 1) {
    306             Testvector = inversematrix * (*Runner)->GetOtherAtom((*iter))->x;
     326          if ((*Runner)->GetOtherAtom((*iter))->getType()->getAtomicNumber() == 1) {
     327            Testvector = inversematrix * (*Runner)->GetOtherAtom((*iter))->getPosition();
    307328            Testvector += Translationvector;
    308329            Testvector *= matrix;
     
    317338
    318339  Center.Scale(1./static_cast<double>(getAtomCount()));
     340  CenterAtVector(&Center);
    319341};
    320342
     
    335357  DoLog(1) && (Log() << Verbose(1) << "Z-X-angle: " << alpha << " ... ");
    336358  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    337     tmp = (*iter)->x[0];
    338     (*iter)->x[0] =  cos(alpha) * tmp + sin(alpha) * (*iter)->x[2];
    339     (*iter)->x[2] = -sin(alpha) * tmp + cos(alpha) * (*iter)->x[2];
     359    tmp = (*iter)->at(0);
     360    (*iter)->set(0,  cos(alpha) * tmp + sin(alpha) * (*iter)->at(2));
     361    (*iter)->set(2, -sin(alpha) * tmp + cos(alpha) * (*iter)->at(2));
    340362    for (int j=0;j<MDSteps;j++) {
    341363      tmp = (*iter)->Trajectory.R.at(j)[0];
     
    354376  DoLog(1) && (Log() << Verbose(1) << "Z-Y-angle: " << alpha << " ... ");
    355377  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    356     tmp = (*iter)->x[1];
    357     (*iter)->x[1] =  cos(alpha) * tmp + sin(alpha) * (*iter)->x[2];
    358     (*iter)->x[2] = -sin(alpha) * tmp + cos(alpha) * (*iter)->x[2];
     378    tmp = (*iter)->at(1);
     379    (*iter)->set(1,  cos(alpha) * tmp + sin(alpha) * (*iter)->at(2));
     380    (*iter)->set(2, -sin(alpha) * tmp + cos(alpha) * (*iter)->at(2));
    359381    for (int j=0;j<MDSteps;j++) {
    360382      tmp = (*iter)->Trajectory.R.at(j)[1];
     
    394416  // go through all atoms
    395417  for (molecule::const_iterator iter = par->mol->begin(); iter != par->mol->end(); ++iter) {
    396     if ((*iter)->type == ((struct lsq_params *)params)->type) { // for specific type
    397       c = (*iter)->x - a;
     418    if ((*iter)->getType() == ((struct lsq_params *)params)->type) { // for specific type
     419      c = (*iter)->getPosition() - a;
    398420      t = c.ScalarProduct(b);           // get direction parameter
    399421      d = t*b;       // and create vector
Note: See TracChangeset for help on using the changeset viewer.