Changeset 6d35e4
- Timestamp:
- May 7, 2008, 1:38:13 PM (17 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 8d9c38
- Parents:
- db066d
- Location:
- src
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Makefile.am
rdb066d r6d35e4 1 1 SOURCE = atom.cpp bond.cpp builder.cpp config.cpp element.cpp helpers.cpp molecules.cpp moleculelist.cpp periodentafel.cpp vector.cpp verbose.cpp 2 HEADER = defs.hpp helpers.hpp molecules.hpp 2 HEADER = defs.hpp helpers.hpp molecules.hpp stackclass.hpp 3 3 4 4 bin_PROGRAMS = molecuilder joiner analyzer -
src/atom.cpp
rdb066d r6d35e4 106 106 }; 107 107 108 /******************************** Functions for class AtomStackClass ********************************/109 110 /** Constructor of class AtomStackClass.111 */112 AtomStackClass::AtomStackClass(int dimension)113 {114 CurrentLastEntry = 0;115 CurrentFirstEntry = 0;116 NextFreeField = 0;117 EntryCount = dimension;118 StackList = (atom **) Malloc(sizeof(atom *)*EntryCount, "AtomStackClass::AtomStackClass: **StackList");119 };120 121 /** Destructor of class AtomStackClass.122 */123 AtomStackClass::~AtomStackClass()124 {125 Free((void **)&StackList, "AtomStackClass::AtomStackClass: **StackList");126 };127 128 /** Pushes an object onto the stack.129 * \param *object atom to be pushed on stack130 * \return true - sucess, false - failure, meaning stack field was occupied131 */132 bool AtomStackClass::Push(atom *object)133 {134 if (!IsFull()) { // check whether free field is really not occupied135 StackList[NextFreeField] = object;136 CurrentLastEntry = NextFreeField;137 NextFreeField = (NextFreeField + 1) % EntryCount; // step on to next free field138 return true;139 } else {140 cerr << "ERROR: Stack is full, " << "Stack: CurrentLastEntry " << CurrentLastEntry<< "\tCurrentFirstEntry " << CurrentFirstEntry << "\tNextFreeField " << NextFreeField << "\tEntryCount " << EntryCount << "!" << endl;141 return false;142 }143 };144 145 /** Pops first/oldest atom from stack.146 * First in, last out.147 * \return atom pointer from stack, NULL - if failure (no atom pointer in field)148 */149 atom *AtomStackClass::PopFirst()150 {151 atom *Walker = NULL;152 if (!IsEmpty()) {153 Walker = StackList[CurrentFirstEntry];154 if (Walker == NULL)155 cerr << "ERROR: Stack's field is empty!" << endl;156 StackList[CurrentFirstEntry] = NULL;157 if (CurrentFirstEntry != CurrentLastEntry) { // hasn't last item been popped as well?158 CurrentFirstEntry = (CurrentFirstEntry + 1) % EntryCount; // step back from current free field to last used (somehow modulo does not work in -1)159 } else {160 CurrentFirstEntry = (CurrentFirstEntry + 1) % EntryCount; // step back from current free field to last used (somehow modulo does not work in -1)161 CurrentLastEntry = CurrentFirstEntry;162 }163 } else164 cerr << "ERROR: Stack is empty!" << endl;165 return Walker;166 };167 168 /** Pops last atom from stack.169 * First in, first out.170 * \return atom pointer from stack, NULL - if failure (no atom pointer in field)171 */172 atom *AtomStackClass::PopLast()173 {174 atom *Walker = NULL;175 if (!IsEmpty()) {176 Walker = StackList[CurrentLastEntry];177 StackList[CurrentLastEntry] = NULL;178 if (Walker == NULL)179 cerr << "ERROR: Stack's field is empty!" << endl;180 NextFreeField = CurrentLastEntry;181 if (CurrentLastEntry != CurrentFirstEntry) // has there been more than one item on stack182 CurrentLastEntry = (CurrentLastEntry + (EntryCount-1)) % EntryCount; // step back from current free field to last (modulo does not work in -1, thus go EntryCount-1 instead)183 } else {184 cerr << "ERROR: Stack is empty!" << endl;185 }186 return Walker;187 };188 189 /** Removes a certain item from the stack.190 * Item is seeked between \a CurrentFirstEntry and \a CurrentLastEntry, if found, place in stack is NULL'd and191 * all subsequent items shifted by one position downward (with wrapping taken into account).192 * \param *ptr adress of item193 * \return true - item was removed, false - item was not found194 */195 bool AtomStackClass::RemoveItem(atom *ptr)196 {197 bool found = false;198 cout << Verbose(5) << "First " << CurrentFirstEntry<< "\tLast " << CurrentLastEntry<< "\tNext " << NextFreeField<< "\tCount " << EntryCount<< "." << endl;199 int i=CurrentFirstEntry;200 if (!IsEmpty())201 do {202 if (StackList[i] == ptr) { // if item found, remove203 cout << Verbose(5) << "Item " << *ptr << " was number " << i << " on stack, removing it." << endl;204 found = true;205 StackList[i] = NULL;206 }207 if ((found) && (StackList[i] != NULL)) { // means we have to shift (and not the removed item)208 if (i == 0) { // we are down to first item in stack, have to put onto last item209 cout << Verbose(5) << "Shifting item 0 to place " << EntryCount-1 << "." << endl;210 StackList[EntryCount-1] = StackList[0];211 } else {212 cout << Verbose(5) << "Shifting item " << i << " to place " << i-1 << "." << endl;213 StackList[i-1] = StackList[i];214 }215 }216 i=((i + 1) % EntryCount); // step on217 } while (i!=NextFreeField);218 else219 cerr << "ERROR: Stack is already empty!" << endl;220 if (found) {221 NextFreeField = CurrentLastEntry;222 if (CurrentLastEntry != CurrentFirstEntry) // has there been more than one item on stack223 CurrentLastEntry = (CurrentLastEntry + (EntryCount-1)) % EntryCount;224 }225 return found;226 };227 228 /** Test the functionality of the stack.229 * \param *out ofstream for debugging230 * \param *test one item to put on stack231 * \return true - all tests worked correctly232 */233 void AtomStackClass::TestImplementation(ofstream *out, atom *test)234 {235 atom *Walker = test;236 *out << Verbose(1) << "Testing the snake stack..." << endl;237 for (int i=0;i<EntryCount;i++) {238 *out << Verbose(2) << "Filling " << i << "th element of stack." << endl;239 Push(Walker);240 Walker=Walker->next;241 }242 *out << endl;243 Output(out);244 if (IsFull())245 *out << "Stack is full as supposed to be!" << endl;246 else247 *out << "ERROR: Stack is not as full as supposed to be!" << endl;248 //if (StackList[(EntryCount+1)/2] != NULL) {249 *out << "Removing element in the middle ..." << endl;250 RemoveItem(StackList[(EntryCount+1)/2]);251 Output(out);252 //}253 //if (StackList[CurrentFirstEntry] != NULL) {254 *out << "Removing first element ..." << endl;255 RemoveItem(StackList[CurrentFirstEntry]);256 Output(out);257 //}258 //if (StackList[CurrentLastEntry] != NULL) {259 *out << "Removing last element ..." << endl;260 RemoveItem(StackList[CurrentLastEntry]);261 Output(out);262 //}263 *out << "Clearing stack ... " << endl;264 ClearStack();265 Output(out);266 if (IsEmpty())267 *out << "Stack is empty as supposed to be!" << endl;268 else269 *out << "ERROR: Stack is not as empty as supposed to be!" << endl;270 *out << "done." << endl;271 };272 273 /** Puts contents of stack into ofstream \a *out.274 * \param *out ofstream for output275 */276 void AtomStackClass::Output(ofstream *out) const277 {278 *out << "Contents of Stack: ";279 for(int i=0;i<EntryCount;i++) {280 *out << "\t";281 if (i == CurrentFirstEntry)282 *out << " 1";283 if (i == CurrentLastEntry)284 *out << " "<< EntryCount;285 if (i == NextFreeField)286 *out << " F";287 *out << ": " << StackList[i];288 }289 *out << endl;290 };291 292 /** Checks whether stack is empty.293 * Simply checks whether AtomStackClass::NextFreeField is equal to AtomStackClass::CurrentFirstEntry and294 * AtomStackClass::CurrentFirstEntry is equal to AtomStackClass::CurrentLastEntry.295 * \return true - empty, false - not296 */297 bool AtomStackClass::IsEmpty()298 {299 return((NextFreeField == CurrentFirstEntry) && (CurrentLastEntry == CurrentFirstEntry));300 };301 302 /** Checks whether stack is full.303 * Simply checks whether AtomStackClass::NextFreeField is equal to AtomStackClass::CurrentFirstEntry and304 * AtomStackClass::CurrentFirstEntry is _not_ equal to AtomStackClass::CurrentLastEntry.305 * \return true - full, false - not306 */307 bool AtomStackClass::IsFull()308 {309 return((NextFreeField == CurrentFirstEntry) && (CurrentLastEntry != CurrentFirstEntry));310 };311 312 /** Returns number of items on stack.313 * Simply returns difference between AtomStackClass::Stacklist entry AtomStackClass::CurrentEntry-1.314 * \return number of items on stack315 * \warning will never return correct item count if stack is full, i.e. count would be AtomStackClass::EntryCount.316 */317 int AtomStackClass::ItemCount()318 {319 //cout << "Stack: CurrentLastEntry " << CurrentLastEntry<< "\tCurrentFirstEntry " << CurrentFirstEntry << "\tEntryCount " << EntryCount << "." << endl;320 return((NextFreeField + (EntryCount - CurrentFirstEntry)) % EntryCount);321 };322 323 /** Clears the stack from all atoms.324 * \return true - sucess, false - failure325 */326 void AtomStackClass::ClearStack()327 {328 for(int i=0;i<EntryCount; i++)329 StackList[i] = NULL;330 CurrentFirstEntry = 0;331 CurrentLastEntry = 0;332 NextFreeField = 0;333 };334 -
src/helpers.hpp
rdb066d r6d35e4 59 59 char *FixedDigitNumber(const int FragmentNumber, const int digits); 60 60 61 /********************************************** helpful structures *********************************/ 61 /********************************************** helpful template functions *********************************/ 62 63 /******************************** Some templates for list management ***********************************/ 64 65 /** Adds linking of an item to a list. 66 * \param *walker 67 * \return true - adding succeeded, false - error in list 68 */ 69 template <typename X> void link(X *walker, X *end) 70 { 71 X *vorher = end->previous; 72 if (vorher != NULL) 73 vorher->next = walker; 74 end->previous = walker; 75 walker->previous = vorher; 76 walker->next = end; 77 }; 78 79 /** Removes linking of an item in a list. 80 * \param *walker 81 * \return true - removing succeeded, false - given item not found in list 82 */ 83 template <typename X> void unlink(X *walker) 84 { 85 if (walker->next != NULL) 86 walker->next->previous = walker->previous; 87 if (walker->previous != NULL) 88 walker->previous->next = walker->next; 89 }; 90 91 /** Adds new item before an item \a *end in a list. 92 * \param *pointer item to be added 93 * \param *end end of list 94 * \return true - addition succeeded, false - unable to add item to list 95 */ 96 template <typename X> bool add(X *pointer, X *end) 97 { 98 if (end != NULL) { 99 link(pointer, end); 100 } else { 101 pointer->previous = NULL; 102 pointer->next = NULL; 103 } 104 return true; 105 }; 106 107 /** Finds item in list 108 * \param *suche search criteria 109 * \param *start begin of list 110 * \param *end end of list 111 * \return X - if found, NULL - if not found 112 */ 113 template <typename X, typename Y> X * find(Y *suche, X *start, X *end) 114 { 115 X *walker = start; 116 while (walker->next != end) { // go through list 117 walker = walker->next; // step onward beforehand 118 if (*walker->sort == *suche) return (walker); 119 } 120 return NULL; 121 }; 122 123 /** Removes an item from the list without check. 124 * \param *walker item to be removed 125 * \return true - removing succeeded, false - given item not found in list 126 */ 127 template <typename X> void removewithoutcheck(X *walker) 128 { 129 if (walker != NULL) { 130 unlink(walker); 131 delete(walker); 132 walker = NULL; 133 } 134 }; 135 136 /** Removes an item from the list, checks if exists. 137 * Checks beforehand if atom is really within molecule list. 138 * \param *pointer item to be removed 139 * \param *start begin of list 140 * \param *end end of list 141 * \return true - removing succeeded, false - given item not found in list 142 */ 143 template <typename X> bool remove(X *pointer, X *start, X *end) 144 { 145 X *walker = find (pointer->sort, start, end); 146 /* while (walker->next != pointer) { // search through list 147 walker = walker->next; 148 if (walker == end) return false; // item not found in list 149 }*/ 150 // atom found, now unlink 151 if (walker != NULL) 152 removewithoutcheck(walker); 153 else 154 return false; 155 return true; 156 }; 157 158 /** Cleans the whole list. 159 * \param *start begin of list 160 * \param *end end of list 161 * \return true - list was cleaned successfully, false - error in list structure 162 */ 163 template <typename X> bool cleanup(X *start, X *end) 164 { 165 X *pointer = start->next; 166 X *walker; 167 while (pointer != end) { // go through list 168 walker = pointer; // mark current 169 pointer = pointer->next; // step onward beforehand 170 // remove walker 171 unlink(walker); 172 delete(walker); 173 walker = NULL; 174 } 175 return true; 176 }; 177 178 /** Returns the first marker in a chain list. 179 * \param *me one arbitrary item in chain list 180 * \return poiner to first marker 181 */ 182 template <typename X> X *GetFirst(X *me) 183 { 184 X *Binder = me; 185 while(Binder->previous != NULL) 186 Binder = Binder->previous; 187 return Binder; 188 }; 189 190 /** Returns the last marker in a chain list. 191 * \param *me one arbitrary item in chain list 192 * \return poiner to last marker 193 */ 194 template <typename X> X *GetLast(X *me) 195 { 196 X *Binder = me; 197 while(Binder->next != NULL) 198 Binder = Binder->next; 199 return Binder; 200 }; 201 202 /** Frees a two-dimensional array. 203 * \param *ptr pointer to array 204 * \param dim first dim of array 205 */ 206 template <typename X> void Free2DArray(X **ptr, int dim) 207 { 208 int i; 209 if (ptr != NULL) { 210 for(i=0;i<dim;i++) 211 if (ptr[i] != NULL) 212 free(ptr[i]); 213 free(ptr); 214 } 215 }; 62 216 63 217 /************************************* Class Verbose & Binary *******************************/ -
src/molecules.cpp
rdb066d r6d35e4 1419 1419 MoleculeLeafClass * molecule::DepthFirstSearchAnalysis(ofstream *out, bool ReturnStack, int &MinimumRingSize) 1420 1420 { 1421 AtomStackClass *AtomStack = new AtomStackClass(AtomCount); 1421 class StackClass<atom *> *AtomStack; 1422 AtomStack = new StackClass<atom *>(AtomCount); 1423 class StackClass<bond *> *BackEdgeStack = new StackClass<bond *> (BondCount); 1422 1424 MoleculeLeafClass *SubGraphs = new MoleculeLeafClass(NULL); 1423 1425 MoleculeLeafClass *LeafWalker = SubGraphs; 1424 1426 int CurrentGraphNr = 0, OldGraphNr; 1425 int CyclicBonds;1426 1427 int ComponentNumber = 0; 1427 1428 atom *Walker = NULL, *OtherAtom = NULL, *Root = start->next; … … 1434 1435 ResetAllAtomNumbers(); 1435 1436 InitComponentNumbers(); 1437 BackEdgeStack->ClearStack(); 1436 1438 while (Root != end) { // if there any atoms at all 1437 1439 // (1) mark all edges unused, empty stack, set atom->GraphNr = 0 for all … … 1468 1470 // (4a) ... if "other" atom has been visited (GraphNr != 0), set lowpoint to minimum of both, go to (3) 1469 1471 Binder->Type = BackEdge; 1472 BackEdgeStack->Push(Binder); 1470 1473 Walker->LowpointNr = ( Walker->LowpointNr < OtherAtom->GraphNr ) ? Walker->LowpointNr : OtherAtom->GraphNr; 1471 1474 *out << Verbose(3) << "(4a) Visited: Setting Lowpoint of Walker[" << Walker->Name << "] to " << Walker->LowpointNr << "." << endl; … … 1568 1571 } 1569 1572 1570 // correct cyclic bonds that are not included in "same LP" argument 1571 Binder = first; 1572 while (Binder->next != last) { 1573 Binder = Binder->next; 1574 Walker = Binder->leftatom; 1575 OtherAtom = Binder->rightatom; 1576 // now check whether both have a cyclic bond in their list 1577 CyclicBonds = 0; // counts cyclic bonds; 1578 for(int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++) 1579 if ((CyclicBonds == 0) && (ListOfBondsPerAtom[Walker->nr][i]->Cyclic)) 1580 CyclicBonds = 1; 1581 for(int i=0;i<NumberOfBondsPerAtom[OtherAtom->nr];i++) 1582 if ((CyclicBonds == 1) && (ListOfBondsPerAtom[OtherAtom->nr][i]->Cyclic)) 1583 CyclicBonds = 2; 1584 Binder->Cyclic = (Binder->Cyclic) || (CyclicBonds == 2); // set the Cyclic criterium either or ... 1585 } 1586 1587 // further analysis of the found cycles (print rings, get minimum cycle length) 1573 // analysis of the cycles (print rings, get minimum cycle length) 1588 1574 CyclicStructureAnalysis(out, MinimumRingSize); 1575 1589 1576 *out << Verbose(1) << "Final graph info for each atom is:" << endl; 1590 1577 Walker = start; … … 1624 1611 void molecule::CyclicStructureAnalysis(ofstream *out, int &MinimumRingSize) 1625 1612 { 1626 AtomStackClass *AtomStack = new AtomStackClass(AtomCount);1613 class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount); 1627 1614 int LP; 1628 1615 atom *Walker = NULL, *OtherAtom = NULL, *Root = NULL, *Runner = NULL; … … 1630 1617 int RingSize, NumCycles; 1631 1618 1632 // go through every atom1619 // count number of cyclic bonds per atom and push all with 3 cyclic bonds onto stack 1633 1620 AtomStack->ClearStack(); 1634 1621 int *NoCyclicBondsPerAtom = (int *) Malloc(sizeof(int)*AtomCount, "molecule::CyclicStructureAnalysis: *NoCyclicBondsPerAtom"); … … 2065 2052 line << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE; 2066 2053 File.open(line.str().c_str(), ios::out); 2067 *out << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... " << endl;2054 *out << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... "; 2068 2055 if (File != NULL) { 2069 2056 // allocate storage structure … … 2119 2106 status = false; 2120 2107 } 2108 *out << endl; 2121 2109 Free((void **)&buffer, "molecule::CheckAdjacencyFileAgainstMolecule: *buffer"); 2122 2110 … … 2620 2608 2621 2609 /** Adds atoms up to \a BondCount distance from \a *Root and notes them down in \a **AddedAtomList. 2622 * Gray vertices are always enqueued in an AtomStackClassFIFO queue, the rest is usual BFS with adding vertices found was2610 * Gray vertices are always enqueued in an StackClass<atom *> FIFO queue, the rest is usual BFS with adding vertices found was 2623 2611 * white and putting into queue. 2624 2612 * \param *out output stream for debugging … … 2636 2624 int *ShortestPathList = (int *) Malloc(sizeof(int)*AtomCount, "molecule::BreadthFirstSearchAdd: *ShortestPathList"); 2637 2625 enum Shading *ColorList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::BreadthFirstSearchAdd: *ColorList"); 2638 AtomStackClass *AtomStack = new AtomStackClass(AtomCount);2626 class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount); 2639 2627 atom *Walker = NULL, *OtherAtom = NULL; 2640 2628 bond *Binder = NULL; … … 2802 2790 2803 2791 2804 /** Looks through a AtomStackClassand returns the likeliest removal candiate.2792 /** Looks through a StackClass<atom *> and returns the likeliest removal candiate. 2805 2793 * \param *out output stream for debugging messages 2806 2794 * \param *&Leaf KeySet to look through … … 2922 2910 enum Shading *ColorVertexList = (enum Shading *) Malloc(sizeof(enum Shading)*AtomCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorList"); 2923 2911 enum Shading *ColorEdgeList = (enum Shading *) Malloc(sizeof(enum Shading)*BondCount, "molecule::CreateListOfUniqueFragmentsOfOrder: *ColorBondList"); 2924 AtomStackClass *RootStack = new AtomStackClass(AtomCount);2925 AtomStackClass *TouchedStack = new AtomStackClass((int)pow(4,Order)+2); // number of atoms reached from one with maximal 4 bonds plus Root itself2926 AtomStackClass *SnakeStack = new AtomStackClass(Order+1); // equal to Order is not possible, as then the AtomStackClasscannot discern between full and empty stack!2912 StackClass<atom *> *RootStack = new StackClass<atom *>(AtomCount); 2913 StackClass<atom *> *TouchedStack = new StackClass<atom *>((int)pow(4,Order)+2); // number of atoms reached from one with maximal 4 bonds plus Root itself 2914 StackClass<atom *> *SnakeStack = new StackClass<atom *>(Order+1); // equal to Order is not possible, as then the StackClass<atom *> cannot discern between full and empty stack! 2927 2915 MoleculeLeafClass *Leaflet = NULL, *TempLeaf = NULL; 2928 2916 MoleculeListClass *FragmentList = NULL; … … 3489 3477 double tmp; 3490 3478 vector TranslationVector; 3491 // AtomStackClass*CompStack = NULL;3492 AtomStackClass *AtomStack = new AtomStackClass(AtomCount);3479 //class StackClass<atom *> *CompStack = NULL; 3480 class StackClass<atom *> *AtomStack = new StackClass<atom *>(AtomCount); 3493 3481 bool flag = true; 3494 3482 -
src/molecules.hpp
rdb066d r6d35e4 21 21 22 22 #include "helpers.hpp" 23 #include "stackclass.hpp" 23 24 24 25 class atom; 25 class AtomStackClass;26 26 class bond; 27 27 class config; … … 46 46 bool operator() (const KeySet SubgraphA, const KeySet SubgraphB) const; 47 47 }; 48 48 49 //bool operator < (KeySet SubgraphA, KeySet SubgraphB); //note: this declaration is important, otherwise normal < is used (producing wrong order) 49 50 inline void InsertFragmentIntoGraph(ofstream *out, struct UniqueFragments *Fragment); // Insert a KeySet into a Graph 50 51 inline void InsertGraphIntoGraph(ofstream *out, Graph &graph1, Graph &graph2, int *counter); // Insert all KeySet's in a Graph into another Graph 51 52 /******************************** Some templates for list management ***********************************/53 54 /** Adds linking of an item to a list.55 * \param *walker56 * \return true - adding succeeded, false - error in list57 */58 template <typename X> void link(X *walker, X *end)59 {60 X *vorher = end->previous;61 if (vorher != NULL)62 vorher->next = walker;63 end->previous = walker;64 walker->previous = vorher;65 walker->next = end;66 };67 68 /** Removes linking of an item in a list.69 * \param *walker70 * \return true - removing succeeded, false - given item not found in list71 */72 template <typename X> void unlink(X *walker)73 {74 if (walker->next != NULL)75 walker->next->previous = walker->previous;76 if (walker->previous != NULL)77 walker->previous->next = walker->next;78 };79 80 /** Adds new item before an item \a *end in a list.81 * \param *pointer item to be added82 * \param *end end of list83 * \return true - addition succeeded, false - unable to add item to list84 */85 template <typename X> bool add(X *pointer, X *end)86 {87 if (end != NULL) {88 link(pointer, end);89 } else {90 pointer->previous = NULL;91 pointer->next = NULL;92 }93 return true;94 };95 96 /** Finds item in list97 * \param *suche search criteria98 * \param *start begin of list99 * \param *end end of list100 * \return X - if found, NULL - if not found101 */102 template <typename X, typename Y> X * find(Y *suche, X *start, X *end)103 {104 X *walker = start;105 while (walker->next != end) { // go through list106 walker = walker->next; // step onward beforehand107 if (*walker->sort == *suche) return (walker);108 }109 return NULL;110 };111 112 /** Removes an item from the list without check.113 * \param *walker item to be removed114 * \return true - removing succeeded, false - given item not found in list115 */116 template <typename X> void removewithoutcheck(X *walker)117 {118 if (walker != NULL) {119 unlink(walker);120 delete(walker);121 walker = NULL;122 }123 };124 125 /** Removes an item from the list, checks if exists.126 * Checks beforehand if atom is really within molecule list.127 * \param *pointer item to be removed128 * \param *start begin of list129 * \param *end end of list130 * \return true - removing succeeded, false - given item not found in list131 */132 template <typename X> bool remove(X *pointer, X *start, X *end)133 {134 X *walker = find (pointer->sort, start, end);135 /* while (walker->next != pointer) { // search through list136 walker = walker->next;137 if (walker == end) return false; // item not found in list138 }*/139 // atom found, now unlink140 if (walker != NULL)141 removewithoutcheck(walker);142 else143 return false;144 return true;145 };146 147 /** Cleans the whole list.148 * \param *start begin of list149 * \param *end end of list150 * \return true - list was cleaned successfully, false - error in list structure151 */152 template <typename X> bool cleanup(X *start, X *end)153 {154 X *pointer = start->next;155 X *walker;156 while (pointer != end) { // go through list157 walker = pointer; // mark current158 pointer = pointer->next; // step onward beforehand159 // remove walker160 unlink(walker);161 delete(walker);162 walker = NULL;163 }164 return true;165 };166 167 /** Returns the first marker in a chain list.168 * \param *me one arbitrary item in chain list169 * \return poiner to first marker170 */171 template <typename X> X *GetFirst(X *me)172 {173 X *Binder = me;174 while(Binder->previous != NULL)175 Binder = Binder->previous;176 return Binder;177 };178 179 /** Returns the last marker in a chain list.180 * \param *me one arbitrary item in chain list181 * \return poiner to last marker182 */183 template <typename X> X *GetLast(X *me)184 {185 X *Binder = me;186 while(Binder->next != NULL)187 Binder = Binder->next;188 return Binder;189 };190 191 /** Frees a two-dimensional array.192 * \param *ptr pointer to array193 * \param dim first dim of array194 */195 template <typename X> void Free2DArray(X **ptr, int dim)196 {197 int i;198 if (ptr != NULL) {199 for(i=0;i<dim;i++)200 if (ptr[i] != NULL)201 free(ptr[i]);202 free(ptr);203 }204 };205 206 52 int CompareDoubles (const void * a, const void * b); 53 207 54 208 55 /************************************* Class definitions ****************************************/ … … 370 217 371 218 ostream & operator << (ostream &ost, atom &a); 372 373 /* Stack of Atoms.374 * Is used during DepthFirstSearchAnalysis() to detect nonseparable components.375 */376 class AtomStackClass {377 public:378 AtomStackClass(int dimension);379 ~AtomStackClass();380 381 bool Push(atom *object);382 atom *PopFirst();383 atom *PopLast();384 bool AtomStackClass::RemoveItem(atom *ptr);385 void ClearStack();386 bool IsEmpty();387 bool IsFull();388 int ItemCount();389 void Output(ofstream *out) const;390 void TestImplementation(ofstream *out, atom *test);391 392 private:393 atom **StackList; //!< the list containing the atom pointers394 int EntryCount; //!< number of entries in the stack395 int CurrentLastEntry; //!< Current last entry (newest item on stack)396 int CurrentFirstEntry; //!< Current first entry (oldest item on stack)397 int NextFreeField; //!< Current index of next free field398 };399 400 219 401 220 /** Bonds between atoms.
Note:
See TracChangeset
for help on using the changeset viewer.