Changeset 45f835 for src


Ignore:
Timestamp:
Oct 14, 2011, 12:10:02 PM (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:
9c27b0
Parents:
34fbb3
Message:

Added Undo/Redo capabilities to RepeatBoxAction.

  • adapted regression tests.
Location:
src/Actions/WorldAction
Files:
2 edited

Legend:

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

    r34fbb3 r45f835  
    3131
    3232#include <iostream>
     33#include <set>
    3334#include <string>
    3435#include <vector>
     
    4243#include "Action_impl_pre.hpp"
    4344/** =========== define the function ====================== */
    44 Action::state_ptr WorldRepeatBoxAction::performCall() {
     45
     46void repeatMoleculesinDomain(Vector Repeater, const std::vector<molecule *> &AllMolecules)
     47{
    4548  int count;
    4649  const element ** Elements;
    47   molecule *mol = NULL;
    4850  int j = 0;
    4951  atom *Walker = NULL;
    5052  MoleculeListClass *molecules = World::getInstance().getMolecules();
    5153
    52   // obtain information
    53   getParametersfromValueStorage();
    54 
    55   vector<molecule *> AllMolecules;
    56   if (mol != NULL) {
    57     DoLog(0) && (Log() << Verbose(0) << "Using molecule " << mol->name << "." << endl);
    58     AllMolecules = World::getInstance().getAllMolecules(MoleculeByPtr(mol));
    59   } else {
    60     DoLog(0) && (Log() << Verbose(0) << "Using all molecules." << endl);
    61     AllMolecules = World::getInstance().getAllMolecules();
    62   }
    63 
    64   (cout << "Repeating box " << params.Repeater << " times for (x,y,z) axis." << endl);
     54  LOG(0, "STATUS: Repeating box " << Repeater << " times for (x,y,z) axis.");
     55
     56  // set new domain
    6557  RealSpaceMatrix M = World::getInstance().getDomain().getM();
    6658  RealSpaceMatrix newM = M;
     
    6961  RealSpaceMatrix repMat;
    7062  for (int axis = 0; axis < NDIM; axis++) {
    71     params.Repeater[axis] = floor(params.Repeater[axis]);
    72     if (params.Repeater[axis] < 1) {
    73       DoeLog(1) && (eLog()<< Verbose(1) << "Repetition factor must be greater than 1!" << endl);
    74       params.Repeater[axis] = 1;
     63    Repeater[axis] = floor(Repeater[axis]);
     64    if (Repeater[axis] < 1) {
     65      ELOG(1, "Repetition factor must be greater than 1!");
     66      Repeater[axis] = 1;
    7567    }
    76     repMat.at(axis,axis) = params.Repeater[axis];
     68    repMat.at(axis,axis) = Repeater[axis];
    7769  }
    7870  newM *= repMat;
    7971  World::getInstance().setDomain(newM);
    8072
     73  // add molecules in each repeated domain part
    8174  molecule *newmol = NULL;
    8275  std::vector<Vector> vectors;
    83   for (n[0] = 0; n[0] < params.Repeater[0]; n[0]++) {
     76  for (n[0] = 0; n[0] < Repeater[0]; n[0]++) {
    8477    y[0] = n[0];
    85     for (n[1] = 0; n[1] < params.Repeater[1]; n[1]++) {
     78    for (n[1] = 0; n[1] < Repeater[1]; n[1]++) {
    8679      y[1] = n[1];
    87       for (n[2] = 0; n[2] < params.Repeater[2]; n[2]++) {
     80      for (n[2] = 0; n[2] < Repeater[2]; n[2]++) {
    8881        y[2] = n[2];
    8982        if ((n[0] == 0) && (n[1] == 0) && (n[2] == 0))
    9083          continue;
    91         for (vector<molecule *>::iterator MolRunner = AllMolecules.begin(); MolRunner != AllMolecules.end(); ++MolRunner) {
    92           mol = *MolRunner;
    93           DoLog(1) && (Log() << Verbose(1) << "Current mol is " << mol->name << "." << endl);
     84        for (vector<molecule *>::const_iterator MolRunner = AllMolecules.begin(); MolRunner != AllMolecules.end(); ++MolRunner) {
     85          const molecule *mol = *MolRunner;
     86          LOG(2, "INFO: Current mol is " << mol->name << ".");
    9487          count = mol->getAtomCount();   // is changed becausing of adding, thus has to be stored away beforehand
    9588          if (count != 0) {  // if there is more than none
     
    9790            vectors.resize(count);
    9891            j = 0;
    99             for(molecule::iterator AtomRunner = mol->begin(); AtomRunner != mol->end(); ++AtomRunner) {
     92            for(molecule::const_iterator AtomRunner = mol->begin(); AtomRunner != mol->end(); ++AtomRunner) {
    10093              Elements[j] = (*AtomRunner)->getType();
    10194              vectors[j] = (*AtomRunner)->getPosition();
     
    10396            }
    10497            if (count != j)
    105               DoeLog(1) && (eLog()<< Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl);
     98              ELOG(1, "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!");
    10699            x = y;
    107100            x *= M;
    108101            newmol = World::getInstance().createMolecule();
     102            // TODO: Remove this when World don't has deprecated MoleculeListClass anymore
    109103            molecules->insert(newmol);
    110104            for (int k=count;k--;) { // go through every atom of the original cell
     
    118112            delete[](Elements);
    119113          } else {
    120             DoLog(1) && (Log() << Verbose(1) << "\t ... is empty." << endl);
     114            LOG(1, "\t ... is empty.");
    121115          }
    122116        }
     
    124118    }
    125119  }
     120}
     121
     122Action::state_ptr WorldRepeatBoxAction::performCall() {
     123  molecule *mol = NULL;
     124
     125  // obtain information
     126  getParametersfromValueStorage();
     127
     128  std::vector<molecule *> AllMolecules;
     129  if (mol != NULL) {
     130    DoLog(0) && (Log() << Verbose(0) << "Using molecule " << mol->name << "." << endl);
     131    AllMolecules = World::getInstance().getAllMolecules(MoleculeByPtr(mol));
     132  } else {
     133    DoLog(0) && (Log() << Verbose(0) << "Using all molecules." << endl);
     134    AllMolecules = World::getInstance().getAllMolecules();
     135  }
     136
     137  // prepare undo state
     138  RealSpaceMatrix olddomain = World::getInstance().getDomain().getM();
     139  std::set<molecule *> oldmolecules;
     140  for(std::vector<molecule *>::const_iterator iter = AllMolecules.begin();
     141      iter != AllMolecules.end();
     142      ++iter)
     143    oldmolecules.insert(*iter);
     144  WorldRepeatBoxState *undostate = new WorldRepeatBoxState(olddomain, oldmolecules, params);
     145
     146  repeatMoleculesinDomain(params.Repeater, AllMolecules);
    126147
    127148  // give final box size
    128149  LOG(0, "Box domain is now " << World::getInstance().getDomain().getM());
    129150
    130   return Action::success;
     151  return Action::state_ptr(undostate);
    131152}
    132153
    133154Action::state_ptr WorldRepeatBoxAction::performUndo(Action::state_ptr _state) {
    134 //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
    135 
    136   return Action::failure;
    137 //  string newName = state->mol->getName();
    138 //  state->mol->setName(state->lastName);
    139 //
    140 //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
     155  WorldRepeatBoxState *state = assert_cast<WorldRepeatBoxState*>(_state.get());
     156  MoleculeListClass *molecules = World::getInstance().getMolecules();
     157
     158  // set old domain
     159  World::getInstance().setDomain(state->olddomain);
     160
     161  // remove all added molecules (and their atoms)
     162  std::vector<molecule *> allmolecules = World::getInstance().getAllMolecules();
     163  for (std::vector<molecule *>::iterator iter = allmolecules.begin();
     164      iter != allmolecules.end();
     165      ++iter) {
     166    if (state->oldmolecules.find(*iter) == state->oldmolecules.end()) {
     167      (*iter)->removeAtomsinMolecule();
     168      // TODO: Remove this when World don't has deprecated MoleculeListClass anymore
     169      molecules->erase(*iter);
     170      World::getInstance().destroyMolecule(*iter);
     171    }
     172  }
     173
     174  // give final box size
     175  LOG(0, "Box domain restored to " << World::getInstance().getDomain().getM());
     176
     177  return Action::state_ptr(_state);
    141178}
    142179
    143180Action::state_ptr WorldRepeatBoxAction::performRedo(Action::state_ptr _state){
    144   return Action::failure;
     181  WorldRepeatBoxState *state = assert_cast<WorldRepeatBoxState*>(_state.get());
     182
     183  std::vector<molecule *> originalmolecules;
     184  for(std::set<molecule *>::const_iterator iter = state->oldmolecules.begin();
     185      iter != state->oldmolecules.end();
     186      ++iter)
     187    originalmolecules.push_back(*iter);
     188  repeatMoleculesinDomain(state->params.Repeater, originalmolecules);
     189
     190  // give final box size
     191  LOG(0, "Box domain is again " << World::getInstance().getDomain().getM());
     192
     193  return Action::state_ptr(_state);
    145194}
    146195
    147196bool WorldRepeatBoxAction::canUndo() {
    148   return false;
     197  return true;
    149198}
    150199
    151200bool WorldRepeatBoxAction::shouldUndo() {
    152   return false;
     201  return true;
    153202}
    154203/** =========== end of function ====================== */
  • src/Actions/WorldAction/RepeatBoxAction.def

    r34fbb3 r45f835  
    88// all includes and forward declarations necessary for non-integral types below
    99#include "Actions/Values.hpp"
     10#include "LinearAlgebra/RealSpaceMatrix.hpp"
    1011#include "LinearAlgebra/Vector.hpp"
     12#include <set>
     13
     14class molecule;
    1115
    1216// i.e. there is an integer with variable name Z that can be found in
     
    1923#define paramreferences (Repeater)
    2024
    21 #undef statetypes
    22 #undef statereferences
     25#define statetypes (RealSpaceMatrix)(std::set< molecule *>)
     26#define statereferences (olddomain)(oldmolecules)
    2327
    2428// some defines for all the names, you may use ACTION, STATE and PARAMS
Note: See TracChangeset for help on using the changeset viewer.