1 | /*
|
---|
2 | * DepthFirstSearchAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 9, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/FragmentationAction/DepthFirstSearchAction.hpp"
|
---|
11 | #include "atom.hpp"
|
---|
12 | #include "bondgraph.hpp"
|
---|
13 | #include "config.hpp"
|
---|
14 | #include "log.hpp"
|
---|
15 | #include "molecule.hpp"
|
---|
16 | #include "Descriptors/MoleculeDescriptor.hpp"
|
---|
17 | #include "Descriptors/MoleculeIdDescriptor.hpp"
|
---|
18 | #include "stackclass.hpp"
|
---|
19 | #include "verbose.hpp"
|
---|
20 | #include "World.hpp"
|
---|
21 |
|
---|
22 | #include <iostream>
|
---|
23 | #include <string>
|
---|
24 |
|
---|
25 | using namespace std;
|
---|
26 |
|
---|
27 | #include "UIElements/UIFactory.hpp"
|
---|
28 | #include "UIElements/Dialog.hpp"
|
---|
29 | #include "UIElements/ValueStorage.hpp"
|
---|
30 |
|
---|
31 | const char FragmentationDepthFirstSearchAction::NAME[] = "depth-first-search";
|
---|
32 |
|
---|
33 | FragmentationDepthFirstSearchAction::FragmentationDepthFirstSearchAction() :
|
---|
34 | Action(NAME)
|
---|
35 | {}
|
---|
36 |
|
---|
37 | FragmentationDepthFirstSearchAction::~FragmentationDepthFirstSearchAction()
|
---|
38 | {}
|
---|
39 |
|
---|
40 | Dialog* FragmentationDepthFirstSearchAction::createDialog() {
|
---|
41 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
42 |
|
---|
43 | dialog->queryDouble(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
44 |
|
---|
45 | return dialog;
|
---|
46 | }
|
---|
47 |
|
---|
48 | Action::state_ptr FragmentationDepthFirstSearchAction::performCall() {
|
---|
49 | double distance;
|
---|
50 |
|
---|
51 | ValueStorage::getInstance().queryCurrentValue(NAME, distance);
|
---|
52 |
|
---|
53 | DoLog(1) && (Log() << Verbose(1) << "Depth-First-Search Analysis." << endl);
|
---|
54 | molecule * const mol = World::getInstance().getMolecule(MoleculeById(0));
|
---|
55 | MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis
|
---|
56 | int *MinimumRingSize = new int[mol->getAtomCount()];
|
---|
57 | atom **ListOfAtoms = NULL;
|
---|
58 | class StackClass<bond *> *BackEdgeStack = NULL;
|
---|
59 | class StackClass<bond *> *LocalBackEdgeStack = NULL;
|
---|
60 | mol->CreateAdjacencyList(distance, World::getInstance().getConfig()->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
|
---|
61 | Subgraphs = mol->DepthFirstSearchAnalysis(BackEdgeStack);
|
---|
62 | if (Subgraphs != NULL) {
|
---|
63 | int FragmentCounter = 0;
|
---|
64 | while (Subgraphs->next != NULL) {
|
---|
65 | Subgraphs = Subgraphs->next;
|
---|
66 | ListOfAtoms = NULL;
|
---|
67 | Subgraphs->FillBondStructureFromReference(mol, ListOfAtoms, false); // we want to keep the created ListOfLocalAtoms
|
---|
68 | LocalBackEdgeStack = new StackClass<bond *> (Subgraphs->Leaf->BondCount);
|
---|
69 | Subgraphs->Leaf->PickLocalBackEdges(ListOfAtoms, BackEdgeStack, LocalBackEdgeStack);
|
---|
70 | Subgraphs->Leaf->CyclicStructureAnalysis(LocalBackEdgeStack, MinimumRingSize);
|
---|
71 | delete(LocalBackEdgeStack);
|
---|
72 | delete(Subgraphs->previous);
|
---|
73 | delete[](ListOfAtoms); // and here we remove it
|
---|
74 | FragmentCounter++;
|
---|
75 | }
|
---|
76 | delete(Subgraphs);
|
---|
77 | }
|
---|
78 | delete(BackEdgeStack);
|
---|
79 | delete[](MinimumRingSize);
|
---|
80 | return Action::success;
|
---|
81 | }
|
---|
82 |
|
---|
83 | Action::state_ptr FragmentationDepthFirstSearchAction::performUndo(Action::state_ptr _state) {
|
---|
84 | return Action::success;
|
---|
85 | }
|
---|
86 |
|
---|
87 | Action::state_ptr FragmentationDepthFirstSearchAction::performRedo(Action::state_ptr _state){
|
---|
88 | return Action::success;
|
---|
89 | }
|
---|
90 |
|
---|
91 | bool FragmentationDepthFirstSearchAction::canUndo() {
|
---|
92 | return true;
|
---|
93 | }
|
---|
94 |
|
---|
95 | bool FragmentationDepthFirstSearchAction::shouldUndo() {
|
---|
96 | return true;
|
---|
97 | }
|
---|
98 |
|
---|
99 | const string FragmentationDepthFirstSearchAction::getName() {
|
---|
100 | return NAME;
|
---|
101 | }
|
---|