Changeset d410e25 for src/Fragmentation


Ignore:
Timestamp:
May 18, 2016, 10:02:07 PM (9 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, 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_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, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, 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:
70aeed
Parents:
3004d2
git-author:
Frederik Heber <heber@…> (03/07/16 16:05:37)
git-committer:
Frederik Heber <heber@…> (05/18/16 22:02:07)
Message:

Interfragmenter now access singleton AtomFragmentsMap.

  • i.e. we do not instantiate the map ourselves but assume that it has been filled elsewhere. We only receive a Graph ("TotalGraph") in order to add the additional fragments to it.
  • FragmentationAction fills the AtomFragmentsMap already before calling interfragmenter.
Location:
src/Fragmentation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Interfragmenter.cpp

    r3004d2 rd410e25  
    3636
    3737#include "Interfragmenter.hpp"
     38
     39#include <algorithm>
    3840
    3941#include "CodePatterns/Assert.hpp"
     
    98100
    99101  return candidates;
    100 }
    101 
    102 Interfragmenter::atomkeyset_t Interfragmenter::getCandidatesSpecificKeySetMap(
    103     const candidates_t &_candidates,
    104     const atomkeyset_t &_atomkeyset) const
    105 {
    106   atomkeyset_t fragmentmap;
    107   for (candidates_t::const_iterator candidateiter = _candidates.begin();
    108       candidateiter != _candidates.end(); ++candidateiter) {
    109     const atomId_t atomid = (*candidateiter)->getId();
    110     atomkeyset_t::const_iterator iter = _atomkeyset.find(atomid);
    111     ASSERT( iter != _atomkeyset.end(),
    112         "Interfragmenter::getAtomSpecificKeySetMap() - could not find atom "
    113         +toString(atomid)+" in lookup.");
    114     fragmentmap.insert( std::make_pair( atomid, iter->second) );
    115   }
    116   LOG(4, "DEBUG: Copied part of lookup map contains " << fragmentmap.size() << " keys.");
    117 
    118   return fragmentmap;
    119102}
    120103
     
    166149
    167150void Interfragmenter::operator()(
     151    Graph &TotalGraph,
    168152    const size_t MaxOrder,
    169153    const double Rcut,
     
    171155{
    172156  AtomFragmentsMap& atomfragments_container = AtomFragmentsMap::getInstance();
    173   atomfragments_container.insert(TotalGraph);
    174157  const atomkeyset_t &atomkeyset = atomfragments_container.getMap();
    175158
    176159  Graph InterFragments;
    177   int counter = TotalGraph.size();
     160  int counter = atomkeyset.size();
    178161
    179162  /// go through all fragments up to MaxOrder
    180163  LOG(1, "INFO: Creating inter-fragments.");
    181   for (Graph::const_iterator keysetiter = TotalGraph.begin();
    182       keysetiter != TotalGraph.end(); ++keysetiter) {
    183     const KeySet &keyset = keysetiter->first;
    184     LOG(2, "DEBUG: Current keyset is " << keyset);
    185     const AtomIdSet atoms(keyset);
    186     const size_t atoms_size = atoms.getAtomIds().size();
    187     if ((atoms_size > MaxOrder) || (atoms_size == 0))
    188       continue;
    189 
    190     // get neighboring atoms outside the current molecule
    191     candidates_t candidates = getNeighborsOutsideMolecule(atoms, Rcut, treatment);
    192 
    193     // create a lookup specific to this fragment
    194     atomkeyset_t fragmentmap = getCandidatesSpecificKeySetMap(candidates, atomkeyset);
    195 
    196     /// combine each remaining fragment with current fragment to a new fragment
    197     /// if keyset is less (to prevent addding same inter-fragment twice)
    198     combineFragments(MaxOrder, candidates, fragmentmap, keyset, InterFragments, counter);
     164  for (atomkeyset_t::const_iterator atomiter = atomkeyset.begin();
     165      atomiter != atomkeyset.end(); ++atomiter) {
     166    const atomId_t &atomid = atomiter->first;
     167    LOG(2, "DEBUG: Current atomid is " << atomid);
     168
     169    const AtomFragmentsMap::keysets_t &keysets = atomiter->second;
     170    for (AtomFragmentsMap::keysets_t::const_iterator keyiter = keysets.begin();
     171        keyiter != keysets.end(); ++keyiter) {
     172      const KeySet &keyset = *keyiter;
     173      const AtomIdSet atoms(keyset);
     174      const size_t atoms_size = atoms.getAtomIds().size();
     175      if ((atoms_size > MaxOrder) || (atoms_size == 0))
     176        continue;
     177
     178      // get neighboring atoms outside the current molecule
     179      candidates_t candidates = getNeighborsOutsideMolecule(atoms, Rcut, treatment);
     180
     181      // create a lookup specific to this fragment
     182      std::vector<atomId_t> atomids(candidates.size());
     183      std::transform(
     184          candidates.begin(), candidates.end(),
     185          atomids.begin(),
     186          boost::bind(&atom::getId, _1));
     187      atomkeyset_t fragmentmap = atomfragments_container.getMap(atomids, MaxOrder);
     188
     189      /// combine each remaining fragment with current fragment to a new fragment
     190      /// if keyset is less (to prevent addding same inter-fragment twice)
     191      combineFragments(MaxOrder, candidates, fragmentmap, keyset, InterFragments, counter);
     192    }
    199193  }
    200194
    201195  /// eventually, add all new fragments to the Graph
    202   counter = TotalGraph.size();
     196  counter = atomkeyset.size();
    203197  TotalGraph.InsertGraph(InterFragments, counter);
    204198}
     
    215209
    216210  // go through each atom and find closest atom not in the same keyset
    217   for (Graph::const_iterator keysetiter = TotalGraph.begin();
    218       keysetiter != TotalGraph.end(); ++keysetiter) {
    219     const KeySet &keyset = keysetiter->first;
    220     LOG(2, "DEBUG: Current keyset is " << keyset);
    221     const AtomIdSet atoms(keyset);
    222 
    223     // get neighboring atoms outside the current molecule
    224     const candidates_t candidates = getNeighborsOutsideMolecule(atoms, _upperbound, _treatment);
    225     const Vector center = getAtomIdSetCenter(atoms);
    226 
    227     for (candidates_t::const_iterator candidateiter = candidates.begin();
    228         candidateiter != candidates.end(); ++candidateiter) {
    229       atom const * const Walker = *candidateiter;
    230       // go through each atom in set and pick minimal distance
    231       for (AtomIdSet::const_iterator setiter = atoms.begin(); setiter != atoms.end(); ++setiter) {
    232         const double distanceSquared = Walker->getPosition().DistanceSquared(center);
    233         // pick the smallest compared to current Rcut if smaller
    234         if (distanceSquared < Rcut) {
    235           Rcut = distanceSquared;
    236           ClosestPair.first = (*setiter)->getId();
    237           ClosestPair.second = Walker->getId();
    238           LOG(2, "DEBUG: Found new pair " << ClosestPair << " with distance " << sqrt(Rcut));
     211  AtomFragmentsMap& atomfragments_container = AtomFragmentsMap::getInstance();
     212  const atomkeyset_t &atomkeyset = atomfragments_container.getMap();
     213  for (atomkeyset_t::const_iterator atomiter = atomkeyset.begin();
     214      atomiter != atomkeyset.end(); ++atomiter) {
     215    const atomId_t &atomid = atomiter->first;
     216    LOG(2, "DEBUG: Current atomid is " << atomid);
     217
     218    const AtomFragmentsMap::keysets_t &keysets = atomiter->second;
     219    for (AtomFragmentsMap::keysets_t::const_iterator keyiter = keysets.begin();
     220        keyiter != keysets.end(); ++keyiter) {
     221      const KeySet &keyset = *keyiter;
     222      const AtomIdSet atoms(keyset);
     223
     224      // get neighboring atoms outside the current molecule
     225      const candidates_t candidates = getNeighborsOutsideMolecule(atoms, _upperbound, _treatment);
     226      const Vector center = getAtomIdSetCenter(atoms);
     227
     228      for (candidates_t::const_iterator candidateiter = candidates.begin();
     229          candidateiter != candidates.end(); ++candidateiter) {
     230        atom const * const Walker = *candidateiter;
     231        // go through each atom in set and pick minimal distance
     232        for (AtomIdSet::const_iterator setiter = atoms.begin(); setiter != atoms.end(); ++setiter) {
     233          const double distanceSquared = Walker->getPosition().DistanceSquared(center);
     234          // pick the smallest compared to current Rcut if smaller
     235          if (distanceSquared < Rcut) {
     236            Rcut = distanceSquared;
     237            ClosestPair.first = (*setiter)->getId();
     238            ClosestPair.second = Walker->getId();
     239            LOG(2, "DEBUG: Found new pair " << ClosestPair << " with distance " << sqrt(Rcut));
     240          }
    239241        }
    240242      }
  • src/Fragmentation/Interfragmenter.hpp

    r3004d2 rd410e25  
    3939{
    4040public:
    41   /** Constructor for class Interfragmenter.
    42    *
    43    * \param _TotalGraph Graph with all fragments to interrelate
    44    */
    45   Interfragmenter(Graph &_TotalGraph) :
    46     TotalGraph(_TotalGraph)
    47   {}
    48 
    4941  /** Adds interrelated fragments to TotalGraph up to \a MaxOrder and \a Rcut.
    5042   *
     43   * \param TotalGraph filled with additional inter-fragments on return
    5144   * \param MaxOrder maximum order for fragments to interrelate
    5245   * \param Rcut maximum distance to check for interrelatable fragments
     
    5447   */
    5548  void operator()(
     49      Graph &TotalGraph,
    5650      const size_t MaxOrder,
    5751      const double Rcut,
     
    9084      const enum HydrogenTreatment _treatment) const;
    9185
    92   /** Helper function to return a fragment/KeySet map specific to all candidates.
    93    *
    94    * \param _candidates all neighboring atoms around keyset
    95    * \param _atomkeyset map with all atoms and the KeySets they are contained in
    96    * \return specific fragment map
    97    */
    98   atomkeyset_t getCandidatesSpecificKeySetMap(
    99       const candidates_t &_candidates,
    100       const atomkeyset_t &_atomkeyset) const;
    101 
    10286  /** For a given set of candidates atoms in \a _candidates and a \a _keyset
    10387   * we combine each fragment from either atom and place it into internal
     
    118102      Graph &_InterFragments,
    119103      int &_counter);
    120 
    121 private:
    122   Graph &TotalGraph;
    123104};
    124105
Note: See TracChangeset for help on using the changeset viewer.