Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_dynamics.cpp

    r1513a74 r112b09  
    66 */
    77
     8#include "Helpers/MemDebug.hpp"
     9
    810#include "World.hpp"
    911#include "atom.hpp"
    1012#include "config.hpp"
    1113#include "element.hpp"
     14#include "info.hpp"
    1215#include "log.hpp"
    1316#include "memoryallocator.hpp"
     
    2831  gsl_matrix *A = gsl_matrix_alloc(NDIM,NDIM);
    2932  gsl_vector *x = gsl_vector_alloc(NDIM);
    30   atom * Runner = mol->start;
    3133  atom *Sprinter = NULL;
    3234  Vector trajectory1, trajectory2, normal, TestVector;
    3335  double Norm1, Norm2, tmp, result = 0.;
    3436
    35   while (Runner->next != mol->end) {
    36     Runner = Runner->next;
    37     if (Runner == Walker) // hence, we only go up to the Walker, not beyond (similar to i=0; i<j; i++)
     37  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     38    if ((*iter) == Walker) // hence, we only go up to the Walker, not beyond (similar to i=0; i<j; i++)
    3839      break;
    3940    // determine normalized trajectories direction vector (n1, n2)
     
    4243    trajectory1.Normalize();
    4344    Norm1 = trajectory1.Norm();
    44     Sprinter = Params.PermutationMap[Runner->nr];   // find second target point
    45     trajectory2 = Sprinter->Trajectory.R.at(Params.endstep) - Runner->Trajectory.R.at(Params.startstep);
     45    Sprinter = Params.PermutationMap[(*iter)->nr];   // find second target point
     46    trajectory2 = Sprinter->Trajectory.R.at(Params.endstep) - (*iter)->Trajectory.R.at(Params.startstep);
    4647    trajectory2.Normalize();
    4748    Norm2 = trajectory1.Norm();
    4849    // check whether either is zero()
    4950    if ((Norm1 < MYEPSILON) && (Norm2 < MYEPSILON)) {
    50       tmp = Walker->Trajectory.R.at(Params.startstep).distance(Runner->Trajectory.R.at(Params.startstep));
     51      tmp = Walker->Trajectory.R.at(Params.startstep).distance((*iter)->Trajectory.R.at(Params.startstep));
    5152    } else if (Norm1 < MYEPSILON) {
    5253      Sprinter = Params.PermutationMap[Walker->nr];   // find first target point
    53       trajectory1 = Sprinter->Trajectory.R.at(Params.endstep) - Runner->Trajectory.R.at(Params.startstep);
     54      trajectory1 = Sprinter->Trajectory.R.at(Params.endstep) - (*iter)->Trajectory.R.at(Params.startstep);
    5455      trajectory2 *= trajectory1.ScalarProduct(trajectory2); // trajectory2 is scaled to unity, hence we don't need to divide by anything
    5556      trajectory1 -= trajectory2;   // project the part in norm direction away
    5657      tmp = trajectory1.Norm();  // remaining norm is distance
    5758    } else if (Norm2 < MYEPSILON) {
    58       Sprinter = Params.PermutationMap[Runner->nr];   // find second target point
     59      Sprinter = Params.PermutationMap[(*iter)->nr];   // find second target point
    5960      trajectory2 = Sprinter->Trajectory.R.at(Params.endstep) - Walker->Trajectory.R.at(Params.startstep);  // copy second offset
    6061      trajectory1 *= trajectory2.ScalarProduct(trajectory1); // trajectory1 is scaled to unity, hence we don't need to divide by anything
     
    6667  //        Log() << Verbose(0) << " and ";
    6768  //        Log() << Verbose(0) << trajectory2;
    68       tmp = Walker->Trajectory.R.at(Params.startstep).distance(Runner->Trajectory.R.at(Params.startstep));
     69      tmp = Walker->Trajectory.R.at(Params.startstep).distance((*iter)->Trajectory.R.at(Params.startstep));
    6970  //        Log() << Verbose(0) << " with distance " << tmp << "." << endl;
    7071    } else { // determine distance by finding minimum distance
    71   //        Log() << Verbose(3) << "Both trajectories of " << *Walker << " and " << *Runner << " are linear independent ";
     72  //        Log() << Verbose(3) << "Both trajectories of " << *Walker << " and " << *(*iter) << " are linear independent ";
    7273  //        Log() << Verbose(0) << endl;
    7374  //        Log() << Verbose(0) << "First Trajectory: ";
     
    8586        gsl_matrix_set(A, 1, i, trajectory2[i]);
    8687        gsl_matrix_set(A, 2, i, normal[i]);
    87         gsl_vector_set(x,i, (Walker->Trajectory.R.at(Params.startstep)[i] - Runner->Trajectory.R.at(Params.startstep)[i]));
     88        gsl_vector_set(x,i, (Walker->Trajectory.R.at(Params.startstep)[i] - (*iter)->Trajectory.R.at(Params.startstep)[i]));
    8889      }
    8990      // solve the linear system by Householder transformations
     
    9697      trajectory2.Scale(gsl_vector_get(x,1));
    9798      normal.Scale(gsl_vector_get(x,2));
    98       TestVector = Runner->Trajectory.R.at(Params.startstep) + trajectory2 + normal
     99      TestVector = (*iter)->Trajectory.R.at(Params.startstep) + trajectory2 + normal
    99100                   - (Walker->Trajectory.R.at(Params.startstep) + trajectory1);
    100101      if (TestVector.Norm() < MYEPSILON) {
     
    125126{
    126127  double result = 0.;
    127   atom * Runner = mol->start;
    128   while (Runner->next != mol->end) {
    129     Runner = Runner->next;
    130     if ((Params.PermutationMap[Walker->nr] == Params.PermutationMap[Runner->nr]) && (Walker->nr < Runner->nr)) {
     128  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     129    if ((Params.PermutationMap[Walker->nr] == Params.PermutationMap[(*iter)->nr]) && (Walker->nr < (*iter)->nr)) {
    131130  //    atom *Sprinter = PermutationMap[Walker->nr];
    132   //        Log() << Verbose(0) << *Walker << " and " << *Runner << " are heading to the same target at ";
     131  //        Log() << Verbose(0) << *Walker << " and " << *(*iter) << " are heading to the same target at ";
    133132  //        Log() << Verbose(0) << Sprinter->Trajectory.R.at(endstep);
    134133  //        Log() << Verbose(0) << ", penalting." << endl;
     
    161160  // go through every atom
    162161  atom *Runner = NULL;
    163   atom *Walker = start;
    164   while (Walker->next != end) {
    165     Walker = Walker->next;
     162  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    166163    // first term: distance to target
    167     Runner = Params.PermutationMap[Walker->nr];   // find target point
    168     tmp = (Walker->Trajectory.R.at(Params.startstep).distance(Runner->Trajectory.R.at(Params.endstep)));
     164    Runner = Params.PermutationMap[(*iter)->nr];   // find target point
     165    tmp = ((*iter)->Trajectory.R.at(Params.startstep).distance(Runner->Trajectory.R.at(Params.endstep)));
    169166    tmp *= Params.IsAngstroem ? 1. : 1./AtomicLengthToAngstroem;
    170167    result += Params.PenaltyConstants[0] * tmp;
     
    172169
    173170    // second term: sum of distances to other trajectories
    174     result += SumDistanceOfTrajectories(Walker, this, Params);
     171    result += SumDistanceOfTrajectories((*iter), this, Params);
    175172
    176173    // third term: penalty for equal targets
    177     result += PenalizeEqualTargets(Walker, this, Params);
     174    result += PenalizeEqualTargets((*iter), this, Params);
    178175  }
    179176
     
    189186{
    190187  stringstream zeile1, zeile2;
    191   int *DoubleList = Calloc<int>(AtomCount, "PrintPermutationMap: *DoubleList");
     188  int *DoubleList = new int[AtomCount];
     189  for(int i=0;i<AtomCount;i++)
     190    DoubleList[i] = 0;
    192191  int doubles = 0;
    193192  zeile1 << "PermutationMap: ";
     
    203202  if (doubles >0)
    204203    DoLog(2) && (Log() << Verbose(2) << "Found " << doubles << " Doubles." << endl);
    205   Free(&DoubleList);
     204  delete[](DoubleList);
    206205//  Log() << Verbose(2) << zeile1.str() << endl << zeile2.str() << endl;
    207206};
     
    213212void FillDistanceList(molecule *mol, struct EvaluatePotential &Params)
    214213{
    215   for (int i=mol->AtomCount; i--;) {
     214  for (int i=mol->getAtomCount(); i--;) {
    216215    Params.DistanceList[i] = new DistanceMap;    // is the distance sorted target list per atom
    217216    Params.DistanceList[i]->clear();
    218217  }
    219218
    220   atom *Runner = NULL;
    221   atom *Walker = mol->start;
    222   while (Walker->next != mol->end) {
    223     Walker = Walker->next;
    224     Runner = mol->start;
    225     while(Runner->next != mol->end) {
    226       Runner = Runner->next;
    227       Params.DistanceList[Walker->nr]->insert( DistancePair(Walker->Trajectory.R.at(Params.startstep).distance(Runner->Trajectory.R.at(Params.endstep)), Runner) );
     219  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     220    for (molecule::const_iterator runner = mol->begin(); runner != mol->end(); ++runner) {
     221      Params.DistanceList[(*iter)->nr]->insert( DistancePair((*iter)->Trajectory.R.at(Params.startstep).distance((*runner)->Trajectory.R.at(Params.endstep)), (*runner)) );
    228222    }
    229223  }
     
    237231void CreateInitialLists(molecule *mol, struct EvaluatePotential &Params)
    238232{
    239   atom *Walker = mol->start;
    240   while (Walker->next != mol->end) {
    241     Walker = Walker->next;
    242     Params.StepList[Walker->nr] = Params.DistanceList[Walker->nr]->begin();    // stores the step to the next iterator that could be a possible next target
    243     Params.PermutationMap[Walker->nr] = Params.DistanceList[Walker->nr]->begin()->second;   // always pick target with the smallest distance
    244     Params.DoubleList[Params.DistanceList[Walker->nr]->begin()->second->nr]++;            // increase this target's source count (>1? not injective)
    245     Params.DistanceIterators[Walker->nr] = Params.DistanceList[Walker->nr]->begin();    // and remember which one we picked
    246     DoLog(2) && (Log() << Verbose(2) << *Walker << " starts with distance " << Params.DistanceList[Walker->nr]->begin()->first << "." << endl);
     233  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     234    Params.StepList[(*iter)->nr] = Params.DistanceList[(*iter)->nr]->begin();    // stores the step to the next iterator that could be a possible next target
     235    Params.PermutationMap[(*iter)->nr] = Params.DistanceList[(*iter)->nr]->begin()->second;   // always pick target with the smallest distance
     236    Params.DoubleList[Params.DistanceList[(*iter)->nr]->begin()->second->nr]++;            // increase this target's source count (>1? not injective)
     237    Params.DistanceIterators[(*iter)->nr] = Params.DistanceList[(*iter)->nr]->begin();    // and remember which one we picked
     238    DoLog(2) && (Log() << Verbose(2) << **iter << " starts with distance " << Params.DistanceList[(*iter)->nr]->begin()->first << "." << endl);
    247239  }
    248240};
     
    285277void MakeInjectivePermutation(molecule *mol, struct EvaluatePotential &Params)
    286278{
    287   atom *Walker = mol->start;
     279  molecule::const_iterator iter = mol->begin();
    288280  DistanceMap::iterator NewBase;
    289281  double Potential = fabs(mol->ConstrainedPotential(Params));
    290282
     283  if (mol->empty()) {
     284    eLog() << Verbose(1) << "Molecule is empty." << endl;
     285    return;
     286  }
    291287  while ((Potential) > Params.PenaltyConstants[2]) {
    292     PrintPermutationMap(mol->AtomCount, Params);
    293     Walker = Walker->next;
    294     if (Walker == mol->end) // round-robin at the end
    295       Walker = mol->start->next;
    296     if (Params.DoubleList[Params.DistanceIterators[Walker->nr]->second->nr] <= 1)  // no need to make those injective that aren't
     288    PrintPermutationMap(mol->getAtomCount(), Params);
     289    iter++;
     290    if (iter == mol->end()) // round-robin at the end
     291      iter = mol->begin();
     292    if (Params.DoubleList[Params.DistanceIterators[(*iter)->nr]->second->nr] <= 1)  // no need to make those injective that aren't
    297293      continue;
    298294    // now, try finding a new one
    299     Potential = TryNextNearestNeighbourForInjectivePermutation(mol, Walker, Potential, Params);
    300   }
    301   for (int i=mol->AtomCount; i--;) // now each single entry in the DoubleList should be <=1
     295    Potential = TryNextNearestNeighbourForInjectivePermutation(mol, (*iter), Potential, Params);
     296  }
     297  for (int i=mol->getAtomCount(); i--;) // now each single entry in the DoubleList should be <=1
    302298    if (Params.DoubleList[i] > 1) {
    303299      DoeLog(0) && (eLog()<< Verbose(0) << "Failed to create an injective PermutationMap!" << endl);
     
    338334  double Potential, OldPotential, OlderPotential;
    339335  struct EvaluatePotential Params;
    340   Params.PermutationMap = Calloc<atom*>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.**PermutationMap");
    341   Params.DistanceList = Malloc<DistanceMap*>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.**DistanceList");
    342   Params.DistanceIterators = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*DistanceIterators");
    343   Params.DoubleList = Calloc<int>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*DoubleList");
    344   Params.StepList = Malloc<DistanceMap::iterator>(AtomCount, "molecule::MinimiseConstrainedPotential: Params.*StepList");
     336  Params.PermutationMap = new atom *[getAtomCount()];
     337  Params.DistanceList = new DistanceMap *[getAtomCount()];
     338  Params.DistanceIterators = new DistanceMap::iterator[getAtomCount()];
     339  Params.DoubleList = new int[getAtomCount()];
     340  Params.StepList = new DistanceMap::iterator[getAtomCount()];
    345341  int round;
    346   atom *Walker = NULL, *Runner = NULL, *Sprinter = NULL;
     342  atom *Sprinter = NULL;
    347343  DistanceMap::iterator Rider, Strider;
     344
     345  // set to zero
     346  for (int i=0;i<getAtomCount();i++) {
     347    Params.PermutationMap[i] = NULL;
     348    Params.DoubleList[i] = 0;
     349  }
    348350
    349351  /// Minimise the potential
     
    362364  DoLog(1) && (Log() << Verbose(1) << "Making the PermutationMap injective ... " << endl);
    363365  MakeInjectivePermutation(this, Params);
    364   Free(&Params.DoubleList);
     366  delete[](Params.DoubleList);
    365367
    366368  // argument minimise the constrained potential in this injective PermutationMap
     
    371373    DoLog(2) && (Log() << Verbose(2) << "Starting round " << ++round << ", at current potential " << OldPotential << " ... " << endl);
    372374    OlderPotential = OldPotential;
     375    molecule::const_iterator iter;
    373376    do {
    374       Walker = start;
    375       while (Walker->next != end) { // pick one
    376         Walker = Walker->next;
    377         PrintPermutationMap(AtomCount, Params);
    378         Sprinter = Params.DistanceIterators[Walker->nr]->second;   // store initial partner
    379         Strider = Params.DistanceIterators[Walker->nr];  //remember old iterator
    380         Params.DistanceIterators[Walker->nr] = Params.StepList[Walker->nr];
    381         if (Params.DistanceIterators[Walker->nr] == Params.DistanceList[Walker->nr]->end()) {// stop, before we run through the list and still on
    382           Params.DistanceIterators[Walker->nr] == Params.DistanceList[Walker->nr]->begin();
     377      iter = begin();
     378      for (; iter != end(); ++iter) {
     379        PrintPermutationMap(getAtomCount(), Params);
     380        Sprinter = Params.DistanceIterators[(*iter)->nr]->second;   // store initial partner
     381        Strider = Params.DistanceIterators[(*iter)->nr];  //remember old iterator
     382        Params.DistanceIterators[(*iter)->nr] = Params.StepList[(*iter)->nr];
     383        if (Params.DistanceIterators[(*iter)->nr] == Params.DistanceList[(*iter)->nr]->end()) {// stop, before we run through the list and still on
     384          Params.DistanceIterators[(*iter)->nr] == Params.DistanceList[(*iter)->nr]->begin();
    383385          break;
    384386        }
    385         //Log() << Verbose(2) << "Current Walker: " << *Walker << " with old/next candidate " << *Sprinter << "/" << *DistanceIterators[Walker->nr]->second << "." << endl;
     387        //Log() << Verbose(2) << "Current Walker: " << *(*iter) << " with old/next candidate " << *Sprinter << "/" << *DistanceIterators[(*iter)->nr]->second << "." << endl;
    386388        // find source of the new target
    387         Runner = start->next;
    388         while(Runner != end) { // find the source whose toes we might be stepping on (Walker's new target should be in use by another already)
    389           if (Params.PermutationMap[Runner->nr] == Params.DistanceIterators[Walker->nr]->second) {
    390             //Log() << Verbose(2) << "Found the corresponding owner " << *Runner << " to " << *PermutationMap[Runner->nr] << "." << endl;
     389        molecule::const_iterator runner = begin();
     390        for (; runner != end(); ++runner) { // find the source whose toes we might be stepping on (Walker's new target should be in use by another already)
     391          if (Params.PermutationMap[(*runner)->nr] == Params.DistanceIterators[(*iter)->nr]->second) {
     392            //Log() << Verbose(2) << "Found the corresponding owner " << *(*runner) << " to " << *PermutationMap[(*runner)->nr] << "." << endl;
    391393            break;
    392394          }
    393           Runner = Runner->next;
    394395        }
    395         if (Runner != end) { // we found the other source
     396        if (runner != end()) { // we found the other source
    396397          // then look in its distance list for Sprinter
    397           Rider = Params.DistanceList[Runner->nr]->begin();
    398           for (; Rider != Params.DistanceList[Runner->nr]->end(); Rider++)
     398          Rider = Params.DistanceList[(*runner)->nr]->begin();
     399          for (; Rider != Params.DistanceList[(*runner)->nr]->end(); Rider++)
    399400            if (Rider->second == Sprinter)
    400401              break;
    401           if (Rider != Params.DistanceList[Runner->nr]->end()) { // if we have found one
    402             //Log() << Verbose(2) << "Current Other: " << *Runner << " with old/next candidate " << *PermutationMap[Runner->nr] << "/" << *Rider->second << "." << endl;
     402          if (Rider != Params.DistanceList[(*runner)->nr]->end()) { // if we have found one
     403            //Log() << Verbose(2) << "Current Other: " << *(*runner) << " with old/next candidate " << *PermutationMap[(*runner)->nr] << "/" << *Rider->second << "." << endl;
    403404            // exchange both
    404             Params.PermutationMap[Walker->nr] = Params.DistanceIterators[Walker->nr]->second; // put next farther distance into PermutationMap
    405             Params.PermutationMap[Runner->nr] = Sprinter;  // and hand the old target to its respective owner
    406             PrintPermutationMap(AtomCount, Params);
     405            Params.PermutationMap[(*iter)->nr] = Params.DistanceIterators[(*iter)->nr]->second; // put next farther distance into PermutationMap
     406            Params.PermutationMap[(*runner)->nr] = Sprinter;  // and hand the old target to its respective owner
     407            PrintPermutationMap(getAtomCount(), Params);
    407408            // calculate the new potential
    408409            //Log() << Verbose(2) << "Checking new potential ..." << endl;
     
    410411            if (Potential > OldPotential) { // we made everything worse! Undo ...
    411412              //Log() << Verbose(3) << "Nay, made the potential worse: " << Potential << " vs. " << OldPotential << "!" << endl;
    412               //Log() << Verbose(3) << "Setting " << *Runner << "'s source to " << *Params.DistanceIterators[Runner->nr]->second << "." << endl;
     413              //Log() << Verbose(3) << "Setting " << *(*runner) << "'s source to " << *Params.DistanceIterators[(*runner)->nr]->second << "." << endl;
    413414              // Undo for Runner (note, we haven't moved the iteration yet, we may use this)
    414               Params.PermutationMap[Runner->nr] = Params.DistanceIterators[Runner->nr]->second;
     415              Params.PermutationMap[(*runner)->nr] = Params.DistanceIterators[(*runner)->nr]->second;
    415416              // Undo for Walker
    416               Params.DistanceIterators[Walker->nr] = Strider;  // take next farther distance target
    417               //Log() << Verbose(3) << "Setting " << *Walker << "'s source to " << *Params.DistanceIterators[Walker->nr]->second << "." << endl;
    418               Params.PermutationMap[Walker->nr] = Params.DistanceIterators[Walker->nr]->second;
     417              Params.DistanceIterators[(*iter)->nr] = Strider;  // take next farther distance target
     418              //Log() << Verbose(3) << "Setting " << *(*iter) << "'s source to " << *Params.DistanceIterators[(*iter)->nr]->second << "." << endl;
     419              Params.PermutationMap[(*iter)->nr] = Params.DistanceIterators[(*iter)->nr]->second;
    419420            } else {
    420               Params.DistanceIterators[Runner->nr] = Rider;  // if successful also move the pointer in the iterator list
     421              Params.DistanceIterators[(*runner)->nr] = Rider;  // if successful also move the pointer in the iterator list
    421422              DoLog(3) && (Log() << Verbose(3) << "Found a better permutation, new potential is " << Potential << " vs." << OldPotential << "." << endl);
    422423              OldPotential = Potential;
     
    428429            //Log() << Verbose(0) << endl;
    429430          } else {
    430             DoeLog(1) && (eLog()<< Verbose(1) << *Runner << " was not the owner of " << *Sprinter << "!" << endl);
     431            DoeLog(1) && (eLog()<< Verbose(1) << **runner << " was not the owner of " << *Sprinter << "!" << endl);
    431432            exit(255);
    432433          }
    433434        } else {
    434           Params.PermutationMap[Walker->nr] = Params.DistanceIterators[Walker->nr]->second; // new target has no source!
     435          Params.PermutationMap[(*iter)->nr] = Params.DistanceIterators[(*iter)->nr]->second; // new target has no source!
    435436        }
    436         Params.StepList[Walker->nr]++; // take next farther distance target
     437        Params.StepList[(*iter)->nr]++; // take next farther distance target
    437438      }
    438     } while (Walker->next != end);
     439    } while (++iter != end());
    439440  } while ((OlderPotential - OldPotential) > 1e-3);
    440441  DoLog(1) && (Log() << Verbose(1) << "done." << endl);
     
    442443
    443444  /// free memory and return with evaluated potential
    444   for (int i=AtomCount; i--;)
     445  for (int i=getAtomCount(); i--;)
    445446    Params.DistanceList[i]->clear();
    446   Free(&Params.DistanceList);
    447   Free(&Params.DistanceIterators);
     447  delete[](Params.DistanceList);
     448  delete[](Params.DistanceIterators);
    448449  return ConstrainedPotential(Params);
    449450};
     
    483484  // Get the Permutation Map by MinimiseConstrainedPotential
    484485  atom **PermutationMap = NULL;
    485   atom *Walker = NULL, *Sprinter = NULL;
     486  atom *Sprinter = NULL;
    486487  if (!MapByIdentity)
    487488    MinimiseConstrainedPotential(PermutationMap, startstep, endstep, configuration.GetIsAngstroem());
    488489  else {
    489     PermutationMap = Malloc<atom *>(AtomCount, "molecule::LinearInterpolationBetweenConfiguration: **PermutationMap");
     490    PermutationMap = new atom *[getAtomCount()];
    490491    SetIndexedArrayForEachAtomTo( PermutationMap, &atom::nr );
    491492  }
     
    502503    mol = World::getInstance().createMolecule();
    503504    MoleculePerStep->insert(mol);
    504     Walker = start;
    505     while (Walker->next != end) {
    506       Walker = Walker->next;
     505    for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    507506      // add to molecule list
    508       Sprinter = mol->AddCopyAtom(Walker);
     507      Sprinter = mol->AddCopyAtom((*iter));
    509508      for (int n=NDIM;n--;) {
    510         Sprinter->x[n] = Walker->Trajectory.R.at(startstep)[n] + (PermutationMap[Walker->nr]->Trajectory.R.at(endstep)[n] - Walker->Trajectory.R.at(startstep)[n])*((double)step/(double)MaxSteps);
     509        Sprinter->x[n] = (*iter)->Trajectory.R.at(startstep)[n] + (PermutationMap[(*iter)->nr]->Trajectory.R.at(endstep)[n] - (*iter)->Trajectory.R.at(startstep)[n])*((double)step/(double)MaxSteps);
    511510        // add to Trajectories
    512511        //Log() << Verbose(3) << step << ">=" << MDSteps-1 << endl;
    513512        if (step < MaxSteps) {
    514           Walker->Trajectory.R.at(step)[n] = Walker->Trajectory.R.at(startstep)[n] + (PermutationMap[Walker->nr]->Trajectory.R.at(endstep)[n] - Walker->Trajectory.R.at(startstep)[n])*((double)step/(double)MaxSteps);
    515           Walker->Trajectory.U.at(step)[n] = 0.;
    516           Walker->Trajectory.F.at(step)[n] = 0.;
     513          (*iter)->Trajectory.R.at(step)[n] = (*iter)->Trajectory.R.at(startstep)[n] + (PermutationMap[(*iter)->nr]->Trajectory.R.at(endstep)[n] - (*iter)->Trajectory.R.at(startstep)[n])*((double)step/(double)MaxSteps);
     514          (*iter)->Trajectory.U.at(step)[n] = 0.;
     515          (*iter)->Trajectory.F.at(step)[n] = 0.;
    517516        }
    518517      }
     
    522521
    523522  // store the list to single step files
    524   int *SortIndex = Malloc<int>(AtomCount, "molecule::LinearInterpolationBetweenConfiguration: *SortIndex");
    525   for (int i=AtomCount; i--; )
     523  int *SortIndex = new int[getAtomCount()];
     524  for (int i=getAtomCount(); i--; )
    526525    SortIndex[i] = i;
    527526  status = MoleculePerStep->OutputConfigForListOfFragments(&configuration, SortIndex);
     527  delete[](SortIndex);
    528528
    529529  // free and return
    530   Free(&PermutationMap);
     530  delete[](PermutationMap);
    531531  delete(MoleculePerStep);
    532532  return status;
     
    548548bool molecule::VerletForceIntegration(char *file, config &configuration)
    549549{
     550  Info FunctionInfo(__func__);
    550551  ifstream input(file);
    551552  string token;
     
    567568      return false;
    568569    }
    569     if (Force.RowCounter[0] != AtomCount) {
    570       DoeLog(0) && (eLog()<< Verbose(0) << "Mismatch between number of atoms in file " << Force.RowCounter[0] << " and in molecule " << AtomCount << "." << endl);
     570    if (Force.RowCounter[0] != getAtomCount()) {
     571      DoeLog(0) && (eLog()<< Verbose(0) << "Mismatch between number of atoms in file " << Force.RowCounter[0] << " and in molecule " << getAtomCount() << "." << endl);
    571572      performCriticalExit();
    572573      return false;
     
    574575    // correct Forces
    575576    Velocity.Zero();
    576     for(int i=0;i<AtomCount;i++)
     577    for(int i=0;i<getAtomCount();i++)
    577578      for(int d=0;d<NDIM;d++) {
    578579        Velocity[d] += Force.Matrix[0][i][d+5];
    579580      }
    580     for(int i=0;i<AtomCount;i++)
     581    for(int i=0;i<getAtomCount();i++)
    581582      for(int d=0;d<NDIM;d++) {
    582         Force.Matrix[0][i][d+5] -= Velocity[d]/(double)AtomCount;
     583        Force.Matrix[0][i][d+5] -= Velocity[d]/static_cast<double>(getAtomCount());
    583584      }
    584585    // solve a constrained potential if we are meant to
     
    588589      ConstrainedPotentialEnergy = MinimiseConstrainedPotential(PermutationMap,configuration.DoConstrainedMD, 0, configuration.GetIsAngstroem());
    589590      EvaluateConstrainedForces(configuration.DoConstrainedMD, 0, PermutationMap, &Force);
    590       Free(&PermutationMap);
     591      delete[](PermutationMap);
    591592    }
    592593
    593594    // and perform Verlet integration for each atom with position, velocity and force vector
    594595    // check size of vectors
    595     ActOnAllAtoms( &atom::ResizeTrajectory, MDSteps+10 );
    596 
    597     ActOnAllAtoms( &atom::VelocityVerletUpdate, MDSteps, &configuration, &Force);
     596    //ActOnAllAtoms( &atom::ResizeTrajectory, MDSteps+10 );
     597
     598    ActOnAllAtoms( &atom::VelocityVerletUpdate, MDSteps+1, &configuration, &Force);
    598599  }
    599600  // correct velocities (rather momenta) so that center of mass remains motionless
    600601  Velocity.Zero();
    601602  IonMass = 0.;
    602   ActOnAllAtoms ( &atom::SumUpKineticEnergy, MDSteps, &IonMass, &Velocity );
     603  ActOnAllAtoms ( &atom::SumUpKineticEnergy, MDSteps+1, &IonMass, &Velocity );
    603604
    604605  // correct velocities (rather momenta) so that center of mass remains motionless
    605606  Velocity.Scale(1./IonMass);
    606607  ActualTemp = 0.;
    607   ActOnAllAtoms ( &atom::CorrectVelocity, &ActualTemp, MDSteps, &Velocity );
     608  ActOnAllAtoms ( &atom::CorrectVelocity, &ActualTemp, MDSteps+1, &Velocity );
    608609  Thermostats(configuration, ActualTemp, Berendsen);
    609610  MDSteps++;
     
    683684      delta_alpha = 0.;
    684685      ActOnAllAtoms( &atom::Thermostat_NoseHoover_init, MDSteps, &delta_alpha );
    685       delta_alpha = (delta_alpha - (3.*AtomCount+1.) * configuration.TargetTemp)/(configuration.HooverMass*Units2Electronmass);
     686      delta_alpha = (delta_alpha - (3.*getAtomCount()+1.) * configuration.TargetTemp)/(configuration.HooverMass*Units2Electronmass);
    686687      configuration.alpha += delta_alpha*configuration.Deltat;
    687688      DoLog(3) && (Log() << Verbose(3) << "alpha = " << delta_alpha << " * " << configuration.Deltat << " = " << configuration.alpha << "." << endl);
Note: See TracChangeset for help on using the changeset viewer.