- Timestamp:
- Aug 12, 2010, 4:34:46 PM (14 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:
- ae959a
- Parents:
- a7a087
- git-author:
- Frederik Heber <heber@…> (08/12/10 16:32:32)
- git-committer:
- Frederik Heber <heber@…> (08/12/10 16:34:46)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/FragmentationAction/SubgraphDissectionAction.cpp
ra7a087 rfaa1c9 15 15 #include "Actions/FragmentationAction/SubgraphDissectionAction.hpp" 16 16 #include "Actions/ActionRegistry.hpp" 17 #include "Descriptors/AtomIdDescriptor.hpp" 17 18 #include "Descriptors/MoleculeDescriptor.hpp" 18 19 … … 22 23 #include "config.hpp" 23 24 #include "Helpers/Log.hpp" 25 #include "Helpers/Verbose.hpp" 24 26 #include "molecule.hpp" 25 27 #include "stackclass.hpp" 26 #include "verbose.hpp"27 28 #include "World.hpp" 28 29 … … 35 36 #include "UIElements/Dialog.hpp" 36 37 #include "Actions/ValueStorage.hpp" 38 39 // memento to remember the state when undoing 40 41 typedef std::map< moleculeId_t, std::vector<atomId_t> > MolAtomList; 42 43 class FragmentationSubgraphDissectionState : public ActionState { 44 public: 45 FragmentationSubgraphDissectionState(const MolAtomList &_moleculelist) : 46 moleculelist(_moleculelist) 47 {} 48 MolAtomList moleculelist; 49 }; 37 50 38 51 const char FragmentationSubgraphDissectionAction::NAME[] = "subgraph-dissect"; … … 63 76 DoLog(1) && (Log() << Verbose(1) << "Dissecting molecular system into a set of disconnected subgraphs ... " << endl); 64 77 78 // first create undo state 79 MolAtomList moleculelist; 80 vector<molecule *> allmolecules = World::getInstance().getAllMolecules(); 81 for (vector<molecule *>::const_iterator moliter = allmolecules.begin(); moliter != allmolecules.end(); ++moliter) { 82 std::vector<atomId_t> atomlist; 83 atomlist.resize((*moliter)->size()); 84 for (molecule::const_iterator atomiter = (*moliter)->begin(); atomiter != (*moliter)->end(); ++atomiter) { 85 atomlist.push_back((*atomiter)->getId()); 86 } 87 moleculelist.insert( std::pair< moleculeId_t, std::vector<atomId_t> > ((*moliter)->getId(), atomlist)); 88 } 89 FragmentationSubgraphDissectionState *UndoState = new FragmentationSubgraphDissectionState(moleculelist); 90 65 91 MoleculeListClass *molecules = World::getInstance().getMolecules(); 66 92 config * const configuration = World::getInstance().getConfig(); 67 93 68 94 // 0a. remove all present molecules 69 vector<molecule *> allmolecules = World::getInstance().getAllMolecules();70 95 for (vector<molecule *>::iterator MolRunner = allmolecules.begin(); MolRunner != allmolecules.end(); ++MolRunner) { 71 96 molecules->erase(*MolRunner); … … 75 100 // 0b. remove all bonds and construct a molecule with all atoms 76 101 molecule *mol = World::getInstance().createMolecule(); 77 vector <atom *> allatoms = World::getInstance().getAllAtoms(); 78 for(vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) { 79 for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); !(*AtomRunner)->ListOfBonds.empty(); BondRunner = (*AtomRunner)->ListOfBonds.begin()) 80 delete(*BondRunner); 81 mol->AddAtom(*AtomRunner); 102 { 103 vector <atom *> allatoms = World::getInstance().getAllAtoms(); 104 for(vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) { 105 for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); !(*AtomRunner)->ListOfBonds.empty(); BondRunner = (*AtomRunner)->ListOfBonds.begin()) 106 delete(*BondRunner); 107 mol->AddAtom(*AtomRunner); 108 } 82 109 } 83 110 … … 100 127 delete(BackEdgeStack); 101 128 if ((Subgraphs == NULL) || (Subgraphs->next == NULL)) { 102 World::getInstance().destroyMolecule(mol);129 //World::getInstance().destroyMolecule(mol); 103 130 DoeLog(1) && (eLog()<< Verbose(1) << "There are no atoms." << endl); 104 131 return Action::failure; 105 132 } 106 <<<<<<< HEAD 107 108 // 3. dissect (the following construct is needed to have the atoms not in the order of the DFS, but in 109 // the original one as parsed in) 110 // TODO: Optimize this, when molecules just contain pointer list of global atoms! 111 112 // 4a. create array of molecules to fill 113 const int MolCount = Subgraphs->next->Count(); 114 char number[MAXSTRINGSIZE]; 115 molecule **moleculelist = new molecule *[MolCount]; 116 MoleculeLeafClass *MolecularWalker = Subgraphs; 117 for (int i=0;i<MolCount;i++) { 118 MolecularWalker = MolecularWalker->next; 119 moleculelist[i] = World::getInstance().createMolecule(); 120 moleculelist[i]->ActiveFlag = true; 121 strncpy(moleculelist[i]->name, mol->name, MAXSTRINGSIZE); 122 if (MolCount > 1) { 123 sprintf(number, "-%d", i+1); 124 strncat(moleculelist[i]->name, number, MAXSTRINGSIZE - strlen(mol->name) - 1); 125 } 126 DoLog(1) && (Log() << Verbose(1) << "MolName is " << moleculelist[i]->name << ", id is " << moleculelist[i]->getId() << endl); 127 for (molecule::iterator iter = MolecularWalker->Leaf->begin(); iter != MolecularWalker->Leaf->end(); ++iter) { 128 DoLog(1) && (Log() << Verbose(1) << **iter << endl); 129 } 130 molecules->insert(moleculelist[i]); 131 } 132 133 // 4b. create and fill map of which atom is associated to which connected molecule (note, counting starts at 1) 134 int FragmentCounter = 0; 135 map<int, atom *> AtomToFragmentMap; 136 MolecularWalker = Subgraphs; 137 while (MolecularWalker->next != NULL) { 138 MolecularWalker = MolecularWalker->next; 139 for (molecule::iterator iter = MolecularWalker->Leaf->begin(); !MolecularWalker->Leaf->empty(); iter = MolecularWalker->Leaf->begin()) { 140 atom * Walker = *iter; 141 DoLog(1) && (Log() << Verbose(1) << "Re-linking " << Walker << "..." << endl); 142 MolecularWalker->Leaf->erase(iter); 143 moleculelist[FragmentCounter]->AddAtom(Walker); // counting starts at 1 144 } 145 FragmentCounter++; 146 } 147 // TODO: When DepthFirstSearchAnalysis does not use AddCopyAtom() anymore, we don't need to delete all original atoms. 148 // 4d. destroy the original molecule 149 ======= 150 int FragmentCounter = Subgraphs->Count(); 133 int FragmentCounter = Subgraphs->next->Count(); 151 134 152 135 // TODO: When DepthFirstSearchAnalysis does not use AddCopyAtom() anymore, we don't need to delete all original atoms 153 // 3. destroy the original molecule154 >>>>>>> Merged MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs() into FragmenationSubgraphDissectionAction. 155 for (molecule::iterator AtomRunner = mol->begin(); !mol->empty(); AtomRunner = mol->begin())156 World::getInstance().destroyAtom(*AtomRunner);157 World::getInstance().destroyMolecule(mol);158 159 <<<<<<< HEAD 160 // 4d. we don't need to redo bonds, as they are connected subgraphs and still maintain their ListOfBonds, but we have to remove them from first..last list161 // TODO: check whether this is really not needed anymore162 // 4e. free Leafs163 MolecularWalker = Subgraphs;164 ======= 136 { 137 // 3a. destroy the original molecule 138 for (molecule::iterator AtomRunner = mol->begin(); !mol->empty(); AtomRunner = mol->begin()) 139 World::getInstance().destroyAtom(*AtomRunner); 140 World::getInstance().destroyMolecule(mol); 141 // 3b. correct fathers (AddCopyAtom sets father to original atom, which has been destroyed). 142 vector <atom *> allatoms = World::getInstance().getAllAtoms(); 143 for(vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) { 144 (*AtomRunner)->father = *AtomRunner; 145 } 146 } 147 165 148 // 4. free Leafs 166 149 MoleculeLeafClass *MolecularWalker = Subgraphs; 167 >>>>>>> Merged MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs() into FragmenationSubgraphDissectionAction.168 150 while (MolecularWalker->next != NULL) { 151 MolecularWalker->Leaf = NULL; 169 152 MolecularWalker = MolecularWalker->next; 170 153 delete(MolecularWalker->previous); 171 154 } 155 MolecularWalker->Leaf = NULL; 172 156 delete(MolecularWalker); 173 <<<<<<< HEAD174 delete[](moleculelist);175 =======176 >>>>>>> Merged MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs() into FragmenationSubgraphDissectionAction.177 157 DoLog(1) && (Log() << Verbose(1) << "I scanned " << FragmentCounter << " molecules." << endl); 178 158 179 return Action::s uccess;159 return Action::state_ptr(UndoState); 180 160 } 181 161 182 162 Action::state_ptr FragmentationSubgraphDissectionAction::performUndo(Action::state_ptr _state) { 183 // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get()); 184 185 return Action::failure; 186 // string newName = state->mol->getName(); 187 // state->mol->setName(state->lastName); 188 // 189 // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName)); 163 FragmentationSubgraphDissectionState *state = assert_cast<FragmentationSubgraphDissectionState*>(_state.get()); 164 165 { 166 // remove all present molecules 167 MoleculeListClass *molecules = World::getInstance().getMolecules(); 168 vector<molecule *> allmolecules = World::getInstance().getAllMolecules(); 169 for (vector<molecule *>::iterator MolRunner = allmolecules.begin(); MolRunner != allmolecules.end(); ++MolRunner) { 170 molecules->erase(*MolRunner); 171 World::getInstance().destroyMolecule(*MolRunner); 172 } 173 } 174 175 { 176 // construct the old state 177 molecule *mol = NULL; 178 for (MolAtomList::const_iterator iter = state->moleculelist.begin(); iter != state->moleculelist.end(); ++iter) { 179 mol = World::getInstance().createMolecule(); 180 if (mol->getId() != (*iter).first) 181 World::getInstance().changeMoleculeId(mol->getId(), (*iter).first); 182 for (std::vector<atomId_t>::const_iterator atomiter = (*iter).second.begin(); atomiter != (*iter).second.end(); ++atomiter) 183 mol->AddAtom(World::getInstance().getAtom(AtomById(*atomiter))); 184 } 185 } 186 187 return Action::state_ptr(_state); 190 188 } 191 189 192 190 Action::state_ptr FragmentationSubgraphDissectionAction::performRedo(Action::state_ptr _state){ 193 return Action::failure;191 return performCall(); 194 192 } 195 193 196 194 bool FragmentationSubgraphDissectionAction::canUndo() { 197 return false;195 return true; 198 196 } 199 197 200 198 bool FragmentationSubgraphDissectionAction::shouldUndo() { 201 return false;199 return true; 202 200 } 203 201
Note:
See TracChangeset
for help on using the changeset viewer.