Changeset 0d9053


Ignore:
Timestamp:
Oct 13, 2015, 8:14:32 PM (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:
b1c5f46
Parents:
7537d1
git-author:
Frederik Heber <heber@…> (09/01/15 08:31:54)
git-committer:
Frederik Heber <heber@…> (10/13/15 20:14:32)
Message:

Exracted several functions out of Interfragmenter::operator().

  • extracted Interfragmenter::getAtomKeysetMap(), ::getNeighborsOutsideMolecule(), ::getAtomSpecificKeySetMap(), ::combineFragments().
  • this is preparatory for enhancing the Interfragmenter to automatically ascertaining a certain "distance" between fragments for long-range interactions. That is, we may afterwards smear out nuclear and electronic charge distributions up to said distance without them overlapping outside of a present fragments (i.e. without capturing their short-range interactions elsewhere).
Location:
src/Fragmentation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Interfragmenter.cpp

    r7537d1 r0d9053  
    3737#include "Interfragmenter.hpp"
    3838
    39 #include <list>
    40 #include <map>
    41 
    4239#include "CodePatterns/Assert.hpp"
    4340#include "CodePatterns/Log.hpp"
     
    4542#include "LinearAlgebra/Vector.hpp"
    4643
    47 #include "AtomIdSet.hpp"
    4844#include "Element/element.hpp"
    4945#include "Fragmentation/Graph.hpp"
     
    5349#include "World.hpp"
    5450
    55 void Interfragmenter::operator()(
    56     size_t MaxOrder,
    57     double Rcut,
    58     const enum HydrogenTreatment treatment)
     51
     52Interfragmenter::atomkeyset_t Interfragmenter::getAtomKeySetMap(
     53    size_t _MaxOrder
     54    ) const
    5955{
    6056  /// create a map of atom to keyset (below equal MaxOrder)
    61   typedef std::list<const KeySet *> keysets_t;
    62   typedef std::map<const atom *, keysets_t > atomkeyset_t;
    6357  atomkeyset_t atomkeyset;
    6458  LOG(1, "INFO: Placing all atoms and their keysets into a map.");
     
    6963    const AtomIdSet atoms(keyset);
    7064    const size_t atoms_size = atoms.getAtomIds().size();
    71     if ((atoms_size > MaxOrder) || (atoms_size == 0))
     65    if ((atoms_size > _MaxOrder) || (atoms_size == 0))
    7266      continue;
    7367    for (AtomIdSet::const_iterator atomiter = atoms.begin();
     
    8781  LOG(2, "DEBUG: There are " << atomkeyset.size() << " entries in lookup.");
    8882
     83  return atomkeyset;
     84}
     85
     86static Vector getAtomIdSetCenter(
     87    const AtomIdSet &_atoms)
     88{
     89  const molecule * const _mol = (*_atoms.begin())->getMolecule();
     90  const size_t atoms_size = _atoms.getAtomIds().size();
     91  Vector center;
     92  for (AtomIdSet::const_iterator iter = _atoms.begin();
     93      iter != _atoms.end(); ++iter) {
     94    center += (*iter)->getPosition();
     95    ASSERT ( _mol == (*iter)->getMolecule(),
     96        "getAtomIdSetCenter() - ids in same keyset belong to different molecule.");
     97  }
     98  center *= 1./(double)atoms_size;
     99
     100  return center;
     101}
     102
     103Interfragmenter::candidates_t Interfragmenter::getNeighborsOutsideMolecule(
     104    const AtomIdSet &_atoms,
     105    double _Rcut,
     106    const enum HydrogenTreatment _treatment) const
     107{
     108  /// go through linked cell and get all neighboring atoms up to Rcut
     109  const LinkedCell::LinkedCell_View view = World::getInstance().getLinkedCell(_Rcut);
     110  const Vector center = getAtomIdSetCenter(_atoms);
     111  const LinkedCell::LinkedList neighbors = view.getAllNeighbors(_Rcut, center);
     112  LOG(4, "DEBUG: Obtained " << neighbors.size() << " neighbors in distance of "
     113      << _Rcut << " around " << center << ".");
     114
     115  /// remove all atoms that belong to same molecule as does one of the
     116  /// fragment's atoms
     117  const molecule * const _mol = (*_atoms.begin())->getMolecule();
     118  candidates_t candidates;
     119  candidates.reserve(neighbors.size());
     120  for (LinkedCell::LinkedList::const_iterator iter = neighbors.begin();
     121      iter != neighbors.end(); ++iter) {
     122    const atom * const _atom = static_cast<const atom * const >(*iter);
     123    ASSERT( _atom != NULL,
     124        "Interfragmenter::getNeighborsOutsideMolecule() - a neighbor is not actually an atom?");
     125    if ((_atom->getMolecule() != _mol)
     126        && (_atom->getPosition().DistanceSquared(center) < _Rcut*_Rcut)
     127        && ((_treatment == IncludeHydrogen) || (_atom->getType()->getAtomicNumber() != 1))) {
     128      candidates.push_back(_atom);
     129    }
     130  }
     131  LOG(3, "DEBUG: There remain " << candidates.size() << " candidates.");
     132
     133  return candidates;
     134}
     135
     136Interfragmenter::atomkeyset_t Interfragmenter::getCandidatesSpecificKeySetMap(
     137    const candidates_t &_candidates,
     138    const atomkeyset_t &_atomkeyset) const
     139{
     140  atomkeyset_t fragmentmap;
     141  for (candidates_t::const_iterator candidateiter = _candidates.begin();
     142      candidateiter != _candidates.end(); ++candidateiter) {
     143    const atom * _atom = *candidateiter;
     144    atomkeyset_t::const_iterator iter = _atomkeyset.find(_atom);
     145    ASSERT( iter != _atomkeyset.end(),
     146        "Interfragmenter::getAtomSpecificKeySetMap() - could not find atom "
     147        +toString(_atom->getId())+" in lookup.");
     148    fragmentmap.insert( std::make_pair( _atom, iter->second) );
     149  }
     150  LOG(4, "DEBUG: Copied part of lookup map contains " << fragmentmap.size() << " keys.");
     151
     152  return fragmentmap;
     153}
     154
     155void Interfragmenter::combineFragments(
     156    const candidates_t &_candidates,
     157    atomkeyset_t &_fragmentmap,
     158    const KeySet &_keyset,
     159    Graph &_InterFragments,
     160    int &_counter)
     161{
     162  for (candidates_t::const_iterator candidateiter = _candidates.begin();
     163      candidateiter != _candidates.end(); ++candidateiter) {
     164    const atom *_atom = *candidateiter;
     165    LOG(3, "DEBUG: Current candidate is " << *_atom << ".");
     166    atomkeyset_t::iterator finditer = _fragmentmap.find(_atom);
     167    ASSERT( finditer != _fragmentmap.end(),
     168        "Interfragmenter::combineFragments() - could not find atom "
     169        +toString(_atom->getId())+" in fragment specific lookup.");
     170    keysets_t &othersets = finditer->second;
     171    keysets_t::iterator otheriter = othersets.begin();
     172    while (otheriter != othersets.end()) {
     173      const KeySet &otherset = **otheriter;
     174      LOG(3, "DEBUG: Current keyset is " << otherset << ".");
     175      // only add them one way round and not the other
     176      if (otherset < _keyset) {
     177        ++otheriter;
     178        continue;
     179      }
     180      KeySet newset(otherset);
     181      newset.insert(_keyset.begin(), _keyset.end());
     182      LOG(3, "DEBUG: Inserting new combined set " << newset << ".");
     183      _InterFragments.insert( std::make_pair(newset, std::make_pair(++_counter, 1.)));
     184      // finally, remove the set such that no other combination exists
     185      otheriter = othersets.erase(otheriter);
     186    }
     187  }
     188}
     189
     190void Interfragmenter::operator()(
     191    const size_t MaxOrder,
     192    const double Rcut,
     193    const enum HydrogenTreatment treatment)
     194{
     195  atomkeyset_t atomkeyset = getAtomKeySetMap(MaxOrder);
     196
    89197  Graph InterFragments;
    90198  int counter = TotalGraph.size();
     
    101209      continue;
    102210
    103     /// go through linked cell and get all neighboring atoms up to Rcut
    104     Vector center;
    105     const molecule *_mol = (*atoms.begin())->getMolecule();
    106     for (AtomIdSet::const_iterator iter = atoms.begin();
    107         iter != atoms.end(); ++iter) {
    108       center += (*iter)->getPosition();
    109       ASSERT ( _mol == (*iter)->getMolecule(),
    110           "Interfragmenter::operator() - ids in same keyset belong to different molecule.");
    111     }
    112     center *= 1./(double)atoms_size;
    113     LinkedCell::LinkedCell_View view = World::getInstance().getLinkedCell(Rcut);
    114     LinkedCell::LinkedList neighbors = view.getAllNeighbors(Rcut, center);
    115     LOG(4, "DEBUG: Obtained " << neighbors.size() << " neighbors in distance of "
    116         << Rcut << " around " << center << ".");
    117 
    118     /// remove all atoms that belong to same molecule as does one of the
    119     /// fragment's atoms
    120     typedef std::vector<const atom *> candidates_t;
    121     candidates_t candidates;
    122     candidates.reserve(neighbors.size());
    123     for (LinkedCell::LinkedList::const_iterator iter = neighbors.begin();
    124         iter != neighbors.end(); ++iter) {
    125       const atom * const _atom = static_cast<const atom * const >(*iter);
    126       ASSERT( _atom != NULL,
    127           "Interfragmenter::operator() - a neighbor is not actually an atom?");
    128       if ((_atom->getMolecule() != _mol)
    129           && (_atom->getPosition().DistanceSquared(center) < Rcut*Rcut)
    130           && ((treatment == IncludeHydrogen) || (_atom->getType()->getAtomicNumber() != 1))) {
    131         candidates.push_back(_atom);
    132       }
    133     }
    134     LOG(3, "DEBUG: There remain " << candidates.size() << " candidates.");
     211    // get neighboring atoms outside the current molecule
     212    candidates_t candidates = getNeighborsOutsideMolecule(atoms, Rcut, treatment);
    135213
    136214    // create a lookup specific to this fragment
    137     atomkeyset_t fragmentmap;
    138     for (candidates_t::const_iterator candidateiter = candidates.begin();
    139         candidateiter != candidates.end(); ++candidateiter) {
    140       const atom * _atom = *candidateiter;
    141       atomkeyset_t::const_iterator iter = atomkeyset.find(_atom);
    142       ASSERT( iter != atomkeyset.end(),
    143           "Interfragmenter::operator() - could not find atom "
    144           +toString(_atom->getId())+" in lookup.");
    145       fragmentmap.insert( std::make_pair( _atom, iter->second) );
    146     }
    147     LOG(4, "DEBUG: Copied part of lookup map contains " << fragmentmap.size() << " keys.");
     215    atomkeyset_t fragmentmap = getCandidatesSpecificKeySetMap(candidates, atomkeyset);
    148216
    149217    /// combine each remaining fragment with current fragment to a new fragment
    150     /// if keyset is less
    151     for (candidates_t::const_iterator candidateiter = candidates.begin();
    152         candidateiter != candidates.end(); ++candidateiter) {
    153       const atom *_atom = *candidateiter;
    154       LOG(3, "DEBUG: Current candidate is " << *_atom << ".");
    155       atomkeyset_t::iterator finditer = fragmentmap.find(_atom);
    156       ASSERT( finditer != fragmentmap.end(),
    157           "Interfragmenter::operator() - could not find atom "
    158           +toString(_atom->getId())+" in fragment specific lookup.");
    159       keysets_t &othersets = finditer->second;
    160       keysets_t::iterator otheriter = othersets.begin();
    161       while (otheriter != othersets.end()) {
    162         const KeySet &otherset = **otheriter;
    163         LOG(3, "DEBUG: Current keyset is " << otherset << ".");
    164         // only add them one way round and not the other
    165         if (otherset < keyset) {
    166           ++otheriter;
    167           continue;
    168         }
    169         KeySet newset(otherset);
    170         newset.insert(keyset.begin(), keyset.end());
    171         LOG(3, "DEBUG: Inserting new combined set " << newset << ".");
    172         InterFragments.insert( std::make_pair(newset, std::make_pair(++counter, 1.)));
    173         // finally, remove the set such that no other combination exists
    174         otheriter = othersets.erase(otheriter);
    175       }
    176     }
     218    /// if keyset is less (to prevent addding same inter-fragment twice)
     219    combineFragments(candidates, fragmentmap, keyset, InterFragments, counter);
    177220  }
    178221
  • src/Fragmentation/Interfragmenter.hpp

    r7537d1 r0d9053  
    1414#endif
    1515
     16#include <list>
     17#include <map>
    1618#include <vector>
    1719
     20#include "AtomIdSet.hpp"
    1821#include "Fragmentation/HydrogenSaturation_enum.hpp"
    1922
     
    5053   */
    5154  void operator()(
    52       size_t MaxOrder,
    53       double Rcut,
     55      const size_t MaxOrder,
     56      const double Rcut,
    5457      const enum HydrogenTreatment treatment);
    5558
     
    6265  std::vector<atom *> getAtomsFromKeySet(const KeySet &keyset) const;
    6366
     67  typedef std::list<const KeySet *> keysets_t;
     68  typedef std::map<const atom *, keysets_t > atomkeyset_t;
     69
     70  /** Helper function to create a map of atoms and their fragments/keysets.
     71   *
     72   * \param _MaxOrder maximum order
     73   * \return map with atoms as a keys and fragments as values
     74   */
     75  atomkeyset_t getAtomKeySetMap(size_t _MaxOrder) const;
     76
     77  typedef std::vector<const atom *> candidates_t;
     78
     79  /** Helper function to get all atoms around a specific keyset not contained in
     80   * the same molecule.
     81   *
     82   * \param _atoms all atoms of a fragment
     83   * \param _Rcut desired distance cutoff
     84   * \param _treatment whether hydrogens are treated special or not
     85   */
     86  candidates_t getNeighborsOutsideMolecule(
     87      const AtomIdSet &_atoms,
     88      const double _Rcut,
     89      const enum HydrogenTreatment _treatment) const;
     90
     91  /** Helper function to return a fragment/KeySet map specific to all candidates.
     92   *
     93   * \param _candidates all neighboring atoms around keyset
     94   * \param _atomkeyset map with all atoms and the KeySets they are contained in
     95   * \return specific fragment map
     96   */
     97  atomkeyset_t getCandidatesSpecificKeySetMap(
     98      const candidates_t &_candidates,
     99      const atomkeyset_t &_atomkeyset) const;
     100
     101  /** For a given set of candidates atoms in \a _candidates and a \a _keyset
     102   * we combine each fragment from either atom and place it into internal
     103   * Graph.
     104   *
     105   * \param _MaxOrder maximum order
     106   * \param _candidates all atoms neighboring the current out outside of its molecule
     107   * \param _fragmentmap all keysets related to this atom
     108   * \param _keyset current keyset (used as base for creating inter-fragments)
     109   * \param _InterFragments container for all created inter-fragments
     110   * \param _counter counts added fragments
     111   */
     112  void combineFragments(
     113      const candidates_t &_candidates,
     114      atomkeyset_t &_fragmentmap,
     115      const KeySet &_keyset,
     116      Graph &_InterFragments,
     117      int &_counter);
    64118
    65119private:
Note: See TracChangeset for help on using the changeset viewer.