Changeset f5fa48


Ignore:
Timestamp:
Aug 20, 2014, 1:06:47 PM (11 years ago)
Author:
Frederik Heber <heber@…>
Children:
d635829
Parents:
ce0ca4
git-author:
Frederik Heber <heber@…> (07/18/14 17:08:09)
git-committer:
Frederik Heber <heber@…> (08/20/14 13:06:47)
Message:

SaturatedFragment can deal with a global saturation position map.

  • so far, we create an empty one in FragmentationAction such that nothing's changed for the moment.
  • similarly in StoreSaturatedFragmentAction. However, there this is intended as only local information is required (it's only a single fragment).
Location:
src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/FragmentationAction/FragmentationAction.cpp

    rce0ca4 rf5fa48  
    4242#include "Fragmentation/Exporters/ExportGraph_ToFiles.hpp"
    4343#include "Fragmentation/Exporters/ExportGraph_ToJobs.hpp"
     44#include "Fragmentation/Exporters/SaturatedFragment.hpp"
    4445#include "Fragmentation/Fragmentation.hpp"
    4546#include "Fragmentation/Graph.hpp"
     
    261262  }
    262263
     264  // create global saturation positions map
     265  SaturatedFragment::GlobalSaturationPositions_t globalsaturationpositions;
     266
    263267  {
    264268    const enum HydrogenSaturation saturation =  params.DoSaturation.get() ? DoSaturate : DontSaturate;
     
    266270    if (params.types.get().size() != 0) {
    267271      // store molecule's fragment to file
    268       ExportGraph_ToFiles exporter(TotalGraph, treatment, saturation);
     272      ExportGraph_ToFiles exporter(TotalGraph, treatment, saturation, globalsaturationpositions);
    269273      exporter.setPrefix(params.prefix.get());
    270274      exporter.setOutputTypes(params.types.get());
     
    272276    } else {
    273277      // store molecule's fragment in FragmentJobQueue
    274       ExportGraph_ToJobs exporter(TotalGraph, treatment, saturation);
     278      ExportGraph_ToJobs exporter(TotalGraph, treatment, saturation, globalsaturationpositions);
    275279      exporter.setLevel(params.level.get());
    276280      exporter();
  • src/Actions/FragmentationAction/StoreSaturatedFragmentAction.cpp

    rce0ca4 rf5fa48  
    3939#include "CodePatterns/Log.hpp"
    4040#include "Fragmentation/Exporters/ExportGraph_ToFiles.hpp"
     41#include "Fragmentation/Exporters/SaturatedFragment.hpp"
    4142#include "Fragmentation/Graph.hpp"
    4243#include "World.hpp"
     
    7778  // store molecule's fragment to file
    7879  {
     80    // we use an empty map here such that saturation is done locally
     81    SaturatedFragment::GlobalSaturationPositions_t globalsaturationpositions;
     82
    7983    const enum HydrogenSaturation saturation =  params.DoSaturation.get() ? DoSaturate : DontSaturate;
    80     ExportGraph_ToFiles exporter(TotalGraph, IncludeHydrogen, saturation);
     84    ExportGraph_ToFiles exporter(TotalGraph, IncludeHydrogen, saturation, globalsaturationpositions);
    8185    exporter.setPrefix(params.prefix.get());
    8286    exporter.setOutputTypes(params.types.get());
  • src/Fragmentation/Exporters/ExportGraph.cpp

    rce0ca4 rf5fa48  
    5858  const Graph &_graph,
    5959  const enum HydrogenTreatment _treatment,
    60   const enum HydrogenSaturation _saturation) :
     60  const enum HydrogenSaturation _saturation,
     61  const SaturatedFragment::GlobalSaturationPositions_t &_globalsaturationpositions) :
    6162  TotalGraph(_graph),
    6263  BondFragments(World::getPointer()),
    6364  treatment(_treatment),
    6465  saturation(_saturation),
     66  globalsaturationpositions(_globalsaturationpositions),
    6567  CurrentKeySet(TotalGraph.begin())
    6668{
     
    115117          hydrogens,
    116118          treatment,
    117           saturation)
     119          saturation,
     120          globalsaturationpositions)
    118121  );
    119122  // and return
  • src/Fragmentation/Exporters/ExportGraph.hpp

    rce0ca4 rf5fa48  
    4141      const Graph &_graph,
    4242      const enum HydrogenTreatment _treatment,
    43       const enum HydrogenSaturation _saturation);
     43      const enum HydrogenSaturation _saturation,
     44      const SaturatedFragment::GlobalSaturationPositions_t &_globalsaturationpositions);
    4445  virtual ~ExportGraph();
    4546
     
    102103  const enum HydrogenSaturation saturation;
    103104
     105  //!> Global information over all atoms with saturation positions to be used per fragment
     106  const SaturatedFragment::GlobalSaturationPositions_t &globalsaturationpositions;
     107
    104108private:
    105109  //!> iterator pointing at the CurrentKeySet to be exported
  • src/Fragmentation/Exporters/ExportGraph_ToFiles.cpp

    rce0ca4 rf5fa48  
    5757 * @param _treatment whether to always add already present hydrogens or not
    5858 * @param _saturation whether to saturate dangling bonds with hydrogen or not
     59 * @param _globalsaturationpositions possibly empty map with global information
     60 *        where to place saturation hydrogens to fulfill consistency principle
    5961 */
    6062ExportGraph_ToFiles::ExportGraph_ToFiles(
    6163    const Graph &_graph,
    6264    const enum HydrogenTreatment _treatment,
    63     const enum HydrogenSaturation _saturation) :
    64                 ExportGraph(_graph, _treatment, _saturation)
     65    const enum HydrogenSaturation _saturation,
     66    const SaturatedFragment::GlobalSaturationPositions_t &_globalsaturationpositions) :
     67                ExportGraph(_graph, _treatment, _saturation, _globalsaturationpositions)
    6568{}
    6669
  • src/Fragmentation/Exporters/ExportGraph_ToFiles.hpp

    rce0ca4 rf5fa48  
    3333            const Graph &_graph,
    3434            const enum HydrogenTreatment _treatment,
    35             const enum HydrogenSaturation _saturation);
     35            const enum HydrogenSaturation _saturation,
     36      const SaturatedFragment::GlobalSaturationPositions_t &_globalsaturationpositions);
    3637        virtual ~ExportGraph_ToFiles();
    3738
  • src/Fragmentation/Exporters/ExportGraph_ToJobs.cpp

    rce0ca4 rf5fa48  
    5959    const Graph &_graph,
    6060    const enum HydrogenTreatment _treatment,
    61     const enum HydrogenSaturation _saturation) :
    62     ExportGraph(_graph, _treatment, _saturation),
     61    const enum HydrogenSaturation _saturation,
     62    const SaturatedFragment::GlobalSaturationPositions_t &_globalsaturationpositions) :
     63    ExportGraph(_graph, _treatment, _saturation,_globalsaturationpositions),
    6364    level(5)
    6465{}
  • src/Fragmentation/Exporters/ExportGraph_ToJobs.hpp

    rce0ca4 rf5fa48  
    3535   * \param _treatment whether hydrogen is excluded in the _graph or not
    3636   * \param _saturation whether we saturate dangling bonds or not
     37   * \param _globalsaturationpositions possibly empty map with global information
     38   *        where to place saturation hydrogens to fulfill consistency principle
    3739   */
    3840  ExportGraph_ToJobs(
    3941      const Graph &_graph,
    4042      const enum HydrogenTreatment _treatment,
    41       const enum HydrogenSaturation _saturation);
     43      const enum HydrogenSaturation _saturation,
     44      const SaturatedFragment::GlobalSaturationPositions_t &_globalsaturationpositions);
    4245  virtual ~ExportGraph_ToJobs();
    4346
  • src/Fragmentation/Exporters/SaturatedFragment.cpp

    rce0ca4 rf5fa48  
    6565    HydrogenPool &_hydrogens,
    6666    const enum HydrogenTreatment _treatment,
    67     const enum HydrogenSaturation _saturation) :
     67    const enum HydrogenSaturation _saturation,
     68    const GlobalSaturationPositions_t &_globalsaturationpositions) :
    6869  container(_container),
    6970  set(_set),
     
    7980  container.insert(set);
    8081
    81   // prepare saturation hydrogens
    82   saturate();
     82  // prepare saturation hydrogens, either using global information
     83  // or if not given, local information (created in the function)
     84  if (_globalsaturationpositions.empty())
     85    saturate();
     86  else
     87    saturate(_globalsaturationpositions);
    8388}
    8489
     
    101106}
    102107
    103 void SaturatedFragment::saturate()
    104 {
    105   // so far, we just have a set of keys. Hence, convert to atom refs
    106   // and gather all atoms in a vector
    107   std::vector<atom *> atoms;
    108   for (KeySet::const_iterator iter = FullMolecule.begin();
    109       iter != FullMolecule.end();
     108typedef std::vector<atom *> atoms_t;
     109
     110atoms_t gatherAllAtoms(const KeySet &_FullMolecule)
     111{
     112  atoms_t atoms;
     113  for (KeySet::const_iterator iter = _FullMolecule.begin();
     114      iter != _FullMolecule.end();
    110115      ++iter) {
    111116    atom * const Walker = World::getInstance().getAtom(AtomById(*iter));
    112117    ASSERT( Walker != NULL,
    113         "SaturatedFragment::OutputConfig() - id "
     118        "gatherAllAtoms() - id "
    114119        +toString(*iter)+" is unknown to World.");
    115120    atoms.push_back(Walker);
     
    117122  LOG(4, "DEBUG: We have gathered the following atoms: " << atoms);
    118123
    119 //  bool LonelyFlag = false;
    120   // go through each atom of the fragment and gather all cut bonds in list
    121   typedef std::map<atom *, BondList > CutBonds_t;
     124  return atoms;
     125}
     126
     127typedef std::map<atom *, BondList > CutBonds_t;
     128
     129CutBonds_t gatherCutBonds(
     130    const atoms_t &_atoms,
     131    const KeySet &_set,
     132    const enum HydrogenTreatment _treatment,
     133    KeySet &_FullMolecule)
     134{
     135  //  bool LonelyFlag = false;
    122136  CutBonds_t CutBonds;
    123   for (std::vector<atom *>::const_iterator iter = atoms.begin();
    124       iter != atoms.end();
     137  for (atoms_t::const_iterator iter = _atoms.begin();
     138      iter != _atoms.end();
    125139      ++iter) {
    126140    atom * const Walker = *iter;
     
    135149      atom * const OtherWalker = (*BondRunner)->GetOtherAtom(Walker);
    136150      // if other atom is in key set
    137       if (set.find(OtherWalker->getId()) != set.end()) {
     151      if (_set.find(OtherWalker->getId()) != _set.end()) {
    138152        LOG(4, "DEBUG: Walker " << *Walker << " is bound to " << *OtherWalker << ".");
    139153//        if (OtherWalker->getId() > Walker->getId()) { // add bond (Nr check is for adding only one of both variants: ab, ba)
     
    150164        LOG(4, "DEBUG: Walker " << *Walker << " is bound to "
    151165            << *OtherWalker << ", who is not in this fragment molecule.");
    152         if ((treatment == ExcludeHydrogen) && (OtherWalker->getElementNo() == (atomicNumber_t)1)) {
     166        if ((_treatment == ExcludeHydrogen) && (OtherWalker->getElementNo() == (atomicNumber_t)1)) {
    153167          LOG(4, "REJECT: " << *OtherWalker << " is a hydrogen, that are excluded from the set.");
    154           FullMolecule.insert(OtherWalker->getId());
     168          _FullMolecule.insert(OtherWalker->getId());
    155169        } else {
    156170          LOG(3, "ACCEPT: Adding " << **BondRunner << " as a cut bond.");
     
    162176  }
    163177  LOG(4, "DEBUG: We have gathered the following CutBonds: " << CutBonds);
     178
     179  return CutBonds;
     180}
     181
     182void SaturatedFragment::saturate()
     183{
     184  // so far, we just have a set of keys. Hence, convert to atom refs
     185  // and gather all atoms in a vector
     186  std::vector<atom *> atoms = gatherAllAtoms(FullMolecule);
     187
     188  // go through each atom of the fragment and gather all cut bonds in list
     189  CutBonds_t CutBonds = gatherCutBonds(atoms, set, treatment, FullMolecule);
    164190
    165191  // go through all cut bonds and replace with a hydrogen
     
    172198      if (!saturateAtom(Walker, atomiter->second))
    173199        exit(1);
     200    }
     201  } else
     202    LOG(3, "INFO: We are not saturating cut bonds.");
     203}
     204
     205void SaturatedFragment::saturate(
     206    const GlobalSaturationPositions_t &_globalsaturationpositions)
     207{
     208  // so far, we just have a set of keys. Hence, convert to atom refs
     209  // and gather all atoms in a vector
     210  std::vector<atom *> atoms = gatherAllAtoms(FullMolecule);
     211
     212  // go through each atom of the fragment and gather all cut bonds in list
     213  CutBonds_t CutBonds = gatherCutBonds(atoms, set, treatment, FullMolecule);
     214
     215  // go through all cut bonds and replace with a hydrogen
     216  if (saturation == DoSaturate) {
     217    for (CutBonds_t::const_iterator atomiter = CutBonds.begin();
     218        atomiter != CutBonds.end(); ++atomiter) {
     219      atom * const Walker = atomiter->first;
     220      LOG(4, "DEBUG: We are now saturating dangling bonds of " << *Walker);
     221
     222      // gather set of positions for this atom from global map
     223      GlobalSaturationPositions_t::const_iterator mapiter =
     224          _globalsaturationpositions.find(Walker->getId());
     225      ASSERT( mapiter != _globalsaturationpositions.end(),
     226          "SaturatedFragment::saturate() - no global information for "
     227          +toString(*Walker));
     228      const SaturationsPositionsPerNeighbor_t &saturationpositions =
     229          mapiter->second;
     230
     231      // go through all cut bonds for this atom
     232      for (BondList::const_iterator bonditer = atomiter->second.begin();
     233          bonditer != atomiter->second.end(); ++bonditer) {
     234        atom * const OtherWalker = (*bonditer)->GetOtherAtom(Walker);
     235
     236        // get positions from global map
     237        SaturationsPositionsPerNeighbor_t::const_iterator positionsiter =
     238            saturationpositions.find(OtherWalker->getId());
     239        ASSERT(positionsiter != saturationpositions.end(),
     240            "SaturatedFragment::saturate() - no information on bond neighbor "
     241            +toString(*OtherWalker)+" to atom "+toString(*Walker));
     242        ASSERT(!positionsiter->second.empty(),
     243            "SaturatedFragment::saturate() - no positions for saturating bond to"
     244            +toString(*OtherWalker)+" to atom "+toString(*Walker));
     245
     246        // get typical bond distance from elements database
     247        double BondDistance = Walker->getType()->getHBondDistance(positionsiter->second.size()-1);
     248        if (BondDistance < 0.) {
     249          ELOG(2, "saturateAtoms() - no typical hydrogen bond distance of degree "
     250              +toString(positionsiter->second.size())+" for element "
     251              +toString(Walker->getType()->getName()));
     252          // try bond degree 1 distance
     253          BondDistance = Walker->getType()->getHBondDistance(1-1);
     254          if (BondDistance < 0.) {
     255            ELOG(1, "saturateAtoms() - no typical hydrogen bond distance for element "
     256                +toString(Walker->getType()->getName()));
     257            BondDistance = 1.;
     258          }
     259        }
     260        ASSERT( BondDistance > 0.,
     261            "SaturatedFragment::saturate() - negative bond distance");
     262
     263        // place hydrogen at each point
     264        LOG(4, "DEBUG: Places to saturate for atom " << *OtherWalker
     265            << " are " << positionsiter->second);
     266        atom * const father = Walker;
     267        for (SaturationsPositions_t::const_iterator positer = positionsiter->second.begin();
     268            positer != positionsiter->second.end(); ++positer) {
     269          const atom& hydrogen =
     270              setHydrogenReplacement(Walker, *positer, BondDistance, father);
     271          FullMolecule.insert(hydrogen.getId());
     272        }
     273      }
    174274    }
    175275  } else
  • src/Fragmentation/Exporters/SaturatedFragment.hpp

    rce0ca4 rf5fa48  
    2323#include "Parser/FormatParserStorage.hpp"
    2424
     25#include "LinearAlgebra/Vector.hpp"
     26
    2527class atom;
    2628class HydrogenPool;
    27 class Vector;
    2829
    2930/** The SaturatedFragment class acts as a wrapper to a KeySet by adding a list
     
    4344  typedef std::set<KeySet> KeySetsInUse_t;
    4445
     46  //!> List of points giving saturation positions for a single bond neighbor
     47  typedef std::list<Vector> SaturationsPositions_t;
     48  //!> map for one atom, containing the saturation points for all its neighbors
     49  typedef std::map<int, SaturationsPositions_t> SaturationsPositionsPerNeighbor_t;
     50  //!> containing the saturation points over all desired atoms required
     51  typedef std::map<int, SaturationsPositionsPerNeighbor_t> GlobalSaturationPositions_t;
     52
    4553  /** Constructor of SaturatedFragment requires \a set which we are tightly
    4654   * associated.
     
    4957   * \param _container container to add KeySet as in-use
    5058   * \param _hydrogens pool with hydrogens for saturation
     59   * \param _globalsaturationpositions saturation positions to be used
    5160   */
    5261  SaturatedFragment(
     
    5564      HydrogenPool &_hydrogens,
    5665      const enum HydrogenTreatment _treatment,
    57       const enum HydrogenSaturation saturation);
     66      const enum HydrogenSaturation saturation,
     67      const GlobalSaturationPositions_t &_globalsaturationpositions);
    5868
    5969  /** Destructor of class SaturatedFragment.
     
    101111  /** Helper function to lease and bring in place saturation hydrogens.
    102112   *
     113   * Here, we use local information to calculate saturation positions.
     114   *
    103115   */
    104116  void saturate();
     117
     118  /** Helper function to lease and bring in place saturation hydrogens.
     119   *
     120   * Here, saturation positions have to be calculated before and are fully
     121   * stored in \a _globalsaturationpositions.
     122   *
     123   * \param_globalsaturationpositions
     124   */
     125  void saturate(const GlobalSaturationPositions_t &_globalsaturationpositions);
     126
     127  /** Replaces all cut bonds with respect to the given atom by hydrogens.
     128   *
     129   * \param _atom atom whose cut bonds to saturate
     130   * \param _cutbonds list of cut bonds for \a _atom
     131   * \return true - bonds saturated, false - something went wrong
     132   */
     133  bool saturateAtom(atom * const _atom, const BondList &_cutbonds);
    105134
    106135  /** Helper function to get a hydrogen replacement for a given \a replacement.
  • src/Fragmentation/Exporters/unittests/SaturatedFragmentUnitTest.cpp

    rce0ca4 rf5fa48  
    6969  ASSERT_DO(Assert::Throw);
    7070
     71  SaturatedFragment::GlobalSaturationPositions_t globalpositions;
    7172  set = new KeySet;
    72   fragment = new SaturatedFragment(*set, KeySetsInUse, hydrogens, ExcludeHydrogen, DoSaturate);
     73  fragment = new SaturatedFragment(
     74      *set,
     75      KeySetsInUse,
     76      hydrogens,
     77      ExcludeHydrogen,
     78      DoSaturate,
     79      globalpositions);
    7380}
    7481
Note: See TracChangeset for help on using the changeset viewer.