Changeset 9879f6 for src/molecule.cpp


Ignore:
Timestamp:
Mar 5, 2010, 10:16:47 AM (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:
d3347e
Parents:
e87acf
git-author:
Frederik Heber <heber@…> (03/05/10 10:08:44)
git-committer:
Frederik Heber <heber@…> (03/05/10 10:16:47)
Message:

Huge Refactoring due to class molecule now being an STL container.

  • molecule::start and molecule::end were dropped. Hence, the usual construct Walker = start while (Walker->next != end) {

Walker = walker->next
...

}
was changed to
for (molecule::iterator iter = begin(); iter != end(); ++iter) {

...

}
and (*iter) used instead of Walker.

  • Two build errors remain (beside some more in folder Actions, Patterns and unittest) in molecule_pointcloud.cpp and molecule.cpp
  • lists.cpp was deleted as specialization of atom* was not needed anymore
  • link, unlink, add, remove, removewithoutcheck all are not needed for atoms anymore, just for bonds (where first, last entries remain in molecule)
  • CreateFatherLookupTable() was put back into class molecule.
  • molecule::InternalPointer is now an iterator
  • class PointCloud: GoToPrevious() and GetTerminalPoint() were dropped as not needed.
  • some new STL functions in class molecule: size(), empty(), erase(), find() and insert()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule.cpp

    re87acf r9879f6  
    3737  formula(this,boost::bind(&molecule::calcFormula,this)),
    3838  last_atom(0),
    39   InternalPointer(start)
    40 {
    41   // init atom chain list
    42   //start->father = NULL;
    43   //end->father = NULL;
    44   //link(start,end);
    45 
     39  InternalPointer(begin())
     40{
    4641  // init bond chain list
    4742  link(first,last);
     
    6762  delete(first);
    6863  delete(last);
    69   end->getWorld()->destroyAtom(end);
    70   start->getWorld()->destroyAtom(start);
    7164};
    7265
     
    10396  for (int j = 0; j<MAX_ELEMENTS;j++)
    10497    Counts[j] = 0;
    105   for(atom *Walker = start; Walker != end; Walker = Walker->next) {
    106     Counts[Walker->type->Z]++;
     98  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     99    Counts[(*iter)->type->Z]++;
    107100  }
    108101  for(element* Elemental = elemente->end; Elemental != elemente->start; Elemental = Elemental->previous) {
     
    124117}
    125118
    126 molecule::iterator molecule::ende(){
     119molecule::iterator molecule::end(){
    127120  return molecule::iterator(atoms.end(),this);
    128121}
    129122
    130 molecule::const_iterator molecule::ende() const{
     123molecule::const_iterator molecule::end() const{
    131124  return atoms.end();
     125}
     126
     127bool molecule::empty() const
     128{
     129  return (begin() == end());
     130}
     131
     132size_t molecule::size() const
     133{
     134  size_t counter = 0;
     135  for (molecule::const_iterator iter = begin(); iter != end (); ++iter)
     136    counter++;
     137  return counter;
     138}
     139
     140molecule::const_iterator molecule::erase( const_iterator loc )
     141{
     142  molecule::const_iterator iter = loc;
     143  iter--;
     144  atoms.erase( loc );
     145  return iter;
     146}
     147
     148molecule::const_iterator molecule::erase( atom *& key )
     149{
     150  molecule::const_iterator iter = find(key);
     151  molecule::const_iterator runner = iter;
     152  if (runner != begin()) {
     153    runner--;
     154    if (iter != end())
     155      atoms.erase( key );
     156    return runner;
     157  } else
     158    return end();
     159}
     160
     161molecule::const_iterator molecule::find ( atom *& key ) const
     162{
     163  return atoms.find( key );
     164}
     165
     166pair<molecule::iterator,bool> molecule::insert ( atom * const key )
     167{
     168  return atoms.insert(key);
    132169}
    133170
     
    139176bool molecule::AddAtom(atom *pointer)
    140177{
    141   bool retval = false;
    142178  OBSERVE;
    143179  if (pointer != NULL) {
    144180    pointer->sort = &pointer->nr;
    145     pointer->nr = last_atom++;  // increase number within molecule
    146181    AtomCount++;
    147182    if (pointer->type != NULL) {
     
    157192      }
    158193    }
    159     retval = add(pointer, end);
    160   }
    161   return retval;
     194    insert(pointer);
     195  }
     196  return true;
    162197};
    163198
     
    175210    walker->Name = Malloc<char>(strlen(pointer->Name) + 1, "atom::atom: *Name");
    176211    strcpy (walker->Name, pointer->Name);
    177     walker->nr = last_atom++;  // increase number within molecule
    178     add(walker, end);
     212    insert(walker);
    179213    if ((pointer->type != NULL) && (pointer->type->Z != 1))
    180214      NoNonHydrogen++;
     
    701735    ElementCount--;
    702736  RemoveBonds(pointer);
    703   return remove(pointer, start, end);
     737  erase(pointer);
     738  return true;
    704739};
    705740
     
    718753  if (ElementsInMolecule[pointer->type->Z] == 0)  // was last atom of this element?
    719754    ElementCount--;
    720   unlink(pointer);
     755  erase(pointer);
    721756  return true;
    722757};
     
    727762bool molecule::CleanupMolecule()
    728763{
    729   return (cleanup(first,last) && cleanup(start,end));
     764  for (molecule::iterator iter = begin(); !empty(); iter = begin())
     765      erase(iter);
     766  return (cleanup(first,last));
    730767};
    731768
     
    734771 * \return pointer to atom or NULL
    735772 */
    736 atom * molecule::FindAtom(int Nr)  const{
    737   atom * walker = find(&Nr, start,end);
    738   if (walker != NULL) {
     773atom * molecule::FindAtom(int Nr)  const
     774{
     775  molecule::const_iterator iter = begin();
     776  for (; iter != end(); ++iter)
     777    if ((*iter)->nr == Nr)
     778      break;
     779  if (iter != end()) {
    739780    //Log() << Verbose(0) << "Found Atom Nr. " << walker->nr << endl;
    740     return walker;
     781    return (*iter);
    741782  } else {
    742783    Log() << Verbose(0) << "Atom not found in list." << endl;
     
    896937void molecule::CountAtoms()
    897938{
    898   int i = 0;
    899   atom *Walker = start;
    900   while (Walker->next != end) {
    901     Walker = Walker->next;
    902     i++;
    903   }
     939  int i = size();
    904940  if ((AtomCount == 0) || (i != AtomCount)) {
    905941    Log() << Verbose(3) << "Mismatch in AtomCount " << AtomCount << " and recounted number " << i << ", renaming all." << endl;
     
    910946      i=0;
    911947      NoNonHydrogen = 0;
    912       Walker = start;
    913       while (Walker->next != end) {
    914         Walker = Walker->next;
    915         Walker->nr = i;   // update number in molecule (for easier referencing in FragmentMolecule lateron)
    916         if (Walker->type->Z != 1) // count non-hydrogen atoms whilst at it
     948      for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     949        (*iter)->nr = i;   // update number in molecule (for easier referencing in FragmentMolecule lateron)
     950        if ((*iter)->type->Z != 1) // count non-hydrogen atoms whilst at it
    917951          NoNonHydrogen++;
    918         Free(&Walker->Name);
    919         Walker->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name");
    920         sprintf(Walker->Name, "%2s%02d", Walker->type->symbol, Walker->nr+1);
    921         Log() << Verbose(3) << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl;
     952        Free(&(*iter)->Name);
     953        (*iter)->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name");
     954        sprintf((*iter)->Name, "%2s%02d", (*iter)->type->symbol, (*iter)->nr+1);
     955        Log() << Verbose(3) << "Naming atom nr. " << (*iter)->nr << " " << (*iter)->Name << "." << endl;
    922956        i++;
    923957      }
     
    10921126int * molecule::GetFatherSonAtomicMap(molecule *OtherMolecule)
    10931127{
    1094   atom *Walker = NULL, *OtherWalker = NULL;
    10951128  Log() << Verbose(3) << "Begin of GetFatherAtomicMap." << endl;
    10961129  int *AtomicMap = Malloc<int>(AtomCount, "molecule::GetAtomicMap: *AtomicMap");
     
    11031136  } else {
    11041137    Log() << Verbose(4) << "Map is ";
    1105     Walker = start;
    1106     while (Walker->next != end) {
    1107       Walker = Walker->next;
    1108       if (Walker->father == NULL) {
    1109         AtomicMap[Walker->nr] = -2;
     1138    for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     1139      if ((*iter)->father == NULL) {
     1140        AtomicMap[(*iter)->nr] = -2;
    11101141      } else {
    1111         OtherWalker = OtherMolecule->start;
    1112         while (OtherWalker->next != OtherMolecule->end) {
    1113           OtherWalker = OtherWalker->next;
     1142        for (molecule::const_iterator runner = OtherMolecule->begin(); runner != OtherMolecule->end(); ++runner) {
    11141143      //for (int i=0;i<AtomCount;i++) { // search atom
    11151144        //for (int j=0;j<OtherMolecule->AtomCount;j++) {
    1116           //Log() << Verbose(4) << "Comparing father " << Walker->father << " with the other one " << OtherWalker->father << "." << endl;
    1117           if (Walker->father == OtherWalker)
    1118             AtomicMap[Walker->nr] = OtherWalker->nr;
     1145          //Log() << Verbose(4) << "Comparing father " << (*iter)->father << " with the other one " << (*runner)->father << "." << endl;
     1146          if ((*iter)->father == (*runner))
     1147            AtomicMap[(*iter)->nr] = (*runner)->nr;
    11191148        }
    11201149      }
    1121       Log() << Verbose(0) << AtomicMap[Walker->nr] << "\t";
     1150      Log() << Verbose(0) << AtomicMap[(*iter)->nr] << "\t";
    11221151    }
    11231152    Log() << Verbose(0) << endl;
     
    11531182void molecule::SetIndexedArrayForEachAtomTo ( atom **array, int ParticleInfo::*index) const
    11541183{
    1155   atom *Walker = start;
    1156   while (Walker->next != end) {
    1157     Walker = Walker->next;
    1158     array[(Walker->*index)] = Walker;
     1184  for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     1185    array[((*iter)->*index)] = (*iter);
    11591186  }
    11601187};
Note: See TracChangeset for help on using the changeset viewer.