Changeset 7d8342


Ignore:
Timestamp:
Aug 28, 2010, 12:57:57 AM (14 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:
76ff55
Parents:
c449d9
git-author:
Frederik Heber <heber@…> (08/27/10 21:15:03)
git-committer:
Frederik Heber <heber@…> (08/28/10 00:57:57)
Message:

SubgraphDissectionAction does not delete bonds anymore and bugfixes regarding its redo.

  • Only creates BondGraph of system when no bonds are present.
  • redo was not working correctly due to wrong end state of performCall():
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/FragmentationAction/SubgraphDissectionAction.cpp

    rc449d9 r7d8342  
    3737
    3838typedef std::map< moleculeId_t, std::vector<atomId_t> > MolAtomList;
     39typedef std::map< atomId_t, atomId_t > AtomAtomList;
    3940
    4041using namespace std;
     
    5253  DoLog(1) && (Log() << Verbose(1) << "Dissecting molecular system into a set of disconnected subgraphs ... " << endl);
    5354
    54   // first create undo state
     55  // first create stuff for undo state
    5556  MolAtomList moleculelist;
    5657  vector<molecule *> allmolecules = World::getInstance().getAllMolecules();
     
    6566  FragmentationSubgraphDissectionState *UndoState = new FragmentationSubgraphDissectionState(moleculelist, params);
    6667
     68  // 0a. remove all present molecules
    6769  MoleculeListClass *molecules = World::getInstance().getMolecules();
    68   config * const configuration = World::getInstance().getConfig();
    69 
    70   // 0a. remove all present molecules
    7170  for (vector<molecule *>::iterator MolRunner = allmolecules.begin(); MolRunner != allmolecules.end(); ++MolRunner) {
    7271    molecules->erase(*MolRunner);
     
    7675  // 0b. remove all bonds and construct a molecule with all atoms
    7776  molecule *mol = World::getInstance().createMolecule();
     77  int BondCount = 0;
    7878  {
    7979    vector <atom *> allatoms = World::getInstance().getAllAtoms();
    8080    for(vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
    81       for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); !(*AtomRunner)->ListOfBonds.empty(); BondRunner = (*AtomRunner)->ListOfBonds.begin())
    82         delete(*BondRunner);
     81      BondCount += (*AtomRunner)->ListOfBonds.size();
     82//      for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); !(*AtomRunner)->ListOfBonds.empty(); BondRunner = (*AtomRunner)->ListOfBonds.begin())
     83//        delete(*BondRunner);
    8384      mol->AddAtom(*AtomRunner);
    8485    }
     
    8687
    8788  // 1. create the bond structure of the single molecule
    88   if (configuration->BG != NULL) {
    89     if (!configuration->BG->ConstructBondGraph(mol)) {
    90       World::getInstance().destroyMolecule(mol);
    91       DoeLog(1) && (eLog()<< Verbose(1) << "There are no bonds." << endl);
     89  if (BondCount == 0) {
     90    config * const configuration = World::getInstance().getConfig();
     91    if ((configuration->BG != NULL)) {
     92      if (!configuration->BG->ConstructBondGraph(mol)) {
     93        World::getInstance().destroyMolecule(mol);
     94        DoeLog(1) && (eLog()<< Verbose(1) << "There are no bonds." << endl);
     95        return Action::failure;
     96      }
     97    } else {
     98      DoeLog(1) && (eLog()<< Verbose(1) << "There is no BondGraph class present to create bonds." << endl);
    9299      return Action::failure;
    93100    }
    94   } else {
    95     DoeLog(1) && (eLog()<< Verbose(1) << "There is no BondGraph class present to create bonds." << endl);
    96     return Action::failure;
    97101  }
    98102
     
    107111    return Action::failure;
    108112  }
    109   int FragmentCounter = Subgraphs->next->Count();
     113
     114  //int FragmentCounter = Subgraphs->next->Count();
    110115
    111116  // TODO: When DepthFirstSearchAnalysis does not use AddCopyAtom() anymore, we don't need to delete all original atoms
    112117  {
    113     // 3a. copy the bonds
    114     atom **ListOfAtoms = NULL;
    115     Subgraphs->next->FillBondStructureFromReference(mol, ListOfAtoms, true);  // we want to keep the created ListOfLocalAtoms
    116     // 3b. correct fathers (AddCopyAtom sets father to original atom, which has been destroyed).
     118    {
     119      atom **ListOfAtoms = NULL;
     120      // 3a. re-create bond structure and insert molecules into general MoleculeListClass
     121      MoleculeLeafClass *MoleculeWalker = Subgraphs->next;
     122      while (MoleculeWalker->next != NULL) {
     123        ListOfAtoms = NULL;
     124        MoleculeWalker->FillBondStructureFromReference(mol, ListOfAtoms, true);  // we want to keep the created ListOfLocalAtoms
     125        molecules->insert(MoleculeWalker->Leaf);
     126        MoleculeWalker = MoleculeWalker->next;
     127      }
     128      molecules->insert(MoleculeWalker->Leaf);
     129      ListOfAtoms = NULL;
     130      MoleculeWalker->FillBondStructureFromReference(mol, ListOfAtoms, true);  // we want to keep the created ListOfLocalAtoms
     131    }
     132
     133    // 3b. store map from new to old ids for 3d
    117134    vector <atom *> allatoms = World::getInstance().getAllAtoms();
    118     for(vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
    119       (*AtomRunner)->father = *AtomRunner;
    120     }
    121     // 3c. destroy the original molecule
    122     for (molecule::iterator AtomRunner = mol->begin(); !mol->empty(); AtomRunner = mol->begin())
    123       World::getInstance().destroyAtom(*AtomRunner);
    124     World::getInstance().destroyMolecule(mol);
     135    AtomAtomList newtooldlist;
     136    for(vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner)
     137      if ((*AtomRunner)->father != (*AtomRunner))
     138        newtooldlist.insert( std::pair<atomId_t, atomId_t> ((*AtomRunner)->getId(),(*AtomRunner)->father->getId()) );
     139
     140    {
     141      // 3c. destroy the original molecule
     142      for (molecule::iterator AtomRunner = mol->begin(); !mol->empty(); AtomRunner = mol->begin())
     143        World::getInstance().destroyAtom(*AtomRunner);
     144      World::getInstance().destroyMolecule(mol);
     145    }
     146
     147    {
     148      // 3d. convert to old Ids and correct fathers (AddCopyAtom sets father to original atom, which has been destroyed).
     149      vector <atom *> allatoms = World::getInstance().getAllAtoms();
     150      for(vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
     151        World::getInstance().changeAtomId((*AtomRunner)->getId(), newtooldlist[(*AtomRunner)->getId()]);
     152        (*AtomRunner)->father = *AtomRunner;
     153      }
     154    }
    125155  }
    126156
     
    134164  MolecularWalker->Leaf = NULL;
    135165  delete(MolecularWalker);
    136   DoLog(1) && (Log() << Verbose(1) << "I scanned " << FragmentCounter << " molecules." << endl);
     166  DoLog(1) && (Log() << Verbose(1) << "I scanned " << molecules->ListOfMolecules.size() << " molecules." << endl);
    137167
    138168  return Action::state_ptr(UndoState);
     
    154184  {
    155185    // construct the old state
     186    MoleculeListClass *molecules = World::getInstance().getMolecules();
    156187    molecule *mol = NULL;
    157188    for (MolAtomList::const_iterator iter = state->moleculelist.begin(); iter != state->moleculelist.end(); ++iter) {
     
    159190      if (mol->getId() != (*iter).first)
    160191        World::getInstance().changeMoleculeId(mol->getId(), (*iter).first);
    161       for (std::vector<atomId_t>::const_iterator atomiter = (*iter).second.begin(); atomiter != (*iter).second.end(); ++atomiter)
    162         mol->AddAtom(World::getInstance().getAtom(AtomById(*atomiter)));
     192      for (std::vector<atomId_t>::const_iterator atomiter = (*iter).second.begin(); atomiter != (*iter).second.end(); ++atomiter) {
     193        atom *Walker = World::getInstance().getAtom(AtomById(*atomiter));
     194        mol->AddAtom(Walker);
     195      }
     196      molecules->insert(mol);
    163197    }
    164198  }
Note: See TracChangeset for help on using the changeset viewer.