Changeset de7d1d


Ignore:
Timestamp:
Oct 14, 2011, 10:44:10 AM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
7b4a29
Parents:
23526c
git-author:
Frederik Heber <heber@…> (09/14/11 15:58:15)
git-committer:
Frederik Heber <heber@…> (10/14/11 10:44:10)
Message:

Added Undo/Redo capabilities to CenterOnEdgeAction.

  • adapted regression test.
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/WorldAction/CenterOnEdgeAction.cpp

    r23526c rde7d1d  
    1818#endif
    1919
     20// include headers that implement a archive in simple text format
     21#include <boost/archive/text_oarchive.hpp>
     22#include <boost/archive/text_iarchive.hpp>
     23#include "boost/serialization/vector.hpp"
     24
    2025#include "CodePatterns/MemDebug.hpp"
    2126
    2227#include "atom.hpp"
    2328#include "CodePatterns/Log.hpp"
     29#include "LinearAlgebra/MatrixContent.hpp"
     30#include "LinearAlgebra/RealSpaceMatrix.hpp"
    2431#include "LinearAlgebra/Vector.hpp"
     32#include "molecule.hpp"
    2533#include "World.hpp"
    26 #include "LinearAlgebra/RealSpaceMatrix.hpp"
    2734
    2835#include <iostream>
    2936#include <string>
     37#include <vector>
    3038
    3139#include "Actions/WorldAction/CenterOnEdgeAction.hpp"
     
    4452  getParametersfromValueStorage();
    4553
     54  // create undo state
     55  std::stringstream undostream;
     56  boost::archive::text_oarchive oa(undostream);
     57  const RealSpaceMatrix &matrix = World::getInstance().getDomain().getM();
     58  oa << matrix;
     59  std::vector< boost::shared_ptr<Vector> > OldPositions;
     60  std::vector<atom *> AllAtoms = World::getInstance().getAllAtoms();
     61  for (std::vector<atom *>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner)
     62    OldPositions.push_back(
     63        boost::shared_ptr<Vector>(new Vector(
     64            (*AtomRunner)->getPosition()
     65            ))
     66        );
     67
    4668  // get maximum and minimum
    47   vector<atom *> AllAtoms = World::getInstance().getAllAtoms();
    4869  ASSERT(AllAtoms.size() > 0, "For CenteronEdge atoms must be present.");
    49   vector<atom *>::iterator AtomRunner = AllAtoms.begin();
     70  std::vector<atom *>::iterator AtomRunner = AllAtoms.begin();
    5071  Min = (*AtomRunner)->getPosition();
    5172  Max = (*AtomRunner)->getPosition();
     
    6788  World::getInstance().setDomain(domain);
    6889  // translate all atoms, such that Min is aty (0,0,0)
    69   for (vector<atom*>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner)
     90  for (std::vector<atom*>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner)
    7091    *(*AtomRunner) -= Min;
    7192
     
    7394  LOG(0, "Box domain is now " << World::getInstance().getDomain().getM());
    7495
    75   return Action::success;
     96  // create undo state
     97  WorldCenterOnEdgeState *UndoState =
     98      new WorldCenterOnEdgeState(
     99          undostream.str(),
     100          Min,
     101          Max,
     102          params
     103          );
     104
     105  return Action::state_ptr(UndoState);
    76106}
    77107
    78108Action::state_ptr WorldCenterOnEdgeAction::performUndo(Action::state_ptr _state) {
    79 //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
     109  WorldCenterOnEdgeState *state = assert_cast<WorldCenterOnEdgeState*>(_state.get());
    80110
    81   return Action::failure;
    82 //  string newName = state->mol->getName();
    83 //  state->mol->setName(state->lastName);
    84 //
    85 //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
     111  // restore domain
     112  RealSpaceMatrix matrix;
     113  std::stringstream undostream(state->undostring);
     114  boost::archive::text_iarchive ia(undostream);
     115  ia >> matrix;
     116  World::getInstance().setDomain(matrix);
     117
     118  // translate all atoms back
     119  std::vector<atom *> AllAtoms = World::getInstance().getAllAtoms();
     120  for (vector<atom*>::iterator AtomRunner = AllAtoms.begin();
     121      AtomRunner != AllAtoms.end();
     122      ++AtomRunner)
     123    *(*AtomRunner) += state->Min;
     124
     125  // give final box size
     126  LOG(0, "Box domain restored to " << World::getInstance().getDomain().getM());
     127
     128  return Action::state_ptr(_state);
    86129}
    87130
    88131Action::state_ptr WorldCenterOnEdgeAction::performRedo(Action::state_ptr _state){
    89   return Action::failure;
     132  WorldCenterOnEdgeState *state = assert_cast<WorldCenterOnEdgeState*>(_state.get());
     133
     134  // set new box size
     135  RealSpaceMatrix rmatrix;
     136  for (int i=0;i<NDIM;i++) {
     137    double tmp = state->Max[i]-state->Min[i];
     138    tmp = fabs(tmp)>=1. ? tmp : 1.0;
     139    rmatrix.at(i,i) = tmp;
     140  }
     141  World::getInstance().setDomain(rmatrix);
     142  // translate all atoms, such that Min is aty (0,0,0)
     143  std::vector<atom *> AllAtoms = World::getInstance().getAllAtoms();
     144  for (vector<atom*>::iterator AtomRunner = AllAtoms.begin();
     145      AtomRunner != AllAtoms.end();
     146      ++AtomRunner)
     147    *(*AtomRunner) -= state->Min;
     148
     149  // give final box size
     150  LOG(0, "Box domain is again " << World::getInstance().getDomain().getM());
     151
     152  return Action::state_ptr(_state);
    90153}
    91154
    92155bool WorldCenterOnEdgeAction::canUndo() {
    93   return false;
     156  return true;
    94157}
    95158
    96159bool WorldCenterOnEdgeAction::shouldUndo() {
    97   return false;
     160  return true;
    98161}
    99162/** =========== end of function ====================== */
  • src/Actions/WorldAction/CenterOnEdgeAction.def

    r23526c rde7d1d  
    77
    88// all includes and forward declarations necessary for non-integral types below
    9 
     9#include "LinearAlgebra/Vector.hpp"
    1010
    1111// i.e. there is an integer with variable name Z that can be found in
     
    1818#undef paramreferences
    1919
    20 #undef statetypes
    21 #undef statereferences
     20#define statetypes (std::string)(Vector)(Vector)
     21#define statereferences (undostring)(Min)(Max)
    2222
    2323// some defines for all the names, you may use ACTION, STATE and PARAMS
  • tests/regression/Domain/CenterOnEdge/testsuite-domain-center-on-edge.at

    r23526c rde7d1d  
    77AT_CHECK([/bin/cp -f ${abs_top_srcdir}/tests/regression/Domain/CenterOnEdge/pre/test.conf $file], 0)
    88AT_CHECK([chmod u+w $file], 0)
    9 AT_CHECK([../../molecuilder -i $file  -O], 0, [stdout], [stderr])
     9AT_CHECK([../../molecuilder -i $file -O], 0, [stdout], [stderr])
    1010AT_CHECK([fgrep "Box domain is now" stdout], 0, [ignore], [ignore])
    1111AT_CHECK([diff $file ${abs_top_srcdir}/tests/regression/Domain/CenterOnEdge/post/test.conf], 0, [stdout], [stderr])
     
    1515
    1616AT_SETUP([Domain - set domain to minimum size with Undo])
    17 AT_XFAIL_IF([/bin/true])
    1817AT_KEYWORDS([domain center-edge undo])
    1918
     
    2120AT_CHECK([/bin/cp -f ${abs_top_srcdir}/tests/regression/Domain/CenterOnEdge/pre/test.conf $file], 0)
    2221AT_CHECK([chmod u+w $file], 0)
    23 AT_CHECK([../../molecuilder -i $file  -O --undo], 0, [stdout], [stderr])
     22AT_CHECK([../../molecuilder -i $file -O --undo], 0, [stdout], [stderr])
    2423AT_CHECK([fgrep "Box domain is now" stdout], 0, [ignore], [ignore])
    25 AT_CHECK([diff $file ${abs_top_srcdir}/tests/regression/Domain/CenterOnEdge/post/test.conf], 0, [stdout], [stderr])
     24AT_CHECK([diff $file ${abs_top_srcdir}/tests/regression/Domain/CenterOnEdge/post/test-undo.conf], 0, [stdout], [stderr])
    2625
    2726AT_CLEANUP
     
    2928
    3029AT_SETUP([Domain - set domain to minimum size with Redo])
    31 AT_XFAIL_IF([/bin/true])
    3230AT_KEYWORDS([domain center-edge redo])
    3331
     
    3533AT_CHECK([/bin/cp -f ${abs_top_srcdir}/tests/regression/Domain/CenterOnEdge/pre/test.conf $file], 0)
    3634AT_CHECK([chmod u+w $file], 0)
    37 AT_CHECK([../../molecuilder -i $file  -O --undo --redo], 0, [stdout], [stderr])
     35AT_CHECK([../../molecuilder -i $file -O --undo --redo], 0, [stdout], [stderr])
    3836AT_CHECK([fgrep "Box domain is now" stdout], 0, [ignore], [ignore])
    3937AT_CHECK([diff $file ${abs_top_srcdir}/tests/regression/Domain/CenterOnEdge/post/test.conf], 0, [stdout], [stderr])
Note: See TracChangeset for help on using the changeset viewer.