Changeset 825d33
- Timestamp:
- Apr 10, 2018, 6:43:30 AM (7 years ago)
- 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)
- Location:
- src/Dynamics
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Dynamics/BondVectors.cpp
r9861d0 r825d33 39 39 40 40 #include <algorithm> 41 #include <functional> 41 42 #include <iterator> 43 #include <numeric> 42 44 43 45 #include "CodePatterns/Assert.hpp" … … 46 48 #include "Atom/atom.hpp" 47 49 #include "Bond/bond.hpp" 50 #include "Helpers/defs.hpp" 48 51 49 52 void BondVectors::recalculateBondVectorsAtStep( … … 107 110 return BondVectors; 108 111 } 112 113 BondVectors::weights_t BondVectors::getWeightsForAtomAtStep( 114 const atom &_walker, 115 const size_t &_step) const 116 { 117 const std::vector<Vector> BondVectors = 118 getAtomsBondVectorsAtStep(_walker, _step); 119 120 weights_t weights; 121 for (std::vector<Vector>::const_iterator iter = BondVectors.begin(); 122 iter != BondVectors.end(); ++iter) { 123 std::vector<double> scps; 124 scps.reserve(BondVectors.size()); 125 std::transform( 126 BondVectors.begin(), BondVectors.end(), 127 std::back_inserter(scps), 128 boost::bind(static_cast< double (*)(double) >(&fabs), 129 boost::bind(&Vector::ScalarProduct, boost::cref(*iter), _1)) 130 ); 131 const double scp_sum = std::accumulate(scps.begin(), scps.end(), 0.); 132 ASSERT( (scp_sum-1.) > -MYEPSILON, 133 "ForceAnnealing() - sum of weights must be equal or larger one but is " 134 +toString(scp_sum)); 135 weights.push_back( 1./scp_sum ); 136 } 137 LOG(4, "DEBUG: Weights for atom #" << _walker.getId() << ": " << weights); 138 139 // for testing we check whether all weighted scalar products now come out as 1. 140 #ifndef NDEBUG 141 for (std::vector<Vector>::const_iterator iter = BondVectors.begin(); 142 iter != BondVectors.end(); ++iter) { 143 std::vector<double> scps; 144 scps.reserve(BondVectors.size()); 145 std::transform( 146 BondVectors.begin(), BondVectors.end(), 147 weights.begin(), 148 std::back_inserter(scps), 149 boost::bind(static_cast< double (*)(double) >(&fabs), 150 boost::bind(std::multiplies<double>(), 151 boost::bind(&Vector::ScalarProduct, boost::cref(*iter), _1), 152 _2)) 153 ); 154 const double scp_sum = std::accumulate(scps.begin(), scps.end(), 0.); 155 ASSERT( fabs(scp_sum - 1.) < MYEPSILON, 156 "ForceAnnealing::operator() - for BondVector "+toString(*iter) 157 +" we have weighted scalar product of "+toString(scp_sum)+" != 1."); 158 } 159 #endif 160 return weights; 161 } -
src/Dynamics/BondVectors.hpp
r9861d0 r825d33 83 83 const size_t &_step) const; 84 84 85 //!> typedef for the weights for the Bondvectors of a single atom 86 typedef std::deque<double> weights_t; 87 88 /** Calculates the weights for a frame where each Bondvector of the 89 * given atom is a vector of the frame. 90 * 91 * The idea is that we can represent any vector by appropriate weights such 92 * that is still sums up to one. 93 * 94 * \param _walker atom to get BondVectors for 95 * \param _step time step for which the bond vector is request 96 */ 97 weights_t getWeightsForAtomAtStep( 98 const atom &_walker, 99 const size_t &_step) const; 100 85 101 private: 86 102 /** Calculates the bond vector for each bond in the internal container. -
src/Dynamics/ForceAnnealing.hpp
r9861d0 r825d33 292 292 293 293 // 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; 296 295 std::vector<weights_per_atom_t> weights_per_atom(2); 297 296 for (size_t timestep = 0; timestep <= 1; ++timestep) { … … 313 312 314 313 // 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); 316 316 317 317 // go through all its bonds and calculate what magnitude is represented 318 318 // 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 = 320 320 weights_per_atom[timestep].insert( 321 std::make_pair(walker.getId(), weights_t()) ); 321 std::make_pair(walker.getId(), 322 bv.getWeightsForAtomAtStep(walker, CurrentStep)) ); 322 323 ASSERT( inserter.second, 323 324 "ForceAnnealing::operator() - weight map for atom "+toString(walker) 324 325 +" 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?"); 365 331 366 332 // projected gradient over all bonds and place in one of projected_forces 367 333 // using the obtained weights 368 334 { 369 weights_t::const_iterator weightiter = weights.begin();335 BondVectors::weights_t::const_iterator weightiter = weights.begin(); 370 336 std::vector<Vector>::const_iterator vectoriter = BondVectors.begin(); 371 337 Vector forcesum_check;
Note:
See TracChangeset
for help on using the changeset viewer.