Changeset 59fff1 for src/molecule.cpp


Ignore:
Timestamp:
Dec 28, 2011, 3:25:49 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:
afa9d8
Parents:
30c753
git-author:
Frederik Heber <heber@…> (12/23/11 10:09:37)
git-committer:
Frederik Heber <heber@…> (12/28/11 15:25:49)
Message:

Replaced the molecule::const_iterator by a true const version of the transform_iterator.

  • lots of places used const_iterator where it made no sense, atom some others one could have sensibly done so but details prevented it, e.g.
    • FormatParserStorage::save() requires vector<atom*> not const atom *,
    • Boundaries (and most of Tesselation for that) requires atom *, not const atom *.
  • Added new function molecule::isInMolecule() to check whether atomic id is in molecule::atomIds.
  • Added const version of atom::GetTrueFather().
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule.cpp

    r30c753 r59fff1  
    173173{
    174174  size_t counter = 0;
    175   for (molecule::const_iterator iter = begin(); iter != end (); ++iter)
     175  for (const_iterator iter = begin(); iter != end (); ++iter)
    176176    counter++;
    177177  return counter;
     
    181181{
    182182  OBSERVE;
    183   molecule::const_iterator iter = loc;
     183  const_iterator iter = loc;
    184184  ++iter;
    185   atom* atom = *loc;
    186   atomIds.erase( atom->getId() );
    187   formula-=atom->getType();
    188   atom->removeFromMolecule();
     185  atom * const _atom = const_cast<atom *>(*loc);
     186  atomIds.erase( _atom->getId() );
     187  formula-=_atom->getType();
     188  _atom->removeFromMolecule();
    189189  return iter;
    190190}
     
    193193{
    194194  OBSERVE;
    195   molecule::const_iterator iter = find(key);
     195  const_iterator iter = find(key);
    196196  if (iter != end()){
    197197    ++iter;
     
    233233//      iter != MyIter(atomIds.end(), FromIdToAtom());
    234234//      ++iter)
    235   for (molecule::const_iterator iter = begin(); iter != end(); ++iter)
     235  for (molecule::iterator iter = begin(); iter != end(); ++iter)
    236236    vector_of_atoms.push_back(*iter);
    237237  return vector_of_atoms;
     
    634634  // copy all atoms
    635635  std::map< const atom *, atom *> FatherFinder;
    636   for (const_iterator iter = begin(); iter != end(); ++iter) {
    637     atom *const copy_atom = copy->AddCopyAtom(*iter);
     636  for (iterator iter = begin(); iter != end(); ++iter) {
     637    atom * const copy_atom = copy->AddCopyAtom(*iter);
    638638    FatherFinder.insert( std::make_pair( *iter, copy_atom ) );
    639639  }
     
    649649        // get the pendant atoms of current bond in the copy molecule
    650650        ASSERT(FatherFinder.count(Binder->leftatom),
    651             "molecule::CopyMolecule() - No copy of original left atom for bond copy found");
     651            "molecule::CopyMolecule() - No copy of original left atom "
     652            +toString(Binder->leftatom)+" for bond copy found");
    652653        ASSERT(FatherFinder.count(Binder->rightatom),
    653             "molecule::CopyMolecule() - No copy of original right atom for bond copy found");
     654            "molecule::CopyMolecule() - No copy of original right atom "
     655            +toString(Binder->rightatom)+"  for bond copy found");
    654656        atom * const LeftAtom = FatherFinder[Binder->leftatom];
    655657        atom * const RightAtom = FatherFinder[Binder->rightatom];
     
    674676{
    675677  // remove each atom from world
    676   for(const_iterator AtomRunner = begin(); !empty(); AtomRunner = begin())
     678  for(iterator AtomRunner = begin(); !empty(); AtomRunner = begin())
    677679    World::getInstance().destroyAtom(*AtomRunner);
    678680};
     
    690692  // copy all atoms
    691693  std::map< const atom *, atom *> FatherFinder;
    692   for (const_iterator iter = begin(); iter != end(); ++iter) {
     694  for (iterator iter = begin(); iter != end(); ++iter) {
    693695    if((*iter)->IsInShape(region)){
    694       atom *const copy_atom = copy->AddCopyAtom(*iter);
     696      atom * const copy_atom = copy->AddCopyAtom(*iter);
    695697      FatherFinder.insert( std::make_pair( *iter, copy_atom ) );
    696698    }
     
    739741
    740742  // some checks to make sure we are able to create the bond
    741   ASSERT(atom1, "First atom in bond-creation was an invalid pointer");
    742   ASSERT(atom2, "Second atom in bond-creation was an invalid pointer");
    743   ASSERT(FindAtom(atom1->getNr()),"First atom in bond-creation was not part of molecule");
    744   ASSERT(FindAtom(atom2->getNr()),"Second atom in bond-creation was not part of molecule");
     743  ASSERT(atom1,
     744      "molecule::AddBond() - First atom "+toString(atom1)
     745      +" is not a invalid pointer");
     746  ASSERT(atom2,
     747      "molecule::AddBond() - Second atom "+toString(atom2)
     748      +" is not a invalid pointer");
     749  ASSERT(isInMolecule(atom1),
     750      "molecule::AddBond() - First atom "+toString(atom1)
     751      +" is not part of molecule");
     752  ASSERT(isInMolecule(atom2),
     753      "molecule::AddBond() - Second atom "+toString(atom2)
     754      +" is not part of molecule");
    745755
    746756  Binder = new bond(atom1, atom2, degree);
    747757  atom1->RegisterBond(WorldTime::getTime(), Binder);
    748758  atom2->RegisterBond(WorldTime::getTime(), Binder);
    749   if ((atom1->getType() != NULL) && (atom1->getType()->getAtomicNumber() != 1) && (atom2->getType() != NULL) && (atom2->getType()->getAtomicNumber() != 1))
     759  if ((atom1->getType() != NULL)
     760      && (atom1->getType()->getAtomicNumber() != 1)
     761      && (atom2->getType() != NULL)
     762      && (atom2->getType()->getAtomicNumber() != 1))
    750763    NoNonBonds++;
    751764
     
    850863atom * molecule::FindAtom(int Nr)  const
    851864{
    852   molecule::const_iterator iter = begin();
     865  molecule::iterator iter = begin();
    853866  for (; iter != end(); ++iter)
    854     if ((*iter)->getNr() == Nr)
    855       break;
     867  if ((*iter)->getNr() == Nr)
     868    break;
    856869  if (iter != end()) {
    857870    //LOG(0, "Found Atom Nr. " << walker->getNr());
    858871    return (*iter);
    859872  } else {
    860     LOG(0, "Atom not found in list.");
     873    ELOG(1, "Atom not found in molecule " << getName() << "'s list.");
    861874    return NULL;
    862875  }
    863 };
     876}
     877
     878/** Checks whether the given atom is a member of this molecule.
     879 *
     880 *  We make use here of molecule::atomIds to get a result on
     881 *
     882 * @param _atom atom to check
     883 * @return true - is member, false - is not
     884 */
     885bool molecule::isInMolecule(const atom * const _atom)
     886{
     887  ASSERT(_atom->getMolecule() == this,
     888      "molecule::isInMolecule() - atom is not designated to be in molecule '"
     889      +toString(this->getName())+"'.");
     890  molecule::atomIdSet::const_iterator iter = atomIds.find(_atom->getId());
     891  return (iter != atomIds.end());
     892}
    864893
    865894/** Asks for atom number, and checks whether in list.
     
    10021031  int i = 0;
    10031032  NoNonHydrogen = 0;
    1004   for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
     1033  for (molecule::iterator iter = begin(); iter != end(); ++iter) {
    10051034    (*iter)->setNr(i);   // update number in molecule (for easier referencing in FragmentMolecule lateron)
    10061035    if ((*iter)->getType()->getAtomicNumber() != 1) // count non-hydrogen atoms whilst at it
Note: See TracChangeset for help on using the changeset viewer.