| 1 | /* | 
|---|
| 2 | * FragmentationAction.cpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: May 9, 2010 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #include "Actions/FragmentationAction/FragmentationAction.hpp" | 
|---|
| 9 | #include "CommandLineParser.hpp" | 
|---|
| 10 | #include "atom.hpp" | 
|---|
| 11 | #include "config.hpp" | 
|---|
| 12 | #include "log.hpp" | 
|---|
| 13 | #include "molecule.hpp" | 
|---|
| 14 | #include "Descriptors/MoleculeDescriptor.hpp" | 
|---|
| 15 | #include "stackclass.hpp" | 
|---|
| 16 | #include "World.hpp" | 
|---|
| 17 |  | 
|---|
| 18 | #include <iostream> | 
|---|
| 19 | #include <string> | 
|---|
| 20 |  | 
|---|
| 21 | using namespace std; | 
|---|
| 22 |  | 
|---|
| 23 | #include "UIElements/UIFactory.hpp" | 
|---|
| 24 | #include "UIElements/Dialog.hpp" | 
|---|
| 25 | #include "Actions/MapOfActions.hpp" | 
|---|
| 26 |  | 
|---|
| 27 | const char FragmentationFragmentationAction::NAME[] = "fragment-mol"; | 
|---|
| 28 |  | 
|---|
| 29 | FragmentationFragmentationAction::FragmentationFragmentationAction() : | 
|---|
| 30 | Action(NAME) | 
|---|
| 31 | {} | 
|---|
| 32 |  | 
|---|
| 33 | FragmentationFragmentationAction::~FragmentationFragmentationAction() | 
|---|
| 34 | {} | 
|---|
| 35 |  | 
|---|
| 36 | Action::state_ptr FragmentationFragmentationAction::performCall() { | 
|---|
| 37 | Dialog *dialog = UIFactory::getInstance().makeDialog(); | 
|---|
| 38 | clock_t start,end; | 
|---|
| 39 | molecule *mol = NULL; | 
|---|
| 40 | double distance = -1.; | 
|---|
| 41 | int order = 0; | 
|---|
| 42 | config *configuration = World::getInstance().getConfig(); | 
|---|
| 43 | int ExitFlag = 0; | 
|---|
| 44 |  | 
|---|
| 45 | cout << "pre-dialog"<< endl; | 
|---|
| 46 | dialog->queryMolecule(NAME, &mol, MapOfActions::getInstance().getDescription(NAME)); | 
|---|
| 47 | dialog->queryDouble("distance", &distance, MapOfActions::getInstance().getDescription("distance")); | 
|---|
| 48 | dialog->queryInt("order", &order, MapOfActions::getInstance().getDescription("order")); | 
|---|
| 49 |  | 
|---|
| 50 | if(dialog->display()) { | 
|---|
| 51 | cout << "POST-dialog"<< endl; | 
|---|
| 52 | ASSERT(mol != NULL, "No molecule has been picked for fragmentation."); | 
|---|
| 53 | DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with bond distance " << distance << " angstroem, order of " << order << "." << endl); | 
|---|
| 54 | DoLog(0) && (Log() << Verbose(0) << "Creating connection matrix..." << endl); | 
|---|
| 55 | start = clock(); | 
|---|
| 56 | mol->CreateAdjacencyList(distance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL); | 
|---|
| 57 | DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl); | 
|---|
| 58 | if (mol->hasBondStructure()) { | 
|---|
| 59 | ExitFlag = mol->FragmentMolecule(order, configuration); | 
|---|
| 60 | } | 
|---|
| 61 | World::getInstance().setExitFlag(ExitFlag); | 
|---|
| 62 | end = clock(); | 
|---|
| 63 | DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl); | 
|---|
| 64 | delete dialog; | 
|---|
| 65 | return Action::success; | 
|---|
| 66 | } else { | 
|---|
| 67 | delete dialog; | 
|---|
| 68 | return Action::failure; | 
|---|
| 69 | } | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | Action::state_ptr FragmentationFragmentationAction::performUndo(Action::state_ptr _state) { | 
|---|
| 73 | //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get()); | 
|---|
| 74 |  | 
|---|
| 75 | return Action::failure; | 
|---|
| 76 | //  string newName = state->mol->getName(); | 
|---|
| 77 | //  state->mol->setName(state->lastName); | 
|---|
| 78 | // | 
|---|
| 79 | //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName)); | 
|---|
| 80 | } | 
|---|
| 81 |  | 
|---|
| 82 | Action::state_ptr FragmentationFragmentationAction::performRedo(Action::state_ptr _state){ | 
|---|
| 83 | return Action::failure; | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | bool FragmentationFragmentationAction::canUndo() { | 
|---|
| 87 | return false; | 
|---|
| 88 | } | 
|---|
| 89 |  | 
|---|
| 90 | bool FragmentationFragmentationAction::shouldUndo() { | 
|---|
| 91 | return false; | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 94 | const string FragmentationFragmentationAction::getName() { | 
|---|
| 95 | return NAME; | 
|---|
| 96 | } | 
|---|