Changes in / [8f215d:a7b761b]


Ignore:
Location:
src
Files:
1 added
1 deleted
39 edited

Legend:

Unmodified
Added
Removed
  • src/Helpers/Assert.cpp

    r8f215d ra7b761b  
    5454
    5555
    56 
    5756bool _my_assert::check(const bool res,
    5857                       const char* condition,
     
    6362{
    6463  if(!res){
    65     cout << "Assertion " << condition << " failed in file " << filename << " at line " << line << endl;
     64    cout << "Assertion \"" << condition << "\" failed in file " << filename << " at line " << line << endl;
    6665    cout << "Assertion Message: " << message << std::endl;
    6766    while(true){
  • src/Legacy/oldmenu.cpp

    r8f215d ra7b761b  
    423423void oldmenu::RemoveAtoms(molecule *mol)
    424424{
    425   atom *first, *second;
     425  atom *second;
    426426  int axis;
    427427  double tmp1, tmp2;
     
    446446      break;
    447447    case 'b':
    448       second = mol->AskAtom("Enter number of atom as reference point: ");
    449       Log() << Verbose(0) << "Enter radius: ";
    450       cin >> tmp1;
    451       first = mol->start;
    452       second = first->next;
    453       while(second != mol->end) {
    454         first = second;
    455         second = first->next;
    456         if (first->x.DistanceSquared(second->x) > tmp1*tmp1) // distance to first above radius ...
    457           mol->RemoveAtom(first);
     448      {
     449        second = mol->AskAtom("Enter number of atom as reference point: ");
     450        Log() << Verbose(0) << "Enter radius: ";
     451        cin >> tmp1;
     452        molecule::iterator runner;
     453        for (molecule::iterator iter = mol->begin(); iter != mol->end(); ) {
     454          runner = iter++;
     455          if ((*runner)->x.DistanceSquared((*runner)->x) > tmp1*tmp1) // distance to first above radius ...
     456            mol->RemoveAtom((*runner));
     457        }
    458458      }
    459459      break;
     
    465465      Log() << Verbose(0) << "Upper boundary: ";
    466466      cin >> tmp2;
    467       first = mol->start;
    468       second = first->next;
    469       while(second != mol->end) {
    470         first = second;
    471         second = first->next;
    472         if ((first->x[axis] < tmp1) || (first->x[axis] > tmp2)) {// out of boundary ...
    473           //Log() << Verbose(0) << "Atom " << *first << " with " << first->x.x[axis] << " on axis " << axis << " is out of bounds [" << tmp1 << "," << tmp2 << "]." << endl;
    474           mol->RemoveAtom(first);
     467      molecule::iterator runner;
     468      for (molecule::iterator iter = mol->begin(); iter != mol->end(); ) {
     469        runner = iter++;
     470        if (((*runner)->x[axis] < tmp1) || ((*runner)->x[axis] > tmp2)) {// out of boundary ...
     471          //Log() << Verbose(0) << "Atom " << *(*runner) << " with " << (*runner)->x.x[axis] << " on axis " << axis << " is out of bounds [" << tmp1 << "," << tmp2 << "]." << endl;
     472          mol->RemoveAtom((*runner));
    475473        }
    476474      }
     
    515513        min[i] = 0.;
    516514
    517       second = mol->start;
    518       while ((second->next != mol->end)) {
    519         second = second->next; // advance
    520         Z = second->type->Z;
     515      for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     516        Z = (*iter)->type->Z;
    521517        tmp1 = 0.;
    522         if (first != second) {
    523           x = first->x - second->x;
     518        if (first != (*iter)) {
     519          x = first->x - (*iter)->x;
    524520          tmp1 = x.Norm();
    525521        }
    526522        if ((tmp1 != 0.) && ((min[Z] == 0.) || (tmp1 < min[Z]))) min[Z] = tmp1;
    527         //Log() << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl;
     523        //Log() << Verbose(0) << "Bond length between Atom " << first->nr << " and " << ((*iter)->nr << ": " << tmp1 << " a.u." << endl;
    528524      }
    529525      for (int i=MAX_ELEMENTS;i--;)
     
    754750    Log() << Verbose(0) << "State the factor: ";
    755751    cin >> faktor;
    756 
    757     mol->CountAtoms(); // recount atoms
    758     if (mol->AtomCount != 0) {  // if there is more than none
    759       count = mol->AtomCount;  // is changed becausing of adding, thus has to be stored away beforehand
     752    if (mol->getAtomCount() != 0) {  // if there is more than none
     753      count = mol->getAtomCount();  // is changed becausing of adding, thus has to be stored away beforehand
    760754      Elements = new const element *[count];
    761755      vectors = new Vector *[count];
    762756      j = 0;
    763       first = mol->start;
    764       while (first->next != mol->end) { // make a list of all atoms with coordinates and element
    765         first = first->next;
    766         Elements[j] = first->type;
    767         vectors[j] = &first->x;
     757      for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     758        Elements[j] = (*iter)->type;
     759        vectors[j] = &(*iter)->x;
    768760        j++;
    769761      }
     
    10241016    return;
    10251017  }
    1026   atom *Walker = mol->start;
    10271018
    10281019  // generate some KeySets
    10291020  Log() << Verbose(0) << "Generating KeySets." << endl;
    1030   KeySet TestSets[mol->AtomCount+1];
     1021  KeySet TestSets[mol->getAtomCount()+1];
    10311022  i=1;
    1032   while (Walker->next != mol->end) {
    1033     Walker = Walker->next;
     1023  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
    10341024    for (int j=0;j<i;j++) {
    1035       TestSets[j].insert(Walker->nr);
     1025      TestSets[j].insert((*iter)->nr);
    10361026    }
    10371027    i++;
     
    10391029  Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl;
    10401030  KeySetTestPair test;
    1041   test = TestSets[mol->AtomCount-1].insert(Walker->nr);
    1042   if (test.second) {
    1043     Log() << Verbose(1) << "Insertion worked?!" << endl;
     1031  molecule::const_iterator iter = mol->begin();
     1032  if (iter != mol->end()) {
     1033    test = TestSets[mol->getAtomCount()-1].insert((*iter)->nr);
     1034    if (test.second) {
     1035      Log() << Verbose(1) << "Insertion worked?!" << endl;
     1036    } else {
     1037      Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl;
     1038    }
    10441039  } else {
    1045     Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl;
    1046   }
    1047   TestSets[mol->AtomCount].insert(mol->end->previous->nr);
    1048   TestSets[mol->AtomCount].insert(mol->end->previous->previous->previous->nr);
     1040    eLog() << Verbose(1) << "No atoms to test double insertion." << endl;
     1041  }
    10491042
    10501043  // constructing Graph structure
     
    10541047  // insert KeySets into Subgraphs
    10551048  Log() << Verbose(0) << "Inserting KeySets into Subgraph class." << endl;
    1056   for (int j=0;j<mol->AtomCount;j++) {
     1049  for (int j=0;j<mol->getAtomCount();j++) {
    10571050    Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.)));
    10581051  }
    10591052  Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl;
    10601053  GraphTestPair test2;
    1061   test2 = Subgraphs.insert(GraphPair (TestSets[mol->AtomCount],pair<int, double>(counter++, 1.)));
     1054  test2 = Subgraphs.insert(GraphPair (TestSets[mol->getAtomCount()],pair<int, double>(counter++, 1.)));
    10621055  if (test2.second) {
    10631056    Log() << Verbose(1) << "Insertion worked?!" << endl;
  • src/Makefile.am

    r8f215d ra7b761b  
    7676                                   Descriptors/MoleculeIdDescriptor.cpp
    7777                                   
    78                                    
     78
    7979DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp \
    8080                                   Descriptors/AtomIdDescriptor.hpp \
     
    9494                                  Exceptions/MathException.hpp \
    9595                                  Exceptions/ZeroVectorException.hpp
     96
    9697
    9798SOURCE = ${ANALYSISSOURCE} \
     
    112113                 graph.cpp \
    113114                 helpers.cpp \
     115                 Helpers/Assert.cpp \
    114116                 info.cpp \
    115117                 leastsquaremin.cpp \
    116118                 Line.cpp \
    117119                 linkedcell.cpp \
    118                  lists.cpp \
    119120                 log.cpp \
    120121                 logger.cpp \
     
    133134                 tesselationhelpers.cpp \
    134135                 triangleintersectionlist.cpp \
     136                 vector.cpp \
    135137                 verbose.cpp \
    136138                 vector_ops.cpp \
  • src/Patterns/Cacheable.hpp

    r8f215d ra7b761b  
    2828        owner(_owner)
    2929        {}
    30       virtual T getValue()=0;
     30      virtual T& getValue()=0;
    3131      virtual void invalidate()=0;
    3232      virtual bool isValid()=0;
     
    4646        {}
    4747
    48       virtual T getValue(){
     48      virtual T& getValue(){
    4949        // set the state to valid
    5050        State::owner->switchState(State::owner->validState);
     
    7272        {}
    7373
    74       virtual T getValue(){
     74      virtual T& getValue(){
    7575        return content;
    7676      }
     
    100100        {}
    101101
    102       virtual T getValue(){
     102      virtual T& getValue(){
    103103        ASSERT(0,"Cannot get a value from a Cacheable after it's Observable has died");
    104104        // we have to return a grossly invalid reference, because no value can be produced anymore
     
    134134    void subjectKilled(Observable *subject);
    135135  private:
    136 
    137136    void switchState(state_ptr newState);
    138137
     
    144143
    145144    Observable *owner;
    146 
    147145    boost::function<T()> recalcMethod;
    148146
     
    221219
    222220    const bool isValid() const;
    223     const T operator*() const;
     221    const T& operator*() const;
    224222
    225223    // methods implemented for base-class Observer
     
    237235
    238236  template<typename T>
    239   const T Cacheable<T>::operator*() const{
     237  const T& Cacheable<T>::operator*() const{
    240238    return recalcMethod();
    241239  }
  • src/Patterns/Observer.cpp

    r8f215d ra7b761b  
    8282Observable::_Observable_protector::_Observable_protector(Observable *_protege) :
    8383  protege(_protege)
     84{
     85  start_observer_internal(protege);
     86}
     87
     88Observable::_Observable_protector::_Observable_protector(const _Observable_protector &dest) :
     89    protege(dest.protege)
    8490{
    8591  start_observer_internal(protege);
     
    189195  ASSERT(callTable.count(this),"SignOff called for an Observable without Observers.");
    190196  callees_t &callees = callTable[this];
     197
    191198  callees_t::iterator iter;
    192199  callees_t::iterator deliter;
  • src/Patterns/Observer.hpp

    r8f215d ra7b761b  
    3636typedef Notification *const Notification_ptr;
    3737
     38template<class _Set>
     39class ObservedIterator;
     40
    3841/**
    3942 * An Observer is notified by all Observed objects, when anything changes.
     
    5356  friend class Observable;
    5457  friend class Notification;
     58  template<class> friend class ObservedIterator;
     59
    5560public:
    5661  Observer();
     
    152157  static std::set<Observable*> busyObservables;
    153158
    154 
    155159  //! @cond
    156160  // Structure for RAII-Style notification
     
    164168  public:
    165169    _Observable_protector(Observable *);
     170    _Observable_protector(const _Observable_protector&);
    166171    ~_Observable_protector();
    167172  private:
  • src/analysis_bonds.cpp

    r8f215d ra7b761b  
    2626  Mean = 0.;
    2727
    28   atom *Walker = mol->start;
    2928  int AtomCount = 0;
    30   while (Walker->next != mol->end) {
    31     Walker = Walker->next;
    32     const int count = Walker->ListOfBonds.size();
     29  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     30    const int count = (*iter)->ListOfBonds.size();
    3331    if (Max < count)
    3432      Max = count;
     
    5856
    5957  int AtomNo = 0;
    60   atom *Walker = mol->start;
    61   while (Walker->next != mol->end) {
    62     Walker = Walker->next;
    63     if (Walker->type == type1)
    64       for (BondList::const_iterator BondRunner = Walker->ListOfBonds.begin(); BondRunner != Walker->ListOfBonds.end(); BondRunner++)
    65         if ((*BondRunner)->GetOtherAtom(Walker)->type == type2) {
     58  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     59    if ((*iter)->type == type1)
     60      for (BondList::const_iterator BondRunner = (*iter)->ListOfBonds.begin(); BondRunner != (*iter)->ListOfBonds.end(); BondRunner++)
     61        if ((*BondRunner)->GetOtherAtom((*iter))->type == type2) {
    6662          const double distance = (*BondRunner)->GetDistanceSquared();
    6763          if (Min > distance)
     
    126122int CountHydrogenBridgeBonds(MoleculeListClass *molecules, element * InterfaceElement = NULL)
    127123{
    128   atom *Walker = NULL;
    129   atom *Runner = NULL;
    130124  int count = 0;
    131125  int OtherHydrogens = 0;
     
    133127  bool InterfaceFlag = false;
    134128  bool OtherHydrogenFlag = true;
    135   for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin();MolWalker != molecules->ListOfMolecules.end(); MolWalker++) {
    136     Walker = (*MolWalker)->start;
    137     while (Walker->next != (*MolWalker)->end) {
    138       Walker = Walker->next;
    139       for (MoleculeList::const_iterator MolRunner = molecules->ListOfMolecules.begin();MolRunner != molecules->ListOfMolecules.end(); MolRunner++) {
    140         Runner = (*MolRunner)->start;
    141         while (Runner->next != (*MolRunner)->end) {
    142           Runner = Runner->next;
    143           if ((Walker->type->Z  == 8) && (Runner->type->Z  == 8)) {
     129  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin();MolWalker != molecules->ListOfMolecules.end(); ++MolWalker) {
     130    molecule::iterator Walker = (*MolWalker)->begin();
     131    for(;Walker!=(*MolWalker)->end();++Walker){
     132      for (MoleculeList::const_iterator MolRunner = molecules->ListOfMolecules.begin();MolRunner != molecules->ListOfMolecules.end(); ++MolRunner) {
     133        molecule::iterator Runner = (*MolRunner)->begin();
     134        for(;Runner!=(*MolRunner)->end();++Runner){
     135          if (((*Walker)->type->Z  == 8) && ((*Runner)->type->Z  == 8)) {
    144136            // check distance
    145             const double distance = Runner->x.DistanceSquared(Walker->x);
     137            const double distance = (*Runner)->x.DistanceSquared((*Walker)->x);
    146138            if ((distance > MYEPSILON) && (distance < HBRIDGEDISTANCE*HBRIDGEDISTANCE)) { // distance >0 means  different atoms
    147139              // on other atom(Runner) we check for bond to interface element and
     
    151143              OtherHydrogens = 0;
    152144              InterfaceFlag = (InterfaceElement == NULL);
    153               for (BondList::const_iterator BondRunner = Runner->ListOfBonds.begin(); BondRunner != Runner->ListOfBonds.end(); BondRunner++) {
    154                 atom * const OtherAtom = (*BondRunner)->GetOtherAtom(Runner);
     145              for (BondList::const_iterator BondRunner = (*Runner)->ListOfBonds.begin(); BondRunner != (*Runner)->ListOfBonds.end(); BondRunner++) {
     146                atom * const OtherAtom = (*BondRunner)->GetOtherAtom(*Runner);
    155147                // if hydrogen, check angle to be greater(!) than 30 degrees
    156148                if (OtherAtom->type->Z == 1) {
    157                   const double angle = CalculateAngle(&OtherAtom->x, &Runner->x, &Walker->x);
     149                  const double angle = CalculateAngle(&OtherAtom->x, &(*Runner)->x, &(*Walker)->x);
    158150                  OtherHydrogenFlag = OtherHydrogenFlag && (angle > M_PI*(30./180.) + MYEPSILON);
    159151                  Otherangle += angle;
     
    176168              if (InterfaceFlag && OtherHydrogenFlag) {
    177169                // on this element (Walker) we check for bond to hydrogen, i.e. part of water molecule
    178                 for (BondList::const_iterator BondRunner = Walker->ListOfBonds.begin(); BondRunner != Walker->ListOfBonds.end(); BondRunner++) {
    179                   atom * const OtherAtom = (*BondRunner)->GetOtherAtom(Walker);
     170                for (BondList::const_iterator BondRunner = (*Walker)->ListOfBonds.begin(); BondRunner != (*Walker)->ListOfBonds.end(); BondRunner++) {
     171                  atom * const OtherAtom = (*BondRunner)->GetOtherAtom(*Walker);
    180172                  if (OtherAtom->type->Z == 1) {
    181173                    // check angle
    182                     if (CheckHydrogenBridgeBondAngle(Walker, OtherAtom, Runner)) {
    183                       DoLog(1) && (Log() << Verbose(1) << Walker->getName() << ", " << OtherAtom->getName() << " and " << Runner->getName() << " has a hydrogen bridge bond with distance " << sqrt(distance) << " and angle " << CalculateAngle(&OtherAtom->x, &Walker->x, &Runner->x)*(180./M_PI) << "." << endl);
     174                    if (CheckHydrogenBridgeBondAngle(*Walker, OtherAtom, *Runner)) {
     175                      DoLog(1) && (Log() << Verbose(1) << (*Walker)->getName() << ", " << OtherAtom->getName() << " and " << (*Runner)->getName() << " has a hydrogen bridge bond with distance " << sqrt(distance) << " and angle " << CalculateAngle(&OtherAtom->x, &(*Walker)->x, &(*Runner)->x)*(180./M_PI) << "." << endl);
    184176                      count++;
    185177                      break;
     
    205197int CountBondsOfTwo(MoleculeListClass * const molecules, const element * const first, const element * const second)
    206198{
    207   atom *Walker = NULL;
    208199  int count = 0;
    209200
    210201  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin();MolWalker != molecules->ListOfMolecules.end(); MolWalker++) {
    211     Walker = (*MolWalker)->start;
    212     while (Walker->next != (*MolWalker)->end) {
    213       Walker = Walker->next;
    214       if ((Walker->type == first) || (Walker->type == second)) {  // first element matches
    215         for (BondList::const_iterator BondRunner = Walker->ListOfBonds.begin(); BondRunner != Walker->ListOfBonds.end(); BondRunner++) {
    216           atom * const OtherAtom = (*BondRunner)->GetOtherAtom(Walker);
    217           if (((OtherAtom->type == first) || (OtherAtom->type == second)) && (Walker->nr < OtherAtom->nr)) {
     202    molecule::iterator Walker = (*MolWalker)->begin();
     203    for(;Walker!=(*MolWalker)->end();++Walker){
     204      atom * theAtom = *Walker;
     205      if ((theAtom->type == first) || (theAtom->type == second)) {  // first element matches
     206        for (BondList::const_iterator BondRunner = theAtom->ListOfBonds.begin(); BondRunner != theAtom->ListOfBonds.end(); BondRunner++) {
     207          atom * const OtherAtom = (*BondRunner)->GetOtherAtom(theAtom);
     208          if (((OtherAtom->type == first) || (OtherAtom->type == second)) && (theAtom->nr < OtherAtom->nr)) {
    218209            count++;
    219210            DoLog(1) && (Log() << Verbose(1) << first->name << "-" << second->name << " bond found between " << *Walker << " and " << *OtherAtom << "." << endl);
     
    240231  bool MatchFlag[2];
    241232  bool result = false;
    242   atom *Walker = NULL;
    243233  const element * ElementArray[2];
    244234  ElementArray[0] = first;
     
    246236
    247237  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin();MolWalker != molecules->ListOfMolecules.end(); MolWalker++) {
    248     Walker = (*MolWalker)->start;
    249     while (Walker->next != (*MolWalker)->end) {
    250       Walker = Walker->next;
    251       if (Walker->type == second) {  // first element matches
     238    molecule::iterator Walker = (*MolWalker)->begin();
     239    for(;Walker!=(*MolWalker)->end();++Walker){
     240      atom *theAtom = *Walker;
     241      if (theAtom->type == second) {  // first element matches
    252242        for (int i=0;i<2;i++)
    253243          MatchFlag[i] = false;
    254         for (BondList::const_iterator BondRunner = Walker->ListOfBonds.begin(); BondRunner != Walker->ListOfBonds.end(); BondRunner++) {
    255           atom * const OtherAtom = (*BondRunner)->GetOtherAtom(Walker);
     244        for (BondList::const_iterator BondRunner = theAtom->ListOfBonds.begin(); BondRunner != theAtom->ListOfBonds.end(); BondRunner++) {
     245          atom * const OtherAtom = (*BondRunner)->GetOtherAtom(theAtom);
    256246          for (int i=0;i<2;i++)
    257247            if ((!MatchFlag[i]) && (OtherAtom->type == ElementArray[i])) {
  • src/analysis_correlation.cpp

    r8f215d ra7b761b  
    4040  }
    4141  outmap = new PairCorrelationMap;
    42   for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
     42  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++){
    4343    if ((*MolWalker)->ActiveFlag) {
    4444      DoeLog(2) && (eLog()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
    45       atom *Walker = (*MolWalker)->start;
    46       while (Walker->next != (*MolWalker)->end) {
    47         Walker = Walker->next;
    48         DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
    49         if ((type1 == NULL) || (Walker->type == type1)) {
    50           for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
     45      eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
     46      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
     47        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
     48        if ((type1 == NULL) || ((*iter)->type == type1)) {
     49          for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++){
    5150            if ((*MolOtherWalker)->ActiveFlag) {
    5251              DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
    53               atom *OtherWalker = (*MolOtherWalker)->start;
    54               while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker
    55                 OtherWalker = OtherWalker->next;
    56                 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl);
    57                 if (Walker->nr < OtherWalker->nr)
    58                   if ((type2 == NULL) || (OtherWalker->type == type2)) {
    59                     distance = Walker->node->PeriodicDistance(*OtherWalker->node, World::getInstance().getDomain());
    60                     //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
    61                     outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
     52              for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
     53                DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
     54                if ((*iter)->getId() < (*runner)->getId()){
     55                  if ((type2 == NULL) || ((*runner)->type == type2)) {
     56                    distance = (*iter)->node->PeriodicDistance(*(*runner)->node,  World::getInstance().getDomain());
     57                    //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
     58                    outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
    6259                  }
     60                }
    6361              }
     62            }
    6463          }
    6564        }
    6665      }
    6766    }
    68 
     67  }
    6968  return outmap;
    7069};
     
    101100      double * FullInverseMatrix = InverseMatrix(FullMatrix);
    102101      DoeLog(2) && (eLog()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
    103       atom *Walker = (*MolWalker)->start;
    104       while (Walker->next != (*MolWalker)->end) {
    105         Walker = Walker->next;
    106         DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
    107         if ((type1 == NULL) || (Walker->type == type1)) {
    108           periodicX = *(Walker->node);
     102      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
     103        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
     104        if ((type1 == NULL) || ((*iter)->type == type1)) {
     105          periodicX = *(*iter)->node;
    109106          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    110107          // go through every range in xyz and get distance
     
    117114                  if ((*MolOtherWalker)->ActiveFlag) {
    118115                    DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
    119                     atom *OtherWalker = (*MolOtherWalker)->start;
    120                     while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker
    121                       OtherWalker = OtherWalker->next;
    122                       DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl);
    123                       if (Walker->nr < OtherWalker->nr)
    124                         if ((type2 == NULL) || (OtherWalker->type == type2)) {
    125                           periodicOtherX = *(OtherWalker->node);
     116                    for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
     117                      DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
     118                      if ((*iter)->nr < (*runner)->nr)
     119                        if ((type2 == NULL) || ((*runner)->type == type2)) {
     120                          periodicOtherX = *(*runner)->node;
    126121                          periodicOtherX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    127122                          // go through every range in xyz and get distance
     
    132127                                checkOtherX.MatrixMultiplication(FullMatrix);
    133128                                distance = checkX.distance(checkOtherX);
    134                                 //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
    135                                 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
     129                                //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
     130                                outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
    136131                              }
    137132                        }
     
    169164    if ((*MolWalker)->ActiveFlag) {
    170165      DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
    171       atom *Walker = (*MolWalker)->start;
    172       while (Walker->next != (*MolWalker)->end) {
    173         Walker = Walker->next;
    174         DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
    175         if ((type == NULL) || (Walker->type == type)) {
    176           distance = Walker->node->PeriodicDistance(*point, World::getInstance().getDomain());
     166      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
     167        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
     168        if ((type == NULL) || ((*iter)->type == type)) {
     169          distance = (*iter)->node->PeriodicDistance(*point, World::getInstance().getDomain());
    177170          DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
    178           outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
     171          outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> ((*iter), point) ) );
    179172        }
    180173      }
     
    211204      double * FullInverseMatrix = InverseMatrix(FullMatrix);
    212205      DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
    213       atom *Walker = (*MolWalker)->start;
    214       while (Walker->next != (*MolWalker)->end) {
    215         Walker = Walker->next;
    216         DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
    217         if ((type == NULL) || (Walker->type == type)) {
    218           periodicX = *(Walker->node);
     206      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
     207        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
     208        if ((type == NULL) || ((*iter)->type == type)) {
     209          periodicX = *(*iter)->node;
    219210          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    220211          // go through every range in xyz and get distance
     
    226217                distance = checkX.distance(*point);
    227218                DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
    228                 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
     219                outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (*iter, point) ) );
    229220              }
    230221        }
     
    261252    if ((*MolWalker)->ActiveFlag) {
    262253      DoLog(1) && (Log() << Verbose(1) << "Current molecule is " << (*MolWalker)->name << "." << endl);
    263       atom *Walker = (*MolWalker)->start;
    264       while (Walker->next != (*MolWalker)->end) {
    265         Walker = Walker->next;
    266         //Log() << Verbose(1) << "Current atom is " << *Walker << "." << endl;
    267         if ((type == NULL) || (Walker->type == type)) {
    268           TriangleIntersectionList Intersections(Walker->node,Surface,LC);
     254      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
     255        //Log() << Verbose(3) << "Current atom is " << *(*iter) << "." << endl;
     256        if ((type == NULL) || ((*iter)->type == type)) {
     257          TriangleIntersectionList Intersections((*iter)->node,Surface,LC);
    269258          distance = Intersections.GetSmallestDistance();
    270259          triangle = Intersections.GetClosestTriangle();
    271           outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) );
     260          outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) );
    272261        }
    273262      }
     
    314303      double * FullInverseMatrix = InverseMatrix(FullMatrix);
    315304      DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
    316       atom *Walker = (*MolWalker)->start;
    317       while (Walker->next != (*MolWalker)->end) {
    318         Walker = Walker->next;
    319         DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
    320         if ((type == NULL) || (Walker->type == type)) {
    321           periodicX = *(Walker->node);
     305      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
     306        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
     307        if ((type == NULL) || ((*iter)->type == type)) {
     308          periodicX = *(*iter)->node;
    322309          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    323310          // go through every range in xyz and get distance
     
    337324              }
    338325          // insert
    339           outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (Walker, ShortestTriangle) ) );
     326          outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (*iter, ShortestTriangle) ) );
    340327          //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl;
    341328        }
  • src/atom.cpp

    r8f215d ra7b761b  
    5959atom::~atom()
    6060{
    61   unlink(this);
    6261};
    6362
  • src/bondgraph.cpp

    r8f215d ra7b761b  
    9090bool status = true;
    9191
    92   if (mol->start->next == mol->end) // only construct if molecule is not empty
     92  if (mol->empty()) // only construct if molecule is not empty
    9393    return false;
    9494
     
    124124  max_distance = 0.;
    125125
    126   atom *Runner = mol->start;
    127   while (Runner->next != mol->end) {
    128     Runner = Runner->next;
    129     if (Runner->type->CovalentRadius > max_distance)
    130       max_distance = Runner->type->CovalentRadius;
     126  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     127    if ((*iter)->type->CovalentRadius > max_distance)
     128      max_distance = (*iter)->type->CovalentRadius;
    131129  }
    132130  max_distance *= 2.;
  • src/boundary.cpp

    r8f215d ra7b761b  
    139139{
    140140        Info FunctionInfo(__func__);
    141   atom *Walker = NULL;
    142141  PointMap PointsOnBoundary;
    143142  LineMap LinesOnBoundary;
     
    165164
    166165    // 3b. construct set of all points, transformed into cylindrical system and with left and right neighbours
    167     Walker = mol->start;
    168     while (Walker->next != mol->end) {
    169       Walker = Walker->next;
    170       ProjectedVector = Walker->x - (*MolCenter);
     166    for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     167      ProjectedVector = (*iter)->x - (*MolCenter);
    171168      ProjectedVector.ProjectOntoPlane(AxisVector);
    172169
     
    182179        angle = 2. * M_PI - angle;
    183180      }
    184       DoLog(1) && (Log() << Verbose(1) << "Inserting " << *Walker << ": (r, alpha) = (" << radius << "," << angle << "): " << ProjectedVector << endl);
    185       BoundaryTestPair = BoundaryPoints[axis].insert(BoundariesPair(angle, DistancePair (radius, Walker)));
     181    DoLog(1) && (Log() << Verbose(1) << "Inserting " << **iter << ": (r, alpha) = (" << radius << "," << angle << "): " << ProjectedVector << endl);
     182      BoundaryTestPair = BoundaryPoints[axis].insert(BoundariesPair(angle, DistancePair (radius, (*iter))));
    186183      if (!BoundaryTestPair.second) { // same point exists, check first r, then distance of original vectors to center of gravity
    187184        DoLog(2) && (Log() << Verbose(2) << "Encountered two vectors whose projection onto axis " << axis << " is equal: " << endl);
    188185        DoLog(2) && (Log() << Verbose(2) << "Present vector: " << *BoundaryTestPair.first->second.second << endl);
    189         DoLog(2) && (Log() << Verbose(2) << "New vector: " << *Walker << endl);
     186        DoLog(2) && (Log() << Verbose(2) << "New vector: " << **iter << endl);
    190187        const double ProjectedVectorNorm = ProjectedVector.NormSquared();
    191188        if ((ProjectedVectorNorm - BoundaryTestPair.first->second.first) > MYEPSILON) {
    192189          BoundaryTestPair.first->second.first = ProjectedVectorNorm;
    193           BoundaryTestPair.first->second.second = Walker;
     190          BoundaryTestPair.first->second.second = (*iter);
    194191          DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger projected distance " << ProjectedVectorNorm << "." << endl);
    195192        } else if (fabs(ProjectedVectorNorm - BoundaryTestPair.first->second.first) < MYEPSILON) {
    196           helper = Walker->x - (*MolCenter);
     193          helper = (*iter)->x;
     194          helper -= *MolCenter;
    197195          const double oldhelperNorm = helper.NormSquared();
    198196          helper = BoundaryTestPair.first->second.second->x - (*MolCenter);
    199197          if (helper.NormSquared() < oldhelperNorm) {
    200             BoundaryTestPair.first->second.second = Walker;
     198            BoundaryTestPair.first->second.second = (*iter);
    201199            DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger distance to molecule center " << helper.NormSquared() << "." << endl);
    202200          } else {
     
    695693  int repetition[NDIM] = { 1, 1, 1 };
    696694  int TotalNoClusters = 1;
    697   atom *Walker = NULL;
    698695  double totalmass = 0.;
    699696  double clustervolume = 0.;
     
    719716
    720717  // sum up the atomic masses
    721   Walker = mol->start;
    722   while (Walker->next != mol->end) {
    723       Walker = Walker->next;
    724       totalmass += Walker->type->mass;
     718  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     719      totalmass += (*iter)->type->mass;
    725720  }
    726721  DoLog(0) && (Log() << Verbose(0) << "RESULT: The summed mass is " << setprecision(10) << totalmass << " atomicmassunit." << endl);
     
    804799  Vector Inserter;
    805800  double FillIt = false;
    806   atom *Walker = NULL;
    807801  bond *Binder = NULL;
    808802  double phi[NDIM];
     
    811805
    812806  for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++)
    813     if ((*ListRunner)->AtomCount > 0) {
     807    if ((*ListRunner)->getAtomCount() > 0) {
    814808      DoLog(1) && (Log() << Verbose(1) << "Pre-creating linked cell lists for molecule " << *ListRunner << "." << endl);
    815809      LCList[(*ListRunner)] = new LinkedCell((*ListRunner), 10.); // get linked cell list
     
    829823  }
    830824
    831   filler->CountAtoms();
    832   atom * CopyAtoms[filler->AtomCount];
     825  atom * CopyAtoms[filler->getAtomCount()];
    833826
    834827  // calculate filler grid in [0,1]^3
     
    855848
    856849        // go through all atoms
    857         for (int i=0;i<filler->AtomCount;i++)
     850        for (int i=0;i<filler->getAtomCount();i++)
    858851          CopyAtoms[i] = NULL;
    859         Walker = filler->start;
    860         while (Walker->next != filler->end) {
    861           Walker = Walker->next;
     852        for(molecule::iterator iter = filler->begin(); iter !=filler->end();++filler){
    862853
    863854          // create atomic random translation vector ...
     
    883874
    884875          // ... and put at new position
    885           Inserter = Walker->x;
     876          Inserter = (*iter)->x;
    886877          if (DoRandomRotation)
    887878            Inserter.MatrixMultiplication(Rotations);
     
    907898            DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is outer point." << endl);
    908899            // copy atom ...
    909             CopyAtoms[Walker->nr] = Walker->clone();
    910             CopyAtoms[Walker->nr]->x = Inserter;
    911             Filling->AddAtom(CopyAtoms[Walker->nr]);
    912             DoLog(4) && (Log() << Verbose(4) << "Filling atom " << *Walker << ", translated to " << AtomTranslations << ", at final position is " << (CopyAtoms[Walker->nr]->x) << "." << endl);
     900            CopyAtoms[(*iter)->nr] = (*iter)->clone();
     901            CopyAtoms[(*iter)->nr]->x = Inserter;
     902            Filling->AddAtom(CopyAtoms[(*iter)->nr]);
     903            DoLog(4) && (Log() << Verbose(4) << "Filling atom " << **iter << ", translated to " << AtomTranslations << ", at final position is " << (CopyAtoms[(*iter)->nr]->x) << "." << endl);
    913904          } else {
    914905            DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is inner point, within boundary or outside of MaxDistance." << endl);
    915             CopyAtoms[Walker->nr] = NULL;
     906            CopyAtoms[(*iter)->nr] = NULL;
    916907            continue;
    917908          }
     
    952943  bool TesselationFailFlag = false;
    953944
     945  mol->getAtomCount();
     946
    954947  if (TesselStruct == NULL) {
    955948    DoLog(1) && (Log() << Verbose(1) << "Allocating Tesselation struct ..." << endl);
     
    10231016//  // look whether all points are inside of the convex envelope, otherwise add them via degenerated triangles
    10241017//  //->InsertStraddlingPoints(mol, LCList);
    1025 //  mol->GoToFirst();
     1018//  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
    10261019//  class TesselPoint *Runner = NULL;
    1027 //  while (!mol->IsEnd()) {
    1028 //    Runner = mol->GetPoint();
     1020//    Runner = *iter;
    10291021//    Log() << Verbose(1) << "Checking on " << Runner->Name << " ... " << endl;
    10301022//    if (!->IsInnerPoint(Runner, LCList)) {
     
    10341026//      Log() << Verbose(2) << Runner->Name << " is inside of or on envelope." << endl;
    10351027//    }
    1036 //    mol->GoToNext();
    10371028//  }
    10381029
     
    10431034  status = CheckListOfBaselines(TesselStruct);
    10441035
     1036  cout << "before correction" << endl;
     1037
    10451038  // store before correction
    1046   StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, "");
     1039  StoreTrianglesinFile(mol, TesselStruct, filename, "");
    10471040
    10481041//  // correct degenerated polygons
     
    10541047  // write final envelope
    10551048  CalculateConcavityPerBoundaryPoint(TesselStruct);
    1056   StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, "");
     1049  cout << "after correction" << endl;
     1050  StoreTrianglesinFile(mol, TesselStruct, filename, "");
    10571051
    10581052  if (freeLC)
  • src/builder.cpp

    r8f215d ra7b761b  
    17441744                if (first->type != NULL) {
    17451745                  mol->AddAtom(first);  // add to molecule
    1746                   if ((configPresent == empty) && (mol->AtomCount != 0))
     1746                  if ((configPresent == empty) && (mol->getAtomCount() != 0))
    17471747                    configPresent = present;
    17481748                } else
     
    17731773                DoLog(1) && (Log() << Verbose(1) << "Depth-First-Search Analysis." << endl);
    17741774                MoleculeLeafClass *Subgraphs = NULL;      // list of subgraphs from DFS analysis
    1775                 int *MinimumRingSize = new int[mol->AtomCount];
     1775                int *MinimumRingSize = new int[mol->getAtomCount()];
    17761776                atom ***ListOfLocalAtoms = NULL;
    17771777                class StackClass<bond *> *BackEdgeStack = NULL;
     
    19211921                          int counter  = 0;
    19221922                          for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) {
    1923                             if ((Boundary == NULL) || (Boundary->AtomCount < (*BigFinder)->AtomCount)) {
     1923                            if ((Boundary == NULL) || (Boundary->getAtomCount() < (*BigFinder)->getAtomCount())) {
    19241924                              Boundary = *BigFinder;
    19251925                            }
     
    19801980                performCriticalExit();
    19811981              } else {
     1982                mol->getAtomCount();
    19821983                SaveFlag = true;
    19831984                DoLog(1) && (Log() << Verbose(1) << "Changing atom " << argv[argptr] << " to element " << argv[argptr+1] << "." << endl);
     
    20982099                int counter  = 0;
    20992100                for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) {
    2100                   (*BigFinder)->CountAtoms();
    2101                   if ((Boundary == NULL) || (Boundary->AtomCount < (*BigFinder)->AtomCount)) {
     2101                  if ((Boundary == NULL) || (Boundary->getAtomCount() < (*BigFinder)->getAtomCount())) {
    21022102                    Boundary = *BigFinder;
    21032103                  }
    21042104                  counter++;
    21052105                }
    2106                 DoLog(1) && (Log() << Verbose(1) << "Biggest molecule has " << Boundary->AtomCount << " atoms." << endl);
     2106                DoLog(1) && (Log() << Verbose(1) << "Biggest molecule has " << Boundary->getAtomCount() << " atoms." << endl);
    21072107                start = clock();
    21082108                LCList = new LinkedCell(Boundary, atof(argv[argptr])*2.);
     
    21802180                double tmp1 = atof(argv[argptr+1]);
    21812181                atom *third = mol->FindAtom(atoi(argv[argptr]));
    2182                 atom *first = mol->start;
    2183                 if ((third != NULL) && (first != mol->end)) {
    2184                   atom *second = first->next;
    2185                   while(second != mol->end) {
    2186                     first = second;
    2187                     second = first->next;
    2188                     if (first->x.DistanceSquared(third->x) > tmp1*tmp1) // distance to first above radius ...
    2189                       mol->RemoveAtom(first);
     2182                if(third){
     2183                  for(molecule::iterator iter = mol->begin(); iter != mol->end();){
     2184                    if ((*iter)->x.DistanceSquared(third->x) > tmp1*tmp1){ // distance to first above radius ...
     2185                      mol->RemoveAtom(*(iter++));
     2186                    }
     2187                    else{
     2188                      ++iter;
     2189                    }
    21902190                  }
    21912191                } else {
     
    23322332                performCriticalExit();
    23332333              } else {
     2334                mol->getAtomCount();
    23342335                SaveFlag = true;
    23352336                DoLog(1) && (Log() << Verbose(1) << "Removing atom " << argv[argptr] << "." << endl);
     
    24512452                    faktor = 1;
    24522453                  }
    2453                   mol->CountAtoms();  // recount atoms
    2454                   if (mol->AtomCount != 0) {  // if there is more than none
    2455                     count = mol->AtomCount;   // is changed becausing of adding, thus has to be stored away beforehand
     2454                  if (mol->getAtomCount() != 0) {  // if there is more than none
     2455                    count = mol->getAtomCount();   // is changed becausing of adding, thus has to be stored away beforehand
    24562456                    Elements = new const element *[count];
    24572457                    vectors = new Vector *[count];
    24582458                    j = 0;
    2459                     first = mol->start;
    2460                     while (first->next != mol->end) {  // make a list of all atoms with coordinates and element
    2461                       first = first->next;
    2462                       Elements[j] = first->type;
    2463                       vectors[j] = &first->x;
     2459                    for(molecule::iterator iter = mol->begin();iter!=mol->end();++iter){
     2460                      Elements[j] = (*iter)->type;
     2461                      vectors[j] = &(*iter)->x;
    24642462                      j++;
    24652463                    }
     
    25562554int main(int argc, char **argv)
    25572555{
     2556    // while we are non interactive, we want to abort from asserts
     2557    //ASSERT_DO(Assert::Abort);
    25582558    molecule *mol = NULL;
    25592559    config *configuration = new config;
     
    25952595    }
    25962596
     2597    // In the interactive mode, we can leave the user the choice in case of error
     2598    ASSERT_DO(Assert::Ask);
     2599
    25972600    {
    25982601      cout << ESPACKVersion << endl;
  • src/config.cpp

    r8f215d ra7b761b  
    15471547  int AtomNo = -1;
    15481548  int MolNo = 0;
    1549   atom *Walker = NULL;
    15501549  FILE *f = NULL;
    15511550
     
    15601559  fprintf(f, "# Created by MoleCuilder\n");
    15611560
    1562   for (MoleculeList::const_iterator Runner = MolList->ListOfMolecules.begin(); Runner != MolList->ListOfMolecules.end(); Runner++) {
    1563     Walker = (*Runner)->start;
     1561  for (MoleculeList::const_iterator MolRunner = MolList->ListOfMolecules.begin(); MolRunner != MolList->ListOfMolecules.end(); MolRunner++) {
    15641562    int *elementNo = Calloc<int>(MAX_ELEMENTS, "config::SavePDB - elementNo");
    15651563    AtomNo = 0;
    1566     while (Walker->next != (*Runner)->end) {
    1567       Walker = Walker->next;
    1568       sprintf(name, "%2s%2d",Walker->type->symbol, elementNo[Walker->type->Z]);
    1569       elementNo[Walker->type->Z] = (elementNo[Walker->type->Z]+1) % 100;   // confine to two digits
     1564    for (molecule::const_iterator iter = (*MolRunner)->begin(); iter != (*MolRunner)->end(); ++iter) {
     1565      sprintf(name, "%2s%2d",(*iter)->type->symbol, elementNo[(*iter)->type->Z]);
     1566      elementNo[(*iter)->type->Z] = (elementNo[(*iter)->type->Z]+1) % 100;   // confine to two digits
    15701567      fprintf(f,
    15711568             "ATOM %6u %-4s %4s%c%4u    %8.3f%8.3f%8.3f%6.2f%6.2f      %4s%2s%2s\n",
    1572              Walker->nr,                /* atom serial number */
     1569             (*iter)->nr,                /* atom serial number */
    15731570             name,         /* atom name */
    1574              (*Runner)->name,      /* residue name */
     1571             (*MolRunner)->name,      /* residue name */
    15751572             'a'+(unsigned char)(AtomNo % 26),           /* letter for chain */
    15761573             MolNo,         /* residue sequence number */
    1577              Walker->node->at(0),                 /* position X in Angstroem */
    1578              Walker->node->at(1),                 /* position Y in Angstroem */
    1579              Walker->node->at(2),                 /* position Z in Angstroem */
    1580              (double)Walker->type->Valence,         /* occupancy */
    1581              (double)Walker->type->NoValenceOrbitals,          /* temperature factor */
     1574             (*iter)->node->at(0),                 /* position X in Angstroem */
     1575             (*iter)->node->at(1),                 /* position Y in Angstroem */
     1576             (*iter)->node->at(2),                 /* position Z in Angstroem */
     1577             (double)(*iter)->type->Valence,         /* occupancy */
     1578             (double)(*iter)->type->NoValenceOrbitals,          /* temperature factor */
    15821579             "0",            /* segment identifier */
    1583              Walker->type->symbol,    /* element symbol */
     1580             (*iter)->type->symbol,    /* element symbol */
    15841581             "0");           /* charge */
    15851582      AtomNo++;
     
    16011598{
    16021599  int AtomNo = -1;
    1603   atom *Walker = NULL;
    16041600  FILE *f = NULL;
    16051601
     
    16161612  fprintf(f, "# Created by MoleCuilder\n");
    16171613
    1618   Walker = mol->start;
    16191614  AtomNo = 0;
    1620   while (Walker->next != mol->end) {
    1621     Walker = Walker->next;
    1622     sprintf(name, "%2s%2d",Walker->type->symbol, elementNo[Walker->type->Z]);
    1623     elementNo[Walker->type->Z] = (elementNo[Walker->type->Z]+1) % 100;   // confine to two digits
     1615  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     1616    sprintf(name, "%2s%2d",(*iter)->type->symbol, elementNo[(*iter)->type->Z]);
     1617    elementNo[(*iter)->type->Z] = (elementNo[(*iter)->type->Z]+1) % 100;   // confine to two digits
    16241618    fprintf(f,
    16251619           "ATOM %6u %-4s %4s%c%4u    %8.3f%8.3f%8.3f%6.2f%6.2f      %4s%2s%2s\n",
    1626            Walker->nr,                /* atom serial number */
     1620           (*iter)->nr,                /* atom serial number */
    16271621           name,         /* atom name */
    16281622           mol->name,      /* residue name */
    16291623           'a'+(unsigned char)(AtomNo % 26),           /* letter for chain */
    16301624           0,         /* residue sequence number */
    1631            Walker->node->at(0),                 /* position X in Angstroem */
    1632            Walker->node->at(1),                 /* position Y in Angstroem */
    1633            Walker->node->at(2),                 /* position Z in Angstroem */
    1634            (double)Walker->type->Valence,         /* occupancy */
    1635            (double)Walker->type->NoValenceOrbitals,          /* temperature factor */
     1625           (*iter)->node->at(0),                 /* position X in Angstroem */
     1626           (*iter)->node->at(1),                 /* position Y in Angstroem */
     1627           (*iter)->node->at(2),                 /* position Z in Angstroem */
     1628           (double)(*iter)->type->Valence,         /* occupancy */
     1629           (double)(*iter)->type->NoValenceOrbitals,          /* temperature factor */
    16361630           "0",            /* segment identifier */
    1637            Walker->type->symbol,    /* element symbol */
     1631           (*iter)->type->symbol,    /* element symbol */
    16381632           "0");           /* charge */
    16391633    AtomNo++;
     
    16531647bool config::SaveTREMOLO(const char * const filename, const molecule * const mol) const
    16541648{
    1655   atom *Walker = NULL;
    16561649  ofstream *output = NULL;
    16571650  stringstream * const fname = new stringstream;
     
    16661659
    16671660  // scan maximum number of neighbours
    1668   Walker = mol->start;
    16691661  int MaxNeighbours = 0;
    1670   while (Walker->next != mol->end) {
    1671     Walker = Walker->next;
    1672     const int count = Walker->ListOfBonds.size();
     1662  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     1663    const int count = (*iter)->ListOfBonds.size();
    16731664    if (MaxNeighbours < count)
    16741665      MaxNeighbours = count;
    16751666  }
    1676   *output << "# ATOMDATA Id name resName resSeq x=3 charge type neighbors=" << MaxNeighbours << endl;
    1677 
    1678   Walker = mol->start;
    1679   while (Walker->next != mol->end) {
    1680     Walker = Walker->next;
    1681     *output << Walker->nr << "\t";
    1682     *output << Walker->getName() << "\t";
     1667  *output << "# ATOMDATA Id name resName resSeq x=3 Charge type neighbors=" << MaxNeighbours << endl;
     1668
     1669  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     1670    *output << (*iter)->nr << "\t";
     1671    *output << (*iter)->getName() << "\t";
    16831672    *output << mol->name << "\t";
    16841673    *output << 0 << "\t";
    1685     *output << Walker->node->at(0) << "\t" << Walker->node->at(1) << "\t" << Walker->node->at(2) << "\t";
    1686     *output << static_cast<double>(Walker->type->Valence) << "\t";
    1687     *output << Walker->type->symbol << "\t";
    1688     for (BondList::iterator runner = Walker->ListOfBonds.begin(); runner != Walker->ListOfBonds.end(); runner++)
    1689       *output << (*runner)->GetOtherAtom(Walker)->nr << "\t";
    1690     for(int i=Walker->ListOfBonds.size(); i < MaxNeighbours; i++)
     1674    *output << (*iter)->node->at(0) << "\t" << (*iter)->node->at(1) << "\t" << (*iter)->node->at(2) << "\t";
     1675    *output << static_cast<double>((*iter)->type->Valence) << "\t";
     1676    *output << (*iter)->type->symbol << "\t";
     1677    for (BondList::iterator runner = (*iter)->ListOfBonds.begin(); runner != (*iter)->ListOfBonds.end(); runner++)
     1678      *output << (*runner)->GetOtherAtom(*iter)->nr << "\t";
     1679    for(int i=(*iter)->ListOfBonds.size(); i < MaxNeighbours; i++)
    16911680      *output << "-\t";
    16921681    *output << endl;
     
    17081697bool config::SaveTREMOLO(const char * const filename, const MoleculeListClass * const MolList) const
    17091698{
    1710   atom *Walker = NULL;
    17111699  ofstream *output = NULL;
    17121700  stringstream * const fname = new stringstream;
     
    17231711  int MaxNeighbours = 0;
    17241712  for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
    1725     Walker = (*MolWalker)->start;
    1726     while (Walker->next != (*MolWalker)->end) {
    1727       Walker = Walker->next;
    1728       const int count = Walker->ListOfBonds.size();
     1713    for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
     1714      const int count = (*iter)->ListOfBonds.size();
    17291715      if (MaxNeighbours < count)
    17301716        MaxNeighbours = count;
    17311717    }
    17321718  }
    1733   *output << "# ATOMDATA Id name resName resSeq x=3 charge type neighbors=" << MaxNeighbours << endl;
     1719  *output << "# ATOMDATA Id name resName resSeq x=3 Charge type neighbors=" << MaxNeighbours << endl;
    17341720
    17351721  // create global to local id map
     
    17521738    int AtomNo = 0;
    17531739    for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
    1754       Walker = (*MolWalker)->start;
    1755       while (Walker->next != (*MolWalker)->end) {
    1756         Walker = Walker->next;
     1740      for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
    17571741        *output << AtomNo+1 << "\t";
    1758         *output << Walker->getName() << "\t";
     1742        *output << (*iter)->getName() << "\t";
    17591743        *output << (*MolWalker)->name << "\t";
    17601744        *output << MolCounter+1 << "\t";
    1761         *output << Walker->node->at(0) << "\t" << Walker->node->at(1) << "\t" << Walker->node->at(2) << "\t";
    1762         *output << (double)Walker->type->Valence << "\t";
    1763         *output << Walker->type->symbol << "\t";
    1764         for (BondList::iterator runner = Walker->ListOfBonds.begin(); runner != Walker->ListOfBonds.end(); runner++)
    1765           *output << LocalNotoGlobalNoMap[MolCounter][ (*runner)->GetOtherAtom(Walker)->nr ]+1 << "\t";
    1766         for(int i=Walker->ListOfBonds.size(); i < MaxNeighbours; i++)
     1745        *output << (*iter)->node->at(0) << "\t" << (*iter)->node->at(1) << "\t" << (*iter)->node->at(2) << "\t";
     1746        *output << (double)(*iter)->type->Valence << "\t";
     1747        *output << (*iter)->type->symbol << "\t";
     1748        for (BondList::iterator runner = (*iter)->ListOfBonds.begin(); runner != (*iter)->ListOfBonds.end(); runner++)
     1749          *output << LocalNotoGlobalNoMap[MolCounter][ (*runner)->GetOtherAtom(*iter)->nr ]+1 << "\t";
     1750        for(int i=(*iter)->ListOfBonds.size(); i < MaxNeighbours; i++)
    17671751          *output << "-\t";
    17681752        *output << endl;
  • src/helpers.hpp

    r8f215d ra7b761b  
    8383};
    8484
    85 /** Creates a lookup table for true father's Atom::Nr -> atom ptr.
    86  * \param *start begin of chain list
    87  * \paran *end end of chain list
    88  * \param **Lookuptable pointer to return allocated lookup table (should be NULL on start)
    89  * \param count optional predetermined size for table (otherwise we set the count to highest true father id)
    90  * \return true - success, false - failure
    91  */
    92 template <typename T> bool CreateFatherLookupTable(T *start, T *end, T **&LookupTable, int count = 0)
    93 {
    94   bool status = true;
    95   T *Walker = NULL;
    96   int AtomNo;
    97 
    98   if (LookupTable != NULL) {
    99     DoLog(0) && (Log() << Verbose(0) << "Pointer for Lookup table is not NULL! Aborting ..." <<endl);
    100     return false;
    101   }
    102 
    103   // count them
    104   if (count == 0) {
    105     Walker = start;
    106     while (Walker->next != end) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron
    107       Walker = Walker->next;
    108       count = (count < Walker->GetTrueFather()->nr) ? Walker->GetTrueFather()->nr : count;
    109     }
    110   }
    111   if (count <= 0) {
    112     DoLog(0) && (Log() << Verbose(0) << "Count of lookup list is 0 or less." << endl);
    113     return false;
    114   }
    115 
    116   // allocate and fill
    117   LookupTable = Calloc<T*>(count, "CreateFatherLookupTable - **LookupTable");
    118   if (LookupTable == NULL) {
    119     DoeLog(0) && (eLog()<< Verbose(0) << "LookupTable memory allocation failed!" << endl);
    120     performCriticalExit();
    121     status = false;
    122   } else {
    123     Walker = start;
    124     while (Walker->next != end) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron
    125       Walker = Walker->next;
    126       AtomNo = Walker->GetTrueFather()->nr;
    127       if ((AtomNo >= 0) && (AtomNo < count)) {
    128         //*out << "Setting LookupTable[" << AtomNo << "] to " << *Walker << endl;
    129         LookupTable[AtomNo] = Walker;
    130       } else {
    131         DoLog(0) && (Log() << Verbose(0) << "Walker " << *Walker << " exceeded range of nuclear ids [0, " << count << ")." << endl);
    132         status = false;
    133         break;
    134       }
    135     }
    136   }
    137 
    138   return status;
    139 };
    140 
    14185/** Frees a two-dimensional array.
    14286 * \param *ptr pointer to array
  • src/lists.hpp

    r8f215d ra7b761b  
    134134};
    135135
    136 /** Returns the first marker in a chain list.
    137  * \param *me one arbitrary item in chain list
    138  * \return poiner to first marker
    139  */
    140 template <typename X> X *GetFirst(X *me)
    141 {
    142   X *Binder = me;
    143   while(Binder->previous != 0)
    144     Binder = Binder->previous;
    145   return Binder;
    146 };
    147 
    148 /** Returns the last marker in a chain list.
    149  * \param *me one arbitrary item in chain list
    150  * \return poiner to last marker
    151  */
    152 template <typename X> X *GetLast(X *me)
    153 {
    154   X *Binder = me;
    155   while(Binder->next != 0)
    156     Binder = Binder->next;
    157   return Binder;
    158 };
    159 
    160136#endif /* LISTS_HPP_ */
  • src/molecule.cpp

    r8f215d ra7b761b  
    3535 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero.
    3636 */
    37 molecule::molecule(const periodentafel * const teil) : elemente(teil), start(World::getInstance().createAtom()), end(World::getInstance().createAtom()),
    38   first(new bond(start, end, 1, -1)), last(new bond(start, end, 1, -1)), MDSteps(0), AtomCount(0),
     37molecule::molecule(const periodentafel * const teil) : elemente(teil),
     38  first(new bond(0, 0, 1, -1)), last(new bond(0, 0, 1, -1)), MDSteps(0),
    3939  BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.),
    4040  ActiveFlag(false), IndexNr(-1),
    4141  formula(this,boost::bind(&molecule::calcFormula,this)),
    42   last_atom(0),
    43   InternalPointer(start)
    44 {
    45   // init atom chain list
    46   start->father = NULL;
    47   end->father = NULL;
    48   link(start,end);
    49 
     42  AtomCount(this,boost::bind(&molecule::doCountAtoms,this)), last_atom(0),  InternalPointer(begin())
     43{
    5044  // init bond chain list
    5145  link(first,last);
     
    6963  delete(first);
    7064  delete(last);
    71   end->getWorld()->destroyAtom(end);
    72   start->getWorld()->destroyAtom(start);
    7365};
    7466
     
    8173const std::string molecule::getName(){
    8274  return std::string(name);
     75}
     76
     77int molecule::getAtomCount() const{
     78  return *AtomCount;
    8379}
    8480
     
    104100  stringstream sstr;
    105101  periodentafel *periode = World::getInstance().getPeriode();
    106   for(atom *Walker = start; Walker != end; Walker = Walker->next) {
    107     counts[Walker->type->getNumber()]++;
     102  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     103    counts[(*iter)->type->getNumber()]++;
    108104  }
    109105  std::map<atomicNumber_t,unsigned int>::reverse_iterator iter;
     
    115111}
    116112
     113/************************** Access to the List of Atoms ****************/
     114
     115
     116molecule::iterator molecule::begin(){
     117  return molecule::iterator(atoms.begin(),this);
     118}
     119
     120molecule::const_iterator molecule::begin() const{
     121  return atoms.begin();
     122}
     123
     124molecule::iterator molecule::end(){
     125  return molecule::iterator(atoms.end(),this);
     126}
     127
     128molecule::const_iterator molecule::end() const{
     129  return atoms.end();
     130}
     131
     132bool molecule::empty() const
     133{
     134  return (begin() == end());
     135}
     136
     137size_t molecule::size() const
     138{
     139  size_t counter = 0;
     140  for (molecule::const_iterator iter = begin(); iter != end (); ++iter)
     141    counter++;
     142  return counter;
     143}
     144
     145molecule::const_iterator molecule::erase( const_iterator loc )
     146{
     147  molecule::const_iterator iter = loc;
     148  iter--;
     149  atoms.erase( loc );
     150  return iter;
     151}
     152
     153molecule::const_iterator molecule::erase( atom *& key )
     154{
     155  cout << "trying to erase atom" << endl;
     156  molecule::const_iterator iter = find(key);
     157  if (iter != end()){
     158    // remove this position and step forward (post-increment)
     159    atoms.erase( iter++ );
     160  }
     161  return iter;
     162}
     163
     164molecule::const_iterator molecule::find ( atom *& key ) const
     165{
     166  return atoms.find( key );
     167}
     168
     169pair<molecule::iterator,bool> molecule::insert ( atom * const key )
     170{
     171  pair<atomSet::iterator,bool> res = atoms.insert(key);
     172  return pair<iterator,bool>(iterator(res.first,this),res.second);
     173}
    117174
    118175/** Adds given atom \a *pointer from molecule list.
     
    123180bool molecule::AddAtom(atom *pointer)
    124181{
    125   bool retval = false;
    126182  OBSERVE;
    127183  if (pointer != NULL) {
    128184    pointer->sort = &pointer->nr;
    129     pointer->nr = last_atom++;  // increase number within molecule
    130     AtomCount++;
    131185    if (pointer->type != NULL) {
    132186      if (ElementsInMolecule[pointer->type->Z] == 0)
     
    141195      }
    142196    }
    143     retval = add(pointer, end);
    144   }
    145   return retval;
     197    insert(pointer);
     198  }
     199  return true;
    146200};
    147201
     
    157211  if (pointer != NULL) {
    158212    atom *walker = pointer->clone();
    159     stringstream sstr;
    160     sstr << pointer->getName();
    161     walker->setName(sstr.str());
     213    walker->setName(pointer->getName());
    162214    walker->nr = last_atom++;  // increase number within molecule
    163     add(walker, end);
     215    insert(walker);
    164216    if ((pointer->type != NULL) && (pointer->type->Z != 1))
    165217      NoNonHydrogen++;
    166     AtomCount++;
    167218    retval=walker;
    168219  }
     
    574625
    575626  // copy values
    576   copy->CountAtoms();
    577627  copy->CountElements();
    578628  if (first->next != last) {  // if adjaceny list is present
     
    609659{
    610660  bond *Binder = NULL;
    611   if ((atom1 != NULL) && (FindAtom(atom1->nr) != NULL) && (atom2 != NULL) && (FindAtom(atom2->nr) != NULL)) {
    612     Binder = new bond(atom1, atom2, degree, BondCount++);
    613     atom1->RegisterBond(Binder);
    614     atom2->RegisterBond(Binder);
    615     if ((atom1->type != NULL) && (atom1->type->Z != 1) && (atom2->type != NULL) && (atom2->type->Z != 1))
    616       NoNonBonds++;
    617     add(Binder, last);
    618   } else {
    619     DoeLog(1) && (eLog()<< Verbose(1) << "Could not add bond between " << atom1->getName() << " and " << atom2->getName() << " as one or both are not present in the molecule." << endl);
    620   }
     661
     662  // some checks to make sure we are able to create the bond
     663  ASSERT(atom1, "First atom in bond-creation was an invalid pointer");
     664  ASSERT(atom2, "Second atom in bond-creation was an invalid pointer");
     665  ASSERT(FindAtom(atom1->nr),"First atom in bond-creation was not part of molecule");
     666  ASSERT(FindAtom(atom2->nr),"Second atom in bond-creation was not parto of molecule");
     667
     668  Binder = new bond(atom1, atom2, degree, BondCount++);
     669  atom1->RegisterBond(Binder);
     670  atom2->RegisterBond(Binder);
     671  if ((atom1->type != NULL) && (atom1->type->Z != 1) && (atom2->type != NULL) && (atom2->type->Z != 1))
     672    NoNonBonds++;
     673  add(Binder, last);
     674
    621675  return Binder;
    622676};
     
    692746bool molecule::RemoveAtom(atom *pointer)
    693747{
     748  ASSERT(pointer, "Null pointer passed to molecule::RemoveAtom().");
     749  OBSERVE;
    694750  if (ElementsInMolecule[pointer->type->Z] != 0)  { // this would indicate an error
    695751    ElementsInMolecule[pointer->type->Z]--;  // decrease number of atom of this element
    696     AtomCount--;
    697752  } else
    698753    DoeLog(1) && (eLog()<< Verbose(1) << "Atom " << pointer->getName() << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl);
     
    700755    ElementCount--;
    701756  RemoveBonds(pointer);
    702   return remove(pointer, start, end);
     757  erase(pointer);
     758  return true;
    703759};
    704760
     
    717773  if (ElementsInMolecule[pointer->type->Z] == 0)  // was last atom of this element?
    718774    ElementCount--;
    719   unlink(pointer);
     775  erase(pointer);
    720776  return true;
    721777};
     
    726782bool molecule::CleanupMolecule()
    727783{
    728   return (cleanup(first,last) && cleanup(start,end));
     784  for (molecule::iterator iter = begin(); !empty(); iter = begin())
     785      erase(iter);
     786  return (cleanup(first,last));
    729787};
    730788
     
    733791 * \return pointer to atom or NULL
    734792 */
    735 atom * molecule::FindAtom(int Nr)  const{
    736   atom * walker = find(&Nr, start,end);
    737   if (walker != NULL) {
     793atom * molecule::FindAtom(int Nr)  const
     794{
     795  molecule::const_iterator iter = begin();
     796  for (; iter != end(); ++iter)
     797    if ((*iter)->nr == Nr)
     798      break;
     799  if (iter != end()) {
    738800    //Log() << Verbose(0) << "Found Atom Nr. " << walker->nr << endl;
    739     return walker;
     801    return (*iter);
    740802  } else {
    741803    DoLog(0) && (Log() << Verbose(0) << "Atom not found in list." << endl);
     
    867929    now = time((time_t *)NULL);   // Get the system time and put it into 'now' as 'calender time'
    868930    for (int step=0;step<MDSteps;step++) {
    869       *output << AtomCount << "\n\tCreated by molecuilder, step " << step << ", on " << ctime(&now);
     931      *output << getAtomCount() << "\n\tCreated by molecuilder, step " << step << ", on " << ctime(&now);
    870932      ActOnAllAtoms( &atom::OutputTrajectoryXYZ, output, step );
    871933    }
     
    884946  if (output != NULL) {
    885947    now = time((time_t *)NULL);   // Get the system time and put it into 'now' as 'calender time'
    886     *output << AtomCount << "\n\tCreated by molecuilder on " << ctime(&now);
     948    *output << getAtomCount() << "\n\tCreated by molecuilder on " << ctime(&now);
    887949    ActOnAllAtoms( &atom::OutputXYZLine, output );
    888950    return true;
     
    894956 * \param *out output stream for debugging
    895957 */
    896 void molecule::CountAtoms()
    897 {
     958int molecule::doCountAtoms()
     959{
     960  int res = size();
    898961  int i = 0;
    899   atom *Walker = start;
    900   while (Walker->next != end) {
    901     Walker = Walker->next;
     962  NoNonHydrogen = 0;
     963  for (molecule::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
     964    (*iter)->nr = i;   // update number in molecule (for easier referencing in FragmentMolecule lateron)
     965    if ((*iter)->type->Z != 1) // count non-hydrogen atoms whilst at it
     966      NoNonHydrogen++;
     967    stringstream sstr;
     968    sstr << (*iter)->type->symbol << (*iter)->nr+1;
     969    (*iter)->setName(sstr.str());
     970    Log() << Verbose(3) << "Naming atom nr. " << (*iter)->nr << " " << (*iter)->getName() << "." << endl;
    902971    i++;
    903972  }
    904   if ((AtomCount == 0) || (i != AtomCount)) {
    905     DoLog(3) && (Log() << Verbose(3) << "Mismatch in AtomCount " << AtomCount << " and recounted number " << i << ", renaming all." << endl);
    906     AtomCount = i;
    907 
    908     // count NonHydrogen atoms and give each atom a unique name
    909     if (AtomCount != 0) {
    910       i=0;
    911       NoNonHydrogen = 0;
    912       Walker = start;
    913       while (Walker->next != end) {
    914         Walker = Walker->next;
    915         Walker->nr = i;   // update number in molecule (for easier referencing in FragmentMolecule lateron)
    916         if (Walker->type->Z != 1) // count non-hydrogen atoms whilst at it
    917           NoNonHydrogen++;
    918         stringstream sstr;
    919         sstr << Walker->type->symbol << Walker->nr+1;
    920         Walker->setName(sstr.str());
    921         DoLog(3) && (Log() << Verbose(3) << "Naming atom nr. " << Walker->nr << " " << Walker->getName() << "." << endl);
    922         i++;
    923       }
    924     } else
    925       DoLog(3) && (Log() << Verbose(3) << "AtomCount is still " << AtomCount << ", thus counting nothing." << endl);
    926   }
     973  return res;
    927974};
    928975
     
    9861033  /// first count both their atoms and elements and update lists thereby ...
    9871034  //Log() << Verbose(0) << "Counting atoms, updating list" << endl;
    988   CountAtoms();
    989   OtherMolecule->CountAtoms();
    9901035  CountElements();
    9911036  OtherMolecule->CountElements();
     
    9941039  /// -# AtomCount
    9951040  if (result) {
    996     if (AtomCount != OtherMolecule->AtomCount) {
    997       DoLog(4) && (Log() << Verbose(4) << "AtomCounts don't match: " << AtomCount << " == " << OtherMolecule->AtomCount << endl);
     1041    if (getAtomCount() != OtherMolecule->getAtomCount()) {
     1042      DoLog(4) && (Log() << Verbose(4) << "AtomCounts don't match: " << getAtomCount() << " == " << OtherMolecule->getAtomCount() << endl);
    9981043      result = false;
    999     } else Log() << Verbose(4) << "AtomCounts match: " << AtomCount << " == " << OtherMolecule->AtomCount << endl;
     1044    } else Log() << Verbose(4) << "AtomCounts match: " << getAtomCount() << " == " << OtherMolecule->getAtomCount() << endl;
    10001045  }
    10011046  /// -# ElementCount
     
    10341079  if (result) {
    10351080    DoLog(5) && (Log() << Verbose(5) << "Calculating distances" << endl);
    1036     Distances = Calloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
    1037     OtherDistances = Calloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
     1081    Distances = Calloc<double>(getAtomCount(), "molecule::IsEqualToWithinThreshold: Distances");
     1082    OtherDistances = Calloc<double>(getAtomCount(), "molecule::IsEqualToWithinThreshold: OtherDistances");
    10381083    SetIndexedArrayForEachAtomTo ( Distances, &atom::nr, &atom::DistanceSquaredToVector, (const Vector &)CenterOfGravity);
    10391084    SetIndexedArrayForEachAtomTo ( OtherDistances, &atom::nr, &atom::DistanceSquaredToVector, (const Vector &)CenterOfGravity);
     
    10411086    /// ... sort each list (using heapsort (o(N log N)) from GSL)
    10421087    DoLog(5) && (Log() << Verbose(5) << "Sorting distances" << endl);
    1043     PermMap = Calloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");
    1044     OtherPermMap = Calloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
    1045     gsl_heapsort_index (PermMap, Distances, AtomCount, sizeof(double), CompareDoubles);
    1046     gsl_heapsort_index (OtherPermMap, OtherDistances, AtomCount, sizeof(double), CompareDoubles);
    1047     PermutationMap = Calloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
     1088    PermMap = Calloc<size_t>(getAtomCount(), "molecule::IsEqualToWithinThreshold: *PermMap");
     1089    OtherPermMap = Calloc<size_t>(getAtomCount(), "molecule::IsEqualToWithinThreshold: *OtherPermMap");
     1090    gsl_heapsort_index (PermMap, Distances, getAtomCount(), sizeof(double), CompareDoubles);
     1091    gsl_heapsort_index (OtherPermMap, OtherDistances, getAtomCount(), sizeof(double), CompareDoubles);
     1092    PermutationMap = Calloc<int>(getAtomCount(), "molecule::IsEqualToWithinThreshold: *PermutationMap");
    10481093    DoLog(5) && (Log() << Verbose(5) << "Combining Permutation Maps" << endl);
    1049     for(int i=AtomCount;i--;)
     1094    for(int i=getAtomCount();i--;)
    10501095      PermutationMap[PermMap[i]] = (int) OtherPermMap[i];
    10511096
     
    10531098    DoLog(4) && (Log() << Verbose(4) << "Comparing distances" << endl);
    10541099    flag = 0;
    1055     for (int i=0;i<AtomCount;i++) {
     1100    for (int i=0;i<getAtomCount();i++) {
    10561101      DoLog(5) && (Log() << Verbose(5) << "Distances squared: |" << Distances[PermMap[i]] << " - " << OtherDistances[OtherPermMap[i]] << "| = " << fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) << " ?<? " <<  threshold << endl);
    10571102      if (fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) > threshold*threshold)
     
    10891134int * molecule::GetFatherSonAtomicMap(molecule *OtherMolecule)
    10901135{
    1091   atom *Walker = NULL, *OtherWalker = NULL;
    10921136  DoLog(3) && (Log() << Verbose(3) << "Begin of GetFatherAtomicMap." << endl);
    1093   int *AtomicMap = Malloc<int>(AtomCount, "molecule::GetAtomicMap: *AtomicMap");
    1094   for (int i=AtomCount;i--;)
     1137  int *AtomicMap = Malloc<int>(getAtomCount(), "molecule::GetAtomicMap: *AtomicMap");
     1138  for (int i=getAtomCount();i--;)
    10951139    AtomicMap[i] = -1;
    10961140  if (OtherMolecule == this) {  // same molecule
    1097     for (int i=AtomCount;i--;) // no need as -1 means already that there is trivial correspondence
     1141    for (int i=getAtomCount();i--;) // no need as -1 means already that there is trivial correspondence
    10981142      AtomicMap[i] = i;
    10991143    DoLog(4) && (Log() << Verbose(4) << "Map is trivial." << endl);
    11001144  } else {
    11011145    DoLog(4) && (Log() << Verbose(4) << "Map is ");
    1102     Walker = start;
    1103     while (Walker->next != end) {
    1104       Walker = Walker->next;
    1105       if (Walker->father == NULL) {
    1106         AtomicMap[Walker->nr] = -2;
     1146    for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     1147      if ((*iter)->father == NULL) {
     1148        AtomicMap[(*iter)->nr] = -2;
    11071149      } else {
    1108         OtherWalker = OtherMolecule->start;
    1109         while (OtherWalker->next != OtherMolecule->end) {
    1110           OtherWalker = OtherWalker->next;
     1150        for (molecule::const_iterator runner = OtherMolecule->begin(); runner != OtherMolecule->end(); ++runner) {
    11111151      //for (int i=0;i<AtomCount;i++) { // search atom
    11121152        //for (int j=0;j<OtherMolecule->AtomCount;j++) {
    1113           //Log() << Verbose(4) << "Comparing father " << Walker->father << " with the other one " << OtherWalker->father << "." << endl;
    1114           if (Walker->father == OtherWalker)
    1115             AtomicMap[Walker->nr] = OtherWalker->nr;
     1153          //Log() << Verbose(4) << "Comparing father " << (*iter)->father << " with the other one " << (*runner)->father << "." << endl;
     1154          if ((*iter)->father == (*runner))
     1155            AtomicMap[(*iter)->nr] = (*runner)->nr;
    11161156        }
    11171157      }
    1118       DoLog(0) && (Log() << Verbose(0) << AtomicMap[Walker->nr] << "\t");
     1158      DoLog(0) && (Log() << Verbose(0) << AtomicMap[(*iter)->nr] << "\t");
    11191159    }
    11201160    DoLog(0) && (Log() << Verbose(0) << endl);
     
    11501190void molecule::SetIndexedArrayForEachAtomTo ( atom **array, int ParticleInfo::*index) const
    11511191{
    1152   atom *Walker = start;
    1153   while (Walker->next != end) {
    1154     Walker = Walker->next;
    1155     array[(Walker->*index)] = Walker;
     1192  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     1193    array[((*iter)->*index)] = (*iter);
    11561194  }
    11571195};
  • src/molecule.hpp

    r8f215d ra7b761b  
    3434#include "tesselation.hpp"
    3535#include "Patterns/Observer.hpp"
     36#include "Patterns/ObservedIterator.hpp"
    3637#include "Patterns/Cacheable.hpp"
    3738
     
    8889  friend molecule *NewMolecule();
    8990  friend void DeleteMolecule(molecule *);
     91
    9092  public:
     93    typedef std::set<atom*> atomSet;
     94    typedef ObservedIterator<atomSet> iterator;
     95    typedef atomSet::const_iterator const_iterator;
     96
    9197    const periodentafel * const elemente; //!< periodic table with each element
    92     atom *start;        //!< start of atom list
    93     atom *end;          //!< end of atom list
     98    // old deprecated atom handling
     99    //atom *start;        //!< start of atom list
     100    //atom *end;          //!< end of atom list
    94101    bond *first;        //!< start of bond list
    95102    bond *last;         //!< end of bond list
    96103    int MDSteps;        //!< The number of MD steps in Trajectories
    97     int AtomCount;          //!< number of atoms, brought up-to-date by CountAtoms()
     104    //int AtomCount;          //!< number of atoms, brought up-to-date by CountAtoms()
    98105    int BondCount;          //!< number of atoms, brought up-to-date by CountBonds()
    99106    int ElementCount;       //!< how many unique elements are therein
     
    110117  private:
    111118    Cacheable<string> formula;
     119    Cacheable<int>    AtomCount;
    112120    moleculeId_t id;
     121    atomSet atoms; //<!set of atoms
    113122  protected:
     123    //void CountAtoms();
     124    /**
     125     * this iterator type should be used for internal variables, \
     126     * since it will not lock
     127     */
     128    typedef atomSet::iterator internal_iterator;
     129
     130
    114131    molecule(const periodentafel * const teil);
    115132    virtual ~molecule();
     
    119136  //getter and setter
    120137  const std::string getName();
     138  int getAtomCount() const;
     139  int doCountAtoms();
    121140  moleculeId_t getId();
    122141  void setId(moleculeId_t);
     
    125144  std::string calcFormula();
    126145
     146  iterator begin();
     147  const_iterator begin() const;
     148  iterator end();
     149  const_iterator end() const;
     150  bool empty() const;
     151  size_t size() const;
     152  const_iterator erase( const_iterator loc );
     153  const_iterator erase( atom *& key );
     154  const_iterator find (  atom *& key ) const;
     155  pair<iterator,bool> insert ( atom * const key );
     156
    127157
    128158  // re-definition of virtual functions from PointCloud
     
    130160  Vector *GetCenter() const ;
    131161  TesselPoint *GetPoint() const ;
    132   TesselPoint *GetTerminalPoint() const ;
    133162  int GetMaxId() const;
    134163  void GoToNext() const ;
    135   void GoToPrevious() const ;
    136164  void GoToFirst() const ;
    137   void GoToLast() const ;
    138165  bool IsEmpty() const ;
    139166  bool IsEnd() const ;
     
    230257
    231258  /// Count and change present atoms' coordination.
    232   void CountAtoms();
    233259  void CountElements();
    234260  void CalculateOrbitals(class config &configuration);
     
    299325  bool StoreForcesFile(MoleculeListClass *BondFragments, char *path, int *SortIndex);
    300326  bool CreateMappingLabelsToConfigSequence(int *&SortIndex);
     327  bool CreateFatherLookupTable(atom **&LookupTable, int count = 0);
    301328  void BreadthFirstSearchAdd(molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem);
    302329  /// -# BOSSANOVA
     
    327354  private:
    328355  int last_atom;      //!< number given to last atom
    329   mutable atom *InternalPointer;  //!< internal pointer for PointCloud
     356  mutable internal_iterator InternalPointer;  //!< internal pointer for PointCloud
    330357};
    331358
  • src/molecule_dynamics.cpp

    r8f215d ra7b761b  
    2828  gsl_matrix *A = gsl_matrix_alloc(NDIM,NDIM);
    2929  gsl_vector *x = gsl_vector_alloc(NDIM);
    30   atom * Runner = mol->start;
    3130  atom *Sprinter = NULL;
    3231  Vector trajectory1, trajectory2, normal, TestVector;
    3332  double Norm1, Norm2, tmp, result = 0.;
    3433
    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++)
     34  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     35    if ((*iter) == Walker) // hence, we only go up to the Walker, not beyond (similar to i=0; i<j; i++)
    3836      break;
    3937    // determine normalized trajectories direction vector (n1, n2)
     
    4240    trajectory1.Normalize();
    4341    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);
     42    Sprinter = Params.PermutationMap[(*iter)->nr];   // find second target point
     43    trajectory2 = Sprinter->Trajectory.R.at(Params.endstep) - (*iter)->Trajectory.R.at(Params.startstep);
    4644    trajectory2.Normalize();
    4745    Norm2 = trajectory1.Norm();
    4846    // check whether either is zero()
    4947    if ((Norm1 < MYEPSILON) && (Norm2 < MYEPSILON)) {
    50       tmp = Walker->Trajectory.R.at(Params.startstep).distance(Runner->Trajectory.R.at(Params.startstep));
     48      tmp = Walker->Trajectory.R.at(Params.startstep).distance((*iter)->Trajectory.R.at(Params.startstep));
    5149    } else if (Norm1 < MYEPSILON) {
    5250      Sprinter = Params.PermutationMap[Walker->nr];   // find first target point
    53       trajectory1 = Sprinter->Trajectory.R.at(Params.endstep) - Runner->Trajectory.R.at(Params.startstep);
     51      trajectory1 = Sprinter->Trajectory.R.at(Params.endstep) - (*iter)->Trajectory.R.at(Params.startstep);
    5452      trajectory2 *= trajectory1.ScalarProduct(trajectory2); // trajectory2 is scaled to unity, hence we don't need to divide by anything
    5553      trajectory1 -= trajectory2;   // project the part in norm direction away
    5654      tmp = trajectory1.Norm();  // remaining norm is distance
    5755    } else if (Norm2 < MYEPSILON) {
    58       Sprinter = Params.PermutationMap[Runner->nr];   // find second target point
     56      Sprinter = Params.PermutationMap[(*iter)->nr];   // find second target point
    5957      trajectory2 = Sprinter->Trajectory.R.at(Params.endstep) - Walker->Trajectory.R.at(Params.startstep);  // copy second offset
    6058      trajectory1 *= trajectory2.ScalarProduct(trajectory1); // trajectory1 is scaled to unity, hence we don't need to divide by anything
     
    6664  //        Log() << Verbose(0) << " and ";
    6765  //        Log() << Verbose(0) << trajectory2;
    68       tmp = Walker->Trajectory.R.at(Params.startstep).distance(Runner->Trajectory.R.at(Params.startstep));
     66      tmp = Walker->Trajectory.R.at(Params.startstep).distance((*iter)->Trajectory.R.at(Params.startstep));
    6967  //        Log() << Verbose(0) << " with distance " << tmp << "." << endl;
    7068    } else { // determine distance by finding minimum distance
    71   //        Log() << Verbose(3) << "Both trajectories of " << *Walker << " and " << *Runner << " are linear independent ";
     69  //        Log() << Verbose(3) << "Both trajectories of " << *Walker << " and " << *(*iter) << " are linear independent ";
    7270  //        Log() << Verbose(0) << endl;
    7371  //        Log() << Verbose(0) << "First Trajectory: ";
     
    8583        gsl_matrix_set(A, 1, i, trajectory2[i]);
    8684        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]));
     85        gsl_vector_set(x,i, (Walker->Trajectory.R.at(Params.startstep)[i] - (*iter)->Trajectory.R.at(Params.startstep)[i]));
    8886      }
    8987      // solve the linear system by Householder transformations
     
    9694      trajectory2.Scale(gsl_vector_get(x,1));
    9795      normal.Scale(gsl_vector_get(x,2));
    98       TestVector = Runner->Trajectory.R.at(Params.startstep) + trajectory2 + normal
     96      TestVector = (*iter)->Trajectory.R.at(Params.startstep) + trajectory2 + normal
    9997                   - (Walker->Trajectory.R.at(Params.startstep) + trajectory1);
    10098      if (TestVector.Norm() < MYEPSILON) {
     
    125123{
    126124  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)) {
     125  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     126    if ((Params.PermutationMap[Walker->nr] == Params.PermutationMap[(*iter)->nr]) && (Walker->nr < (*iter)->nr)) {
    131127  //    atom *Sprinter = PermutationMap[Walker->nr];
    132   //        Log() << Verbose(0) << *Walker << " and " << *Runner << " are heading to the same target at ";
     128  //        Log() << Verbose(0) << *Walker << " and " << *(*iter) << " are heading to the same target at ";
    133129  //        Log() << Verbose(0) << Sprinter->Trajectory.R.at(endstep);
    134130  //        Log() << Verbose(0) << ", penalting." << endl;
     
    161157  // go through every atom
    162158  atom *Runner = NULL;
    163   atom *Walker = start;
    164   while (Walker->next != end) {
    165     Walker = Walker->next;
     159  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    166160    // 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)));
     161    Runner = Params.PermutationMap[(*iter)->nr];   // find target point
     162    tmp = ((*iter)->Trajectory.R.at(Params.startstep).distance(Runner->Trajectory.R.at(Params.endstep)));
    169163    tmp *= Params.IsAngstroem ? 1. : 1./AtomicLengthToAngstroem;
    170164    result += Params.PenaltyConstants[0] * tmp;
     
    172166
    173167    // second term: sum of distances to other trajectories
    174     result += SumDistanceOfTrajectories(Walker, this, Params);
     168    result += SumDistanceOfTrajectories((*iter), this, Params);
    175169
    176170    // third term: penalty for equal targets
    177     result += PenalizeEqualTargets(Walker, this, Params);
     171    result += PenalizeEqualTargets((*iter), this, Params);
    178172  }
    179173
     
    213207void FillDistanceList(molecule *mol, struct EvaluatePotential &Params)
    214208{
    215   for (int i=mol->AtomCount; i--;) {
     209  for (int i=mol->getAtomCount(); i--;) {
    216210    Params.DistanceList[i] = new DistanceMap;    // is the distance sorted target list per atom
    217211    Params.DistanceList[i]->clear();
    218212  }
    219213
    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) );
     214  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     215    for (molecule::const_iterator runner = mol->begin(); runner != mol->end(); ++runner) {
     216      Params.DistanceList[(*iter)->nr]->insert( DistancePair((*iter)->Trajectory.R.at(Params.startstep).distance((*runner)->Trajectory.R.at(Params.endstep)), (*runner)) );
    228217    }
    229218  }
     
    237226void CreateInitialLists(molecule *mol, struct EvaluatePotential &Params)
    238227{
    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);
     228  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     229    Params.StepList[(*iter)->nr] = Params.DistanceList[(*iter)->nr]->begin();    // stores the step to the next iterator that could be a possible next target
     230    Params.PermutationMap[(*iter)->nr] = Params.DistanceList[(*iter)->nr]->begin()->second;   // always pick target with the smallest distance
     231    Params.DoubleList[Params.DistanceList[(*iter)->nr]->begin()->second->nr]++;            // increase this target's source count (>1? not injective)
     232    Params.DistanceIterators[(*iter)->nr] = Params.DistanceList[(*iter)->nr]->begin();    // and remember which one we picked
     233    DoLog(2) && (Log() << Verbose(2) << **iter << " starts with distance " << Params.DistanceList[(*iter)->nr]->begin()->first << "." << endl);
    247234  }
    248235};
     
    285272void MakeInjectivePermutation(molecule *mol, struct EvaluatePotential &Params)
    286273{
    287   atom *Walker = mol->start;
     274  molecule::const_iterator iter = mol->begin();
    288275  DistanceMap::iterator NewBase;
    289276  double Potential = fabs(mol->ConstrainedPotential(Params));
    290277
     278  if (mol->empty()) {
     279    eLog() << Verbose(1) << "Molecule is empty." << endl;
     280    return;
     281  }
    291282  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
     283    PrintPermutationMap(mol->getAtomCount(), Params);
     284    iter++;
     285    if (iter == mol->end()) // round-robin at the end
     286      iter = mol->begin();
     287    if (Params.DoubleList[Params.DistanceIterators[(*iter)->nr]->second->nr] <= 1)  // no need to make those injective that aren't
    297288      continue;
    298289    // 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
     290    Potential = TryNextNearestNeighbourForInjectivePermutation(mol, (*iter), Potential, Params);
     291  }
     292  for (int i=mol->getAtomCount(); i--;) // now each single entry in the DoubleList should be <=1
    302293    if (Params.DoubleList[i] > 1) {
    303294      DoeLog(0) && (eLog()<< Verbose(0) << "Failed to create an injective PermutationMap!" << endl);
     
    338329  double Potential, OldPotential, OlderPotential;
    339330  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");
     331  Params.PermutationMap = Calloc<atom*>(getAtomCount(), "molecule::MinimiseConstrainedPotential: Params.**PermutationMap");
     332  Params.DistanceList = Malloc<DistanceMap*>(getAtomCount(), "molecule::MinimiseConstrainedPotential: Params.**DistanceList");
     333  Params.DistanceIterators = Malloc<DistanceMap::iterator>(getAtomCount(), "molecule::MinimiseConstrainedPotential: Params.*DistanceIterators");
     334  Params.DoubleList = Calloc<int>(getAtomCount(), "molecule::MinimiseConstrainedPotential: Params.*DoubleList");
     335  Params.StepList = Malloc<DistanceMap::iterator>(getAtomCount(), "molecule::MinimiseConstrainedPotential: Params.*StepList");
    345336  int round;
    346   atom *Walker = NULL, *Runner = NULL, *Sprinter = NULL;
     337  atom *Sprinter = NULL;
    347338  DistanceMap::iterator Rider, Strider;
    348339
     
    371362    DoLog(2) && (Log() << Verbose(2) << "Starting round " << ++round << ", at current potential " << OldPotential << " ... " << endl);
    372363    OlderPotential = OldPotential;
     364    molecule::const_iterator iter;
    373365    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();
     366      iter = begin();
     367      for (; iter != end(); ++iter) {
     368        PrintPermutationMap(getAtomCount(), Params);
     369        Sprinter = Params.DistanceIterators[(*iter)->nr]->second;   // store initial partner
     370        Strider = Params.DistanceIterators[(*iter)->nr];  //remember old iterator
     371        Params.DistanceIterators[(*iter)->nr] = Params.StepList[(*iter)->nr];
     372        if (Params.DistanceIterators[(*iter)->nr] == Params.DistanceList[(*iter)->nr]->end()) {// stop, before we run through the list and still on
     373          Params.DistanceIterators[(*iter)->nr] == Params.DistanceList[(*iter)->nr]->begin();
    383374          break;
    384375        }
    385         //Log() << Verbose(2) << "Current Walker: " << *Walker << " with old/next candidate " << *Sprinter << "/" << *DistanceIterators[Walker->nr]->second << "." << endl;
     376        //Log() << Verbose(2) << "Current Walker: " << *(*iter) << " with old/next candidate " << *Sprinter << "/" << *DistanceIterators[(*iter)->nr]->second << "." << endl;
    386377        // 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;
     378        molecule::const_iterator runner = begin();
     379        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)
     380          if (Params.PermutationMap[(*runner)->nr] == Params.DistanceIterators[(*iter)->nr]->second) {
     381            //Log() << Verbose(2) << "Found the corresponding owner " << *(*runner) << " to " << *PermutationMap[(*runner)->nr] << "." << endl;
    391382            break;
    392383          }
    393           Runner = Runner->next;
    394384        }
    395         if (Runner != end) { // we found the other source
     385        if (runner != end()) { // we found the other source
    396386          // then look in its distance list for Sprinter
    397           Rider = Params.DistanceList[Runner->nr]->begin();
    398           for (; Rider != Params.DistanceList[Runner->nr]->end(); Rider++)
     387          Rider = Params.DistanceList[(*runner)->nr]->begin();
     388          for (; Rider != Params.DistanceList[(*runner)->nr]->end(); Rider++)
    399389            if (Rider->second == Sprinter)
    400390              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;
     391          if (Rider != Params.DistanceList[(*runner)->nr]->end()) { // if we have found one
     392            //Log() << Verbose(2) << "Current Other: " << *(*runner) << " with old/next candidate " << *PermutationMap[(*runner)->nr] << "/" << *Rider->second << "." << endl;
    403393            // 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);
     394            Params.PermutationMap[(*iter)->nr] = Params.DistanceIterators[(*iter)->nr]->second; // put next farther distance into PermutationMap
     395            Params.PermutationMap[(*runner)->nr] = Sprinter;  // and hand the old target to its respective owner
     396            PrintPermutationMap(getAtomCount(), Params);
    407397            // calculate the new potential
    408398            //Log() << Verbose(2) << "Checking new potential ..." << endl;
     
    410400            if (Potential > OldPotential) { // we made everything worse! Undo ...
    411401              //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;
     402              //Log() << Verbose(3) << "Setting " << *(*runner) << "'s source to " << *Params.DistanceIterators[(*runner)->nr]->second << "." << endl;
    413403              // 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;
     404              Params.PermutationMap[(*runner)->nr] = Params.DistanceIterators[(*runner)->nr]->second;
    415405              // 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;
     406              Params.DistanceIterators[(*iter)->nr] = Strider;  // take next farther distance target
     407              //Log() << Verbose(3) << "Setting " << *(*iter) << "'s source to " << *Params.DistanceIterators[(*iter)->nr]->second << "." << endl;
     408              Params.PermutationMap[(*iter)->nr] = Params.DistanceIterators[(*iter)->nr]->second;
    419409            } else {
    420               Params.DistanceIterators[Runner->nr] = Rider;  // if successful also move the pointer in the iterator list
     410              Params.DistanceIterators[(*runner)->nr] = Rider;  // if successful also move the pointer in the iterator list
    421411              DoLog(3) && (Log() << Verbose(3) << "Found a better permutation, new potential is " << Potential << " vs." << OldPotential << "." << endl);
    422412              OldPotential = Potential;
     
    428418            //Log() << Verbose(0) << endl;
    429419          } else {
    430             DoeLog(1) && (eLog()<< Verbose(1) << *Runner << " was not the owner of " << *Sprinter << "!" << endl);
     420            DoeLog(1) && (eLog()<< Verbose(1) << **runner << " was not the owner of " << *Sprinter << "!" << endl);
    431421            exit(255);
    432422          }
    433423        } else {
    434           Params.PermutationMap[Walker->nr] = Params.DistanceIterators[Walker->nr]->second; // new target has no source!
     424          Params.PermutationMap[(*iter)->nr] = Params.DistanceIterators[(*iter)->nr]->second; // new target has no source!
    435425        }
    436         Params.StepList[Walker->nr]++; // take next farther distance target
     426        Params.StepList[(*iter)->nr]++; // take next farther distance target
    437427      }
    438     } while (Walker->next != end);
     428    } while (++iter != end());
    439429  } while ((OlderPotential - OldPotential) > 1e-3);
    440430  DoLog(1) && (Log() << Verbose(1) << "done." << endl);
     
    442432
    443433  /// free memory and return with evaluated potential
    444   for (int i=AtomCount; i--;)
     434  for (int i=getAtomCount(); i--;)
    445435    Params.DistanceList[i]->clear();
    446436  Free(&Params.DistanceList);
     
    483473  // Get the Permutation Map by MinimiseConstrainedPotential
    484474  atom **PermutationMap = NULL;
    485   atom *Walker = NULL, *Sprinter = NULL;
     475  atom *Sprinter = NULL;
    486476  if (!MapByIdentity)
    487477    MinimiseConstrainedPotential(PermutationMap, startstep, endstep, configuration.GetIsAngstroem());
    488478  else {
    489     PermutationMap = Malloc<atom *>(AtomCount, "molecule::LinearInterpolationBetweenConfiguration: **PermutationMap");
     479    PermutationMap = Malloc<atom *>(getAtomCount(), "molecule::LinearInterpolationBetweenConfiguration: **PermutationMap");
    490480    SetIndexedArrayForEachAtomTo( PermutationMap, &atom::nr );
    491481  }
     
    502492    mol = World::getInstance().createMolecule();
    503493    MoleculePerStep->insert(mol);
    504     Walker = start;
    505     while (Walker->next != end) {
    506       Walker = Walker->next;
     494    for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    507495      // add to molecule list
    508       Sprinter = mol->AddCopyAtom(Walker);
     496      Sprinter = mol->AddCopyAtom((*iter));
    509497      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);
     498        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);
    511499        // add to Trajectories
    512500        //Log() << Verbose(3) << step << ">=" << MDSteps-1 << endl;
    513501        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.;
     502          (*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);
     503          (*iter)->Trajectory.U.at(step)[n] = 0.;
     504          (*iter)->Trajectory.F.at(step)[n] = 0.;
    517505        }
    518506      }
     
    522510
    523511  // store the list to single step files
    524   int *SortIndex = Malloc<int>(AtomCount, "molecule::LinearInterpolationBetweenConfiguration: *SortIndex");
    525   for (int i=AtomCount; i--; )
     512  int *SortIndex = Malloc<int>(getAtomCount(), "molecule::LinearInterpolationBetweenConfiguration: *SortIndex");
     513  for (int i=getAtomCount(); i--; )
    526514    SortIndex[i] = i;
    527515  status = MoleculePerStep->OutputConfigForListOfFragments(&configuration, SortIndex);
     
    567555      return false;
    568556    }
    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);
     557    if (Force.RowCounter[0] != getAtomCount()) {
     558      DoeLog(0) && (eLog()<< Verbose(0) << "Mismatch between number of atoms in file " << Force.RowCounter[0] << " and in molecule " << getAtomCount() << "." << endl);
    571559      performCriticalExit();
    572560      return false;
     
    574562    // correct Forces
    575563    Velocity.Zero();
    576     for(int i=0;i<AtomCount;i++)
     564    for(int i=0;i<getAtomCount();i++)
    577565      for(int d=0;d<NDIM;d++) {
    578566        Velocity[d] += Force.Matrix[0][i][d+5];
    579567      }
    580     for(int i=0;i<AtomCount;i++)
     568    for(int i=0;i<getAtomCount();i++)
    581569      for(int d=0;d<NDIM;d++) {
    582         Force.Matrix[0][i][d+5] -= Velocity[d]/(double)AtomCount;
     570        Force.Matrix[0][i][d+5] -= Velocity[d]/static_cast<double>(getAtomCount());
    583571      }
    584572    // solve a constrained potential if we are meant to
     
    683671      delta_alpha = 0.;
    684672      ActOnAllAtoms( &atom::Thermostat_NoseHoover_init, MDSteps, &delta_alpha );
    685       delta_alpha = (delta_alpha - (3.*AtomCount+1.) * configuration.TargetTemp)/(configuration.HooverMass*Units2Electronmass);
     673      delta_alpha = (delta_alpha - (3.*getAtomCount()+1.) * configuration.TargetTemp)/(configuration.HooverMass*Units2Electronmass);
    686674      configuration.alpha += delta_alpha*configuration.Deltat;
    687675      DoLog(3) && (Log() << Verbose(3) << "alpha = " << delta_alpha << " * " << configuration.Deltat << " = " << configuration.alpha << "." << endl);
  • src/molecule_fragmentation.cpp

    r8f215d ra7b761b  
    3939  int FragmentCount;
    4040  // get maximum bond degree
    41   atom *Walker = start;
    42   while (Walker->next != end) {
    43     Walker = Walker->next;
    44     c = (Walker->ListOfBonds.size() > c) ? Walker->ListOfBonds.size() : c;
     41  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     42    c = ((*iter)->ListOfBonds.size() > c) ? (*iter)->ListOfBonds.size() : c;
    4543  }
    4644  FragmentCount = NoNonHydrogen*(1 << (c*order));
     
    359357map<double, pair<int,int> >  * ReMapAdaptiveCriteriaListToValue(map<int, pair<double,int> > *AdaptiveCriteriaList, molecule *mol)
    360358{
    361   atom *Walker = mol->start;
     359  atom *Walker = NULL;
    362360  map<double, pair<int,int> > *FinalRootCandidates = new map<double, pair<int,int> > ;
    363361  DoLog(1) && (Log() << Verbose(1) << "Root candidate list is: " << endl);
     
    391389bool MarkUpdateCandidates(bool *AtomMask, map<double, pair<int,int> > &FinalRootCandidates, int Order, molecule *mol)
    392390{
    393   atom *Walker = mol->start;
     391  atom *Walker = NULL;
    394392  int No = -1;
    395393  bool status = false;
     
    435433bool molecule::CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path)
    436434{
    437   atom *Walker = start;
    438435  bool status = false;
    439436
    440437  // initialize mask list
    441   for(int i=AtomCount;i--;)
     438  for(int i=getAtomCount();i--;)
    442439    AtomMask[i] = false;
    443440
    444441  if (Order < 0) { // adaptive increase of BondOrder per site
    445     if (AtomMask[AtomCount] == true)  // break after one step
     442    if (AtomMask[getAtomCount()] == true)  // break after one step
    446443      return false;
    447444
     
    457454    if (AdaptiveCriteriaList->empty()) {
    458455      DoeLog(2) && (eLog()<< Verbose(2) << "Unable to parse file, incrementing all." << endl);
    459       while (Walker->next != end) {
    460         Walker = Walker->next;
     456      for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    461457    #ifdef ADDHYDROGEN
    462         if (Walker->type->Z != 1) // skip hydrogen
     458        if ((*iter)->type->Z != 1) // skip hydrogen
    463459    #endif
    464460        {
    465           AtomMask[Walker->nr] = true;  // include all (non-hydrogen) atoms
     461          AtomMask[(*iter)->nr] = true;  // include all (non-hydrogen) atoms
    466462          status = true;
    467463        }
     
    478474    Free(&FinalRootCandidates);
    479475  } else { // global increase of Bond Order
    480     while (Walker->next != end) {
    481       Walker = Walker->next;
     476    for(molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    482477  #ifdef ADDHYDROGEN
    483       if (Walker->type->Z != 1) // skip hydrogen
     478      if ((*iter)->type->Z != 1) // skip hydrogen
    484479  #endif
    485480      {
    486         AtomMask[Walker->nr] = true;  // include all (non-hydrogen) atoms
    487         if ((Order != 0) && (Walker->AdaptiveOrder < Order)) // && (Walker->AdaptiveOrder < MinimumRingSize[Walker->nr]))
     481        AtomMask[(*iter)->nr] = true;  // include all (non-hydrogen) atoms
     482        if ((Order != 0) && ((*iter)->AdaptiveOrder < Order)) // && ((*iter)->AdaptiveOrder < MinimumRingSize[(*iter)->nr]))
    488483          status = true;
    489484      }
    490485    }
    491     if ((Order == 0) && (AtomMask[AtomCount] == false))  // single stepping, just check
     486    if ((!Order) && (!AtomMask[getAtomCount()]))  // single stepping, just check
    492487      status = true;
    493488
     
    500495  }
    501496
    502   PrintAtomMask(AtomMask, AtomCount); // for debugging
     497  PrintAtomMask(AtomMask, getAtomCount()); // for debugging
    503498
    504499  return status;
     
    516511    return false;
    517512  }
    518   SortIndex = Malloc<int>(AtomCount, "molecule::CreateMappingLabelsToConfigSequence: *SortIndex");
    519   for(int i=AtomCount;i--;)
     513  SortIndex = Malloc<int>(getAtomCount(), "molecule::CreateMappingLabelsToConfigSequence: *SortIndex");
     514  for(int i=getAtomCount();i--;)
    520515    SortIndex[i] = -1;
    521516
     
    524519
    525520  return true;
     521};
     522
     523
     524
     525/** Creates a lookup table for true father's Atom::Nr -> atom ptr.
     526 * \param *start begin of list (STL iterator, i.e. first item)
     527 * \paran *end end of list (STL iterator, i.e. one past last item)
     528 * \param **Lookuptable pointer to return allocated lookup table (should be NULL on start)
     529 * \param count optional predetermined size for table (otherwise we set the count to highest true father id)
     530 * \return true - success, false - failure
     531 */
     532bool molecule::CreateFatherLookupTable(atom **&LookupTable, int count)
     533{
     534  bool status = true;
     535  int AtomNo;
     536
     537  if (LookupTable != NULL) {
     538    Log() << Verbose(0) << "Pointer for Lookup table is not NULL! Aborting ..." <<endl;
     539    return false;
     540  }
     541
     542  // count them
     543  if (count == 0) {
     544    for (molecule::iterator iter = begin(); iter != end(); ++iter) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron
     545      count = (count < (*iter)->GetTrueFather()->nr) ? (*iter)->GetTrueFather()->nr : count;
     546    }
     547  }
     548  if (count <= 0) {
     549    Log() << Verbose(0) << "Count of lookup list is 0 or less." << endl;
     550    return false;
     551  }
     552
     553  // allocate and fill
     554  LookupTable = Calloc<atom *>(count, "CreateFatherLookupTable - **LookupTable");
     555  if (LookupTable == NULL) {
     556    eLog() << Verbose(0) << "LookupTable memory allocation failed!" << endl;
     557    performCriticalExit();
     558    status = false;
     559  } else {
     560    for (molecule::iterator iter = begin(); iter != end(); ++iter) {
     561      AtomNo = (*iter)->GetTrueFather()->nr;
     562      if ((AtomNo >= 0) && (AtomNo < count)) {
     563        //*out << "Setting LookupTable[" << AtomNo << "] to " << *(*iter) << endl;
     564        LookupTable[AtomNo] = (*iter);
     565      } else {
     566        Log() << Verbose(0) << "Walker " << *(*iter) << " exceeded range of nuclear ids [0, " << count << ")." << endl;
     567        status = false;
     568        break;
     569      }
     570    }
     571  }
     572
     573  return status;
    526574};
    527575
     
    548596  MoleculeListClass *BondFragments = NULL;
    549597  int *SortIndex = NULL;
    550   int *MinimumRingSize = new int[AtomCount];
     598  int *MinimumRingSize = new int[getAtomCount()];
    551599  int FragmentCounter;
    552600  MoleculeLeafClass *MolecularWalker = NULL;
     
    576624
    577625  // create lookup table for Atom::nr
    578   FragmentationToDo = FragmentationToDo && CreateFatherLookupTable(start, end, ListOfAtoms, AtomCount);
     626  FragmentationToDo = FragmentationToDo && CreateFatherLookupTable(ListOfAtoms, getAtomCount());
    579627
    580628  // === compare it with adjacency file ===
     
    586634
    587635  // analysis of the cycles (print rings, get minimum cycle length) for each subgraph
    588   for(int i=AtomCount;i--;)
    589     MinimumRingSize[i] = AtomCount;
     636  for(int i=getAtomCount();i--;)
     637    MinimumRingSize[i] = getAtomCount();
    590638  MolecularWalker = Subgraphs;
    591639  FragmentCounter = 0;
     
    624672  // ===== 6b. prepare and go into the adaptive (Order<0), single-step (Order==0) or incremental (Order>0) cycle
    625673  KeyStack *RootStack = new KeyStack[Subgraphs->next->Count()];
    626   AtomMask = new bool[AtomCount+1];
    627   AtomMask[AtomCount] = false;
     674  AtomMask = new bool[getAtomCount()+1];
     675  AtomMask[getAtomCount()] = false;
    628676  FragmentationToDo = false;  // if CheckOrderAtSite just ones recommends fragmentation, we will save fragments afterwards
    629677  while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, configuration->configpath))) {
    630678    FragmentationToDo = FragmentationToDo || CheckOrder;
    631     AtomMask[AtomCount] = true;   // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite()
     679    AtomMask[getAtomCount()] = true;   // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite()
    632680    // ===== 6b. fill RootStack for each subgraph (second adaptivity check) =====
    633681    Subgraphs->next->FillRootStackForSubgraphs(RootStack, AtomMask, (FragmentCounter = 0));
     
    768816bool molecule::ParseOrderAtSiteFromFile(char *path)
    769817{
    770   unsigned char *OrderArray = Calloc<unsigned char>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *OrderArray");
    771   bool *MaxArray = Calloc<bool>(AtomCount, "molecule::ParseOrderAtSiteFromFile - *MaxArray");
     818  unsigned char *OrderArray = Calloc<unsigned char>(getAtomCount(), "molecule::ParseOrderAtSiteFromFile - *OrderArray");
     819  bool *MaxArray = Calloc<bool>(getAtomCount(), "molecule::ParseOrderAtSiteFromFile - *MaxArray");
    772820  bool status;
    773821  int AtomNr, value;
     
    872920  atom *OtherFather = NULL;
    873921  atom *FatherOfRunner = NULL;
    874   Leaf->CountAtoms();
    875 
    876   atom *Runner = Leaf->start;
    877   while (Runner->next != Leaf->end) {
    878     Runner = Runner->next;
     922
     923#ifdef ADDHYDROGEN
     924  molecule::const_iterator runner;
     925#endif
     926  // we increment the iter just before skipping the hydrogen
     927  for (molecule::const_iterator iter = Leaf->begin(); iter != Leaf->end();) {
    879928    LonelyFlag = true;
    880     FatherOfRunner = Runner->father;
     929    FatherOfRunner = (*iter)->father;
     930    ASSERT(FatherOfRunner,"Atom without father found");
    881931    if (SonList[FatherOfRunner->nr] != NULL)  {  // check if this, our father, is present in list
    882932      // create all bonds
     
    889939//            Log() << Verbose(3) << "Adding Bond: ";
    890940//            Log() << Verbose(0) <<
    891             Leaf->AddBond(Runner, SonList[OtherFather->nr], (*BondRunner)->BondDegree);
     941            Leaf->AddBond((*iter), SonList[OtherFather->nr], (*BondRunner)->BondDegree);
    892942//            Log() << Verbose(0) << "." << endl;
    893             //NumBonds[Runner->nr]++;
     943            //NumBonds[(*iter)->nr]++;
    894944          } else {
    895945//            Log() << Verbose(3) << "Not adding bond, labels in wrong order." << endl;
     
    899949//          Log() << Verbose(0) << ", who has no son in this fragment molecule." << endl;
    900950#ifdef ADDHYDROGEN
    901           //Log() << Verbose(3) << "Adding Hydrogen to " << Runner->Name << " and a bond in between." << endl;
    902           if(!Leaf->AddHydrogenReplacementAtom((*BondRunner), Runner, FatherOfRunner, OtherFather, IsAngstroem))
     951          //Log() << Verbose(3) << "Adding Hydrogen to " << (*iter)->Name << " and a bond in between." << endl;
     952          if(!Leaf->AddHydrogenReplacementAtom((*BondRunner), (*iter), FatherOfRunner, OtherFather, IsAngstroem))
    903953            exit(1);
    904954#endif
    905           //NumBonds[Runner->nr] += Binder->BondDegree;
     955          //NumBonds[(*iter)->nr] += Binder->BondDegree;
    906956        }
    907957      }
    908958    } else {
    909       DoeLog(1) && (eLog()<< Verbose(1) << "Son " << Runner->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->nr] << "!" << endl);
    910     }
    911     if ((LonelyFlag) && (Leaf->AtomCount > 1)) {
    912       DoLog(0) && (Log() << Verbose(0) << *Runner << "has got bonds only to hydrogens!" << endl);
    913     }
     959    DoeLog(1) && (eLog()<< Verbose(1) << "Son " << (*iter)->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->nr] << "!" << endl);
     960    }
     961    if ((LonelyFlag) && (Leaf->getAtomCount() > 1)) {
     962      DoLog(0) && (Log() << Verbose(0) << **iter << "has got bonds only to hydrogens!" << endl);
     963    }
     964    ++iter;
    914965#ifdef ADDHYDROGEN
    915     while ((Runner->next != Leaf->end) && (Runner->next->type->Z == 1)) // skip added hydrogen
    916       Runner = Runner->next;
     966    while ((iter != Leaf->end()) && ((*iter)->type->Z == 1)){ // skip added hydrogen
     967      iter++;
     968    }
    917969#endif
    918970  }
     
    929981molecule * molecule::StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem)
    930982{
    931   atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
     983  atom **SonList = Calloc<atom*>(getAtomCount(), "molecule::StoreFragmentFromStack: **SonList");
    932984  molecule *Leaf = World::getInstance().createMolecule();
    933985
     
    15561608  FragmentSearch.FragmentSet = new KeySet;
    15571609  FragmentSearch.Root = FindAtom(RootKeyNr);
    1558   FragmentSearch.ShortestPathList = Malloc<int>(AtomCount, "molecule::PowerSetGenerator: *ShortestPathList");
    1559   for (int i=AtomCount;i--;) {
     1610  FragmentSearch.ShortestPathList = Malloc<int>(getAtomCount(), "molecule::PowerSetGenerator: *ShortestPathList");
     1611  for (int i=getAtomCount();i--;) {
    15601612    FragmentSearch.ShortestPathList[i] = -1;
    15611613  }
    15621614
    15631615  // Construct the complete KeySet which we need for topmost level only (but for all Roots)
    1564   atom *Walker = start;
    15651616  KeySet CompleteMolecule;
    1566   while (Walker->next != end) {
    1567     Walker = Walker->next;
    1568     CompleteMolecule.insert(Walker->GetTrueFather()->nr);
     1617  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     1618    CompleteMolecule.insert((*iter)->GetTrueFather()->nr);
    15691619  }
    15701620
     
    15771627    RootKeyNr = RootStack.front();
    15781628    RootStack.pop_front();
    1579     Walker = FindAtom(RootKeyNr);
     1629    atom *Walker = FindAtom(RootKeyNr);
    15801630    // check cyclic lengths
    15811631    //if ((MinimumRingSize[Walker->GetTrueFather()->nr] != -1) && (Walker->GetTrueFather()->AdaptiveOrder+1 > MinimumRingSize[Walker->GetTrueFather()->nr])) {
     
    16641714  Vector Translationvector;
    16651715  //class StackClass<atom *> *CompStack = NULL;
    1666   class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount);
     1716  class StackClass<atom *> *AtomStack = new StackClass<atom *>(getAtomCount());
    16671717  bool flag = true;
    16681718
    16691719  DoLog(2) && (Log() << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl);
    16701720
    1671   ColorList = Calloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
     1721  ColorList = Calloc<enum Shading>(getAtomCount(), "molecule::ScanForPeriodicCorrection: *ColorList");
    16721722  while (flag) {
    16731723    // remove bonds that are beyond bonddistance
     
    17011751      Log() << Verbose(0) << Translationvector <<  endl;
    17021752      // apply to all atoms of first component via BFS
    1703       for (int i=AtomCount;i--;)
     1753      for (int i=getAtomCount();i--;)
    17041754        ColorList[i] = white;
    17051755      AtomStack->Push(Binder->leftatom);
  • src/molecule_geometry.cpp

    r8f215d ra7b761b  
    6969
    7070//  Log() << Verbose(3) << "Begin of CenterEdge." << endl;
    71   atom *ptr = start->next;  // start at first in list
    72   if (ptr != end) {  //list not empty?
     71  molecule::const_iterator iter = begin();  // start at first in list
     72  if (iter != end()) { //list not empty?
    7373    for (int i=NDIM;i--;) {
    74       max->at(i) = ptr->x[i];
    75       min->at(i) = ptr->x[i];
    76     }
    77     while (ptr->next != end) {  // continue with second if present
    78       ptr = ptr->next;
    79       //ptr->Output(1,1,out);
     74      max->at(i) = (*iter)->x[i];
     75      min->at(i) = (*iter)->x[i];
     76    }
     77    for (; iter != end(); ++iter) {// continue with second if present
     78      //(*iter)->Output(1,1,out);
    8079      for (int i=NDIM;i--;) {
    81         max->at(i) = (max->at(i) < ptr->x[i]) ? ptr->x[i] : max->at(i);
    82         min->at(i) = (min->at(i) > ptr->x[i]) ? ptr->x[i] : min->at(i);
     80        max->at(i) = (max->at(i) < (*iter)->x[i]) ? (*iter)->x[i] : max->at(i);
     81        min->at(i) = (min->at(i) > (*iter)->x[i]) ? (*iter)->x[i] : min->at(i);
    8382      }
    8483    }
     
    104103{
    105104  int Num = 0;
    106   atom *ptr = start;  // start at first in list
     105  molecule::const_iterator iter = begin();  // start at first in list
    107106
    108107  Center.Zero();
    109108
    110   if (ptr->next != end) {   //list not empty?
    111     while (ptr->next != end) {  // continue with second if present
    112       ptr = ptr->next;
     109  if (iter != end()) {   //list not empty?
     110    for (; iter != end(); ++iter) {  // continue with second if present
    113111      Num++;
    114       Center += ptr->x;
     112      Center += (*iter)->x;
    115113    }
    116114    Center.Scale(-1./Num); // divide through total number (and sign for direction)
     
    125123Vector * molecule::DetermineCenterOfAll() const
    126124{
    127   atom *ptr = start->next;  // start at first in list
     125  molecule::const_iterator iter = begin();  // start at first in list
    128126  Vector *a = new Vector();
    129127  Vector tmp;
     
    132130  a->Zero();
    133131
    134   if (ptr != end) {   //list not empty?
    135     while (ptr->next != end) {  // continue with second if present
    136       ptr = ptr->next;
     132  if (iter != end()) {   //list not empty?
     133    for (; iter != end(); ++iter) {  // continue with second if present
    137134      Num += 1.;
    138       tmp = ptr->x;
     135      tmp = (*iter)->x;
    139136      (*a) += tmp;
    140137    }
     
    150147Vector * molecule::DetermineCenterOfGravity()
    151148{
    152   atom *ptr = start->next;  // start at first in list
     149  molecule::const_iterator iter = begin();  // start at first in list
    153150  Vector *a = new Vector();
    154151  Vector tmp;
     
    157154  a->Zero();
    158155
    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 = ptr->type->mass * ptr->x;
     156  if (iter != end()) {   //list not empty?
     157    for (; iter != end(); ++iter) {  // continue with second if present
     158      Num += (*iter)->type->mass;
     159      tmp = (*iter)->type->mass * (*iter)->x;
    164160      (*a) += tmp;
    165161    }
     
    202198void molecule::Scale(const double ** const factor)
    203199{
    204   atom *ptr = start;
    205 
    206   while (ptr->next != end) {
    207     ptr = ptr->next;
     200  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    208201    for (int j=0;j<MDSteps;j++)
    209       ptr->Trajectory.R.at(j).ScaleAll(*factor);
    210     ptr->x.ScaleAll(*factor);
     202      (*iter)->Trajectory.R.at(j).ScaleAll(*factor);
     203    (*iter)->x.ScaleAll(*factor);
    211204  }
    212205};
     
    217210void molecule::Translate(const Vector *trans)
    218211{
    219   atom *ptr = start;
    220 
    221   while (ptr->next != end) {
    222     ptr = ptr->next;
     212  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    223213    for (int j=0;j<MDSteps;j++)
    224       ptr->Trajectory.R.at(j) += (*trans);
    225     ptr->x += (*trans);
     214      (*iter)->Trajectory.R.at(j) += (*trans);
     215    (*iter)->x += (*trans);
    226216  }
    227217};
     
    259249void molecule::DeterminePeriodicCenter(Vector &center)
    260250{
    261   atom *Walker = start;
    262251  double * const cell_size = World::getInstance().getDomain();
    263252  double *matrix = ReturnFullMatrixforSymmetric(cell_size);
     
    270259    Center.Zero();
    271260    flag = true;
    272     while (Walker->next != end) {
    273       Walker = Walker->next;
     261    for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
    274262#ifdef ADDHYDROGEN
    275       if (Walker->type->Z != 1) {
     263      if ((*iter)->type->Z != 1) {
    276264#endif
    277         Testvector = Walker->x;
     265        Testvector = (*iter)->x;
    278266        Testvector.MatrixMultiplication(inversematrix);
    279267        Translationvector.Zero();
    280         for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
    281          if (Walker->nr < (*Runner)->GetOtherAtom(Walker)->nr) // otherwise we shift one to, the other fro and gain nothing
     268        for (BondList::const_iterator Runner = (*iter)->ListOfBonds.begin(); Runner != (*iter)->ListOfBonds.end(); (++Runner)) {
     269         if ((*iter)->nr < (*Runner)->GetOtherAtom((*iter))->nr) // otherwise we shift one to, the other fro and gain nothing
    282270            for (int j=0;j<NDIM;j++) {
    283               tmp = Walker->x[j] - (*Runner)->GetOtherAtom(Walker)->x[j];
     271              tmp = (*iter)->x[j] - (*Runner)->GetOtherAtom(*iter)->x[j];
    284272              if ((fabs(tmp)) > BondDistance) {
    285273                flag = false;
    286                 DoLog(0) && (Log() << Verbose(0) << "Hit: atom " << Walker->getName() << " in bond " << *(*Runner) << " has to be shifted due to " << tmp << "." << endl);
     274                DoLog(0) && (Log() << Verbose(0) << "Hit: atom " << (*iter)->getName() << " in bond " << *(*Runner) << " has to be shifted due to " << tmp << "." << endl);
    287275                if (tmp > 0)
    288276                  Translationvector[j] -= 1.;
     
    298286#ifdef ADDHYDROGEN
    299287        // now also change all hydrogens
    300         for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
    301           if ((*Runner)->GetOtherAtom(Walker)->type->Z == 1) {
    302             Testvector = (*Runner)->GetOtherAtom(Walker)->x;
     288        for (BondList::const_iterator Runner = (*iter)->ListOfBonds.begin(); Runner != (*iter)->ListOfBonds.end(); (++Runner)) {
     289          if ((*Runner)->GetOtherAtom((*iter))->type->Z == 1) {
     290            Testvector = (*Runner)->GetOtherAtom((*iter))->x;
    303291            Testvector.MatrixMultiplication(inversematrix);
    304292            Testvector += Translationvector;
     
    315303  Free(&inversematrix);
    316304
    317   Center.Scale(1./(double)AtomCount);
     305  Center.Scale(1./static_cast<double>(getAtomCount()));
    318306};
    319307
     
    325313void molecule::PrincipalAxisSystem(bool DoRotate)
    326314{
    327   atom *ptr = start;  // start at first in list
    328315  double InertiaTensor[NDIM*NDIM];
    329316  Vector *CenterOfGravity = DetermineCenterOfGravity();
     
    336323
    337324  // sum up inertia tensor
    338   while (ptr->next != end) {
    339     ptr = ptr->next;
    340     Vector x = ptr->x;
     325  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     326    Vector x = (*iter)->x;
    341327    //x.SubtractVector(CenterOfGravity);
    342     InertiaTensor[0] += ptr->type->mass*(x[1]*x[1] + x[2]*x[2]);
    343     InertiaTensor[1] += ptr->type->mass*(-x[0]*x[1]);
    344     InertiaTensor[2] += ptr->type->mass*(-x[0]*x[2]);
    345     InertiaTensor[3] += ptr->type->mass*(-x[1]*x[0]);
    346     InertiaTensor[4] += ptr->type->mass*(x[0]*x[0] + x[2]*x[2]);
    347     InertiaTensor[5] += ptr->type->mass*(-x[1]*x[2]);
    348     InertiaTensor[6] += ptr->type->mass*(-x[2]*x[0]);
    349     InertiaTensor[7] += ptr->type->mass*(-x[2]*x[1]);
    350     InertiaTensor[8] += ptr->type->mass*(x[0]*x[0] + x[1]*x[1]);
     328    InertiaTensor[0] += (*iter)->type->mass*(x[1]*x[1] + x[2]*x[2]);
     329    InertiaTensor[1] += (*iter)->type->mass*(-x[0]*x[1]);
     330    InertiaTensor[2] += (*iter)->type->mass*(-x[0]*x[2]);
     331    InertiaTensor[3] += (*iter)->type->mass*(-x[1]*x[0]);
     332    InertiaTensor[4] += (*iter)->type->mass*(x[0]*x[0] + x[2]*x[2]);
     333    InertiaTensor[5] += (*iter)->type->mass*(-x[1]*x[2]);
     334    InertiaTensor[6] += (*iter)->type->mass*(-x[2]*x[0]);
     335    InertiaTensor[7] += (*iter)->type->mass*(-x[2]*x[1]);
     336    InertiaTensor[8] += (*iter)->type->mass*(x[0]*x[0] + x[1]*x[1]);
    351337  }
    352338  // print InertiaTensor for debugging
     
    386372
    387373    // sum up inertia tensor
    388     ptr = start;
    389     while (ptr->next != end) {
    390       ptr = ptr->next;
    391       Vector x = ptr->x;
    392       //x.SubtractVector(CenterOfGravity);
    393       InertiaTensor[0] += ptr->type->mass*(x[1]*x[1] + x[2]*x[2]);
    394       InertiaTensor[1] += ptr->type->mass*(-x[0]*x[1]);
    395       InertiaTensor[2] += ptr->type->mass*(-x[0]*x[2]);
    396       InertiaTensor[3] += ptr->type->mass*(-x[1]*x[0]);
    397       InertiaTensor[4] += ptr->type->mass*(x[0]*x[0] + x[2]*x[2]);
    398       InertiaTensor[5] += ptr->type->mass*(-x[1]*x[2]);
    399       InertiaTensor[6] += ptr->type->mass*(-x[2]*x[0]);
    400       InertiaTensor[7] += ptr->type->mass*(-x[2]*x[1]);
    401       InertiaTensor[8] += ptr->type->mass*(x[0]*x[0] + x[1]*x[1]);
     374    for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     375      Vector x = (*iter)->x;
     376      InertiaTensor[0] += (*iter)->type->mass*(x[1]*x[1] + x[2]*x[2]);
     377      InertiaTensor[1] += (*iter)->type->mass*(-x[0]*x[1]);
     378      InertiaTensor[2] += (*iter)->type->mass*(-x[0]*x[2]);
     379      InertiaTensor[3] += (*iter)->type->mass*(-x[1]*x[0]);
     380      InertiaTensor[4] += (*iter)->type->mass*(x[0]*x[0] + x[2]*x[2]);
     381      InertiaTensor[5] += (*iter)->type->mass*(-x[1]*x[2]);
     382      InertiaTensor[6] += (*iter)->type->mass*(-x[2]*x[0]);
     383      InertiaTensor[7] += (*iter)->type->mass*(-x[2]*x[1]);
     384      InertiaTensor[8] += (*iter)->type->mass*(x[0]*x[0] + x[1]*x[1]);
    402385    }
    403386    // print InertiaTensor for debugging
     
    423406void molecule::Align(Vector *n)
    424407{
    425   atom *ptr = start;
    426408  double alpha, tmp;
    427409  Vector z_axis;
     
    434416  alpha = atan(-n->at(0)/n->at(2));
    435417  DoLog(1) && (Log() << Verbose(1) << "Z-X-angle: " << alpha << " ... ");
    436   while (ptr->next != end) {
    437     ptr = ptr->next;
    438     tmp = ptr->x[0];
    439     ptr->x[0] =  cos(alpha) * tmp + sin(alpha) * ptr->x[2];
    440     ptr->x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x[2];
     418  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     419    tmp = (*iter)->x[0];
     420    (*iter)->x[0] =  cos(alpha) * tmp + sin(alpha) * (*iter)->x[2];
     421    (*iter)->x[2] = -sin(alpha) * tmp + cos(alpha) * (*iter)->x[2];
    441422    for (int j=0;j<MDSteps;j++) {
    442       tmp = ptr->Trajectory.R.at(j)[0];
    443       ptr->Trajectory.R.at(j)[0] =  cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j)[2];
    444       ptr->Trajectory.R.at(j)[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j)[2];
     423      tmp = (*iter)->Trajectory.R.at(j)[0];
     424      (*iter)->Trajectory.R.at(j)[0] =  cos(alpha) * tmp + sin(alpha) * (*iter)->Trajectory.R.at(j)[2];
     425      (*iter)->Trajectory.R.at(j)[2] = -sin(alpha) * tmp + cos(alpha) * (*iter)->Trajectory.R.at(j)[2];
    445426    }
    446427  }
     
    452433
    453434  // rotate on z-y plane
    454   ptr = start;
    455435  alpha = atan(-n->at(1)/n->at(2));
    456436  DoLog(1) && (Log() << Verbose(1) << "Z-Y-angle: " << alpha << " ... ");
    457   while (ptr->next != end) {
    458     ptr = ptr->next;
    459     tmp = ptr->x[1];
    460     ptr->x[1] =  cos(alpha) * tmp + sin(alpha) * ptr->x[2];
    461     ptr->x[2] = -sin(alpha) * tmp + cos(alpha) * ptr->x[2];
     437  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     438    tmp = (*iter)->x[1];
     439    (*iter)->x[1] =  cos(alpha) * tmp + sin(alpha) * (*iter)->x[2];
     440    (*iter)->x[2] = -sin(alpha) * tmp + cos(alpha) * (*iter)->x[2];
    462441    for (int j=0;j<MDSteps;j++) {
    463       tmp = ptr->Trajectory.R.at(j)[1];
    464       ptr->Trajectory.R.at(j)[1] =  cos(alpha) * tmp + sin(alpha) * ptr->Trajectory.R.at(j)[2];
    465       ptr->Trajectory.R.at(j)[2] = -sin(alpha) * tmp + cos(alpha) * ptr->Trajectory.R.at(j)[2];
     442      tmp = (*iter)->Trajectory.R.at(j)[1];
     443      (*iter)->Trajectory.R.at(j)[1] =  cos(alpha) * tmp + sin(alpha) * (*iter)->Trajectory.R.at(j)[2];
     444      (*iter)->Trajectory.R.at(j)[2] = -sin(alpha) * tmp + cos(alpha) * (*iter)->Trajectory.R.at(j)[2];
    466445    }
    467446  }
     
    487466  Vector a,b,c,d;
    488467  struct lsq_params *par = (struct lsq_params *)params;
    489   atom *ptr = par->mol->start;
    490468
    491469  // initialize vectors
     
    497475  b[2] = gsl_vector_get(x,5);
    498476  // go through all atoms
    499   while (ptr != par->mol->end) {
    500     ptr = ptr->next;
    501     if (ptr->type == ((struct lsq_params *)params)->type) { // for specific type
    502       c = ptr->x - a;
     477  for (molecule::const_iterator iter = par->mol->begin(); iter != par->mol->end(); ++iter) {
     478    if ((*iter)->type == ((struct lsq_params *)params)->type) { // for specific type
     479      c = (*iter)->x - a;
    503480      t = c.ScalarProduct(b);           // get direction parameter
    504481      d = t*b;       // and create vector
  • src/molecule_graph.cpp

    r8f215d ra7b761b  
    1919#include "World.hpp"
    2020#include "Helpers/fast_functions.hpp"
     21#include "Helpers/Assert.hpp"
     22
    2123
    2224struct BFSAccounting
     
    7476      flip(atom1, atom2);
    7577    Walker = FindAtom(atom1);
     78    ASSERT(Walker,"Could not find an atom with the ID given in dbond file");
    7679    OtherWalker = FindAtom(atom2);
     80    ASSERT(OtherWalker,"Could not find an atom with the ID given in dbond file");
    7781    AddBond(Walker, OtherWalker); //Add the bond between the two atoms with respective indices.
    7882  }
     
    103107  atom *Walker = NULL;
    104108  atom *OtherWalker = NULL;
    105   atom **AtomMap = NULL;
    106109  int n[NDIM];
    107110  double MinDistance, MaxDistance;
     
    128131
    129132  // count atoms in molecule = dimension of matrix (also give each unique name and continuous numbering)
    130   CountAtoms();
    131   DoLog(1) && (Log() << Verbose(1) << "AtomCount " << AtomCount << " and bonddistance is " << bonddistance << "." << endl);
    132 
    133   if ((AtomCount > 1) && (bonddistance > 1.)) {
     133  DoLog(1) && (Log() << Verbose(1) << "AtomCount " << getAtomCount() << " and bonddistance is " << bonddistance << "." << endl);
     134
     135  if ((getAtomCount() > 1) && (bonddistance > 1.)) {
    134136    DoLog(2) && (Log() << Verbose(2) << "Creating Linked Cell structure ... " << endl);
    135137    LC = new LinkedCell(this, bonddistance);
     
    137139    // create a list to map Tesselpoint::nr to atom *
    138140    DoLog(2) && (Log() << Verbose(2) << "Creating TesselPoint to atom map ... " << endl);
    139     AtomMap = Calloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount");
    140     Walker = start;
    141     while (Walker->next != end) {
    142       Walker = Walker->next;
    143       AtomMap[Walker->nr] = Walker;
     141
     142    // set numbers for atoms that can later be used
     143    int i=0;
     144    for(internal_iterator iter = atoms.begin();iter!= atoms.end(); ++iter){
     145      (*iter)->nr = i++;
    144146    }
    145147
     
    153155          if (List != NULL) {
    154156            for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    155               Walker = AtomMap[(*Runner)->nr];
    156 //              Log() << Verbose(0) << "Current Atom is " << *Walker << "." << endl;
     157              Walker = dynamic_cast<atom*>(*Runner);
     158              ASSERT(Walker,"Tesselpoint that was not an atom retrieved from LinkedNode");
     159              //Log() << Verbose(0) << "Current Atom is " << *Walker << "." << endl;
    157160              // 3c. check for possible bond between each atom in this and every one in the 27 cells
    158161              for (n[0] = -1; n[0] <= 1; n[0]++)
     
    164167                      for (LinkedCell::LinkedNodes::const_iterator OtherRunner = OtherList->begin(); OtherRunner != OtherList->end(); OtherRunner++) {
    165168                        if ((*OtherRunner)->nr > Walker->nr) {
    166                           OtherWalker = AtomMap[(*OtherRunner)->nr];
    167 //                          Log() << Verbose(0) << "Current other Atom is " << *OtherWalker << "." << endl;
    168                           const double distance = OtherWalker->x.PeriodicDistanceSquared(Walker->x, cell_size);
    169 //                          Log() << Verbose(1) << "Checking distance " << distance << " against typical bond length of " << bonddistance*bonddistance << "." << endl;
     169                          OtherWalker = dynamic_cast<atom*>(*OtherRunner);
     170                          ASSERT(OtherWalker,"TesselPoint that was not an atom retrieved from LinkedNode");
     171                          //Log() << Verbose(1) << "Checking distance " << OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size) << " against typical bond length of " << bonddistance*bonddistance << "." << endl;
    170172                          (BG->*minmaxdistance)(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
     173                          const double distance = OtherWalker->x.PeriodicDistanceSquared(Walker->x,cell_size);
    171174                          const bool status = (distance <= MaxDistance * MaxDistance) && (distance >= MinDistance * MinDistance);
    172175//                          Log() << Verbose(1) << "MinDistance is " << MinDistance << " and MaxDistance is " << MaxDistance << "." << endl;
     
    188191          }
    189192        }
    190     Free(&AtomMap);
    191193    delete (LC);
    192194    DoLog(1) && (Log() << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl);
     
    199201    ActOnAllAtoms( &atom::OutputBondOfAtom );
    200202  } else
    201     DoLog(1) && (Log() << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl);
     203    DoLog(1) && (Log() << Verbose(1) << "AtomCount is " << getAtomCount() << ", thus no bonds, no connections!." << endl);
    202204  DoLog(0) && (Log() << Verbose(0) << "End of CreateAdjacencyList." << endl);
    203205  if (free_BG)
     
    241243    DoLog(0) && (Log() << Verbose(0) << " done." << endl);
    242244  } else {
    243     DoLog(1) && (Log() << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl);
     245    DoLog(1) && (Log() << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << getAtomCount() << " atoms." << endl);
    244246  }
    245247  DoLog(0) && (Log() << Verbose(0) << No << " bonds could not be corrected." << endl);
     
    461463void DepthFirstSearchAnalysis_Init(struct DFSAccounting &DFS, const molecule * const mol)
    462464{
    463   DFS.AtomStack = new StackClass<atom *> (mol->AtomCount);
     465  DFS.AtomStack = new StackClass<atom *> (mol->getAtomCount());
    464466  DFS.CurrentGraphNr = 0;
    465467  DFS.ComponentNumber = 0;
     
    502504  bond *Binder = NULL;
    503505
    504   if (AtomCount == 0)
     506  if (getAtomCount() == 0)
    505507    return SubGraphs;
    506508  DoLog(0) && (Log() << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl);
    507509  DepthFirstSearchAnalysis_Init(DFS, this);
    508510
    509   DFS.Root = start->next;
    510   while (DFS.Root != end) { // if there any atoms at all
     511  for (molecule::const_iterator iter = begin(); iter != end();) {
     512    DFS.Root = *iter;
    511513    // (1) mark all edges unused, empty stack, set atom->GraphNr = -1 for all
    512514    DFS.AtomStack->ClearStack();
     
    548550
    549551    // step on to next root
    550     while ((DFS.Root != end) && (DFS.Root->GraphNr != -1)) {
    551       //Log() << Verbose(1) << "Current next subgraph root candidate is " << Root->Name << "." << endl;
    552       if (DFS.Root->GraphNr != -1) // if already discovered, step on
    553         DFS.Root = DFS.Root->next;
     552    while ((iter != end()) && ((*iter)->GraphNr != -1)) {
     553      //Log() << Verbose(1) << "Current next subgraph root candidate is " << (*iter)->Name << "." << endl;
     554      if ((*iter)->GraphNr != -1) // if already discovered, step on
     555        iter++;
    554556    }
    555557  }
     
    854856  if (MinRingSize != -1) { // if rings are present
    855857    // go over all atoms
    856     Root = mol->start;
    857     while (Root->next != mol->end) {
    858       Root = Root->next;
    859 
    860       if (MinimumRingSize[Root->GetTrueFather()->nr] == mol->AtomCount) { // check whether MinimumRingSize is set, if not BFS to next where it is
     858    for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     859      Root = *iter;
     860
     861      if (MinimumRingSize[Root->GetTrueFather()->nr] == mol->getAtomCount()) { // check whether MinimumRingSize is set, if not BFS to next where it is
    861862        Walker = Root;
    862863
    863864        //Log() << Verbose(1) << "---------------------------------------------------------------------------------------------------------" << endl;
    864         CyclicStructureAnalysis_BFSToNextCycle(Root, Walker, MinimumRingSize, mol->AtomCount);
     865        CyclicStructureAnalysis_BFSToNextCycle(Root, Walker, MinimumRingSize, mol->getAtomCount());
    865866
    866867      }
     
    892893  int MinRingSize = -1;
    893894
    894   InitializeBFSAccounting(BFS, AtomCount);
     895  InitializeBFSAccounting(BFS, getAtomCount());
    895896
    896897  //Log() << Verbose(1) << "Back edge list - ";
     
    11341135    CurrentBondsOfAtom = -1; // we count one too far due to line end
    11351136    // parse into structure
    1136     if ((AtomNr >= 0) && (AtomNr < AtomCount)) {
     1137    if ((AtomNr >= 0) && (AtomNr < getAtomCount())) {
    11371138      Walker = ListOfAtoms[AtomNr];
    11381139      while (!line.eof())
     
    13131314    AddedAtomList[Root->nr] = Mol->AddCopyAtom(Root);
    13141315
    1315   BreadthFirstSearchAdd_Init(BFS, Root, BondOrder, AtomCount, AddedAtomList);
     1316  BreadthFirstSearchAdd_Init(BFS, Root, BondOrder, getAtomCount(), AddedAtomList);
    13161317
    13171318  // and go on ... Queue always contains all lightgray vertices
     
    13691370  // fill parent list with sons
    13701371  DoLog(3) && (Log() << Verbose(3) << "Filling Parent List." << endl);
    1371   atom *Walker = mol->start;
    1372   while (Walker->next != mol->end) {
    1373     Walker = Walker->next;
    1374     ParentList[Walker->father->nr] = Walker;
     1372  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     1373    ParentList[(*iter)->father->nr] = (*iter);
    13751374    // Outputting List for debugging
    1376     DoLog(4) && (Log() << Verbose(4) << "Son[" << Walker->father->nr << "] of " << Walker->father << " is " << ParentList[Walker->father->nr] << "." << endl);
    1377   }
    1378 
    1379 }
    1380 ;
     1375    DoLog(4) && (Log() << Verbose(4) << "Son[" << (*iter)->father->nr << "] of " << (*iter)->father << " is " << ParentList[(*iter)->father->nr] << "." << endl);
     1376  }
     1377};
    13811378
    13821379void BuildInducedSubgraph_Finalize(atom **&ParentList)
     
    13891386{
    13901387  bool status = true;
    1391   atom *Walker = NULL;
    13921388  atom *OtherAtom = NULL;
    13931389  // check each entry of parent list and if ok (one-to-and-onto matching) create bonds
    13941390  DoLog(3) && (Log() << Verbose(3) << "Creating bonds." << endl);
    1395   Walker = Father->start;
    1396   while (Walker->next != Father->end) {
    1397     Walker = Walker->next;
    1398     if (ParentList[Walker->nr] != NULL) {
    1399       if (ParentList[Walker->nr]->father != Walker) {
     1391  for (molecule::const_iterator iter = Father->begin(); iter != Father->end(); ++iter) {
     1392    if (ParentList[(*iter)->nr] != NULL) {
     1393      if (ParentList[(*iter)->nr]->father != (*iter)) {
    14001394        status = false;
    14011395      } else {
    1402         for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
    1403           OtherAtom = (*Runner)->GetOtherAtom(Walker);
     1396        for (BondList::const_iterator Runner = (*iter)->ListOfBonds.begin(); Runner != (*iter)->ListOfBonds.end(); (++Runner)) {
     1397          OtherAtom = (*Runner)->GetOtherAtom((*iter));
    14041398          if (ParentList[OtherAtom->nr] != NULL) { // if otheratom is also a father of an atom on this molecule, create the bond
    1405             DoLog(4) && (Log() << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[Walker->nr]->getName() << " and " << ParentList[OtherAtom->nr]->getName() << "." << endl);
    1406             mol->AddBond(ParentList[Walker->nr], ParentList[OtherAtom->nr], (*Runner)->BondDegree);
     1399            DoLog(4) && (Log() << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[(*iter)->nr]->getName() << " and " << ParentList[OtherAtom->nr]->getName() << "." << endl);
     1400            mol->AddBond(ParentList[(*iter)->nr], ParentList[OtherAtom->nr], (*Runner)->BondDegree);
    14071401          }
    14081402        }
     
    14271421  bool status = true;
    14281422  atom **ParentList = NULL;
    1429 
    14301423  DoLog(2) && (Log() << Verbose(2) << "Begin of BuildInducedSubgraph." << endl);
    1431   BuildInducedSubgraph_Init(ParentList, Father->AtomCount);
     1424  BuildInducedSubgraph_Init(ParentList, Father->getAtomCount());
    14321425  BuildInducedSubgraph_FillParentList(this, Father, ParentList);
    14331426  status = BuildInducedSubgraph_CreateBondsFromParent(this, Father, ParentList);
  • src/molecule_pointcloud.cpp

    r8f215d ra7b761b  
    88#include "atom.hpp"
    99#include "config.hpp"
     10#include "info.hpp"
    1011#include "memoryallocator.hpp"
    1112#include "molecule.hpp"
     
    3132};
    3233
    33 /** Return current atom in the list.
    34  * \return pointer to atom or NULL if none present
     34
     35/** PointCloud implementation of GoPoint
     36 * Uses atoms and STL stuff.
    3537 */
    36 TesselPoint *molecule::GetPoint() const
     38TesselPoint* molecule::GetPoint() const
    3739{
    38   if ((InternalPointer != start) && (InternalPointer != end))
    39     return InternalPointer;
    40   else
    41     return NULL;
     40  Info FunctionInfo(__func__);
     41  return (*InternalPointer);
    4242};
    4343
    44 /** Return pointer to one after last atom in the list.
    45  * \return pointer to end marker
    46  */
    47 TesselPoint *molecule::GetTerminalPoint() const
    48 {
    49   return end;
    50 };
    51 
    52 /** Return the greatest index of all atoms in the list.
    53  * \return greatest index
    54  */
    55 int molecule::GetMaxId() const
    56 {
    57   return last_atom;
    58 };
    59 
    60 /** Go to next atom.
    61  * Stops at last one.
     44/** PointCloud implementation of GoToNext.
     45 * Uses atoms and STL stuff.
    6246 */
    6347void molecule::GoToNext() const
    6448{
    65   if (InternalPointer != end)
    66     InternalPointer = InternalPointer->next;
     49  Info FunctionInfo(__func__);
     50  if (InternalPointer != atoms.end())
     51    InternalPointer++;
    6752};
    6853
    69 /** Go to previous atom.
    70  * Stops at first one.
    71  */
    72 void molecule::GoToPrevious() const
    73 {
    74   if (InternalPointer->previous != start)
    75     InternalPointer = InternalPointer->previous;
    76 };
    77 
    78 /** Goes to first atom.
     54/** PointCloud implementation of GoToFirst.
     55 * Uses atoms and STL stuff.
    7956 */
    8057void molecule::GoToFirst() const
    8158{
    82   InternalPointer = start->next;
     59  Info FunctionInfo(__func__);
     60  InternalPointer = atoms.begin();
    8361};
    8462
    85 /** Goes to last atom.
    86  */
    87 void molecule::GoToLast() const
    88 {
    89   InternalPointer = end->previous;
    90 };
    91 
    92 /** Checks whether we have any atoms in molecule.
    93  * \return true - no atoms, false - not empty
     63/** PointCloud implementation of IsEmpty.
     64 * Uses atoms and STL stuff.
    9465 */
    9566bool molecule::IsEmpty() const
    9667{
    97   return (start->next == end);
     68  Info FunctionInfo(__func__);
     69  return (empty());
    9870};
    9971
    100 /** Checks whether we are at the last atom
    101  * \return true - current atom is last one, false - is not last one
     72/** PointCloud implementation of IsLast.
     73 * Uses atoms and STL stuff.
    10274 */
    10375bool molecule::IsEnd() const
    10476{
    105   return (InternalPointer == end);
     77  Info FunctionInfo(__func__);
     78  return (InternalPointer == atoms.end());
    10679};
     80
     81int molecule::GetMaxId() const {
     82  return getAtomCount();
     83}
  • src/molecule_template.hpp

    r8f215d ra7b761b  
    2424template <typename res> void molecule::ActOnAllVectors( res (Vector::*f)() ) const
    2525    {
    26   atom *Walker = start;
    27   while (Walker->next != end) {
    28     Walker = Walker->next;
    29     ((Walker->node)->*f)();
     26  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     27    (((*iter)->node)->*f)();
    3028  }
    3129};
    3230template <typename res> void molecule::ActOnAllVectors( res (Vector::*f)() const ) const
    3331    {
    34   atom *Walker = start;
    35   while (Walker->next != end) {
    36     Walker = Walker->next;
    37     ((Walker->node)->*f)();
     32  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     33    (((*iter)->node)->*f)();
    3834  }
    3935};
     
    4137template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T), T t ) const
    4238{
    43   atom *Walker = start;
    44   while (Walker->next != end) {
    45     Walker = Walker->next;
    46     ((Walker->node)->*f)(t);
     39  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     40    (((*iter)->node)->*f)(t);
    4741  }
    4842};
    4943template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T) const, T t ) const
    5044{
    51   atom *Walker = start;
    52   while (Walker->next != end) {
    53     Walker = Walker->next;
    54     ((Walker->node)->*f)(t);
     45  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     46    (((*iter)->node)->*f)(t);
    5547  }
    5648};
    5749template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T&), T &t ) const
    5850{
    59   atom *Walker = start;
    60   while (Walker->next != end) {
    61     Walker = Walker->next;
    62     ((Walker->node)->*f)(t);
     51  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     52    (((*iter)->node)->*f)(t);
    6353  }
    6454};
    6555template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T&) const, T &t ) const
    6656{
    67   atom *Walker = start;
    68   while (Walker->next != end) {
    69     Walker = Walker->next;
    70     ((Walker->node)->*f)(t);
     57  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     58    (((*iter)->node)->*f)(t);
    7159  }
    7260};
     
    7462template <typename res, typename T, typename U> void molecule::ActOnAllVectors( res (Vector::*f)(T, U), T t, U u ) const
    7563{
    76   atom *Walker = start;
    77   while (Walker->next != end) {
    78     Walker = Walker->next;
    79     ((Walker->node)->*f)(t, u);
     64  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     65    (((*iter)->node)->*f)(t, u);
    8066  }
    8167};
    8268template <typename res, typename T, typename U> void molecule::ActOnAllVectors( res (Vector::*f)(T, U) const, T t, U u ) const
    8369{
    84   atom *Walker = start;
    85   while (Walker->next != end) {
    86     Walker = Walker->next;
    87     ((Walker->node)->*f)(t, u);
     70  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     71    (((*iter)->node)->*f)(t, u);
    8872  }
    8973};
     
    9175template <typename res, typename T, typename U, typename V> void molecule::ActOnAllVectors( res (Vector::*f)(T, U, V), T t, U u, V v) const
    9276{
    93   atom *Walker = start;
    94   while (Walker->next != end) {
    95     Walker = Walker->next;
    96     ((Walker->node)->*f)(t, u, v);
     77  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     78    (((*iter)->node)->*f)(t, u, v);
    9779  }
    9880};
    9981template <typename res, typename T, typename U, typename V> void molecule::ActOnAllVectors( res (Vector::*f)(T, U, V) const, T t, U u, V v) const
    10082{
    101   atom *Walker = start;
    102   while (Walker->next != end) {
    103     Walker = Walker->next;
    104     ((Walker->node)->*f)(t, u, v);
     83  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     84    (((*iter)->node)->*f)(t, u, v);
    10585  }
    10686};
     
    11292{
    11393  res result = 0;
    114   atom *Walker = start;
    115   while (Walker->next != end) {
    116     Walker = Walker->next;
    117     result += (Walker->*f)();
     94  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     95    result += ((*iter)->*f)();
    11896  }
    11997  return result;
     
    122100{
    123101  res result = 0;
    124   atom *Walker = start;
    125   while (Walker->next != end) {
    126     Walker = Walker->next;
    127     result += (Walker->*f)();
     102  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     103    result += ((*iter)->*f)();
    128104  }
    129105  return result;
     
    133109{
    134110  res result = 0;
    135   atom *Walker = start;
    136   while (Walker->next != end) {
    137     Walker = Walker->next;
    138     result += (Walker->*f)(t);
     111  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     112    result += ((*iter)->*f)(t);
    139113  }
    140114  return result;
     
    143117{
    144118  res result = 0;
    145   atom *Walker = start;
    146   while (Walker->next != end) {
    147     Walker = Walker->next;
    148     result += (Walker->*f)(t);
     119  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     120    result += ((*iter)->*f)(t);
    149121  }
    150122  return result;
     
    157129template <typename res> void molecule::ActWithEachAtom( res (molecule::*f)(atom *)) const
    158130{
    159   atom *Walker = start;
    160   while (Walker->next != end) {
    161     Walker = Walker->next;
    162     (*f)(Walker);
     131  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     132    (*f)((*iter));
    163133  }
    164134};
    165135template <typename res> void molecule::ActWithEachAtom( res (molecule::*f)(atom *) const) const
    166136{
    167   atom *Walker = start;
    168   while (Walker->next != end) {
    169     Walker = Walker->next;
    170     (*f)(Walker);
     137  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     138    (*f)((*iter));
    171139  }
    172140};
     
    177145template <typename res> void molecule::ActOnCopyWithEachAtom( res (molecule::*f)(atom *) , molecule *copy) const
    178146{
    179   atom *Walker = start;
    180   while (Walker->next != end) {
    181     Walker = Walker->next;
    182     (copy->*f)(Walker);
     147  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     148    (copy->*f)((*iter));
    183149  }
    184150};
    185151template <typename res> void molecule::ActOnCopyWithEachAtom( res (molecule::*f)(atom *) const, molecule *copy) const
    186152{
    187   atom *Walker = start;
    188   while (Walker->next != end) {
    189     Walker = Walker->next;
    190     (copy->*f)(Walker);
     153  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     154    (copy->*f)((*iter));
    191155  }
    192156};
     
    197161template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () ) const
    198162{
    199   atom *Walker = start;
    200   while (Walker->next != end) {
    201     Walker = Walker->next;
    202     if ((Walker->*condition)())
    203       (copy->*f)(Walker);
     163  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     164    if (((*iter)->*condition)())
     165      (copy->*f)((*iter));
    204166  }
    205167};
    206168template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () const ) const
    207169{
    208   atom *Walker = start;
    209   while (Walker->next != end) {
    210     Walker = Walker->next;
    211     if ((Walker->*condition)())
    212       (copy->*f)(Walker);
     170  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     171    if (((*iter)->*condition)())
     172      (copy->*f)((*iter));
    213173  }
    214174};
    215175template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const , molecule *copy, bool (atom::*condition) () ) const
    216176{
    217   atom *Walker = start;
    218   while (Walker->next != end) {
    219     Walker = Walker->next;
    220     if ((Walker->*condition)())
    221       (copy->*f)(Walker);
     177  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     178    if (((*iter)->*condition)())
     179      (copy->*f)((*iter));
    222180  }
    223181};
    224182template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) () const ) const
    225183{
    226   atom *Walker = start;
    227   while (Walker->next != end) {
    228     Walker = Walker->next;
    229     if ((Walker->*condition)())
    230       (copy->*f)(Walker);
     184  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     185    if (((*iter)->*condition)())
     186      (copy->*f)((*iter));
    231187  }
    232188};
     
    234190template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T), T t ) const
    235191{
    236   atom *Walker = start;
    237   while (Walker->next != end) {
    238     Walker = Walker->next;
    239     if ((Walker->*condition)(t))
    240       (copy->*f)(Walker);
     192  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     193    if (((*iter)->*condition)(t))
     194      (copy->*f)((*iter));
    241195  }
    242196};
    243197template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T) const, T t ) const
    244198{
    245   atom *Walker = start;
    246   while (Walker->next != end) {
    247     Walker = Walker->next;
    248     if ((Walker->*condition)(t))
    249       (copy->*f)(Walker);
     199  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     200    if (((*iter)->*condition)(t))
     201      (copy->*f)((*iter));
    250202  }
    251203};
    252204template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T), T t ) const
    253205{
    254   atom *Walker = start;
    255   while (Walker->next != end) {
    256     Walker = Walker->next;
    257     if ((Walker->*condition)(t))
    258       (copy->*f)(Walker);
     206  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     207    if (((*iter)->*condition)(t))
     208      (copy->*f)((*iter));
    259209  }
    260210};
    261211template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T) const, T t ) const
    262212{
    263   atom *Walker = start;
    264   while (Walker->next != end) {
    265     Walker = Walker->next;
    266     if ((Walker->*condition)(t))
    267       (copy->*f)(Walker);
     213  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     214    if (((*iter)->*condition)(t))
     215      (copy->*f)((*iter));
    268216  }
    269217};
     
    271219template <typename res, typename T, typename U> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U), T t, U u ) const
    272220{
    273   atom *Walker = start;
    274   while (Walker->next != end) {
    275     Walker = Walker->next;
    276     if ((Walker->*condition)(t,u))
    277       (copy->*f)(Walker);
     221  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     222    if (((*iter)->*condition)(t,u))
     223      (copy->*f)((*iter));
    278224  }
    279225};
    280226template <typename res, typename T, typename U> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U) const, T t, U u ) const
    281227{
    282   atom *Walker = start;
    283   while (Walker->next != end) {
    284     Walker = Walker->next;
    285     if ((Walker->*condition)(t,u))
    286       (copy->*f)(Walker);
     228  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     229    if (((*iter)->*condition)(t,u))
     230      (copy->*f)((*iter));
    287231  }
    288232};
    289233template <typename res, typename T, typename U> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T, U), T t, U u ) const
    290234{
    291   atom *Walker = start;
    292   while (Walker->next != end) {
    293     Walker = Walker->next;
    294     if ((Walker->*condition)(t,u))
    295       (copy->*f)(Walker);
     235  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     236    if (((*iter)->*condition)(t,u))
     237      (copy->*f)((*iter));
    296238  }
    297239};
    298240template <typename res, typename T, typename U> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T, U) const, T t, U u ) const
    299241{
    300   atom *Walker = start;
    301   while (Walker->next != end) {
    302     Walker = Walker->next;
    303     if ((Walker->*condition)(t,u))
    304       (copy->*f)(Walker);
     242  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     243    if (((*iter)->*condition)(t,u))
     244      (copy->*f)((*iter));
    305245  }
    306246};
     
    308248template <typename res, typename T, typename U, typename V> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U, V), T t, U u, V v ) const
    309249{
    310   atom *Walker = start;
    311   while (Walker->next != end) {
    312     Walker = Walker->next;
    313     if ((Walker->*condition)(t,u,v))
    314       (copy->*f)(Walker);
     250  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     251    if (((*iter)->*condition)(t,u,v))
     252      (copy->*f)((*iter));
    315253  }
    316254};
    317255template <typename res, typename T, typename U, typename V> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U, V) const, T t, U u, V v ) const
    318256{
    319   atom *Walker = start;
    320   while (Walker->next != end) {
    321     Walker = Walker->next;
    322     if ((Walker->*condition)(t,u,v))
    323       (copy->*f)(Walker);
     257  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     258    if (((*iter)->*condition)(t,u,v))
     259      (copy->*f)((*iter));
    324260  }
    325261};
    326262template <typename res, typename T, typename U, typename V> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T, U, V), T t, U u, V v ) const
    327263{
    328   atom *Walker = start;
    329   while (Walker->next != end) {
    330     Walker = Walker->next;
    331     if ((Walker->*condition)(t,u,v))
    332       (copy->*f)(Walker);
     264  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     265    if (((*iter)->*condition)(t,u,v))
     266      (copy->*f)((*iter));
    333267  }
    334268};
    335269template <typename res, typename T, typename U, typename V> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T, U, V) const, T t, U u, V v ) const
    336270{
    337   atom *Walker = start;
    338   while (Walker->next != end) {
    339     Walker = Walker->next;
    340     if ((Walker->*condition)(t,u,v))
    341       (copy->*f)(Walker);
     271  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     272    if (((*iter)->*condition)(t,u,v))
     273      (copy->*f)((*iter));
    342274  }
    343275};
     
    348280template <typename res, typename typ> void molecule::ActOnAllAtoms( res (typ::*f)()) const
    349281{
    350   atom *Walker = start;
    351   while (Walker->next != end) {
    352     Walker = Walker->next;
    353     (Walker->*f)();
     282  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     283    ((*iter)->*f)();
    354284  }
    355285};
    356286template <typename res, typename typ> void molecule::ActOnAllAtoms( res (typ::*f)() const) const
    357287{
    358   atom *Walker = start;
    359   while (Walker->next != end) {
    360     Walker = Walker->next;
    361     (Walker->*f)();
     288  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     289    ((*iter)->*f)();
    362290  }
    363291};
     
    365293template <typename res, typename typ, typename T> void molecule::ActOnAllAtoms( res (typ::*f)(T), T t ) const
    366294{
    367   atom *Walker = start;
    368   while (Walker->next != end) {
    369     Walker = Walker->next;
    370     (Walker->*f)(t);
     295  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     296    ((*iter)->*f)(t);
    371297  }
    372298};
    373299template <typename res, typename typ, typename T> void molecule::ActOnAllAtoms( res (typ::*f)(T) const, T t ) const
    374300{
    375   atom *Walker = start;
    376   while (Walker->next != end) {
    377     Walker = Walker->next;
    378     (Walker->*f)(t);
     301  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     302    ((*iter)->*f)(t);
    379303  }
    380304};
     
    382306template <typename res, typename typ, typename T, typename U> void molecule::ActOnAllAtoms( res (typ::*f)(T, U), T t, U u ) const
    383307{
    384   atom *Walker = start;
    385   while (Walker->next != end) {
    386     Walker = Walker->next;
    387     (Walker->*f)(t, u);
     308  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     309    ((*iter)->*f)(t, u);
    388310  }
    389311};
    390312template <typename res, typename typ, typename T, typename U> void molecule::ActOnAllAtoms( res (typ::*f)(T, U) const, T t, U u ) const
    391313{
    392   atom *Walker = start;
    393   while (Walker->next != end) {
    394     Walker = Walker->next;
    395     (Walker->*f)(t, u);
     314  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     315    ((*iter)->*f)(t, u);
    396316  }
    397317};
     
    399319template <typename res, typename typ, typename T, typename U, typename V> void molecule::ActOnAllAtoms( res (typ::*f)(T, U, V), T t, U u, V v) const
    400320{
    401   atom *Walker = start;
    402   while (Walker->next != end) {
    403     Walker = Walker->next;
    404     (Walker->*f)(t, u, v);
     321  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     322    ((*iter)->*f)(t, u, v);
    405323  }
    406324};
    407325template <typename res, typename typ, typename T, typename U, typename V> void molecule::ActOnAllAtoms( res (typ::*f)(T, U, V) const, T t, U u, V v) const
    408326{
    409   atom *Walker = start;
    410   while (Walker->next != end) {
    411     Walker = Walker->next;
    412     (Walker->*f)(t, u, v);
     327  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     328    ((*iter)->*f)(t, u, v);
    413329  }
    414330};
     
    416332template <typename res, typename typ, typename T, typename U, typename V, typename W> void molecule::ActOnAllAtoms( res (typ::*f)(T, U, V, W), T t, U u, V v, W w) const
    417333{
    418   atom *Walker = start;
    419   while (Walker->next != end) {
    420     Walker = Walker->next;
    421     (Walker->*f)(t, u, v, w);
     334  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     335    ((*iter)->*f)(t, u, v, w);
    422336  }
    423337};
    424338template <typename res, typename typ, typename T, typename U, typename V, typename W> void molecule::ActOnAllAtoms( res (typ::*f)(T, U, V, W) const, T t, U u, V v, W w) const
    425339{
    426   atom *Walker = start;
    427   while (Walker->next != end) {
    428     Walker = Walker->next;
    429     (Walker->*f)(t, u, v, w);
     340  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     341    ((*iter)->*f)(t, u, v, w);
    430342  }
    431343};
     
    436348template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *) ) const
    437349{
    438   atom *Walker = start;
    439350  int inc = 1;
    440   while (Walker->next != end) {
    441     Walker = Walker->next;
    442     (*Setor) (&array[(Walker->*index)], &inc);
     351  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     352    (*Setor) (&array[((*iter)->*index)], &inc);
    443353  }
    444354};
    445355template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *), T value ) const
    446356{
    447   atom *Walker = start;
    448   while (Walker->next != end) {
    449     Walker = Walker->next;
    450     (*Setor) (&array[(Walker->*index)], &value);
     357  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     358    (*Setor) (&array[((*iter)->*index)], &value);
    451359  }
    452360};
    453361template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *), T *value ) const
    454362{
    455   atom *Walker = start;
    456   while (Walker->next != end) {
    457     Walker = Walker->next;
    458     (*Setor) (&array[(Walker->*index)], value);
     363  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     364    (*Setor) (&array[((*iter)->*index)], value);
    459365  }
    460366};
     
    462368template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *) ) const
    463369{
    464   atom *Walker = start;
    465370  int inc = 1;
    466   while (Walker->next != end) {
    467     Walker = Walker->next;
    468     (*Setor) (&array[(Walker->type->*index)], &inc);
     371  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     372    (*Setor) (&array[((*iter)->type->*index)], &inc);
    469373  }
    470374};
    471375template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *), T value ) const
    472376{
    473   atom *Walker = start;
    474   while (Walker->next != end) {
    475     Walker = Walker->next;
    476     (*Setor) (&array[(Walker->type->*index)], &value);
     377  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     378    (*Setor) (&array[((*iter)->type->*index)], &value);
    477379  }
    478380};
    479381template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *), T *value ) const
    480382{
    481   atom *Walker = start;
    482   while (Walker->next != end) {
    483     Walker = Walker->next;
    484     (*Setor) (&array[(Walker->type->*index)], value);
     383  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     384    (*Setor) (&array[((*iter)->type->*index)], value);
    485385  }
    486386};
     
    488388template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &), typ atom::*value ) const
    489389{
    490   atom *Walker = start;
    491   while (Walker->next != end) {
    492     Walker = Walker->next;
    493     array[(Walker->*index)] = (Walker->*Setor) (Walker->*value);
     390  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     391    array[((*iter)->*index)] = ((*iter)->*Setor) ((*iter)->*value);
    494392  }
    495393};
    496394template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &) const, typ atom::*value ) const
    497395{
    498   atom *Walker = start;
    499   while (Walker->next != end) {
    500     Walker = Walker->next;
    501     array[(Walker->*index)] = (Walker->*Setor) (Walker->*value);
     396  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     397    array[((*iter)->*index)] = ((*iter)->*Setor) ((*iter)->*value);
    502398  }
    503399};
    504400template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &), typ &vect ) const
    505401{
    506   atom *Walker = start;
    507   while (Walker->next != end) {
    508     Walker = Walker->next;
    509     array[(Walker->*index)] = (Walker->*Setor) (vect);
     402  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     403    array[((*iter)->*index)] = ((*iter)->*Setor) (vect);
    510404  }
    511405};
    512406template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &) const, typ &vect ) const
    513407{
    514   atom *Walker = start;
    515   while (Walker->next != end) {
    516     Walker = Walker->next;
    517     array[(Walker->*index)] = (Walker->*Setor) (vect);
     408  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     409    array[((*iter)->*index)] = ((*iter)->*Setor) (vect);
    518410  }
    519411};
    520412template <typename T, typename typ, typename typ2> void molecule::SetAtomValueToIndexedArray ( T *array, int typ::*index, T typ2::*value ) const
    521413{
    522   atom *Walker = start;
    523   while (Walker->next != end) {
    524     Walker = Walker->next;
    525     Walker->*value = array[(Walker->*index)];
    526     //Log() << Verbose(2) << *Walker << " gets " << (Walker->*value); << endl;
     414  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     415    (*iter)->*value = array[((*iter)->*index)];
     416    //Log() << Verbose(2) << *(*iter) << " gets " << ((*iter)->*value); << endl;
    527417  }
    528418};
     
    530420template <typename T, typename typ> void molecule::SetAtomValueToValue ( T value, T typ::*ptr ) const
    531421{
    532   atom *Walker = start;
    533   while (Walker->next != end) {
    534     Walker = Walker->next;
    535     Walker->*ptr = value;
    536     //Log() << Verbose(2) << *Walker << " gets " << (Walker->*ptr) << endl;
     422  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     423    (*iter)->*ptr = value;
     424    //Log() << Verbose(2) << *(*iter) << " gets " << ((*iter)->*ptr) << endl;
    537425  }
    538426};
  • src/moleculelist.cpp

    r8f215d ra7b761b  
    2020#include "memoryallocator.hpp"
    2121#include "periodentafel.hpp"
    22 #include "World.hpp"
     22#include "Helpers/Assert.hpp"
    2323
    2424/*********************************** Functions for class MoleculeListClass *************************/
     
    6969  int Count, Counter, aCounter, bCounter;
    7070  int flag;
    71   atom *aWalker = NULL;
    72   atom *bWalker = NULL;
    7371
    7472  // sort each atom list and put the numbers into a list, then go through
    7573  //Log() << Verbose(0) << "Comparing fragment no. " << *(molecule **)a << " to " << *(molecule **)b << "." << endl;
    76   if ((**(molecule **) a).AtomCount < (**(molecule **) b).AtomCount) {
     74  // Yes those types are awkward... but check it for yourself it checks out this way
     75  molecule *const *mol1_ptr= static_cast<molecule *const *>(a);
     76  molecule *mol1 = *mol1_ptr;
     77  molecule *const *mol2_ptr= static_cast<molecule *const *>(b);
     78  molecule *mol2 = *mol2_ptr;
     79  if (mol1->getAtomCount() < mol2->getAtomCount()) {
    7780    return -1;
    7881  } else {
    79     if ((**(molecule **) a).AtomCount > (**(molecule **) b).AtomCount)
     82    if (mol1->getAtomCount() > mol2->getAtomCount())
    8083      return +1;
    8184    else {
    82       Count = (**(molecule **) a).AtomCount;
     85      Count = mol1->getAtomCount();
    8386      aList = new int[Count];
    8487      bList = new int[Count];
    8588
    8689      // fill the lists
    87       aWalker = (**(molecule **) a).start;
    88       bWalker = (**(molecule **) b).start;
    8990      Counter = 0;
    9091      aCounter = 0;
    9192      bCounter = 0;
    92       while ((aWalker->next != (**(molecule **) a).end) && (bWalker->next != (**(molecule **) b).end)) {
    93         aWalker = aWalker->next;
    94         bWalker = bWalker->next;
    95         if (aWalker->GetTrueFather() == NULL)
     93      molecule::const_iterator aiter = mol1->begin();
     94      molecule::const_iterator biter = mol2->begin();
     95      for (;(aiter != mol1->end()) && (biter != mol2->end());
     96          ++aiter, ++biter) {
     97        if ((*aiter)->GetTrueFather() == NULL)
    9698          aList[Counter] = Count + (aCounter++);
    9799        else
    98           aList[Counter] = aWalker->GetTrueFather()->nr;
    99         if (bWalker->GetTrueFather() == NULL)
     100          aList[Counter] = (*aiter)->GetTrueFather()->nr;
     101        if ((*biter)->GetTrueFather() == NULL)
    100102          bList[Counter] = Count + (bCounter++);
    101103        else
    102           bList[Counter] = bWalker->GetTrueFather()->nr;
     104          bList[Counter] = (*biter)->GetTrueFather()->nr;
    103105        Counter++;
    104106      }
    105107      // check if AtomCount was for real
    106108      flag = 0;
    107       if ((aWalker->next == (**(molecule **) a).end) && (bWalker->next != (**(molecule **) b).end)) {
     109      if ((aiter == mol1->end()) && (biter != mol2->end())) {
    108110        flag = -1;
    109111      } else {
    110         if ((aWalker->next != (**(molecule **) a).end) && (bWalker->next == (**(molecule **) b).end))
     112        if ((aiter != mol1->end()) && (biter == mol2->end()))
    111113          flag = 1;
    112114      }
     
    142144void MoleculeListClass::Enumerate(ostream *out)
    143145{
    144   atom *Walker = NULL;
    145146  periodentafel *periode = World::getInstance().getPeriode();
    146147  std::map<atomicNumber_t,unsigned int> counts;
     
    158159      // count atoms per element and determine size of bounding sphere
    159160      size=0.;
    160       Walker = (*ListRunner)->start;
    161       while (Walker->next != (*ListRunner)->end) {
    162         Walker = Walker->next;
    163         counts[Walker->type->getNumber()]++;
    164         if (Walker->x.DistanceSquared(Origin) > size)
    165           size = Walker->x.DistanceSquared(Origin);
     161      for (molecule::const_iterator iter = (*ListRunner)->begin(); iter != (*ListRunner)->end(); ++iter) {
     162        counts[(*iter)->type->getNumber()]++;
     163        if ((*iter)->x.DistanceSquared(Origin) > size)
     164          size = (*iter)->x.DistanceSquared(Origin);
    166165      }
    167166      // output Index, Name, number of atoms, chemical formula
    168       (*out) << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->AtomCount << "\t";
     167      (*out) << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->getAtomCount() << "\t";
    169168
    170169      std::map<atomicNumber_t,unsigned int>::reverse_iterator iter;
     
    202201
    203202  // put all molecules of src into mol
    204   atom *Walker = srcmol->start;
    205   atom *NextAtom = Walker->next;
    206   while (NextAtom != srcmol->end) {
    207     Walker = NextAtom;
    208     NextAtom = Walker->next;
    209     srcmol->UnlinkAtom(Walker);
    210     mol->AddAtom(Walker);
     203  molecule::iterator runner;
     204  for (molecule::iterator iter = srcmol->begin(); iter != srcmol->end(); ++iter) {
     205    runner = iter++;
     206    srcmol->UnlinkAtom((*runner));
     207    mol->AddAtom((*runner));
    211208  }
    212209
     
    228225
    229226  // put all molecules of src into mol
    230   atom *Walker = srcmol->start;
    231   atom *NextAtom = Walker->next;
    232   while (NextAtom != srcmol->end) {
    233     Walker = NextAtom;
    234     NextAtom = Walker->next;
    235     Walker = mol->AddCopyAtom(Walker);
     227  atom *Walker = NULL;
     228  for (molecule::iterator iter = srcmol->begin(); iter != srcmol->end(); ++iter) {
     229    Walker = mol->AddCopyAtom((*iter));
    236230    Walker->father = Walker;
    237231  }
     
    330324
    331325  // prepare index list for bonds
    332   srcmol->CountAtoms();
    333   atom ** CopyAtoms = new atom*[srcmol->AtomCount];
    334   for(int i=0;i<srcmol->AtomCount;i++)
     326  atom ** CopyAtoms = new atom*[srcmol->getAtomCount()];
     327  for(int i=0;i<srcmol->getAtomCount();i++)
    335328    CopyAtoms[i] = NULL;
    336329
    337330  // for each of the source atoms check whether we are in- or outside and add copy atom
    338   atom *Walker = srcmol->start;
    339331  int nr=0;
    340   while (Walker->next != srcmol->end) {
    341     Walker = Walker->next;
    342     DoLog(2) && (Log() << Verbose(2) << "INFO: Current Walker is " << *Walker << "." << endl);
    343     if (!TesselStruct->IsInnerPoint(Walker->x, LCList)) {
    344       CopyAtoms[Walker->nr] = Walker->clone();
    345       mol->AddAtom(CopyAtoms[Walker->nr]);
     332  for (molecule::const_iterator iter = srcmol->begin(); iter != srcmol->end(); ++iter) {
     333    DoLog(2) && (Log() << Verbose(2) << "INFO: Current Walker is " << **iter << "." << endl);
     334    if (!TesselStruct->IsInnerPoint((*iter)->x, LCList)) {
     335      CopyAtoms[(*iter)->nr] = (*iter)->clone();
     336      mol->AddAtom(CopyAtoms[(*iter)->nr]);
    346337      nr++;
    347338    } else {
     
    349340    }
    350341  }
    351   DoLog(1) && (Log() << Verbose(1) << nr << " of " << srcmol->AtomCount << " atoms have been merged.");
     342  DoLog(1) && (Log() << Verbose(1) << nr << " of " << srcmol->getAtomCount() << " atoms have been merged.");
    352343
    353344  // go through all bonds and add as well
     
    382373bool MoleculeListClass::AddHydrogenCorrection(char *path)
    383374{
    384   atom *Walker = NULL;
    385   atom *Runner = NULL;
    386375  bond *Binder = NULL;
    387376  double ***FitConstant = NULL, **correction = NULL;
     
    488477        correction[k][j] = 0.;
    489478    // 2. take every hydrogen that is a saturated one
    490     Walker = (*ListRunner)->start;
    491     while (Walker->next != (*ListRunner)->end) {
    492       Walker = Walker->next;
    493       //Log() << Verbose(1) << "Walker: " << *Walker << " with first bond " << *(Walker->ListOfBonds.begin()) << "." << endl;
    494       if ((Walker->type->Z == 1) && ((Walker->father == NULL)
    495           || (Walker->father->type->Z != 1))) { // if it's a hydrogen
    496         Runner = (*ListRunner)->start;
    497         while (Runner->next != (*ListRunner)->end) {
    498           Runner = Runner->next;
    499           //Log() << Verbose(2) << "Runner: " << *Runner << " with first bond " << *(Walker->ListOfBonds.begin()) << "." << endl;
     479    for (molecule::const_iterator iter = (*ListRunner)->begin(); iter != (*ListRunner)->end(); ++iter) {
     480      //Log() << Verbose(1) << "(*iter): " << *(*iter) << " with first bond " << *((*iter)->ListOfBonds.begin()) << "." << endl;
     481      if (((*iter)->type->Z == 1) && (((*iter)->father == NULL)
     482          || ((*iter)->father->type->Z != 1))) { // if it's a hydrogen
     483        for (molecule::const_iterator runner = (*ListRunner)->begin(); runner != (*ListRunner)->end(); ++runner) {
     484          //Log() << Verbose(2) << "Runner: " << *(*runner) << " with first bond " << *((*iter)->ListOfBonds.begin()) << "." << endl;
    500485          // 3. take every other hydrogen that is the not the first and not bound to same bonding partner
    501           Binder = *(Runner->ListOfBonds.begin());
    502           if ((Runner->type->Z == 1) && (Runner->nr > Walker->nr) && (Binder->GetOtherAtom(Runner) != Binder->GetOtherAtom(Walker))) { // (hydrogens have only one bonding partner!)
     486          Binder = *((*runner)->ListOfBonds.begin());
     487          if (((*runner)->type->Z == 1) && ((*runner)->nr > (*iter)->nr) && (Binder->GetOtherAtom((*runner)) != Binder->GetOtherAtom((*iter)))) { // (hydrogens have only one bonding partner!)
    503488            // 4. evaluate the morse potential for each matrix component and add up
    504             distance = Runner->x.distance(Walker->x);
    505             //Log() << Verbose(0) << "Fragment " << (*ListRunner)->name << ": " << *Runner << "<= " << distance << "=>" << *Walker << ":" << endl;
     489            distance = (*runner)->x.distance((*iter)->x);
     490            //Log() << Verbose(0) << "Fragment " << (*ListRunner)->name << ": " << *(*runner) << "<= " << distance << "=>" << *(*iter) << ":" << endl;
    506491            for (int k = 0; k < a; k++) {
    507492              for (int j = 0; j < b; j++) {
     
    577562  ofstream ForcesFile;
    578563  stringstream line;
    579   atom *Walker = NULL;
    580564  periodentafel *periode=World::getInstance().getPeriode();
    581565
     
    590574      periodentafel::const_iterator elemIter;
    591575      for(elemIter=periode->begin();elemIter!=periode->end();++elemIter){
    592           if ((*ListRunner)->ElementsInMolecule[(*elemIter).first]) { // if this element got atoms
    593           Walker = (*ListRunner)->start;
    594           while (Walker->next != (*ListRunner)->end) { // go through every atom of this element
    595             Walker = Walker->next;
    596             if (Walker->type->getNumber() == (*elemIter).first) {
    597               if ((Walker->GetTrueFather() != NULL) && (Walker->GetTrueFather() != Walker)) {// if there is a rea
     576        if ((*ListRunner)->ElementsInMolecule[(*elemIter).first]) { // if this element got atoms
     577          for(molecule::iterator atomIter = (*ListRunner)->begin(); atomIter !=(*ListRunner)->end();++atomIter){
     578            if ((*atomIter)->type->getNumber() == (*elemIter).first) {
     579              if (((*atomIter)->GetTrueFather() != NULL) && ((*atomIter)->GetTrueFather() != (*atomIter))) {// if there is a rea
    598580                //Log() << Verbose(0) << "Walker is " << *Walker << " with true father " << *( Walker->GetTrueFather()) << ", it
    599                 ForcesFile << SortIndex[Walker->GetTrueFather()->nr] << "\t";
     581                ForcesFile << SortIndex[(*atomIter)->GetTrueFather()->nr] << "\t";
    600582              } else
    601583                // otherwise a -1 to indicate an added saturation hydrogen
     
    633615  bool result = true;
    634616  bool intermediateResult = true;
    635   atom *Walker = NULL;
    636617  Vector BoxDimension;
    637618  char *FragmentNumber = NULL;
     
    674655    // list atoms in fragment for debugging
    675656    DoLog(2) && (Log() << Verbose(2) << "Contained atoms: ");
    676     Walker = (*ListRunner)->start;
    677     while (Walker->next != (*ListRunner)->end) {
    678       Walker = Walker->next;
    679       DoLog(0) && (Log() << Verbose(0) << Walker->getName() << " ");
     657    for (molecule::const_iterator iter = (*ListRunner)->begin(); iter != (*ListRunner)->end(); ++iter) {
     658      DoLog(0) && (Log() << Verbose(0) << (*iter)->getName() << " ");
    680659    }
    681660    DoLog(0) && (Log() << Verbose(0) << endl);
     
    757736{
    758737  molecule *mol = World::getInstance().createMolecule();
    759   atom *Walker = NULL;
    760   atom *Advancer = NULL;
    761738  bond *Binder = NULL;
    762739  bond *Stepper = NULL;
     
    764741  for (MoleculeList::iterator MolRunner = ListOfMolecules.begin(); !ListOfMolecules.empty(); MolRunner = ListOfMolecules.begin()) {
    765742    // shift all atoms to new molecule
    766     Advancer = (*MolRunner)->start->next;
    767     while (Advancer != (*MolRunner)->end) {
    768       Walker = Advancer;
    769       Advancer = Advancer->next;
    770       DoLog(3) && (Log() << Verbose(3) << "Re-linking " << *Walker << "..." << endl);
    771       unlink(Walker);
    772       Walker->father = Walker;
    773       mol->AddAtom(Walker);    // counting starts at 1
     743    for (molecule::iterator iter = (*MolRunner)->begin(); (*MolRunner)->empty(); iter = (*MolRunner)->begin()) {
     744      DoLog(3) && (Log() << Verbose(3) << "Re-linking " << (*iter) << "..." << endl);
     745      (*iter)->father = (*iter);
     746      mol->AddAtom((*iter));    // counting starts at 1
     747      (*MolRunner)->erase(iter);
    774748    }
    775749    // remove all bonds
     
    825799  // 4b. create and fill map of which atom is associated to which connected molecule (note, counting starts at 1)
    826800  int FragmentCounter = 0;
    827   int *MolMap = Calloc<int>(mol->AtomCount, "config::Load() - *MolMap");
     801  int *MolMap = Calloc<int>(mol->getAtomCount(), "config::Load() - *MolMap");
    828802  MoleculeLeafClass *MolecularWalker = Subgraphs;
    829   Walker = NULL;
    830803  while (MolecularWalker->next != NULL) {
    831804    MolecularWalker = MolecularWalker->next;
    832     Walker = MolecularWalker->Leaf->start;
    833     while (Walker->next != MolecularWalker->Leaf->end) {
    834       Walker = Walker->next;
    835       MolMap[Walker->GetTrueFather()->nr] = FragmentCounter+1;
     805    for (molecule::const_iterator iter = MolecularWalker->Leaf->begin(); iter != MolecularWalker->Leaf->end(); ++iter) {
     806      MolMap[(*iter)->GetTrueFather()->nr] = FragmentCounter+1;
    836807    }
    837808    FragmentCounter++;
     
    839810
    840811  // 4c. relocate atoms to new molecules and remove from Leafs
    841   Walker = NULL;
    842   while (mol->start->next != mol->end) {
    843     Walker = mol->start->next;
    844     if ((Walker->nr <0) || (Walker->nr >= mol->AtomCount)) {
    845       DoeLog(0) && (eLog()<< Verbose(0) << "Index of atom " << *Walker << " is invalid!" << endl);
     812  for (molecule::iterator iter = mol->begin(); !mol->empty(); iter = mol->begin()) {
     813    if (((*iter)->nr <0) || ((*iter)->nr >= mol->getAtomCount())) {
     814      DoeLog(0) && (eLog()<< Verbose(0) << "Index of atom " << **iter << " is invalid!" << endl);
    846815      performCriticalExit();
    847816    }
    848     FragmentCounter = MolMap[Walker->nr];
     817    FragmentCounter = MolMap[(*iter)->nr];
    849818    if (FragmentCounter != 0) {
    850       DoLog(3) && (Log() << Verbose(3) << "Re-linking " << *Walker << "..." << endl);
    851       unlink(Walker);
    852       molecules[FragmentCounter-1]->AddAtom(Walker);    // counting starts at 1
     819      DoLog(3) && (Log() << Verbose(3) << "Re-linking " << **iter << "..." << endl);
     820      molecules[FragmentCounter-1]->AddAtom((*iter));    // counting starts at 1
     821      mol->erase(iter);
    853822    } else {
    854       DoeLog(0) && (eLog()<< Verbose(0) << "Atom " << *Walker << " not associated to molecule!" << endl);
     823      DoeLog(0) && (eLog()<< Verbose(0) << "Atom " << **iter << " not associated to molecule!" << endl);
    855824      performCriticalExit();
    856825    }
     
    860829  while (mol->first->next != mol->last) {
    861830    Binder = mol->first->next;
    862     Walker = Binder->leftatom;
     831    const atom * const Walker = Binder->leftatom;
    863832    unlink(Binder);
    864833    link(Binder,molecules[MolMap[Walker->nr]-1]->last);   // counting starts at 1
     
    882851int MoleculeListClass::CountAllAtoms() const
    883852{
    884   atom *Walker = NULL;
    885853  int AtomNo = 0;
    886854  for (MoleculeList::const_iterator MolWalker = ListOfMolecules.begin(); MolWalker != ListOfMolecules.end(); MolWalker++) {
    887     Walker = (*MolWalker)->start;
    888     while (Walker->next != (*MolWalker)->end) {
    889       Walker = Walker->next;
    890       AtomNo++;
    891     }
     855    AtomNo += (*MolWalker)->size();
    892856  }
    893857  return AtomNo;
     
    10641028bool MoleculeLeafClass::FillBondStructureFromReference(const molecule * const reference, int &FragmentCounter, atom ***&ListOfLocalAtoms, bool FreeList)
    10651029{
    1066   atom *Walker = NULL;
    10671030  atom *OtherWalker = NULL;
    10681031  atom *Father = NULL;
     
    10721035  DoLog(1) && (Log() << Verbose(1) << "Begin of FillBondStructureFromReference." << endl);
    10731036  // fill ListOfLocalAtoms if NULL was given
    1074   if (!FillListOfLocalAtoms(ListOfLocalAtoms, FragmentCounter, reference->AtomCount, FreeList)) {
     1037  if (!FillListOfLocalAtoms(ListOfLocalAtoms, FragmentCounter, reference->getAtomCount(), FreeList)) {
    10751038    DoLog(1) && (Log() << Verbose(1) << "Filling of ListOfLocalAtoms failed." << endl);
    10761039    return false;
     
    10881051    }
    10891052
    1090     Walker = Leaf->start;
    1091     while (Walker->next != Leaf->end) {
    1092       Walker = Walker->next;
    1093       Father = Walker->GetTrueFather();
     1053    for(molecule::const_iterator iter = Leaf->begin(); iter != Leaf->end(); ++iter) {
     1054      Father = (*iter)->GetTrueFather();
    10941055      AtomNo = Father->nr; // global id of the current walker
    10951056      for (BondList::const_iterator Runner = Father->ListOfBonds.begin(); Runner != Father->ListOfBonds.end(); (++Runner)) {
    1096         OtherWalker = ListOfLocalAtoms[FragmentCounter][(*Runner)->GetOtherAtom(Walker->GetTrueFather())->nr]; // local copy of current bond partner of walker
     1057        OtherWalker = ListOfLocalAtoms[FragmentCounter][(*Runner)->GetOtherAtom((*iter)->GetTrueFather())->nr]; // local copy of current bond partner of walker
    10971058        if (OtherWalker != NULL) {
    1098           if (OtherWalker->nr > Walker->nr)
    1099             Leaf->AddBond(Walker, OtherWalker, (*Runner)->BondDegree);
     1059          if (OtherWalker->nr > (*iter)->nr)
     1060            Leaf->AddBond((*iter), OtherWalker, (*Runner)->BondDegree);
    11001061        } else {
    1101           DoLog(1) && (Log() << Verbose(1) << "OtherWalker = ListOfLocalAtoms[" << FragmentCounter << "][" << (*Runner)->GetOtherAtom(Walker->GetTrueFather())->nr << "] is NULL!" << endl);
     1062          DoLog(1) && (Log() << Verbose(1) << "OtherWalker = ListOfLocalAtoms[" << FragmentCounter << "][" << (*Runner)->GetOtherAtom((*iter)->GetTrueFather())->nr << "] is NULL!" << endl);
    11021063          status = false;
    11031064        }
     
    11261087bool MoleculeLeafClass::FillRootStackForSubgraphs(KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter)
    11271088{
    1128   atom *Walker = NULL, *Father = NULL;
     1089  atom *Father = NULL;
    11291090
    11301091  if (RootStack != NULL) {
     
    11321093    if (&(RootStack[FragmentCounter]) != NULL) {
    11331094      RootStack[FragmentCounter].clear();
    1134       Walker = Leaf->start;
    1135       while (Walker->next != Leaf->end) { // go through all (non-hydrogen) atoms
    1136         Walker = Walker->next;
    1137         Father = Walker->GetTrueFather();
     1095      for(molecule::const_iterator iter = Leaf->begin(); iter != Leaf->end(); ++iter) {
     1096        Father = (*iter)->GetTrueFather();
    11381097        if (AtomMask[Father->nr]) // apply mask
    11391098#ifdef ADDHYDROGEN
    1140           if (Walker->type->Z != 1) // skip hydrogen
     1099          if ((*iter)->type->Z != 1) // skip hydrogen
    11411100#endif
    1142           RootStack[FragmentCounter].push_front(Walker->nr);
     1101          RootStack[FragmentCounter].push_front((*iter)->nr);
    11431102      }
    11441103      if (next != NULL)
     
    11791138
    11801139  if ((ListOfLocalAtoms != NULL) && (ListOfLocalAtoms[FragmentCounter] == NULL)) { // allocate and fill list of this fragment/subgraph
    1181     status = status && CreateFatherLookupTable(Leaf->start, Leaf->end, ListOfLocalAtoms[FragmentCounter], GlobalAtomCount);
     1140    status = status && Leaf->CreateFatherLookupTable(ListOfLocalAtoms[FragmentCounter], GlobalAtomCount);
    11821141    FreeList = FreeList && true;
    11831142  }
     
    12031162  DoLog(1) && (Log() << Verbose(1) << "Begin of AssignKeySetsToFragment." << endl);
    12041163  // fill ListOfLocalAtoms if NULL was given
    1205   if (!FillListOfLocalAtoms(ListOfLocalAtoms, FragmentCounter, reference->AtomCount, FreeList)) {
     1164  if (!FillListOfLocalAtoms(ListOfLocalAtoms, FragmentCounter, reference->getAtomCount(), FreeList)) {
    12061165    DoLog(1) && (Log() << Verbose(1) << "Filling of ListOfLocalAtoms failed." << endl);
    12071166    return false;
  • src/tesselation.cpp

    r8f215d ra7b761b  
    2121#include "Plane.hpp"
    2222#include "Exceptions/LinearDependenceException.hpp"
     23#include "Helpers/Assert.hpp"
     24
    2325#include "Helpers/Assert.hpp"
    2426
     
    358360  // get ascending order of endpoints
    359361  PointMap OrderMap;
    360   for (int i = 0; i < 3; i++)
     362  for (int i = 0; i < 3; i++) {
    361363    // for all three lines
    362364    for (int j = 0; j < 2; j++) { // for both endpoints
     
    364366      // and we don't care whether insertion fails
    365367    }
     368  }
    366369  // set endpoints
    367370  int Counter = 0;
     
    372375    Counter++;
    373376  }
    374   if (Counter < 3) {
    375     DoeLog(0) && (eLog() << Verbose(0) << "We have a triangle with only two distinct endpoints!" << endl);
    376     performCriticalExit();
    377   }
    378 }
    379 ;
     377  ASSERT(Counter >= 3,"We have a triangle with only two distinct endpoints!");
     378};
     379
    380380
    381381/** Destructor of BoundaryTriangleSet.
     
    12321232;
    12331233
    1234 /** PointCloud implementation of GetTerminalPoint.
    1235  * Uses PointsOnBoundary and STL stuff.
    1236  */
    1237 TesselPoint * Tesselation::GetTerminalPoint() const
    1238 {
    1239   Info FunctionInfo(__func__);
    1240   PointMap::const_iterator Runner = PointsOnBoundary.end();
    1241   Runner--;
    1242   return (Runner->second->node);
    1243 }
    1244 ;
    1245 
    12461234/** PointCloud implementation of GoToNext.
    12471235 * Uses PointsOnBoundary and STL stuff.
     
    12551243;
    12561244
    1257 /** PointCloud implementation of GoToPrevious.
    1258  * Uses PointsOnBoundary and STL stuff.
    1259  */
    1260 void Tesselation::GoToPrevious() const
    1261 {
    1262   Info FunctionInfo(__func__);
    1263   if (InternalPointer != PointsOnBoundary.begin())
    1264     InternalPointer--;
    1265 }
    1266 ;
    1267 
    12681245/** PointCloud implementation of GoToFirst.
    12691246 * Uses PointsOnBoundary and STL stuff.
     
    12731250  Info FunctionInfo(__func__);
    12741251  InternalPointer = PointsOnBoundary.begin();
    1275 }
    1276 ;
    1277 
    1278 /** PointCloud implementation of GoToLast.
    1279  * Uses PointsOnBoundary and STL stuff.
    1280  */
    1281 void Tesselation::GoToLast() const
    1282 {
    1283   Info FunctionInfo(__func__);
    1284   InternalPointer = PointsOnBoundary.end();
    1285   InternalPointer--;
    12861252}
    12871253;
     
    25932559  // fill the set of neighbours
    25942560  TesselPointSet SetOfNeighbours;
     2561
    25952562  SetOfNeighbours.insert(CandidateLine.BaseLine->endpoints[1]->node);
    25962563  for (TesselPointList::iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); Runner++)
  • src/tesselation.hpp

    r8f215d ra7b761b  
    244244  virtual Vector *GetCenter() const { return NULL; };
    245245  virtual TesselPoint *GetPoint() const { return NULL; };
    246   virtual TesselPoint *GetTerminalPoint() const { return NULL; };
    247246  virtual int GetMaxId() const { return 0; };
    248247  virtual void GoToNext() const {};
    249   virtual void GoToPrevious() const {};
    250248  virtual void GoToFirst() const {};
    251   virtual void GoToLast() const {};
    252249  virtual bool IsEmpty() const { return true; };
    253250  virtual bool IsEnd() const { return true; };
     
    363360    virtual Vector *GetCenter(ofstream *out) const;
    364361    virtual TesselPoint *GetPoint() const;
    365     virtual TesselPoint *GetTerminalPoint() const;
    366362    virtual void GoToNext() const;
    367     virtual void GoToPrevious() const;
    368363    virtual void GoToFirst() const;
    369     virtual void GoToLast() const;
    370364    virtual bool IsEmpty() const;
    371365    virtual bool IsEnd() const;
  • src/tesselationhelpers.cpp

    r8f215d ra7b761b  
    838838    int i=cloud->GetMaxId();
    839839    int *LookupList = new int[i];
    840     for (cloud->GoToFirst(), i=0; !cloud->IsEnd(); cloud->GoToNext(), i++)
     840    for (cloud->GoToFirst(), i=0; !cloud->IsEnd(); cloud->GoToNext(), i++){
    841841      LookupList[i] = -1;
     842    }
    842843
    843844    // print atom coordinates
    844845    int Counter = 1;
    845846    TesselPoint *Walker = NULL;
    846     for (PointMap::const_iterator target = TesselStruct->PointsOnBoundary.begin(); target != TesselStruct->PointsOnBoundary.end(); target++) {
     847    for (PointMap::const_iterator target = TesselStruct->PointsOnBoundary.begin(); target != TesselStruct->PointsOnBoundary.end(); ++target) {
    847848      Walker = target->second->node;
    848849      LookupList[Walker->nr] = Counter++;
  • src/unittests/AnalysisCorrelationToPointUnitTest.cpp

    r8f215d ra7b761b  
    2525#include "periodentafel.hpp"
    2626#include "tesselation.hpp"
    27 #include "World.hpp"
    2827
    2928#ifdef HAVE_TESTRUNNER
     
    8079
    8180  // check that TestMolecule was correctly constructed
    82   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
     81  CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
    8382
    8483  TestList = World::getInstance().getMolecules();
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    r8f215d ra7b761b  
    2626#include "tesselation.hpp"
    2727#include "World.hpp"
     28#include "Helpers/Assert.hpp"
    2829
    2930#include "Helpers/Assert.hpp"
     
    4041void AnalysisCorrelationToSurfaceUnitTest::setUp()
    4142{
    42   //ASSERT_DO(Assert::Throw);
     43  ASSERT_DO(Assert::Throw);
    4344
    4445  atom *Walker = NULL;
     
    7172  // construct molecule (tetraeder of hydrogens) base
    7273  TestSurfaceMolecule = World::getInstance().createMolecule();
     74
    7375  Walker = World::getInstance().createAtom();
    7476  Walker->type = hydrogen;
    7577  *Walker->node = Vector(1., 0., 1. );
    76 
    77   TestSurfaceMolecule->AddAtom(Walker);
     78  TestSurfaceMolecule->AddAtom(Walker);
     79
    7880  Walker = World::getInstance().createAtom();
    7981  Walker->type = hydrogen;
    8082  *Walker->node = Vector(0., 1., 1. );
    8183  TestSurfaceMolecule->AddAtom(Walker);
     84
    8285  Walker = World::getInstance().createAtom();
    8386  Walker->type = hydrogen;
    8487  *Walker->node = Vector(1., 1., 0. );
    8588  TestSurfaceMolecule->AddAtom(Walker);
     89
    8690  Walker = World::getInstance().createAtom();
    8791  Walker->type = hydrogen;
     
    9094
    9195  // check that TestMolecule was correctly constructed
    92   CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->AtomCount, 4 );
     96  CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->getAtomCount(), 4 );
    9397
    9498  TestList = World::getInstance().getMolecules();
     
    107111  *Walker->node = Vector(4., 0., 4. );
    108112  TestSurfaceMolecule->AddAtom(Walker);
     113
    109114  Walker = World::getInstance().createAtom();
    110115  Walker->type = carbon;
    111116  *Walker->node = Vector(0., 4., 4. );
    112117  TestSurfaceMolecule->AddAtom(Walker);
     118
    113119  Walker = World::getInstance().createAtom();
    114120  Walker->type = carbon;
    115121  *Walker->node = Vector(4., 4., 0. );
    116122  TestSurfaceMolecule->AddAtom(Walker);
     123
    117124  // add inner atoms
    118125  Walker = World::getInstance().createAtom();
     
    120127  *Walker->node = Vector(0.5, 0.5, 0.5 );
    121128  TestSurfaceMolecule->AddAtom(Walker);
     129
    122130  TestSurfaceMolecule->ActiveFlag = true;
    123131  TestList->insert(TestSurfaceMolecule);
     
    150158void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest()
    151159{
    152   CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->AtomCount );
     160  CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->getAtomCount() );
    153161  CPPUNIT_ASSERT_EQUAL( (size_t)2, TestList->ListOfMolecules.size() );
    154162  CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
  • src/unittests/AnalysisPairCorrelationUnitTest.cpp

    r8f215d ra7b761b  
    7979
    8080  // check that TestMolecule was correctly constructed
    81   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
     81  CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
    8282
    8383  TestList = World::getInstance().getMolecules();
  • src/unittests/CountBondsUnitTest.cpp

    r8f215d ra7b761b  
    102102
    103103  // check that TestMolecule was correctly constructed
    104   CPPUNIT_ASSERT_EQUAL( TestMolecule1->AtomCount, 3 );
    105   Walker = TestMolecule1->start->next;
    106   CPPUNIT_ASSERT( TestMolecule1->end != Walker );
    107   CPPUNIT_ASSERT_EQUAL( TestMolecule2->AtomCount, 3 );
    108   Walker = TestMolecule2->start->next;
    109   CPPUNIT_ASSERT( TestMolecule2->end != Walker );
     104  CPPUNIT_ASSERT_EQUAL( TestMolecule1->getAtomCount(), 3 );
     105  CPPUNIT_ASSERT_EQUAL( TestMolecule2->getAtomCount(), 3 );
    110106
    111107  // create a small file with table
  • src/unittests/LinkedCellUnitTest.cpp

    r8f215d ra7b761b  
    6969
    7070  // check that TestMolecule was correctly constructed
    71   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 3*3*3 );
    72   Walker = TestMolecule->start->next;
    73   CPPUNIT_ASSERT( TestMolecule->end != Walker );
     71  CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 3*3*3 );
    7472};
    7573
     
    197195{
    198196  // check all atoms
    199   atom *Walker = TestMolecule->start;
    200   while (Walker->next != TestMolecule->end) {
    201     Walker = Walker->next;
    202     CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToNode(Walker) );
     197  for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end();++iter){
     198    CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToNode(*iter) );
    203199  }
    204200
    205201  // check internal vectors, returns false, because this atom is not in LC-list!
    206   Walker = World::getInstance().createAtom();
    207   Walker->setName("test");
    208   Walker->x= Vector(1,1,1);
    209   CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) );
    210   World::getInstance().destroyAtom(Walker);
     202  atom *newAtom = World::getInstance().createAtom();
     203  newAtom->setName("test");
     204  newAtom->x= Vector(1,1,1);
     205  CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(newAtom) );
     206  World::getInstance().destroyAtom(newAtom);
    211207
    212208  // check out of bounds vectors
    213   Walker = World::getInstance().createAtom();
    214   Walker->setName("test");
    215   Walker->x = Vector(0,-1,0);
    216   CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) );
    217   World::getInstance().destroyAtom(Walker);
     209  newAtom = World::getInstance().createAtom();
     210  newAtom->setName("test");
     211  newAtom->x = Vector(0,-1,0);
     212  CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(newAtom) );
     213  World::getInstance().destroyAtom(newAtom);
    218214};
    219215
     
    287283  size = ListOfPoints->size();
    288284  CPPUNIT_ASSERT_EQUAL( (size_t)27, size );
    289   Walker = TestMolecule->start;
    290   Walker = TestMolecule->start;
    291   while (Walker->next != TestMolecule->end) {
    292     Walker = Walker->next;
    293     ListOfPoints->remove(Walker);
     285
     286  for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end(); ++iter){
     287    ListOfPoints->remove((*iter));
    294288    size--;
    295289    CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
     
    306300  size=ListOfPoints->size();
    307301  CPPUNIT_ASSERT_EQUAL( (size_t)8, size );
    308   Walker = TestMolecule->start;
    309   while (Walker->next != TestMolecule->end) {
    310     Walker = Walker->next;
    311     if ((Walker->x[0] <2) && (Walker->x[1] <2) && (Walker->x[2] <2)) {
    312       ListOfPoints->remove(Walker);
     302  for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end(); ++iter){
     303    if (((*iter)->x[0] <2) && ((*iter)->x[1] <2) && ((*iter)->x[2] <2)) {
     304      ListOfPoints->remove(*iter);
    313305      size--;
    314306      CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
     
    326318  size=ListOfPoints->size();
    327319  CPPUNIT_ASSERT_EQUAL( (size_t)27, size );
    328   Walker = TestMolecule->start;
    329   while (Walker->next != TestMolecule->end) {
    330     Walker = Walker->next;
    331     ListOfPoints->remove(Walker);
     320  for(molecule::iterator iter = TestMolecule->begin(); iter!=TestMolecule->end();++iter){
     321    ListOfPoints->remove(*iter);
    332322    size--;
    333323    CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
     
    355345  size = ListOfPoints->size();
    356346  CPPUNIT_ASSERT_EQUAL( (size_t)7, size );
    357   Walker = TestMolecule->start;
    358   while (Walker->next != TestMolecule->end) {
    359     Walker = Walker->next;
    360     if ((Walker->x.DistanceSquared(tester) - 1.) < MYEPSILON ) {
    361       ListOfPoints->remove(Walker);
     347  for(molecule::iterator iter = TestMolecule->begin(); iter!=TestMolecule->end();++iter){
     348    if (((*iter)->x.DistanceSquared(tester) - 1.) < MYEPSILON ) {
     349      ListOfPoints->remove(*iter);
    362350      size--;
    363351      CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
  • src/unittests/ObserverTest.cpp

    r8f215d ra7b761b  
    1111#include <cppunit/extensions/TestFactoryRegistry.h>
    1212#include <cppunit/ui/text/TestRunner.h>
     13#include <set>
    1314
    1415#include "Patterns/Observer.hpp"
     16#include "Patterns/ObservedIterator.hpp"
    1517#include "Helpers/Assert.hpp"
    1618
     
    162164  bool wasNotified;
    163165};
     166
     167class ObservableCollection : public Observable {
     168public:
     169  typedef std::set<SimpleObservable*> set;
     170  typedef ObservedIterator<set> iterator;
     171  typedef set::const_iterator const_iterator;
     172
     173  ObservableCollection(int _num) :
     174  num(_num)
     175  {
     176    for(int i=0; i<num; ++i){
     177      SimpleObservable *content = new SimpleObservable();
     178      content->signOn(this);
     179      theSet.insert(content);
     180    }
     181  }
     182
     183  ~ObservableCollection(){
     184    set::iterator iter;
     185    for(iter=theSet.begin(); iter!=theSet.end(); ++iter ){
     186      delete (*iter);
     187    }
     188  }
     189
     190  iterator begin(){
     191    return iterator(theSet.begin(),this);
     192  }
     193
     194  iterator end(){
     195    return iterator(theSet.end(),this);
     196  }
     197
     198  const int num;
     199
     200private:
     201  set theSet;
     202};
     203
    164204
    165205/******************* actuall tests ***************/
     
    173213  blockObservable = new BlockObservable();
    174214  notificationObservable = new NotificationObservable();
     215  collection = new ObservableCollection(5);
    175216
    176217  observer1 = new UpdateCountObserver();
     
    181222  notificationObserver1 = new NotificationObserver(notificationObservable->notification1);
    182223  notificationObserver2 = new NotificationObserver(notificationObservable->notification2);
    183 
    184224}
    185225
     
    191231  delete blockObservable;
    192232  delete notificationObservable;
     233  delete collection;
    193234
    194235  delete observer1;
     
    277318  blockObservable->changeMethod2();
    278319  blockObservable->noChangeMethod();
     320}
     321
     322void ObserverTest::iteratorTest(){
     323  int i = 0;
     324  // test the general iterator methods
     325  for(ObservableCollection::iterator iter=collection->begin(); iter!=collection->end();++iter){
     326    CPPUNIT_ASSERT(i< collection->num);
     327    i++;
     328  }
     329
     330  i=0;
     331  for(ObservableCollection::const_iterator iter=collection->begin(); iter!=collection->end();++iter){
     332    CPPUNIT_ASSERT(i<collection->num);
     333    i++;
     334  }
     335
     336  collection->signOn(observer1);
     337  {
     338    // we construct this out of the loop, so the iterator dies at the end of
     339    // the scope and not the end of the loop (allows more testing)
     340    ObservableCollection::iterator iter;
     341    for(iter=collection->begin(); iter!=collection->end(); ++iter){
     342      (*iter)->changeMethod();
     343    }
     344    // At this point no change should have been propagated
     345    CPPUNIT_ASSERT_EQUAL( 0, observer1->updates);
     346  }
     347  // After the Iterator has died the propagation should take place
     348  CPPUNIT_ASSERT_EQUAL( 1, observer1->updates);
     349
     350  // when using a const_iterator no changes should be propagated
     351  for(ObservableCollection::const_iterator iter = collection->begin(); iter!=collection->end();++iter);
     352  CPPUNIT_ASSERT_EQUAL( 1, observer1->updates);
     353  collection->signOff(observer1);
    279354}
    280355
  • src/unittests/ObserverTest.hpp

    r8f215d ra7b761b  
    1717class CallObservable;
    1818class SuperObservable;
     19class ObservableCollection;
    1920class BlockObservable;
    2021class NotificationObservable;
    21 
    2222
    2323class ObserverTest :  public CppUnit::TestFixture
     
    2929  CPPUNIT_TEST ( doesNotifyTest );
    3030  CPPUNIT_TEST ( doesReportTest );
     31  CPPUNIT_TEST ( iteratorTest );
    3132  CPPUNIT_TEST ( CircleDetectionTest );
    3233  CPPUNIT_TEST_SUITE_END();
     
    4142  void doesNotifyTest();
    4243  void doesReportTest();
     44  void iteratorTest();
    4345  void CircleDetectionTest();
    4446
     
    5860  SuperObservable *superObservable;
    5961  NotificationObservable *notificationObservable;
     62  ObservableCollection *collection;
     63
    6064};
    6165
  • src/unittests/analysisbondsunittest.cpp

    r8f215d ra7b761b  
    2525#include "molecule.hpp"
    2626#include "periodentafel.hpp"
     27#include "World.hpp"
    2728
    2829#ifdef HAVE_TESTRUNNER
     
    8990
    9091  // check that TestMolecule was correctly constructed
    91   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 5 );
     92  CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 5 );
    9293
    9394  // create a small file with table
  • src/unittests/bondgraphunittest.cpp

    r8f215d ra7b761b  
    8989
    9090  // check that TestMolecule was correctly constructed
    91   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
     91  CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
    9292
    9393  // create a small file with table
     
    120120};
    121121
     122/** Tests whether setup worked.
     123 */
     124void BondGraphTest::SetupTest()
     125{
     126  CPPUNIT_ASSERT_EQUAL (false, TestMolecule->empty());
     127  CPPUNIT_ASSERT_EQUAL ((size_t)4, TestMolecule->size());
     128};
     129
    122130/** UnitTest for BondGraphTest::LoadBondLengthTable().
    123131 */
     
    134142void BondGraphTest::ConstructGraphFromTableTest()
    135143{
    136   atom *Walker = TestMolecule->start->next;
    137   atom *Runner = TestMolecule->end->previous;
    138   CPPUNIT_ASSERT( TestMolecule->end != Walker );
     144  molecule::iterator Walker = TestMolecule->begin();
     145  molecule::iterator Runner = TestMolecule->begin();
     146  Runner++;
    139147  CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
    140148  CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
    141   CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
     149  CPPUNIT_ASSERT_EQUAL( true , (*Walker)->IsBondedTo((*Runner)) );
    142150};
    143151
     
    146154void BondGraphTest::ConstructGraphFromCovalentRadiiTest()
    147155{
    148   atom *Walker = TestMolecule->start->next;
    149   atom *Runner = TestMolecule->end->previous;
    150   CPPUNIT_ASSERT( TestMolecule->end != Walker );
     156
     157  //atom *Walker = TestMolecule->start->next;
     158  //atom *Runner = TestMolecule->end->previous;
     159  //CPPUNIT_ASSERT( TestMolecule->end != Walker );
    151160  CPPUNIT_ASSERT_EQUAL( false , BG->LoadBondLengthTable(*dummyname) );
    152161  CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
    153   CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
     162
     163  // this cannot be assured using dynamic IDs
     164  //CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
    154165};
    155166
  • src/unittests/bondgraphunittest.hpp

    r8f215d ra7b761b  
    2222{
    2323    CPPUNIT_TEST_SUITE( BondGraphTest) ;
     24    CPPUNIT_TEST ( SetupTest );
    2425    CPPUNIT_TEST ( LoadTableTest );
    2526    CPPUNIT_TEST ( ConstructGraphFromTableTest );
     
    3031      void setUp();
    3132      void tearDown();
     33      void SetupTest();
    3234      void LoadTableTest();
    3335      void ConstructGraphFromTableTest();
  • src/unittests/listofbondsunittest.cpp

    r8f215d ra7b761b  
    7474
    7575  // check that TestMolecule was correctly constructed
    76   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
     76  CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
    7777
    7878};
     
    9090};
    9191
     92/** Tests whether setup worked correctly.
     93 *
     94 */
     95void ListOfBondsTest::SetupTest()
     96{
     97  CPPUNIT_ASSERT_EQUAL( false, TestMolecule->empty() );
     98  CPPUNIT_ASSERT_EQUAL( (size_t)4, TestMolecule->size() );
     99};
     100
    92101/** Unit Test of molecule::AddBond()
    93102 *
     
    96105{
    97106  bond *Binder = NULL;
    98   atom *atom1 = TestMolecule->start->next;
    99   atom *atom2 = atom1->next;
     107  molecule::iterator iter = TestMolecule->begin();
     108  atom *atom1 = *iter;
     109  iter++;
     110  atom *atom2 = *iter;
    100111  CPPUNIT_ASSERT( atom1 != NULL );
    101112  CPPUNIT_ASSERT( atom2 != NULL );
     
    124135{
    125136  bond *Binder = NULL;
    126   atom *atom1 = TestMolecule->start->next;
    127   atom *atom2 = atom1->next;
     137  molecule::iterator iter = TestMolecule->begin();
     138  atom *atom1 = *iter;
     139  iter++;
     140  atom *atom2 = *iter;
    128141  CPPUNIT_ASSERT( atom1 != NULL );
    129142  CPPUNIT_ASSERT( atom2 != NULL );
     
    150163{
    151164  bond *Binder = NULL;
    152   atom *atom1 = TestMolecule->start->next;
    153   atom *atom2 = atom1->next;
    154   atom *atom3 = atom2->next;
     165  molecule::iterator iter = TestMolecule->begin();
     166  atom *atom1 = *iter;
     167  iter++;
     168  atom *atom2 = *iter;
     169  iter++;
     170  atom *atom3 = *iter;
    155171  CPPUNIT_ASSERT( atom1 != NULL );
    156172  CPPUNIT_ASSERT( atom2 != NULL );
     
    189205{
    190206  bond *Binder = NULL;
    191   atom *atom1 = TestMolecule->start->next;
    192   atom *atom2 = atom1->next;
     207  molecule::iterator iter = TestMolecule->begin();
     208  atom *atom1 = *iter;
     209  iter++;
     210  atom *atom2 = *iter;
    193211  CPPUNIT_ASSERT( atom1 != NULL );
    194212  CPPUNIT_ASSERT( atom2 != NULL );
     
    215233{
    216234  bond *Binder = NULL;
    217   atom *atom1 = TestMolecule->start->next;
    218   atom *atom2 = atom1->next;
     235  molecule::iterator iter = TestMolecule->begin();
     236  atom *atom1 = *iter;
     237  iter++;
     238  atom *atom2 = *iter;
    219239  CPPUNIT_ASSERT( atom1 != NULL );
    220240  CPPUNIT_ASSERT( atom2 != NULL );
     
    240260{
    241261  bond *Binder = NULL;
    242   atom *atom1 = TestMolecule->start->next;
    243   atom *atom2 = atom1->next;
     262  molecule::iterator iter = TestMolecule->begin();
     263  atom *atom1 = *iter;
     264  iter++;
     265  atom *atom2 = *iter;
    244266  CPPUNIT_ASSERT( atom1 != NULL );
    245267  CPPUNIT_ASSERT( atom2 != NULL );
  • src/unittests/listofbondsunittest.hpp

    r8f215d ra7b761b  
    2020{
    2121    CPPUNIT_TEST_SUITE( ListOfBondsTest) ;
     22    CPPUNIT_TEST ( SetupTest );
    2223    CPPUNIT_TEST ( AddingBondTest );
    2324    CPPUNIT_TEST ( RemovingBondTest );
     
    3132      void setUp();
    3233      void tearDown();
     34      void SetupTest();
    3335      void AddingBondTest();
    3436      void RemovingBondTest();
Note: See TracChangeset for help on using the changeset viewer.