Ignore:
Timestamp:
Feb 7, 2016, 5:57:03 AM (9 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:
918a6c
Parents:
5cf341
git-author:
Frederik Heber <heber@…> (10/28/15 12:09:43)
git-committer:
Frederik Heber <heber@…> (02/07/16 05:57:03)
Message:

AddAction and UndoRedoHelpers' AddAtomsFromAtomicInfo use recreate..().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/AtomAction/AddAction.cpp

    r5cf341 r8ad68b  
    6565}
    6666
     67atom * regetNewAtom(const AtomAddAction::AtomAddParameters &_params, const atomId_t _id)
     68{
     69  atom * first = World::getInstance().recreateAtom(_id);
     70  first->setType(_params.elemental.get());
     71  first->setPosition(_params.position.get());
     72
     73  return first;
     74}
     75
    6776std::vector<atomId_t> createAtoms(
    6877    const AtomAddAction::AtomAddParameters &_params,
     
    91100
    92101  return ids;
     102}
     103
     104std::vector<atomId_t> recreateAtoms(
     105    const AtomAddAction::AtomAddParameters &_params,
     106    const std::vector<atomId_t> &_ids,
     107    std::vector<molecule *> &_molecules)
     108{
     109  molecule *mol = NULL;
     110  if (!_molecules.empty()) {
     111    ASSERT (_molecules.size() == 1,
     112        "recreateAtoms() - more than one molecules given.");
     113    mol = *_molecules.begin();
     114  } else {
     115    mol = World::getInstance().createMolecule();
     116    mol->setName("none");
     117  }
     118  std::vector<atomId_t> newids;
     119  for (std::vector<atomId_t>::const_iterator iter = _ids.begin();
     120      iter != _ids.end(); ++iter) {
     121    atom *first = regetNewAtom(_params, *iter);
     122    if (first != NULL) {
     123      newids.push_back(first->getId());
     124      mol->AddAtom(first);
     125      LOG(1, "Adding new atom with element " << first->getType()->getName()
     126          << " at " << (first->getPosition()) << " to new molecule.");
     127    } else {
     128      ELOG(1, "Could not recreate atom with id " << *iter);
     129      break;
     130    }
     131  }
     132
     133  return newids;
    93134}
    94135
     
    120161
    121162  std::vector<molecule *> molecules = World::getInstance().getSelectedMolecules();
    122   std::vector<atomId_t> newids = createAtoms(params, molecules);
    123 
     163  std::vector<atomId_t> newids = recreateAtoms(state->params, state->ids, molecules);
    124164  if (newids.size() != state->ids.size()) {
    125165    STATUS("Could not recreate all atoms after undo.");
     
    128168    return Action::failure;
    129169  }
    130 
    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);
     170  return ActionState::ptr(_state);
    158171}
    159172
Note: See TracChangeset for help on using the changeset viewer.