Changeset fc3aff for src/Actions


Ignore:
Timestamp:
Aug 20, 2014, 1:10:07 PM (11 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, Candidate_v1.7.0, Candidate_v1.7.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:
4c9101
Parents:
ee4f2d (diff), 3a33e3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'StructuralOptimization' into stable

Location:
src/Actions
Files:
6 added
9 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/ActionRegistry.cpp

    ree4f2d rfc3aff  
    7373  clearOptionRegistry();
    7474
    75   // second clear each macro action that require presence of all primitive ones
     75  // add all MakroActions: PLEASE adhere to the alphabetical ordering
     76  {
     77    MakroAction * presentAction =
     78        dynamic_cast<MakroAction *>(getActionByName("molecular-dynamics"));
     79    ASSERT( presentAction != NULL,
     80        "ActionRegistry::fillRegistry() - makro action has not been registered.");
     81    presentAction->unprepare(*this);
     82  }
     83  {
     84    MakroAction * presentAction =
     85        dynamic_cast<MakroAction *>(getActionByName("optimize-structure"));
     86    ASSERT( presentAction != NULL,
     87        "ActionRegistry::fillRegistry() - makro action has not been registered.");
     88    presentAction->unprepare(*this);
     89  }
    7690  {
    7791    MakroAction * presentAction =
     
    8195    presentAction->unprepare(*this);
    8296  }
    83 #ifdef HAVE_JOBMARKET
    84   {
    85     MakroAction * presentAction =
    86         dynamic_cast<MakroAction *>(getActionByName("molecular-dynamics"));
    87     ASSERT( presentAction != NULL,
    88         "ActionRegistry::fillRegistry() - makro action has not been registered.");
    89     presentAction->unprepare(*this);
    90   }
    91 #endif
    9297
    9398  //std::cout << "ActionRegistry::~ActionRegistry() called, instance is " << this << "." << std::endl;
     
    121126    presentAction->prepare(*this);
    122127  }
    123 #ifdef HAVE_JOBMARKET
    124128  {
    125129    MakroAction * presentAction =
     
    129133    presentAction->prepare(*this);
    130134  }
    131 #endif
     135  {
     136    MakroAction * presentAction =
     137        dynamic_cast<MakroAction *>(getActionByName("optimize-structure"));
     138    ASSERT( presentAction != NULL,
     139        "ActionRegistry::fillRegistry() - makro action has not been registered.");
     140    presentAction->prepare(*this);
     141  }
    132142}
    133143
  • src/Actions/AtomAction/RemoveAction.def

    ree4f2d rfc3aff  
    77
    88// all includes and forward declarations necessary for non-integral types below
    9 
    10 
    11 #include "Parameters/Validators/DummyValidator.hpp"
    129
    1310// i.e. there is an integer with variable name Z that can be found in
  • src/Actions/FragmentationAction/FragmentationAutomationAction.cpp

    ree4f2d rfc3aff  
    108108}
    109109
    110 #ifdef HAVE_JOBMARKET
    111110static void updateSteps(Process &p, const size_t step, const size_t total)
    112111{
     
    114113  p.setCurrStep(step);
    115114}
    116 #endif
    117115
    118116ActionState::ptr FragmentationFragmentationAutomationAction::performCall() {
     
    178176        );
    179177    LOG(1, "INFO: Added " << NoJobs << " from FragmentJobsQueue.");
     178
     179    // prepare process
     180    setMaxSteps(NumberJobs);
     181    mpqccontroller.setUpdateHandler(
     182        boost::bind(&updateSteps, boost::ref(*this), _1, _2)
     183        );
     184    start();
    180185    mpqccontroller.run();
     186    stop();
    181187
    182188    // get back the results and place them in shortrangedata
  • src/Actions/GlobalListOfActions.hpp

    ree4f2d rfc3aff  
    1818
    1919// this is global list of actions valid for all cases
     20// PLEASE adhere to the alphabetical ordering of the list of Actions
     21// NOTE that Redo must remain at the front due to technical reasons
    2022#define GLOBALLISTOFACTIONS_initial \
    2123  (Redo) \
    22   (GraphUpdateMolecules) \
    23   (GraphCorrectBondDegree) \
    24   (GraphCreateAdjacency) \
    25   (GraphDepthFirstSearch) \
    26   (GraphDestroyAdjacency) \
    27   (GraphSubgraphDissection) \
    28   (MoleculeSaveTemperature) \
    29   (MoleculeCopy) \
    30   (MoleculeSuspendInWater) \
    31   (MoleculeFillWithMolecule) \
    32   (MoleculeRotateToPrincipalAxisSystem) \
    33   (MoleculeSaveAdjacency) \
    34   (MoleculeFillVoidWithMolecule) \
    35   (MoleculeVerletIntegration) \
    36   (MoleculeChangeName) \
    37   (MoleculeChangeBondAngle) \
    38   (MoleculeRotateAroundSelfByAngle) \
    39   (MoleculeSaveSelectedMolecules) \
    40   (MoleculeSaveBonds) \
    41   (MoleculeStretchBond) \
    42   (MoleculeLinearInterpolationofTrajectories) \
    43   (MoleculeLoad) \
    44   (MoleculeBondFile) \
    45   (TesselationNonConvexEnvelope) \
    46   (TesselationConvexEnvelope) \
     24  (AnalysisDipoleAngularCorrelation) \
     25  (AnalysisDipoleCorrelation) \
     26  (AnalysisMolecularVolume) \
     27  (AnalysisPairCorrelation) \
     28  (AnalysisPointCorrelation) \
     29  (AnalysisPrincipalAxisSystem) \
     30  (AnalysisSurfaceCorrelation) \
     31  (AtomAdd) \
     32  (AtomChangeElement) \
     33  (AtomRemove) \
     34  (AtomRotateAroundOriginByAngle) \
     35  (AtomSaveSelectedAtoms) \
     36  (AtomTranslate) \
     37  (BondAdd) \
     38  (BondRemove) \
    4739  (CommandElementDb) \
    4840  (CommandBondLengthTable) \
     
    5648  (CommandVersion) \
    5749  (CommandWarranty) \
    58   (ParserSetTremoloAtomdata) \
     50  (FillRegularGrid) \
     51  (FillSurface) \
     52  (FragmentationAnalyseFragmentationResults) \
     53  (FragmentationClearFragmentationResults) \
     54  (FragmentationFragmentation) \
     55  (FragmentationFragmentationAutomation) \
     56  (FragmentationMolecularDynamics) \
     57  (FragmentationParseFragmentJobs) \
     58  (FragmentationStoreSaturatedFragment) \
     59  (FragmentationStructuralOptimization) \
     60  (GraphUpdateMolecules) \
     61  (GraphCorrectBondDegree) \
     62  (GraphCreateAdjacency) \
     63  (GraphDepthFirstSearch) \
     64  (GraphDestroyAdjacency) \
     65  (GraphSubgraphDissection) \
     66  (MoleculeBondFile) \
     67  (MoleculeChangeName) \
     68  (MoleculeChangeBondAngle) \
     69  (MoleculeCopy) \
     70  (MoleculeFillWithMolecule) \
     71  (MoleculeFillVoidWithMolecule) \
     72  (MoleculeForceAnnealing) \
     73  (MoleculeLinearInterpolationofTrajectories) \
     74  (MoleculeLoad) \
     75  (MoleculeRotateAroundSelfByAngle) \
     76  (MoleculeRotateToPrincipalAxisSystem) \
     77  (MoleculeSaveAdjacency) \
     78  (MoleculeSaveBonds) \
     79  (MoleculeSaveSelectedMolecules) \
     80  (MoleculeSaveTemperature) \
     81  (MoleculeStretchBond) \
     82  (MoleculeSuspendInWater) \
     83  (MoleculeVerletIntegration) \
     84  (PotentialFitParticleCharges) \
     85  (PotentialParseHomologies) \
     86  (PotentialSaveHomologies) \
    5987  (ParserParseTremoloPotentials) \
    6088  (ParserSaveSelectedAtomsAsExtTypes) \
    6189  (ParserSetParserParameters) \
    6290  (ParserSetOutputFormats) \
    63   (AnalysisDipoleAngularCorrelation) \
    64   (AnalysisDipoleCorrelation) \
    65   (AnalysisPairCorrelation) \
    66   (AnalysisPointCorrelation) \
    67   (AnalysisSurfaceCorrelation) \
    68   (AnalysisMolecularVolume) \
    69   (AnalysisPrincipalAxisSystem) \
     91  (ParserSetTremoloAtomdata) \
    7092  (Undo) \
    71   (AtomSaveSelectedAtoms) \
    72   (AtomRotateAroundOriginByAngle) \
    73   (AtomChangeElement) \
    74   (AtomRemove) \
    75   (AtomTranslate) \
    76   (AtomAdd) \
    77   (BondAdd) \
    78   (BondRemove) \
    79   (WorldCenterInBox) \
    80   (WorldRepeatBox) \
    81   (WorldChangeBox) \
    82   (WorldCenterOnEdge) \
    83   (WorldSetWorldTime) \
    84   (WorldSetBoundaryConditions) \
    85   (WorldOutput) \
    86   (WorldOutputAs) \
    87   (WorldSetDefaultName) \
    88   (WorldScaleBox) \
    89   (WorldAddEmptyBoundary) \
    90   (WorldBoundInBox) \
    91   (WorldInput) \
    92   (SelectionNotMoleculeOfAtom) \
    93   (SelectionNotAllMolecules) \
    94   (SelectionNotMoleculeById) \
    95   (SelectionMoleculeByOrder) \
    96   (SelectionMoleculeOfAtom) \
    97   (SelectionNotMoleculeByOrder) \
    98   (SelectionMoleculeByName) \
    99   (SelectionMoleculeById) \
    100   (SelectionAllMolecules) \
    101   (SelectionClearAllMolecules) \
    102   (SelectionInvertMolecules) \
    103   (SelectionMoleculeByFormula) \
    104   (SelectionNotMoleculeByFormula) \
    105   (SelectionNotMoleculeByName) \
    106   (SelectionNotAtomById) \
    107   (SelectionNotAtomByOrder) \
    10893  (SelectionAllAtoms) \
    109   (SelectionClearAllAtoms) \
    110   (SelectionInvertAtoms) \
    111   (SelectionNotAllAtoms) \
    112   (SelectionNotAtomByElement) \
    11394  (SelectionAllAtomsInsideVolume) \
    11495  (SelectionAllAtomsOfMolecule) \
    115   (SelectionNotAllAtomsInsideVolume) \
     96  (SelectionAllMolecules) \
     97  (SelectionAllShapes) \
    11698  (SelectionAtomByElement) \
    117   (SelectionNotAllAtomsOfMolecule) \
    11899  (SelectionAtomById) \
    119100  (SelectionAtomByOrder) \
    120   (SelectionAllShapes) \
     101  (SelectionClearAllAtoms) \
     102  (SelectionClearAllMolecules) \
     103  (SelectionInvertAtoms) \
     104  (SelectionInvertMolecules) \
     105  (SelectionMoleculeOfAtom) \
     106  (SelectionMoleculeByFormula) \
     107  (SelectionMoleculeById) \
     108  (SelectionMoleculeByName) \
     109  (SelectionMoleculeByOrder) \
     110  (SelectionNotAllAtoms) \
     111  (SelectionNotAllAtomsInsideVolume) \
     112  (SelectionNotAllAtomsOfMolecule) \
     113  (SelectionNotAllMolecules) \
     114  (SelectionNotAllShapes) \
     115  (SelectionNotAtomById) \
     116  (SelectionNotAtomByElement) \
     117  (SelectionNotAtomByOrder) \
     118  (SelectionNotMoleculeOfAtom) \
     119  (SelectionNotMoleculeByFormula) \
     120  (SelectionNotMoleculeById) \
     121  (SelectionNotMoleculeByName) \
     122  (SelectionNotMoleculeByOrder) \
     123  (SelectionNotShapeByName) \
    121124  (SelectionShapeByName) \
    122   (SelectionNotAllShapes) \
    123   (SelectionNotShapeByName) \
    124   (FragmentationAnalyseFragmentationResults) \
    125   (FragmentationFragmentationAutomation) \
    126   (FragmentationClearFragmentationResults) \
    127   (FragmentationFragmentation) \
    128   (FragmentationMolecularDynamics) \
    129   (FragmentationParseFragmentJobs) \
    130   (FragmentationStoreSaturatedFragment) \
    131   (PotentialFitParticleCharges) \
    132   (PotentialParseHomologies) \
    133   (PotentialSaveHomologies) \
    134   (FillRegularGrid) \
    135   (FillSurface) \
    136125  (ShapeCombineShapes) \
    137126  (ShapeCreateShape) \
     
    139128  (ShapeRotateShape) \
    140129  (ShapeStretchShape) \
    141   (ShapeTranslateShape)
     130  (ShapeTranslateShape) \
     131  (TesselationConvexEnvelope) \
     132  (TesselationNonConvexEnvelope) \
     133  (WorldAddEmptyBoundary) \
     134  (WorldBoundInBox) \
     135  (WorldCenterInBox) \
     136  (WorldCenterOnEdge) \
     137  (WorldChangeBox) \
     138  (WorldInput) \
     139  (WorldOutput) \
     140  (WorldOutputAs) \
     141  (WorldRepeatBox) \
     142  (WorldScaleBox) \
     143  (WorldSetBoundaryConditions) \
     144  (WorldSetDefaultName) \
     145  (WorldSetWorldTime)
    142146
    143147// extend list of actions in case levmar is available
  • src/Actions/Makefile.am

    ree4f2d rfc3aff  
    231231  Actions/FragmentationAction/MolecularDynamicsAction.cpp \
    232232  Actions/FragmentationAction/ParseFragmentJobsAction.cpp \
    233   Actions/FragmentationAction/StoreSaturatedFragmentAction.cpp
     233  Actions/FragmentationAction/StoreSaturatedFragmentAction.cpp \
     234  Actions/FragmentationAction/StructuralOptimizationAction.cpp
    234235FRAGMENTATIONACTIONHEADER = \
    235236  Actions/FragmentationAction/AnalyseFragmentationResultsAction.hpp \
     
    239240  Actions/FragmentationAction/MolecularDynamicsAction.hpp \
    240241  Actions/FragmentationAction/ParseFragmentJobsAction.hpp \
    241   Actions/FragmentationAction/StoreSaturatedFragmentAction.hpp
     242  Actions/FragmentationAction/StoreSaturatedFragmentAction.hpp \
     243  Actions/FragmentationAction/StructuralOptimizationAction.hpp
    242244FRAGMENTATIONACTIONDEFS = \
    243245  Actions/FragmentationAction/AnalyseFragmentationResultsAction.def \
     
    247249  Actions/FragmentationAction/MolecularDynamicsAction.def \
    248250  Actions/FragmentationAction/ParseFragmentJobsAction.def \
    249   Actions/FragmentationAction/StoreSaturatedFragmentAction.def
     251  Actions/FragmentationAction/StoreSaturatedFragmentAction.def \
     252  Actions/FragmentationAction/StructuralOptimizationAction.def
    250253
    251254GRAPHACTIONSOURCE = \
     
    278281  Actions/MoleculeAction/FillWithMoleculeAction.cpp \
    279282  Actions/MoleculeAction/FillVoidWithMoleculeAction.cpp \
     283  Actions/MoleculeAction/ForceAnnealingAction.cpp \
    280284  Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.cpp \
    281285  Actions/MoleculeAction/LoadAction.cpp \
     
    296300  Actions/MoleculeAction/FillWithMoleculeAction.hpp \
    297301  Actions/MoleculeAction/FillVoidWithMoleculeAction.hpp \
     302  Actions/MoleculeAction/ForceAnnealingAction.hpp \
    298303  Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.hpp \
    299304  Actions/MoleculeAction/LoadAction.hpp \
     
    314319  Actions/MoleculeAction/FillWithMoleculeAction.def \
    315320  Actions/MoleculeAction/FillVoidWithMoleculeAction.def \
     321  Actions/MoleculeAction/ForceAnnealingAction.def \
    316322  Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.def \
    317323  Actions/MoleculeAction/LoadAction.def \
  • src/Actions/MoleculeAction/VerletIntegrationAction.cpp

    ree4f2d rfc3aff  
    33 * Description: creates and alters molecular systems
    44 * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
     5 * Copyright (C)  2013-2014 Frederik Heber. All rights reserved.
    56 *
    67 *
     
    3536#include "CodePatterns/MemDebug.hpp"
    3637
     38#include "Actions/UndoRedoHelpers.hpp"
    3739#include "Atom/atom.hpp"
     40#include "Atom/AtomicInfo.hpp"
    3841#include "Atom/AtomSet.hpp"
    3942#include "CodePatterns/Log.hpp"
     
    5356using namespace MoleCuilder;
    5457
     58enum {
     59  PositionIndex=0,
     60  VelocityIndex=1,
     61  ForceIndex=2,
     62  MAXINDEX
     63} VectorIndexType;
     64
    5565// and construct the stuff
    5666#include "VerletIntegrationAction.def"
     
    5868/** =========== define the function ====================== */
    5969ActionState::ptr MoleculeVerletIntegrationAction::performCall() {
    60   // TODO: sollte besser stream nutzen, nicht filename direkt (es sei denn, ist prefix), besser fuer unit test
    6170  AtomSetMixin<std::vector<atom *> > set(World::getInstance().getSelectedAtoms());
     71  if (set.empty()) {
     72    LOG(0, "STATUS: No atoms selected.");
     73    return Action::failure;
     74  }
    6275  // we always operate relative to current time step
    63   size_t CurrentStep = WorldTime::getInstance().getTime();
     76  const size_t CurrentStep = WorldTime::getInstance().getTime();
    6477  VerletForceIntegration<std::vector<atom *> > Verlet(set, params.Deltat.get(), true);
    6578  // parse forces into next step
     
    7184      LOG(2, "File " << params.forcesfile.get() << " found and parsed.");
    7285  }
     86
     87  // create undo state for all selected atoms (undo info)
     88  std::vector<AtomicInfo> UndoInfo;
     89  UndoInfo.reserve(set.size());
     90  {
     91    for (World::AtomSelectionConstIterator iter = World::getInstance().beginAtomSelection();
     92        iter != World::getInstance().endAtomSelection();
     93        ++iter)
     94      UndoInfo.push_back(AtomicInfo(*(iter->second)));
     95  }
     96
    7397  // perform velocity verlet update
    74   LOG(1, "Verlet integrating.");
    75   if (!Verlet(CurrentStep+1, 1, 0, params.FixedCenterOfMass.get()))
    76     ELOG(1, "Velocity verlet failed.");
    77   else
    78     LOG(2, "DEBUG: Successfully performed updates on velocity and position.");
    79   // increment to next time step
     98  Verlet(CurrentStep+1, 1, 0, params.FixedCenterOfMass.get());
     99  LOG(0, "STATUS: Successfully performed updates on velocity and position.");
     100  // increment to next time step: re-creates bond graph
    80101  World::getInstance().setTime(CurrentStep+1);
    81102
    82   return Action::success;
     103  // create undo state for all selected atoms (redo info):
     104  // we need:
     105  // -# forces from last step (possible parsing forces file, already in UndoInfo)
     106  // -# velocities from last step (..UpdateU(), already in UndoInfo)
     107  // -# current position (..UpdateX())
     108  std::vector<Vectors_t> UpdatedStep(MAXINDEX);
     109  UpdatedStep[PositionIndex].reserve(set.size());
     110  UpdatedStep[VelocityIndex].reserve(set.size());
     111  UpdatedStep[ForceIndex].reserve(set.size());
     112  {
     113    for (World::AtomSelectionConstIterator iter = World::getInstance().beginAtomSelection();
     114        iter != World::getInstance().endAtomSelection();
     115        ++iter) {
     116      UpdatedStep[PositionIndex].push_back(iter->second->getPositionAtStep(CurrentStep+1));
     117      UpdatedStep[VelocityIndex].push_back(iter->second->getAtomicVelocityAtStep(CurrentStep));
     118      UpdatedStep[ForceIndex].push_back(iter->second->getAtomicForceAtStep(CurrentStep));
     119    }
     120  }
     121  MoleculeVerletIntegrationState *UndoState =
     122      new MoleculeVerletIntegrationState(UndoInfo, UpdatedStep, params);
     123
     124  return ActionState::ptr(UndoState);
    83125}
    84126
    85127ActionState::ptr MoleculeVerletIntegrationAction::performUndo(ActionState::ptr _state) {
    86 //  MoleculeVerletIntegrationState *state = assert_cast<MoleculeVerletIntegrationState*>(_state.get());
     128  MoleculeVerletIntegrationState *state =
     129      assert_cast<MoleculeVerletIntegrationState*>(_state.get());
    87130
    88 //  string newName = state->mol->getName();
    89 //  state->mol->setName(state->lastName);
     131  // go back one step
     132  const size_t CurrentStep = WorldTime::getInstance().getTime();
     133  World::getInstance().setTime(CurrentStep-1);
    90134
    91   STATUS("Undo of MoleculeVerletIntegrationAction not implemented.");
    92   return Action::failure;
     135  // remove current step for all modified atoms
     136  removeLastStep(getIdsFromAtomicInfo(state->UndoInfo));
     137
     138  // and set back the old step (forces have been changed)
     139  SetAtomsFromAtomicInfo(state->UndoInfo);
     140
     141  return ActionState::ptr(_state);
    93142}
    94143
    95144ActionState::ptr MoleculeVerletIntegrationAction::performRedo(ActionState::ptr _state){
    96   STATUS("Rddo of MoleculeVerletIntegrationAction not implemented.");
    97   return Action::failure;
     145  MoleculeVerletIntegrationState *state =
     146      assert_cast<MoleculeVerletIntegrationState*>(_state.get());
     147
     148  // set forces and velocities
     149  ResetAtomVelocity(state->UndoInfo, state->UpdatedStep[VelocityIndex]);
     150  ResetAtomForce(state->UndoInfo, state->UpdatedStep[ForceIndex]);
     151
     152  // set stored new state
     153  addNewStep(state->UndoInfo);
     154
     155  // add a new time step
     156  size_t CurrentStep = WorldTime::getInstance().getTime();
     157  World::getInstance().setTime(CurrentStep+1);
     158
     159  // and set positions of the new step
     160  ResetAtomPosition(state->UndoInfo, state->UpdatedStep[PositionIndex]);
     161
     162  return ActionState::ptr(_state);
    98163}
    99164
  • src/Actions/MoleculeAction/VerletIntegrationAction.def

    ree4f2d rfc3aff  
    77
    88// all includes and forward declarations necessary for non-integral types below
    9 class MoleculeListClass;
     9#include "LinearAlgebra/Vector.hpp"
     10#include <vector>
     11typedef std::vector<Vector> Vectors_t;
    1012
    1113#include "Parameters/Validators/DummyValidator.hpp"
     
    2729(DummyValidator< bool >())
    2830
    29 #undef statetypes
    30 #undef statereferences
     31#define statetypes (std::vector<AtomicInfo>)(std::vector<Vectors_t>)
     32#define statereferences (UndoInfo)(UpdatedStep)
    3133
    3234// some defines for all the names, you may use ACTION, STATE and PARAMS
  • src/Actions/UndoRedoHelpers.cpp

    ree4f2d rfc3aff  
    33 * Description: creates and alters molecular systems
    44 * Copyright (C)  2012 University of Bonn. All rights reserved.
     5 * Copyright (C)  2013-2014 Frederik Heber. All rights reserved.
    56 *
    67 *
     
    3839#include "UndoRedoHelpers.hpp"
    3940
     41#include <boost/bind.hpp>
    4042#include <boost/foreach.hpp>
     43#include <boost/function.hpp>
    4144
    4245#include "Atom/atom.hpp"
     
    4750#include "CodePatterns/Log.hpp"
    4851#include "World.hpp"
     52#include "WorldTime.hpp"
    4953
    5054bool MoleCuilder::AddAtomsFromAtomicInfo(std::vector<AtomicInfo> &atoms)
     
    103107}
    104108
    105 void MoleCuilder::SetAtomsFromAtomicInfo(std::vector<AtomicInfo> &movedatoms)
    106 {
    107   BOOST_FOREACH( const AtomicInfo &_atominfo, movedatoms) {
     109void MoleCuilder::SetAtomsFromAtomicInfo(const std::vector<AtomicInfo> &_movedatoms)
     110{
     111  BOOST_FOREACH( const AtomicInfo &_atominfo, _movedatoms) {
    108112    const atomId_t id = _atominfo.getId();
    109113    atom * const _atom = World::getInstance().getAtom(AtomById(id));
     
    115119}
    116120
    117 void MoleCuilder::SelectAtomsFromAtomicInfo(std::vector<AtomicInfo> &movedatoms)
    118 {
    119   BOOST_FOREACH( const AtomicInfo &_atominfo, movedatoms) {
     121void MoleCuilder::SelectAtomsFromAtomicInfo(const std::vector<AtomicInfo> &_movedatoms)
     122{
     123  BOOST_FOREACH( const AtomicInfo &_atominfo, _movedatoms) {
    120124    const atomId_t id = _atominfo.getId();
    121125    World::getInstance().selectAtom(id);
     
    124128
    125129void MoleCuilder::ResetAtomPosition(const std::vector<AtomicInfo> &movedatoms, const std::vector<Vector> &MovedToVector)
     130{
     131  boost::function<void(atom *, const Vector&)> setter =
     132      boost::bind(&atom::setPosition, _1, _2);
     133  ResetByFunction(movedatoms, MovedToVector, setter);
     134}
     135
     136void MoleCuilder::ResetAtomVelocity(const std::vector<AtomicInfo> &movedatoms, const std::vector<Vector> &VelocityVector)
     137{
     138  boost::function<void(atom *, const Vector&)> setter =
     139      boost::bind(&atom::setAtomicVelocity, _1, _2);
     140  ResetByFunction(movedatoms, VelocityVector, setter);
     141}
     142
     143void MoleCuilder::ResetAtomForce(const std::vector<AtomicInfo> &movedatoms, const std::vector<Vector> &ForceVector)
     144{
     145  boost::function<void(atom *, const Vector&)> setter =
     146      boost::bind(&atom::setAtomicForce, _1, _2);
     147  ResetByFunction(movedatoms, ForceVector, setter);
     148}
     149
     150void MoleCuilder::ResetByFunction(
     151    const std::vector<AtomicInfo> &movedatoms,
     152    const std::vector<Vector> &MovedToVector,
     153    boost::function<void(atom *, const Vector&)> &setter)
    126154{
    127155  std::vector<Vector>::const_iterator positer = MovedToVector.begin();
     
    136164        "FillSphericalSurfaceAction::performRedo() - cannot find atom with id "
    137165        +toString(id)+" in the world.");
    138     _atom->setPosition( *positer );
     166    setter(_atom, *positer );
    139167    ++positer;
    140168  }
     
    152180  }
    153181}
     182
     183void MoleCuilder::removeLastStep(const std::vector<atomId_t> &_atoms)
     184{
     185  for (size_t i=0; i<_atoms.size(); ++i) {
     186    atom * const _atom = World::getInstance().getAtom(AtomById(_atoms[i]));
     187    _atom->removeSteps();
     188  }
     189}
     190
     191void MoleCuilder::addNewStep(const std::vector<AtomicInfo> &_movedatoms)
     192{
     193  for(size_t i=0; i< _movedatoms.size(); ++i) {
     194    atom * const _atom = World::getInstance().getAtom(AtomById(_movedatoms[i].getId()));
     195    _atom->UpdateSteps();
     196  }
     197}
     198
     199void MoleCuilder::addNewStep(const std::vector<atomId_t> &_ids)
     200{
     201  for(size_t i=0; i< _ids.size(); ++i) {
     202    atom * const _atom = World::getInstance().getAtom(AtomById(_ids[i]));
     203    _atom->UpdateSteps();
     204  }
     205}
     206
     207std::vector<atomId_t> MoleCuilder::getIdsFromAtomicInfo(const std::vector<AtomicInfo> &movedatoms)
     208{
     209  std::vector<atomId_t> ids(movedatoms.size(), (size_t)-1);
     210  std::transform(
     211      movedatoms.begin(), movedatoms.end(),
     212      ids.begin(),
     213      boost::bind(&AtomicInfo::getId, _1));
     214  return ids;
     215}
  • src/Actions/UndoRedoHelpers.hpp

    ree4f2d rfc3aff  
    5555   * @param movedatoms vector of atomicInfo
    5656   */
    57   void SetAtomsFromAtomicInfo(std::vector<AtomicInfo> &movedatoms);
     57  void SetAtomsFromAtomicInfo(const std::vector<AtomicInfo> &_movedatoms);
    5858
    5959  /** Selects all atoms inside the given vector
     
    6161   * @param movedatoms vector of atomicInfo
    6262   */
    63   void SelectAtomsFromAtomicInfo(std::vector<AtomicInfo> &movedatoms);
     63  void SelectAtomsFromAtomicInfo(const std::vector<AtomicInfo> &_movedatoms);
     64
     65  /** Helper function to allow setting arbitrary atom vectorial information via some
     66   * \a setter function.
     67   *
     68   * @param movedatoms atoms whose info to change
     69   * @param MovedToVector vector with old vectorial information
     70   */
     71  void ResetByFunction(
     72      const std::vector<AtomicInfo> &movedatoms,
     73      const std::vector<Vector> &MovedToVector,
     74      boost::function<void(atom *, const Vector&)> &setter);
    6475
    6576  /** Sets the atoms whose id is stored in given AtomicInfo in \a movedatoms
     
    7182  void ResetAtomPosition(const std::vector<AtomicInfo> &movedatoms, const std::vector<Vector> &MovedToVector);
    7283
     84  /** Sets the atoms whose id is stored in given AtomicInfo in \a movedatoms
     85   *  to position in \a MovedToVector.
     86   *
     87   * @param movedatoms atoms whose position to change
     88   * @param VelocityVector vector with old velocities
     89   */
     90  void ResetAtomVelocity(const std::vector<AtomicInfo> &movedatoms, const std::vector<Vector> &VelocityVector);
     91
     92  /** Sets the atoms whose id is stored in given AtomicInfo in \a movedatoms
     93   *  to position in \a MovedToVector.
     94   *
     95   * @param movedatoms atoms whose position to change
     96   * @param ForceVector vector with old forces
     97   */
     98  void ResetAtomForce(const std::vector<AtomicInfo> &movedatoms, const std::vector<Vector> &ForceVector);
     99
    73100  /** Remove all molecules identified by their ids given in \a ids.
    74101   *
     
    76103   */
    77104  void RemoveMoleculesWithAtomsByIds(const std::vector<moleculeId_t> &ids);
     105
     106  /** Removes the last time step for all \a movedatoms
     107   *
     108   * @param movedatoms atoms whose last step in time to remove
     109   */
     110  void removeLastStep(const std::vector<atomId_t> &movedatoms);
     111
     112  /** Adds another time step to all \a movedatoms.
     113   *
     114   * Note that the time step is initialized to zero.
     115   *
     116   * @param _ids atoms whose last step in time to remove
     117   */
     118  void addNewStep(const std::vector<atomId_t> &_ids);
     119
     120  /** Adds another time step to all \a movedatoms.
     121   *
     122   * Note that the time step is initialized to zero. This gives you a chance
     123   * to set the time step and call setAtomsFromAtomicInfo() yourself.
     124   *
     125   * @param _movedatoms atoms whose last step in time to remove
     126   */
     127  void addNewStep(const std::vector<AtomicInfo> &_movedatoms);
     128
     129  /** Helper function to extract id information from vector of AtomicInfo.
     130   *
     131   * @param movedatoms atoms whose ids to extract
     132   */
     133  std::vector<atomId_t> getIdsFromAtomicInfo(const std::vector<AtomicInfo> &movedatoms);
    78134}
    79135
Note: See TracChangeset for help on using the changeset viewer.