Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_geometry.cpp

    ra67d19 r7fd416  
    2727  bool status = true;
    2828  const Vector *Center = DetermineCenterOfAll();
    29   double * const cell_size = World::get()->cell_size;
     29  const Vector *CenterBox = DetermineCenterOfBox();
     30  double * const cell_size = World::getInstance().getDomain();
    3031  double *M = ReturnFullMatrixforSymmetric(cell_size);
    3132  double *Minv = InverseMatrix(M);
    3233
    3334  // go through all atoms
    34   ActOnAllVectors( &Vector::SubtractVector, Center);
     35  ActOnAllVectors( &Vector::SubtractVector, *Center);
     36  ActOnAllVectors( &Vector::SubtractVector, *CenterBox);
    3537  ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
    3638
    37   Free(&M);
    38   Free(&Minv);
     39  delete[](M);
     40  delete[](Minv);
    3941  delete(Center);
    4042  return status;
     
    4850{
    4951  bool status = true;
    50   double * const cell_size = World::get()->cell_size;
     52  double * const cell_size = World::getInstance().getDomain();
    5153  double *M = ReturnFullMatrixforSymmetric(cell_size);
    5254  double *Minv = InverseMatrix(M);
     
    5557  ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
    5658
    57   Free(&M);
    58   Free(&Minv);
     59  delete[](M);
     60  delete[](Minv);
    5961  return status;
    6062};
     
    6971
    7072//  Log() << Verbose(3) << "Begin of CenterEdge." << endl;
    71   atom *ptr = start->next;  // start at first in list
    72   if (ptr != end) {  //list not empty?
     73  molecule::const_iterator iter = begin();  // start at first in list
     74  if (iter != end()) { //list not empty?
    7375    for (int i=NDIM;i--;) {
    74       max->x[i] = ptr->x.x[i];
    75       min->x[i] = ptr->x.x[i];
    76     }
    77     while (ptr->next != end) {  // continue with second if present
    78       ptr = ptr->next;
    79       //ptr->Output(1,1,out);
     76      max->at(i) = (*iter)->x[i];
     77      min->at(i) = (*iter)->x[i];
     78    }
     79    for (; iter != end(); ++iter) {// continue with second if present
     80      //(*iter)->Output(1,1,out);
    8081      for (int i=NDIM;i--;) {
    81         max->x[i] = (max->x[i] < ptr->x.x[i]) ? ptr->x.x[i] : max->x[i];
    82         min->x[i] = (min->x[i] > ptr->x.x[i]) ? ptr->x.x[i] : min->x[i];
     82        max->at(i) = (max->at(i) < (*iter)->x[i]) ? (*iter)->x[i] : max->at(i);
     83        min->at(i) = (min->at(i) > (*iter)->x[i]) ? (*iter)->x[i] : min->at(i);
    8384      }
    8485    }
     
    8990//    Log() << Verbose(0) << endl;
    9091    min->Scale(-1.);
    91     max->AddVector(min);
     92    (*max) += (*min);
    9293    Translate(min);
    9394    Center.Zero();
     
    104105{
    105106  int Num = 0;
    106   atom *ptr = start;  // start at first in list
     107  molecule::const_iterator iter = begin();  // start at first in list
    107108
    108109  Center.Zero();
    109110
    110   if (ptr->next != end) {   //list not empty?
    111     while (ptr->next != end) {  // continue with second if present
    112       ptr = ptr->next;
     111  if (iter != end()) {   //list not empty?
     112    for (; iter != end(); ++iter) {  // continue with second if present
    113113      Num++;
    114       Center.AddVector(&ptr->x);
     114      Center += (*iter)->x;
    115115    }
    116116    Center.Scale(-1./Num); // divide through total number (and sign for direction)
     
    125125Vector * molecule::DetermineCenterOfAll() const
    126126{
    127   atom *ptr = start->next;  // start at first in list
     127  molecule::const_iterator iter = begin();  // start at first in list
     128  Vector *a = new Vector();
     129  double Num = 0;
     130
     131  a->Zero();
     132
     133  if (iter != end()) {   //list not empty?
     134    for (; iter != end(); ++iter) {  // continue with second if present
     135      Num++;
     136      (*a) += (*iter)->x;
     137    }
     138    a->Scale(1./Num); // divide through total mass (and sign for direction)
     139  }
     140  return a;
     141};
     142
     143/** Returns vector pointing to center of the domain.
     144 * \return pointer to center of the domain
     145 */
     146Vector * molecule::DetermineCenterOfBox() const
     147{
     148  Vector *a = new Vector(0.5,0.5,0.5);
     149
     150  const double *cell_size = World::getInstance().getDomain();
     151  double *M = ReturnFullMatrixforSymmetric(cell_size);
     152  a->MatrixMultiplication(M);
     153  delete[](M);
     154
     155  return a;
     156};
     157
     158/** Returns vector pointing to center of gravity.
     159 * \param *out output stream for debugging
     160 * \return pointer to center of gravity vector
     161 */
     162Vector * molecule::DetermineCenterOfGravity()
     163{
     164  molecule::const_iterator iter = begin();  // start at first in list
    128165  Vector *a = new Vector();
    129166  Vector tmp;
     
    132169  a->Zero();
    133170
    134   if (ptr != end) {   //list not empty?
    135     while (ptr->next != end) {  // continue with second if present
    136       ptr = ptr->next;
    137       Num += 1.;
    138       tmp.CopyVector(&ptr->x);
    139       a->AddVector(&tmp);
     171  if (iter != end()) {   //list not empty?
     172    for (; iter != end(); ++iter) {  // continue with second if present
     173      Num += (*iter)->type->mass;
     174      tmp = (*iter)->type->mass * (*iter)->x;
     175      (*a) += tmp;
    140176    }
    141177    a->Scale(1./Num); // divide through total mass (and sign for direction)
    142   }
    143   return a;
    144 };
    145 
    146 /** Returns vector pointing to center of gravity.
    147  * \param *out output stream for debugging
    148  * \return pointer to center of gravity vector
    149  */
    150 Vector * molecule::DetermineCenterOfGravity()
    151 {
    152   atom *ptr = start->next;  // start at first in list
    153   Vector *a = new Vector();
    154   Vector tmp;
    155   double Num = 0;
    156 
    157   a->Zero();
    158 
    159   if (ptr != end) {   //list not empty?
    160     while (ptr->next != end) {  // continue with second if present
    161       ptr = ptr->next;
    162       Num += ptr->type->mass;
    163       tmp.CopyVector(&ptr->x);
    164       tmp.Scale(ptr->type->mass);  // scale by mass
    165       a->AddVector(&tmp);
    166     }
    167     a->Scale(-1./Num); // divide through total mass (and sign for direction)
    168178  }
    169179//  Log() << Verbose(1) << "Resulting center of gravity: ";
     
    189199void molecule::CenterAtVector(Vector *newcenter)
    190200{
    191   Center.CopyVector(newcenter);
     201  Center = *newcenter;
    192202};
    193203
     
    195205/** Scales all atoms by \a *factor.
    196206 * \param *factor pointer to scaling factor
     207 *
     208 * TODO: Is this realy what is meant, i.e.
     209 * x=(x[0]*factor[0],x[1]*factor[1],x[2]*factor[2]) (current impl)
     210 * or rather
     211 * x=(**factor) * x (as suggested by comment)
    197212 */
    198213void molecule::Scale(const double ** const factor)
    199214{
    200   atom *ptr = start;
    201 
    202   while (ptr->next != end) {
    203     ptr = ptr->next;
     215  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    204216    for (int j=0;j<MDSteps;j++)
    205       ptr->Trajectory.R.at(j).Scale(factor);
    206     ptr->x.Scale(factor);
     217      (*iter)->Trajectory.R.at(j).ScaleAll(*factor);
     218    (*iter)->x.ScaleAll(*factor);
    207219  }
    208220};
     
    213225void molecule::Translate(const Vector *trans)
    214226{
    215   atom *ptr = start;
    216 
    217   while (ptr->next != end) {
    218     ptr = ptr->next;
     227  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    219228    for (int j=0;j<MDSteps;j++)
    220       ptr->Trajectory.R.at(j).Translate(trans);
    221     ptr->x.Translate(trans);
     229      (*iter)->Trajectory.R.at(j) += (*trans);
     230    (*iter)->x += (*trans);
    222231  }
    223232};
     
    229238void molecule::TranslatePeriodically(const Vector *trans)
    230239{
    231   double * const cell_size = World::get()->cell_size;
     240  double * const cell_size = World::getInstance().getDomain();
    232241  double *M = ReturnFullMatrixforSymmetric(cell_size);
    233242  double *Minv = InverseMatrix(M);
    234243
    235244  // go through all atoms
    236   ActOnAllVectors( &Vector::SubtractVector, trans);
     245  ActOnAllVectors( &Vector::AddVector, *trans);
    237246  ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
    238247
    239   Free(&M);
    240   Free(&Minv);
     248  delete[](M);
     249  delete[](Minv);
    241250};
    242251
     
    247256void molecule::Mirror(const Vector *n)
    248257{
    249   ActOnAllVectors( &Vector::Mirror, n );
     258  ActOnAllVectors( &Vector::Mirror, *n );
    250259};
    251260
     
    255264void molecule::DeterminePeriodicCenter(Vector &center)
    256265{
    257   atom *Walker = start;
    258   double * const cell_size = World::get()->cell_size;
     266  double * const cell_size = World::getInstance().getDomain();
    259267  double *matrix = ReturnFullMatrixforSymmetric(cell_size);
    260   double *inversematrix = InverseMatrix(cell_size);
     268  double *inversematrix = InverseMatrix(matrix);
    261269  double tmp;
    262270  bool flag;
     
    266274    Center.Zero();
    267275    flag = true;
    268     while (Walker->next != end) {
    269       Walker = Walker->next;
     276    for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    270277#ifdef ADDHYDROGEN
    271       if (Walker->type->Z != 1) {
     278      if ((*iter)->type->Z != 1) {
    272279#endif
    273         Testvector.CopyVector(&Walker->x);
     280        Testvector = (*iter)->x;
    274281        Testvector.MatrixMultiplication(inversematrix);
    275282        Translationvector.Zero();
    276         for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
    277          if (Walker->nr < (*Runner)->GetOtherAtom(Walker)->nr) // otherwise we shift one to, the other fro and gain nothing
     283        for (BondList::const_iterator Runner = (*iter)->ListOfBonds.begin(); Runner != (*iter)->ListOfBonds.end(); (++Runner)) {
     284         if ((*iter)->nr < (*Runner)->GetOtherAtom((*iter))->nr) // otherwise we shift one to, the other fro and gain nothing
    278285            for (int j=0;j<NDIM;j++) {
    279               tmp = Walker->x.x[j] - (*Runner)->GetOtherAtom(Walker)->x.x[j];
     286              tmp = (*iter)->x[j] - (*Runner)->GetOtherAtom(*iter)->x[j];
    280287              if ((fabs(tmp)) > BondDistance) {
    281288                flag = false;
    282                 DoLog(0) && (Log() << Verbose(0) << "Hit: atom " << Walker->Name << " in bond " << *(*Runner) << " has to be shifted due to " << tmp << "." << endl);
     289                DoLog(0) && (Log() << Verbose(0) << "Hit: atom " << (*iter)->getName() << " in bond " << *(*Runner) << " has to be shifted due to " << tmp << "." << endl);
    283290                if (tmp > 0)
    284                   Translationvector.x[j] -= 1.;
     291                  Translationvector[j] -= 1.;
    285292                else
    286                   Translationvector.x[j] += 1.;
     293                  Translationvector[j] += 1.;
    287294              }
    288295            }
    289296        }
    290         Testvector.AddVector(&Translationvector);
     297        Testvector += Translationvector;
    291298        Testvector.MatrixMultiplication(matrix);
    292         Center.AddVector(&Testvector);
    293         DoLog(1) && (Log() << Verbose(1) << "vector is: ");
    294         Testvector.Output();
    295         DoLog(0) && (Log() << Verbose(0) << endl);
     299        Center += Testvector;
     300        Log() << Verbose(1) << "vector is: " << Testvector << endl;
    296301#ifdef ADDHYDROGEN
    297302        // now also change all hydrogens
    298         for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
    299           if ((*Runner)->GetOtherAtom(Walker)->type->Z == 1) {
    300             Testvector.CopyVector(&(*Runner)->GetOtherAtom(Walker)->x);
     303        for (BondList::const_iterator Runner = (*iter)->ListOfBonds.begin(); Runner != (*iter)->ListOfBonds.end(); (++Runner)) {
     304          if ((*Runner)->GetOtherAtom((*iter))->type->Z == 1) {
     305            Testvector = (*Runner)->GetOtherAtom((*iter))->x;
    301306            Testvector.MatrixMultiplication(inversematrix);
    302             Testvector.AddVector(&Translationvector);
     307            Testvector += Translationvector;
    303308            Testvector.MatrixMultiplication(matrix);
    304             Center.AddVector(&Testvector);
    305             DoLog(1) && (Log() << Verbose(1) << "Hydrogen vector is: ");
    306             Testvector.Output();
    307             DoLog(0) && (Log() << Verbose(0) << endl);
     309            Center += Testvector;
     310            Log() << Verbose(1) << "Hydrogen vector is: " << Testvector << endl;
    308311          }
    309312        }
     
    312315    }
    313316  } while (!flag);
    314   Free(&matrix);
    315   Free(&inversematrix);
    316 
    317   Center.Scale(1./(double)AtomCount);
     317  delete[](matrix);
     318  delete[](inversematrix);
     319
     320  Center.Scale(1./static_cast<double>(getAtomCount()));
    318321};
    319322
     
    325328void molecule::PrincipalAxisSystem(bool DoRotate)
    326329{
    327   atom *ptr = start;  // start at first in list
    328330  double InertiaTensor[NDIM*NDIM];
    329331  Vector *CenterOfGravity = DetermineCenterOfGravity();
     
    336338
    337339  // sum up inertia tensor
    338   while (ptr->next != end) {
    339     ptr = ptr->next;
    340     Vector x;
    341     x.CopyVector(&ptr->x);
     340  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     341    Vector x = (*iter)->x;
    342342    //x.SubtractVector(CenterOfGravity);
    343     InertiaTensor[0] += ptr->type->mass*(x.x[1]*x.x[1] + x.x[2]*x.x[2]);
    344     InertiaTensor[1] += ptr->type->mass*(-x.x[0]*x.x[1]);
    345     InertiaTensor[2] += ptr->type->mass*(-x.x[0]*x.x[2]);
    346     InertiaTensor[3] += ptr->type->mass*(-x.x[1]*x.x[0]);
    347     InertiaTensor[4] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[2]*x.x[2]);
    348     InertiaTensor[5] += ptr->type->mass*(-x.x[1]*x.x[2]);
    349     InertiaTensor[6] += ptr->type->mass*(-x.x[2]*x.x[0]);
    350     InertiaTensor[7] += ptr->type->mass*(-x.x[2]*x.x[1]);
    351     InertiaTensor[8] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[1]*x.x[1]);
     343    InertiaTensor[0] += (*iter)->type->mass*(x[1]*x[1] + x[2]*x[2]);
     344    InertiaTensor[1] += (*iter)->type->mass*(-x[0]*x[1]);
     345    InertiaTensor[2] += (*iter)->type->mass*(-x[0]*x[2]);
     346    InertiaTensor[3] += (*iter)->type->mass*(-x[1]*x[0]);
     347    InertiaTensor[4] += (*iter)->type->mass*(x[0]*x[0] + x[2]*x[2]);
     348    InertiaTensor[5] += (*iter)->type->mass*(-x[1]*x[2]);
     349    InertiaTensor[6] += (*iter)->type->mass*(-x[2]*x[0]);
     350    InertiaTensor[7] += (*iter)->type->mass*(-x[2]*x[1]);
     351    InertiaTensor[8] += (*iter)->type->mass*(x[0]*x[0] + x[1]*x[1]);
    352352  }
    353353  // print InertiaTensor for debugging
     
    387387
    388388    // sum up inertia tensor
    389     ptr = start;
    390     while (ptr->next != end) {
    391       ptr = ptr->next;
    392       Vector x;
    393       x.CopyVector(&ptr->x);
    394       //x.SubtractVector(CenterOfGravity);
    395       InertiaTensor[0] += ptr->type->mass*(x.x[1]*x.x[1] + x.x[2]*x.x[2]);
    396       InertiaTensor[1] += ptr->type->mass*(-x.x[0]*x.x[1]);
    397       InertiaTensor[2] += ptr->type->mass*(-x.x[0]*x.x[2]);
    398       InertiaTensor[3] += ptr->type->mass*(-x.x[1]*x.x[0]);
    399       InertiaTensor[4] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[2]*x.x[2]);
    400       InertiaTensor[5] += ptr->type->mass*(-x.x[1]*x.x[2]);
    401       InertiaTensor[6] += ptr->type->mass*(-x.x[2]*x.x[0]);
    402       InertiaTensor[7] += ptr->type->mass*(-x.x[2]*x.x[1]);
    403       InertiaTensor[8] += ptr->type->mass*(x.x[0]*x.x[0] + x.x[1]*x.x[1]);
     389    for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     390      Vector x = (*iter)->x;
     391      InertiaTensor[0] += (*iter)->type->mass*(x[1]*x[1] + x[2]*x[2]);
     392      InertiaTensor[1] += (*iter)->type->mass*(-x[0]*x[1]);
     393      InertiaTensor[2] += (*iter)->type->mass*(-x[0]*x[2]);
     394      InertiaTensor[3] += (*iter)->type->mass*(-x[1]*x[0]);
     395      InertiaTensor[4] += (*iter)->type->mass*(x[0]*x[0] + x[2]*x[2]);
     396      InertiaTensor[5] += (*iter)->type->mass*(-x[1]*x[2]);
     397      InertiaTensor[6] += (*iter)->type->mass*(-x[2]*x[0]);
     398      InertiaTensor[7] += (*iter)->type->mass*(-x[2]*x[1]);
     399      InertiaTensor[8] += (*iter)->type->mass*(x[0]*x[0] + x[1]*x[1]);
    404400    }
    405401    // print InertiaTensor for debugging
     
    425421void molecule::Align(Vector *n)
    426422{
    427   atom *ptr = start;
    428423  double alpha, tmp;
    429424  Vector z_axis;
    430   z_axis.x[0] = 0.;
    431   z_axis.x[1] = 0.;
    432   z_axis.x[2] = 1.;
     425  z_axis[0] = 0.;
     426  z_axis[1] = 0.;
     427  z_axis[2] = 1.;
    433428
    434429  // rotate on z-x plane
    435430  DoLog(0) && (Log() << Verbose(0) << "Begin of Aligning all atoms." << endl);
    436   alpha = atan(-n->x[0]/n->x[2]);
     431  alpha = atan(-n->at(0)/n->at(2));
    437432  DoLog(1) && (Log() << Verbose(1) << "Z-X-angle: " << alpha << " ... ");
    438   while (ptr->next != end) {
    439     ptr = ptr->next;
    440     tmp = ptr->x.x[0];
    441     ptr->x.x[0] =  cos(alpha) * tmp + sin(alpha) * ptr->x.x[2];
    442     ptr->x.x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x.x[2];
     433  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     434    tmp = (*iter)->x[0];
     435    (*iter)->x[0] =  cos(alpha) * tmp + sin(alpha) * (*iter)->x[2];
     436    (*iter)->x[2] = -sin(alpha) * tmp + cos(alpha) * (*iter)->x[2];
    443437    for (int j=0;j<MDSteps;j++) {
    444       tmp = ptr->Trajectory.R.at(j).x[0];
    445       ptr->Trajectory.R.at(j).x[0] =  cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j).x[2];
    446       ptr->Trajectory.R.at(j).x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j).x[2];
     438      tmp = (*iter)->Trajectory.R.at(j)[0];
     439      (*iter)->Trajectory.R.at(j)[0] =  cos(alpha) * tmp + sin(alpha) * (*iter)->Trajectory.R.at(j)[2];
     440      (*iter)->Trajectory.R.at(j)[2] = -sin(alpha) * tmp + cos(alpha) * (*iter)->Trajectory.R.at(j)[2];
    447441    }
    448442  }
    449443  // rotate n vector
    450   tmp = n->x[0];
    451   n->x[0] =  cos(alpha) * tmp +  sin(alpha) * n->x[2];
    452   n->x[2] = -sin(alpha) * tmp +  cos(alpha) * n->x[2];
    453   DoLog(1) && (Log() << Verbose(1) << "alignment vector after first rotation: ");
    454   n->Output();
    455   DoLog(0) && (Log() << Verbose(0) << endl);
     444  tmp = n->at(0);
     445  n->at(0) =  cos(alpha) * tmp +  sin(alpha) * n->at(2);
     446  n->at(2) = -sin(alpha) * tmp +  cos(alpha) * n->at(2);
     447  DoLog(1) && (Log() << Verbose(1) << "alignment vector after first rotation: " << n << endl);
    456448
    457449  // rotate on z-y plane
    458   ptr = start;
    459   alpha = atan(-n->x[1]/n->x[2]);
     450  alpha = atan(-n->at(1)/n->at(2));
    460451  DoLog(1) && (Log() << Verbose(1) << "Z-Y-angle: " << alpha << " ... ");
    461   while (ptr->next != end) {
    462     ptr = ptr->next;
    463     tmp = ptr->x.x[1];
    464     ptr->x.x[1] =  cos(alpha) * tmp + sin(alpha) * ptr->x.x[2];
    465     ptr->x.x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x.x[2];
     452  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     453    tmp = (*iter)->x[1];
     454    (*iter)->x[1] =  cos(alpha) * tmp + sin(alpha) * (*iter)->x[2];
     455    (*iter)->x[2] = -sin(alpha) * tmp + cos(alpha) * (*iter)->x[2];
    466456    for (int j=0;j<MDSteps;j++) {
    467       tmp = ptr->Trajectory.R.at(j).x[1];
    468       ptr->Trajectory.R.at(j).x[1] =  cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j).x[2];
    469       ptr->Trajectory.R.at(j).x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j).x[2];
     457      tmp = (*iter)->Trajectory.R.at(j)[1];
     458      (*iter)->Trajectory.R.at(j)[1] =  cos(alpha) * tmp + sin(alpha) * (*iter)->Trajectory.R.at(j)[2];
     459      (*iter)->Trajectory.R.at(j)[2] = -sin(alpha) * tmp + cos(alpha) * (*iter)->Trajectory.R.at(j)[2];
    470460    }
    471461  }
    472462  // rotate n vector (for consistency check)
    473   tmp = n->x[1];
    474   n->x[1] =  cos(alpha) * tmp +  sin(alpha) * n->x[2];
    475   n->x[2] = -sin(alpha) * tmp +  cos(alpha) * n->x[2];
    476 
    477   DoLog(1) && (Log() << Verbose(1) << "alignment vector after second rotation: ");
    478   n->Output();
    479   DoLog(1) && (Log() << Verbose(1) << endl);
     463  tmp = n->at(1);
     464  n->at(1) =  cos(alpha) * tmp +  sin(alpha) * n->at(2);
     465  n->at(2) = -sin(alpha) * tmp +  cos(alpha) * n->at(2);
     466
     467
     468  DoLog(1) && (Log() << Verbose(1) << "alignment vector after second rotation: " << n << endl);
    480469  DoLog(0) && (Log() << Verbose(0) << "End of Aligning all atoms." << endl);
    481470};
     
    492481  Vector a,b,c,d;
    493482  struct lsq_params *par = (struct lsq_params *)params;
    494   atom *ptr = par->mol->start;
    495483
    496484  // initialize vectors
    497   a.x[0] = gsl_vector_get(x,0);
    498   a.x[1] = gsl_vector_get(x,1);
    499   a.x[2] = gsl_vector_get(x,2);
    500   b.x[0] = gsl_vector_get(x,3);
    501   b.x[1] = gsl_vector_get(x,4);
    502   b.x[2] = gsl_vector_get(x,5);
     485  a[0] = gsl_vector_get(x,0);
     486  a[1] = gsl_vector_get(x,1);
     487  a[2] = gsl_vector_get(x,2);
     488  b[0] = gsl_vector_get(x,3);
     489  b[1] = gsl_vector_get(x,4);
     490  b[2] = gsl_vector_get(x,5);
    503491  // go through all atoms
    504   while (ptr != par->mol->end) {
    505     ptr = ptr->next;
    506     if (ptr->type == ((struct lsq_params *)params)->type) { // for specific type
    507       c.CopyVector(&ptr->x);  // copy vector to temporary one
    508       c.SubtractVector(&a);   // subtract offset vector
    509       t = c.ScalarProduct(&b);           // get direction parameter
    510       d.CopyVector(&b);       // and create vector
    511       d.Scale(&t);
    512       c.SubtractVector(&d);   // ... yielding distance vector
    513       res += d.ScalarProduct((const Vector *)&d);        // add squared distance
     492  for (molecule::const_iterator iter = par->mol->begin(); iter != par->mol->end(); ++iter) {
     493    if ((*iter)->type == ((struct lsq_params *)params)->type) { // for specific type
     494      c = (*iter)->x - a;
     495      t = c.ScalarProduct(b);           // get direction parameter
     496      d = t*b;       // and create vector
     497      c -= d;   // ... yielding distance vector
     498      res += d.ScalarProduct(d);        // add squared distance
    514499    }
    515500  }
Note: See TracChangeset for help on using the changeset viewer.