source: src/Actions/FragmentationAction/SubgraphDissectionAction.cpp@ b5cf6c

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
Last change on this file since b5cf6c was 1fd675, checked in by Frederik Heber <heber@…>, 14 years ago

All Actions are converted to the new macro framework.

  • included all three values that have been used to create or convert the files
    • createdef.sh
    • createCpp.sh
    • createHeader.sh
  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * SubgraphDissectionAction.cpp
10 *
11 * Created on: May 9, 2010
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "Helpers/MemDebug.hpp"
21
22#include "Descriptors/AtomIdDescriptor.hpp"
23#include "Descriptors/MoleculeDescriptor.hpp"
24
25#include "atom.hpp"
26#include "bond.hpp"
27#include "bondgraph.hpp"
28#include "config.hpp"
29#include "Helpers/Log.hpp"
30#include "Helpers/Verbose.hpp"
31#include "molecule.hpp"
32#include "stackclass.hpp"
33#include "World.hpp"
34
35#include <iostream>
36#include <string>
37
38typedef std::map< moleculeId_t, std::vector<atomId_t> > MolAtomList;
39
40using namespace std;
41
42#include "Actions/FragmentationAction/SubgraphDissectionAction.hpp"
43
44// and construct the stuff
45#include "SubgraphDissectionAction.def"
46#include "Action_impl_pre.hpp"
47/** =========== define the function ====================== */
48Action::state_ptr FragmentationSubgraphDissectionAction::performCall() {
49 // obtain information
50 getParametersfromValueStorage();
51
52 DoLog(1) && (Log() << Verbose(1) << "Dissecting molecular system into a set of disconnected subgraphs ... " << endl);
53
54 // first create undo state
55 MolAtomList moleculelist;
56 vector<molecule *> allmolecules = World::getInstance().getAllMolecules();
57 for (vector<molecule *>::const_iterator moliter = allmolecules.begin(); moliter != allmolecules.end(); ++moliter) {
58 std::vector<atomId_t> atomlist;
59 atomlist.resize((*moliter)->size());
60 for (molecule::const_iterator atomiter = (*moliter)->begin(); atomiter != (*moliter)->end(); ++atomiter) {
61 atomlist.push_back((*atomiter)->getId());
62 }
63 moleculelist.insert( std::pair< moleculeId_t, std::vector<atomId_t> > ((*moliter)->getId(), atomlist));
64 }
65 FragmentationSubgraphDissectionState *UndoState = new FragmentationSubgraphDissectionState(moleculelist, params);
66
67 MoleculeListClass *molecules = World::getInstance().getMolecules();
68 config * const configuration = World::getInstance().getConfig();
69
70 // 0a. remove all present molecules
71 for (vector<molecule *>::iterator MolRunner = allmolecules.begin(); MolRunner != allmolecules.end(); ++MolRunner) {
72 molecules->erase(*MolRunner);
73 World::getInstance().destroyMolecule(*MolRunner);
74 }
75
76 // 0b. remove all bonds and construct a molecule with all atoms
77 molecule *mol = World::getInstance().createMolecule();
78 {
79 vector <atom *> allatoms = World::getInstance().getAllAtoms();
80 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);
83 mol->AddAtom(*AtomRunner);
84 }
85 }
86
87 // 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);
92 return Action::failure;
93 }
94 } else {
95 DoeLog(1) && (eLog()<< Verbose(1) << "There is no BondGraph class present to create bonds." << endl);
96 return Action::failure;
97 }
98
99 // 2. scan for connected subgraphs
100 MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis
101 class StackClass<bond *> *BackEdgeStack = NULL;
102 Subgraphs = mol->DepthFirstSearchAnalysis(BackEdgeStack);
103 delete(BackEdgeStack);
104 if ((Subgraphs == NULL) || (Subgraphs->next == NULL)) {
105 //World::getInstance().destroyMolecule(mol);
106 DoeLog(1) && (eLog()<< Verbose(1) << "There are no atoms." << endl);
107 return Action::failure;
108 }
109 int FragmentCounter = Subgraphs->next->Count();
110
111 // TODO: When DepthFirstSearchAnalysis does not use AddCopyAtom() anymore, we don't need to delete all original atoms
112 {
113 // 3a. destroy the original molecule
114 for (molecule::iterator AtomRunner = mol->begin(); !mol->empty(); AtomRunner = mol->begin())
115 World::getInstance().destroyAtom(*AtomRunner);
116 World::getInstance().destroyMolecule(mol);
117 // 3b. correct fathers (AddCopyAtom sets father to original atom, which has been destroyed).
118 vector <atom *> allatoms = World::getInstance().getAllAtoms();
119 for(vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
120 (*AtomRunner)->father = *AtomRunner;
121 }
122 }
123
124 // 4. free Leafs
125 MoleculeLeafClass *MolecularWalker = Subgraphs;
126 while (MolecularWalker->next != NULL) {
127 MolecularWalker->Leaf = NULL;
128 MolecularWalker = MolecularWalker->next;
129 delete(MolecularWalker->previous);
130 }
131 MolecularWalker->Leaf = NULL;
132 delete(MolecularWalker);
133 DoLog(1) && (Log() << Verbose(1) << "I scanned " << FragmentCounter << " molecules." << endl);
134
135 return Action::state_ptr(UndoState);
136}
137
138Action::state_ptr FragmentationSubgraphDissectionAction::performUndo(Action::state_ptr _state) {
139 FragmentationSubgraphDissectionState *state = assert_cast<FragmentationSubgraphDissectionState*>(_state.get());
140
141 {
142 // remove all present molecules
143 MoleculeListClass *molecules = World::getInstance().getMolecules();
144 vector<molecule *> allmolecules = World::getInstance().getAllMolecules();
145 for (vector<molecule *>::iterator MolRunner = allmolecules.begin(); MolRunner != allmolecules.end(); ++MolRunner) {
146 molecules->erase(*MolRunner);
147 World::getInstance().destroyMolecule(*MolRunner);
148 }
149 }
150
151 {
152 // construct the old state
153 molecule *mol = NULL;
154 for (MolAtomList::const_iterator iter = state->moleculelist.begin(); iter != state->moleculelist.end(); ++iter) {
155 mol = World::getInstance().createMolecule();
156 if (mol->getId() != (*iter).first)
157 World::getInstance().changeMoleculeId(mol->getId(), (*iter).first);
158 for (std::vector<atomId_t>::const_iterator atomiter = (*iter).second.begin(); atomiter != (*iter).second.end(); ++atomiter)
159 mol->AddAtom(World::getInstance().getAtom(AtomById(*atomiter)));
160 }
161 }
162
163 return Action::state_ptr(_state);
164}
165
166Action::state_ptr FragmentationSubgraphDissectionAction::performRedo(Action::state_ptr _state){
167 return performCall();
168}
169
170bool FragmentationSubgraphDissectionAction::canUndo() {
171 return true;
172}
173
174bool FragmentationSubgraphDissectionAction::shouldUndo() {
175 return true;
176}
177
178const string FragmentationSubgraphDissectionAction::getName() {
179 return NAME;
180}
181/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.