Changeset 4b2adf for src/Dynamics


Ignore:
Timestamp:
Jun 20, 2018, 8:20:43 AM (7 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
AutomationFragmentation_failures, Candidate_v1.6.1, ChemicalSpaceEvaluator, Exclude_Hydrogens_annealWithBondGraph, ForceAnnealing_with_BondGraph_contraction-expansion, StoppableMakroAction
Children:
70caa3
Parents:
e3ce0e
git-author:
Frederik Heber <frederik.heber@…> (12/03/17 17:31:16)
git-committer:
Frederik Heber <frederik.heber@…> (06/20/18 08:20:43)
Message:

ForceAnnealiing now returns bool to indicate stop condition for MakroAction.

  • Introducing FORCE_THRESHOLD below which we always stop.
  • modified (simplified) bond side picking criterion.
  • added some explanations to annealWithBondgraph().
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Dynamics/ForceAnnealing.hpp

    re3ce0e r4b2adf  
    7878    maxSteps(_maxSteps),
    7979    max_distance(_max_distance),
    80     damping_factor(_damping_factor)
     80    damping_factor(_damping_factor),
     81    FORCE_THRESHOLD(1e-8)
    8182  {}
    8283
     
    9495   * \param _TimeStep time step to update (i.e. \f$ t + \Delta t \f$ in the sense of the velocity verlet)
    9596   * \param offset offset in matrix file to the first force component
     97   * \return false - need to continue annealing, true - may stop because forces very small
    9698   * \todo This is not yet checked if it is correctly working with DoConstrainedMD set >0.
    9799   */
    98   void operator()(
     100  bool operator()(
    99101      const int _TimeStep,
    100102      const size_t _offset,
     
    135137        << currentStep << " are " << maxComponents);
    136138
     139    // check whether are smaller than threshold
     140    bool AnnealingFinished = false;
     141    double maxcomp = 0.;
     142    for (size_t i=0;i<NDIM;++i)
     143      maxcomp = std::max(maxcomp, fabs(maxComponents[i]));
     144    if (maxcomp < FORCE_THRESHOLD) {
     145      LOG(1, "STATUS: Force components are all less than " << FORCE_THRESHOLD
     146          << ", stopping.");
     147      currentStep = maxSteps;
     148      AnnealingFinished = true;
     149    }
     150
    137151    // are we in final step? Remember to reset static entities
    138152    if (currentStep == maxSteps) {
     
    140154      reset();
    141155    }
     156
     157    return AnnealingFinished;
    142158  }
    143159
     
    431447      LOG(3, "DEBUG: Update would be " << stepwidth << "*" << currentGradient << " = " << PositionUpdate);
    432448
     449      /** for each atom, we imagine a plane at the position of the atom with
     450       * its atomic gradient as the normal vector. We go through all its bonds
     451       * and check on which side of the plane the bond is. This defines whether
     452       * the bond is contracting (+) or expanding (-) with respect to this atom.
     453       *
     454       * A bond has two atoms, however. Hence, we do this for either atom and
     455       * look at the combination: Is it in sum contracting or expanding given
     456       * both projected_forces?
     457       */
     458
    433459      /** go through all bonds and check projected_forces and side of plane
    434460       * the idea is that if all bonds on one side are contracting ones or expanding,
     
    440466       * if they are not mixed on either side, then we also only shift the
    441467       * atom, namely away from expanding and towards contracting bonds.
     468       *
     469       * We may get this information right away by looking at the projected_forces.
     470       * They give the atomic gradient of either atom projected onto the BondVector
     471       * with an additional weight in [0,1].
    442472       */
    443473
     
    456486        std::vector<double> &forcelist = (&walker == current_bond->leftatom) ?
    457487            projected_forces[BondVectors::leftside] : projected_forces[BondVectors::rightside];
     488        // note that projected_forces has sign such as to indicate whether
     489        // atomic gradient wants bond to contract (-) or expand (+).
     490        // This goes into sides: Minus side points away from gradient, plus side point
     491        // towards gradient.
     492        //
     493        // the sum of both bond sides goes into types, depending on which is
     494        // stronger if either wants a different thing
    458495        const double &temp = forcelist[index];
    459496        sides.push_back( -1.*temp/fabs(temp) ); // BondVectors has exactly opposite sign for sides decision
     
    515552        LOG(4, "DEBUG: Chosen side is " << sideno << " with type " << typeside[sideno]);
    516553        ASSERT( (typeside[sideno] == contracting) || (typeside[sideno] == expanding),
    517             "annealWithBondGraph_BB() - chosen side is either expanding nor contracting.");
     554            "annealWithBondGraph_BB() - chosen side is neither expanding nor contracting.");
    518555        // one side is not mixed, all bonds on one side are of same type
    519556        // hence, find out which bonds to exclude
    520557        const BondList& ListOfBonds = walker.getListOfBonds();
    521558
    522         // away from gradient (minus) and contracting
    523         // or towards gradient (plus) and expanding
    524         // gather all on same side and remove
    525         const double sign =
    526             (sides[first_per_side[sideno]] == types[first_per_side[sideno]])
    527             ? sides[first_per_side[sideno]] : -1.*sides[first_per_side[sideno]];
     559        // sideno is away (0) or in direction (1) of gradient
     560        // tpyes[first_per_side[sideno]] is either contracting (-1) or expanding (+1)
     561        // : side (i), where (i) means which bonds we keep for the BFS, bonds
     562        // on side (-i) are removed
     563        // If all bonds on side away (0) want expansion (+1), move towards side with atom: side 1
     564        // if all bonds side towards (1) want contraction (-1), move away side with atom : side -1
     565
     566        // unsure whether this or do nothing in the remaining cases:
     567        // If all bonds on side toward (1) want expansion (+1), move away side with atom : side -1
     568        //    (the reasoning is that the bond's other atom must have a stronger
     569        //     gradient in the same direction and they push along atoms in
     570        //     gradient direction: we don't want to interface with those.
     571        //     Hence, move atoms along on away side
     572        // if all bonds side away (0) want contraction (-1), move towards side with atom: side 1
     573        //    (the reasoning is the same, don't interfere with update from
     574        //     stronger gradient)
     575        // hence, the decision is only based on sides once we have picked a side
     576        // depending on all bonds associated with have same good type.
     577        const double sign = sides[first_per_side[sideno]];
    528578        LOG(4, "DEBUG: Removing edges from side with sign " << sign);
    529579        BondList::const_iterator bonditer = ListOfBonds.begin();
     
    649699  //!> the shifted is dampened by this factor with the power of the bond graph distance to the shift causing atom
    650700  const double damping_factor;
     701  //!> threshold for force components to stop annealing
     702  const double FORCE_THRESHOLD;
    651703};
    652704
Note: See TracChangeset for help on using the changeset viewer.