| 1 | /*
|
|---|
| 2 | * FragmentationAction.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: May 9, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | // include config.h
|
|---|
| 9 | #ifdef HAVE_CONFIG_H
|
|---|
| 10 | #include <config.h>
|
|---|
| 11 | #endif
|
|---|
| 12 |
|
|---|
| 13 | #include "Helpers/MemDebug.hpp"
|
|---|
| 14 |
|
|---|
| 15 | #include "Actions/FragmentationAction/FragmentationAction.hpp"
|
|---|
| 16 | #include "Actions/ActionRegistry.hpp"
|
|---|
| 17 | #include "atom.hpp"
|
|---|
| 18 | #include "bondgraph.hpp"
|
|---|
| 19 | #include "config.hpp"
|
|---|
| 20 | #include "Helpers/Log.hpp"
|
|---|
| 21 | #include "molecule.hpp"
|
|---|
| 22 | #include "Descriptors/MoleculeDescriptor.hpp"
|
|---|
| 23 | #include "stackclass.hpp"
|
|---|
| 24 | #include "World.hpp"
|
|---|
| 25 |
|
|---|
| 26 | #include <iostream>
|
|---|
| 27 | #include <string>
|
|---|
| 28 |
|
|---|
| 29 | using namespace std;
|
|---|
| 30 |
|
|---|
| 31 | #include "UIElements/UIFactory.hpp"
|
|---|
| 32 | #include "UIElements/Dialog.hpp"
|
|---|
| 33 | #include "Actions/ValueStorage.hpp"
|
|---|
| 34 |
|
|---|
| 35 | const char FragmentationFragmentationAction::NAME[] = "fragment-mol";
|
|---|
| 36 |
|
|---|
| 37 | FragmentationFragmentationAction::FragmentationFragmentationAction() :
|
|---|
| 38 | Action(NAME)
|
|---|
| 39 | {}
|
|---|
| 40 |
|
|---|
| 41 | FragmentationFragmentationAction::~FragmentationFragmentationAction()
|
|---|
| 42 | {}
|
|---|
| 43 |
|
|---|
| 44 | void FragmentationFragmentation(std::string &path, double distance, int order) {
|
|---|
| 45 | ValueStorage::getInstance().setCurrentValue(FragmentationFragmentationAction::NAME, path);
|
|---|
| 46 | ValueStorage::getInstance().setCurrentValue("distance", distance);
|
|---|
| 47 | ValueStorage::getInstance().setCurrentValue("order", order);
|
|---|
| 48 | ActionRegistry::getInstance().getActionByName(FragmentationFragmentationAction::NAME)->call(Action::NonInteractive);
|
|---|
| 49 | };
|
|---|
| 50 |
|
|---|
| 51 | Dialog* FragmentationFragmentationAction::fillDialog(Dialog *dialog) {
|
|---|
| 52 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
|---|
| 53 |
|
|---|
| 54 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
|---|
| 55 | dialog->queryDouble("distance", ValueStorage::getInstance().getDescription("distance"));
|
|---|
| 56 | dialog->queryInt("order", ValueStorage::getInstance().getDescription("order"));
|
|---|
| 57 |
|
|---|
| 58 | return dialog;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | Action::state_ptr FragmentationFragmentationAction::performCall() {
|
|---|
| 62 | clock_t start,end;
|
|---|
| 63 | molecule *mol = NULL;
|
|---|
| 64 | double distance = -1.;
|
|---|
| 65 | int order = 0;
|
|---|
| 66 | std::string path;
|
|---|
| 67 | config *configuration = World::getInstance().getConfig();
|
|---|
| 68 | int ExitFlag = 0;
|
|---|
| 69 |
|
|---|
| 70 | ValueStorage::getInstance().queryCurrentValue(NAME, path);
|
|---|
| 71 | ValueStorage::getInstance().queryCurrentValue("distance", distance);
|
|---|
| 72 | ValueStorage::getInstance().queryCurrentValue("order", order);
|
|---|
| 73 |
|
|---|
| 74 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
|---|
| 75 | mol = iter->second;
|
|---|
| 76 | ASSERT(mol != NULL, "No molecule has been picked for fragmentation.");
|
|---|
| 77 | DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with bond distance " << distance << " angstroem, order of " << order << "." << endl);
|
|---|
| 78 | DoLog(0) && (Log() << Verbose(0) << "Creating connection matrix..." << endl);
|
|---|
| 79 | start = clock();
|
|---|
| 80 | mol->CreateAdjacencyList(distance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
|
|---|
| 81 | DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl);
|
|---|
| 82 | if (mol->hasBondStructure()) {
|
|---|
| 83 | ExitFlag = mol->FragmentMolecule(order, path);
|
|---|
| 84 | }
|
|---|
| 85 | World::getInstance().setExitFlag(ExitFlag);
|
|---|
| 86 | end = clock();
|
|---|
| 87 | DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl);
|
|---|
| 88 | }
|
|---|
| 89 | return Action::success;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | Action::state_ptr FragmentationFragmentationAction::performUndo(Action::state_ptr _state) {
|
|---|
| 93 | return Action::success;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | Action::state_ptr FragmentationFragmentationAction::performRedo(Action::state_ptr _state){
|
|---|
| 97 | return Action::success;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | bool FragmentationFragmentationAction::canUndo() {
|
|---|
| 101 | return true;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | bool FragmentationFragmentationAction::shouldUndo() {
|
|---|
| 105 | return true;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | const string FragmentationFragmentationAction::getName() {
|
|---|
| 109 | return NAME;
|
|---|
| 110 | }
|
|---|