| 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 "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 **ListOfAtoms = 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 | ListOfAtoms = NULL;
|
|---|
| 61 | Subgraphs->FillBondStructureFromReference(mol, ListOfAtoms, false); // we want to keep the created ListOfLocalAtoms
|
|---|
| 62 | LocalBackEdgeStack = new StackClass<bond *> (Subgraphs->Leaf->BondCount);
|
|---|
| 63 | Subgraphs->Leaf->PickLocalBackEdges(ListOfAtoms, BackEdgeStack, LocalBackEdgeStack);
|
|---|
| 64 | Subgraphs->Leaf->CyclicStructureAnalysis(LocalBackEdgeStack, MinimumRingSize);
|
|---|
| 65 | delete(LocalBackEdgeStack);
|
|---|
| 66 | delete(Subgraphs->previous);
|
|---|
| 67 | delete[](ListOfAtoms); // and here we remove it
|
|---|
| 68 | FragmentCounter++;
|
|---|
| 69 | }
|
|---|
| 70 | delete(Subgraphs);
|
|---|
| 71 | }
|
|---|
| 72 | delete(BackEdgeStack);
|
|---|
| 73 | delete[](MinimumRingSize);
|
|---|
| 74 | delete dialog;
|
|---|
| 75 | return Action::success;
|
|---|
| 76 | } else {
|
|---|
| 77 | delete dialog;
|
|---|
| 78 | return Action::failure;
|
|---|
| 79 | }
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | Action::state_ptr FragmentationDepthFirstSearchAction::performUndo(Action::state_ptr _state) {
|
|---|
| 83 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
|---|
| 84 |
|
|---|
| 85 | return Action::failure;
|
|---|
| 86 | // string newName = state->mol->getName();
|
|---|
| 87 | // state->mol->setName(state->lastName);
|
|---|
| 88 | //
|
|---|
| 89 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | Action::state_ptr FragmentationDepthFirstSearchAction::performRedo(Action::state_ptr _state){
|
|---|
| 93 | return Action::failure;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | bool FragmentationDepthFirstSearchAction::canUndo() {
|
|---|
| 97 | return false;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | bool FragmentationDepthFirstSearchAction::shouldUndo() {
|
|---|
| 101 | return false;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | const string FragmentationDepthFirstSearchAction::getName() {
|
|---|
| 105 | return NAME;
|
|---|
| 106 | }
|
|---|