Changeset f67817f
- 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:
- d0b375b
- Parents:
- 23fb72
- git-author:
- Frederik Heber <heber@…> (10/18/11 12:26:01)
- git-committer:
- Frederik Heber <heber@…> (10/25/11 12:08:03)
- Location:
- src
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Makefile.am
r23fb72 rf67817f 10 10 Fragmentation/KeySetsContainer.cpp \ 11 11 Fragmentation/MatrixContainer.cpp \ 12 Fragmentation/PowerSetGenerator.cpp \ 12 13 Fragmentation/UniqueFragments.cpp 13 14 … … 15 16 Fragmentation/defs.hpp \ 16 17 Fragmentation/EnergyMatrix.hpp \ 18 Fragmentation/ForceMatrix.hpp \ 17 19 Fragmentation/fragmentation_helpers.hpp \ 18 Fragmentation/ForceMatrix.hpp \19 20 Fragmentation/helpers.hpp \ 20 21 Fragmentation/HessianMatrix.hpp \ 21 22 Fragmentation/KeySetsContainer.hpp \ 22 23 Fragmentation/MatrixContainer.hpp \ 24 Fragmentation/PowerSetGenerator.hpp \ 23 25 Fragmentation/UniqueFragments.hpp 24 26 -
src/Fragmentation/fragmentation_helpers.cpp
r23fb72 rf67817f 426 426 427 427 428 /** Clears the touched list429 * \param *out output stream for debugging430 * \param verbosity verbosity level431 * \param *&TouchedList touched list432 * \param SubOrder current suborder433 * \param TouchedIndex currently touched434 */435 void SPFragmentGenerator_ClearingTouched(int verbosity, int *&TouchedList, int SubOrder, int &TouchedIndex)436 {437 Log() << Verbose(1+verbosity) << "Clearing touched list." << endl;438 for (TouchedIndex=SubOrder+1;TouchedIndex--;) // empty touched list439 TouchedList[TouchedIndex] = -1;440 TouchedIndex = 0;441 442 }443 444 /** Adds the current combination of the power set to the snake stack.445 * \param *out output stream for debugging446 * \param verbosity verbosity level447 * \param CurrentCombination448 * \param SetDimension maximum number of bits in power set449 * \param *FragmentSet snake stack to remove from450 * \param &BondsSet set of bonds451 * \param *&TouchedList touched list452 * \param TouchedIndex currently touched453 * \return number of set bits454 */455 int AddPowersetToSnakeStack(int verbosity, int CurrentCombination, int SetDimension, KeySet *FragmentSet, std::vector<bond *> &BondsSet, int *&TouchedList, int &TouchedIndex)456 {457 atom *OtherWalker = NULL;458 bool bit = false;459 KeySetTestPair TestKeySetInsert;460 461 int Added = 0;462 for (int j=0;j<SetDimension;j++) { // pull out every bit by shifting463 bit = ((CurrentCombination & (1 << j)) != 0); // mask the bit for the j-th bond464 if (bit) { // if bit is set, we add this bond partner465 OtherWalker = BondsSet[j]->rightatom; // rightatom is always the one more distant, i.e. the one to add466 //Log() << Verbose(1+verbosity) << "Current Bond is " << BondsSet[j] << ", checking on " << *OtherWalker << "." << endl;467 Log() << Verbose(2+verbosity) << "Adding " << *OtherWalker << " with nr " << OtherWalker->getNr() << "." << endl;468 TestKeySetInsert = FragmentSet->insert(OtherWalker->getNr());469 if (TestKeySetInsert.second) {470 TouchedList[TouchedIndex++] = OtherWalker->getNr(); // note as added471 Added++;472 } else {473 Log() << Verbose(2+verbosity) << "This was item was already present in the keyset." << endl;474 }475 } else {476 Log() << Verbose(2+verbosity) << "Not adding." << endl;477 }478 }479 return Added;480 };481 482 /** Counts the number of elements in a power set.483 * \param SetFirst begin iterator first bond484 * \param SetLast end iterator485 * \param *&TouchedList touched list486 * \param TouchedIndex currently touched487 * \return number of elements488 */489 int CountSetMembers(std::list<bond *>::const_iterator SetFirst, std::list<bond *>::const_iterator SetLast, int *&TouchedList, int TouchedIndex)490 {491 int SetDimension = 0;492 for( std::list<bond *>::const_iterator Binder = SetFirst;493 Binder != SetLast;494 ++Binder) {495 for (int k=TouchedIndex;k--;) {496 if ((*Binder)->Contains(TouchedList[k])) // if we added this very endpiece497 SetDimension++;498 }499 }500 return SetDimension;501 };502 503 /** Fills a list of bonds from another504 * \param *BondsList bonds array/vector to fill505 * \param SetFirst begin iterator first bond506 * \param SetLast end iterator507 * \param *&TouchedList touched list508 * \param TouchedIndex currently touched509 * \return number of elements510 */511 int FillBondsList(std::vector<bond *> &BondsList, std::list<bond *>::const_iterator SetFirst, std::list<bond *>::const_iterator SetLast, int *&TouchedList, int TouchedIndex)512 {513 int SetDimension = 0;514 for( std::list<bond *>::const_iterator Binder = SetFirst;515 Binder != SetLast;516 ++Binder) {517 for (int k=0;k<TouchedIndex;k++) {518 if ((*Binder)->leftatom->getNr() == TouchedList[k]) // leftatom is always the closer one519 BondsList[SetDimension++] = (*Binder);520 }521 }522 return SetDimension;523 };524 525 /** Remove all items that were added on this SP level.526 * \param *out output stream for debugging527 * \param verbosity verbosity level528 * \param *FragmentSet snake stack to remove from529 * \param *&TouchedList touched list530 * \param TouchedIndex currently touched531 */532 void RemoveAllTouchedFromSnakeStack(int verbosity, KeySet *FragmentSet, int *&TouchedList, int &TouchedIndex)533 {534 int Removal = 0;535 for(int j=0;j<TouchedIndex;j++) {536 Removal = TouchedList[j];537 Log() << Verbose(2+verbosity) << "Removing item nr. " << Removal << " from snake stack." << endl;538 FragmentSet->erase(Removal);539 TouchedList[j] = -1;540 }541 DoLog(2) && (Log() << Verbose(2) << "Remaining local nr.s on snake stack are: ");542 for(KeySet::iterator runner = FragmentSet->begin(); runner != FragmentSet->end(); runner++)543 DoLog(0) && (Log() << Verbose(0) << (*runner) << " ");544 DoLog(0) && (Log() << Verbose(0) << endl);545 TouchedIndex = 0; // set Index to 0 for list of atoms added on this level546 };547 548 549 428 bool KeyCompare::operator() (const KeySet SubgraphA, const KeySet SubgraphB) const 550 429 { -
src/Fragmentation/fragmentation_helpers.hpp
r23fb72 rf67817f 36 36 bool MarkUpdateCandidates(bool *AtomMask, std::map<double, std::pair<int,int> > &FinalRootCandidates, int Order, molecule *mol); 37 37 void PrintAtomMask(bool *AtomMask, int AtomCount); 38 void SPFragmentGenerator_ClearingTouched(int verbosity, int *&TouchedList, int SubOrder, int &TouchedIndex);39 int AddPowersetToSnakeStack(int verbosity, int CurrentCombination, int SetDimension, KeySet *FragmentSet, std::vector<bond *> &BondsSet, int *&TouchedList, int &TouchedIndex);40 int CountSetMembers(std::list<bond *>::const_iterator SetFirst, std::list<bond *>::const_iterator SetLast, int *&TouchedList, int TouchedIndex);41 int FillBondsList(std::vector<bond *> &BondsList, std::list<bond *>::const_iterator SetFirst, std::list<bond *>::const_iterator SetLast, int *&TouchedList, int TouchedIndex);42 void RemoveAllTouchedFromSnakeStack(int verbosity, KeySet *FragmentSet, int *&TouchedList, int &TouchedIndex);43 38 44 39 int CombineAllOrderListIntoOne(Graph *&FragmentList, Graph ***FragmentLowerOrdersList, KeyStack &RootStack, molecule *mol); -
src/molecule.hpp
r23fb72 rf67817f 224 224 /// -# BOSSANOVA 225 225 void FragmentBOSSANOVA(Graph *&FragmentList, KeyStack &RootStack); 226 int PowerSetGenerator(int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);227 226 molecule * StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem); 228 void SPFragmentGenerator(struct UniqueFragments *FragmentSearch, int RootDistance, std::vector<bond *> &BondsSet, int SetDimension, int SubOrder);229 227 int LookForRemovalCandidate(KeySet *&Leaf, int *&ShortestPathList); 230 228 int GuesstimateFragmentCount(int order); -
src/molecule_fragmentation.cpp
r23fb72 rf67817f 31 31 #include "Element/periodentafel.hpp" 32 32 #include "Fragmentation/fragmentation_helpers.hpp" 33 #include "Fragmentation/PowerSetGenerator.hpp" 33 34 #include "Fragmentation/UniqueFragments.hpp" 34 35 #include "Graph/BondGraph.hpp" … … 658 659 }; 659 660 660 /** From a given set of Bond sorted by Shortest Path distance, create all possible fragments of size \a SetDimension.661 * -# loops over every possible combination (2^dimension of edge set)662 * -# inserts current set, if there's still space left663 * -# yes: calls SPFragmentGenerator with structure, created new edge list and size respective to root dist664 ance+1665 * -# no: stores fragment into keyset list by calling InsertFragmentIntoGraph666 * -# removes all items added into the snake stack (in UniqueFragments structure) added during level (root667 distance) and current set668 * \param FragmentSearch UniqueFragments structure with all values needed669 * \param RootDistance current shortest path level, whose set of edges is represented by **BondsSet670 * \param BondsSet array of bonds to check671 * \param SetDimension Number of possible bonds on this level (i.e. size of the array BondsSet[])672 * \param SubOrder remaining number of allowed vertices to add673 */674 void molecule::SPFragmentGenerator(struct UniqueFragments *FragmentSearch, int RootDistance, std::vector<bond *> &BondsSet, int SetDimension, int SubOrder)675 {676 int verbosity = 0; //FragmentSearch->ANOVAOrder-SubOrder;677 int NumCombinations;678 int bits, TouchedIndex, SubSetDimension, SP, Added;679 int SpaceLeft;680 int *TouchedList = new int[SubOrder + 1];681 KeySetTestPair TestKeySetInsert;682 683 NumCombinations = 1 << SetDimension;684 685 // here for all bonds of Walker all combinations of end pieces (from the bonds)686 // have to be added and for the remaining ANOVA order GraphCrawler be called687 // recursively for the next level688 689 Log() << Verbose(1+verbosity) << "Begin of SPFragmentGenerator." << endl;690 Log() << Verbose(1+verbosity) << "We are " << RootDistance << " away from Root, which is " << *FragmentSearch->getRoot() << ", SubOrder is " << SubOrder << ", SetDimension is " << SetDimension << " and this means " << NumCombinations-1 << " combination(s)." << endl;691 692 // initialised touched list (stores added atoms on this level)693 SPFragmentGenerator_ClearingTouched(verbosity, TouchedList, SubOrder, TouchedIndex);694 695 // create every possible combination of the endpieces696 Log() << Verbose(1+verbosity) << "Going through all combinations of the power set." << endl;697 for (int i=1;i<NumCombinations;i++) { // sweep through all power set combinations (skip empty set!)698 // count the set bit of i699 bits = 0;700 for (int j=SetDimension;j--;)701 bits += (i & (1 << j)) >> j;702 703 Log() << Verbose(1+verbosity) << "Current set is " << Binary(i | (1 << SetDimension)) << ", number of bits is " << bits << "." << endl;704 if (bits <= SubOrder) { // if not greater than additional atoms allowed on stack, continue705 // --1-- add this set of the power set of bond partners to the snake stack706 Added = AddPowersetToSnakeStack(verbosity, i, SetDimension, FragmentSearch->FragmentSet, BondsSet, TouchedList, TouchedIndex);707 708 SpaceLeft = SubOrder - Added ;// SubOrder - bits; // due to item's maybe being already present, this does not work anymore709 if (SpaceLeft > 0) {710 Log() << Verbose(1+verbosity) << "There's still some space left on stack: " << SpaceLeft << "." << endl;711 if (SubOrder > 1) { // Due to Added above we have to check extra whether we're not already reaching beyond the desired Order712 // --2-- look at all added end pieces of this combination, construct bond subsets and sweep through a power set of these by recursion713 SP = RootDistance+1; // this is the next level714 715 // first count the members in the subset716 SubSetDimension = CountSetMembers(FragmentSearch->BondsPerSPList[SP].begin(), FragmentSearch->BondsPerSPList[SP].end(), TouchedList, TouchedIndex);717 718 // then allocate and fill the list719 std::vector<bond *> BondsList;720 BondsList.resize(SubSetDimension);721 SubSetDimension = FillBondsList(BondsList, FragmentSearch->BondsPerSPList[SP].begin(), FragmentSearch->BondsPerSPList[SP].end(), TouchedList, TouchedIndex);722 723 // then iterate724 Log() << Verbose(2+verbosity) << "Calling subset generator " << SP << " away from root " << *FragmentSearch->getRoot() << " with sub set dimension " << SubSetDimension << "." << endl;725 SPFragmentGenerator(FragmentSearch, SP, BondsList, SubSetDimension, SubOrder-bits);726 }727 } else {728 // --2-- otherwise store the complete fragment729 Log() << Verbose(1+verbosity) << "Enough items on stack for a fragment!" << endl;730 // store fragment as a KeySet731 DoLog(2) && (Log() << Verbose(2) << "Found a new fragment[" << FragmentSearch->FragmentCounter << "], local nr.s are: ");732 for(KeySet::iterator runner = FragmentSearch->FragmentSet->begin(); runner != FragmentSearch->FragmentSet->end(); runner++)733 DoLog(0) && (Log() << Verbose(0) << (*runner) << " ");734 DoLog(0) && (Log() << Verbose(0) << endl);735 FragmentSearch->InsertFragmentIntoGraph();736 }737 738 // --3-- remove all added items in this level from snake stack739 Log() << Verbose(1+verbosity) << "Removing all items that were added on this SP level " << RootDistance << "." << endl;740 RemoveAllTouchedFromSnakeStack(verbosity, FragmentSearch->FragmentSet, TouchedList, TouchedIndex);741 } else {742 Log() << Verbose(2+verbosity) << "More atoms to add for this set (" << bits << ") than space left on stack " << SubOrder << ", skipping this set." << endl;743 }744 }745 delete[](TouchedList);746 Log() << Verbose(1+verbosity) << "End of SPFragmentGenerator, " << RootDistance << " away from Root " << *FragmentSearch->getRoot() << " and SubOrder is " << SubOrder << "." << endl;747 };748 749 750 /** Creates a list of all unique fragments of certain vertex size from a given graph \a Fragment for a given root vertex in the context of \a this molecule.751 * -# initialises UniqueFragments structure752 * -# fills edge list via BFS753 * -# creates the fragment by calling recursive function SPFragmentGenerator with UniqueFragments structure, 0 as754 root distance, the edge set, its dimension and the current suborder755 * -# Free'ing structure756 * 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 all757 * with SP of 2, then those with SP of 3, then those with SP of 4 and so on.758 * \param *out output stream for debugging759 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation760 * \param FragmentSearch UniqueFragments structure containing TEFactor, root atom and so on761 * \param RestrictedKeySet Restricted vertex set to use in context of molecule762 * \return number of inserted fragments763 * \note ShortestPathList in FragmentSearch structure is probably due to NumberOfAtomsSPLevel and SP not needed anymore764 */765 int molecule::PowerSetGenerator(int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet)766 {767 int Counter = FragmentSearch.FragmentCounter; // mark current value of counter768 769 DoLog(0) && (Log() << Verbose(0) << endl);770 DoLog(0) && (Log() << Verbose(0) << "Begin of PowerSetGenerator with order " << Order << " at Root " << *FragmentSearch.getRoot() << "." << endl);771 772 FragmentSearch.SetSPList(Order);773 774 // do a BFS search to fill the SP lists and label the found vertices775 FragmentSearch.FillSPListandLabelVertices(Order, RestrictedKeySet);776 777 // outputting all list for debugging778 FragmentSearch.OutputSPList(Order);779 780 // creating fragments with the found edge sets (may be done in reverse order, faster)781 int SP = FragmentSearch.CountNumbersInBondsList(Order);782 DoLog(0) && (Log() << Verbose(0) << "Total number of edges is " << SP << "." << endl);783 if (SP >= (Order-1)) {784 // start with root (push on fragment stack)785 DoLog(0) && (Log() << Verbose(0) << "Starting fragment generation with " << *FragmentSearch.getRoot() << ", local nr is " << FragmentSearch.getRoot()->getNr() << "." << endl);786 FragmentSearch.FragmentSet->clear();787 DoLog(0) && (Log() << Verbose(0) << "Preparing subset for this root and calling generator." << endl);788 789 // prepare the subset and call the generator790 std::vector<bond*> BondsList;791 BondsList.resize(FragmentSearch.BondsPerSPCount[0]);792 ASSERT(FragmentSearch.BondsPerSPList[0].size() != 0,793 "molecule::PowerSetGenerator() - FragmentSearch.BondsPerSPList[0] contains no root bond.");794 BondsList[0] = (*FragmentSearch.BondsPerSPList[0].begin()); // on SP level 0 there's only the root bond795 796 SPFragmentGenerator(&FragmentSearch, 0, BondsList, FragmentSearch.BondsPerSPCount[0], Order);797 } else {798 DoLog(0) && (Log() << Verbose(0) << "Not enough total number of edges to build " << Order << "-body fragments." << endl);799 }800 801 // as FragmentSearch structure is used only once, we don't have to clean it anymore802 // remove root from stack803 DoLog(0) && (Log() << Verbose(0) << "Removing root again from stack." << endl);804 FragmentSearch.FragmentSet->erase(FragmentSearch.getRoot()->getNr());805 806 // free'ing the bonds lists807 FragmentSearch.ResetSPList(Order);808 809 // return list810 DoLog(0) && (Log() << Verbose(0) << "End of PowerSetGenerator." << endl);811 return (FragmentSearch.FragmentCounter - Counter);812 };813 814 815 816 817 661 /** Performs BOSSANOVA decomposition at selected sites, increasing the cutoff by one at these sites. 818 662 * -# constructs a complete keyset of the molecule … … 844 688 int RootNr = 0; 845 689 struct UniqueFragments FragmentSearch; 690 class PowerSetGenerator PSG; 846 691 847 692 DoLog(0) && (Log() << Verbose(0) << "Begin of FragmentBOSSANOVA." << endl); … … 901 746 FragmentSearch.Leaflet = FragmentLowerOrdersList[RootNr][0]; // set to insertion graph 902 747 FragmentSearch.setRoot(Walker); 903 NumMoleculesOfOrder[RootNr] = P owerSetGenerator(Walker->AdaptiveOrder, FragmentSearch, CompleteMolecule);748 NumMoleculesOfOrder[RootNr] = PSG(&FragmentSearch, Walker->AdaptiveOrder, CompleteMolecule); 904 749 905 750 // output resulting number
Note:
See TracChangeset
for help on using the changeset viewer.