Changes in / [8f215d:a7b761b]
- Location:
- src
- Files:
-
- 1 added
- 1 deleted
- 39 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Helpers/Assert.cpp
r8f215d ra7b761b 54 54 55 55 56 57 56 bool _my_assert::check(const bool res, 58 57 const char* condition, … … 63 62 { 64 63 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; 66 65 cout << "Assertion Message: " << message << std::endl; 67 66 while(true){ -
src/Legacy/oldmenu.cpp
r8f215d ra7b761b 423 423 void oldmenu::RemoveAtoms(molecule *mol) 424 424 { 425 atom * first, *second;425 atom *second; 426 426 int axis; 427 427 double tmp1, tmp2; … … 446 446 break; 447 447 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 } 458 458 } 459 459 break; … … 465 465 Log() << Verbose(0) << "Upper boundary: "; 466 466 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)); 475 473 } 476 474 } … … 515 513 min[i] = 0.; 516 514 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; 521 517 tmp1 = 0.; 522 if (first != second) {523 x = first->x - second->x;518 if (first != (*iter)) { 519 x = first->x - (*iter)->x; 524 520 tmp1 = x.Norm(); 525 521 } 526 522 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; 528 524 } 529 525 for (int i=MAX_ELEMENTS;i--;) … … 754 750 Log() << Verbose(0) << "State the factor: "; 755 751 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 760 754 Elements = new const element *[count]; 761 755 vectors = new Vector *[count]; 762 756 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; 768 760 j++; 769 761 } … … 1024 1016 return; 1025 1017 } 1026 atom *Walker = mol->start;1027 1018 1028 1019 // generate some KeySets 1029 1020 Log() << Verbose(0) << "Generating KeySets." << endl; 1030 KeySet TestSets[mol-> AtomCount+1];1021 KeySet TestSets[mol->getAtomCount()+1]; 1031 1022 i=1; 1032 while (Walker->next != mol->end) { 1033 Walker = Walker->next; 1023 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) { 1034 1024 for (int j=0;j<i;j++) { 1035 TestSets[j].insert( Walker->nr);1025 TestSets[j].insert((*iter)->nr); 1036 1026 } 1037 1027 i++; … … 1039 1029 Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl; 1040 1030 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 } 1044 1039 } 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 } 1049 1042 1050 1043 // constructing Graph structure … … 1054 1047 // insert KeySets into Subgraphs 1055 1048 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++) { 1057 1050 Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.))); 1058 1051 } 1059 1052 Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl; 1060 1053 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.))); 1062 1055 if (test2.second) { 1063 1056 Log() << Verbose(1) << "Insertion worked?!" << endl; -
src/Makefile.am
r8f215d ra7b761b 76 76 Descriptors/MoleculeIdDescriptor.cpp 77 77 78 78 79 79 DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp \ 80 80 Descriptors/AtomIdDescriptor.hpp \ … … 94 94 Exceptions/MathException.hpp \ 95 95 Exceptions/ZeroVectorException.hpp 96 96 97 97 98 SOURCE = ${ANALYSISSOURCE} \ … … 112 113 graph.cpp \ 113 114 helpers.cpp \ 115 Helpers/Assert.cpp \ 114 116 info.cpp \ 115 117 leastsquaremin.cpp \ 116 118 Line.cpp \ 117 119 linkedcell.cpp \ 118 lists.cpp \119 120 log.cpp \ 120 121 logger.cpp \ … … 133 134 tesselationhelpers.cpp \ 134 135 triangleintersectionlist.cpp \ 136 vector.cpp \ 135 137 verbose.cpp \ 136 138 vector_ops.cpp \ -
src/Patterns/Cacheable.hpp
r8f215d ra7b761b 28 28 owner(_owner) 29 29 {} 30 virtual T getValue()=0;30 virtual T& getValue()=0; 31 31 virtual void invalidate()=0; 32 32 virtual bool isValid()=0; … … 46 46 {} 47 47 48 virtual T getValue(){48 virtual T& getValue(){ 49 49 // set the state to valid 50 50 State::owner->switchState(State::owner->validState); … … 72 72 {} 73 73 74 virtual T getValue(){74 virtual T& getValue(){ 75 75 return content; 76 76 } … … 100 100 {} 101 101 102 virtual T getValue(){102 virtual T& getValue(){ 103 103 ASSERT(0,"Cannot get a value from a Cacheable after it's Observable has died"); 104 104 // we have to return a grossly invalid reference, because no value can be produced anymore … … 134 134 void subjectKilled(Observable *subject); 135 135 private: 136 137 136 void switchState(state_ptr newState); 138 137 … … 144 143 145 144 Observable *owner; 146 147 145 boost::function<T()> recalcMethod; 148 146 … … 221 219 222 220 const bool isValid() const; 223 const T operator*() const;221 const T& operator*() const; 224 222 225 223 // methods implemented for base-class Observer … … 237 235 238 236 template<typename T> 239 const T Cacheable<T>::operator*() const{237 const T& Cacheable<T>::operator*() const{ 240 238 return recalcMethod(); 241 239 } -
src/Patterns/Observer.cpp
r8f215d ra7b761b 82 82 Observable::_Observable_protector::_Observable_protector(Observable *_protege) : 83 83 protege(_protege) 84 { 85 start_observer_internal(protege); 86 } 87 88 Observable::_Observable_protector::_Observable_protector(const _Observable_protector &dest) : 89 protege(dest.protege) 84 90 { 85 91 start_observer_internal(protege); … … 189 195 ASSERT(callTable.count(this),"SignOff called for an Observable without Observers."); 190 196 callees_t &callees = callTable[this]; 197 191 198 callees_t::iterator iter; 192 199 callees_t::iterator deliter; -
src/Patterns/Observer.hpp
r8f215d ra7b761b 36 36 typedef Notification *const Notification_ptr; 37 37 38 template<class _Set> 39 class ObservedIterator; 40 38 41 /** 39 42 * An Observer is notified by all Observed objects, when anything changes. … … 53 56 friend class Observable; 54 57 friend class Notification; 58 template<class> friend class ObservedIterator; 59 55 60 public: 56 61 Observer(); … … 152 157 static std::set<Observable*> busyObservables; 153 158 154 155 159 //! @cond 156 160 // Structure for RAII-Style notification … … 164 168 public: 165 169 _Observable_protector(Observable *); 170 _Observable_protector(const _Observable_protector&); 166 171 ~_Observable_protector(); 167 172 private: -
src/analysis_bonds.cpp
r8f215d ra7b761b 26 26 Mean = 0.; 27 27 28 atom *Walker = mol->start;29 28 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(); 33 31 if (Max < count) 34 32 Max = count; … … 58 56 59 57 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) { 66 62 const double distance = (*BondRunner)->GetDistanceSquared(); 67 63 if (Min > distance) … … 126 122 int CountHydrogenBridgeBonds(MoleculeListClass *molecules, element * InterfaceElement = NULL) 127 123 { 128 atom *Walker = NULL;129 atom *Runner = NULL;130 124 int count = 0; 131 125 int OtherHydrogens = 0; … … 133 127 bool InterfaceFlag = false; 134 128 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)) { 144 136 // check distance 145 const double distance = Runner->x.DistanceSquared(Walker->x);137 const double distance = (*Runner)->x.DistanceSquared((*Walker)->x); 146 138 if ((distance > MYEPSILON) && (distance < HBRIDGEDISTANCE*HBRIDGEDISTANCE)) { // distance >0 means different atoms 147 139 // on other atom(Runner) we check for bond to interface element and … … 151 143 OtherHydrogens = 0; 152 144 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); 155 147 // if hydrogen, check angle to be greater(!) than 30 degrees 156 148 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); 158 150 OtherHydrogenFlag = OtherHydrogenFlag && (angle > M_PI*(30./180.) + MYEPSILON); 159 151 Otherangle += angle; … … 176 168 if (InterfaceFlag && OtherHydrogenFlag) { 177 169 // 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); 180 172 if (OtherAtom->type->Z == 1) { 181 173 // 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); 184 176 count++; 185 177 break; … … 205 197 int CountBondsOfTwo(MoleculeListClass * const molecules, const element * const first, const element * const second) 206 198 { 207 atom *Walker = NULL;208 199 int count = 0; 209 200 210 201 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 matches215 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)) { 218 209 count++; 219 210 DoLog(1) && (Log() << Verbose(1) << first->name << "-" << second->name << " bond found between " << *Walker << " and " << *OtherAtom << "." << endl); … … 240 231 bool MatchFlag[2]; 241 232 bool result = false; 242 atom *Walker = NULL;243 233 const element * ElementArray[2]; 244 234 ElementArray[0] = first; … … 246 236 247 237 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 matches238 molecule::iterator Walker = (*MolWalker)->begin(); 239 for(;Walker!=(*MolWalker)->end();++Walker){ 240 atom *theAtom = *Walker; 241 if (theAtom->type == second) { // first element matches 252 242 for (int i=0;i<2;i++) 253 243 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); 256 246 for (int i=0;i<2;i++) 257 247 if ((!MatchFlag[i]) && (OtherAtom->type == ElementArray[i])) { -
src/analysis_correlation.cpp
r8f215d ra7b761b 40 40 } 41 41 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++){ 43 43 if ((*MolWalker)->ActiveFlag) { 44 44 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++){ 51 50 if ((*MolOtherWalker)->ActiveFlag) { 52 51 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)) ) ); 62 59 } 60 } 63 61 } 62 } 64 63 } 65 64 } 66 65 } 67 66 } 68 67 } 69 68 return outmap; 70 69 }; … … 101 100 double * FullInverseMatrix = InverseMatrix(FullMatrix); 102 101 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; 109 106 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 110 107 // go through every range in xyz and get distance … … 117 114 if ((*MolOtherWalker)->ActiveFlag) { 118 115 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; 126 121 periodicOtherX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 127 122 // go through every range in xyz and get distance … … 132 127 checkOtherX.MatrixMultiplication(FullMatrix); 133 128 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)) ) ); 136 131 } 137 132 } … … 169 164 if ((*MolWalker)->ActiveFlag) { 170 165 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()); 177 170 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) ) ); 179 172 } 180 173 } … … 211 204 double * FullInverseMatrix = InverseMatrix(FullMatrix); 212 205 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; 219 210 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 220 211 // go through every range in xyz and get distance … … 226 217 distance = checkX.distance(*point); 227 218 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) ) ); 229 220 } 230 221 } … … 261 252 if ((*MolWalker)->ActiveFlag) { 262 253 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); 269 258 distance = Intersections.GetSmallestDistance(); 270 259 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) ) ); 272 261 } 273 262 } … … 314 303 double * FullInverseMatrix = InverseMatrix(FullMatrix); 315 304 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; 322 309 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 323 310 // go through every range in xyz and get distance … … 337 324 } 338 325 // 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) ) ); 340 327 //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl; 341 328 } -
src/atom.cpp
r8f215d ra7b761b 59 59 atom::~atom() 60 60 { 61 unlink(this);62 61 }; 63 62 -
src/bondgraph.cpp
r8f215d ra7b761b 90 90 bool status = true; 91 91 92 if (mol-> start->next == mol->end) // only construct if molecule is not empty92 if (mol->empty()) // only construct if molecule is not empty 93 93 return false; 94 94 … … 124 124 max_distance = 0.; 125 125 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; 131 129 } 132 130 max_distance *= 2.; -
src/boundary.cpp
r8f215d ra7b761b 139 139 { 140 140 Info FunctionInfo(__func__); 141 atom *Walker = NULL;142 141 PointMap PointsOnBoundary; 143 142 LineMap LinesOnBoundary; … … 165 164 166 165 // 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); 171 168 ProjectedVector.ProjectOntoPlane(AxisVector); 172 169 … … 182 179 angle = 2. * M_PI - angle; 183 180 } 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)))); 186 183 if (!BoundaryTestPair.second) { // same point exists, check first r, then distance of original vectors to center of gravity 187 184 DoLog(2) && (Log() << Verbose(2) << "Encountered two vectors whose projection onto axis " << axis << " is equal: " << endl); 188 185 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); 190 187 const double ProjectedVectorNorm = ProjectedVector.NormSquared(); 191 188 if ((ProjectedVectorNorm - BoundaryTestPair.first->second.first) > MYEPSILON) { 192 189 BoundaryTestPair.first->second.first = ProjectedVectorNorm; 193 BoundaryTestPair.first->second.second = Walker;190 BoundaryTestPair.first->second.second = (*iter); 194 191 DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger projected distance " << ProjectedVectorNorm << "." << endl); 195 192 } else if (fabs(ProjectedVectorNorm - BoundaryTestPair.first->second.first) < MYEPSILON) { 196 helper = Walker->x - (*MolCenter); 193 helper = (*iter)->x; 194 helper -= *MolCenter; 197 195 const double oldhelperNorm = helper.NormSquared(); 198 196 helper = BoundaryTestPair.first->second.second->x - (*MolCenter); 199 197 if (helper.NormSquared() < oldhelperNorm) { 200 BoundaryTestPair.first->second.second = Walker;198 BoundaryTestPair.first->second.second = (*iter); 201 199 DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger distance to molecule center " << helper.NormSquared() << "." << endl); 202 200 } else { … … 695 693 int repetition[NDIM] = { 1, 1, 1 }; 696 694 int TotalNoClusters = 1; 697 atom *Walker = NULL;698 695 double totalmass = 0.; 699 696 double clustervolume = 0.; … … 719 716 720 717 // 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; 725 720 } 726 721 DoLog(0) && (Log() << Verbose(0) << "RESULT: The summed mass is " << setprecision(10) << totalmass << " atomicmassunit." << endl); … … 804 799 Vector Inserter; 805 800 double FillIt = false; 806 atom *Walker = NULL;807 801 bond *Binder = NULL; 808 802 double phi[NDIM]; … … 811 805 812 806 for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++) 813 if ((*ListRunner)-> AtomCount> 0) {807 if ((*ListRunner)->getAtomCount() > 0) { 814 808 DoLog(1) && (Log() << Verbose(1) << "Pre-creating linked cell lists for molecule " << *ListRunner << "." << endl); 815 809 LCList[(*ListRunner)] = new LinkedCell((*ListRunner), 10.); // get linked cell list … … 829 823 } 830 824 831 filler->CountAtoms(); 832 atom * CopyAtoms[filler->AtomCount]; 825 atom * CopyAtoms[filler->getAtomCount()]; 833 826 834 827 // calculate filler grid in [0,1]^3 … … 855 848 856 849 // go through all atoms 857 for (int i=0;i<filler-> AtomCount;i++)850 for (int i=0;i<filler->getAtomCount();i++) 858 851 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){ 862 853 863 854 // create atomic random translation vector ... … … 883 874 884 875 // ... and put at new position 885 Inserter = Walker->x;876 Inserter = (*iter)->x; 886 877 if (DoRandomRotation) 887 878 Inserter.MatrixMultiplication(Rotations); … … 907 898 DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is outer point." << endl); 908 899 // 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); 913 904 } else { 914 905 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; 916 907 continue; 917 908 } … … 952 943 bool TesselationFailFlag = false; 953 944 945 mol->getAtomCount(); 946 954 947 if (TesselStruct == NULL) { 955 948 DoLog(1) && (Log() << Verbose(1) << "Allocating Tesselation struct ..." << endl); … … 1023 1016 // // look whether all points are inside of the convex envelope, otherwise add them via degenerated triangles 1024 1017 // //->InsertStraddlingPoints(mol, LCList); 1025 // mol->GoToFirst();1018 // for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) { 1026 1019 // class TesselPoint *Runner = NULL; 1027 // while (!mol->IsEnd()) { 1028 // Runner = mol->GetPoint(); 1020 // Runner = *iter; 1029 1021 // Log() << Verbose(1) << "Checking on " << Runner->Name << " ... " << endl; 1030 1022 // if (!->IsInnerPoint(Runner, LCList)) { … … 1034 1026 // Log() << Verbose(2) << Runner->Name << " is inside of or on envelope." << endl; 1035 1027 // } 1036 // mol->GoToNext();1037 1028 // } 1038 1029 … … 1043 1034 status = CheckListOfBaselines(TesselStruct); 1044 1035 1036 cout << "before correction" << endl; 1037 1045 1038 // store before correction 1046 StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, "");1039 StoreTrianglesinFile(mol, TesselStruct, filename, ""); 1047 1040 1048 1041 // // correct degenerated polygons … … 1054 1047 // write final envelope 1055 1048 CalculateConcavityPerBoundaryPoint(TesselStruct); 1056 StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, ""); 1049 cout << "after correction" << endl; 1050 StoreTrianglesinFile(mol, TesselStruct, filename, ""); 1057 1051 1058 1052 if (freeLC) -
src/builder.cpp
r8f215d ra7b761b 1744 1744 if (first->type != NULL) { 1745 1745 mol->AddAtom(first); // add to molecule 1746 if ((configPresent == empty) && (mol-> AtomCount!= 0))1746 if ((configPresent == empty) && (mol->getAtomCount() != 0)) 1747 1747 configPresent = present; 1748 1748 } else … … 1773 1773 DoLog(1) && (Log() << Verbose(1) << "Depth-First-Search Analysis." << endl); 1774 1774 MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis 1775 int *MinimumRingSize = new int[mol-> AtomCount];1775 int *MinimumRingSize = new int[mol->getAtomCount()]; 1776 1776 atom ***ListOfLocalAtoms = NULL; 1777 1777 class StackClass<bond *> *BackEdgeStack = NULL; … … 1921 1921 int counter = 0; 1922 1922 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())) { 1924 1924 Boundary = *BigFinder; 1925 1925 } … … 1980 1980 performCriticalExit(); 1981 1981 } else { 1982 mol->getAtomCount(); 1982 1983 SaveFlag = true; 1983 1984 DoLog(1) && (Log() << Verbose(1) << "Changing atom " << argv[argptr] << " to element " << argv[argptr+1] << "." << endl); … … 2098 2099 int counter = 0; 2099 2100 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())) { 2102 2102 Boundary = *BigFinder; 2103 2103 } 2104 2104 counter++; 2105 2105 } 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); 2107 2107 start = clock(); 2108 2108 LCList = new LinkedCell(Boundary, atof(argv[argptr])*2.); … … 2180 2180 double tmp1 = atof(argv[argptr+1]); 2181 2181 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 } 2190 2190 } 2191 2191 } else { … … 2332 2332 performCriticalExit(); 2333 2333 } else { 2334 mol->getAtomCount(); 2334 2335 SaveFlag = true; 2335 2336 DoLog(1) && (Log() << Verbose(1) << "Removing atom " << argv[argptr] << "." << endl); … … 2451 2452 faktor = 1; 2452 2453 } 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 2456 2456 Elements = new const element *[count]; 2457 2457 vectors = new Vector *[count]; 2458 2458 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; 2464 2462 j++; 2465 2463 } … … 2556 2554 int main(int argc, char **argv) 2557 2555 { 2556 // while we are non interactive, we want to abort from asserts 2557 //ASSERT_DO(Assert::Abort); 2558 2558 molecule *mol = NULL; 2559 2559 config *configuration = new config; … … 2595 2595 } 2596 2596 2597 // In the interactive mode, we can leave the user the choice in case of error 2598 ASSERT_DO(Assert::Ask); 2599 2597 2600 { 2598 2601 cout << ESPACKVersion << endl; -
src/config.cpp
r8f215d ra7b761b 1547 1547 int AtomNo = -1; 1548 1548 int MolNo = 0; 1549 atom *Walker = NULL;1550 1549 FILE *f = NULL; 1551 1550 … … 1560 1559 fprintf(f, "# Created by MoleCuilder\n"); 1561 1560 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++) { 1564 1562 int *elementNo = Calloc<int>(MAX_ELEMENTS, "config::SavePDB - elementNo"); 1565 1563 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 1570 1567 fprintf(f, 1571 1568 "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 */ 1573 1570 name, /* atom name */ 1574 (* Runner)->name, /* residue name */1571 (*MolRunner)->name, /* residue name */ 1575 1572 'a'+(unsigned char)(AtomNo % 26), /* letter for chain */ 1576 1573 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 */ 1582 1579 "0", /* segment identifier */ 1583 Walker->type->symbol, /* element symbol */1580 (*iter)->type->symbol, /* element symbol */ 1584 1581 "0"); /* charge */ 1585 1582 AtomNo++; … … 1601 1598 { 1602 1599 int AtomNo = -1; 1603 atom *Walker = NULL;1604 1600 FILE *f = NULL; 1605 1601 … … 1616 1612 fprintf(f, "# Created by MoleCuilder\n"); 1617 1613 1618 Walker = mol->start;1619 1614 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 1624 1618 fprintf(f, 1625 1619 "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 */ 1627 1621 name, /* atom name */ 1628 1622 mol->name, /* residue name */ 1629 1623 'a'+(unsigned char)(AtomNo % 26), /* letter for chain */ 1630 1624 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 */ 1636 1630 "0", /* segment identifier */ 1637 Walker->type->symbol, /* element symbol */1631 (*iter)->type->symbol, /* element symbol */ 1638 1632 "0"); /* charge */ 1639 1633 AtomNo++; … … 1653 1647 bool config::SaveTREMOLO(const char * const filename, const molecule * const mol) const 1654 1648 { 1655 atom *Walker = NULL;1656 1649 ofstream *output = NULL; 1657 1650 stringstream * const fname = new stringstream; … … 1666 1659 1667 1660 // scan maximum number of neighbours 1668 Walker = mol->start;1669 1661 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(); 1673 1664 if (MaxNeighbours < count) 1674 1665 MaxNeighbours = count; 1675 1666 } 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"; 1683 1672 *output << mol->name << "\t"; 1684 1673 *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++) 1691 1680 *output << "-\t"; 1692 1681 *output << endl; … … 1708 1697 bool config::SaveTREMOLO(const char * const filename, const MoleculeListClass * const MolList) const 1709 1698 { 1710 atom *Walker = NULL;1711 1699 ofstream *output = NULL; 1712 1700 stringstream * const fname = new stringstream; … … 1723 1711 int MaxNeighbours = 0; 1724 1712 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(); 1729 1715 if (MaxNeighbours < count) 1730 1716 MaxNeighbours = count; 1731 1717 } 1732 1718 } 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; 1734 1720 1735 1721 // create global to local id map … … 1752 1738 int AtomNo = 0; 1753 1739 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) { 1757 1741 *output << AtomNo+1 << "\t"; 1758 *output << Walker->getName() << "\t";1742 *output << (*iter)->getName() << "\t"; 1759 1743 *output << (*MolWalker)->name << "\t"; 1760 1744 *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++) 1767 1751 *output << "-\t"; 1768 1752 *output << endl; -
src/helpers.hpp
r8f215d ra7b761b 83 83 }; 84 84 85 /** Creates a lookup table for true father's Atom::Nr -> atom ptr.86 * \param *start begin of chain list87 * \paran *end end of chain list88 * \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 - failure91 */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 them104 if (count == 0) {105 Walker = start;106 while (Walker->next != end) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron107 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 fill117 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 lateron125 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 141 85 /** Frees a two-dimensional array. 142 86 * \param *ptr pointer to array -
src/lists.hpp
r8f215d ra7b761b 134 134 }; 135 135 136 /** Returns the first marker in a chain list.137 * \param *me one arbitrary item in chain list138 * \return poiner to first marker139 */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 list150 * \return poiner to last marker151 */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 160 136 #endif /* LISTS_HPP_ */ -
src/molecule.cpp
r8f215d ra7b761b 35 35 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero. 36 36 */ 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),37 molecule::molecule(const periodentafel * const teil) : elemente(teil), 38 first(new bond(0, 0, 1, -1)), last(new bond(0, 0, 1, -1)), MDSteps(0), 39 39 BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.), 40 40 ActiveFlag(false), IndexNr(-1), 41 41 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 { 50 44 // init bond chain list 51 45 link(first,last); … … 69 63 delete(first); 70 64 delete(last); 71 end->getWorld()->destroyAtom(end);72 start->getWorld()->destroyAtom(start);73 65 }; 74 66 … … 81 73 const std::string molecule::getName(){ 82 74 return std::string(name); 75 } 76 77 int molecule::getAtomCount() const{ 78 return *AtomCount; 83 79 } 84 80 … … 104 100 stringstream sstr; 105 101 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()]++; 108 104 } 109 105 std::map<atomicNumber_t,unsigned int>::reverse_iterator iter; … … 115 111 } 116 112 113 /************************** Access to the List of Atoms ****************/ 114 115 116 molecule::iterator molecule::begin(){ 117 return molecule::iterator(atoms.begin(),this); 118 } 119 120 molecule::const_iterator molecule::begin() const{ 121 return atoms.begin(); 122 } 123 124 molecule::iterator molecule::end(){ 125 return molecule::iterator(atoms.end(),this); 126 } 127 128 molecule::const_iterator molecule::end() const{ 129 return atoms.end(); 130 } 131 132 bool molecule::empty() const 133 { 134 return (begin() == end()); 135 } 136 137 size_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 145 molecule::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 153 molecule::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 164 molecule::const_iterator molecule::find ( atom *& key ) const 165 { 166 return atoms.find( key ); 167 } 168 169 pair<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 } 117 174 118 175 /** Adds given atom \a *pointer from molecule list. … … 123 180 bool molecule::AddAtom(atom *pointer) 124 181 { 125 bool retval = false;126 182 OBSERVE; 127 183 if (pointer != NULL) { 128 184 pointer->sort = &pointer->nr; 129 pointer->nr = last_atom++; // increase number within molecule130 AtomCount++;131 185 if (pointer->type != NULL) { 132 186 if (ElementsInMolecule[pointer->type->Z] == 0) … … 141 195 } 142 196 } 143 retval = add(pointer, end);144 } 145 return retval;197 insert(pointer); 198 } 199 return true; 146 200 }; 147 201 … … 157 211 if (pointer != NULL) { 158 212 atom *walker = pointer->clone(); 159 stringstream sstr; 160 sstr << pointer->getName(); 161 walker->setName(sstr.str()); 213 walker->setName(pointer->getName()); 162 214 walker->nr = last_atom++; // increase number within molecule 163 add(walker, end);215 insert(walker); 164 216 if ((pointer->type != NULL) && (pointer->type->Z != 1)) 165 217 NoNonHydrogen++; 166 AtomCount++;167 218 retval=walker; 168 219 } … … 574 625 575 626 // copy values 576 copy->CountAtoms();577 627 copy->CountElements(); 578 628 if (first->next != last) { // if adjaceny list is present … … 609 659 { 610 660 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 621 675 return Binder; 622 676 }; … … 692 746 bool molecule::RemoveAtom(atom *pointer) 693 747 { 748 ASSERT(pointer, "Null pointer passed to molecule::RemoveAtom()."); 749 OBSERVE; 694 750 if (ElementsInMolecule[pointer->type->Z] != 0) { // this would indicate an error 695 751 ElementsInMolecule[pointer->type->Z]--; // decrease number of atom of this element 696 AtomCount--;697 752 } else 698 753 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); … … 700 755 ElementCount--; 701 756 RemoveBonds(pointer); 702 return remove(pointer, start, end); 757 erase(pointer); 758 return true; 703 759 }; 704 760 … … 717 773 if (ElementsInMolecule[pointer->type->Z] == 0) // was last atom of this element? 718 774 ElementCount--; 719 unlink(pointer);775 erase(pointer); 720 776 return true; 721 777 }; … … 726 782 bool molecule::CleanupMolecule() 727 783 { 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)); 729 787 }; 730 788 … … 733 791 * \return pointer to atom or NULL 734 792 */ 735 atom * molecule::FindAtom(int Nr) const{ 736 atom * walker = find(&Nr, start,end); 737 if (walker != NULL) { 793 atom * 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()) { 738 800 //Log() << Verbose(0) << "Found Atom Nr. " << walker->nr << endl; 739 return walker;801 return (*iter); 740 802 } else { 741 803 DoLog(0) && (Log() << Verbose(0) << "Atom not found in list." << endl); … … 867 929 now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time' 868 930 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); 870 932 ActOnAllAtoms( &atom::OutputTrajectoryXYZ, output, step ); 871 933 } … … 884 946 if (output != NULL) { 885 947 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); 887 949 ActOnAllAtoms( &atom::OutputXYZLine, output ); 888 950 return true; … … 894 956 * \param *out output stream for debugging 895 957 */ 896 void molecule::CountAtoms() 897 { 958 int molecule::doCountAtoms() 959 { 960 int res = size(); 898 961 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; 902 971 i++; 903 972 } 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; 927 974 }; 928 975 … … 986 1033 /// first count both their atoms and elements and update lists thereby ... 987 1034 //Log() << Verbose(0) << "Counting atoms, updating list" << endl; 988 CountAtoms();989 OtherMolecule->CountAtoms();990 1035 CountElements(); 991 1036 OtherMolecule->CountElements(); … … 994 1039 /// -# AtomCount 995 1040 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); 998 1043 result = false; 999 } else Log() << Verbose(4) << "AtomCounts match: " << AtomCount << " == " << OtherMolecule->AtomCount<< endl;1044 } else Log() << Verbose(4) << "AtomCounts match: " << getAtomCount() << " == " << OtherMolecule->getAtomCount() << endl; 1000 1045 } 1001 1046 /// -# ElementCount … … 1034 1079 if (result) { 1035 1080 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"); 1038 1083 SetIndexedArrayForEachAtomTo ( Distances, &atom::nr, &atom::DistanceSquaredToVector, (const Vector &)CenterOfGravity); 1039 1084 SetIndexedArrayForEachAtomTo ( OtherDistances, &atom::nr, &atom::DistanceSquaredToVector, (const Vector &)CenterOfGravity); … … 1041 1086 /// ... sort each list (using heapsort (o(N log N)) from GSL) 1042 1087 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"); 1048 1093 DoLog(5) && (Log() << Verbose(5) << "Combining Permutation Maps" << endl); 1049 for(int i= AtomCount;i--;)1094 for(int i=getAtomCount();i--;) 1050 1095 PermutationMap[PermMap[i]] = (int) OtherPermMap[i]; 1051 1096 … … 1053 1098 DoLog(4) && (Log() << Verbose(4) << "Comparing distances" << endl); 1054 1099 flag = 0; 1055 for (int i=0;i< AtomCount;i++) {1100 for (int i=0;i<getAtomCount();i++) { 1056 1101 DoLog(5) && (Log() << Verbose(5) << "Distances squared: |" << Distances[PermMap[i]] << " - " << OtherDistances[OtherPermMap[i]] << "| = " << fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) << " ?<? " << threshold << endl); 1057 1102 if (fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) > threshold*threshold) … … 1089 1134 int * molecule::GetFatherSonAtomicMap(molecule *OtherMolecule) 1090 1135 { 1091 atom *Walker = NULL, *OtherWalker = NULL;1092 1136 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--;) 1095 1139 AtomicMap[i] = -1; 1096 1140 if (OtherMolecule == this) { // same molecule 1097 for (int i= AtomCount;i--;) // no need as -1 means already that there is trivial correspondence1141 for (int i=getAtomCount();i--;) // no need as -1 means already that there is trivial correspondence 1098 1142 AtomicMap[i] = i; 1099 1143 DoLog(4) && (Log() << Verbose(4) << "Map is trivial." << endl); 1100 1144 } else { 1101 1145 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; 1107 1149 } 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) { 1111 1151 //for (int i=0;i<AtomCount;i++) { // search atom 1112 1152 //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; 1116 1156 } 1117 1157 } 1118 DoLog(0) && (Log() << Verbose(0) << AtomicMap[ Walker->nr] << "\t");1158 DoLog(0) && (Log() << Verbose(0) << AtomicMap[(*iter)->nr] << "\t"); 1119 1159 } 1120 1160 DoLog(0) && (Log() << Verbose(0) << endl); … … 1150 1190 void molecule::SetIndexedArrayForEachAtomTo ( atom **array, int ParticleInfo::*index) const 1151 1191 { 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); 1156 1194 } 1157 1195 }; -
src/molecule.hpp
r8f215d ra7b761b 34 34 #include "tesselation.hpp" 35 35 #include "Patterns/Observer.hpp" 36 #include "Patterns/ObservedIterator.hpp" 36 37 #include "Patterns/Cacheable.hpp" 37 38 … … 88 89 friend molecule *NewMolecule(); 89 90 friend void DeleteMolecule(molecule *); 91 90 92 public: 93 typedef std::set<atom*> atomSet; 94 typedef ObservedIterator<atomSet> iterator; 95 typedef atomSet::const_iterator const_iterator; 96 91 97 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 94 101 bond *first; //!< start of bond list 95 102 bond *last; //!< end of bond list 96 103 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() 98 105 int BondCount; //!< number of atoms, brought up-to-date by CountBonds() 99 106 int ElementCount; //!< how many unique elements are therein … … 110 117 private: 111 118 Cacheable<string> formula; 119 Cacheable<int> AtomCount; 112 120 moleculeId_t id; 121 atomSet atoms; //<!set of atoms 113 122 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 114 131 molecule(const periodentafel * const teil); 115 132 virtual ~molecule(); … … 119 136 //getter and setter 120 137 const std::string getName(); 138 int getAtomCount() const; 139 int doCountAtoms(); 121 140 moleculeId_t getId(); 122 141 void setId(moleculeId_t); … … 125 144 std::string calcFormula(); 126 145 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 127 157 128 158 // re-definition of virtual functions from PointCloud … … 130 160 Vector *GetCenter() const ; 131 161 TesselPoint *GetPoint() const ; 132 TesselPoint *GetTerminalPoint() const ;133 162 int GetMaxId() const; 134 163 void GoToNext() const ; 135 void GoToPrevious() const ;136 164 void GoToFirst() const ; 137 void GoToLast() const ;138 165 bool IsEmpty() const ; 139 166 bool IsEnd() const ; … … 230 257 231 258 /// Count and change present atoms' coordination. 232 void CountAtoms();233 259 void CountElements(); 234 260 void CalculateOrbitals(class config &configuration); … … 299 325 bool StoreForcesFile(MoleculeListClass *BondFragments, char *path, int *SortIndex); 300 326 bool CreateMappingLabelsToConfigSequence(int *&SortIndex); 327 bool CreateFatherLookupTable(atom **&LookupTable, int count = 0); 301 328 void BreadthFirstSearchAdd(molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem); 302 329 /// -# BOSSANOVA … … 327 354 private: 328 355 int last_atom; //!< number given to last atom 329 mutable atom *InternalPointer; //!< internal pointer for PointCloud356 mutable internal_iterator InternalPointer; //!< internal pointer for PointCloud 330 357 }; 331 358 -
src/molecule_dynamics.cpp
r8f215d ra7b761b 28 28 gsl_matrix *A = gsl_matrix_alloc(NDIM,NDIM); 29 29 gsl_vector *x = gsl_vector_alloc(NDIM); 30 atom * Runner = mol->start;31 30 atom *Sprinter = NULL; 32 31 Vector trajectory1, trajectory2, normal, TestVector; 33 32 double Norm1, Norm2, tmp, result = 0.; 34 33 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++) 38 36 break; 39 37 // determine normalized trajectories direction vector (n1, n2) … … 42 40 trajectory1.Normalize(); 43 41 Norm1 = trajectory1.Norm(); 44 Sprinter = Params.PermutationMap[ Runner->nr]; // find second target point45 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); 46 44 trajectory2.Normalize(); 47 45 Norm2 = trajectory1.Norm(); 48 46 // check whether either is zero() 49 47 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)); 51 49 } else if (Norm1 < MYEPSILON) { 52 50 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); 54 52 trajectory2 *= trajectory1.ScalarProduct(trajectory2); // trajectory2 is scaled to unity, hence we don't need to divide by anything 55 53 trajectory1 -= trajectory2; // project the part in norm direction away 56 54 tmp = trajectory1.Norm(); // remaining norm is distance 57 55 } else if (Norm2 < MYEPSILON) { 58 Sprinter = Params.PermutationMap[ Runner->nr]; // find second target point56 Sprinter = Params.PermutationMap[(*iter)->nr]; // find second target point 59 57 trajectory2 = Sprinter->Trajectory.R.at(Params.endstep) - Walker->Trajectory.R.at(Params.startstep); // copy second offset 60 58 trajectory1 *= trajectory2.ScalarProduct(trajectory1); // trajectory1 is scaled to unity, hence we don't need to divide by anything … … 66 64 // Log() << Verbose(0) << " and "; 67 65 // 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)); 69 67 // Log() << Verbose(0) << " with distance " << tmp << "." << endl; 70 68 } 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 "; 72 70 // Log() << Verbose(0) << endl; 73 71 // Log() << Verbose(0) << "First Trajectory: "; … … 85 83 gsl_matrix_set(A, 1, i, trajectory2[i]); 86 84 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])); 88 86 } 89 87 // solve the linear system by Householder transformations … … 96 94 trajectory2.Scale(gsl_vector_get(x,1)); 97 95 normal.Scale(gsl_vector_get(x,2)); 98 TestVector = Runner->Trajectory.R.at(Params.startstep) + trajectory2 + normal96 TestVector = (*iter)->Trajectory.R.at(Params.startstep) + trajectory2 + normal 99 97 - (Walker->Trajectory.R.at(Params.startstep) + trajectory1); 100 98 if (TestVector.Norm() < MYEPSILON) { … … 125 123 { 126 124 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)) { 131 127 // 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 "; 133 129 // Log() << Verbose(0) << Sprinter->Trajectory.R.at(endstep); 134 130 // Log() << Verbose(0) << ", penalting." << endl; … … 161 157 // go through every atom 162 158 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) { 166 160 // first term: distance to target 167 Runner = Params.PermutationMap[ Walker->nr]; // find target point168 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))); 169 163 tmp *= Params.IsAngstroem ? 1. : 1./AtomicLengthToAngstroem; 170 164 result += Params.PenaltyConstants[0] * tmp; … … 172 166 173 167 // second term: sum of distances to other trajectories 174 result += SumDistanceOfTrajectories( Walker, this, Params);168 result += SumDistanceOfTrajectories((*iter), this, Params); 175 169 176 170 // third term: penalty for equal targets 177 result += PenalizeEqualTargets( Walker, this, Params);171 result += PenalizeEqualTargets((*iter), this, Params); 178 172 } 179 173 … … 213 207 void FillDistanceList(molecule *mol, struct EvaluatePotential &Params) 214 208 { 215 for (int i=mol-> AtomCount; i--;) {209 for (int i=mol->getAtomCount(); i--;) { 216 210 Params.DistanceList[i] = new DistanceMap; // is the distance sorted target list per atom 217 211 Params.DistanceList[i]->clear(); 218 212 } 219 213 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)) ); 228 217 } 229 218 } … … 237 226 void CreateInitialLists(molecule *mol, struct EvaluatePotential &Params) 238 227 { 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); 247 234 } 248 235 }; … … 285 272 void MakeInjectivePermutation(molecule *mol, struct EvaluatePotential &Params) 286 273 { 287 atom *Walker = mol->start;274 molecule::const_iterator iter = mol->begin(); 288 275 DistanceMap::iterator NewBase; 289 276 double Potential = fabs(mol->ConstrainedPotential(Params)); 290 277 278 if (mol->empty()) { 279 eLog() << Verbose(1) << "Molecule is empty." << endl; 280 return; 281 } 291 282 while ((Potential) > Params.PenaltyConstants[2]) { 292 PrintPermutationMap(mol-> AtomCount, Params);293 Walker = Walker->next;294 if ( Walker == mol->end) // round-robin at the end295 Walker = mol->start->next;296 if (Params.DoubleList[Params.DistanceIterators[ Walker->nr]->second->nr] <= 1) // no need to make those injective that aren't283 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 297 288 continue; 298 289 // 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 <=1290 Potential = TryNextNearestNeighbourForInjectivePermutation(mol, (*iter), Potential, Params); 291 } 292 for (int i=mol->getAtomCount(); i--;) // now each single entry in the DoubleList should be <=1 302 293 if (Params.DoubleList[i] > 1) { 303 294 DoeLog(0) && (eLog()<< Verbose(0) << "Failed to create an injective PermutationMap!" << endl); … … 338 329 double Potential, OldPotential, OlderPotential; 339 330 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"); 345 336 int round; 346 atom * Walker = NULL, *Runner = NULL, *Sprinter = NULL;337 atom *Sprinter = NULL; 347 338 DistanceMap::iterator Rider, Strider; 348 339 … … 371 362 DoLog(2) && (Log() << Verbose(2) << "Starting round " << ++round << ", at current potential " << OldPotential << " ... " << endl); 372 363 OlderPotential = OldPotential; 364 molecule::const_iterator iter; 373 365 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(); 383 374 break; 384 375 } 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; 386 377 // 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; 391 382 break; 392 383 } 393 Runner = Runner->next;394 384 } 395 if ( Runner != end) { // we found the other source385 if (runner != end()) { // we found the other source 396 386 // 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++) 399 389 if (Rider->second == Sprinter) 400 390 break; 401 if (Rider != Params.DistanceList[ Runner->nr]->end()) { // if we have found one402 //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; 403 393 // exchange both 404 Params.PermutationMap[ Walker->nr] = Params.DistanceIterators[Walker->nr]->second; // put next farther distance into PermutationMap405 Params.PermutationMap[ Runner->nr] = Sprinter; // and hand the old target to its respective owner406 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); 407 397 // calculate the new potential 408 398 //Log() << Verbose(2) << "Checking new potential ..." << endl; … … 410 400 if (Potential > OldPotential) { // we made everything worse! Undo ... 411 401 //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; 413 403 // 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; 415 405 // Undo for Walker 416 Params.DistanceIterators[ Walker->nr] = Strider; // take next farther distance target417 //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; 419 409 } else { 420 Params.DistanceIterators[ Runner->nr] = Rider; // if successful also move the pointer in the iterator list410 Params.DistanceIterators[(*runner)->nr] = Rider; // if successful also move the pointer in the iterator list 421 411 DoLog(3) && (Log() << Verbose(3) << "Found a better permutation, new potential is " << Potential << " vs." << OldPotential << "." << endl); 422 412 OldPotential = Potential; … … 428 418 //Log() << Verbose(0) << endl; 429 419 } 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); 431 421 exit(255); 432 422 } 433 423 } 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! 435 425 } 436 Params.StepList[ Walker->nr]++; // take next farther distance target426 Params.StepList[(*iter)->nr]++; // take next farther distance target 437 427 } 438 } while ( Walker->next != end);428 } while (++iter != end()); 439 429 } while ((OlderPotential - OldPotential) > 1e-3); 440 430 DoLog(1) && (Log() << Verbose(1) << "done." << endl); … … 442 432 443 433 /// free memory and return with evaluated potential 444 for (int i= AtomCount; i--;)434 for (int i=getAtomCount(); i--;) 445 435 Params.DistanceList[i]->clear(); 446 436 Free(&Params.DistanceList); … … 483 473 // Get the Permutation Map by MinimiseConstrainedPotential 484 474 atom **PermutationMap = NULL; 485 atom * Walker = NULL, *Sprinter = NULL;475 atom *Sprinter = NULL; 486 476 if (!MapByIdentity) 487 477 MinimiseConstrainedPotential(PermutationMap, startstep, endstep, configuration.GetIsAngstroem()); 488 478 else { 489 PermutationMap = Malloc<atom *>( AtomCount, "molecule::LinearInterpolationBetweenConfiguration: **PermutationMap");479 PermutationMap = Malloc<atom *>(getAtomCount(), "molecule::LinearInterpolationBetweenConfiguration: **PermutationMap"); 490 480 SetIndexedArrayForEachAtomTo( PermutationMap, &atom::nr ); 491 481 } … … 502 492 mol = World::getInstance().createMolecule(); 503 493 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) { 507 495 // add to molecule list 508 Sprinter = mol->AddCopyAtom( Walker);496 Sprinter = mol->AddCopyAtom((*iter)); 509 497 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); 511 499 // add to Trajectories 512 500 //Log() << Verbose(3) << step << ">=" << MDSteps-1 << endl; 513 501 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.; 517 505 } 518 506 } … … 522 510 523 511 // 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--; ) 526 514 SortIndex[i] = i; 527 515 status = MoleculePerStep->OutputConfigForListOfFragments(&configuration, SortIndex); … … 567 555 return false; 568 556 } 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); 571 559 performCriticalExit(); 572 560 return false; … … 574 562 // correct Forces 575 563 Velocity.Zero(); 576 for(int i=0;i< AtomCount;i++)564 for(int i=0;i<getAtomCount();i++) 577 565 for(int d=0;d<NDIM;d++) { 578 566 Velocity[d] += Force.Matrix[0][i][d+5]; 579 567 } 580 for(int i=0;i< AtomCount;i++)568 for(int i=0;i<getAtomCount();i++) 581 569 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()); 583 571 } 584 572 // solve a constrained potential if we are meant to … … 683 671 delta_alpha = 0.; 684 672 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); 686 674 configuration.alpha += delta_alpha*configuration.Deltat; 687 675 DoLog(3) && (Log() << Verbose(3) << "alpha = " << delta_alpha << " * " << configuration.Deltat << " = " << configuration.alpha << "." << endl); -
src/molecule_fragmentation.cpp
r8f215d ra7b761b 39 39 int FragmentCount; 40 40 // 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; 45 43 } 46 44 FragmentCount = NoNonHydrogen*(1 << (c*order)); … … 359 357 map<double, pair<int,int> > * ReMapAdaptiveCriteriaListToValue(map<int, pair<double,int> > *AdaptiveCriteriaList, molecule *mol) 360 358 { 361 atom *Walker = mol->start;359 atom *Walker = NULL; 362 360 map<double, pair<int,int> > *FinalRootCandidates = new map<double, pair<int,int> > ; 363 361 DoLog(1) && (Log() << Verbose(1) << "Root candidate list is: " << endl); … … 391 389 bool MarkUpdateCandidates(bool *AtomMask, map<double, pair<int,int> > &FinalRootCandidates, int Order, molecule *mol) 392 390 { 393 atom *Walker = mol->start;391 atom *Walker = NULL; 394 392 int No = -1; 395 393 bool status = false; … … 435 433 bool molecule::CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path) 436 434 { 437 atom *Walker = start;438 435 bool status = false; 439 436 440 437 // initialize mask list 441 for(int i= AtomCount;i--;)438 for(int i=getAtomCount();i--;) 442 439 AtomMask[i] = false; 443 440 444 441 if (Order < 0) { // adaptive increase of BondOrder per site 445 if (AtomMask[ AtomCount] == true) // break after one step442 if (AtomMask[getAtomCount()] == true) // break after one step 446 443 return false; 447 444 … … 457 454 if (AdaptiveCriteriaList->empty()) { 458 455 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) { 461 457 #ifdef ADDHYDROGEN 462 if ( Walker->type->Z != 1) // skip hydrogen458 if ((*iter)->type->Z != 1) // skip hydrogen 463 459 #endif 464 460 { 465 AtomMask[ Walker->nr] = true; // include all (non-hydrogen) atoms461 AtomMask[(*iter)->nr] = true; // include all (non-hydrogen) atoms 466 462 status = true; 467 463 } … … 478 474 Free(&FinalRootCandidates); 479 475 } 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) { 482 477 #ifdef ADDHYDROGEN 483 if ( Walker->type->Z != 1) // skip hydrogen478 if ((*iter)->type->Z != 1) // skip hydrogen 484 479 #endif 485 480 { 486 AtomMask[ Walker->nr] = true; // include all (non-hydrogen) atoms487 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])) 488 483 status = true; 489 484 } 490 485 } 491 if (( Order == 0) && (AtomMask[AtomCount] == false)) // single stepping, just check486 if ((!Order) && (!AtomMask[getAtomCount()])) // single stepping, just check 492 487 status = true; 493 488 … … 500 495 } 501 496 502 PrintAtomMask(AtomMask, AtomCount); // for debugging497 PrintAtomMask(AtomMask, getAtomCount()); // for debugging 503 498 504 499 return status; … … 516 511 return false; 517 512 } 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--;) 520 515 SortIndex[i] = -1; 521 516 … … 524 519 525 520 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 */ 532 bool 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; 526 574 }; 527 575 … … 548 596 MoleculeListClass *BondFragments = NULL; 549 597 int *SortIndex = NULL; 550 int *MinimumRingSize = new int[ AtomCount];598 int *MinimumRingSize = new int[getAtomCount()]; 551 599 int FragmentCounter; 552 600 MoleculeLeafClass *MolecularWalker = NULL; … … 576 624 577 625 // create lookup table for Atom::nr 578 FragmentationToDo = FragmentationToDo && CreateFatherLookupTable( start, end, ListOfAtoms, AtomCount);626 FragmentationToDo = FragmentationToDo && CreateFatherLookupTable(ListOfAtoms, getAtomCount()); 579 627 580 628 // === compare it with adjacency file === … … 586 634 587 635 // 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(); 590 638 MolecularWalker = Subgraphs; 591 639 FragmentCounter = 0; … … 624 672 // ===== 6b. prepare and go into the adaptive (Order<0), single-step (Order==0) or incremental (Order>0) cycle 625 673 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; 628 676 FragmentationToDo = false; // if CheckOrderAtSite just ones recommends fragmentation, we will save fragments afterwards 629 677 while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, configuration->configpath))) { 630 678 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() 632 680 // ===== 6b. fill RootStack for each subgraph (second adaptivity check) ===== 633 681 Subgraphs->next->FillRootStackForSubgraphs(RootStack, AtomMask, (FragmentCounter = 0)); … … 768 816 bool molecule::ParseOrderAtSiteFromFile(char *path) 769 817 { 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"); 772 820 bool status; 773 821 int AtomNr, value; … … 872 920 atom *OtherFather = NULL; 873 921 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();) { 879 928 LonelyFlag = true; 880 FatherOfRunner = Runner->father; 929 FatherOfRunner = (*iter)->father; 930 ASSERT(FatherOfRunner,"Atom without father found"); 881 931 if (SonList[FatherOfRunner->nr] != NULL) { // check if this, our father, is present in list 882 932 // create all bonds … … 889 939 // Log() << Verbose(3) << "Adding Bond: "; 890 940 // Log() << Verbose(0) << 891 Leaf->AddBond( Runner, SonList[OtherFather->nr], (*BondRunner)->BondDegree);941 Leaf->AddBond((*iter), SonList[OtherFather->nr], (*BondRunner)->BondDegree); 892 942 // Log() << Verbose(0) << "." << endl; 893 //NumBonds[ Runner->nr]++;943 //NumBonds[(*iter)->nr]++; 894 944 } else { 895 945 // Log() << Verbose(3) << "Not adding bond, labels in wrong order." << endl; … … 899 949 // Log() << Verbose(0) << ", who has no son in this fragment molecule." << endl; 900 950 #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)) 903 953 exit(1); 904 954 #endif 905 //NumBonds[ Runner->nr] += Binder->BondDegree;955 //NumBonds[(*iter)->nr] += Binder->BondDegree; 906 956 } 907 957 } 908 958 } 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; 914 965 #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 } 917 969 #endif 918 970 } … … 929 981 molecule * molecule::StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem) 930 982 { 931 atom **SonList = Calloc<atom*>( AtomCount, "molecule::StoreFragmentFromStack: **SonList");983 atom **SonList = Calloc<atom*>(getAtomCount(), "molecule::StoreFragmentFromStack: **SonList"); 932 984 molecule *Leaf = World::getInstance().createMolecule(); 933 985 … … 1556 1608 FragmentSearch.FragmentSet = new KeySet; 1557 1609 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--;) { 1560 1612 FragmentSearch.ShortestPathList[i] = -1; 1561 1613 } 1562 1614 1563 1615 // Construct the complete KeySet which we need for topmost level only (but for all Roots) 1564 atom *Walker = start;1565 1616 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); 1569 1619 } 1570 1620 … … 1577 1627 RootKeyNr = RootStack.front(); 1578 1628 RootStack.pop_front(); 1579 Walker = FindAtom(RootKeyNr);1629 atom *Walker = FindAtom(RootKeyNr); 1580 1630 // check cyclic lengths 1581 1631 //if ((MinimumRingSize[Walker->GetTrueFather()->nr] != -1) && (Walker->GetTrueFather()->AdaptiveOrder+1 > MinimumRingSize[Walker->GetTrueFather()->nr])) { … … 1664 1714 Vector Translationvector; 1665 1715 //class StackClass<atom *> *CompStack = NULL; 1666 class StackClass<atom *> *AtomStack = new StackClass<atom *>( AtomCount);1716 class StackClass<atom *> *AtomStack = new StackClass<atom *>(getAtomCount()); 1667 1717 bool flag = true; 1668 1718 1669 1719 DoLog(2) && (Log() << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl); 1670 1720 1671 ColorList = Calloc<enum Shading>( AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");1721 ColorList = Calloc<enum Shading>(getAtomCount(), "molecule::ScanForPeriodicCorrection: *ColorList"); 1672 1722 while (flag) { 1673 1723 // remove bonds that are beyond bonddistance … … 1701 1751 Log() << Verbose(0) << Translationvector << endl; 1702 1752 // apply to all atoms of first component via BFS 1703 for (int i= AtomCount;i--;)1753 for (int i=getAtomCount();i--;) 1704 1754 ColorList[i] = white; 1705 1755 AtomStack->Push(Binder->leftatom); -
src/molecule_geometry.cpp
r8f215d ra7b761b 69 69 70 70 // Log() << Verbose(3) << "Begin of CenterEdge." << endl; 71 atom *ptr = start->next; // start at first in list72 if ( ptr != end) {//list not empty?71 molecule::const_iterator iter = begin(); // start at first in list 72 if (iter != end()) { //list not empty? 73 73 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); 80 79 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); 83 82 } 84 83 } … … 104 103 { 105 104 int Num = 0; 106 atom *ptr = start; // start at first in list105 molecule::const_iterator iter = begin(); // start at first in list 107 106 108 107 Center.Zero(); 109 108 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 113 111 Num++; 114 Center += ptr->x;112 Center += (*iter)->x; 115 113 } 116 114 Center.Scale(-1./Num); // divide through total number (and sign for direction) … … 125 123 Vector * molecule::DetermineCenterOfAll() const 126 124 { 127 atom *ptr = start->next; // start at first in list125 molecule::const_iterator iter = begin(); // start at first in list 128 126 Vector *a = new Vector(); 129 127 Vector tmp; … … 132 130 a->Zero(); 133 131 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 137 134 Num += 1.; 138 tmp = ptr->x;135 tmp = (*iter)->x; 139 136 (*a) += tmp; 140 137 } … … 150 147 Vector * molecule::DetermineCenterOfGravity() 151 148 { 152 atom *ptr = start->next; // start at first in list149 molecule::const_iterator iter = begin(); // start at first in list 153 150 Vector *a = new Vector(); 154 151 Vector tmp; … … 157 154 a->Zero(); 158 155 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; 164 160 (*a) += tmp; 165 161 } … … 202 198 void molecule::Scale(const double ** const factor) 203 199 { 204 atom *ptr = start; 205 206 while (ptr->next != end) { 207 ptr = ptr->next; 200 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 208 201 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); 211 204 } 212 205 }; … … 217 210 void molecule::Translate(const Vector *trans) 218 211 { 219 atom *ptr = start; 220 221 while (ptr->next != end) { 222 ptr = ptr->next; 212 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 223 213 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); 226 216 } 227 217 }; … … 259 249 void molecule::DeterminePeriodicCenter(Vector ¢er) 260 250 { 261 atom *Walker = start;262 251 double * const cell_size = World::getInstance().getDomain(); 263 252 double *matrix = ReturnFullMatrixforSymmetric(cell_size); … … 270 259 Center.Zero(); 271 260 flag = true; 272 while (Walker->next != end) { 273 Walker = Walker->next; 261 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { 274 262 #ifdef ADDHYDROGEN 275 if ( Walker->type->Z != 1) {263 if ((*iter)->type->Z != 1) { 276 264 #endif 277 Testvector = Walker->x;265 Testvector = (*iter)->x; 278 266 Testvector.MatrixMultiplication(inversematrix); 279 267 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 nothing268 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 282 270 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]; 284 272 if ((fabs(tmp)) > BondDistance) { 285 273 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); 287 275 if (tmp > 0) 288 276 Translationvector[j] -= 1.; … … 298 286 #ifdef ADDHYDROGEN 299 287 // 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; 303 291 Testvector.MatrixMultiplication(inversematrix); 304 292 Testvector += Translationvector; … … 315 303 Free(&inversematrix); 316 304 317 Center.Scale(1./ (double)AtomCount);305 Center.Scale(1./static_cast<double>(getAtomCount())); 318 306 }; 319 307 … … 325 313 void molecule::PrincipalAxisSystem(bool DoRotate) 326 314 { 327 atom *ptr = start; // start at first in list328 315 double InertiaTensor[NDIM*NDIM]; 329 316 Vector *CenterOfGravity = DetermineCenterOfGravity(); … … 336 323 337 324 // 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; 341 327 //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]); 351 337 } 352 338 // print InertiaTensor for debugging … … 386 372 387 373 // 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]); 402 385 } 403 386 // print InertiaTensor for debugging … … 423 406 void molecule::Align(Vector *n) 424 407 { 425 atom *ptr = start;426 408 double alpha, tmp; 427 409 Vector z_axis; … … 434 416 alpha = atan(-n->at(0)/n->at(2)); 435 417 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]; 441 422 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]; 445 426 } 446 427 } … … 452 433 453 434 // rotate on z-y plane 454 ptr = start;455 435 alpha = atan(-n->at(1)/n->at(2)); 456 436 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]; 462 441 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]; 466 445 } 467 446 } … … 487 466 Vector a,b,c,d; 488 467 struct lsq_params *par = (struct lsq_params *)params; 489 atom *ptr = par->mol->start;490 468 491 469 // initialize vectors … … 497 475 b[2] = gsl_vector_get(x,5); 498 476 // 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; 503 480 t = c.ScalarProduct(b); // get direction parameter 504 481 d = t*b; // and create vector -
src/molecule_graph.cpp
r8f215d ra7b761b 19 19 #include "World.hpp" 20 20 #include "Helpers/fast_functions.hpp" 21 #include "Helpers/Assert.hpp" 22 21 23 22 24 struct BFSAccounting … … 74 76 flip(atom1, atom2); 75 77 Walker = FindAtom(atom1); 78 ASSERT(Walker,"Could not find an atom with the ID given in dbond file"); 76 79 OtherWalker = FindAtom(atom2); 80 ASSERT(OtherWalker,"Could not find an atom with the ID given in dbond file"); 77 81 AddBond(Walker, OtherWalker); //Add the bond between the two atoms with respective indices. 78 82 } … … 103 107 atom *Walker = NULL; 104 108 atom *OtherWalker = NULL; 105 atom **AtomMap = NULL;106 109 int n[NDIM]; 107 110 double MinDistance, MaxDistance; … … 128 131 129 132 // 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.)) { 134 136 DoLog(2) && (Log() << Verbose(2) << "Creating Linked Cell structure ... " << endl); 135 137 LC = new LinkedCell(this, bonddistance); … … 137 139 // create a list to map Tesselpoint::nr to atom * 138 140 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++; 144 146 } 145 147 … … 153 155 if (List != NULL) { 154 156 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; 157 160 // 3c. check for possible bond between each atom in this and every one in the 27 cells 158 161 for (n[0] = -1; n[0] <= 1; n[0]++) … … 164 167 for (LinkedCell::LinkedNodes::const_iterator OtherRunner = OtherList->begin(); OtherRunner != OtherList->end(); OtherRunner++) { 165 168 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; 170 172 (BG->*minmaxdistance)(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem); 173 const double distance = OtherWalker->x.PeriodicDistanceSquared(Walker->x,cell_size); 171 174 const bool status = (distance <= MaxDistance * MaxDistance) && (distance >= MinDistance * MinDistance); 172 175 // Log() << Verbose(1) << "MinDistance is " << MinDistance << " and MaxDistance is " << MaxDistance << "." << endl; … … 188 191 } 189 192 } 190 Free(&AtomMap);191 193 delete (LC); 192 194 DoLog(1) && (Log() << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl); … … 199 201 ActOnAllAtoms( &atom::OutputBondOfAtom ); 200 202 } 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); 202 204 DoLog(0) && (Log() << Verbose(0) << "End of CreateAdjacencyList." << endl); 203 205 if (free_BG) … … 241 243 DoLog(0) && (Log() << Verbose(0) << " done." << endl); 242 244 } 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); 244 246 } 245 247 DoLog(0) && (Log() << Verbose(0) << No << " bonds could not be corrected." << endl); … … 461 463 void DepthFirstSearchAnalysis_Init(struct DFSAccounting &DFS, const molecule * const mol) 462 464 { 463 DFS.AtomStack = new StackClass<atom *> (mol-> AtomCount);465 DFS.AtomStack = new StackClass<atom *> (mol->getAtomCount()); 464 466 DFS.CurrentGraphNr = 0; 465 467 DFS.ComponentNumber = 0; … … 502 504 bond *Binder = NULL; 503 505 504 if ( AtomCount== 0)506 if (getAtomCount() == 0) 505 507 return SubGraphs; 506 508 DoLog(0) && (Log() << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl); 507 509 DepthFirstSearchAnalysis_Init(DFS, this); 508 510 509 DFS.Root = start->next;510 while (DFS.Root != end) { // if there any atoms at all511 for (molecule::const_iterator iter = begin(); iter != end();) { 512 DFS.Root = *iter; 511 513 // (1) mark all edges unused, empty stack, set atom->GraphNr = -1 for all 512 514 DFS.AtomStack->ClearStack(); … … 548 550 549 551 // 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 on553 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++; 554 556 } 555 557 } … … 854 856 if (MinRingSize != -1) { // if rings are present 855 857 // 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 861 862 Walker = Root; 862 863 863 864 //Log() << Verbose(1) << "---------------------------------------------------------------------------------------------------------" << endl; 864 CyclicStructureAnalysis_BFSToNextCycle(Root, Walker, MinimumRingSize, mol-> AtomCount);865 CyclicStructureAnalysis_BFSToNextCycle(Root, Walker, MinimumRingSize, mol->getAtomCount()); 865 866 866 867 } … … 892 893 int MinRingSize = -1; 893 894 894 InitializeBFSAccounting(BFS, AtomCount);895 InitializeBFSAccounting(BFS, getAtomCount()); 895 896 896 897 //Log() << Verbose(1) << "Back edge list - "; … … 1134 1135 CurrentBondsOfAtom = -1; // we count one too far due to line end 1135 1136 // parse into structure 1136 if ((AtomNr >= 0) && (AtomNr < AtomCount)) {1137 if ((AtomNr >= 0) && (AtomNr < getAtomCount())) { 1137 1138 Walker = ListOfAtoms[AtomNr]; 1138 1139 while (!line.eof()) … … 1313 1314 AddedAtomList[Root->nr] = Mol->AddCopyAtom(Root); 1314 1315 1315 BreadthFirstSearchAdd_Init(BFS, Root, BondOrder, AtomCount, AddedAtomList);1316 BreadthFirstSearchAdd_Init(BFS, Root, BondOrder, getAtomCount(), AddedAtomList); 1316 1317 1317 1318 // and go on ... Queue always contains all lightgray vertices … … 1369 1370 // fill parent list with sons 1370 1371 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); 1375 1374 // 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 }; 1381 1378 1382 1379 void BuildInducedSubgraph_Finalize(atom **&ParentList) … … 1389 1386 { 1390 1387 bool status = true; 1391 atom *Walker = NULL;1392 1388 atom *OtherAtom = NULL; 1393 1389 // check each entry of parent list and if ok (one-to-and-onto matching) create bonds 1394 1390 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)) { 1400 1394 status = false; 1401 1395 } 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)); 1404 1398 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); 1407 1401 } 1408 1402 } … … 1427 1421 bool status = true; 1428 1422 atom **ParentList = NULL; 1429 1430 1423 DoLog(2) && (Log() << Verbose(2) << "Begin of BuildInducedSubgraph." << endl); 1431 BuildInducedSubgraph_Init(ParentList, Father-> AtomCount);1424 BuildInducedSubgraph_Init(ParentList, Father->getAtomCount()); 1432 1425 BuildInducedSubgraph_FillParentList(this, Father, ParentList); 1433 1426 status = BuildInducedSubgraph_CreateBondsFromParent(this, Father, ParentList); -
src/molecule_pointcloud.cpp
r8f215d ra7b761b 8 8 #include "atom.hpp" 9 9 #include "config.hpp" 10 #include "info.hpp" 10 11 #include "memoryallocator.hpp" 11 12 #include "molecule.hpp" … … 31 32 }; 32 33 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. 35 37 */ 36 TesselPoint *molecule::GetPoint() const38 TesselPoint* molecule::GetPoint() const 37 39 { 38 if ((InternalPointer != start) && (InternalPointer != end)) 39 return InternalPointer; 40 else 41 return NULL; 40 Info FunctionInfo(__func__); 41 return (*InternalPointer); 42 42 }; 43 43 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. 62 46 */ 63 47 void molecule::GoToNext() const 64 48 { 65 if (InternalPointer != end) 66 InternalPointer = InternalPointer->next; 49 Info FunctionInfo(__func__); 50 if (InternalPointer != atoms.end()) 51 InternalPointer++; 67 52 }; 68 53 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. 79 56 */ 80 57 void molecule::GoToFirst() const 81 58 { 82 InternalPointer = start->next; 59 Info FunctionInfo(__func__); 60 InternalPointer = atoms.begin(); 83 61 }; 84 62 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. 94 65 */ 95 66 bool molecule::IsEmpty() const 96 67 { 97 return (start->next == end); 68 Info FunctionInfo(__func__); 69 return (empty()); 98 70 }; 99 71 100 /** Checks whether we are at the last atom101 * \return true - current atom is last one, false - is not last one72 /** PointCloud implementation of IsLast. 73 * Uses atoms and STL stuff. 102 74 */ 103 75 bool molecule::IsEnd() const 104 76 { 105 return (InternalPointer == end); 77 Info FunctionInfo(__func__); 78 return (InternalPointer == atoms.end()); 106 79 }; 80 81 int molecule::GetMaxId() const { 82 return getAtomCount(); 83 } -
src/molecule_template.hpp
r8f215d ra7b761b 24 24 template <typename res> void molecule::ActOnAllVectors( res (Vector::*f)() ) const 25 25 { 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)(); 30 28 } 31 29 }; 32 30 template <typename res> void molecule::ActOnAllVectors( res (Vector::*f)() const ) const 33 31 { 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)(); 38 34 } 39 35 }; … … 41 37 template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T), T t ) const 42 38 { 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); 47 41 } 48 42 }; 49 43 template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T) const, T t ) const 50 44 { 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); 55 47 } 56 48 }; 57 49 template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T&), T &t ) const 58 50 { 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); 63 53 } 64 54 }; 65 55 template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T&) const, T &t ) const 66 56 { 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); 71 59 } 72 60 }; … … 74 62 template <typename res, typename T, typename U> void molecule::ActOnAllVectors( res (Vector::*f)(T, U), T t, U u ) const 75 63 { 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); 80 66 } 81 67 }; 82 68 template <typename res, typename T, typename U> void molecule::ActOnAllVectors( res (Vector::*f)(T, U) const, T t, U u ) const 83 69 { 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); 88 72 } 89 73 }; … … 91 75 template <typename res, typename T, typename U, typename V> void molecule::ActOnAllVectors( res (Vector::*f)(T, U, V), T t, U u, V v) const 92 76 { 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); 97 79 } 98 80 }; 99 81 template <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 100 82 { 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); 105 85 } 106 86 }; … … 112 92 { 113 93 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)(); 118 96 } 119 97 return result; … … 122 100 { 123 101 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)(); 128 104 } 129 105 return result; … … 133 109 { 134 110 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); 139 113 } 140 114 return result; … … 143 117 { 144 118 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); 149 121 } 150 122 return result; … … 157 129 template <typename res> void molecule::ActWithEachAtom( res (molecule::*f)(atom *)) const 158 130 { 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)); 163 133 } 164 134 }; 165 135 template <typename res> void molecule::ActWithEachAtom( res (molecule::*f)(atom *) const) const 166 136 { 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)); 171 139 } 172 140 }; … … 177 145 template <typename res> void molecule::ActOnCopyWithEachAtom( res (molecule::*f)(atom *) , molecule *copy) const 178 146 { 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)); 183 149 } 184 150 }; 185 151 template <typename res> void molecule::ActOnCopyWithEachAtom( res (molecule::*f)(atom *) const, molecule *copy) const 186 152 { 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)); 191 155 } 192 156 }; … … 197 161 template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () ) const 198 162 { 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)); 204 166 } 205 167 }; 206 168 template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () const ) const 207 169 { 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)); 213 173 } 214 174 }; 215 175 template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const , molecule *copy, bool (atom::*condition) () ) const 216 176 { 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)); 222 180 } 223 181 }; 224 182 template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) () const ) const 225 183 { 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)); 231 187 } 232 188 }; … … 234 190 template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T), T t ) const 235 191 { 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)); 241 195 } 242 196 }; 243 197 template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T) const, T t ) const 244 198 { 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)); 250 202 } 251 203 }; 252 204 template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T), T t ) const 253 205 { 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)); 259 209 } 260 210 }; 261 211 template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T) const, T t ) const 262 212 { 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)); 268 216 } 269 217 }; … … 271 219 template <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 272 220 { 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)); 278 224 } 279 225 }; 280 226 template <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 281 227 { 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)); 287 231 } 288 232 }; 289 233 template <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 290 234 { 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)); 296 238 } 297 239 }; 298 240 template <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 299 241 { 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)); 305 245 } 306 246 }; … … 308 248 template <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 309 249 { 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)); 315 253 } 316 254 }; 317 255 template <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 318 256 { 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)); 324 260 } 325 261 }; 326 262 template <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 327 263 { 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)); 333 267 } 334 268 }; 335 269 template <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 336 270 { 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)); 342 274 } 343 275 }; … … 348 280 template <typename res, typename typ> void molecule::ActOnAllAtoms( res (typ::*f)()) const 349 281 { 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)(); 354 284 } 355 285 }; 356 286 template <typename res, typename typ> void molecule::ActOnAllAtoms( res (typ::*f)() const) const 357 287 { 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)(); 362 290 } 363 291 }; … … 365 293 template <typename res, typename typ, typename T> void molecule::ActOnAllAtoms( res (typ::*f)(T), T t ) const 366 294 { 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); 371 297 } 372 298 }; 373 299 template <typename res, typename typ, typename T> void molecule::ActOnAllAtoms( res (typ::*f)(T) const, T t ) const 374 300 { 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); 379 303 } 380 304 }; … … 382 306 template <typename res, typename typ, typename T, typename U> void molecule::ActOnAllAtoms( res (typ::*f)(T, U), T t, U u ) const 383 307 { 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); 388 310 } 389 311 }; 390 312 template <typename res, typename typ, typename T, typename U> void molecule::ActOnAllAtoms( res (typ::*f)(T, U) const, T t, U u ) const 391 313 { 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); 396 316 } 397 317 }; … … 399 319 template <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 400 320 { 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); 405 323 } 406 324 }; 407 325 template <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 408 326 { 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); 413 329 } 414 330 }; … … 416 332 template <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 417 333 { 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); 422 336 } 423 337 }; 424 338 template <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 425 339 { 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); 430 342 } 431 343 }; … … 436 348 template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *) ) const 437 349 { 438 atom *Walker = start;439 350 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); 443 353 } 444 354 }; 445 355 template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *), T value ) const 446 356 { 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); 451 359 } 452 360 }; 453 361 template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *), T *value ) const 454 362 { 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); 459 365 } 460 366 }; … … 462 368 template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *) ) const 463 369 { 464 atom *Walker = start;465 370 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); 469 373 } 470 374 }; 471 375 template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *), T value ) const 472 376 { 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); 477 379 } 478 380 }; 479 381 template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *), T *value ) const 480 382 { 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); 485 385 } 486 386 }; … … 488 388 template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &), typ atom::*value ) const 489 389 { 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); 494 392 } 495 393 }; 496 394 template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &) const, typ atom::*value ) const 497 395 { 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); 502 398 } 503 399 }; 504 400 template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &), typ &vect ) const 505 401 { 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); 510 404 } 511 405 }; 512 406 template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &) const, typ &vect ) const 513 407 { 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); 518 410 } 519 411 }; 520 412 template <typename T, typename typ, typename typ2> void molecule::SetAtomValueToIndexedArray ( T *array, int typ::*index, T typ2::*value ) const 521 413 { 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; 527 417 } 528 418 }; … … 530 420 template <typename T, typename typ> void molecule::SetAtomValueToValue ( T value, T typ::*ptr ) const 531 421 { 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; 537 425 } 538 426 }; -
src/moleculelist.cpp
r8f215d ra7b761b 20 20 #include "memoryallocator.hpp" 21 21 #include "periodentafel.hpp" 22 #include " World.hpp"22 #include "Helpers/Assert.hpp" 23 23 24 24 /*********************************** Functions for class MoleculeListClass *************************/ … … 69 69 int Count, Counter, aCounter, bCounter; 70 70 int flag; 71 atom *aWalker = NULL;72 atom *bWalker = NULL;73 71 74 72 // sort each atom list and put the numbers into a list, then go through 75 73 //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()) { 77 80 return -1; 78 81 } else { 79 if ( (**(molecule **) a).AtomCount > (**(molecule **) b).AtomCount)82 if (mol1->getAtomCount() > mol2->getAtomCount()) 80 83 return +1; 81 84 else { 82 Count = (**(molecule **) a).AtomCount;85 Count = mol1->getAtomCount(); 83 86 aList = new int[Count]; 84 87 bList = new int[Count]; 85 88 86 89 // fill the lists 87 aWalker = (**(molecule **) a).start;88 bWalker = (**(molecule **) b).start;89 90 Counter = 0; 90 91 aCounter = 0; 91 92 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) 96 98 aList[Counter] = Count + (aCounter++); 97 99 else 98 aList[Counter] = aWalker->GetTrueFather()->nr;99 if ( bWalker->GetTrueFather() == NULL)100 aList[Counter] = (*aiter)->GetTrueFather()->nr; 101 if ((*biter)->GetTrueFather() == NULL) 100 102 bList[Counter] = Count + (bCounter++); 101 103 else 102 bList[Counter] = bWalker->GetTrueFather()->nr;104 bList[Counter] = (*biter)->GetTrueFather()->nr; 103 105 Counter++; 104 106 } 105 107 // check if AtomCount was for real 106 108 flag = 0; 107 if ((a Walker->next == (**(molecule **) a).end) && (bWalker->next != (**(molecule **) b).end)) {109 if ((aiter == mol1->end()) && (biter != mol2->end())) { 108 110 flag = -1; 109 111 } else { 110 if ((a Walker->next != (**(molecule **) a).end) && (bWalker->next == (**(molecule **) b).end))112 if ((aiter != mol1->end()) && (biter == mol2->end())) 111 113 flag = 1; 112 114 } … … 142 144 void MoleculeListClass::Enumerate(ostream *out) 143 145 { 144 atom *Walker = NULL;145 146 periodentafel *periode = World::getInstance().getPeriode(); 146 147 std::map<atomicNumber_t,unsigned int> counts; … … 158 159 // count atoms per element and determine size of bounding sphere 159 160 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); 166 165 } 167 166 // 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"; 169 168 170 169 std::map<atomicNumber_t,unsigned int>::reverse_iterator iter; … … 202 201 203 202 // 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)); 211 208 } 212 209 … … 228 225 229 226 // 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)); 236 230 Walker->father = Walker; 237 231 } … … 330 324 331 325 // 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++) 335 328 CopyAtoms[i] = NULL; 336 329 337 330 // for each of the source atoms check whether we are in- or outside and add copy atom 338 atom *Walker = srcmol->start;339 331 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]); 346 337 nr++; 347 338 } else { … … 349 340 } 350 341 } 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."); 352 343 353 344 // go through all bonds and add as well … … 382 373 bool MoleculeListClass::AddHydrogenCorrection(char *path) 383 374 { 384 atom *Walker = NULL;385 atom *Runner = NULL;386 375 bond *Binder = NULL; 387 376 double ***FitConstant = NULL, **correction = NULL; … … 488 477 correction[k][j] = 0.; 489 478 // 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; 500 485 // 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!) 503 488 // 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; 506 491 for (int k = 0; k < a; k++) { 507 492 for (int j = 0; j < b; j++) { … … 577 562 ofstream ForcesFile; 578 563 stringstream line; 579 atom *Walker = NULL;580 564 periodentafel *periode=World::getInstance().getPeriode(); 581 565 … … 590 574 periodentafel::const_iterator elemIter; 591 575 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 598 580 //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"; 600 582 } else 601 583 // otherwise a -1 to indicate an added saturation hydrogen … … 633 615 bool result = true; 634 616 bool intermediateResult = true; 635 atom *Walker = NULL;636 617 Vector BoxDimension; 637 618 char *FragmentNumber = NULL; … … 674 655 // list atoms in fragment for debugging 675 656 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() << " "); 680 659 } 681 660 DoLog(0) && (Log() << Verbose(0) << endl); … … 757 736 { 758 737 molecule *mol = World::getInstance().createMolecule(); 759 atom *Walker = NULL;760 atom *Advancer = NULL;761 738 bond *Binder = NULL; 762 739 bond *Stepper = NULL; … … 764 741 for (MoleculeList::iterator MolRunner = ListOfMolecules.begin(); !ListOfMolecules.empty(); MolRunner = ListOfMolecules.begin()) { 765 742 // 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); 774 748 } 775 749 // remove all bonds … … 825 799 // 4b. create and fill map of which atom is associated to which connected molecule (note, counting starts at 1) 826 800 int FragmentCounter = 0; 827 int *MolMap = Calloc<int>(mol-> AtomCount, "config::Load() - *MolMap");801 int *MolMap = Calloc<int>(mol->getAtomCount(), "config::Load() - *MolMap"); 828 802 MoleculeLeafClass *MolecularWalker = Subgraphs; 829 Walker = NULL;830 803 while (MolecularWalker->next != NULL) { 831 804 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; 836 807 } 837 808 FragmentCounter++; … … 839 810 840 811 // 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); 846 815 performCriticalExit(); 847 816 } 848 FragmentCounter = MolMap[ Walker->nr];817 FragmentCounter = MolMap[(*iter)->nr]; 849 818 if (FragmentCounter != 0) { 850 DoLog(3) && (Log() << Verbose(3) << "Re-linking " << * Walker << "..." << endl);851 unlink(Walker);852 mol ecules[FragmentCounter-1]->AddAtom(Walker); // counting starts at 1819 DoLog(3) && (Log() << Verbose(3) << "Re-linking " << **iter << "..." << endl); 820 molecules[FragmentCounter-1]->AddAtom((*iter)); // counting starts at 1 821 mol->erase(iter); 853 822 } 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); 855 824 performCriticalExit(); 856 825 } … … 860 829 while (mol->first->next != mol->last) { 861 830 Binder = mol->first->next; 862 Walker = Binder->leftatom;831 const atom * const Walker = Binder->leftatom; 863 832 unlink(Binder); 864 833 link(Binder,molecules[MolMap[Walker->nr]-1]->last); // counting starts at 1 … … 882 851 int MoleculeListClass::CountAllAtoms() const 883 852 { 884 atom *Walker = NULL;885 853 int AtomNo = 0; 886 854 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(); 892 856 } 893 857 return AtomNo; … … 1064 1028 bool MoleculeLeafClass::FillBondStructureFromReference(const molecule * const reference, int &FragmentCounter, atom ***&ListOfLocalAtoms, bool FreeList) 1065 1029 { 1066 atom *Walker = NULL;1067 1030 atom *OtherWalker = NULL; 1068 1031 atom *Father = NULL; … … 1072 1035 DoLog(1) && (Log() << Verbose(1) << "Begin of FillBondStructureFromReference." << endl); 1073 1036 // fill ListOfLocalAtoms if NULL was given 1074 if (!FillListOfLocalAtoms(ListOfLocalAtoms, FragmentCounter, reference-> AtomCount, FreeList)) {1037 if (!FillListOfLocalAtoms(ListOfLocalAtoms, FragmentCounter, reference->getAtomCount(), FreeList)) { 1075 1038 DoLog(1) && (Log() << Verbose(1) << "Filling of ListOfLocalAtoms failed." << endl); 1076 1039 return false; … … 1088 1051 } 1089 1052 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(); 1094 1055 AtomNo = Father->nr; // global id of the current walker 1095 1056 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 walker1057 OtherWalker = ListOfLocalAtoms[FragmentCounter][(*Runner)->GetOtherAtom((*iter)->GetTrueFather())->nr]; // local copy of current bond partner of walker 1097 1058 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); 1100 1061 } 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); 1102 1063 status = false; 1103 1064 } … … 1126 1087 bool MoleculeLeafClass::FillRootStackForSubgraphs(KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter) 1127 1088 { 1128 atom * Walker = NULL, *Father = NULL;1089 atom *Father = NULL; 1129 1090 1130 1091 if (RootStack != NULL) { … … 1132 1093 if (&(RootStack[FragmentCounter]) != NULL) { 1133 1094 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(); 1138 1097 if (AtomMask[Father->nr]) // apply mask 1139 1098 #ifdef ADDHYDROGEN 1140 if ( Walker->type->Z != 1) // skip hydrogen1099 if ((*iter)->type->Z != 1) // skip hydrogen 1141 1100 #endif 1142 RootStack[FragmentCounter].push_front( Walker->nr);1101 RootStack[FragmentCounter].push_front((*iter)->nr); 1143 1102 } 1144 1103 if (next != NULL) … … 1179 1138 1180 1139 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); 1182 1141 FreeList = FreeList && true; 1183 1142 } … … 1203 1162 DoLog(1) && (Log() << Verbose(1) << "Begin of AssignKeySetsToFragment." << endl); 1204 1163 // fill ListOfLocalAtoms if NULL was given 1205 if (!FillListOfLocalAtoms(ListOfLocalAtoms, FragmentCounter, reference-> AtomCount, FreeList)) {1164 if (!FillListOfLocalAtoms(ListOfLocalAtoms, FragmentCounter, reference->getAtomCount(), FreeList)) { 1206 1165 DoLog(1) && (Log() << Verbose(1) << "Filling of ListOfLocalAtoms failed." << endl); 1207 1166 return false; -
src/tesselation.cpp
r8f215d ra7b761b 21 21 #include "Plane.hpp" 22 22 #include "Exceptions/LinearDependenceException.hpp" 23 #include "Helpers/Assert.hpp" 24 23 25 #include "Helpers/Assert.hpp" 24 26 … … 358 360 // get ascending order of endpoints 359 361 PointMap OrderMap; 360 for (int i = 0; i < 3; i++) 362 for (int i = 0; i < 3; i++) { 361 363 // for all three lines 362 364 for (int j = 0; j < 2; j++) { // for both endpoints … … 364 366 // and we don't care whether insertion fails 365 367 } 368 } 366 369 // set endpoints 367 370 int Counter = 0; … … 372 375 Counter++; 373 376 } 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 380 380 381 381 /** Destructor of BoundaryTriangleSet. … … 1232 1232 ; 1233 1233 1234 /** PointCloud implementation of GetTerminalPoint.1235 * Uses PointsOnBoundary and STL stuff.1236 */1237 TesselPoint * Tesselation::GetTerminalPoint() const1238 {1239 Info FunctionInfo(__func__);1240 PointMap::const_iterator Runner = PointsOnBoundary.end();1241 Runner--;1242 return (Runner->second->node);1243 }1244 ;1245 1246 1234 /** PointCloud implementation of GoToNext. 1247 1235 * Uses PointsOnBoundary and STL stuff. … … 1255 1243 ; 1256 1244 1257 /** PointCloud implementation of GoToPrevious.1258 * Uses PointsOnBoundary and STL stuff.1259 */1260 void Tesselation::GoToPrevious() const1261 {1262 Info FunctionInfo(__func__);1263 if (InternalPointer != PointsOnBoundary.begin())1264 InternalPointer--;1265 }1266 ;1267 1268 1245 /** PointCloud implementation of GoToFirst. 1269 1246 * Uses PointsOnBoundary and STL stuff. … … 1273 1250 Info FunctionInfo(__func__); 1274 1251 InternalPointer = PointsOnBoundary.begin(); 1275 }1276 ;1277 1278 /** PointCloud implementation of GoToLast.1279 * Uses PointsOnBoundary and STL stuff.1280 */1281 void Tesselation::GoToLast() const1282 {1283 Info FunctionInfo(__func__);1284 InternalPointer = PointsOnBoundary.end();1285 InternalPointer--;1286 1252 } 1287 1253 ; … … 2593 2559 // fill the set of neighbours 2594 2560 TesselPointSet SetOfNeighbours; 2561 2595 2562 SetOfNeighbours.insert(CandidateLine.BaseLine->endpoints[1]->node); 2596 2563 for (TesselPointList::iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); Runner++) -
src/tesselation.hpp
r8f215d ra7b761b 244 244 virtual Vector *GetCenter() const { return NULL; }; 245 245 virtual TesselPoint *GetPoint() const { return NULL; }; 246 virtual TesselPoint *GetTerminalPoint() const { return NULL; };247 246 virtual int GetMaxId() const { return 0; }; 248 247 virtual void GoToNext() const {}; 249 virtual void GoToPrevious() const {};250 248 virtual void GoToFirst() const {}; 251 virtual void GoToLast() const {};252 249 virtual bool IsEmpty() const { return true; }; 253 250 virtual bool IsEnd() const { return true; }; … … 363 360 virtual Vector *GetCenter(ofstream *out) const; 364 361 virtual TesselPoint *GetPoint() const; 365 virtual TesselPoint *GetTerminalPoint() const;366 362 virtual void GoToNext() const; 367 virtual void GoToPrevious() const;368 363 virtual void GoToFirst() const; 369 virtual void GoToLast() const;370 364 virtual bool IsEmpty() const; 371 365 virtual bool IsEnd() const; -
src/tesselationhelpers.cpp
r8f215d ra7b761b 838 838 int i=cloud->GetMaxId(); 839 839 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++){ 841 841 LookupList[i] = -1; 842 } 842 843 843 844 // print atom coordinates 844 845 int Counter = 1; 845 846 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) { 847 848 Walker = target->second->node; 848 849 LookupList[Walker->nr] = Counter++; -
src/unittests/AnalysisCorrelationToPointUnitTest.cpp
r8f215d ra7b761b 25 25 #include "periodentafel.hpp" 26 26 #include "tesselation.hpp" 27 #include "World.hpp"28 27 29 28 #ifdef HAVE_TESTRUNNER … … 80 79 81 80 // check that TestMolecule was correctly constructed 82 CPPUNIT_ASSERT_EQUAL( TestMolecule-> AtomCount, 4 );81 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 ); 83 82 84 83 TestList = World::getInstance().getMolecules(); -
src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
r8f215d ra7b761b 26 26 #include "tesselation.hpp" 27 27 #include "World.hpp" 28 #include "Helpers/Assert.hpp" 28 29 29 30 #include "Helpers/Assert.hpp" … … 40 41 void AnalysisCorrelationToSurfaceUnitTest::setUp() 41 42 { 42 //ASSERT_DO(Assert::Throw);43 ASSERT_DO(Assert::Throw); 43 44 44 45 atom *Walker = NULL; … … 71 72 // construct molecule (tetraeder of hydrogens) base 72 73 TestSurfaceMolecule = World::getInstance().createMolecule(); 74 73 75 Walker = World::getInstance().createAtom(); 74 76 Walker->type = hydrogen; 75 77 *Walker->node = Vector(1., 0., 1. ); 76 77 TestSurfaceMolecule->AddAtom(Walker); 78 TestSurfaceMolecule->AddAtom(Walker); 79 78 80 Walker = World::getInstance().createAtom(); 79 81 Walker->type = hydrogen; 80 82 *Walker->node = Vector(0., 1., 1. ); 81 83 TestSurfaceMolecule->AddAtom(Walker); 84 82 85 Walker = World::getInstance().createAtom(); 83 86 Walker->type = hydrogen; 84 87 *Walker->node = Vector(1., 1., 0. ); 85 88 TestSurfaceMolecule->AddAtom(Walker); 89 86 90 Walker = World::getInstance().createAtom(); 87 91 Walker->type = hydrogen; … … 90 94 91 95 // check that TestMolecule was correctly constructed 92 CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule-> AtomCount, 4 );96 CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->getAtomCount(), 4 ); 93 97 94 98 TestList = World::getInstance().getMolecules(); … … 107 111 *Walker->node = Vector(4., 0., 4. ); 108 112 TestSurfaceMolecule->AddAtom(Walker); 113 109 114 Walker = World::getInstance().createAtom(); 110 115 Walker->type = carbon; 111 116 *Walker->node = Vector(0., 4., 4. ); 112 117 TestSurfaceMolecule->AddAtom(Walker); 118 113 119 Walker = World::getInstance().createAtom(); 114 120 Walker->type = carbon; 115 121 *Walker->node = Vector(4., 4., 0. ); 116 122 TestSurfaceMolecule->AddAtom(Walker); 123 117 124 // add inner atoms 118 125 Walker = World::getInstance().createAtom(); … … 120 127 *Walker->node = Vector(0.5, 0.5, 0.5 ); 121 128 TestSurfaceMolecule->AddAtom(Walker); 129 122 130 TestSurfaceMolecule->ActiveFlag = true; 123 131 TestList->insert(TestSurfaceMolecule); … … 150 158 void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest() 151 159 { 152 CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule-> AtomCount);160 CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->getAtomCount() ); 153 161 CPPUNIT_ASSERT_EQUAL( (size_t)2, TestList->ListOfMolecules.size() ); 154 162 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() ); -
src/unittests/AnalysisPairCorrelationUnitTest.cpp
r8f215d ra7b761b 79 79 80 80 // check that TestMolecule was correctly constructed 81 CPPUNIT_ASSERT_EQUAL( TestMolecule-> AtomCount, 4 );81 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 ); 82 82 83 83 TestList = World::getInstance().getMolecules(); -
src/unittests/CountBondsUnitTest.cpp
r8f215d ra7b761b 102 102 103 103 // 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 ); 110 106 111 107 // create a small file with table -
src/unittests/LinkedCellUnitTest.cpp
r8f215d ra7b761b 69 69 70 70 // 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 ); 74 72 }; 75 73 … … 197 195 { 198 196 // 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) ); 203 199 } 204 200 205 201 // 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); 211 207 212 208 // 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); 218 214 }; 219 215 … … 287 283 size = ListOfPoints->size(); 288 284 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)); 294 288 size--; 295 289 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() ); … … 306 300 size=ListOfPoints->size(); 307 301 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); 313 305 size--; 314 306 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() ); … … 326 318 size=ListOfPoints->size(); 327 319 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); 332 322 size--; 333 323 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() ); … … 355 345 size = ListOfPoints->size(); 356 346 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); 362 350 size--; 363 351 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() ); -
src/unittests/ObserverTest.cpp
r8f215d ra7b761b 11 11 #include <cppunit/extensions/TestFactoryRegistry.h> 12 12 #include <cppunit/ui/text/TestRunner.h> 13 #include <set> 13 14 14 15 #include "Patterns/Observer.hpp" 16 #include "Patterns/ObservedIterator.hpp" 15 17 #include "Helpers/Assert.hpp" 16 18 … … 162 164 bool wasNotified; 163 165 }; 166 167 class ObservableCollection : public Observable { 168 public: 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 200 private: 201 set theSet; 202 }; 203 164 204 165 205 /******************* actuall tests ***************/ … … 173 213 blockObservable = new BlockObservable(); 174 214 notificationObservable = new NotificationObservable(); 215 collection = new ObservableCollection(5); 175 216 176 217 observer1 = new UpdateCountObserver(); … … 181 222 notificationObserver1 = new NotificationObserver(notificationObservable->notification1); 182 223 notificationObserver2 = new NotificationObserver(notificationObservable->notification2); 183 184 224 } 185 225 … … 191 231 delete blockObservable; 192 232 delete notificationObservable; 233 delete collection; 193 234 194 235 delete observer1; … … 277 318 blockObservable->changeMethod2(); 278 319 blockObservable->noChangeMethod(); 320 } 321 322 void 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); 279 354 } 280 355 -
src/unittests/ObserverTest.hpp
r8f215d ra7b761b 17 17 class CallObservable; 18 18 class SuperObservable; 19 class ObservableCollection; 19 20 class BlockObservable; 20 21 class NotificationObservable; 21 22 22 23 23 class ObserverTest : public CppUnit::TestFixture … … 29 29 CPPUNIT_TEST ( doesNotifyTest ); 30 30 CPPUNIT_TEST ( doesReportTest ); 31 CPPUNIT_TEST ( iteratorTest ); 31 32 CPPUNIT_TEST ( CircleDetectionTest ); 32 33 CPPUNIT_TEST_SUITE_END(); … … 41 42 void doesNotifyTest(); 42 43 void doesReportTest(); 44 void iteratorTest(); 43 45 void CircleDetectionTest(); 44 46 … … 58 60 SuperObservable *superObservable; 59 61 NotificationObservable *notificationObservable; 62 ObservableCollection *collection; 63 60 64 }; 61 65 -
src/unittests/analysisbondsunittest.cpp
r8f215d ra7b761b 25 25 #include "molecule.hpp" 26 26 #include "periodentafel.hpp" 27 #include "World.hpp" 27 28 28 29 #ifdef HAVE_TESTRUNNER … … 89 90 90 91 // check that TestMolecule was correctly constructed 91 CPPUNIT_ASSERT_EQUAL( TestMolecule-> AtomCount, 5 );92 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 5 ); 92 93 93 94 // create a small file with table -
src/unittests/bondgraphunittest.cpp
r8f215d ra7b761b 89 89 90 90 // check that TestMolecule was correctly constructed 91 CPPUNIT_ASSERT_EQUAL( TestMolecule-> AtomCount, 4 );91 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 ); 92 92 93 93 // create a small file with table … … 120 120 }; 121 121 122 /** Tests whether setup worked. 123 */ 124 void BondGraphTest::SetupTest() 125 { 126 CPPUNIT_ASSERT_EQUAL (false, TestMolecule->empty()); 127 CPPUNIT_ASSERT_EQUAL ((size_t)4, TestMolecule->size()); 128 }; 129 122 130 /** UnitTest for BondGraphTest::LoadBondLengthTable(). 123 131 */ … … 134 142 void BondGraphTest::ConstructGraphFromTableTest() 135 143 { 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++; 139 147 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) ); 140 148 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) ); 141 CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );149 CPPUNIT_ASSERT_EQUAL( true , (*Walker)->IsBondedTo((*Runner)) ); 142 150 }; 143 151 … … 146 154 void BondGraphTest::ConstructGraphFromCovalentRadiiTest() 147 155 { 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 ); 151 160 CPPUNIT_ASSERT_EQUAL( false , BG->LoadBondLengthTable(*dummyname) ); 152 161 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) ); 154 165 }; 155 166 -
src/unittests/bondgraphunittest.hpp
r8f215d ra7b761b 22 22 { 23 23 CPPUNIT_TEST_SUITE( BondGraphTest) ; 24 CPPUNIT_TEST ( SetupTest ); 24 25 CPPUNIT_TEST ( LoadTableTest ); 25 26 CPPUNIT_TEST ( ConstructGraphFromTableTest ); … … 30 31 void setUp(); 31 32 void tearDown(); 33 void SetupTest(); 32 34 void LoadTableTest(); 33 35 void ConstructGraphFromTableTest(); -
src/unittests/listofbondsunittest.cpp
r8f215d ra7b761b 74 74 75 75 // check that TestMolecule was correctly constructed 76 CPPUNIT_ASSERT_EQUAL( TestMolecule-> AtomCount, 4 );76 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 ); 77 77 78 78 }; … … 90 90 }; 91 91 92 /** Tests whether setup worked correctly. 93 * 94 */ 95 void ListOfBondsTest::SetupTest() 96 { 97 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->empty() ); 98 CPPUNIT_ASSERT_EQUAL( (size_t)4, TestMolecule->size() ); 99 }; 100 92 101 /** Unit Test of molecule::AddBond() 93 102 * … … 96 105 { 97 106 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; 100 111 CPPUNIT_ASSERT( atom1 != NULL ); 101 112 CPPUNIT_ASSERT( atom2 != NULL ); … … 124 135 { 125 136 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; 128 141 CPPUNIT_ASSERT( atom1 != NULL ); 129 142 CPPUNIT_ASSERT( atom2 != NULL ); … … 150 163 { 151 164 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; 155 171 CPPUNIT_ASSERT( atom1 != NULL ); 156 172 CPPUNIT_ASSERT( atom2 != NULL ); … … 189 205 { 190 206 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; 193 211 CPPUNIT_ASSERT( atom1 != NULL ); 194 212 CPPUNIT_ASSERT( atom2 != NULL ); … … 215 233 { 216 234 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; 219 239 CPPUNIT_ASSERT( atom1 != NULL ); 220 240 CPPUNIT_ASSERT( atom2 != NULL ); … … 240 260 { 241 261 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; 244 266 CPPUNIT_ASSERT( atom1 != NULL ); 245 267 CPPUNIT_ASSERT( atom2 != NULL ); -
src/unittests/listofbondsunittest.hpp
r8f215d ra7b761b 20 20 { 21 21 CPPUNIT_TEST_SUITE( ListOfBondsTest) ; 22 CPPUNIT_TEST ( SetupTest ); 22 23 CPPUNIT_TEST ( AddingBondTest ); 23 24 CPPUNIT_TEST ( RemovingBondTest ); … … 31 32 void setUp(); 32 33 void tearDown(); 34 void SetupTest(); 33 35 void AddingBondTest(); 34 36 void RemovingBondTest();
Note:
See TracChangeset
for help on using the changeset viewer.