Changeset 88afc9 for src/Actions/BondAction
- Timestamp:
- Feb 13, 2015, 9:18:04 AM (10 years ago)
- 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)
- Location:
- src/Actions/BondAction
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/BondAction/BondAddAction.cpp
r2fcef3 r88afc9 57 57 ActionState::ptr BondAddAction::performCall() { 58 58 // 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."); 61 62 return Action::failure; 62 63 } 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."); 66 79 return Action::failure; 67 80 } 68 81 69 82 // create undo 70 BondAddState *UndoState = new BondAddState( selected_atoms[0]->getId(), selected_atoms[1]->getId(), params);83 BondAddState *UndoState = new BondAddState(bondPairIds, params); 71 84 72 85 // 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), 75 95 "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 } 77 98 78 99 return ActionState::ptr(UndoState); … … 83 104 84 105 // 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 } 95 120 } 96 121 … … 102 127 103 128 // 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 } 114 143 } 115 144 -
src/Actions/BondAction/BondAddAction.def
r2fcef3 r88afc9 8 8 // all includes and forward declarations necessary for non-integral types below 9 9 #include "types.hpp" 10 #include <vector> 11 #include <utility> 12 13 typedef std::vector<std::pair<atomId_t,atomId_t> > bondPairIds_t; 10 14 11 15 // i.e. there is an integer with variable name Z that can be found in … … 20 24 #undef paramvalids 21 25 22 #define statetypes ( atomId_t)(atomId_t)23 #define statereferences ( firstId)(secondId)26 #define statetypes (bondPairIds_t) 27 #define statereferences (bondPairIds) 24 28 25 29 // some defines for all the names, you may use ACTION, STATE and PARAMS … … 28 32 #define MENUPOSITION 1 29 33 #define ACTIONNAME Add 30 #define TOKEN "add-bond "34 #define TOKEN "add-bonds" 31 35 32 36 // finally the information stored in the ActionTrait specialization 33 #define DESCRIPTION "add bond in between twoselected atoms"37 #define DESCRIPTION "add bonds in between any number of selected atoms" 34 38 #undef SHORTFORM -
src/Actions/BondAction/BondRemoveAction.cpp
r2fcef3 r88afc9 57 57 ActionState::ptr BondRemoveAction::performCall() { 58 58 // 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."); 61 62 return Action::failure; 62 63 } 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."); 66 79 return Action::failure; 67 80 } 68 81 69 82 // create undo 70 BondRemoveState *UndoState = new BondRemoveState( selected_atoms[0]->getId(), selected_atoms[1]->getId(), params);83 BondRemoveState *UndoState = new BondRemoveState(bondPairIds, params); 71 84 72 85 // 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 } 77 98 78 99 return ActionState::ptr(UndoState); … … 82 103 BondRemoveState *state = assert_cast<BondRemoveState*>(_state.get()); 83 104 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 } 95 119 } 96 120 … … 101 125 BondRemoveState *state = assert_cast<BondRemoveState*>(_state.get()); 102 126 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 } 114 141 } 115 142 -
src/Actions/BondAction/BondRemoveAction.def
r2fcef3 r88afc9 7 7 8 8 // all includes and forward declarations necessary for non-integral types below 9 #include "types.hpp" 10 #include <vector> 11 #include <utility> 12 13 typedef std::vector<std::pair<atomId_t,atomId_t> > bondPairIds_t; 9 14 10 15 // i.e. there is an integer with variable name Z that can be found in … … 19 24 #undef paramvalids 20 25 21 #define statetypes ( atomId_t)(atomId_t)22 #define statereferences ( firstId)(secondId)26 #define statetypes (bondPairIds_t) 27 #define statereferences (bondPairIds) 23 28 24 29 // some defines for all the names, you may use ACTION, STATE and PARAMS … … 27 32 #define MENUPOSITION 2 28 33 #define ACTIONNAME Remove 29 #define TOKEN "remove-bond "34 #define TOKEN "remove-bonds" 30 35 31 36 // finally the information stored in the ActionTrait specialization 32 #define DESCRIPTION "remove the bond in between twoselected atoms"37 #define DESCRIPTION "remove all bonds present between selected atoms" 33 38 #undef SHORTFORM
Note:
See TracChangeset
for help on using the changeset viewer.