[97ebf8] | 1 | /*
|
---|
| 2 | * FragmentationAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 9, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[bf3817] | 8 | // include config.h
|
---|
| 9 | #ifdef HAVE_CONFIG_H
|
---|
| 10 | #include <config.h>
|
---|
| 11 | #endif
|
---|
| 12 |
|
---|
[112b09] | 13 | #include "Helpers/MemDebug.hpp"
|
---|
| 14 |
|
---|
[97ebf8] | 15 | #include "Actions/FragmentationAction/FragmentationAction.hpp"
|
---|
[0430e3] | 16 | #include "Actions/ActionRegistry.hpp"
|
---|
[97ebf8] | 17 | #include "atom.hpp"
|
---|
[a3fded] | 18 | #include "bondgraph.hpp"
|
---|
[97ebf8] | 19 | #include "config.hpp"
|
---|
[952f38] | 20 | #include "Helpers/Log.hpp"
|
---|
[97ebf8] | 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"
|
---|
[861874] | 33 | #include "Actions/ValueStorage.hpp"
|
---|
[97ebf8] | 34 |
|
---|
[e4b5de] | 35 | const char FragmentationFragmentationAction::NAME[] = "fragment-mol";
|
---|
[97ebf8] | 36 |
|
---|
| 37 | FragmentationFragmentationAction::FragmentationFragmentationAction() :
|
---|
| 38 | Action(NAME)
|
---|
| 39 | {}
|
---|
| 40 |
|
---|
| 41 | FragmentationFragmentationAction::~FragmentationFragmentationAction()
|
---|
| 42 | {}
|
---|
| 43 |
|
---|
[4ff081] | 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 |
|
---|
[047878] | 51 | Dialog* FragmentationFragmentationAction::fillDialog(Dialog *dialog) {
|
---|
| 52 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[70d9b9] | 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() {
|
---|
[e4b5de] | 62 | clock_t start,end;
|
---|
| 63 | molecule *mol = NULL;
|
---|
| 64 | double distance = -1.;
|
---|
| 65 | int order = 0;
|
---|
[35b698] | 66 | std::string path;
|
---|
[e4b5de] | 67 | config *configuration = World::getInstance().getConfig();
|
---|
| 68 | int ExitFlag = 0;
|
---|
| 69 |
|
---|
[70d9b9] | 70 | ValueStorage::getInstance().queryCurrentValue(NAME, path);
|
---|
| 71 | ValueStorage::getInstance().queryCurrentValue("distance", distance);
|
---|
| 72 | ValueStorage::getInstance().queryCurrentValue("order", order);
|
---|
[97ebf8] | 73 |
|
---|
[70d9b9] | 74 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
---|
| 75 | mol = iter->second;
|
---|
[e4b5de] | 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()) {
|
---|
[35b698] | 83 | ExitFlag = mol->FragmentMolecule(order, path);
|
---|
[e4b5de] | 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);
|
---|
[97ebf8] | 88 | }
|
---|
[70d9b9] | 89 | return Action::success;
|
---|
[97ebf8] | 90 | }
|
---|
| 91 |
|
---|
| 92 | Action::state_ptr FragmentationFragmentationAction::performUndo(Action::state_ptr _state) {
|
---|
[70d9b9] | 93 | return Action::success;
|
---|
[97ebf8] | 94 | }
|
---|
| 95 |
|
---|
| 96 | Action::state_ptr FragmentationFragmentationAction::performRedo(Action::state_ptr _state){
|
---|
[70d9b9] | 97 | return Action::success;
|
---|
[97ebf8] | 98 | }
|
---|
| 99 |
|
---|
| 100 | bool FragmentationFragmentationAction::canUndo() {
|
---|
[70d9b9] | 101 | return true;
|
---|
[97ebf8] | 102 | }
|
---|
| 103 |
|
---|
| 104 | bool FragmentationFragmentationAction::shouldUndo() {
|
---|
[70d9b9] | 105 | return true;
|
---|
[97ebf8] | 106 | }
|
---|
| 107 |
|
---|
| 108 | const string FragmentationFragmentationAction::getName() {
|
---|
| 109 | return NAME;
|
---|
| 110 | }
|
---|