Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_geometry.cpp

    r833b15 r9291d04  
    5858/************************************* Functions for class molecule *********************************/
    5959
    60 /** Returns vector pointing to center of the domain.
    61  * \return pointer to center of the domain
    62  */
    63 #ifdef HAVE_INLINE
    64 inline
    65 #else
    66 static
    67 #endif
    68 const Vector DetermineCenterOfBox()
    69 {
    70   Vector a(0.5,0.5,0.5);
    71   const RealSpaceMatrix &M = World::getInstance().getDomain().getM();
    72   a *= M;
    73   return a;
    74 }
    7560
    7661/** Centers the molecule in the box whose lengths are defined by vector \a *BoxLengths.
     
    8065{
    8166  bool status = true;
    82   const Vector Center = DetermineCenterOfAll();
    83   const Vector CenterBox = DetermineCenterOfBox();
     67  const Vector *Center = DetermineCenterOfAll();
     68  const Vector *CenterBox = DetermineCenterOfBox();
    8469  Box &domain = World::getInstance().getDomain();
    8570
    8671  // go through all atoms
    87   Translate(CenterBox - Center);
     72  for (iterator iter = begin(); iter != end(); ++iter) {
     73    if (DoLog(4) && (*Center != *CenterBox))
     74      LOG(4, "INFO: atom before is at " << **iter);
     75    **iter -= *Center;
     76    **iter += *CenterBox;
     77    if (DoLog(4) && (*Center != *CenterBox))
     78      LOG(4, "INFO: atom after is at " << **iter);
     79  }
    8880  getAtomSet().transformNodes(boost::bind(&Box::enforceBoundaryConditions,domain,_1));
    8981
     82  delete(Center);
     83  delete(CenterBox);
    9084  return status;
    91 }
     85};
    9286
    9387
     
    10498
    10599  return status;
    106 }
     100};
    107101
    108102/** Centers the edge of the atoms at (0,0,0).
    109  */
    110 void molecule::CenterEdge()
    111 {
    112   const_iterator iter = begin();
    113   if (iter != end()) {   //list not empty?
    114     Vector min = (*begin())->getPosition();
    115     for (;iter != end(); ++iter) { // continue with second if present
    116       const Vector &currentPos = (*iter)->getPosition();
    117       for (size_t i=0;i<NDIM;++i)
    118         if (min[i] > currentPos[i])
    119           min[i] = currentPos[i];
    120     }
    121     Translate(-1.*min);
    122   }
    123 }
     103 * \param *out output stream for debugging
     104 * \param *max coordinates of other edge, specifying box dimensions.
     105 */
     106void molecule::CenterEdge(Vector *max)
     107{
     108//  Info info(__func__);
     109  Vector *min = new Vector;
     110
     111  const_iterator iter = begin();  // start at first in list
     112  if (iter != end()) { //list not empty?
     113    for (int i=NDIM;i--;) {
     114      max->at(i) = (*iter)->at(i);
     115      min->at(i) = (*iter)->at(i);
     116    }
     117    for (; iter != end(); ++iter) {// continue with second if present
     118      //(*iter)->Output(1,1,out);
     119      for (int i=NDIM;i--;) {
     120        max->at(i) = (max->at(i) < (*iter)->at(i)) ? (*iter)->at(i) : max->at(i);
     121        min->at(i) = (min->at(i) > (*iter)->at(i)) ? (*iter)->at(i) : min->at(i);
     122      }
     123    }
     124    LOG(1, "INFO: Maximum is " << *max << ", Minimum is " << *min << ".");
     125    min->Scale(-1.);
     126    (*max) += (*min);
     127    Translate(min);
     128  }
     129  delete(min);
     130};
    124131
    125132/** Centers the center of the atoms at (0,0,0).
     
    140147    }
    141148    Center.Scale(-1./(double)Num); // divide through total number (and sign for direction)
    142     Translate(Center);
    143   }
    144 }
     149    Translate(&Center);
     150  }
     151};
    145152
    146153/** Returns vector pointing to center of all atoms.
    147154 * \return pointer to center of all vector
    148155 */
    149 const Vector molecule::DetermineCenterOfAll() const
     156Vector * molecule::DetermineCenterOfAll() const
    150157{
    151158  const_iterator iter = begin();  // start at first in list
    152   Vector a;
     159  Vector *a = new Vector();
    153160  double Num = 0;
    154161
    155   a.Zero();
     162  a->Zero();
    156163
    157164  if (iter != end()) {   //list not empty?
    158165    for (; iter != end(); ++iter) {  // continue with second if present
    159166      Num++;
    160       a += (*iter)->getPosition();
    161     }
    162     a.Scale(1./(double)Num); // divide through total mass (and sign for direction)
     167      (*a) += (*iter)->getPosition();
     168    }
     169    a->Scale(1./(double)Num); // divide through total mass (and sign for direction)
    163170  }
    164171  return a;
    165 }
    166 
     172};
     173
     174/** Returns vector pointing to center of the domain.
     175 * \return pointer to center of the domain
     176 */
     177Vector * molecule::DetermineCenterOfBox() const
     178{
     179  Vector *a = new Vector(0.5,0.5,0.5);
     180  const RealSpaceMatrix &M = World::getInstance().getDomain().getM();
     181  (*a) *= M;
     182  return a;
     183};
    167184
    168185/** Returns vector pointing to center of gravity.
     
    170187 * \return pointer to center of gravity vector
    171188 */
    172 const Vector molecule::DetermineCenterOfGravity() const
     189Vector * molecule::DetermineCenterOfGravity() const
    173190{
    174191  const_iterator iter = begin();  // start at first in list
    175   Vector a;
     192  Vector *a = new Vector();
    176193  Vector tmp;
    177194  double Num = 0;
    178195
    179   a.Zero();
     196  a->Zero();
    180197
    181198  if (iter != end()) {   //list not empty?
     
    183200      Num += (*iter)->getType()->getMass();
    184201      tmp = (*iter)->getType()->getMass() * (*iter)->getPosition();
    185       a += tmp;
    186     }
    187     a.Scale(1./Num); // divide through total mass
    188   }
    189   LOG(1, "INFO: Resulting center of gravity: " << a << ".");
     202      (*a) += tmp;
     203    }
     204    a->Scale(1./Num); // divide through total mass
     205  }
     206  LOG(1, "INFO: Resulting center of gravity: " << *a << ".");
    190207  return a;
    191 }
     208};
    192209
    193210/** Centers the center of gravity of the atoms at (0,0,0).
     
    199216  Vector NewCenter;
    200217  DeterminePeriodicCenter(NewCenter);
    201   Translate(-1.*NewCenter);
    202 }
     218  // go through all atoms
     219  for (iterator iter = begin(); iter != end(); ++iter) {
     220    **iter -= NewCenter;
     221  }
     222};
    203223
    204224
     
    207227 * \param *center return vector for translation vector
    208228 */
    209 void molecule::CenterAtVector(const Vector &newcenter)
    210 {
    211   Translate(-1.*newcenter);
    212 }
     229void molecule::CenterAtVector(Vector *newcenter)
     230{
     231  // go through all atoms
     232  for (iterator iter = begin(); iter != end(); ++iter) {
     233    **iter -= *newcenter;
     234  }
     235};
    213236
    214237/** Calculate the inertia tensor of a the molecule.
     
    219242{
    220243  RealSpaceMatrix InertiaTensor;
    221   const Vector CenterOfGravity = DetermineCenterOfGravity();
     244  Vector *CenterOfGravity = DetermineCenterOfGravity();
    222245
    223246  // reset inertia tensor
     
    227250  for (const_iterator iter = begin(); iter != end(); ++iter) {
    228251    Vector x = (*iter)->getPosition();
    229     x -= CenterOfGravity;
     252    x -= *CenterOfGravity;
    230253    const double mass = (*iter)->getType()->getMass();
    231254    InertiaTensor.at(0,0) += mass*(x[1]*x[1] + x[2]*x[2]);
     
    242265  LOG(1, "INFO: The inertia tensor of molecule " << getName() <<  " is:" << InertiaTensor);
    243266
     267  delete CenterOfGravity;
    244268  return InertiaTensor;
    245269}
     
    252276void molecule::RotateToPrincipalAxisSystem(const Vector &Axis)
    253277{
    254   const Vector CenterOfGravity = DetermineCenterOfGravity();
     278  Vector *CenterOfGravity = DetermineCenterOfGravity();
    255279  RealSpaceMatrix InertiaTensor = getInertiaTensor();
    256280
     
    264288
    265289  // obtain first column, eigenvector to biggest eigenvalue
    266   const Vector BiggestEigenvector(InertiaTensor.column(Eigenvalues.SmallestComponent()));
     290  Vector BiggestEigenvector(InertiaTensor.column(Eigenvalues.SmallestComponent()));
    267291  Vector DesiredAxis(Axis.getNormalized());
    268292
     
    278302  // and rotate
    279303  for (iterator iter = begin(); iter != end(); ++iter) {
    280     *(*iter) -= CenterOfGravity;
     304    *(*iter) -= *CenterOfGravity;
    281305    (*iter)->setPosition(RotationAxis.rotateVector((*iter)->getPosition(), alpha));
    282     *(*iter) += CenterOfGravity;
     306    *(*iter) += *CenterOfGravity;
    283307  }
    284308  LOG(0, "STATUS: done.");
     309
     310  delete CenterOfGravity;
    285311}
    286312
     
    293319 * x=(**factor) * x (as suggested by comment)
    294320 */
    295 void molecule::Scale(const double *factor)
     321void molecule::Scale(const double ** const factor)
    296322{
    297323  for (iterator iter = begin(); iter != end(); ++iter) {
    298324    for (size_t j=0;j<(*iter)->getTrajectorySize();j++) {
    299325      Vector temp = (*iter)->getPositionAtStep(j);
    300       temp.ScaleAll(factor);
     326      temp.ScaleAll(*factor);
    301327      (*iter)->setPositionAtStep(j,temp);
    302328    }
     
    307333 * \param trans[] translation vector.
    308334 */
    309 void molecule::Translate(const Vector &trans)
    310 {
    311   getAtomSet().translate(trans);
     335void molecule::Translate(const Vector *trans)
     336{
     337  for (iterator iter = begin(); iter != end(); ++iter) {
     338    for (size_t j=0;j<(*iter)->getTrajectorySize();j++) {
     339      (*iter)->setPositionAtStep(j, (*iter)->getPositionAtStep(j) + (*trans));
     340    }
     341  }
    312342};
    313343
     
    316346 * TODO treatment of trajectories missing
    317347 */
    318 void molecule::TranslatePeriodically(const Vector &trans)
    319 {
    320   Translate(trans);
     348void molecule::TranslatePeriodically(const Vector *trans)
     349{
    321350  Box &domain = World::getInstance().getDomain();
     351
     352  // go through all atoms
     353  for (iterator iter = begin(); iter != end(); ++iter) {
     354    **iter += *trans;
     355  }
    322356  getAtomSet().transformNodes(boost::bind(&Box::enforceBoundaryConditions,domain,_1));
     357
    323358};
    324359
     
    327362 * \param n[] normal vector of mirror plane.
    328363 */
    329 void molecule::Mirror(const Vector &n)
    330 {
    331   Plane p(n,0);
     364void molecule::Mirror(const Vector *n)
     365{
     366  OBSERVE;
     367  Plane p(*n,0);
    332368  getAtomSet().transformNodes(boost::bind(&Plane::mirrorVector,p,_1));
    333369};
     
    345381  Vector Testvector, Translationvector;
    346382  Vector Center;
    347   const BondGraph * const BG = World::getInstance().getBondGraph();
     383  BondGraph *BG = World::getInstance().getBondGraph();
    348384
    349385  do {
     
    396432
    397433  Center.Scale(1./static_cast<double>(getAtomCount()));
    398   CenterAtVector(Center);
     434  CenterAtVector(&Center);
    399435};
    400436
     
    402438 * \param n[] alignment vector.
    403439 */
    404 void molecule::Align(const Vector &n)
     440void molecule::Align(Vector *n)
    405441{
    406442  double alpha, tmp;
    407443  Vector z_axis;
    408   Vector alignment(n);
    409444  z_axis[0] = 0.;
    410445  z_axis[1] = 0.;
     
    413448  // rotate on z-x plane
    414449  LOG(0, "Begin of Aligning all atoms.");
    415   alpha = atan(-alignment.at(0)/alignment.at(2));
     450  alpha = atan(-n->at(0)/n->at(2));
    416451  LOG(1, "INFO: Z-X-angle: " << alpha << " ... ");
    417452  for (iterator iter = begin(); iter != end(); ++iter) {
     
    427462  }
    428463  // rotate n vector
    429   tmp = alignment.at(0);
    430   alignment.at(0) =  cos(alpha) * tmp +  sin(alpha) * alignment.at(2);
    431   alignment.at(2) = -sin(alpha) * tmp +  cos(alpha) * alignment.at(2);
    432   LOG(1, "alignment vector after first rotation: " << alignment);
     464  tmp = n->at(0);
     465  n->at(0) =  cos(alpha) * tmp +  sin(alpha) * n->at(2);
     466  n->at(2) = -sin(alpha) * tmp +  cos(alpha) * n->at(2);
     467  LOG(1, "alignment vector after first rotation: " << n);
    433468
    434469  // rotate on z-y plane
    435   alpha = atan(-alignment.at(1)/alignment.at(2));
     470  alpha = atan(-n->at(1)/n->at(2));
    436471  LOG(1, "INFO: Z-Y-angle: " << alpha << " ... ");
    437472  for (iterator iter = begin(); iter != end(); ++iter) {
     
    447482  }
    448483  // rotate n vector (for consistency check)
    449   tmp = alignment.at(1);
    450   alignment.at(1) =  cos(alpha) * tmp +  sin(alpha) * alignment.at(2);
    451   alignment.at(2) = -sin(alpha) * tmp +  cos(alpha) * alignment.at(2);
    452 
    453   LOG(1, "alignment vector after second rotation: " << alignment);
     484  tmp = n->at(1);
     485  n->at(1) =  cos(alpha) * tmp +  sin(alpha) * n->at(2);
     486  n->at(2) = -sin(alpha) * tmp +  cos(alpha) * n->at(2);
     487
     488
     489  LOG(1, "alignment vector after second rotation: " << n);
    454490  LOG(0, "End of Aligning all atoms.");
    455491};
Note: See TracChangeset for help on using the changeset viewer.