Ignore:
Timestamp:
Apr 10, 2018, 6:43:30 AM (7 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
AutomationFragmentation_failures, Candidate_v1.6.1, ChemicalSpaceEvaluator, Exclude_Hydrogens_annealWithBondGraph, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_contraction-expansion, Gui_displays_atomic_force_velocity, PythonUI_with_named_parameters, StoppableMakroAction, TremoloParser_IncreasedPrecision
Children:
c1c6cb
Parents:
9861d0
git-author:
Frederik Heber <frederik.heber@…> (06/29/17 14:53:38)
git-committer:
Frederik Heber <frederik.heber@…> (04/10/18 06:43:30)
Message:

Extracted calculation of weights per atom into BondVectors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Dynamics/ForceAnnealing.hpp

    r9861d0 r825d33  
    292292
    293293    // for each atom we need to gather weights and then project the gradient
    294     typedef std::deque<double> weights_t;
    295     typedef std::map<atomId_t, weights_t > weights_per_atom_t;
     294    typedef std::map<atomId_t, BondVectors::weights_t > weights_per_atom_t;
    296295    std::vector<weights_per_atom_t> weights_per_atom(2);
    297296    for (size_t timestep = 0; timestep <= 1; ++timestep) {
     
    313312
    314313          // gather subset of BondVectors for the current atom
    315           std::vector<Vector> BondVectors = bv.getAtomsBondVectorsAtStep(walker, CurrentStep);
     314          const std::vector<Vector> BondVectors =
     315              bv.getAtomsBondVectorsAtStep(walker, CurrentStep);
    316316
    317317          // go through all its bonds and calculate what magnitude is represented
    318318          // by the others i.e. sum of scalar products against other bonds
    319           std::pair<weights_per_atom_t::iterator, bool> inserter =
     319          const std::pair<weights_per_atom_t::iterator, bool> inserter =
    320320              weights_per_atom[timestep].insert(
    321                   std::make_pair(walker.getId(), weights_t()) );
     321                  std::make_pair(walker.getId(),
     322                  bv.getWeightsForAtomAtStep(walker, CurrentStep)) );
    322323          ASSERT( inserter.second,
    323324              "ForceAnnealing::operator() - weight map for atom "+toString(walker)
    324325              +" and time step "+toString(timestep)+" already filled?");
    325           weights_t &weights = inserter.first->second;
    326           for (std::vector<Vector>::const_iterator iter = BondVectors.begin();
    327               iter != BondVectors.end(); ++iter) {
    328             std::vector<double> scps;
    329             scps.reserve(BondVectors.size());
    330             std::transform(
    331                 BondVectors.begin(), BondVectors.end(),
    332                 std::back_inserter(scps),
    333                 boost::bind(static_cast< double (*)(double) >(&fabs),
    334                     boost::bind(&Vector::ScalarProduct, boost::cref(*iter), _1))
    335                 );
    336             const double scp_sum = std::accumulate(scps.begin(), scps.end(), 0.);
    337             ASSERT( (scp_sum-1.) > -MYEPSILON,
    338                 "ForceAnnealing() - sum of weights must be equal or larger one but is "
    339                 +toString(scp_sum));
    340             weights.push_back( 1./scp_sum );
    341           }
    342           LOG(4, "DEBUG: Weights for atom #" << walker.getId() << ": " << weights);
    343 
    344           // for testing we check whether all weighted scalar products now come out as 1.
    345 #ifndef NDEBUG
    346           for (std::vector<Vector>::const_iterator iter = BondVectors.begin();
    347               iter != BondVectors.end(); ++iter) {
    348             std::vector<double> scps;
    349             scps.reserve(BondVectors.size());
    350             std::transform(
    351                 BondVectors.begin(), BondVectors.end(),
    352                 weights.begin(),
    353                 std::back_inserter(scps),
    354                 boost::bind(static_cast< double (*)(double) >(&fabs),
    355                     boost::bind(std::multiplies<double>(),
    356                         boost::bind(&Vector::ScalarProduct, boost::cref(*iter), _1),
    357                         _2))
    358                 );
    359             const double scp_sum = std::accumulate(scps.begin(), scps.end(), 0.);
    360             ASSERT( fabs(scp_sum - 1.) < MYEPSILON,
    361                 "ForceAnnealing::operator() - for BondVector "+toString(*iter)
    362                 +" we have weighted scalar product of "+toString(scp_sum)+" != 1.");
    363           }
    364 #endif
     326          BondVectors::weights_t &weights = inserter.first->second;
     327          ASSERT( weights.size() == ListOfBonds.size(),
     328              "ForceAnnealing::operator() - number of weights "
     329              +toString(weights.size())+" does not match number of bonds "
     330              +toString(ListOfBonds.size())+", error in calculation?");
    365331
    366332          // projected gradient over all bonds and place in one of projected_forces
    367333          // using the obtained weights
    368334          {
    369             weights_t::const_iterator weightiter = weights.begin();
     335            BondVectors::weights_t::const_iterator weightiter = weights.begin();
    370336            std::vector<Vector>::const_iterator vectoriter = BondVectors.begin();
    371337            Vector forcesum_check;
Note: See TracChangeset for help on using the changeset viewer.