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).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.