Ignore:
Timestamp:
Feb 24, 2011, 7:43:03 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, Candidate_v1.7.0, 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:
6a465e
Parents:
8aba3c
git-author:
Frederik Heber <heber@…> (02/16/11 14:02:14)
git-committer:
Frederik Heber <heber@…> (02/24/11 19:43:03)
Message:

bonds::previous and ::next removed, lists.hpp deleted.

  • the last of the concatenated lists has fallen to STL lists and vectors.
  • greatest impact is on fragmentation functions.
  • rewritten UniqueFragments::BondsPerSPList to vector<list<bond*> >.
  • removed include of lists.hpp.
  • removed lists.hpp from Makefile.am.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule_fragmentation.cpp

    r8aba3c r03c77c  
    2828#include "element.hpp"
    2929#include "Helpers/helpers.hpp"
    30 #include "lists.hpp"
    3130#include "CodePatterns/Verbose.hpp"
    3231#include "CodePatterns/Log.hpp"
     
    11051104 * \param SetDimension maximum number of bits in power set
    11061105 * \param *FragmentSet snake stack to remove from
     1106 * \param &BondsSet set of bonds
    11071107 * \param *&TouchedList touched list
    11081108 * \param TouchedIndex currently touched
    11091109 * \return number of set bits
    11101110 */
    1111 int AddPowersetToSnakeStack(int verbosity, int CurrentCombination, int SetDimension, KeySet *FragmentSet, bond **BondsSet, int *&TouchedList, int &TouchedIndex)
     1111int AddPowersetToSnakeStack(int verbosity, int CurrentCombination, int SetDimension, KeySet *FragmentSet, std::vector<bond *> &BondsSet, int *&TouchedList, int &TouchedIndex)
    11121112{
    11131113  atom *OtherWalker = NULL;
     
    11371137
    11381138/** Counts the number of elements in a power set.
    1139  * \param *SetFirst
    1140  * \param *SetLast
     1139 * \param SetFirst begin iterator first bond
     1140 * \param SetLast end iterator
    11411141 * \param *&TouchedList touched list
    11421142 * \param TouchedIndex currently touched
    11431143 * \return number of elements
    11441144 */
    1145 int CountSetMembers(bond *SetFirst, bond *SetLast, int *&TouchedList, int TouchedIndex)
     1145int CountSetMembers(std::list<bond *>::const_iterator SetFirst, std::list<bond *>::const_iterator SetLast, int *&TouchedList, int TouchedIndex)
    11461146{
    11471147  int SetDimension = 0;
    1148   bond *Binder = SetFirst;    // start node for this level
    1149   while (Binder->next != SetLast) {    // compare to end node of this level
    1150     Binder = Binder->next;
     1148  for( std::list<bond *>::const_iterator Binder = SetFirst;
     1149      Binder != SetLast;
     1150      ++Binder) {
    11511151    for (int k=TouchedIndex;k--;) {
    1152       if (Binder->Contains(TouchedList[k]))   // if we added this very endpiece
     1152      if ((*Binder)->Contains(TouchedList[k]))   // if we added this very endpiece
    11531153        SetDimension++;
    11541154    }
     
    11571157};
    11581158
    1159 /** Counts the number of elements in a power set.
    1160  * \param *BondsList bonds list to fill
    1161  * \param *SetFirst
    1162  * \param *SetLast
     1159/** Fills a list of bonds from another
     1160 * \param *BondsList bonds array/vector to fill
     1161 * \param SetFirst begin iterator first bond
     1162 * \param SetLast end iterator
    11631163 * \param *&TouchedList touched list
    11641164 * \param TouchedIndex currently touched
    11651165 * \return number of elements
    11661166 */
    1167 int FillBondsList(bond **BondsList, bond *SetFirst, bond *SetLast, int *&TouchedList, int TouchedIndex)
     1167int FillBondsList(std::vector<bond *> &BondsList, std::list<bond *>::const_iterator SetFirst, std::list<bond *>::const_iterator SetLast, int *&TouchedList, int TouchedIndex)
    11681168{
    11691169  int SetDimension = 0;
    1170   bond *Binder = SetFirst;    // start node for this level
    1171   while (Binder->next != SetLast) {    // compare to end node of this level
    1172     Binder = Binder->next;
     1170  for( std::list<bond *>::const_iterator Binder = SetFirst;
     1171      Binder != SetLast;
     1172      ++Binder) {
    11731173    for (int k=0;k<TouchedIndex;k++) {
    1174       if (Binder->leftatom->nr == TouchedList[k])   // leftatom is always the close one
    1175         BondsList[SetDimension++] = Binder;
     1174      if ((*Binder)->leftatom->nr == TouchedList[k])   // leftatom is always the closer one
     1175        BondsList[SetDimension++] = (*Binder);
    11761176    }
    11771177  }
     
    12101210 *  -# removes all items added into the snake stack (in UniqueFragments structure) added during level (root
    12111211distance) and current set
    1212  * \param *out output stream for debugging
    12131212 * \param FragmentSearch UniqueFragments structure with all values needed
    12141213 * \param RootDistance current shortest path level, whose set of edges is represented by **BondsSet
     1214 * \param BondsSet array of bonds to check
    12151215 * \param SetDimension Number of possible bonds on this level (i.e. size of the array BondsSet[])
    12161216 * \param SubOrder remaining number of allowed vertices to add
    12171217 */
    1218 void molecule::SPFragmentGenerator(struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder)
     1218void molecule::SPFragmentGenerator(struct UniqueFragments *FragmentSearch, int RootDistance, std::vector<bond *> &BondsSet, int SetDimension, int SubOrder)
    12191219{
    12201220  int verbosity = 0; //FragmentSearch->ANOVAOrder-SubOrder;
     
    12581258
    12591259          // first count the members in the subset
    1260           SubSetDimension = CountSetMembers(FragmentSearch->BondsPerSPList[2*SP], FragmentSearch->BondsPerSPList[2*SP+1], TouchedList, TouchedIndex);
     1260          SubSetDimension = CountSetMembers(FragmentSearch->BondsPerSPList[SP].begin(), FragmentSearch->BondsPerSPList[SP].end(), TouchedList, TouchedIndex);
    12611261
    12621262          // then allocate and fill the list
    1263           bond *BondsList[SubSetDimension];
    1264           SubSetDimension = FillBondsList(BondsList, FragmentSearch->BondsPerSPList[2*SP], FragmentSearch->BondsPerSPList[2*SP+1], TouchedList, TouchedIndex);
     1263          std::vector<bond *> BondsList;
     1264          BondsList.resize(SubSetDimension);
     1265          SubSetDimension = FillBondsList(BondsList, FragmentSearch->BondsPerSPList[SP].begin(), FragmentSearch->BondsPerSPList[SP].end(), TouchedList, TouchedIndex);
    12651266
    12661267          // then iterate
     
    13001301void InitialiseSPList(int Order, struct UniqueFragments &FragmentSearch)
    13011302{
    1302   FragmentSearch.BondsPerSPList = new bond* [Order * 2];
     1303  FragmentSearch.BondsPerSPList.resize(Order);
    13031304  FragmentSearch.BondsPerSPCount = new int[Order];
    13041305  for (int i=Order;i--;) {
    1305     FragmentSearch.BondsPerSPList[2*i] = new bond();    // start node
    1306     FragmentSearch.BondsPerSPList[2*i+1] = new bond();  // end node
    1307     FragmentSearch.BondsPerSPList[2*i]->next = FragmentSearch.BondsPerSPList[2*i+1];     // intertwine these two
    1308     FragmentSearch.BondsPerSPList[2*i+1]->previous = FragmentSearch.BondsPerSPList[2*i];
    13091306    FragmentSearch.BondsPerSPCount[i] = 0;
    13101307  }
     
    13201317{
    13211318  delete[](FragmentSearch.BondsPerSPCount);
    1322   for (int i=Order;i--;) {
    1323     delete(FragmentSearch.BondsPerSPList[2*i]);
    1324     delete(FragmentSearch.BondsPerSPList[2*i+1]);
    1325   }
    1326   delete[](FragmentSearch.BondsPerSPList);
    13271319};
    13281320
     
    13451337  FragmentSearch.BondsPerSPCount[0] = 1;
    13461338  bond *Binder = new bond(FragmentSearch.Root, FragmentSearch.Root);
    1347   add(Binder, FragmentSearch.BondsPerSPList[1]);
     1339  FragmentSearch.BondsPerSPList[0].push_back(Binder);
    13481340};
    13491341
     
    13561348void ResetSPList(int Order, struct UniqueFragments &FragmentSearch)
    13571349{
    1358   bond *Binder = NULL;
    13591350  DoLog(0) && (Log() << Verbose(0) << "Free'ing all found lists. and resetting index lists" << endl);
    13601351  for(int i=Order;i--;) {
    13611352    DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << ": ");
    1362     Binder = FragmentSearch.BondsPerSPList[2*i];
    1363     while (Binder->next != FragmentSearch.BondsPerSPList[2*i+1]) {
    1364       Binder = Binder->next;
     1353    for (UniqueFragments::BondsPerSP::const_iterator iter = FragmentSearch.BondsPerSPList[i].begin();
     1354        iter != FragmentSearch.BondsPerSPList[i].end();
     1355        ++iter) {
    13651356      // Log() << Verbose(0) << "Removing atom " << Binder->leftatom->nr << " and " << Binder->rightatom->nr << "." << endl; // make sure numbers are local
    1366       FragmentSearch.ShortestPathList[Binder->leftatom->nr] = -1;
    1367       FragmentSearch.ShortestPathList[Binder->rightatom->nr] = -1;
     1357      FragmentSearch.ShortestPathList[(*iter)->leftatom->nr] = -1;
     1358      FragmentSearch.ShortestPathList[(*iter)->rightatom->nr] = -1;
    13681359    }
    13691360    // delete added bonds
    1370     cleanup(FragmentSearch.BondsPerSPList[2*i], FragmentSearch.BondsPerSPList[2*i+1]);
     1361    for (UniqueFragments::BondsPerSP::iterator iter = FragmentSearch.BondsPerSPList[i].begin();
     1362        iter != FragmentSearch.BondsPerSPList[i].end();
     1363        ++iter) {
     1364      delete(*iter);
     1365    }
     1366    FragmentSearch.BondsPerSPList[i].clear();
    13711367    // also start and end node
    13721368    DoLog(0) && (Log() << Verbose(0) << "cleaned." << endl);
     
    13941390  atom *OtherWalker = NULL;
    13951391  atom *Predecessor = NULL;
    1396   bond *CurrentEdge = NULL;
    13971392  bond *Binder = NULL;
    13981393  int RootKeyNr = FragmentSearch.Root->GetTrueFather()->nr;
     
    14101405
    14111406    RemainingWalkers = FragmentSearch.BondsPerSPCount[SP];
    1412     CurrentEdge = FragmentSearch.BondsPerSPList[2*SP];    /// start of this SP level's list
    1413     while (CurrentEdge->next != FragmentSearch.BondsPerSPList[2*SP+1]) {    /// end of this SP level's list
    1414       CurrentEdge = CurrentEdge->next;
     1407    for (UniqueFragments::BondsPerSP::const_iterator CurrentEdge = FragmentSearch.BondsPerSPList[SP].begin();
     1408        CurrentEdge != FragmentSearch.BondsPerSPList[SP].end();
     1409        ++CurrentEdge) { /// start till end of this SP level's list
    14151410      RemainingWalkers--;
    1416       Walker = CurrentEdge->rightatom;    // rightatom is always the one more distant
    1417       Predecessor = CurrentEdge->leftatom;    // ... and leftatom is predecessor
     1411      Walker = (*CurrentEdge)->rightatom;    // rightatom is always the one more distant
     1412      Predecessor = (*CurrentEdge)->leftatom;    // ... and leftatom is predecessor
    14181413      AtomKeyNr = Walker->nr;
    14191414      DoLog(0) && (Log() << Verbose(0) << "Current Walker is: " << *Walker << " with nr " << Walker->nr << " and SP of " << SP << ", with " << RemainingWalkers << " remaining walkers on this level." << endl);
     
    14381433            // add the bond in between to the SP list
    14391434            Binder = new bond(Walker, OtherWalker); // create a new bond in such a manner, that bond::rightatom is always the one more distant
    1440             add(Binder, FragmentSearch.BondsPerSPList[2*(SP+1)+1]);
     1435            FragmentSearch.BondsPerSPList[SP+1].push_back(Binder);
    14411436            FragmentSearch.BondsPerSPCount[SP+1]++;
    14421437            DoLog(3) && (Log() << Verbose(3) << "Added its bond to SP list, having now " << FragmentSearch.BondsPerSPCount[SP+1] << " item(s)." << endl);
     
    14601455void OutputSPList(int Order, struct UniqueFragments &FragmentSearch)
    14611456{
    1462   bond *Binder = NULL;
    14631457  DoLog(0) && (Log() << Verbose(0) << "Printing all found lists." << endl);
    14641458  for(int i=1;i<Order;i++) {    // skip the root edge in the printing
    1465     Binder = FragmentSearch.BondsPerSPList[2*i];
    14661459    DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << "." << endl);
    1467     while (Binder->next != FragmentSearch.BondsPerSPList[2*i+1]) {
    1468       Binder = Binder->next;
     1460    for (UniqueFragments::BondsPerSP::const_iterator Binder = FragmentSearch.BondsPerSPList[i].begin();
     1461        Binder != FragmentSearch.BondsPerSPList[i].end();
     1462        ++Binder) {
    14691463      DoLog(2) && (Log() << Verbose(2) << *Binder << endl);
    14701464    }
     
    14791473int CountNumbersInBondsList(int Order, struct UniqueFragments &FragmentSearch)
    14801474{
    1481   bond *Binder = NULL;
    14821475  int SP = -1;  // the Root <-> Root edge must be subtracted!
    14831476  for(int i=Order;i--;) { // sum up all found edges
    1484     Binder = FragmentSearch.BondsPerSPList[2*i];
    1485     while (Binder->next != FragmentSearch.BondsPerSPList[2*i+1]) {
    1486       Binder = Binder->next;
     1477    for (UniqueFragments::BondsPerSP::const_iterator Binder = FragmentSearch.BondsPerSPList[i].begin();
     1478        Binder != FragmentSearch.BondsPerSPList[i].end();
     1479        ++Binder) {
    14871480      SP++;
    14881481    }
     
    15311524
    15321525    // prepare the subset and call the generator
    1533     bond* BondsList[FragmentSearch.BondsPerSPCount[0]];
    1534     for(int i=0;i<FragmentSearch.BondsPerSPCount[0];i++)
    1535       BondsList[i] = NULL;
    1536     BondsList[0] = FragmentSearch.BondsPerSPList[0]->next;  // on SP level 0 there's only the root bond
     1526    std::vector<bond*> BondsList;
     1527    BondsList.resize(FragmentSearch.BondsPerSPCount[0]);
     1528    ASSERT(FragmentSearch.BondsPerSPList[0].size() != 0,
     1529        "molecule::PowerSetGenerator() - FragmentSearch.BondsPerSPList[0] contains no root bond.");
     1530    BondsList[0] = (*FragmentSearch.BondsPerSPList[0].begin());  // on SP level 0 there's only the root bond
    15371531
    15381532    SPFragmentGenerator(&FragmentSearch, 0, BondsList, FragmentSearch.BondsPerSPCount[0], Order);
     
    17971791{
    17981792  bond *Binder = NULL;
    1799   bond *OtherBinder = NULL;
     1793  //bond *OtherBinder = NULL;
    18001794  atom *Walker = NULL;
    18011795  atom *OtherWalker = NULL;
     
    18031797  enum Shading *ColorList = NULL;
    18041798  double tmp;
    1805   bool LastBond = true; // only needed to due list construct
     1799  //bool LastBond = true; // only needed to due list construct
    18061800  Vector Translationvector;
    18071801  //std::deque<atom *> *CompStack = NULL;
     
    18291823          //Log() << Verbose(3) << "Checking " << i << "th distance of " << *Binder->leftatom << " to " << *Binder->rightatom << ": " << tmp << "." << endl;
    18301824          if (tmp > BondDistance) {
    1831 //            OtherBinder = Binder->next; // note down binding partner for later re-insertion
    1832 //            if (OtherBinder != NULL) {
    1833 //              LastBond = false;
    1834 //            } else {
    1835 //              OtherBinder = Binder->previous;
    1836 //              LastBond = true;
    1837 //            }
    1838 //            unlink(Binder);   // unlink bond
    18391825            DoLog(2) && (Log() << Verbose(2) << "Correcting at bond " << *Binder << "." << endl);
    18401826            flag = true;
     
    18771863        }
    18781864      }
    1879       // re-add bond
    1880       if (OtherBinder == NULL) { // is the only bond?
    1881         //Do nothing
    1882       } else {
    1883         if (!LastBond) {
    1884           link(Binder, OtherBinder);
    1885         } else {
    1886           link(OtherBinder, Binder);
    1887         }
    1888       }
     1865//      // re-add bond
     1866//      if (OtherBinder == NULL) { // is the only bond?
     1867//        //Do nothing
     1868//      } else {
     1869//        if (!LastBond) {
     1870//          link(Binder, OtherBinder); // no more implemented bond::previous ...
     1871//        } else {
     1872//          link(OtherBinder, Binder); // no more implemented bond::previous ...
     1873//        }
     1874//      }
    18891875    } else {
    18901876      DoLog(3) && (Log() << Verbose(3) << "No corrections for this fragment." << endl);
Note: See TracChangeset for help on using the changeset viewer.