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