Changeset b03d7d


Ignore:
Timestamp:
May 23, 2017, 8:58:02 PM (8 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
ForceAnnealing_tocheck
Children:
175543
Parents:
9190e6
Message:

tempcommit: Merge with 9190e6a

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/MoleculeAction/ForceAnnealingAction.cpp

    r9190e6 rb03d7d  
    9393      set,
    9494      true,
    95       params.steps.get());
     95      params.steps.get(),
     96      params.MaxDistance.get());
    9697  // parse forces into next step
    9798  if (!params.forcesfile.get().string().empty()) {
  • src/Actions/MoleculeAction/ForceAnnealingAction.def

    r9190e6 rb03d7d  
    1616// ValueStorage by the token "Z" -> first column: int, Z, "Z"
    1717// "undefine" if no parameters are required, use (NOPARAM_DEFAULT) for each (undefined) default value
    18 #define paramtypes (boost::filesystem::path)(unsigned int)(bool)
    19 #define paramtokens ("forces-file")("steps")("output-every-step")
    20 #define paramdescriptions ("file containing")("fixed number of optimization steps to be performed")("whether WorldTime should be increased and output written after every step, useful if optimization might hang")
    21 #define paramdefaults (PARAM_DEFAULT(""))(NOPARAM_DEFAULT)(PARAM_DEFAULT("0"))
    22 #define paramreferences (forcesfile)(steps)(DoOutput)
     18#define paramtypes (boost::filesystem::path)(unsigned int)(bool)(int)
     19#define paramtokens ("forces-file")("steps")("output-every-step")("max-distance")
     20#define paramdescriptions ("file containing")("fixed number of optimization steps to be performed")("whether WorldTime should be increased and output written after every step, useful if optimization might hang")("maximum distance to which bond graph is taken into account")
     21#define paramdefaults (PARAM_DEFAULT(""))(NOPARAM_DEFAULT)(PARAM_DEFAULT("0"))(PARAM_DEFAULT(0))
     22#define paramreferences (forcesfile)(steps)(DoOutput)(MaxDistance)
    2323#define paramvalids \
    2424(DummyValidator< boost::filesystem::path >()) \
    2525(NotZeroValidator< unsigned int >()) \
    26 (DummyValidator<bool>())
     26(DummyValidator<bool>()) \
     27(DummyValidator< int >())
    2728
    2829#define statetypes (std::vector<AtomicInfo>)(std::vector<AtomicInfo>)
  • src/Dynamics/ForceAnnealing.hpp

    r9190e6 rb03d7d  
    2020#include "CodePatterns/Log.hpp"
    2121#include "CodePatterns/Verbose.hpp"
     22#include "Descriptors/AtomIdDescriptor.hpp"
    2223#include "Dynamics/AtomicForceManipulator.hpp"
    2324#include "Fragmentation/ForceMatrix.hpp"
     
    3839 * step width (we cannot perform a line search, as we have no control over the
    3940 * calculation of the forces).
     41 *
     42 * However, we do use the bond graph, i.e. if a single atom needs to be shifted
     43 * to the left, then the whole molecule left of it is shifted, too. This is
     44 * controlled by the \a max_distance parameter.
    4045 */
    4146template <class T>
     
    5156   * \param _IsAngstroem whether length units are in angstroem or bohr radii
    5257   * \param _maxSteps number of optimization steps to perform
     58   * \param _max_distance up to this bond order is bond graph taken into account.
    5359   */
    5460  ForceAnnealing(
    5561      AtomSetMixin<T> &_atoms,
    5662      bool _IsAngstroem,
    57       const size_t _maxSteps) :
     63      const size_t _maxSteps,
     64      const int _max_distance) :
    5865    AtomicForceManipulator<T>(_atoms, 1., _IsAngstroem),
    59     maxSteps(_maxSteps)
     66    maxSteps(_maxSteps),
     67    max_distance(_max_distance),
     68    damping_factor(0.5)
    6069  {}
    6170  /** Destructor of class ForceAnnealing.
     
    130139      LOG(3, "DEBUG: Update would be " << PositionUpdate);
    131140
    132       // add update to central atom
    133       const atomId_t atomid = (*iter)->getId();
    134       if (GatheredUpdates.count(atomid)) {
    135         GatheredUpdates[atomid] += PositionUpdate;
    136       } else
    137         GatheredUpdates.insert( std::make_pair(atomid, PositionUpdate) );
     141//      // add update to central atom
     142//      const atomId_t atomid = (*iter)->getId();
     143//      if (GatheredUpdates.count(atomid)) {
     144//        GatheredUpdates[atomid] += PositionUpdate;
     145//      } else
     146//        GatheredUpdates.insert( std::make_pair(atomid, PositionUpdate) );
    138147
    139148      // We assume that a force is local, i.e. a bond is too short yet and hence
     
    145154
    146155      /// get all nodes from bonds in the direction of the current force
    147       const size_t max_distance = 4;
    148       const double damping_factor = 0.9;
    149156
    150157      // remove edges facing in the wrong direction
     
    184191            "ForceAnnealing() - could not find distance to an atom.");
    185192        const double factor = pow(damping_factor, diter->second);
     193        LOG(3, "DEBUG: Update for atom #" << *setiter << " will be "
     194            << factor << "*" << PositionUpdate);
    186195        if (GatheredUpdates.count((*setiter))) {
    187196          GatheredUpdates[(*setiter)] += factor*PositionUpdate;
     
    199208          maxComponents[i] = currentGradient[i];
    200209
    201       // are we in initial step? Then don't check against velocity
    202       if ((currentStep > 1) && (!(*iter)->getAtomicVelocity().IsZero()))
    203         // update with currentDelta tells us how the current gradient relates to
    204         // the last one: If it has become larger, reduce currentDelta
    205         if ((PositionUpdate.ScalarProduct((*iter)->getAtomicVelocity()) < 0)
    206             && (currentDeltat > MinimumDeltat)) {
    207           currentDeltat = .5*currentDeltat;
    208           LOG(2, "DEBUG: Upgrade in other direction: " << PositionUpdate.NormSquared()
    209               << " > " << (*iter)->getAtomicVelocity().NormSquared()
    210               << ", decreasing deltat: " << currentDeltat);
    211           PositionUpdate = currentDeltat * currentGradient;
    212         }
    213 
    214       // finally set new values
    215       (*iter)->setPosition(currentPosition + PositionUpdate);
    216       (*iter)->setAtomicVelocity(PositionUpdate);
    217       //std::cout << "Id of atom is " << (*iter)->getId() << std::endl;
    218 //        (*iter)->VelocityVerletUpdateU((*iter)->getId(), NextStep-1, Deltat, IsAngstroem);
    219 
    220210      // reset force vector for next step except on final one
    221211      if (currentStep != maxSteps)
    222212        (*iter)->setAtomicForce(zeroVec);
     213    }
     214    // apply the gathered updates
     215    for (std::map<atomId_t, Vector>::const_iterator iter = GatheredUpdates.begin();
     216        iter != GatheredUpdates.end(); ++iter) {
     217      const atomId_t &atomid = iter->first;
     218      const Vector &update = iter->second;
     219      atom* const walker = World::getInstance().getAtom(AtomById(atomid));
     220      ASSERT( walker != NULL,
     221          "ForceAnnealing() - walker with id "+toString(atomid)+" has suddenly disappeared.");
     222      walker->setPosition( walker->getPosition() + update );
     223      walker->setAtomicVelocity(update);
     224      LOG(3, "DEBUG: Applying update " << update << " to atom " << *walker);
    223225    }
    224226
     
    255257  //!> minimum deltat for internal while loop (adaptive step width)
    256258  static double MinimumDeltat;
     259  //!> contains the maximum bond graph distance up to which shifts of a single atom are spread
     260  const int max_distance;
     261  //!> the shifted is dampened by this factor with the power of the bond graph distance to the shift causing atom
     262  const double damping_factor;
    257263};
    258264
Note: See TracChangeset for help on using the changeset viewer.