Changeset 6145577


Ignore:
Timestamp:
Apr 10, 2018, 6:43:12 AM (7 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
AutomationFragmentation_failures, Candidate_v1.6.1, ChemicalSpaceEvaluator, Enhanced_StructuralOptimization_continued, Exclude_Hydrogens_annealWithBondGraph, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_contraction-expansion, Gui_displays_atomic_force_velocity, PythonUI_with_named_parameters, StoppableMakroAction, TremoloParser_IncreasedPrecision
Children:
c87d6e
Parents:
8c6b68
git-author:
Frederik Heber <frederik.heber@…> (08/03/17 10:47:26)
git-committer:
Frederik Heber <frederik.heber@…> (04/10/18 06:43:12)
Message:

FIX: ForceAnnealingAction's Undo is again working.

  • AtomicInfo::setAtom() and SetAtomsFromAtomicInfo() now accept a time step. This allows to undo changes to the old state (where forces might have been passed to) and the current state (modified by time integration).
  • TESTFIX: ForceAnnealing's undo test.conf was no longer valid since the additional time stepping is extracted (and the tests were changed already). I.e. the extra trajectory step is because of step-world-time and not because of force-annealing. Hence, it should not be undone here.
Files:
8 edited

Legend:

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

    r8c6b68 r6145577  
    7171    return Action::failure;
    7272  }
     73
     74  size_t CurrentStep = WorldTime::getInstance().getTime();
     75  if (CurrentStep == 0) {
     76    ELOG(1, "WorldTime must be at least at step 1 already, use step-world-time if necessary.");
     77    return Action::failure;
     78  }
     79
    7380  // first, we need to sort the mixin according to their ids (as selected atoms are sorted
    7481  // according to their arbitrary address in memory)
     
    7683
    7784  // create undo state for all selected atoms (undo info)
    78   std::vector<AtomicInfo> UndoInfo;
    79   UndoInfo.reserve(set.size());
    80   {
    81     for (World::AtomSelectionConstIterator iter = World::getInstance().beginAtomSelection();
    82         iter != World::getInstance().endAtomSelection();
    83         ++iter)
    84       UndoInfo.push_back(AtomicInfo(*(iter->second)));
     85  std::vector< std::vector<AtomicInfo> > UndoInfo(2);
     86  for (int i=0;i<2;++i) {
     87    UndoInfo[i].reserve(set.size());
     88    {
     89      for (World::AtomSelectionConstIterator iter = World::getInstance().beginAtomSelection();
     90          iter != World::getInstance().endAtomSelection();
     91          ++iter)
     92        UndoInfo[i].push_back(AtomicInfo(*(iter->second), CurrentStep-i));
     93    }
    8594  }
    8695
     
    93102      params.MaxDistance.get(),
    94103      params.DampingFactor.get());
    95   size_t CurrentStep = WorldTime::getInstance().getTime();
    96   if (CurrentStep == 0) {
    97     ELOG(1, "WorldTime must be at least at step 1 already, use step-world-time if necessary.");
    98     return Action::failure;
    99   }
    100104
    101105  // parse forces into last step (assuming we stepped on already)
     
    113117  STATUS("Successfully optimized structure by one step.");
    114118
    115   std::vector<AtomicInfo> RedoInfo;
    116   RedoInfo.reserve(set.size());
    117   {
    118     for (World::AtomSelectionConstIterator iter = World::getInstance().beginAtomSelection();
    119         iter != World::getInstance().endAtomSelection();
    120         ++iter)
    121       RedoInfo.push_back(AtomicInfo(*(iter->second)));
     119  std::vector< std::vector<AtomicInfo> > RedoInfo(2);
     120  for (int i=0;i<2;++i) {
     121    RedoInfo[i].reserve(set.size());
     122    {
     123      for (World::AtomSelectionConstIterator iter = World::getInstance().beginAtomSelection();
     124          iter != World::getInstance().endAtomSelection();
     125          ++iter)
     126        RedoInfo[i].push_back(AtomicInfo(*(iter->second), CurrentStep-i));
     127    }
    122128  }
     129
    123130  MoleculeForceAnnealingState *UndoState =
    124131    new MoleculeForceAnnealingState(UndoInfo, RedoInfo, params);
     
    130137  MoleculeForceAnnealingState *state =
    131138      assert_cast<MoleculeForceAnnealingState*>(_state.get());
     139  const size_t CurrentStep = WorldTime::getInstance().getTime();
    132140
    133141  // set stored old state
    134   SetAtomsFromAtomicInfo(state->UndoInfo);
     142  for (int i=0;i<2;++i)
     143    SetAtomsFromAtomicInfo(state->UndoInfo[i], CurrentStep-i);
    135144
    136145  return ActionState::ptr(_state);
     
    140149  MoleculeForceAnnealingState *state =
    141150      assert_cast<MoleculeForceAnnealingState*>(_state.get());
     151  const size_t CurrentStep = WorldTime::getInstance().getTime();
    142152
    143153  // set stored new state
    144   SetAtomsFromAtomicInfo(state->RedoInfo);
     154  for (int i=0;i<2;++i)
     155    SetAtomsFromAtomicInfo(state->RedoInfo[i], CurrentStep-i);
    145156
    146157  return ActionState::ptr(_state);
  • src/Actions/MoleculeAction/ForceAnnealingAction.def

    r8c6b68 r6145577  
    3232(DummyValidator<bool>())
    3333
    34 #define statetypes (std::vector<AtomicInfo>)(std::vector<AtomicInfo>)
     34#define statetypes (std::vector< std::vector<AtomicInfo> >)(std::vector< std::vector<AtomicInfo> >)
    3535#define statereferences (UndoInfo)(RedoInfo)
    3636
  • src/Actions/UndoRedoHelpers.cpp

    r8c6b68 r6145577  
    145145}
    146146
    147 void MoleCuilder::SetAtomsFromAtomicInfo(const std::vector<AtomicInfo> &_movedatoms)
     147void MoleCuilder::SetAtomsFromAtomicInfo(
     148    const std::vector<AtomicInfo> &_movedatoms,
     149    const unsigned int _step)
    148150{
    149151  BOOST_FOREACH( const AtomicInfo &_atominfo, _movedatoms) {
     
    153155        "MoleCuilder::SetAtomsFromAtomicInfo() - cannot find atom with id "
    154156        +toString(id)+" in the world.");
    155     _atominfo.setAtom( *_atom );
     157    _atominfo.setAtom( *_atom, _step );
    156158  }
    157159}
  • src/Actions/UndoRedoHelpers.hpp

    r8c6b68 r6145577  
    1919#include "Atom/AtomicInfo.hpp"
    2020#include "Bond/BondInfo.hpp"
     21#include "WorldTime.hpp"
    2122
    2223namespace MoleCuilder {
     
    6162   *
    6263   * @param movedatoms vector of atomicInfo
     64   * @param _step set state information for given world time
    6365   */
    64   void SetAtomsFromAtomicInfo(const std::vector<AtomicInfo> &_movedatoms);
     66  void SetAtomsFromAtomicInfo(
     67      const std::vector<AtomicInfo> &_movedatoms,
     68      const unsigned int _step = WorldTime::getTime());
    6569
    6670  /** Selects all atoms inside the given vector
  • src/Atom/AtomicInfo.cpp

    r8c6b68 r6145577  
    5858{}
    5959
    60 AtomicInfo::AtomicInfo(const atom &_atom) :
    61     Position(_atom.getPosition()),
     60AtomicInfo::AtomicInfo(const atom &_atom, unsigned int _step) :
     61    Position(_atom.getPositionAtStep(_step)),
    6262    Type(_atom.getType()),
    6363    charge(_atom.getCharge()),
    64     Velocity(_atom.getAtomicVelocity()),
    65     Force(_atom.getAtomicForce()),
     64    Velocity(_atom.getAtomicVelocityAtStep(_step)),
     65    Force(_atom.getAtomicForceAtStep(_step)),
    6666    FatherId(_atom.father->getId()),
    6767    MolId(0),
     
    101101
    102102
    103 bool AtomicInfo::setAtom(atom &_atom) const
     103bool AtomicInfo::setAtom(atom &_atom, const unsigned int _step) const
    104104{
    105   _atom.setPosition(Position);
     105  _atom.setPositionAtStep(_step, Position);
    106106  _atom.setType(Type);
    107107  _atom.setCharge(charge);
    108   _atom.setAtomicVelocity(Velocity);
    109   _atom.setAtomicForce(Force);
     108  _atom.setAtomicVelocityAtStep(_step, Velocity);
     109  _atom.setAtomicForceAtStep(_step, Force);
    110110
    111111  // set old id
  • src/Atom/AtomicInfo.hpp

    r8c6b68 r6145577  
    2020
    2121#include "Bond/BondInfo.hpp"
     22#include "WorldTime.hpp"
    2223
    2324class atom;
     
    3132public:
    3233  AtomicInfo();
    33   AtomicInfo(const atom &_atom);
     34  AtomicInfo(const atom &_atom, const unsigned int _step = WorldTime::getTime());
    3435  AtomicInfo(const AtomicInfo &_atominfo);
    3536  ~AtomicInfo();
    3637
    37   bool setAtom(atom &_atom) const;
     38  bool setAtom(atom &_atom, const unsigned int _step = WorldTime::getTime()) const;
    3839  atomId_t getId() const;
    3940
  • tests/regression/Molecules/ForceAnnealing/post/test-undo.conf

    r8c6b68 r6145577  
    8282Ion_Type2_2     8.532785963     4.158586027     3.535886037     0       1.000000e-01    0.000000e+00    0.000000e+00     # molecule nr 9
    8383Ion_Type2_3     7.283585982     3.275186040     3.535886037     0       1.000000e-01    0.000000e+00    0.000000e+00     # molecule nr 10
     84
     85Ion_Type1_1     9.782085945     2.645886050     2.645886050     0 # molecule nr 0
     86Ion_Type1_2     9.782085945     2.645886050     4.425886024     0 # molecule nr 1
     87Ion_Type1_3     10.672039608    3.904536878     3.535886037     0 # molecule nr 2
     88Ion_Type1_4     8.532785963     4.787886018     2.645886050     0 # molecule nr 3
     89Ion_Type1_5     8.532785963     4.787886018     4.425886024     0 # molecule nr 4
     90Ion_Type1_6     6.393632318     3.904536877     3.535886037     0 # molecule nr 5
     91Ion_Type1_7     7.283585982     2.645886050     2.645886050     0 # molecule nr 6
     92Ion_Type1_8     7.283585982     2.645886050     4.425886024     0 # molecule nr 7
     93Ion_Type2_1     9.782085945     3.275186040     3.535886037     0 # molecule nr 8
     94Ion_Type2_2     8.532785963     4.158586027     3.535886037     0 # molecule nr 9
     95Ion_Type2_3     7.283585982     3.275186040     3.535886037     0 # molecule nr 10
  • tests/regression/Molecules/ForceAnnealing/testsuite-molecules-force-annealing.at

    r8c6b68 r6145577  
    3333AT_SETUP([Molecules - Force Annealing with Undo])
    3434AT_KEYWORDS([molecules force-annealing undo])
    35 AT_XFAIL_IF([/bin/true])
    3635
    3736file=test.conf
Note: See TracChangeset for help on using the changeset viewer.