[5589e7e] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2013 University of Bonn. All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | *
|
---|
| 7 | * This file is part of MoleCuilder.
|
---|
| 8 | *
|
---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 21 | */
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | * StoreSaturatedFragmentAction.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: Feb 26, 2013
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 36 |
|
---|
| 37 | #include "Atom/atom.hpp"
|
---|
| 38 | #include "CodePatterns/Log.hpp"
|
---|
| 39 | #include "Fragmentation/Exporters/ExportGraph_ToFiles.hpp"
|
---|
| 40 | #include "Fragmentation/Graph.hpp"
|
---|
| 41 | #include "World.hpp"
|
---|
| 42 |
|
---|
| 43 | #include <boost/filesystem.hpp>
|
---|
| 44 | #include <algorithm>
|
---|
| 45 | #include <iostream>
|
---|
| 46 | #include <string>
|
---|
| 47 |
|
---|
| 48 | #include "Actions/FragmentationAction/StoreSaturatedFragmentAction.hpp"
|
---|
| 49 |
|
---|
| 50 | using namespace MoleCuilder;
|
---|
| 51 |
|
---|
| 52 | // and construct the stuff
|
---|
| 53 | #include "StoreSaturatedFragmentAction.def"
|
---|
| 54 | #include "Action_impl_pre.hpp"
|
---|
| 55 | /** =========== define the function ====================== */
|
---|
| 56 | Action::state_ptr FragmentationStoreSaturatedFragmentAction::performCall() {
|
---|
| 57 | World &world = World::getInstance();
|
---|
| 58 |
|
---|
| 59 | // check for selected atoms
|
---|
| 60 | if (world.beginAtomSelection() == world.endAtomSelection()) {
|
---|
| 61 | ELOG(1, "There are not atoms selected for storing.");
|
---|
| 62 | return Action::failure;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | // create single graph from selected atoms
|
---|
| 66 | Graph TotalGraph;
|
---|
| 67 | KeySet SelectedAtoms;
|
---|
| 68 | for (World::AtomSelectionConstIterator iter = world.beginAtomSelection();
|
---|
| 69 | iter != world.endAtomSelection();
|
---|
| 70 | ++iter) {
|
---|
| 71 | LOG(3, "DEBUG: Adding atom " << *iter->second << " to fragment.");
|
---|
| 72 | SelectedAtoms.insert( iter->second->getId() );
|
---|
| 73 | }
|
---|
| 74 | TotalGraph.insert( GraphPair( SelectedAtoms, NumberValuePair(1, 0.)) );
|
---|
| 75 |
|
---|
| 76 | // store molecule's fragment to file
|
---|
| 77 | {
|
---|
| 78 | const enum HydrogenSaturation saturation = params.DoSaturation.get() ? DoSaturate : DontSaturate;
|
---|
| 79 | ExportGraph_ToFiles exporter(TotalGraph, IncludeHydrogen, saturation);
|
---|
| 80 | exporter.setPrefix(params.prefix.get());
|
---|
| 81 | exporter.setOutputTypes(params.types.get());
|
---|
| 82 | exporter();
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | return Action::success;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | Action::state_ptr FragmentationStoreSaturatedFragmentAction::performUndo(Action::state_ptr _state) {
|
---|
| 89 | return Action::success;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | Action::state_ptr FragmentationStoreSaturatedFragmentAction::performRedo(Action::state_ptr _state){
|
---|
| 93 | return Action::success;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | bool FragmentationStoreSaturatedFragmentAction::canUndo() {
|
---|
| 97 | return true;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | bool FragmentationStoreSaturatedFragmentAction::shouldUndo() {
|
---|
| 101 | return true;
|
---|
| 102 | }
|
---|
| 103 | /** =========== end of function ====================== */
|
---|