Changeset 9a8a6b
- Timestamp:
- Jan 31, 2016, 12:46:56 PM (9 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:
- 6a922b
- Parents:
- 08d9df7 (diff), ceaab1 (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. - Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/AtomAction/AddAction.cpp
r08d9df7 r9a8a6b 55 55 #include "Action_impl_pre.hpp" 56 56 /** =========== define the function ====================== */ 57 58 atom * getNewAtom(const AtomAddAction::AtomAddParameters &_params) 59 { 60 atom * first = World::getInstance().createAtom(); 61 first->setType(_params.elemental.get()); 62 first->setPosition(_params.position.get()); 63 64 return first; 65 } 66 67 std::vector<atomId_t> createAtoms( 68 const AtomAddAction::AtomAddParameters &_params, 69 std::vector<molecule *> &_molecules) 70 { 71 std::vector<atomId_t> ids; 72 if (!_molecules.empty()) { 73 if (_molecules.size() == 1) { 74 atom *first = getNewAtom(_params); 75 molecule *mol = *_molecules.begin(); 76 LOG(1, "Adding new atom with element " << first->getType()->getName() 77 << " at " << (first->getPosition()) << " to selected molecule " 78 << mol->getName()+"."); 79 mol->AddAtom(first); 80 ids.push_back(first->getId()); 81 } 82 } else { 83 atom *first = getNewAtom(_params); 84 molecule *mol = World::getInstance().createMolecule(); 85 mol->setName("none"); 86 mol->AddAtom(first); 87 LOG(1, "Adding new atom with element " << first->getType()->getName() 88 << " at " << (first->getPosition()) << " to new molecule."); 89 ids.push_back(first->getId()); 90 } 91 92 return ids; 93 } 94 57 95 ActionState::ptr AtomAddAction::performCall() { 58 96 // execute action 59 atom * first = World::getInstance().createAtom(); 60 first->setType(params.elemental.get()); 61 first->setPosition(params.position.get()); 62 LOG(1, "Adding new atom with element " << first->getType()->getName() << " at " << (first->getPosition()) << "."); 63 // TODO: remove when all of World's atoms are stored. 64 std::vector<molecule *> molecules = World::getInstance().getAllMolecules(); 65 if (!molecules.empty()) { 66 std::vector<molecule *>::iterator iter = molecules.begin(); 67 (*iter)->AddAtom(first); 68 } 69 return ActionState::ptr(new AtomAddState(first->getId(), params)); 97 std::vector<molecule *> molecules = World::getInstance().getSelectedMolecules(); 98 std::vector<atomId_t> ids = createAtoms(params, molecules); 99 100 if (molecules.size() > 1) 101 return Action::failure; 102 else 103 return ActionState::ptr(new AtomAddState(ids, params)); 70 104 } 71 105 … … 73 107 AtomAddState *state = assert_cast<AtomAddState*>(_state.get()); 74 108 75 LOG(1, "Removing atom with id " << state->id << "."); 76 World::getInstance().destroyAtom(state->id); 109 for (std::vector<atomId_t>::const_iterator iter = state->ids.begin(); 110 iter != state->ids.end(); ++iter) { 111 LOG(1, "Removing atom with id " << *iter << "."); 112 World::getInstance().destroyAtom(*iter); 113 } 77 114 78 115 return ActionState::ptr(_state); … … 82 119 AtomAddState *state = assert_cast<AtomAddState*>(_state.get()); 83 120 84 atom * first = World::getInstance().createAtom(); 85 first->setType(state->params.elemental.get()); 86 first->setPosition(state->params.position.get()); 87 LOG(1, "Re-adding new atom with element " << state->params.elemental.get()->getName() << " at " << state->params.position.get() << "."); 88 // TODO: remove when all of World's atoms are stored. 89 std::vector<molecule *> molecules = World::getInstance().getAllMolecules(); 90 if (!molecules.empty()) { 91 std::vector<molecule *>::iterator iter = molecules.begin(); 92 (*iter)->AddAtom(first); 121 std::vector<molecule *> molecules = World::getInstance().getSelectedMolecules(); 122 std::vector<atomId_t> newids = createAtoms(params, molecules); 123 124 if (newids.size() != state->ids.size()) { 125 STATUS("Could not recreate all atoms after undo."); 126 for (std::vector<atomId_t>::const_iterator iter = newids.begin(); iter != newids.end();++iter) 127 World::getInstance().destroyAtom(*iter); 128 return Action::failure; 93 129 } 94 if (first->getId() != state->id)95 if (!first->changeId(state->id)) {96 STATUS("Could not change atom id "+toString(first->getId())+"->"+toString(state->id)+".");97 return Action::failure;98 }99 130 100 return ActionState::ptr(_state); 131 std::vector<atomId_t>::const_iterator newiter = newids.begin(); 132 std::vector<atomId_t>::const_iterator olditer = state->ids.begin(); 133 bool status=true; 134 for (; newiter != newids.end(); ++newiter, ++olditer) { 135 atom * first = World::getInstance().getAtom(AtomById(*newiter)); 136 ASSERT( first != NULL, 137 "AtomAddAction::performRedo() - re-created atom not present?"); 138 if (first->getId() != *olditer) 139 if (!first->changeId(*olditer)) { 140 STATUS("Could not change atom id "+toString(first->getId())+"->"+toString(*olditer)+"."); 141 // remove all created atoms 142 for (std::vector<atomId_t>::const_iterator iter = state->ids.begin(); iter != olditer;++iter) 143 World::getInstance().destroyAtom(*iter); 144 olditer = state->ids.end(); 145 for (std::vector<atomId_t>::const_iterator iter = newiter; iter != newids.end();++iter) 146 World::getInstance().destroyAtom(*iter); 147 status = false; 148 break; 149 } 150 } 151 ASSERT( olditer == state->ids.end(), 152 "AtomAddAction::performRedo() - after all unequal amount of ids in new and old?"); 153 154 if (!status) { 155 return Action::failure; 156 } else 157 return ActionState::ptr(_state); 101 158 } 102 159 -
src/Actions/AtomAction/AddAction.def
r08d9df7 r9a8a6b 27 27 (BoxVectorValidator()) 28 28 29 #define statetypes ( const atomId_t)30 #define statereferences (id )29 #define statetypes (std::vector<atomId_t>) 30 #define statereferences (ids) 31 31 32 32 // some defines for all the names, you may use ACTION, STATE and PARAMS -
src/Atom/atom.cpp
r08d9df7 r9a8a6b 264 264 // first we move ourselves in the world 265 265 // the world lets us know if that succeeded 266 atomId_t oldid = id; 266 267 if(world->changeAtomId(id,newId,this)){ 267 268 OBSERVE; 268 269 id = newId; 270 if (mol != NULL) 271 mol->changeAtomId(oldid, newId); 269 272 NOTIFY(IndexChanged); 270 273 return true; -
src/molecule.cpp
r08d9df7 r9a8a6b 168 168 return false; 169 169 } 170 } 171 172 bool molecule::changeAtomId(int oldId, int newId) 173 { 174 OBSERVE; 175 if ((!atomIds.contains( oldId )) || (atomIds.contains( newId ))) 176 return false; 177 atomIds.erase( oldId ); 178 atomIds.insert( newId ); 179 return true; 170 180 } 171 181 -
src/molecule.hpp
r08d9df7 r9a8a6b 237 237 */ 238 238 bool changeAtomNr(int oldNr, int newNr, atom* target=0); 239 240 friend bool atom::changeId(atomId_t newId); 241 /** 242 * used when changing an ParticleInfo::Id. 243 * Note that this number is global (and the molecule uses it to know which atoms belong to it) 244 * 245 * @param oldId old Id 246 * @param newId new Id to set 247 * @return indicates wether the change could be done or not. 248 */ 249 bool changeAtomId(int oldId, int newId); 239 250 240 251 /** Updates the internal lookup fro local to global indices. -
tests/regression/Atoms/Add/post/test.pdb
r08d9df7 r9a8a6b 1 1 REMARK created by molecuilder on Wed Feb 2 18:06:07 2011 2 ATOM 1 H01 0 - 0010.000 10.000 10.000 0.00 0.00 H 02 ATOM 1 H01 0non 01 10.000 10.000 10.000 0.00 0.00 H 0 3 3 END
Note:
See TracChangeset
for help on using the changeset viewer.