Ignore:
Timestamp:
Feb 13, 2015, 9:18:04 AM (10 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:
b9b49e
Parents:
2fcef3
git-author:
Frederik Heber <heber@…> (01/29/15 00:25:11)
git-committer:
Frederik Heber <heber@…> (02/13/15 09:18:04)
Message:

Enhanced add-bonds and remove-bonds to multiply selected pairs of atoms.

  • renamed add/remove-bond -> add/remove-bond(s) to emphasize this.
  • added regression test on three selected atoms.
  • modified userguide entry for both actions.
Location:
src/Actions/BondAction
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/BondAction/BondAddAction.cpp

    r2fcef3 r88afc9  
    5757ActionState::ptr BondAddAction::performCall() {
    5858  // check preconditions
    59   if (World::getInstance().countSelectedAtoms() != 2) {
    60     STATUS("Exactly two atoms must be selected for BondAction Add.");
     59  World& world = World::getInstance();
     60  if (world.countSelectedAtoms() <= 1) {
     61    STATUS("There must be at least two atoms selected for BondAction Add.");
    6162    return Action::failure;
    6263  }
    63   const std::vector<atom *> selected_atoms = World::getInstance().getSelectedAtoms();
    64   if (selected_atoms[0]->IsBondedTo(WorldTime::getTime(), selected_atoms[1])) {
    65     STATUS("There already is a bond in between the two selected atoms.");
     64
     65  bondPairIds_t bondPairIds;
     66  for (World::AtomSelectionConstIterator firstiter = world.beginAtomSelection();
     67      firstiter != world.endAtomSelection(); ++firstiter) {
     68    for (World::AtomSelectionConstIterator seconditer = firstiter;
     69        seconditer != world.endAtomSelection(); ++seconditer) {
     70      if (firstiter == seconditer)
     71        continue;
     72      if (!(firstiter->second)->IsBondedTo(WorldTime::getTime(), seconditer->second))
     73        bondPairIds.push_back(
     74            std::make_pair((firstiter->second)->getId(), (seconditer->second)->getId()));
     75    }
     76  }
     77  if (bondPairIds.empty()) {
     78    STATUS("All bonds are already present.");
    6679    return Action::failure;
    6780  }
    6881
    6982  // create undo
    70   BondAddState *UndoState = new BondAddState(selected_atoms[0]->getId(), selected_atoms[1]->getId(), params);
     83  BondAddState *UndoState = new BondAddState(bondPairIds, params);
    7184
    7285  // execute action
    73   selected_atoms[0]->addBond(WorldTime::getTime(), selected_atoms[1]);
    74   ASSERT( selected_atoms[0]->IsBondedTo(WorldTime::getTime(), selected_atoms[1]),
     86  for (bondPairIds_t::const_iterator iter = bondPairIds.begin();
     87      iter != bondPairIds.end(); ++iter) {
     88    atom *firstatom = world.getAtom(AtomById(iter->first));
     89    atom *secondatom = world.getAtom(AtomById(iter->second));
     90    ASSERT((firstatom != NULL) && (secondatom != NULL),
     91        "BondAddAction::performCall() - at least one of the ids "
     92        +toString(iter->first)+" or "+toString(iter->second)+" is not present.");
     93    firstatom->addBond(WorldTime::getTime(), secondatom);
     94    ASSERT( firstatom->IsBondedTo(WorldTime::getTime(), secondatom),
    7595      "BondAddAction::performCall() - adding bond in between "
    76       +toString(*selected_atoms[0])+" and "+toString(*selected_atoms[1])+" failed.");
     96      +toString(*firstatom)+" and "+toString(*secondatom)+" failed.");
     97  }
    7798
    7899  return ActionState::ptr(UndoState);
     
    83104
    84105  // check whether bond already existed
    85   atom * const first = World::getInstance().getAtom(AtomById(state->firstId));
    86   atom * const second = World::getInstance().getAtom(AtomById(state->secondId));
    87   ASSERT((first != NULL) && (second != NULL),
    88       "BondAddAction::performUndo() - at least one of the ids "
    89       +toString(state->firstId)+" or "+toString(state->secondId)+" is not present.");
    90   if (first->IsBondedTo(WorldTime::getTime(), second)) {
    91     first->removeBond(WorldTime::getTime(), second);
    92   } else {
    93     ELOG(2, "There is no bond in between "+toString(state->firstId)
    94         +" and "+toString(state->secondId)+".");
     106  World& world = World::getInstance();
     107  for (bondPairIds_t::const_iterator iter = state->bondPairIds.begin();
     108      iter != state->bondPairIds.end(); ++iter) {
     109    atom *firstatom = world.getAtom(AtomById(iter->first));
     110    atom *secondatom = world.getAtom(AtomById(iter->second));
     111    ASSERT((firstatom != NULL) && (secondatom != NULL),
     112        "BondAddAction::performCall() - at least one of the ids "
     113        +toString(iter->first)+" or "+toString(iter->second)+" is not present.");
     114    if (firstatom->IsBondedTo(WorldTime::getTime(), secondatom)) {
     115      firstatom->removeBond(WorldTime::getTime(), secondatom);
     116    } else {
     117      ELOG(2, "There is no bond in between "+toString(iter->first)
     118          +" and "+toString(iter->second)+".");
     119    }
    95120  }
    96121
     
    102127
    103128  // check whether bond already existed
    104   atom * const first = World::getInstance().getAtom(AtomById(state->firstId));
    105   atom * const second = World::getInstance().getAtom(AtomById(state->secondId));
    106   ASSERT((first != NULL) && (second != NULL),
    107       "BondAddAction::performRedo() - at least one of the ids "
    108       +toString(state->firstId)+" or "+toString(state->secondId)+" is not present.");
    109   if (!first->IsBondedTo(WorldTime::getTime(), second)) {
    110     first->addBond(WorldTime::getTime(), second);
    111   } else {
    112     ELOG(2, "There is already a bond in between "+toString(state->firstId)
    113         +" and "+toString(state->secondId)+".");
     129  World& world = World::getInstance();
     130  for (bondPairIds_t::const_iterator iter = state->bondPairIds.begin();
     131      iter != state->bondPairIds.end(); ++iter) {
     132    atom * const firstatom = world.getAtom(AtomById(iter->first));
     133    atom * const secondatom = world.getAtom(AtomById(iter->second));
     134    ASSERT((firstatom != NULL) && (secondatom != NULL),
     135        "BondAddAction::performCall() - at least one of the ids "
     136        +toString(iter->first)+" or "+toString(iter->second)+" is not present.");
     137    if (!firstatom->IsBondedTo(WorldTime::getTime(), secondatom)) {
     138      firstatom->addBond(WorldTime::getTime(), secondatom);
     139    } else {
     140      ELOG(2, "There is already a bond in between "+toString(iter->first)
     141          +" and "+toString(iter->second)+".");
     142    }
    114143  }
    115144
  • src/Actions/BondAction/BondAddAction.def

    r2fcef3 r88afc9  
    88// all includes and forward declarations necessary for non-integral types below
    99#include "types.hpp"
     10#include <vector>
     11#include <utility>
     12
     13typedef std::vector<std::pair<atomId_t,atomId_t> > bondPairIds_t;
    1014
    1115// i.e. there is an integer with variable name Z that can be found in
     
    2024#undef paramvalids
    2125
    22 #define statetypes (atomId_t)(atomId_t)
    23 #define statereferences (firstId)(secondId)
     26#define statetypes (bondPairIds_t)
     27#define statereferences (bondPairIds)
    2428
    2529// some defines for all the names, you may use ACTION, STATE and PARAMS
     
    2832#define MENUPOSITION 1
    2933#define ACTIONNAME Add
    30 #define TOKEN "add-bond"
     34#define TOKEN "add-bonds"
    3135
    3236// finally the information stored in the ActionTrait specialization
    33 #define DESCRIPTION "add bond in between two selected atoms"
     37#define DESCRIPTION "add bonds in between any number of selected atoms"
    3438#undef SHORTFORM
  • src/Actions/BondAction/BondRemoveAction.cpp

    r2fcef3 r88afc9  
    5757ActionState::ptr BondRemoveAction::performCall() {
    5858  // check preconditions
    59   if (World::getInstance().countSelectedAtoms() != 2) {
    60     STATUS("Exactly two atoms must be selected for BondAction Remove.");
     59  World& world = World::getInstance();
     60  if (world.countSelectedAtoms() <= 1) {
     61    STATUS("At least two atoms must be selected for BondAction Remove.");
    6162    return Action::failure;
    6263  }
    63   const std::vector<atom *> selected_atoms = World::getInstance().getSelectedAtoms();
    64   if (!selected_atoms[0]->IsBondedTo(WorldTime::getTime(), selected_atoms[1])) {
    65     STATUS("There is no bond in between the two selected atoms.");
     64
     65  bondPairIds_t bondPairIds;
     66  for (World::AtomSelectionConstIterator firstiter = world.beginAtomSelection();
     67      firstiter != world.endAtomSelection(); ++firstiter) {
     68    for (World::AtomSelectionConstIterator seconditer = firstiter;
     69        seconditer != world.endAtomSelection(); ++seconditer) {
     70      if (firstiter == seconditer)
     71        continue;
     72      if ((firstiter->second)->IsBondedTo(WorldTime::getTime(), seconditer->second))
     73        bondPairIds.push_back(
     74            std::make_pair((firstiter->second)->getId(), (seconditer->second)->getId()));
     75    }
     76  }
     77  if (bondPairIds.empty()) {
     78    STATUS("No bonds are present.");
    6679    return Action::failure;
    6780  }
    6881
    6982  // create undo
    70   BondRemoveState *UndoState = new BondRemoveState(selected_atoms[0]->getId(), selected_atoms[1]->getId(), params);
     83  BondRemoveState *UndoState = new BondRemoveState(bondPairIds, params);
    7184
    7285  // execute action
    73   selected_atoms[0]->removeBond(WorldTime::getTime(), selected_atoms[1]);
    74   ASSERT( !selected_atoms[0]->IsBondedTo(WorldTime::getTime(), selected_atoms[1]),
    75       "BondRemoveAction::performCall() - removing bond in between "
    76       +toString(*selected_atoms[0])+" and "+toString(*selected_atoms[1])+" failed.");
     86  for (bondPairIds_t::const_iterator iter = bondPairIds.begin();
     87      iter != bondPairIds.end(); ++iter) {
     88    atom *firstatom = world.getAtom(AtomById(iter->first));
     89    atom *secondatom = world.getAtom(AtomById(iter->second));
     90    ASSERT((firstatom != NULL) && (secondatom != NULL),
     91        "BondAddAction::performCall() - at least one of the ids "
     92        +toString(iter->first)+" or "+toString(iter->second)+" is not present.");
     93    firstatom->removeBond(WorldTime::getTime(), secondatom);
     94    ASSERT( !firstatom->IsBondedTo(WorldTime::getTime(), secondatom),
     95      "BondAddAction::performCall() - adding bond in between "
     96      +toString(*firstatom)+" and "+toString(*secondatom)+" failed.");
     97  }
    7798
    7899  return ActionState::ptr(UndoState);
     
    82103  BondRemoveState *state = assert_cast<BondRemoveState*>(_state.get());
    83104
    84   // check whether bond already existed
    85   atom * const first = World::getInstance().getAtom(AtomById(state->firstId));
    86   atom * const second = World::getInstance().getAtom(AtomById(state->secondId));
    87   ASSERT((first != NULL) && (second != NULL),
    88       "BondRemoveAction::performUndo() - at least one of the ids "
    89       +toString(state->firstId)+" or "+toString(state->secondId)+" is not present.");
    90   if (!first->IsBondedTo(WorldTime::getTime(), second)) {
    91     first->addBond(WorldTime::getTime(), second);
    92   } else {
    93     ELOG(2, "There is already a bond in between "+toString(state->firstId)
    94         +" and "+toString(state->secondId)+".");
     105  World& world = World::getInstance();
     106  for (bondPairIds_t::const_iterator iter = state->bondPairIds.begin();
     107      iter != state->bondPairIds.end(); ++iter) {
     108    atom * const firstatom = world.getAtom(AtomById(iter->first));
     109    atom * const secondatom = world.getAtom(AtomById(iter->second));
     110    ASSERT((firstatom != NULL) && (secondatom != NULL),
     111        "BondAddAction::performCall() - at least one of the ids "
     112        +toString(iter->first)+" or "+toString(iter->second)+" is not present.");
     113    if (!firstatom->IsBondedTo(WorldTime::getTime(), secondatom)) {
     114      firstatom->addBond(WorldTime::getTime(), secondatom);
     115    } else {
     116      ELOG(2, "There is already a bond in between "+toString(iter->first)
     117          +" and "+toString(iter->second)+".");
     118    }
    95119  }
    96120
     
    101125  BondRemoveState *state = assert_cast<BondRemoveState*>(_state.get());
    102126
    103   // check whether bond already existed
    104   atom * const first = World::getInstance().getAtom(AtomById(state->firstId));
    105   atom * const second = World::getInstance().getAtom(AtomById(state->secondId));
    106   ASSERT((first != NULL) && (second != NULL),
    107       "BondRemoveAction::performRedo() - at least one of the ids "
    108       +toString(state->firstId)+" or "+toString(state->secondId)+" is not present.");
    109   if (first->IsBondedTo(WorldTime::getTime(), second)) {
    110     first->removeBond(WorldTime::getTime(), second);
    111   } else {
    112     ELOG(2, "There is no bond in between "+toString(state->firstId)
    113         +" and "+toString(state->secondId)+".");
     127  World& world = World::getInstance();
     128  for (bondPairIds_t::const_iterator iter = state->bondPairIds.begin();
     129      iter != state->bondPairIds.end(); ++iter) {
     130    atom *firstatom = world.getAtom(AtomById(iter->first));
     131    atom *secondatom = world.getAtom(AtomById(iter->second));
     132    ASSERT((firstatom != NULL) && (secondatom != NULL),
     133        "BondAddAction::performCall() - at least one of the ids "
     134        +toString(iter->first)+" or "+toString(iter->second)+" is not present.");
     135    if (firstatom->IsBondedTo(WorldTime::getTime(), secondatom)) {
     136      firstatom->removeBond(WorldTime::getTime(), secondatom);
     137    } else {
     138      ELOG(2, "There is no bond in between "+toString(iter->first)
     139          +" and "+toString(iter->second)+".");
     140    }
    114141  }
    115142
  • src/Actions/BondAction/BondRemoveAction.def

    r2fcef3 r88afc9  
    77
    88// all includes and forward declarations necessary for non-integral types below
     9#include "types.hpp"
     10#include <vector>
     11#include <utility>
     12
     13typedef std::vector<std::pair<atomId_t,atomId_t> > bondPairIds_t;
    914
    1015// i.e. there is an integer with variable name Z that can be found in
     
    1924#undef paramvalids
    2025
    21 #define statetypes (atomId_t)(atomId_t)
    22 #define statereferences (firstId)(secondId)
     26#define statetypes (bondPairIds_t)
     27#define statereferences (bondPairIds)
    2328
    2429// some defines for all the names, you may use ACTION, STATE and PARAMS
     
    2732#define MENUPOSITION 2
    2833#define ACTIONNAME Remove
    29 #define TOKEN "remove-bond"
     34#define TOKEN "remove-bonds"
    3035
    3136// finally the information stored in the ActionTrait specialization
    32 #define DESCRIPTION "remove the bond in between two selected atoms"
     37#define DESCRIPTION "remove all  bonds present between selected atoms"
    3338#undef SHORTFORM
Note: See TracChangeset for help on using the changeset viewer.