[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"
|
---|
| 12 | #include "config.hpp"
|
---|
| 13 | #include "log.hpp"
|
---|
| 14 | #include "molecule.hpp"
|
---|
| 15 | #include "Descriptors/MoleculeDescriptor.hpp"
|
---|
| 16 | #include "Descriptors/MoleculeIdDescriptor.hpp"
|
---|
| 17 | #include "stackclass.hpp"
|
---|
| 18 | #include "verbose.hpp"
|
---|
| 19 | #include "World.hpp"
|
---|
| 20 |
|
---|
| 21 | #include <iostream>
|
---|
| 22 | #include <string>
|
---|
| 23 |
|
---|
| 24 | using namespace std;
|
---|
| 25 |
|
---|
| 26 | #include "UIElements/UIFactory.hpp"
|
---|
| 27 | #include "UIElements/Dialog.hpp"
|
---|
| 28 | #include "Actions/MapOfActions.hpp"
|
---|
| 29 |
|
---|
| 30 | const char FragmentationDepthFirstSearchAction::NAME[] = "depth-first-search";
|
---|
| 31 |
|
---|
| 32 | FragmentationDepthFirstSearchAction::FragmentationDepthFirstSearchAction() :
|
---|
| 33 | Action(NAME)
|
---|
| 34 | {}
|
---|
| 35 |
|
---|
| 36 | FragmentationDepthFirstSearchAction::~FragmentationDepthFirstSearchAction()
|
---|
| 37 | {}
|
---|
| 38 |
|
---|
| 39 | Action::state_ptr FragmentationDepthFirstSearchAction::performCall() {
|
---|
| 40 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
| 41 | double distance;
|
---|
| 42 |
|
---|
| 43 | dialog->queryDouble(NAME, &distance, MapOfActions::getInstance().getDescription(NAME));
|
---|
| 44 |
|
---|
| 45 | if(dialog->display()) {
|
---|
| 46 | DoLog(1) && (Log() << Verbose(1) << "Depth-First-Search Analysis." << endl);
|
---|
| 47 | molecule * const mol = World::getInstance().getMolecule(MoleculeById(0));
|
---|
| 48 | MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis
|
---|
[1024cb] | 49 | int *MinimumRingSize = new int[mol->getAtomCount()];
|
---|
[97ebf8] | 50 | atom ***ListOfLocalAtoms = NULL;
|
---|
| 51 | class StackClass<bond *> *BackEdgeStack = NULL;
|
---|
| 52 | class StackClass<bond *> *LocalBackEdgeStack = NULL;
|
---|
| 53 | mol->CreateAdjacencyList(distance, World::getInstance().getConfig()->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
|
---|
| 54 | Subgraphs = mol->DepthFirstSearchAnalysis(BackEdgeStack);
|
---|
| 55 | if (Subgraphs != NULL) {
|
---|
| 56 | int FragmentCounter = 0;
|
---|
| 57 | while (Subgraphs->next != NULL) {
|
---|
| 58 | Subgraphs = Subgraphs->next;
|
---|
| 59 | Subgraphs->FillBondStructureFromReference(mol, FragmentCounter, ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms
|
---|
| 60 | LocalBackEdgeStack = new StackClass<bond *> (Subgraphs->Leaf->BondCount);
|
---|
| 61 | Subgraphs->Leaf->PickLocalBackEdges(ListOfLocalAtoms[FragmentCounter], BackEdgeStack, LocalBackEdgeStack);
|
---|
| 62 | Subgraphs->Leaf->CyclicStructureAnalysis(LocalBackEdgeStack, MinimumRingSize);
|
---|
| 63 | delete(LocalBackEdgeStack);
|
---|
| 64 | delete(Subgraphs->previous);
|
---|
| 65 | FragmentCounter++;
|
---|
| 66 | }
|
---|
| 67 | delete(Subgraphs);
|
---|
| 68 | for (int i=0;i<FragmentCounter;i++)
|
---|
[920c70] | 69 | delete[](ListOfLocalAtoms[i]);
|
---|
| 70 | delete[](ListOfLocalAtoms);
|
---|
[97ebf8] | 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 | }
|
---|