Changeset 29f7c1 for src/molecule.cpp


Ignore:
Timestamp:
Feb 11, 2016, 8:07:50 AM (9 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:
951aa6
Parents:
c0f2fc
git-author:
Frederik Heber <heber@…> (12/29/15 19:49:43)
git-committer:
Frederik Heber <heber@…> (02/11/16 08:07:50)
Message:

Molecule now has maps with old values for bond counts and element number per atom.

  • this allows to update the total bond count and the formula in an O(N log N) fashion.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecule.cpp

    rc0f2fc r29f7c1  
    9292  ActiveFlag(false),
    9393  IndexNr(-1),
    94   NoNonHydrogen(this,boost::bind(&molecule::doCountNoNonHydrogen,this),"NoNonHydrogen"),
    95   BondCount(this,boost::bind(&molecule::doCountBonds,this),"BondCount"),
     94  NoNonHydrogen(0),
     95  BondCount(0),
    9696  atomIdPool(1, 20, 100),
    9797  BoundingBoxSweepingAxis(std::vector<AtomDistanceMap_t>(NDIM)),
     
    153153int molecule::getAtomCount() const{
    154154  return atomIds.size();
    155 }
    156 
    157 size_t molecule::getNoNonHydrogen() const{
    158   return *NoNonHydrogen;
    159 }
    160 
    161 int molecule::getBondCount() const{
    162   return *BondCount;
    163155}
    164156
     
    293285  }
    294286  NOTIFY(FormulaChanged);
    295   formula-=_atom->getType();
    296287  _atom->removeFromMolecule();
    297288  return iter;
     
    330321    setAtomName(key);
    331322    NOTIFY(FormulaChanged);
    332     formula+=key->getType();
    333323    return res;
    334324  } else {
     
    11721162        OBSERVE;
    11731163        NOTIFY(FormulaChanged);
    1174         resetFormula();
     1164        const ElementPerAtom_t::iterator iter = ElementPerAtom.find(_lastchangedatomid);
     1165        ASSERT( iter != ElementPerAtom.end(),
     1166            "molecule::recieveNotification() - atom "
     1167            +toString(_atom->getId()+" is not contained in ElementsPerAtom."));
     1168        formula -= iter->second;
     1169        if (iter->second == (atomicNumber_t)1) // was a hydrogen ?
     1170          --NoNonHydrogen;
     1171        iter->second = _atom->getElementNo();
     1172        formula += iter->second;
     1173        if (iter->second == (atomicNumber_t)1) // is a hydrogen ?
     1174          ++NoNonHydrogen;
    11751175        break;
     1176      }
     1177      case AtomObservable::BondsAdded:
     1178      case AtomObservable::BondsRemoved:
     1179      {
     1180        // emit others about one of our atoms moved
     1181        _lastchangedatomid = _atom->getId();
     1182        const BondCountsPerAtom_t::iterator iter = BondCountsPerAtom.find(_lastchangedatomid);
     1183        ASSERT( iter != BondCountsPerAtom.end(),
     1184            "molecule::recieveNotification() - atom "
     1185            +toString(_atom->getId()+" is not contained in BondCountsPerAtom."));
     1186        BondCount -= iter->second;
     1187        iter->second = _atom->getListOfBonds().size();
     1188        BondCount += iter->second;
     1189       break;
    11761190      }
    11771191      default:
     
    12161230  _atom->signOn(this, AtomObservable::PositionChanged);
    12171231  _atom->signOn(this, AtomObservable::ElementChanged);
     1232  _atom->signOn(this, AtomObservable::BondsAdded);
     1233  _atom->signOn(this, AtomObservable::BondsRemoved);
    12181234  insert(_atom);
     1235  {
     1236    const size_t atom_bondcount = _atom->getListOfBonds().size();
     1237#ifndef NDEBUG
     1238    const std::pair<BondCountsPerAtom_t::iterator, bool> inserter =
     1239#endif
     1240    BondCountsPerAtom.insert( std::make_pair(_atom->getId(), atom_bondcount) );
     1241    ASSERT( inserter.second,
     1242       "molecule::associateAtomWithMolecule() - atom "
     1243        +toString(_atom->getId()+" already in BondCountsPerAtom."));
     1244    BondCount += atom_bondcount;
     1245  }
     1246  {
     1247    const int atom_elementno = _atom->getElementNo();
     1248#ifndef NDEBUG
     1249    const std::pair<ElementPerAtom_t::iterator, bool> inserter =
     1250#endif
     1251    ElementPerAtom.insert( std::make_pair(_atom->getId(), atom_elementno) );
     1252    ASSERT( inserter.second,
     1253       "molecule::associateAtomWithMolecule() - atom "
     1254        +toString(_atom->getId()+" already in ElementPerAtom."));
     1255    formula += atom_elementno;
     1256  }
    12191257}
    12201258
     
    12231261  _atom->signOff(this, AtomObservable::PositionChanged);
    12241262  _atom->signOff(this, AtomObservable::ElementChanged);
     1263  _atom->signOff(this, AtomObservable::BondsAdded);
     1264  _atom->signOff(this, AtomObservable::BondsRemoved);
    12251265  erase(_atom);
     1266  {
     1267    const BondCountsPerAtom_t::iterator iter = BondCountsPerAtom.find(_atom->getId());
     1268    ASSERT( iter != BondCountsPerAtom.end(),
     1269        "molecule::disassociateAtomWithMolecule() - atom "
     1270        +toString(_atom->getId()+" is not contained in BondCountsPerAtom."));
     1271    BondCount -= iter->second;
     1272    BondCountsPerAtom.erase(iter);
     1273  }
     1274  {
     1275    const ElementPerAtom_t::iterator iter = ElementPerAtom.find(_atom->getId());
     1276    ASSERT( iter != ElementPerAtom.end(),
     1277        "molecule::disassociateAtomWithMolecule() - atom "
     1278        +toString(_atom->getId()+" is not contained in ElementPerAtom."));
     1279    formula -= iter->second;
     1280    ElementPerAtom.erase(iter);
     1281  }
    12261282}
    12271283
Note: See TracChangeset for help on using the changeset viewer.