Changeset 0ac85c3 for src/Actions


Ignore:
Timestamp:
Jan 29, 2015, 7:37:57 AM (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:
27e464
Parents:
7b38d3 (diff), 4f2895 (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 'GUI_TesselatedLargeMolecules' into Candidate_v1.4.10

Location:
src/Actions
Files:
18 added
18 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/Action.cpp

    r7b38d3 r0ac85c3  
    146146  endTimer();
    147147
    148   if(shouldUndo() && state != failure){
    149     if(canUndo()){
     148  if (shouldUndo() && state != Action::failure) {
     149    if (canUndo()) {
    150150      ActionQueue::getInstance().addElement(this,state);
    151151    }
    152     else{
    153       ActionQueue::getInstance().clear();
    154     }
     152//    else{
     153//      ActionQueue::getInstance().clear();
     154//    }
    155155  }
    156156
  • src/Actions/ActionQueue.cpp

    r7b38d3 r0ac85c3  
    4444#include <boost/date_time/posix_time/posix_time.hpp>
    4545#include <boost/version.hpp>
     46#include <iterator>
    4647#include <string>
    4748#include <sstream>
     
    6162    AR(new ActionRegistry()),
    6263    history(new ActionHistory),
    63     CurrentAction(0),
    6464#ifndef HAVE_ACTION_THREAD
    6565    lastActionOk(true)
    6666#else
     67    CurrentAction(0),
    6768    lastActionOk(true),
    6869    run_thread(boost::bind(&ActionQueue::run, this)),
     
    8283#ifdef HAVE_ACTION_THREAD
    8384  stop();
     85
     86  clearTempQueue();
    8487#endif
    8588
     
    111114    std::cerr << "Action " << *boost::get_error_info<ActionNameString>(e) << " has failed." << std::endl;
    112115    World::getInstance().setExitFlag(5);
    113     clearQueue();
     116    clearQueue(actionqueue.size()-1);
    114117    lastActionOk = false;
    115     std::cerr << "ActionQueue cleared." << std::endl;
     118    std::cerr << "Remaining Actions cleared from queue." << std::endl;
    116119  } catch (std::exception &e) {
    117120    pushStatus("FAIL: General exception caught, aborting.");
    118121    World::getInstance().setExitFlag(134);
    119     clearQueue();
     122    clearQueue(actionqueue.size()-1);
    120123    lastActionOk = false;
    121     std::cerr << "ActionQueue cleared." << std::endl;
     124    std::cerr << "Remaining Actions cleared from queue." << std::endl;
    122125  }
    123126  if (lastActionOk) {
     
    127130  }
    128131#else
    129   {
    130     boost::lock_guard<boost::mutex> lock(mtx_idle);
    131     run_thread_isIdle = (CurrentAction == actionqueue.size());
    132   }
     132  setRunThreadIdle(CurrentAction == actionqueue.size());
    133133  mtx_queue.unlock();
    134134#endif
     
    144144  mtx_queue.lock();
    145145  tempqueue.push_back( newaction );
    146   {
    147     boost::lock_guard<boost::mutex> lock(mtx_idle);
    148     run_thread_isIdle = !((CurrentAction != actionqueue.size()) || !tempqueue.empty());
    149   }
     146  setRunThreadIdle( !((CurrentAction != actionqueue.size()) || !tempqueue.empty()) );
    150147  mtx_queue.unlock();
    151148#endif
     
    184181        pushStatus("FAIL: Action "+*boost::get_error_info<ActionNameString>(e)+" has failed.");
    185182        World::getInstance().setExitFlag(5);
    186         clearQueue();
     183        clearQueue(CurrentAction);
     184        clearTempQueue();
    187185        lastActionOk = false;
    188         std::cerr << "ActionQueue cleared." << std::endl;
    189         CurrentAction = (size_t)-1;
     186        std::cerr << "Remaining Actions cleared from queue." << std::endl;
    190187      } catch (std::exception &e) {
    191188        pushStatus("FAIL: General exception caught, aborting.");
    192189        World::getInstance().setExitFlag(134);
    193         clearQueue();
    194         std::cerr << "ActionQueue cleared." << std::endl;
    195         CurrentAction = (size_t)-1;
     190        clearQueue(CurrentAction);
     191        clearTempQueue();
     192        std::cerr << "Remaining Actions cleared from queue." << std::endl;
    196193      }
    197194      if (lastActionOk) {
     
    199196        NOTIFY(ActionQueued);
    200197        _lastchangedaction = actionqueue[CurrentAction];
     198        mtx_queue.lock();
     199        CurrentAction++;
     200        mtx_queue.unlock();
    201201      }
    202202      // access actionqueue, hence using mutex
    203203      mtx_queue.lock();
    204       // step on to next action and check for end
    205       CurrentAction++;
    206204      // insert new actions (before [CurrentAction]) if they have been spawned
    207205      // we must have an extra vector for this, as we cannot change actionqueue
     
    211209      mtx_queue.unlock();
    212210    }
    213     {
    214       boost::lock_guard<boost::mutex> lock(mtx_idle);
    215       run_thread_isIdle = !((CurrentAction != actionqueue.size()) || !tempqueue.empty());
    216     }
     211    setRunThreadIdle( !((CurrentAction != actionqueue.size()) || !tempqueue.empty()) );
    217212    cond_idle.notify_one();
    218213//    LOG(1, "DEBUG: End of ActionQueue's run() loop.");
    219214  } while (!Interrupted);
    220215}
    221 #endif
    222216
    223217void ActionQueue::insertTempQueue()
     
    231225}
    232226
    233 #ifdef HAVE_ACTION_THREAD
    234227void ActionQueue::wait()
    235228{
     
    316309}
    317310
    318 void ActionQueue::clearQueue()
    319 {
    320   // free all actions contained in actionqueue
    321   for (ActionQueue_t::iterator iter = actionqueue.begin();
    322       !actionqueue.empty(); iter = actionqueue.begin()) {
     311void ActionQueue::clearQueue(const size_t _fromAction)
     312{
     313#ifdef HAVE_ACTION_THREAD
     314  mtx_queue.lock();
     315#endif
     316  LOG(1, "Removing all Actions from position " << _fromAction << " onward.");
     317  // free all actions still to be called contained in actionqueue
     318  ActionQueue_t::iterator inititer = actionqueue.begin();
     319  std::advance(inititer, _fromAction);
     320  for (ActionQueue_t::iterator iter = inititer; iter != actionqueue.end(); ++iter)
    323321    delete *iter;
    324     actionqueue.erase(iter);
    325   }
     322  actionqueue.erase(inititer, actionqueue.end());
     323  LOG(1, "There are " << actionqueue.size() << " remaining Actions.");
     324#ifdef HAVE_ACTION_THREAD
     325  CurrentAction = actionqueue.size();
     326  mtx_queue.unlock();
     327#endif
     328}
     329
     330#ifdef HAVE_ACTION_THREAD
     331void ActionQueue::clearTempQueue()
     332{
    326333  // free all actions contained in tempqueue
    327334  for (ActionQueue_t::iterator iter = tempqueue.begin();
     
    330337    tempqueue.erase(iter);
    331338  }
    332 #ifdef HAVE_ACTION_THREAD
     339}
     340
     341void ActionQueue::setRunThreadIdle(const bool _flag)
     342{
    333343  {
    334344    boost::unique_lock<boost::mutex> lock(mtx_idle);
    335     run_thread_isIdle = true;
    336   }
    337 #endif
    338 }
     345    run_thread_isIdle = _flag;
     346  }
     347}
     348#endif
    339349
    340350const ActionQueue::ActionTokens_t ActionQueue::getListOfActions() const
     
    355365}
    356366
     367bool ActionQueue::canUndo() const
     368{
     369  return history->hasUndo();
     370}
     371
    357372void ActionQueue::redoLast()
    358373{
     
    360375}
    361376
     377bool ActionQueue::canRedo() const
     378{
     379  return history->hasRedo();
     380}
     381
    362382
    363383CONSTRUCT_SINGLETON(ActionQueue)
  • src/Actions/ActionQueue.hpp

    r7b38d3 r0ac85c3  
    145145  void redoLast();
    146146
     147  /** Checks whether there is one completed Action stored in ActionHistory in the past.
     148   *
     149   * @return true - at least one Action to undo present, false - else
     150   */
     151  bool canUndo() const;
     152
     153  /** Checks whether there is one completed Action stored in ActionHistory in the future.
     154   *
     155   * @return true - at least one Action to redo present, false - else
     156   */
     157  bool canRedo() const;
     158
    147159  /** Return status of last executed action.
    148160   *
     
    190202  void clear();
    191203
    192   /** Clears all actions currently present in the actionqueues.
    193    *
    194    */
    195   void clearQueue();
    196 
    197 #ifdef HAVE_ACTION_THREAD
     204  /** Clears all actions present in the actionqueues from \a _fromAction.
     205   *
     206   * @param _fromAction 0 if all Actions to clear or else
     207   */
     208  void clearQueue(const size_t _fromAction = 0);
     209
     210#ifdef HAVE_ACTION_THREAD
     211
     212  /** Clears the temporary queue.
     213   *
     214   */
     215  void clearTempQueue();
     216
     217  /** Sets the run_thread_isIdle flag.
     218   *
     219   * @param _flag state to set to
     220   */
     221  void setRunThreadIdle(const bool _flag);
     222
    198223  /** Runs the ActionQueue.
    199224   *
     
    214239   */
    215240  void wait();
     241
     242  /** Moves all action from tempqueue into real queue.
     243   *
     244   */
     245  void insertTempQueue();
     246
    216247#endif
    217248
     
    224255  void insertAction(Action *_action, enum Action::QueryOptions state);
    225256
    226   /** Moves all action from tempqueue into real queue.
    227    *
    228    */
    229   void insertTempQueue();
    230 
    231257private:
    232258  /** Private cstor for ActionQueue.
     
    255281  ActionQueue_t actionqueue;
    256282
     283  //!> indicates that the last action has failed
     284  bool lastActionOk;
     285
     286#ifdef HAVE_ACTION_THREAD
    257287  //!> point to current action in actionqueue
    258288  size_t CurrentAction;
     
    261291  ActionQueue_t tempqueue;
    262292
    263   //!> indicates that the last action has failed
    264   bool lastActionOk;
    265 
    266 #ifdef HAVE_ACTION_THREAD
    267293  //!> internal thread to call Actions
    268294  boost::thread run_thread;
  • src/Actions/ActionRegistry.cpp

    r7b38d3 r0ac85c3  
    9191    MakroAction * presentAction =
    9292        dynamic_cast<MakroAction *>(getActionByName("subgraph-dissection"));
     93    ASSERT( presentAction != NULL,
     94        "ActionRegistry::fillRegistry() - makro action has not been registered.");
     95    presentAction->unprepare(*this);
     96  }
     97  {
     98    MakroAction * presentAction =
     99        dynamic_cast<MakroAction *>(getActionByName("translate-molecules"));
    93100    ASSERT( presentAction != NULL,
    94101        "ActionRegistry::fillRegistry() - makro action has not been registered.");
     
    136143    MakroAction * presentAction =
    137144        dynamic_cast<MakroAction *>(getActionByName("optimize-structure"));
     145    ASSERT( presentAction != NULL,
     146        "ActionRegistry::fillRegistry() - makro action has not been registered.");
     147    presentAction->prepare(*this);
     148  }
     149  {
     150    MakroAction * presentAction =
     151        dynamic_cast<MakroAction *>(getActionByName("translate-molecules"));
    138152    ASSERT( presentAction != NULL,
    139153        "ActionRegistry::fillRegistry() - makro action has not been registered.");
  • src/Actions/AtomAction/TranslateAction.def

    r7b38d3 r0ac85c3  
    1616// "undefine" if no parameters are required, use (NOPARAM_DEFAULT) for each (undefined) default value
    1717#define paramtypes (Vector)(bool)
    18 #define paramtokens ("translate-atoms")("periodic")
     18#define paramtokens ("position")("periodic")
    1919#define paramdescriptions ("translation vector")("system is constraint to periodic boundary conditions")
    2020#define paramreferences (x)(periodic)
  • src/Actions/FillAction/SuspendInMoleculeAction.cpp

    r7b38d3 r0ac85c3  
    129129  filler->CenterEdge();
    130130
     131  std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
     132  if (molecules.size() < 2) {
     133    STATUS("There must be at least two molecules: filler and to be suspended.");
     134    return Action::failure;
     135  }
     136
    131137  /// first we need to calculate some volumes and masses
    132   std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
    133138  double totalmass = 0.;
    134139  const bool IsAngstroem = true;
     
    139144      iter != molecules.end(); ++iter)
    140145  {
     146    // skip the filler
     147    if (*iter == filler)
     148      continue;
    141149    molecule & mol = **iter;
    142150    const double mass = calculateMass(mol);
     
    152160  LOG(1, "INFO: The average density is " << setprecision(10)
    153161      << totalmass / clustervolume << " atomicmassunit/"
    154       << (IsAngstroem ? "angstrom" : "atomiclength") << "^3.");
     162      << (IsAngstroem ? " angstrom" : " atomiclength") << "^3.");
     163  if ( ((totalmass / clustervolume < 1.) && (params.density.get() > 1.))
     164      || ((totalmass / clustervolume > 1.) && (params.density.get() < 1.))) {
     165    STATUS("Desired and present molecular densities must both be either in [0,1) or in (1, inf).");
     166    return Action::failure;
     167  }
    155168
    156169  // calculate maximum solvent density
    157170  std::vector<double> fillerdiameters(NDIM, 0.);
    158   const double solventdensity =
    159       calculateMass(*filler) / calculateEnvelopeVolume(*filler, fillerdiameters);
    160 
    161   std::vector<unsigned int> counts(3, 0);
    162   Vector offset(.5,.5,.5);
     171  const double fillervolume = calculateEnvelopeVolume(*filler, fillerdiameters);
     172  const double fillermass = calculateMass(*filler);
     173  LOG(1, "INFO: The filler's mass is " << setprecision(10)
     174      << fillermass << " atomicmassunit, and it's volume is "
     175      << fillervolume << (IsAngstroem ? " angstrom" : " atomiclength") << "^3.");
     176  const double solventdensity = fillermass / fillervolume;
    163177
    164178  /// solve cubic polynomial
    165179  double cellvolume = 0.;
    166180  LOG(1, "Solving equidistant suspension in water problem ...");
    167   cellvolume = (totalmass / solventdensity
    168       - (totalmass / clustervolume)) / (params.density.get() - 1.);
     181  // s = solvent, f = filler, 0 = initial molecules/cluster
     182  // v_s = v_0 + v_f, m_s = m_0 + rho_f * v_f --> rho_s = m_s/v_s ==> v_f = (m_0 - rho_s * v_o) / (rho_s - rho_f)
     183  cellvolume = (totalmass - params.density.get() * clustervolume) / (params.density.get() - 1.) + clustervolume;
    169184  LOG(1, "Cellvolume needed for a density of " << params.density.get()
    170185      << " g/cm^3 is " << cellvolume << " angstroem^3.");
     
    173188      (GreatestDiameter[0] * GreatestDiameter[1] * GreatestDiameter[2]);
    174189  LOG(1, "Minimum volume of the convex envelope contained in a rectangular box is "
    175       << minimumvolume << "angstrom^3.");
     190      << minimumvolume << " angstrom^3.");
    176191
    177192  if (minimumvolume > cellvolume) {
     
    187202        + GreatestDiameter[1] * GreatestDiameter[2];
    188203    BoxLengths[2] = minimumvolume - cellvolume;
    189     double x0 = 0.;
    190     double x1 = 0.;
    191     double x2 = 0.;
     204    std::vector<double> x(3, 0.);
    192205    // for cubic polynomial there are either 1 or 3 unique solutions
    193     if (gsl_poly_solve_cubic(BoxLengths[0], BoxLengths[1], BoxLengths[2], &x0, &x1, &x2) == 1)
    194       LOG(0, "RESULT: The resulting spacing is: " << x0 << " .");
    195     else {
    196       LOG(0, "RESULT: The resulting spacings are: " << x0 << " and " << x1 << " and " << x2 << " .");
    197       std::swap(x0, x2); // sorted in ascending order
    198     }
     206    if (gsl_poly_solve_cubic(BoxLengths[0], BoxLengths[1], BoxLengths[2], &x[0], &x[1], &x[2]) == 1) {
     207      x[1] = x[0];
     208      x[2] = x[0];
     209    } else {
     210      std::swap(x[0], x[2]); // sorted in ascending order
     211    }
     212    LOG(0, "RESULT: The resulting spacing is: " << x << " .");
    199213
    200214    cellvolume = 1.;
    201215    for (size_t i = 0; i < NDIM; ++i) {
    202       BoxLengths[i] = x0 + GreatestDiameter[i];
     216      BoxLengths[i] = x[i] + GreatestDiameter[i];
    203217      cellvolume *= BoxLengths[i];
    204218    }
    205 
    206     // set new box dimensions
    207     LOG(0, "Translating to box with these boundaries.");
    208     {
    209       RealSpaceMatrix domain;
    210       for(size_t i =0; i<NDIM;++i)
    211         domain.at(i,i) = BoxLengths[i];
    212       World::getInstance().setDomain(domain);
    213     }
    214 //    mol->CenterInBox();
     219  }
     220
     221  // TODO: Determine counts from resulting mass correctly (hard problem due to integers)
     222  std::vector<unsigned int> counts(3, 0);
     223  const unsigned int totalcounts = round(params.density.get() * cellvolume - totalmass) / fillermass;
     224  if (totalcounts > 0) {
     225    counts[0] = ceil(BoxLengths[0]/3.1);
     226    counts[1] = ceil(BoxLengths[1]/3.1);
     227    counts[2] = ceil(BoxLengths[2]/3.1);
    215228  }
    216229
     
    231244      params.RandMoleculeDisplacement.get(),
    232245      params.DoRotate.get());
     246  Vector offset(.5,.5,.5);
    233247  filler_preparator.addCubeMesh(
    234248      counts,
  • src/Actions/FillAction/SuspendInMoleculeAction.def

    r7b38d3 r0ac85c3  
    1717#include "Parameters/Validators/RangeValidator.hpp"
    1818#include "Parameters/Validators/STLVectorValidator.hpp"
     19#include "Parameters/Validators/Ops_Validator.hpp"
    1920#include "Parameters/Validators/Specific/BoxLengthValidator.hpp"
    2021#include "Parameters/Validators/Specific/VectorZeroOneComponentsValidator.hpp"
     
    2526#define paramtypes (double)(double)(double)(double)(bool)
    2627#define paramtokens ("density")("min-distance")("random-atom-displacement")("random-molecule-displacement")("DoRotate")
    27 #define paramdescriptions ("desired density for the total domain")("minimum distance of water molecules to present atoms")("magnitude of random atom displacement")("magnitude of random molecule displacement")("whether to rotate or not")
     28#define paramdescriptions ("desired density for the total domain, unequal 1.")("minimum distance of water molecules to present atoms")("magnitude of random atom displacement")("magnitude of random molecule displacement")("whether to rotate or not")
    2829#define paramdefaults (PARAM_DEFAULT(1.))(PARAM_DEFAULT(1.))(PARAM_DEFAULT(0.))(PARAM_DEFAULT(0.))(PARAM_DEFAULT(false))
    2930#define paramreferences (density)(mindistance)(RandAtomDisplacement)(RandMoleculeDisplacement)(DoRotate)
    3031#define paramvalids \
    31 (RangeValidator< double >(0., std::numeric_limits<double>::max())) \
     32(RangeValidator< double >(0., 1. - std::numeric_limits<double>::epsilon()) || RangeValidator< double >(1. + std::numeric_limits<double>::epsilon(), std::numeric_limits<double>::max())) \
    3233(BoxLengthValidator()) \
    3334(BoxLengthValidator()) \
  • src/Actions/GlobalListOfActions.hpp

    r7b38d3 r0ac85c3  
    7676  (MoleculeLinearInterpolationofTrajectories) \
    7777  (MoleculeLoad) \
     78  (MoleculeRemove) \
    7879  (MoleculeRotateAroundSelfByAngle) \
    7980  (MoleculeRotateToPrincipalAxisSystem) \
     
    8384  (MoleculeSaveTemperature) \
    8485  (MoleculeStretchBond) \
     86  (MoleculeTranslate) \
    8587  (MoleculeVerletIntegration) \
    8688  (PotentialFitParticleCharges) \
     
    126128  (SelectionNotMoleculeByOrder) \
    127129  (SelectionNotShapeByName) \
     130  (SelectionPopAtoms) \
     131  (SelectionPushAtoms) \
     132  (SelectionPopMolecules) \
     133  (SelectionPushMolecules) \
    128134  (SelectionShapeByName) \
    129135  (ShapeCombineShapes) \
  • src/Actions/GraphAction/SubgraphDissectionAction.cpp

    r7b38d3 r0ac85c3  
    4242#include "Actions/GraphAction/UpdateMoleculesAction.hpp"
    4343#include "Actions/GraphAction/SubgraphDissectionAction.hpp"
     44#include "Actions/SelectionAction/Atoms/PushAtomsAction.hpp"
     45#include "Actions/SelectionAction/Atoms/PopAtomsAction.hpp"
     46#include "Actions/SelectionAction/Atoms/AllAtomsAction.hpp"
    4447#include "Actions/ActionQueue.hpp"
    4548#include "Actions/ActionRegistry.hpp"
     
    6063void GraphSubgraphDissectionAction::prepare(ActionRegistry &AR)
    6164{
     65  actions.addAction(AR.getActionByName(std::string("push-atom-selection")));
    6266  actions.addAction(AR.getActionByName(std::string("select-all-atoms")));
    6367  actions.addAction(AR.getActionByName(std::string("destroy-adjacency")));
    6468  actions.addAction(AR.getActionByName(std::string("create-adjacency")));
    6569  actions.addAction(AR.getActionByName(std::string("update-molecules")));
     70  actions.addAction(AR.getActionByName(std::string("pop-atom-selection")));
    6671  isPrepared = true;
    6772}
     
    7479}
    7580
    76 void reselectAtoms(const std::vector<atom *> &selected_atoms)
    77 {
    78   World::getInstance().clearAtomSelection();
    79   for (std::vector<atom *>::const_iterator iter = selected_atoms.begin();
    80       iter != selected_atoms.end();
    81       ++iter)
    82     World::getInstance().selectAtom(*iter);
    83 }
    84 
    8581ActionState::ptr GraphSubgraphDissectionAction::performCall(){
    86   // we need to "emulate" that all atoms have been selected without destroying
    87   // current selection
    88   const std::vector<atom *> selected_atoms = World::getInstance().getSelectedAtoms();
    8982  ActionState::ptr state(MakroAction::performCall());
    90   reselectAtoms(selected_atoms);
    9183
    9284  return state;
     
    9486
    9587ActionState::ptr GraphSubgraphDissectionAction::performUndo(ActionState::ptr _state) {
    96   // we need to "emulate" that all atoms have been selected without destroying
    97   // current selection
    98   const std::vector<atom *> selected_atoms = World::getInstance().getSelectedAtoms();
    9988  ActionState::ptr state(MakroAction::performUndo(_state));
    100   reselectAtoms(selected_atoms);
    10189
    10290  return state;
     
    10492
    10593ActionState::ptr GraphSubgraphDissectionAction::performRedo(ActionState::ptr _state){
    106   // we need to "emulate" that all atoms have been selected without destroying
    107   // current selection
    108   const std::vector<atom *> selected_atoms = World::getInstance().getSelectedAtoms();
    10994  ActionState::ptr state(MakroAction::performRedo(_state));
    110   reselectAtoms(selected_atoms);
    11195
    11296  return state;
  • src/Actions/Makefile.am

    r7b38d3 r0ac85c3  
    297297  Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.cpp \
    298298  Actions/MoleculeAction/LoadAction.cpp \
     299  Actions/MoleculeAction/RemoveAction.cpp \
    299300  Actions/MoleculeAction/RotateAroundSelfByAngleAction.cpp \
    300301  Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.cpp \
     
    304305  Actions/MoleculeAction/SaveTemperatureAction.cpp \
    305306  Actions/MoleculeAction/StretchBondAction.cpp \
     307  Actions/MoleculeAction/TranslateAction.cpp \
    306308  Actions/MoleculeAction/VerletIntegrationAction.cpp
    307309MOLECULEACTIONHEADER = \
     
    313315  Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.hpp \
    314316  Actions/MoleculeAction/LoadAction.hpp \
     317  Actions/MoleculeAction/RemoveAction.hpp \
    315318  Actions/MoleculeAction/RotateAroundSelfByAngleAction.hpp \
    316319  Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.hpp \
     
    320323  Actions/MoleculeAction/SaveTemperatureAction.hpp \
    321324  Actions/MoleculeAction/StretchBondAction.hpp \
     325  Actions/MoleculeAction/TranslateAction.hpp \
    322326  Actions/MoleculeAction/VerletIntegrationAction.hpp
    323327MOLECULEACTIONDEFS = \
     
    329333  Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.def \
    330334  Actions/MoleculeAction/LoadAction.def \
     335  Actions/MoleculeAction/RemoveAction.def \
    331336  Actions/MoleculeAction/RotateAroundSelfByAngleAction.def \
    332337  Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.def \
     
    336341  Actions/MoleculeAction/SaveTemperatureAction.def \
    337342  Actions/MoleculeAction/StretchBondAction.def \
     343  Actions/MoleculeAction/TranslateAction.def \
    338344  Actions/MoleculeAction/VerletIntegrationAction.def
    339345
     
    412418  Actions/SelectionAction/Atoms/NotAtomByElementAction.cpp \
    413419  Actions/SelectionAction/Atoms/NotAtomByIdAction.cpp \
    414   Actions/SelectionAction/Atoms/NotAtomByOrderAction.cpp
     420  Actions/SelectionAction/Atoms/NotAtomByOrderAction.cpp \
     421  Actions/SelectionAction/Atoms/PopAtomsAction.cpp \
     422  Actions/SelectionAction/Atoms/PushAtomsAction.cpp
    415423SELECTIONATOMACTIONHEADER = \
    416424  Actions/SelectionAction/Atoms/AllAtomsAction.hpp \
     
    427435  Actions/SelectionAction/Atoms/NotAtomByElementAction.hpp \
    428436  Actions/SelectionAction/Atoms/NotAtomByIdAction.hpp \
    429   Actions/SelectionAction/Atoms/NotAtomByOrderAction.hpp
     437  Actions/SelectionAction/Atoms/NotAtomByOrderAction.hpp \
     438  Actions/SelectionAction/Atoms/PopAtomsAction.hpp \
     439  Actions/SelectionAction/Atoms/PushAtomsAction.hpp
    430440SELECTIONATOMACTIONDEFS = \
    431441  Actions/SelectionAction/Atoms/AllAtomsAction.def \
     
    442452  Actions/SelectionAction/Atoms/NotAtomByElementAction.def \
    443453  Actions/SelectionAction/Atoms/NotAtomByIdAction.def \
    444   Actions/SelectionAction/Atoms/NotAtomByOrderAction.def
     454  Actions/SelectionAction/Atoms/NotAtomByOrderAction.def \
     455  Actions/SelectionAction/Atoms/PopAtomsAction.def \
     456  Actions/SelectionAction/Atoms/PushAtomsAction.def
    445457
    446458SELECTIONMOLECULEACTIONSOURCE = \
     
    458470  Actions/SelectionAction/Molecules/NotMoleculeByNameAction.cpp \
    459471  Actions/SelectionAction/Molecules/NotMoleculeByOrderAction.cpp \
    460   Actions/SelectionAction/Molecules/NotMoleculeOfAtomAction.cpp
     472  Actions/SelectionAction/Molecules/NotMoleculeOfAtomAction.cpp \
     473  Actions/SelectionAction/Molecules/PopMoleculesAction.cpp \
     474  Actions/SelectionAction/Molecules/PushMoleculesAction.cpp
    461475SELECTIONMOLECULEACTIONHEADER = \
    462476  Actions/SelectionAction/Molecules/AllMoleculesAction.hpp \
     
    473487  Actions/SelectionAction/Molecules/NotMoleculeByNameAction.hpp \
    474488  Actions/SelectionAction/Molecules/NotMoleculeByOrderAction.hpp \
    475   Actions/SelectionAction/Molecules/NotMoleculeOfAtomAction.hpp
     489  Actions/SelectionAction/Molecules/NotMoleculeOfAtomAction.hpp \
     490  Actions/SelectionAction/Molecules/PopMoleculesAction.hpp \
     491  Actions/SelectionAction/Molecules/PushMoleculesAction.hpp
    476492SELECTIONMOLECULEACTIONDEFS = \
    477493  Actions/SelectionAction/Molecules/AllMoleculesAction.def \
     
    488504  Actions/SelectionAction/Molecules/NotMoleculeByNameAction.def \
    489505  Actions/SelectionAction/Molecules/NotMoleculeByOrderAction.def \
    490   Actions/SelectionAction/Molecules/NotMoleculeOfAtomAction.def
     506  Actions/SelectionAction/Molecules/NotMoleculeOfAtomAction.def \
     507  Actions/SelectionAction/Molecules/PopMoleculesAction.def \
     508  Actions/SelectionAction/Molecules/PushMoleculesAction.def
    491509                 
    492510SELECTIONSHAPEACTIONSOURCE = \
  • src/Actions/SelectionAction/Atoms/NotAtomByIdAction.def

    r7b38d3 r0ac85c3  
    2626(STLVectorValidator< std::vector<atomId_t> >(AtomIdValidator()))
    2727
    28 
    2928#define statetypes (atomids_t)
    3029#define statereferences (undoatomids)
  • src/Actions/SelectionAction/Molecules/MoleculeByIdAction.cpp

    r7b38d3 r0ac85c3  
    5353/** =========== define the function ====================== */
    5454ActionState::ptr SelectionMoleculeByIdAction::performCall() {
    55   const molecule *mol = World::getInstance().getMolecule(MoleculeById(params.molindex.get()));
    56   if (mol != NULL) {
    57     if (!World::getInstance().isSelected(mol)) {
    58       LOG(1, "Selecting molecule " << mol->name);
    59       World::getInstance().selectAllMolecules(MoleculeById(params.molindex.get()));
    60       LOG(0, World::getInstance().countSelectedMolecules() << " molecules selected.");
    61       return ActionState::ptr(new SelectionMoleculeByIdState(params));
     55
     56  enum Sucess {
     57    NoStatus,
     58    AllMoleculesUnselected,
     59    MoleculesSelected,
     60    MoleculeMissing
     61  } status = NoStatus;
     62
     63  const molids_t molids = params.molids.get();
     64  molids_t undomolids;
     65  undomolids.reserve(molids.size());
     66  for (molids_t::const_iterator iter = molids.begin(); iter != molids.end(); ++iter) {
     67    const molecule *Walker = World::getInstance().getMolecule(MoleculeById(*iter));
     68    if (Walker != NULL) {
     69      if (!World::getInstance().isSelected(Walker)) {
     70        LOG(1, "Selecting mol " << Walker->getName());
     71        World::getInstance().selectMolecule(Walker);
     72        undomolids.push_back(*iter);
     73        if (status < MoleculeMissing)
     74          status = MoleculesSelected;
     75      } else {
     76        if (status == NoStatus)
     77          status = AllMoleculesUnselected;
     78      }
    6279    } else {
    63       return Action::success;
     80      status = MoleculeMissing;
    6481    }
    65   } else {
    66     STATUS("Cannot find molecule by given index "+toString(params.molindex.get())+".");
    67     return Action::failure;
    6882  }
     83  LOG(0, World::getInstance().countSelectedMolecules() << " mols selected.");
     84
     85  switch (status) {
     86    case MoleculeMissing:
     87      STATUS("Cannot find all mols with given ids.");
     88      return Action::failure;
     89      break;
     90    case AllMoleculesUnselected:
     91    case MoleculesSelected:
     92      return ActionState::ptr(new SelectionMoleculeByIdState(undomolids, params));
     93      break;
     94    default:
     95      STATUS("No mols have been selected.");
     96      return Action::failure;
     97      break;
     98  }
     99  return Action::failure;
    69100}
    70101
     
    72103  SelectionMoleculeByIdState *state = assert_cast<SelectionMoleculeByIdState*>(_state.get());
    73104
    74   World::getInstance().unselectAllMolecules(MoleculeById(state->params.molindex.get()));
     105  for (molids_t::const_iterator iter = state->undomolids.begin();
     106      iter != state->undomolids.end(); ++iter) {
     107    const molecule *Walker = World::getInstance().getMolecule(MoleculeById(*iter));
     108    World::getInstance().unselectMolecule(Walker);
     109  }
    75110
    76111  return ActionState::ptr(_state);
     
    80115  SelectionMoleculeByIdState *state = assert_cast<SelectionMoleculeByIdState*>(_state.get());
    81116
    82   World::getInstance().selectAllMolecules(MoleculeById(state->params.molindex.get()));
     117  for (molids_t::const_iterator iter = state->undomolids.begin();
     118      iter != state->undomolids.end(); ++iter) {
     119    const molecule *Walker = World::getInstance().getMolecule(MoleculeById(*iter));
     120    World::getInstance().selectMolecule(Walker);
     121  }
    83122
    84123  return ActionState::ptr(_state);
  • src/Actions/SelectionAction/Molecules/MoleculeByIdAction.def

    r7b38d3 r0ac85c3  
    77
    88// all includes and forward declarations necessary for non-integral types below
     9#include <vector>
    910#include "types.hpp"
    1011
     12typedef std::vector<moleculeId_t> molids_t;
     13
     14#include "Parameters/Validators/STLVectorValidator.hpp"
    1115#include "Parameters/Validators/Specific/MoleculeIdValidator.hpp"
    1216
     
    1418// ValueStorage by the token "Z" -> first column: int, Z, "Z"
    1519// "undefine" if no parameters are required, use (NOPARAM_DEFAULT) for each (undefined) default value
    16 #define paramtypes (moleculeId_t)
     20#define paramtypes (molids_t)
    1721#define paramtokens ("select-molecule-by-id")
    18 #define paramdescriptions ("molecule index")
     22#define paramdescriptions ("molecule indices to select")
    1923#undef paramdefaults
    20 #define paramreferences (molindex)
     24#define paramreferences (molids)
    2125#define paramvalids \
    22 (MoleculeIdValidator())
     26(STLVectorValidator< std::vector<moleculeId_t> >(MoleculeIdValidator()))
    2327
    24 #undef statetypes
    25 #undef statereferences
     28#define statetypes (molids_t)
     29#define statereferences (undomolids)
    2630
    2731// some defines for all the names, you may use ACTION, STATE and PARAMS
  • src/Actions/SelectionAction/Molecules/NotMoleculeByIdAction.cpp

    r7b38d3 r0ac85c3  
    5353/** =========== define the function ====================== */
    5454ActionState::ptr SelectionNotMoleculeByIdAction::performCall() {
    55   const molecule *mol = World::getInstance().getMolecule(MoleculeById(params.molindex.get()));
    56   if (mol != NULL) {
    57     if (World::getInstance().isSelected(mol)) {
    58       LOG(1, "Unselecting molecule " << mol->name);
    59       World::getInstance().unselectAllMolecules(MoleculeById(params.molindex.get()));
    60       LOG(0, World::getInstance().countSelectedMolecules() << " molecules remain selected.");
    61       return ActionState::ptr(new SelectionNotMoleculeByIdState(params));
     55  enum Sucess {
     56    NoStatus,
     57    AllMoleculesSelected,
     58    MoleculesUnselected,
     59    MoleculeMissing
     60  } status = NoStatus;
     61
     62  const molids_t molids = params.molids.get();
     63  molids_t undomolids;
     64  undomolids.reserve(molids.size());
     65  for (molids_t::const_iterator iter = molids.begin(); iter != molids.end(); ++iter) {
     66    const molecule *Walker = World::getInstance().getMolecule(MoleculeById(*iter));
     67    if (Walker != NULL) {
     68      if (World::getInstance().isSelected(Walker)) {
     69        LOG(1, "Unselecting mol " << Walker->getName());
     70        World::getInstance().unselectMolecule(Walker);
     71        undomolids.push_back(*iter);
     72        if (status < MoleculeMissing)
     73          status = MoleculesUnselected;
     74      } else {
     75        if (status == NoStatus)
     76          status = AllMoleculesSelected;
     77      }
    6278    } else {
    63       return Action::success;
     79      status = MoleculeMissing;
    6480    }
    65   } else {
    66     STATUS("Cannot find molecule by given index "+toString(params.molindex.get())+".");
    67     return Action::failure;
    6881  }
     82  LOG(0, World::getInstance().countSelectedMolecules() << " mols remain selected.");
     83
     84  switch (status) {
     85    case MoleculeMissing:
     86      STATUS("Cannot find all mols by given ids.");
     87      return Action::failure;
     88      break;
     89    case AllMoleculesSelected:
     90    case MoleculesUnselected:
     91      return ActionState::ptr(new SelectionNotMoleculeByIdState(undomolids, params));
     92      break;
     93    default:
     94      STATUS("No mols have been selected.");
     95      return Action::failure;
     96      break;
     97  }
     98  return Action::failure;
    6999}
    70100
     
    72102  SelectionNotMoleculeByIdState *state = assert_cast<SelectionNotMoleculeByIdState*>(_state.get());
    73103
    74   World::getInstance().selectAllMolecules(MoleculeById(state->params.molindex.get()));
     104  for (molids_t::const_iterator iter = state->undomolids.begin();
     105      iter != state->undomolids.end(); ++iter) {
     106    const molecule *Walker = World::getInstance().getMolecule(MoleculeById(*iter));
     107    World::getInstance().selectMolecule(Walker);
     108  }
    75109
    76110  return ActionState::ptr(_state);
     
    80114  SelectionNotMoleculeByIdState *state = assert_cast<SelectionNotMoleculeByIdState*>(_state.get());
    81115
    82   World::getInstance().unselectAllMolecules(MoleculeById(state->params.molindex.get()));
     116  for (molids_t::const_iterator iter = state->undomolids.begin();
     117      iter != state->undomolids.end(); ++iter) {
     118    const molecule *Walker = World::getInstance().getMolecule(MoleculeById(*iter));
     119    World::getInstance().unselectMolecule(Walker);
     120  }
    83121
    84122  return ActionState::ptr(_state);
  • src/Actions/SelectionAction/Molecules/NotMoleculeByIdAction.def

    r7b38d3 r0ac85c3  
    77
    88// all includes and forward declarations necessary for non-integral types below
     9#include <vector>
    910#include "types.hpp"
    1011
     12typedef std::vector<moleculeId_t> molids_t;
     13
     14#include "Parameters/Validators/STLVectorValidator.hpp"
    1115#include "Parameters/Validators/Specific/MoleculeIdValidator.hpp"
    1216
     
    1418// ValueStorage by the token "Z" -> first column: int, Z, "Z"
    1519// "undefine" if no parameters are required, use (NOPARAM_DEFAULT) for each (undefined) default value
    16 #define paramtypes (moleculeId_t)
     20#define paramtypes (molids_t)
    1721#define paramtokens ("unselect-molecule-by-id")
    18 #define paramdescriptions ("molecule index")
     22#define paramdescriptions ("molecule indices to unselect")
    1923#undef paramdefaults
    20 #define paramreferences (molindex)
     24#define paramreferences (molids)
    2125#define paramvalids \
    22 (MoleculeIdValidator())
     26(STLVectorValidator< std::vector<moleculeId_t> >(MoleculeIdValidator()))
    2327
    24 #undef statetypes
    25 #undef statereferences
     28#define statetypes (molids_t)
     29#define statereferences (undomolids)
    2630
    2731// some defines for all the names, you may use ACTION, STATE and PARAMS
  • src/Actions/UndoRedoHelpers.cpp

    r7b38d3 r0ac85c3  
    5252#include "WorldTime.hpp"
    5353
    54 bool MoleCuilder::AddAtomsFromAtomicInfo(std::vector<AtomicInfo> &atoms)
     54bool MoleCuilder::AddAtomsFromAtomicInfo(const std::vector<AtomicInfo> &atoms)
    5555{
    5656  size_t i=0;
     
    6969    for (size_t j=0;j<i;++j)
    7070      World::getInstance().destroyAtom(atoms[j].getId());
     71    // and announce the failure
     72    return false;
     73  }
     74  return true;
     75}
     76
     77bool MoleCuilder::AddMoleculesFromAtomicInfo(std::map< moleculeId_t, std::vector<AtomicInfo> > &mol_atoms)
     78{
     79  bool status = true;
     80  for (std::map< moleculeId_t, std::vector<AtomicInfo> >::const_iterator iter = mol_atoms.begin();
     81      iter != mol_atoms.end(); ++iter) {
     82    // re-create the atom
     83    LOG(3, "DEBUG: Re-adding molecule " << iter->first << ".");
     84    molecule *mol_Walker = World::getInstance().createMolecule();
     85
     86    // reset the mol id
     87    bool status = true;
     88    if (mol_Walker->getId() != iter->first)
     89      status &= mol_Walker->changeId(iter->first);
     90
     91    // add all its atoms
     92    status &= AddAtomsFromAtomicInfo(iter->second);
     93  }
     94  if (!status) {
     95    // remove all molecules again
     96    for (std::map< moleculeId_t, std::vector<AtomicInfo> >::const_iterator iter = mol_atoms.begin();
     97        iter != mol_atoms.end(); ++iter) {
     98      molecule * mol = World::getInstance().getMolecule(MoleculeById(iter->first));
     99      if (mol != NULL)
     100        removeAtomsinMolecule(mol);
     101    }
    71102    // and announce the failure
    72103    return false;
     
    173204  for (std::vector<moleculeId_t>::const_iterator iter = ids.begin();
    174205      iter != ids.end(); ++iter) {
    175     molecule * const mol = World::getInstance().getMolecule(MoleculeById(*iter));
     206    molecule * mol = World::getInstance().getMolecule(MoleculeById(*iter));
    176207    if (mol != NULL) {
    177       mol->removeAtomsinMolecule();
    178       World::getInstance().destroyMolecule(mol);
     208      removeAtomsinMolecule(mol);
     209      // molecules are automatically removed when empty
    179210    }
    180211  }
  • src/Actions/UndoRedoHelpers.hpp

    r7b38d3 r0ac85c3  
    2727   * @return restoral was successful, at least atom could not be restored.
    2828   */
    29   bool AddAtomsFromAtomicInfo(std::vector<AtomicInfo> &atoms);
     29  bool AddAtomsFromAtomicInfo(const std::vector<AtomicInfo> &atoms);
     30
     31  /** Adds removed molecules with their atoms back to the world.
     32   *
     33   * @param mol_atoms map of molecules with ids and their atoms as AtomicInfo
     34   * \return true - restoral was successful, at least one atom or molecule could not be restored
     35   */
     36  bool AddMoleculesFromAtomicInfo(std::map< moleculeId_t, std::vector<AtomicInfo> > &mol_atoms);
    3037
    3138  /** Removes atoms whose state information is stored as AtomicInfo.
  • src/Actions/WorldAction/RepeatBoxAction.cpp

    r7b38d3 r0ac85c3  
    147147      iter != allmolecules.end();
    148148      ++iter) {
    149     if (state->oldmolecules.find(*iter) == state->oldmolecules.end()) {
    150       (*iter)->removeAtomsinMolecule();
    151       // TODO: Remove this when World don't has deprecated MoleculeListClass anymore
    152       molecules->erase(*iter);
    153       World::getInstance().destroyMolecule(*iter);
    154     }
     149    if (state->oldmolecules.find(*iter) == state->oldmolecules.end())
     150      removeAtomsinMolecule(*iter);
    155151  }
    156152
Note: See TracChangeset for help on using the changeset viewer.