Changeset 212c179
- Timestamp:
- Oct 25, 2011, 12:08:03 PM (13 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:
- 246e13
- Parents:
- d0b375b
- git-author:
- Frederik Heber <heber@…> (10/18/11 13:16:51)
- git-committer:
- Frederik Heber <heber@…> (10/25/11 12:08:03)
- Location:
- src
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Makefile.am
rd0b375b r212c179 3 3 4 4 FRAGMENTATIONSOURCE = \ 5 Fragmentation/BondsPerShortestPath.cpp \ 5 6 Fragmentation/EnergyMatrix.cpp \ 6 7 Fragmentation/ForceMatrix.cpp \ … … 14 15 15 16 FRAGMENTATIONHEADER = \ 17 Fragmentation/BondsPerShortestPath.hpp \ 16 18 Fragmentation/defs.hpp \ 17 19 Fragmentation/EnergyMatrix.hpp \ -
src/Fragmentation/PowerSetGenerator.cpp
rd0b375b r212c179 31 31 * 32 32 */ 33 PowerSetGenerator::PowerSetGenerator() : 34 FragmentSearch(NULL) 33 PowerSetGenerator::PowerSetGenerator(class UniqueFragments *_FragmentSearch, int Order) : 34 BondsPerSPList(Order), 35 FragmentSearch(_FragmentSearch) 35 36 {} 36 37 … … 44 45 45 46 /** Clears the touched list 46 * \param *out output stream for debugging47 47 * \param verbosity verbosity level 48 48 * \param *&TouchedList touched list … … 60 60 61 61 /** Adds the current combination of the power set to the snake stack. 62 * \param *out output stream for debugging63 62 * \param verbosity verbosity level 64 63 * \param CurrentCombination … … 141 140 142 141 /** Remove all items that were added on this SP level. 143 * \param *out output stream for debugging144 142 * \param verbosity verbosity level 145 143 * \param *FragmentSet snake stack to remove from … … 172 170 * Note that we may use the fact that the atoms are SP-ordered on the atomstack. I.e. when popping always the last, we first get all 173 171 * with SP of 2, then those with SP of 3, then those with SP of 4 and so on. 174 * \param *_FragmentSearch helpful structure containing additional information175 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation176 172 * \param RestrictedKeySet Restricted vertex set to use in context of molecule 177 173 * \return number of inserted fragments 178 174 * \note ShortestPathList in FragmentSearch structure is probably due to NumberOfAtomsSPLevel and SP not needed anymore 179 175 */ 180 int PowerSetGenerator::operator()(struct UniqueFragments *_FragmentSearch, int Order, KeySet RestrictedKeySet) 181 { 182 FragmentSearch = _FragmentSearch; 176 int PowerSetGenerator::operator()(KeySet &RestrictedKeySet) 177 { 183 178 int Counter = FragmentSearch->FragmentCounter; // mark current value of counter 184 179 185 180 DoLog(0) && (Log() << Verbose(0) << endl); 186 DoLog(0) && (Log() << Verbose(0) << "Begin of PowerSetGenerator with order " << Order<< " at Root " << *FragmentSearch->getRoot() << "." << endl);187 188 FragmentSearch->SetSPList(Order);181 DoLog(0) && (Log() << Verbose(0) << "Begin of PowerSetGenerator with order " << BondsPerSPList.getOrder() << " at Root " << *FragmentSearch->getRoot() << "." << endl); 182 183 BondsPerSPList.SetSPList(FragmentSearch->getRoot()); 189 184 190 185 // do a BFS search to fill the SP lists and label the found vertices 191 FragmentSearch->FillSPListandLabelVertices(Order, RestrictedKeySet);186 BondsPerSPList.FillSPListandLabelVertices(FragmentSearch->getRoot()->GetTrueFather()->getNr(), RestrictedKeySet); 192 187 193 188 // outputting all list for debugging 194 FragmentSearch->OutputSPList(Order);189 BondsPerSPList.OutputSPList(); 195 190 196 191 // creating fragments with the found edge sets (may be done in reverse order, faster) 197 int SP = FragmentSearch->CountNumbersInBondsList(Order);192 int SP = BondsPerSPList.CountNumbersInBondsList(); 198 193 DoLog(0) && (Log() << Verbose(0) << "Total number of edges is " << SP << "." << endl); 199 if (SP >= ( Order-1)) {194 if (SP >= (BondsPerSPList.getOrder()-1)) { 200 195 // start with root (push on fragment stack) 201 196 DoLog(0) && (Log() << Verbose(0) << "Starting fragment generation with " << *FragmentSearch->getRoot() << ", local nr is " << FragmentSearch->getRoot()->getNr() << "." << endl); … … 205 200 // prepare the subset and call the generator 206 201 std::vector<bond*> BondsList; 207 BondsList.resize( FragmentSearch->BondsPerSPCount[0]);208 ASSERT( FragmentSearch->BondsPerSPList[0].size() != 0,209 "molecule::PowerSetGenerator() - FragmentSearch->BondsPerSPList[0] contains no root bond.");210 BondsList[0] = (* FragmentSearch->BondsPerSPList[0].begin()); // on SP level 0 there's only the root bond211 212 SPFragmentGenerator(0, BondsList, FragmentSearch->BondsPerSPCount[0], Order);202 BondsList.resize(BondsPerSPList.BondsPerSPCount[0]); 203 ASSERT(BondsPerSPList.BondsPerSPList[0].size() != 0, 204 "molecule::PowerSetGenerator() - BondsPerSPList.BondsPerSPList[0] contains no root bond."); 205 BondsList[0] = (*BondsPerSPList.BondsPerSPList[0].begin()); // on SP level 0 there's only the root bond 206 207 SPFragmentGenerator(0, BondsList, BondsPerSPList.BondsPerSPCount[0], BondsPerSPList.getOrder()); 213 208 } else { 214 DoLog(0) && (Log() << Verbose(0) << "Not enough total number of edges to build " << Order<< "-body fragments." << endl);209 DoLog(0) && (Log() << Verbose(0) << "Not enough total number of edges to build " << BondsPerSPList.getOrder() << "-body fragments." << endl); 215 210 } 216 211 … … 221 216 222 217 // free'ing the bonds lists 223 FragmentSearch->ResetSPList(Order);218 BondsPerSPList.ResetSPList(); 224 219 225 220 // return list … … 283 278 284 279 // first count the members in the subset 285 SubSetDimension = CountSetMembers( FragmentSearch->BondsPerSPList[SP].begin(), FragmentSearch->BondsPerSPList[SP].end(), TouchedList, TouchedIndex);280 SubSetDimension = CountSetMembers(BondsPerSPList.BondsPerSPList[SP].begin(), BondsPerSPList.BondsPerSPList[SP].end(), TouchedList, TouchedIndex); 286 281 287 282 // then allocate and fill the list 288 283 std::vector<bond *> BondsList; 289 284 BondsList.resize(SubSetDimension); 290 SubSetDimension = FillBondsList(BondsList, FragmentSearch->BondsPerSPList[SP].begin(), FragmentSearch->BondsPerSPList[SP].end(), TouchedList, TouchedIndex);285 SubSetDimension = FillBondsList(BondsList, BondsPerSPList.BondsPerSPList[SP].begin(), BondsPerSPList.BondsPerSPList[SP].end(), TouchedList, TouchedIndex); 291 286 292 287 // then iterate -
src/Fragmentation/PowerSetGenerator.hpp
rd0b375b r212c179 17 17 #include <vector> 18 18 19 #include "Fragmentation/BondsPerShortestPath.hpp" 19 20 #include "graph.hpp" 20 21 … … 25 26 { 26 27 public: 27 PowerSetGenerator( );28 PowerSetGenerator(UniqueFragments *_FragmentSearch, int Order); 28 29 ~PowerSetGenerator(); 29 30 30 31 void SPFragmentGenerator(int RootDistance, std::vector<bond *> &BondsSet, int SetDimension, int SubOrder); 31 int operator()( struct UniqueFragments *_FragmentSearch, int Order, KeySetRestrictedKeySet);32 int operator()(KeySet &RestrictedKeySet); 32 33 void RemoveAllTouchedFromSnakeStack(int verbosity, KeySet *FragmentSet, int *&TouchedList, int &TouchedIndex); 33 34 int FillBondsList(std::vector<bond *> &BondsList, std::list<bond *>::const_iterator SetFirst, std::list<bond *>::const_iterator SetLast, int *&TouchedList, int TouchedIndex); … … 37 38 38 39 private: 40 BondsPerShortestPath BondsPerSPList; 41 39 42 class UniqueFragments *FragmentSearch; 40 43 }; -
src/Fragmentation/UniqueFragments.cpp
rd0b375b r212c179 58 58 }; 59 59 60 /** Allocates memory for UniqueFragments::BondsPerSPList.61 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation62 * \sa UniqueFragments::FreeSPList()63 */64 void UniqueFragments::InitialiseSPList(int Order)65 {66 BondsPerSPList.resize(Order);67 BondsPerSPCount = new int[Order];68 for (int i=Order;i--;) {69 BondsPerSPCount[i] = 0;70 }71 };72 73 /** Free's memory for for UniqueFragments::BondsPerSPList.74 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation75 * \sa UniqueFragments::InitialiseSPList()76 */77 void UniqueFragments::FreeSPList(int Order)78 {79 delete[](BondsPerSPCount);80 };81 82 /** Sets FragmenSearch to initial value.83 * Sets UniqueFragments::BondsPerSPCount to zero (except zero level to 1) and adds initial bond84 * UniqueFragments::Root to UniqueFragments::Root to UniqueFragments::BondsPerSPList85 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation86 * \sa UniqueFragments::FreeSPList()87 */88 void UniqueFragments::SetSPList(int Order)89 {90 // prepare root level (SP = 0) and a loop bond denoting Root91 for (int i=Order;i--;)92 BondsPerSPCount[i] = 0;93 BondsPerSPCount[0] = 1;94 bond *Binder = new bond(Root, Root);95 BondsPerSPList[0].push_back(Binder);96 };97 98 /** Cleans bonds from UniqueFragments::BondsPerSPList.99 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation100 * \sa UniqueFragments::InitialiseSPList()101 */102 void UniqueFragments::ResetSPList(int Order)103 {104 DoLog(0) && (Log() << Verbose(0) << "Free'ing all found lists. and resetting index lists" << endl);105 for(int i=Order;i--;) {106 DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << ": ");107 // delete added bonds108 for (UniqueFragments::BondsPerSP::iterator iter = BondsPerSPList[i].begin();109 iter != BondsPerSPList[i].end();110 ++iter) {111 delete(*iter);112 }113 BondsPerSPList[i].clear();114 // also start and end node115 DoLog(0) && (Log() << Verbose(0) << "cleaned." << endl);116 }117 };118 119 120 /** Fills the Bonds per Shortest Path List and set the vertex labels.121 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation122 * \param RestrictedKeySet Restricted vertex set to use in context of molecule123 */124 void UniqueFragments::FillSPListandLabelVertices(int Order, KeySet &RestrictedKeySet)125 {126 // Actually, we should construct a spanning tree vom the root atom and select all edges therefrom and put them into127 // according shortest path lists. However, we don't. Rather we fill these lists right away, as they do form a spanning128 // tree already sorted into various SP levels. That's why we just do loops over the depth (CurrentSP) and breadth129 // (EdgeinSPLevel) of this tree ...130 // In another picture, the bonds always contain a direction by rightatom being the one more distant from root and hence131 // naturally leftatom forming its predecessor, preventing the BFS"seeker" from continuing in the wrong direction.132 int AtomKeyNr = -1;133 atom *Walker = NULL;134 atom *OtherWalker = NULL;135 atom *Predecessor = NULL;136 bond *Binder = NULL;137 int RootKeyNr = Root->GetTrueFather()->getNr();138 int RemainingWalkers = -1;139 int SP = -1;140 141 DoLog(0) && (Log() << Verbose(0) << "Starting BFS analysis ..." << endl);142 for (SP = 0; SP < (Order-1); SP++) {143 DoLog(1) && (Log() << Verbose(1) << "New SP level reached: " << SP << ", creating new SP list with " << BondsPerSPCount[SP] << " item(s)");144 if (SP > 0) {145 DoLog(0) && (Log() << Verbose(0) << ", old level closed with " << BondsPerSPCount[SP-1] << " item(s)." << endl);146 BondsPerSPCount[SP] = 0;147 } else148 DoLog(0) && (Log() << Verbose(0) << "." << endl);149 150 RemainingWalkers = BondsPerSPCount[SP];151 for (BondsPerSP::const_iterator CurrentEdge = BondsPerSPList[SP].begin();152 CurrentEdge != BondsPerSPList[SP].end();153 ++CurrentEdge) { /// start till end of this SP level's list154 RemainingWalkers--;155 Walker = (*CurrentEdge)->rightatom; // rightatom is always the one more distant156 Predecessor = (*CurrentEdge)->leftatom; // ... and leftatom is predecessor157 AtomKeyNr = Walker->getNr();158 DoLog(0) && (Log() << Verbose(0) << "Current Walker is: " << *Walker << " with nr " << Walker->getNr() << " and SP of " << SP << ", with " << RemainingWalkers << " remaining walkers on this level." << endl);159 // check for new sp level160 // go through all its bonds161 DoLog(1) && (Log() << Verbose(1) << "Going through all bonds of Walker." << endl);162 const BondList& ListOfBonds = Walker->getListOfBonds();163 for (BondList::const_iterator Runner = ListOfBonds.begin();164 Runner != ListOfBonds.end();165 ++Runner) {166 OtherWalker = (*Runner)->GetOtherAtom(Walker);167 if ((RestrictedKeySet.find(OtherWalker->getNr()) != RestrictedKeySet.end())168 #ifdef ADDHYDROGEN169 && (OtherWalker->getType()->getAtomicNumber() != 1)170 #endif171 ) { // skip hydrogens and restrict to fragment172 DoLog(2) && (Log() << Verbose(2) << "Current partner is " << *OtherWalker << " with nr " << OtherWalker->getNr() << " in bond " << *(*Runner) << "." << endl);173 // set the label if not set (and push on root stack as well)174 if ((OtherWalker != Predecessor) && (OtherWalker->GetTrueFather()->getNr() > RootKeyNr)) { // only pass through those with label bigger than Root's175 // add the bond in between to the SP list176 Binder = new bond(Walker, OtherWalker); // create a new bond in such a manner, that bond::rightatom is always the one more distant177 BondsPerSPList[SP+1].push_back(Binder);178 BondsPerSPCount[SP+1]++;179 DoLog(3) && (Log() << Verbose(3) << "Added its bond to SP list, having now " << BondsPerSPCount[SP+1] << " item(s)." << endl);180 } else {181 if (OtherWalker != Predecessor)182 DoLog(3) && (Log() << Verbose(3) << "Not passing on, as index of " << *OtherWalker << " " << OtherWalker->GetTrueFather()->getNr() << " is smaller than that of Root " << RootKeyNr << "." << endl);183 else184 DoLog(3) && (Log() << Verbose(3) << "This is my predecessor " << *Predecessor << "." << endl);185 }186 } else Log() << Verbose(2) << "Is not in the restricted keyset or skipping hydrogen " << *OtherWalker << "." << endl;187 }188 }189 }190 };191 192 /** prints the Bonds per Shortest Path list in UniqueFragments.193 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation194 */195 void UniqueFragments::OutputSPList(int Order)196 {197 DoLog(0) && (Log() << Verbose(0) << "Printing all found lists." << endl);198 for(int i=1;i<Order;i++) { // skip the root edge in the printing199 DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << "." << endl);200 for (UniqueFragments::BondsPerSP::const_iterator Binder = BondsPerSPList[i].begin();201 Binder != BondsPerSPList[i].end();202 ++Binder) {203 DoLog(2) && (Log() << Verbose(2) << *Binder << endl);204 }205 }206 };207 208 /** Simply counts all bonds in all UniqueFragments::BondsPerSPList lists.209 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation210 */211 int UniqueFragments::CountNumbersInBondsList(int Order)212 {213 int SP = -1; // the Root <-> Root edge must be subtracted!214 for(int i=Order;i--;) { // sum up all found edges215 for (UniqueFragments::BondsPerSP::const_iterator Binder = BondsPerSPList[i].begin();216 Binder != BondsPerSPList[i].end();217 ++Binder) {218 SP++;219 }220 }221 return SP;222 };223 224 60 /** Initialization for UniqueFragments. 225 61 * … … 247 83 * @return const ref to root atom. 248 84 */ 249 const atom *UniqueFragments::getRoot() const85 atom * const UniqueFragments::getRoot() const 250 86 { 251 87 return Root; … … 260 96 Root=_root; 261 97 } 98 99 /** Sets initial values before PowerSetGenerator uses this class. 100 * 101 * @param _TEFactor total energy factor 102 * @param _Leaflet current graph to work on 103 * @param _Root root atom 104 */ 105 void UniqueFragments::PrepareForPowersetGeneration(double _TEFactor, Graph *_Leaflet, atom *_Root) 106 { 107 TEFactor = _TEFactor; 108 Leaflet = _Leaflet; 109 Root = _Root; 110 } -
src/Fragmentation/UniqueFragments.hpp
rd0b375b r212c179 31 31 ~UniqueFragments(); 32 32 33 typedef std::list<bond*> BondsPerSP;34 typedef std::vector< BondsPerSP > AllSPBonds;35 36 33 void InsertFragmentIntoGraph(); // Insert a KeySet into a Graph 37 void InitialiseSPList(int Order);38 void FreeSPList(int Order);39 void SetSPList(int Order);40 void ResetSPList(int Order);41 void FillSPListandLabelVertices(int Order, KeySet &RestrictedKeySet);42 void OutputSPList(int Order);43 int CountNumbersInBondsList(int Order);44 34 void Init(atom *_Root); 45 35 void Cleanup(); 46 36 47 const atom *getRoot() const;37 atom * const getRoot() const; 48 38 void setRoot(atom *_root); 39 40 void PrepareForPowersetGeneration(double _TEFactor, Graph *_Leaflet, atom *_Root); 49 41 50 42 KeySet *FragmentSet; 51 43 int FragmentCounter; 52 int *BondsPerSPCount;53 double TEFactor;54 Graph *Leaflet;55 AllSPBonds BondsPerSPList;56 57 44 58 45 private: 59 46 atom *Root; 47 double TEFactor; 48 Graph *Leaflet; 60 49 61 50 private: -
src/molecule_fragmentation.cpp
rd0b375b r212c179 661 661 int RootNr = 0; 662 662 struct UniqueFragments FragmentSearch; 663 class PowerSetGenerator PSG;664 663 665 664 DoLog(0) && (Log() << Verbose(0) << "Begin of FragmentBOSSANOVA." << endl); … … 702 701 703 702 // initialise Order-dependent entries of UniqueFragments structure 704 FragmentSearch.InitialiseSPList(Order);703 class PowerSetGenerator PSG(&FragmentSearch, Walker->AdaptiveOrder); 705 704 706 705 // allocate memory for all lower level orders in this 1D-array of ptrs … … 715 714 716 715 // Create list of Graphs of current Bond Order (i.e. F_{ij}) 717 FragmentLowerOrdersList[RootNr][0] = new Graph; 718 FragmentSearch.TEFactor = 1.; 719 FragmentSearch.Leaflet = FragmentLowerOrdersList[RootNr][0]; // set to insertion graph 720 FragmentSearch.setRoot(Walker); 721 NumMoleculesOfOrder[RootNr] = PSG(&FragmentSearch, Walker->AdaptiveOrder, CompleteMolecule); 716 FragmentLowerOrdersList[RootNr][0] = new Graph; 717 FragmentSearch.PrepareForPowersetGeneration(1., FragmentLowerOrdersList[RootNr][0], Walker); 718 NumMoleculesOfOrder[RootNr] = PSG(CompleteMolecule); 722 719 723 720 // output resulting number … … 734 731 RootStack.push_back(RootKeyNr); // put back on stack 735 732 RootNr++; 736 737 // free Order-dependent entries of UniqueFragments structure for next loop cycle738 FragmentSearch.FreeSPList(Order);739 733 } 740 734 }
Note:
See TracChangeset
for help on using the changeset viewer.