Changeset d3abb1 for src


Ignore:
Timestamp:
Oct 25, 2011, 12:08:03 PM (13 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:
f7fd17
Parents:
ba94c5
git-author:
Frederik Heber <heber@…> (10/20/11 09:32:35)
git-committer:
Frederik Heber <heber@…> (10/25/11 12:08:03)
Message:

Extracted MoleculeLeafClass into own module.

  • removed some unnecessary includes in moleculelist.cpp.
Location:
src
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/GraphAction/DepthFirstSearchAction.cpp

    rba94c5 rd3abb1  
    2828#include "Graph/DepthFirstSearchAnalysis.hpp"
    2929#include "molecule.hpp"
     30#include "MoleculeLeafClass.hpp"
    3031#include "Descriptors/MoleculeDescriptor.hpp"
    3132#include "Descriptors/MoleculeIdDescriptor.hpp"
  • src/Fragmentation/Fragmentation.cpp

    rba94c5 rd3abb1  
    3636#include "Graph/CheckAgainstAdjacencyFile.hpp"
    3737#include "molecule.hpp"
     38#include "MoleculeLeafClass.hpp"
    3839#include "World.hpp"
    3940
  • src/Graph/DepthFirstSearchAnalysis.cpp

    rba94c5 rd3abb1  
    3333#include "Descriptors/AtomDescriptor.hpp"
    3434#include "molecule.hpp"
     35#include "MoleculeLeafClass.hpp"
    3536#include "World.hpp"
    3637
  • src/Makefile.am

    rba94c5 rd3abb1  
    172172  Formula.cpp \
    173173  linkedcell.cpp \
     174  MoleculeLeafClass.cpp \
    174175  moleculelist.cpp \
    175176  molecule.cpp \
     
    195196  Formula.hpp \
    196197  linkedcell.hpp \
     198  MoleculeLeafClass.hpp \
    197199  molecule.hpp \
    198200  ThermoStatContainer.hpp \
  • src/molecule.hpp

    rba94c5 rd3abb1  
    2727#include "CodePatterns/ObservedIterator.hpp"
    2828#include "CodePatterns/Cacheable.hpp"
    29 #include "Fragmentation/fragmentation_helpers.hpp"
    3029#include "Helpers/defs.hpp"
    3130#include "Formula.hpp"
     
    275274};
    276275
    277 /** A leaf for a tree of \a molecule class
    278  * Wraps molecules in a tree structure
    279  */
    280 class MoleculeLeafClass
    281 {
    282 public:
    283   molecule *Leaf; //!< molecule of this leaf
    284   //MoleculeLeafClass *UpLeaf;        //!< Leaf one level up
    285   //MoleculeLeafClass *DownLeaf;      //!< First leaf one level down
    286   MoleculeLeafClass *previous; //!< Previous leaf on this level
    287   MoleculeLeafClass *next; //!< Next leaf on this level
    288 
    289   //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
    290   MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
    291   ~MoleculeLeafClass();
    292 
    293   bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
    294   bool FillRootStackForSubgraphs(KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
    295   bool AssignKeySetsToFragment(molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
    296   void TranslateIndicesToGlobalIDs(Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
    297   int Count() const;
    298 };
    299276
    300277#endif /*MOLECULES_HPP_*/
  • src/moleculelist.cpp

    rba94c5 rd3abb1  
    1919#include "CodePatterns/MemDebug.hpp"
    2020
    21 #include <cstring>
    22 
    23 #include <gsl/gsl_inline.h>
     21//#include <cstring>
     22
     23//#include <gsl/gsl_inline.h>
    2424#include <gsl/gsl_heapsort.h>
     25
     26#include "molecule.hpp"
     27
     28#include "CodePatterns/Log.hpp"
    2529
    2630#include "atom.hpp"
    2731#include "Bond/bond.hpp"
    28 #include "Tesselation/boundary.hpp"
    2932#include "Box.hpp"
    30 #include "CodePatterns/Assert.hpp"
    31 #include "CodePatterns/Log.hpp"
    32 #include "CodePatterns/Verbose.hpp"
    3333#include "config.hpp"
    3434#include "Element/element.hpp"
     35#include "Element/periodentafel.hpp"
    3536#include "Fragmentation/Graph.hpp"
    3637#include "Fragmentation/KeySet.hpp"
     
    3839#include "Helpers/helpers.hpp"
    3940#include "LinearAlgebra/RealSpaceMatrix.hpp"
    40 #include "linkedcell.hpp"
    41 #include "molecule.hpp"
    42 #include "Parser/MpqcParser.hpp"
    4341#include "Parser/FormatParserStorage.hpp"
    44 #include "Element/periodentafel.hpp"
    45 #include "Tesselation/tesselation.hpp"
    4642#include "World.hpp"
    47 #include "WorldTime.hpp"
    48 
    49 /*********************************** Functions for class MoleculeListClass *************************/
     43
    5044
    5145/** Constructor for MoleculeListClass.
     
    755749    }
    756750};
    757 
    758 
    759 /******************************************* Class MoleculeLeafClass ************************************************/
    760 
    761 /** Constructor for MoleculeLeafClass root leaf.
    762  * \param *Up Leaf on upper level
    763  * \param *PreviousLeaf NULL - We are the first leaf on this level, otherwise points to previous in list
    764  */
    765 //MoleculeLeafClass::MoleculeLeafClass(MoleculeLeafClass *Up = NULL, MoleculeLeafClass *Previous = NULL)
    766 MoleculeLeafClass::MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf = NULL) :
    767   Leaf(NULL),
    768   previous(PreviousLeaf)
    769 {
    770   //  if (Up != NULL)
    771   //    if (Up->DownLeaf == NULL) // are we the first down leaf for the upper leaf?
    772   //      Up->DownLeaf = this;
    773   //  UpLeaf = Up;
    774   //  DownLeaf = NULL;
    775   if (previous != NULL) {
    776     MoleculeLeafClass *Walker = previous->next;
    777     previous->next = this;
    778     next = Walker;
    779   } else {
    780     next = NULL;
    781   }
    782 };
    783 
    784 /** Destructor for MoleculeLeafClass.
    785  */
    786 MoleculeLeafClass::~MoleculeLeafClass()
    787 {
    788   //  if (DownLeaf != NULL) {// drop leaves further down
    789   //    MoleculeLeafClass *Walker = DownLeaf;
    790   //    MoleculeLeafClass *Next;
    791   //    do {
    792   //      Next = Walker->NextLeaf;
    793   //      delete(Walker);
    794   //      Walker = Next;
    795   //    } while (Walker != NULL);
    796   //    // Last Walker sets DownLeaf automatically to NULL
    797   //  }
    798   // remove the leaf itself
    799   if (Leaf != NULL) {
    800     Leaf->removeAtomsinMolecule();
    801     World::getInstance().destroyMolecule(Leaf);
    802     Leaf = NULL;
    803   }
    804   // remove this Leaf from level list
    805   if (previous != NULL)
    806     previous->next = next;
    807   //  } else { // we are first in list (connects to UpLeaf->DownLeaf)
    808   //    if ((NextLeaf != NULL) && (NextLeaf->UpLeaf == NULL))
    809   //      NextLeaf->UpLeaf = UpLeaf;  // either null as we are top level or the upleaf of the first node
    810   //    if (UpLeaf != NULL)
    811   //      UpLeaf->DownLeaf = NextLeaf;  // either null as we are only leaf or NextLeaf if we are just the first
    812   //  }
    813   //  UpLeaf = NULL;
    814   if (next != NULL) // are we last in list
    815     next->previous = previous;
    816   next = NULL;
    817   previous = NULL;
    818 };
    819 
    820 /** Adds \a molecule leaf to the tree.
    821  * \param *ptr ptr to molecule to be added
    822  * \param *Previous previous MoleculeLeafClass referencing level and which on the level
    823  * \return true - success, false - something went wrong
    824  */
    825 bool MoleculeLeafClass::AddLeaf(molecule *ptr, MoleculeLeafClass *Previous)
    826 {
    827   return false;
    828 };
    829 
    830 /** Fills the root stack for sites to be used as root in fragmentation depending on order or adaptivity criteria
    831  * Again, as in \sa FillBondStructureFromReference steps recursively through each Leaf in this chain list of molecule's.
    832  * \param *out output stream for debugging
    833  * \param *&RootStack stack to be filled
    834  * \param *AtomMask defines true/false per global Atom::Nr to mask in/out each nuclear site
    835  * \param &FragmentCounter counts through the fragments in this MoleculeLeafClass
    836  * \return true - stack is non-empty, fragmentation necessary, false - stack is empty, no more sites to update
    837  */
    838 bool MoleculeLeafClass::FillRootStackForSubgraphs(KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter)
    839 {
    840   atom *Father = NULL;
    841 
    842   if (RootStack != NULL) {
    843     // find first root candidates
    844     if (&(RootStack[FragmentCounter]) != NULL) {
    845       RootStack[FragmentCounter].clear();
    846       for(molecule::const_iterator iter = Leaf->begin(); iter != Leaf->end(); ++iter) {
    847         Father = (*iter)->GetTrueFather();
    848         if (AtomMask[Father->getNr()]) // apply mask
    849 #ifdef ADDHYDROGEN
    850           if ((*iter)->getType()->getAtomicNumber() != 1) // skip hydrogen
    851 #endif
    852           RootStack[FragmentCounter].push_front((*iter)->getNr());
    853       }
    854       if (next != NULL)
    855         next->FillRootStackForSubgraphs(RootStack, AtomMask, ++FragmentCounter);
    856     } else {
    857       DoLog(1) && (Log() << Verbose(1) << "Rootstack[" << FragmentCounter << "] is NULL." << endl);
    858       return false;
    859     }
    860     FragmentCounter--;
    861     return true;
    862   } else {
    863     DoLog(1) && (Log() << Verbose(1) << "Rootstack is NULL." << endl);
    864     return false;
    865   }
    866 };
    867 
    868 /** The indices per keyset are compared to the respective father's Atom::Nr in each subgraph and thus put into \a **&FragmentList.
    869  * \param *out output stream fro debugging
    870  * \param *reference reference molecule with the bond structure to be copied
    871  * \param *KeySetList list with all keysets
    872  * \param ***ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled
    873  * \param **&FragmentList list to be allocated and returned
    874  * \param &FragmentCounter counts the fragments as we move along the list
    875  * \param FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not
    876  * \retuen true - success, false - failure
    877  */
    878 bool MoleculeLeafClass::AssignKeySetsToFragment(molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList)
    879 {
    880   bool status = true;
    881   int KeySetCounter = 0;
    882 
    883   DoLog(1) && (Log() << Verbose(1) << "Begin of AssignKeySetsToFragment." << endl);
    884   // fill ListOfLocalAtoms if NULL was given
    885   if (!Leaf->FillListOfLocalAtoms(ListOfLocalAtoms[FragmentCounter], reference->getAtomCount())) {
    886     DoLog(1) && (Log() << Verbose(1) << "Filling of ListOfLocalAtoms failed." << endl);
    887     return false;
    888   }
    889 
    890   // allocate fragment list
    891   if (FragmentList == NULL) {
    892     KeySetCounter = Count();
    893     FragmentList = new Graph*[KeySetCounter];
    894     for (int i=0;i<KeySetCounter;i++)
    895       FragmentList[i] = NULL;
    896     KeySetCounter = 0;
    897   }
    898 
    899   if ((KeySetList != NULL) && (KeySetList->size() != 0)) { // if there are some scanned keysets at all
    900     // assign scanned keysets
    901     if (FragmentList[FragmentCounter] == NULL)
    902       FragmentList[FragmentCounter] = new Graph;
    903     KeySet *TempSet = new KeySet;
    904     for (Graph::iterator runner = KeySetList->begin(); runner != KeySetList->end(); runner++) { // key sets contain global numbers!
    905       if (ListOfLocalAtoms[FragmentCounter][reference->FindAtom(*((*runner).first.begin()))->getNr()] != NULL) {// as we may assume that that bond structure is unchanged, we only test the first key in each set
    906         // translate keyset to local numbers
    907         for (KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)
    908           TempSet->insert(ListOfLocalAtoms[FragmentCounter][reference->FindAtom(*sprinter)->getNr()]->getNr());
    909         // insert into FragmentList
    910         FragmentList[FragmentCounter]->insert(GraphPair(*TempSet, pair<int, double> (KeySetCounter++, (*runner).second.second)));
    911       }
    912       TempSet->clear();
    913     }
    914     delete (TempSet);
    915     if (KeySetCounter == 0) {// if there are no keysets, delete the list
    916       DoLog(1) && (Log() << Verbose(1) << "KeySetCounter is zero, deleting FragmentList." << endl);
    917       delete (FragmentList[FragmentCounter]);
    918     } else
    919       DoLog(1) && (Log() << Verbose(1) << KeySetCounter << " keysets were assigned to subgraph " << FragmentCounter << "." << endl);
    920     FragmentCounter++;
    921     if (next != NULL)
    922       next->AssignKeySetsToFragment(reference, KeySetList, ListOfLocalAtoms, FragmentList, FragmentCounter, FreeList);
    923     FragmentCounter--;
    924   } else
    925     DoLog(1) && (Log() << Verbose(1) << "KeySetList is NULL or empty." << endl);
    926 
    927   if ((FreeList) && (ListOfLocalAtoms != NULL)) {
    928     // free the index lookup list
    929     delete[](ListOfLocalAtoms[FragmentCounter]);
    930   }
    931   DoLog(1) && (Log() << Verbose(1) << "End of AssignKeySetsToFragment." << endl);
    932   return status;
    933 };
    934 
    935 /** Translate list into global numbers (i.e. ones that are valid in "this" molecule, not in MolecularWalker->Leaf)
    936  * \param *out output stream for debugging
    937  * \param **FragmentList Graph with local numbers per fragment
    938  * \param &FragmentCounter counts the fragments as we move along the list
    939  * \param &TotalNumberOfKeySets global key set counter
    940  * \param &TotalGraph Graph to be filled with global numbers
    941  */
    942 void MoleculeLeafClass::TranslateIndicesToGlobalIDs(Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph)
    943 {
    944   DoLog(1) && (Log() << Verbose(1) << "Begin of TranslateIndicesToGlobalIDs." << endl);
    945   KeySet *TempSet = new KeySet;
    946   if (FragmentList[FragmentCounter] != NULL) {
    947     for (Graph::iterator runner = FragmentList[FragmentCounter]->begin(); runner != FragmentList[FragmentCounter]->end(); runner++) {
    948       for (KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)
    949         TempSet->insert((Leaf->FindAtom(*sprinter))->GetTrueFather()->getNr());
    950       TotalGraph.insert(GraphPair(*TempSet, pair<int, double> (TotalNumberOfKeySets++, (*runner).second.second)));
    951       TempSet->clear();
    952     }
    953     delete (TempSet);
    954   } else {
    955     DoLog(1) && (Log() << Verbose(1) << "FragmentList is NULL." << endl);
    956   }
    957   if (next != NULL)
    958     next->TranslateIndicesToGlobalIDs(FragmentList, ++FragmentCounter, TotalNumberOfKeySets, TotalGraph);
    959   FragmentCounter--;
    960   DoLog(1) && (Log() << Verbose(1) << "End of TranslateIndicesToGlobalIDs." << endl);
    961 };
    962 
    963 /** Simply counts the number of items in the list, from given MoleculeLeafClass.
    964  * \return number of items
    965  */
    966 int MoleculeLeafClass::Count() const
    967 {
    968   if (next != NULL)
    969     return next->Count() + 1;
    970   else
    971     return 1;
    972 };
    973 
Note: See TracChangeset for help on using the changeset viewer.