Changeset e139180


Ignore:
Timestamp:
Aug 20, 2014, 1:04:08 PM (11 years ago)
Author:
Frederik Heber <heber@…>
Children:
d734ff
Parents:
0d5ca7
git-author:
Frederik Heber <heber@…> (06/04/14 11:22:49)
git-committer:
Frederik Heber <heber@…> (08/20/14 13:04:08)
Message:

Fixes to SaturatedFragment::saturateFragment().

  • properly setting up the number of points and the "old" polygon.
  • properly filling in the hydrogen atoms at the calculated places.
  • We have the number of remaining bonds plus the rest. The rest is the valence minus the number of remaining bonds each weighted with its degree. This gives the right number of places to put hydrogens and fill up the valence.
  • TESTS: Removed XFAIL from FragmentMolecule cycles regression test.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/Fragmentation/Exporters/SaturatedFragment.cpp

    r0d5ca7 re139180  
    3838#include "SaturatedFragment.hpp"
    3939
     40#include <algorithm>
    4041#include <cmath>
    4142#include <iostream>
     
    114115    atoms.push_back(Walker);
    115116  }
     117  LOG(4, "DEBUG: We have gathered the following atoms: " << atoms);
    116118
    117119//  bool LonelyFlag = false;
     
    123125      ++iter) {
    124126    atom * const Walker = *iter;
     127    // start with an empty list
     128    CutBonds.insert( std::make_pair(Walker, BondList() ));
    125129
    126130    // go through all bonds
     
    146150        LOG(4, "DEBUG: Walker " << *Walker << " is bound to "
    147151            << *OtherWalker << ", who is not in this fragment molecule.");
    148         if (saturation == DoSaturate) {
    149 //          LOG(3, "ACCEPT: Adding Hydrogen to " << (*iter)->Name << " and a bond in between.");
    150           if (CutBonds.count(Walker) == 0)
    151             CutBonds.insert( std::make_pair(Walker, BondList() ));
     152        if ((treatment == ExcludeHydrogen) && (OtherWalker->getElementNo() == (atomicNumber_t)1)) {
     153          LOG(4, "REJECT: " << *OtherWalker << " is a hydrogen, that are excluded from the set.");
     154          FullMolecule.insert(OtherWalker->getId());
     155        } else {
     156          LOG(3, "ACCEPT: Adding " << **BondRunner << " as a cut bond.");
     157          // there is always at least an empty list
    152158          CutBonds[Walker].push_back(*BondRunner);
    153159        }
    154 //        } else if ((treatment == ExcludeHydrogen) && (OtherWalker->getElementNo() == (atomicNumber_t)1)) {
    155 //          // just copy the atom if it's a hydrogen
    156 //          atom * const OtherWalker = Leaf->AddCopyAtom(OtherWalker);
    157 //          Leaf->AddBond((*iter), OtherWalker, (*BondRunner)->getDegree());
    158 //        }
    159         //NumBonds[(*iter)->getNr()] += Binder->getDegree();
    160160      }
    161161    }
    162162  }
     163  LOG(4, "DEBUG: We have gathered the following CutBonds: " << CutBonds);
    163164
    164165  // go through all cut bonds and replace with a hydrogen
    165   for (CutBonds_t::const_iterator atomiter = CutBonds.begin();
    166       atomiter != CutBonds.end(); ++atomiter) {
    167     atom * const Walker = atomiter->first;
    168     if (!saturateAtom(Walker, atomiter->second))
    169       exit(1);
    170   }
     166  if (saturation == DoSaturate) {
     167    for (CutBonds_t::const_iterator atomiter = CutBonds.begin();
     168        atomiter != CutBonds.end(); ++atomiter) {
     169      atom * const Walker = atomiter->first;
     170      LOG(4, "DEBUG: We are now saturating " << *Walker);
     171
     172      if (!saturateAtom(Walker, atomiter->second))
     173        exit(1);
     174    }
     175  } else
     176    LOG(3, "INFO: We are not saturating cut bonds.");
    171177}
    172178
     
    188194//  }
    189195
    190   // gather the nodes of the shape defined by the current set of bonded atoms
    191196  SphericalPointDistribution::Polygon_t Polygon;
    192   for (BondList::const_iterator bonditer = _cutbonds.begin();
    193       bonditer != _cutbonds.end(); ++bonditer) {
    194     Vector DistanceVector;
    195     if ((*bonditer)->leftatom == _atom)
    196       DistanceVector = (*bonditer)->rightatom->getPosition() - (*bonditer)->leftatom->getPosition();
    197     else
    198       DistanceVector = (*bonditer)->leftatom->getPosition() - (*bonditer)->rightatom->getPosition();
    199     // always use unit distances
    200     DistanceVector.Normalize();
    201     Polygon.push_back( DistanceVector );
    202   }
    203   LOG(3, "DEBUG: Polygon of atom " << _atom << " to saturate is " << Polygon);
    204 
    205   // get the new number of bonds (where all cut bonds are replaced by as
    206   // many hydrogens as is their degree)
    207   //  unsigned int NumberOfPoints = _atom->getElement().NoValenceOrbitals;
    208   unsigned int NumberOfPoints =
    209       _atom->getListOfBonds().size() - _cutbonds.size();
    210   const BondList& ListOfBonds = _atom->getListOfBonds();
    211   for (BondList::const_iterator BondRunner = ListOfBonds.begin();
    212       BondRunner != ListOfBonds.end();
    213       ++BondRunner) {
    214     NumberOfPoints += (*BondRunner)->getDegree();
    215     // ALTERNATIVE starting from valence:
    216     //    // if not one of the cut bonds, reduce by its bond degree -1 (for the one bond itself)
    217     //    if (_cutbonds.count(*BondRunner))
    218     //      NumberOfPoints -= (*BondRunner)->getDegree() - 1;
    219   }
    220   LOG(3, "DEBUG: There are " << NumberOfPoints
    221       << " to fill in in total for this atom " << _atom << ".");
     197  {
     198    // prepare a list of "uncut" bonds via set_difference. For this both lists
     199    // have to be sorted.
     200    typedef std::vector<bond::ptr> BondVector_t;
     201    BondVector_t ListOfBonds(_atom->getListOfBonds().begin(),_atom->getListOfBonds().end());
     202    std::sort(ListOfBonds.begin(), ListOfBonds.end());
     203    BondVector_t CutBonds(_cutbonds.begin(), _cutbonds.end());
     204    std::sort(CutBonds.begin(), CutBonds.end());
     205    const BondVector_t::iterator eraseiter = std::set_difference(
     206        ListOfBonds.begin(), ListOfBonds.end(),
     207        CutBonds.begin(), CutBonds.end(),
     208        ListOfBonds.begin());
     209    ListOfBonds.erase(eraseiter, ListOfBonds.end());
     210
     211    // gather the nodes of the shape defined by the current set of bonded atoms
     212    for (BondVector_t::const_iterator bonditer = ListOfBonds.begin();
     213        bonditer != ListOfBonds.end();
     214        ++bonditer) {
     215      Vector DistanceVector;
     216      if ((*bonditer)->leftatom == _atom)
     217        DistanceVector = (*bonditer)->rightatom->getPosition() - (*bonditer)->leftatom->getPosition();
     218      else
     219        DistanceVector = (*bonditer)->leftatom->getPosition() - (*bonditer)->rightatom->getPosition();
     220      // always use unit distances
     221      DistanceVector.Normalize();
     222      Polygon.push_back( DistanceVector );
     223    }
     224    LOG(3, "DEBUG: Polygon of atom " << *_atom << " to saturate is " << Polygon);
     225  }
     226
     227  unsigned int NumberOfPoints = 0;
     228  {
     229    // get the new number of bonds
     230    const BondList & ListOfBonds = _atom->getListOfBonds();
     231    NumberOfPoints = ListOfBonds.size() - _cutbonds.size(); // number remaining bonds
     232    NumberOfPoints += _atom->getElement().getNoValenceOrbitals(); // plus valence
     233    // minus remaining bonds weighted by its degree
     234    for (BondList::const_iterator BondRunner = ListOfBonds.begin();
     235        BondRunner != ListOfBonds.end();
     236        ++BondRunner) {
     237      // if not one of the cut bonds, reduce by its bond degree -1 (for the one bond itself)
     238      const BondList::const_iterator finditer =
     239          std::find(_cutbonds.begin(), _cutbonds.end(), *BondRunner);
     240      if (finditer == _cutbonds.end())
     241        NumberOfPoints -= (*BondRunner)->getDegree();
     242    }
     243    LOG(3, "DEBUG: There are " << NumberOfPoints
     244        << " places to fill in in total for this atom " << *_atom << ".");
     245  }
    222246
    223247  // get perfect node distribution for the given remaining atoms with respect
     
    287311    atom * const _father = _atom;
    288312    LOG(4, "DEBUG: Filling saturation hydrogen for atom " << _atom << " at " << *iter);
    289     setHydrogenReplacement(
     313    const atom& hydrogen = setHydrogenReplacement(
    290314        _atom,
    291315        *iter,
    292316        1.,
    293317        _father);
     318    FullMolecule.insert(hydrogen.getId());
    294319  }
    295320
     
    355380}
    356381
    357 void SaturatedFragment::setHydrogenReplacement(
     382const atom& SaturatedFragment::setHydrogenReplacement(
    358383    const atom * const _OwnerAtom,
    359384    const Vector &_position,
     
    368393  _atom->father = _father;
    369394  SaturationHydrogens.insert(_atom->getId());
     395  return *_atom;
    370396}
    371397
  • TabularUnified src/Fragmentation/Exporters/SaturatedFragment.hpp

    r0d5ca7 re139180  
    117117   * \param _distance scale factor to the distance (default 1.)
    118118   * \param _father bond partner of \a _OwnerAtom that is replaced
     119   * \return pointer to saturation hydrogen atom
    119120   */
    120   void setHydrogenReplacement(
     121  const atom& setHydrogenReplacement(
    121122      const atom * const _OwnerAtom,
    122123      const Vector &_position,
  • TabularUnified tests/regression/Fragmentation/FragmentMolecule/testsuite-fragmentation-fragment-molecule.at

    r0d5ca7 re139180  
    3737AT_SETUP([Fragmentation - Fragmentation with cycles])
    3838AT_KEYWORDS([fragmentation fragment-molecule cycle])
    39 AT_XFAIL_IF([/bin/true])
    4039
    4140file=benzene.pdb
Note: See TracChangeset for help on using the changeset viewer.