Changeset d2943b for src


Ignore:
Timestamp:
Oct 12, 2009, 12:49:19 PM (15 years ago)
Author:
Frederik Heber <heber@…>
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:
14e73a
Parents:
5034e1
Message:

Rewritten molecule::molecule::SPFragmentGenerator()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_fragmentation.cpp

    r5034e1 rd2943b  
    943943};
    944944
     945
     946/** Clears the touched list
     947 * \param *out output stream for debugging
     948 * \param verbosity verbosity level
     949 * \param *&TouchedList touched list
     950 * \param SubOrder current suborder
     951 * \param TouchedIndex currently touched
     952 */
     953void SPFragmentGenerator_ClearingTouched(ofstream *out, int verbosity, int *&TouchedList, int SubOrder, int &TouchedIndex)
     954{
     955  *out << Verbose(1+verbosity) << "Clearing touched list." << endl;
     956  for (TouchedIndex=SubOrder+1;TouchedIndex--;)  // empty touched list
     957    TouchedList[TouchedIndex] = -1;
     958  TouchedIndex = 0;
     959
     960}
     961
     962/** Adds the current combination of the power set to the snake stack.
     963 * \param *out output stream for debugging
     964 * \param verbosity verbosity level
     965 * \param CurrentCombination
     966 * \param SetDimension maximum number of bits in power set
     967 * \param *FragmentSet snake stack to remove from
     968 * \param *&TouchedList touched list
     969 * \param TouchedIndex currently touched
     970 * \return number of set bits
     971 */
     972int AddPowersetToSnakeStack(ofstream *out, int verbosity, int CurrentCombination, int SetDimension, KeySet *FragmentSet, bond **BondsSet, int *&TouchedList, int &TouchedIndex)
     973{
     974  atom *OtherWalker = NULL;
     975  bool bit = false;
     976  KeySetTestPair TestKeySetInsert;
     977
     978  int Added = 0;
     979  for (int j=0;j<SetDimension;j++) {  // pull out every bit by shifting
     980    bit = ((CurrentCombination & (1 << j)) != 0);  // mask the bit for the j-th bond
     981    if (bit) {  // if bit is set, we add this bond partner
     982      OtherWalker = BondsSet[j]->rightatom;  // rightatom is always the one more distant, i.e. the one to add
     983      //*out << Verbose(1+verbosity) << "Current Bond is " << ListOfBondsPerAtom[Walker->nr][CurrentCombination] << ", checking on " << *OtherWalker << "." << endl;
     984      *out << Verbose(2+verbosity) << "Adding " << *OtherWalker << " with nr " << OtherWalker->nr << "." << endl;
     985      TestKeySetInsert = FragmentSet->insert(OtherWalker->nr);
     986      if (TestKeySetInsert.second) {
     987        TouchedList[TouchedIndex++] = OtherWalker->nr;  // note as added
     988        Added++;
     989      } else {
     990        *out << Verbose(2+verbosity) << "This was item was already present in the keyset." << endl;
     991      }
     992    } else {
     993      *out << Verbose(2+verbosity) << "Not adding." << endl;
     994    }
     995  }
     996  return Added;
     997};
     998
     999/** Counts the number of elements in a power set.
     1000 * \param *SetFirst
     1001 * \param *SetLast
     1002 * \param *&TouchedList touched list
     1003 * \param TouchedIndex currently touched
     1004 * \return number of elements
     1005 */
     1006int CountSetMembers(bond *SetFirst, bond *SetLast, int *&TouchedList, int TouchedIndex)
     1007{
     1008  int SetDimension = 0;
     1009  bond *Binder = SetFirst;    // start node for this level
     1010  while (Binder->next != SetLast) {    // compare to end node of this level
     1011    Binder = Binder->next;
     1012    for (int k=TouchedIndex;k--;) {
     1013      if (Binder->Contains(TouchedList[k]))   // if we added this very endpiece
     1014        SetDimension++;
     1015    }
     1016  }
     1017  return SetDimension;
     1018};
     1019
     1020/** Counts the number of elements in a power set.
     1021 * \param *BondsList bonds list to fill
     1022 * \param *SetFirst
     1023 * \param *SetLast
     1024 * \param *&TouchedList touched list
     1025 * \param TouchedIndex currently touched
     1026 * \return number of elements
     1027 */
     1028int FillBondsList(bond **BondsList, bond *SetFirst, bond *SetLast, int *&TouchedList, int TouchedIndex)
     1029{
     1030  int SetDimension = 0;
     1031  bond *Binder = SetFirst;    // start node for this level
     1032  while (Binder->next != SetLast) {    // compare to end node of this level
     1033    Binder = Binder->next;
     1034    for (int k=0;k<TouchedIndex;k++) {
     1035      if (Binder->leftatom->nr == TouchedList[k])   // leftatom is always the close one
     1036        BondsList[SetDimension++] = Binder;
     1037    }
     1038  }
     1039  return SetDimension;
     1040};
     1041
     1042/** Remove all items that were added on this SP level.
     1043 * \param *out output stream for debugging
     1044 * \param verbosity verbosity level
     1045 * \param *FragmentSet snake stack to remove from
     1046 * \param *&TouchedList touched list
     1047 * \param TouchedIndex currently touched
     1048 */
     1049void RemoveAllTouchedFromSnakeStack(ofstream *out, int verbosity, KeySet *FragmentSet, int *&TouchedList, int &TouchedIndex)
     1050{
     1051  int Removal = 0;
     1052  for(int j=0;j<TouchedIndex;j++) {
     1053    Removal = TouchedList[j];
     1054    *out << Verbose(2+verbosity) << "Removing item nr. " << Removal << " from snake stack." << endl;
     1055    FragmentSet->erase(Removal);
     1056    TouchedList[j] = -1;
     1057  }
     1058  *out << Verbose(2) << "Remaining local nr.s on snake stack are: ";
     1059  for(KeySet::iterator runner = FragmentSet->begin(); runner != FragmentSet->end(); runner++)
     1060    *out << (*runner) << " ";
     1061  *out << endl;
     1062  TouchedIndex = 0; // set Index to 0 for list of atoms added on this level
     1063};
     1064
    9451065/** From a given set of Bond sorted by Shortest Path distance, create all possible fragments of size \a SetDimension.
    9461066 * -# loops over every possible combination (2^dimension of edge set)
     
    9591079void molecule::SPFragmentGenerator(ofstream *out, struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder)
    9601080{
    961   atom *OtherWalker = NULL;
    9621081  int verbosity = 0; //FragmentSearch->ANOVAOrder-SubOrder;
    9631082  int NumCombinations;
    964   bool bit;
    9651083  int bits, TouchedIndex, SubSetDimension, SP, Added;
    966   int Removal;
    9671084  int SpaceLeft;
    9681085  int *TouchedList = Malloc<int>(SubOrder + 1, "molecule::SPFragmentGenerator: *TouchedList");
    969   bond *Binder = NULL;
    9701086  bond **BondsList = NULL;
    9711087  KeySetTestPair TestKeySetInsert;
     
    9811097
    9821098  // initialised touched list (stores added atoms on this level)
    983   *out << Verbose(1+verbosity) << "Clearing touched list." << endl;
    984   for (TouchedIndex=SubOrder+1;TouchedIndex--;)  // empty touched list
    985     TouchedList[TouchedIndex] = -1;
    986   TouchedIndex = 0;
     1099  SPFragmentGenerator_ClearingTouched(out, verbosity, TouchedList, SubOrder, TouchedIndex);
    9871100
    9881101  // create every possible combination of the endpieces
     
    9971110    if (bits <= SubOrder) { // if not greater than additional atoms allowed on stack, continue
    9981111      // --1-- add this set of the power set of bond partners to the snake stack
    999       Added = 0;
    1000       for (int j=0;j<SetDimension;j++) {  // pull out every bit by shifting
    1001         bit = ((i & (1 << j)) != 0);  // mask the bit for the j-th bond
    1002         if (bit) {  // if bit is set, we add this bond partner
    1003           OtherWalker = BondsSet[j]->rightatom;  // rightatom is always the one more distant, i.e. the one to add
    1004           //*out << Verbose(1+verbosity) << "Current Bond is " << ListOfBondsPerAtom[Walker->nr][i] << ", checking on " << *OtherWalker << "." << endl;
    1005           *out << Verbose(2+verbosity) << "Adding " << *OtherWalker << " with nr " << OtherWalker->nr << "." << endl;
    1006           TestKeySetInsert = FragmentSearch->FragmentSet->insert(OtherWalker->nr);
    1007           if (TestKeySetInsert.second) {
    1008             TouchedList[TouchedIndex++] = OtherWalker->nr;  // note as added
    1009             Added++;
    1010           } else {
    1011             *out << Verbose(2+verbosity) << "This was item was already present in the keyset." << endl;
    1012           }
    1013             //FragmentSearch->UsedList[OtherWalker->nr][i] = true;
    1014           //}
    1015         } else {
    1016           *out << Verbose(2+verbosity) << "Not adding." << endl;
    1017         }
    1018       }
     1112      Added = AddPowersetToSnakeStack(out, verbosity, i, SetDimension, FragmentSearch->FragmentSet, BondsSet, TouchedList, TouchedIndex);
    10191113
    10201114      SpaceLeft = SubOrder - Added ;// SubOrder - bits; // due to item's maybe being already present, this does not work anymore
     
    10241118          // --2-- look at all added end pieces of this combination, construct bond subsets and sweep through a power set of these by recursion
    10251119          SP = RootDistance+1;  // this is the next level
     1120
    10261121          // first count the members in the subset
    1027           SubSetDimension = 0;
    1028           Binder = FragmentSearch->BondsPerSPList[2*SP];    // start node for this level
    1029           while (Binder->next != FragmentSearch->BondsPerSPList[2*SP+1]) {    // compare to end node of this level
    1030             Binder = Binder->next;
    1031             for (int k=TouchedIndex;k--;) {
    1032               if (Binder->Contains(TouchedList[k]))   // if we added this very endpiece
    1033                 SubSetDimension++;
    1034             }
    1035           }
     1122          SubSetDimension = CountSetMembers(FragmentSearch->BondsPerSPList[2*SP], FragmentSearch->BondsPerSPList[2*SP+1], TouchedList, TouchedIndex);
     1123
    10361124          // then allocate and fill the list
    10371125          BondsList = Malloc<bond*>(SubSetDimension, "molecule::SPFragmentGenerator: **BondsList");
    1038           SubSetDimension = 0;
    1039           Binder = FragmentSearch->BondsPerSPList[2*SP];
    1040           while (Binder->next != FragmentSearch->BondsPerSPList[2*SP+1]) {
    1041             Binder = Binder->next;
    1042             for (int k=0;k<TouchedIndex;k++) {
    1043               if (Binder->leftatom->nr == TouchedList[k])   // leftatom is always the close one
    1044                 BondsList[SubSetDimension++] = Binder;
    1045             }
    1046           }
     1126          SubSetDimension = FillBondsList(BondsList, FragmentSearch->BondsPerSPList[2*SP], FragmentSearch->BondsPerSPList[2*SP+1], TouchedList, TouchedIndex);
     1127
     1128          // then iterate
    10471129          *out << Verbose(2+verbosity) << "Calling subset generator " << SP << " away from root " << *FragmentSearch->Root << " with sub set dimension " << SubSetDimension << "." << endl;
    10481130          SPFragmentGenerator(out, FragmentSearch, SP, BondsList, SubSetDimension, SubOrder-bits);
     1131
    10491132          Free(&BondsList);
    10501133        }
     
    10601143          //*out << Verbose(0) << "ERROR: The found fragment is not a connected subgraph!" << endl;
    10611144        InsertFragmentIntoGraph(out, FragmentSearch);
    1062         //Removal = LookForRemovalCandidate(out, FragmentSearch->FragmentSet, FragmentSearch->ShortestPathList);
    1063         //Removal = StoreFragmentFromStack(out, FragmentSearch->Root, FragmentSearch->Leaflet, FragmentSearch->FragmentStack, FragmentSearch->ShortestPathList, &FragmentSearch->FragmentCounter, FragmentSearch->configuration);
    10641145      }
    10651146
    10661147      // --3-- remove all added items in this level from snake stack
    10671148      *out << Verbose(1+verbosity) << "Removing all items that were added on this SP level " << RootDistance << "." << endl;
    1068       for(int j=0;j<TouchedIndex;j++) {
    1069         Removal = TouchedList[j];
    1070         *out << Verbose(2+verbosity) << "Removing item nr. " << Removal << " from snake stack." << endl;
    1071         FragmentSearch->FragmentSet->erase(Removal);
    1072         TouchedList[j] = -1;
    1073       }
    1074       *out << Verbose(2) << "Remaining local nr.s on snake stack are: ";
    1075       for(KeySet::iterator runner = FragmentSearch->FragmentSet->begin(); runner != FragmentSearch->FragmentSet->end(); runner++)
    1076         *out << (*runner) << " ";
    1077       *out << endl;
    1078       TouchedIndex = 0; // set Index to 0 for list of atoms added on this level
     1149      RemoveAllTouchedFromSnakeStack(out, verbosity, FragmentSearch->FragmentSet, TouchedList, TouchedIndex);
    10791150    } else {
    10801151      *out << Verbose(2+verbosity) << "More atoms to add for this set (" << bits << ") than space left on stack " << SubOrder << ", skipping this set." << endl;
Note: See TracChangeset for help on using the changeset viewer.