source: src/Actions/FragmentationAction/SubgraphDissectionAction.cpp@ 49c059

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 49c059 was 49c059, checked in by Frederik Heber <heber@…>, 14 years ago

Moved DepthFirstSearchAnalysis into functor in Graph/.

Smaller fixes:

TESTFIXES:

  • Property mode set to 100644
File size: 5.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 "CodePatterns/MemDebug.hpp"
21
22#include "Descriptors/AtomIdDescriptor.hpp"
23#include "Descriptors/MoleculeDescriptor.hpp"
24
25#include "atom.hpp"
26#include "Bond/bond.hpp"
27#include "config.hpp"
28#include "CodePatterns/Log.hpp"
29#include "CodePatterns/Verbose.hpp"
30#include "Graph/BondGraph.hpp"
31#include "Graph/DepthFirstSearchAnalysis.hpp"
32#include "molecule.hpp"
33#include "World.hpp"
34
35#include <iostream>
36#include <string>
37
38typedef std::map< moleculeId_t, std::vector<atomId_t> > MolAtomList;
39typedef std::map< atomId_t, atomId_t > AtomAtomList;
40
41using namespace std;
42
43#include "Actions/FragmentationAction/SubgraphDissectionAction.hpp"
44
45// and construct the stuff
46#include "SubgraphDissectionAction.def"
47#include "Action_impl_pre.hpp"
48/** =========== define the function ====================== */
49Action::state_ptr FragmentationSubgraphDissectionAction::performCall() {
50 // obtain information
51 getParametersfromValueStorage();
52
53
54 // first create stuff for undo state
55 LOG(0, "STATUS: Creating undo state.");
56 MolAtomList moleculelist;
57 vector<molecule *> allmolecules = World::getInstance().getAllMolecules();
58 for (vector<molecule *>::const_iterator moliter = allmolecules.begin(); moliter != allmolecules.end(); ++moliter) {
59 std::vector<atomId_t> atomlist;
60 atomlist.resize((*moliter)->size());
61 for (molecule::const_iterator atomiter = (*moliter)->begin(); atomiter != (*moliter)->end(); ++atomiter) {
62 atomlist.push_back((*atomiter)->getId());
63 }
64 moleculelist.insert( std::pair< moleculeId_t, std::vector<atomId_t> > ((*moliter)->getId(), atomlist));
65 }
66 FragmentationSubgraphDissectionState *UndoState = new FragmentationSubgraphDissectionState(moleculelist, params);
67
68 // 0a. remove all present molecules
69 LOG(0, "STATUS: Removing all present molecules.");
70 MoleculeListClass *molecules = World::getInstance().getMolecules();
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// const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
82// for(BondList::iterator BondRunner = ListOfBonds.begin();
83// !ListOfBonds.empty();
84// BondRunner = ListOfBonds.begin()) {
85// delete(*BondRunner);
86// }
87 mol->AddAtom(*AtomRunner);
88 }
89 }
90
91 // 1. create the bond structure of the single molecule
92 LOG(0, "STATUS: (Re-)constructing adjacency.");
93 if (mol->getBondCount() == 0) {
94 BondGraph *BG = World::getInstance().getBondGraph();
95 molecule::atomVector Set = mol->getAtomSet();
96 BG->CreateAdjacency(Set);
97// if (mol->getBondCount() == 0) {
98// World::getInstance().destroyMolecule(mol);
99// ELOG(1, "There are no bonds.");
100// return Action::failure;
101// }
102 }
103
104 // 2. scan for connected subgraphs
105 DepthFirstSearchAnalysis DFS;
106 DFS();
107 DFS.UpdateMoleculeStructure();
108 if (!World::getInstance().numMolecules()) {
109 //World::getInstance().destroyMolecule(mol);
110 DoeLog(1) && (eLog()<< Verbose(1) << "There are no atoms." << endl);
111 return Action::failure;
112 }
113
114 DoLog(1) && (Log() << Verbose(1) << "I scanned " << World::getInstance().numMolecules() << " molecules." << endl);
115
116 return Action::state_ptr(UndoState);
117}
118
119Action::state_ptr FragmentationSubgraphDissectionAction::performUndo(Action::state_ptr _state) {
120 FragmentationSubgraphDissectionState *state = assert_cast<FragmentationSubgraphDissectionState*>(_state.get());
121
122 {
123 // remove all present molecules
124 MoleculeListClass *molecules = World::getInstance().getMolecules();
125 vector<molecule *> allmolecules = World::getInstance().getAllMolecules();
126 for (vector<molecule *>::iterator MolRunner = allmolecules.begin(); MolRunner != allmolecules.end(); ++MolRunner) {
127 molecules->erase(*MolRunner);
128 World::getInstance().destroyMolecule(*MolRunner);
129 }
130 }
131
132 {
133 // construct the old state
134 MoleculeListClass *molecules = World::getInstance().getMolecules();
135 molecule *mol = NULL;
136 for (MolAtomList::const_iterator iter = state->moleculelist.begin(); iter != state->moleculelist.end(); ++iter) {
137 mol = World::getInstance().createMolecule();
138 if (mol->getId() != (*iter).first)
139 World::getInstance().changeMoleculeId(mol->getId(), (*iter).first);
140 for (std::vector<atomId_t>::const_iterator atomiter = (*iter).second.begin(); atomiter != (*iter).second.end(); ++atomiter) {
141 atom *Walker = World::getInstance().getAtom(AtomById(*atomiter));
142 mol->AddAtom(Walker);
143 }
144 molecules->insert(mol);
145 }
146 }
147
148 return Action::state_ptr(_state);
149}
150
151Action::state_ptr FragmentationSubgraphDissectionAction::performRedo(Action::state_ptr _state){
152 return performCall();
153}
154
155bool FragmentationSubgraphDissectionAction::canUndo() {
156 return true;
157}
158
159bool FragmentationSubgraphDissectionAction::shouldUndo() {
160 return true;
161}
162/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.