[97ebf8] | 1 | /*
|
---|
| 2 | * DepthFirstSearchAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 9, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[112b09] | 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
[97ebf8] | 10 | #include "Actions/FragmentationAction/DepthFirstSearchAction.hpp"
|
---|
| 11 | #include "atom.hpp"
|
---|
[a3fded] | 12 | #include "bondgraph.hpp"
|
---|
[97ebf8] | 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"
|
---|
[f394a6] | 29 | #include "UIElements/ValueStorage.hpp"
|
---|
[97ebf8] | 30 |
|
---|
| 31 | const char FragmentationDepthFirstSearchAction::NAME[] = "depth-first-search";
|
---|
| 32 |
|
---|
| 33 | FragmentationDepthFirstSearchAction::FragmentationDepthFirstSearchAction() :
|
---|
| 34 | Action(NAME)
|
---|
| 35 | {}
|
---|
| 36 |
|
---|
| 37 | FragmentationDepthFirstSearchAction::~FragmentationDepthFirstSearchAction()
|
---|
| 38 | {}
|
---|
| 39 |
|
---|
[f394a6] | 40 | Dialog* FragmentationDepthFirstSearchAction::createDialog() {
|
---|
[97ebf8] | 41 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
[f394a6] | 42 |
|
---|
| 43 | dialog->queryDouble(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 44 |
|
---|
| 45 | return dialog;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | Action::state_ptr FragmentationDepthFirstSearchAction::performCall() {
|
---|
[97ebf8] | 49 | double distance;
|
---|
| 50 |
|
---|
[f394a6] | 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++;
|
---|
[97ebf8] | 75 | }
|
---|
[f394a6] | 76 | delete(Subgraphs);
|
---|
[97ebf8] | 77 | }
|
---|
[f394a6] | 78 | delete(BackEdgeStack);
|
---|
| 79 | delete[](MinimumRingSize);
|
---|
| 80 | return Action::success;
|
---|
[97ebf8] | 81 | }
|
---|
| 82 |
|
---|
| 83 | Action::state_ptr FragmentationDepthFirstSearchAction::performUndo(Action::state_ptr _state) {
|
---|
[f394a6] | 84 | return Action::success;
|
---|
[97ebf8] | 85 | }
|
---|
| 86 |
|
---|
| 87 | Action::state_ptr FragmentationDepthFirstSearchAction::performRedo(Action::state_ptr _state){
|
---|
[f394a6] | 88 | return Action::success;
|
---|
[97ebf8] | 89 | }
|
---|
| 90 |
|
---|
| 91 | bool FragmentationDepthFirstSearchAction::canUndo() {
|
---|
[f394a6] | 92 | return true;
|
---|
[97ebf8] | 93 | }
|
---|
| 94 |
|
---|
| 95 | bool FragmentationDepthFirstSearchAction::shouldUndo() {
|
---|
[f394a6] | 96 | return true;
|
---|
[97ebf8] | 97 | }
|
---|
| 98 |
|
---|
| 99 | const string FragmentationDepthFirstSearchAction::getName() {
|
---|
| 100 | return NAME;
|
---|
| 101 | }
|
---|