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 "CommandLineParser.hpp"
|
---|
12 | #include "atom.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 "Actions/MapOfActions.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 | Action::state_ptr FragmentationDepthFirstSearchAction::performCall() {
|
---|
41 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
42 | double distance;
|
---|
43 |
|
---|
44 | dialog->queryDouble(NAME, &distance, MapOfActions::getInstance().getDescription(NAME));
|
---|
45 |
|
---|
46 | if(dialog->display()) {
|
---|
47 | DoLog(1) && (Log() << Verbose(1) << "Depth-First-Search Analysis." << endl);
|
---|
48 | molecule * const mol = World::getInstance().getMolecule(MoleculeById(0));
|
---|
49 | MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis
|
---|
50 | int *MinimumRingSize = new int[mol->getAtomCount()];
|
---|
51 | atom ***ListOfLocalAtoms = NULL;
|
---|
52 | class StackClass<bond *> *BackEdgeStack = NULL;
|
---|
53 | class StackClass<bond *> *LocalBackEdgeStack = NULL;
|
---|
54 | mol->CreateAdjacencyList(distance, World::getInstance().getConfig()->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
|
---|
55 | Subgraphs = mol->DepthFirstSearchAnalysis(BackEdgeStack);
|
---|
56 | if (Subgraphs != NULL) {
|
---|
57 | int FragmentCounter = 0;
|
---|
58 | while (Subgraphs->next != NULL) {
|
---|
59 | Subgraphs = Subgraphs->next;
|
---|
60 | Subgraphs->FillBondStructureFromReference(mol, FragmentCounter, ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms
|
---|
61 | LocalBackEdgeStack = new StackClass<bond *> (Subgraphs->Leaf->BondCount);
|
---|
62 | Subgraphs->Leaf->PickLocalBackEdges(ListOfLocalAtoms[FragmentCounter], BackEdgeStack, LocalBackEdgeStack);
|
---|
63 | Subgraphs->Leaf->CyclicStructureAnalysis(LocalBackEdgeStack, MinimumRingSize);
|
---|
64 | delete(LocalBackEdgeStack);
|
---|
65 | delete(Subgraphs->previous);
|
---|
66 | FragmentCounter++;
|
---|
67 | }
|
---|
68 | delete(Subgraphs);
|
---|
69 | for (int i=0;i<FragmentCounter;i++)
|
---|
70 | delete[](ListOfLocalAtoms[i]);
|
---|
71 | delete[](ListOfLocalAtoms);
|
---|
72 | }
|
---|
73 | delete(BackEdgeStack);
|
---|
74 | delete[](MinimumRingSize);
|
---|
75 | delete dialog;
|
---|
76 | return Action::success;
|
---|
77 | } else {
|
---|
78 | delete dialog;
|
---|
79 | return Action::failure;
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | Action::state_ptr FragmentationDepthFirstSearchAction::performUndo(Action::state_ptr _state) {
|
---|
84 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
85 |
|
---|
86 | return Action::failure;
|
---|
87 | // string newName = state->mol->getName();
|
---|
88 | // state->mol->setName(state->lastName);
|
---|
89 | //
|
---|
90 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
91 | }
|
---|
92 |
|
---|
93 | Action::state_ptr FragmentationDepthFirstSearchAction::performRedo(Action::state_ptr _state){
|
---|
94 | return Action::failure;
|
---|
95 | }
|
---|
96 |
|
---|
97 | bool FragmentationDepthFirstSearchAction::canUndo() {
|
---|
98 | return false;
|
---|
99 | }
|
---|
100 |
|
---|
101 | bool FragmentationDepthFirstSearchAction::shouldUndo() {
|
---|
102 | return false;
|
---|
103 | }
|
---|
104 |
|
---|
105 | const string FragmentationDepthFirstSearchAction::getName() {
|
---|
106 | return NAME;
|
---|
107 | }
|
---|