| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2016 Frederik Heber. 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 | * ParseParticleParametersAction.cpp
|
|---|
| 25 | *
|
|---|
| 26 | * Created on: Feb 27, 2016
|
|---|
| 27 | * Author: heber
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 | // include config.h
|
|---|
| 31 | #ifdef HAVE_CONFIG_H
|
|---|
| 32 | #include <config.h>
|
|---|
| 33 | #endif
|
|---|
| 34 |
|
|---|
| 35 | // include headers that implement a archive in simple text format
|
|---|
| 36 | // and before MemDebug due to placement new
|
|---|
| 37 | #include <boost/archive/text_oarchive.hpp>
|
|---|
| 38 | #include <boost/archive/text_iarchive.hpp>
|
|---|
| 39 |
|
|---|
| 40 | #include "CodePatterns/MemDebug.hpp"
|
|---|
| 41 |
|
|---|
| 42 | #include "Actions/PotentialAction/ParseParticleParametersAction.hpp"
|
|---|
| 43 |
|
|---|
| 44 | #include <boost/filesystem.hpp>
|
|---|
| 45 | #include <fstream>
|
|---|
| 46 |
|
|---|
| 47 | #include "CodePatterns/Log.hpp"
|
|---|
| 48 |
|
|---|
| 49 | #include "Potentials/Exceptions.hpp"
|
|---|
| 50 | #include "Potentials/Particles/ParticleFactory.hpp"
|
|---|
| 51 | #include "Potentials/Particles/ParticleRegistry.hpp"
|
|---|
| 52 | #include "Potentials/RegistryDeserializer.hpp"
|
|---|
| 53 |
|
|---|
| 54 | using namespace MoleCuilder;
|
|---|
| 55 |
|
|---|
| 56 | // and construct the stuff
|
|---|
| 57 | #include "ParseParticleParametersAction.def"
|
|---|
| 58 | #include "Action_impl_pre.hpp"
|
|---|
| 59 | /** =========== define the function ====================== */
|
|---|
| 60 |
|
|---|
| 61 | ActionState::ptr PotentialParseParticleParametersAction::performCall()
|
|---|
| 62 | {
|
|---|
| 63 | if (boost::filesystem::exists(params.particle_file.get())) {
|
|---|
| 64 | std::ifstream returnstream(params.particle_file.get().string().c_str());
|
|---|
| 65 | if (returnstream.good()) {
|
|---|
| 66 | try {
|
|---|
| 67 | RegistryDeserializer<Particle> deserialize(
|
|---|
| 68 | returnstream,
|
|---|
| 69 | ParticleFactory::getInstance(),
|
|---|
| 70 | ParticleRegistry::getInstance(),
|
|---|
| 71 | std::string("particle"));
|
|---|
| 72 | deserialize();
|
|---|
| 73 | } catch (SerializerMissingValueException &e) {
|
|---|
| 74 | if (const std::string *key = boost::get_error_info<SerializerKey>(e))
|
|---|
| 75 | STATUS("Missing value when parsing information for particle "+*key+".");
|
|---|
| 76 | else
|
|---|
| 77 | STATUS("Missing value parsing information for particle with unknown key.");
|
|---|
| 78 | return Action::failure;
|
|---|
| 79 | } catch (SerializerIllegalKeyException &e) {
|
|---|
| 80 | if (const std::string *key = boost::get_error_info<SerializerKey>(e))
|
|---|
| 81 | STATUS("Illegal key parsing information for particle "+*key+".");
|
|---|
| 82 | else
|
|---|
| 83 | STATUS("Illegal key parsing information for particle with unknown key.");
|
|---|
| 84 | return Action::failure;
|
|---|
| 85 | }
|
|---|
| 86 | } else {
|
|---|
| 87 | STATUS("Failed to parse from "+params.particle_file.get().string()+".");
|
|---|
| 88 | return Action::failure;
|
|---|
| 89 | }
|
|---|
| 90 | returnstream.close();
|
|---|
| 91 |
|
|---|
| 92 | LOG(0, "STATUS: Parsed a set of particle parameters parsed from "
|
|---|
| 93 | << params.particle_file.get().string() << ".");
|
|---|
| 94 |
|
|---|
| 95 | } else {
|
|---|
| 96 | STATUS("No existing particles file given!");
|
|---|
| 97 | return Action::failure;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | return Action::success;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | ActionState::ptr PotentialParseParticleParametersAction::performUndo(ActionState::ptr _state) {
|
|---|
| 104 | STATUS("Undo of PotentialParseParticleParametersAction not implemented.");
|
|---|
| 105 | return Action::failure;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | ActionState::ptr PotentialParseParticleParametersAction::performRedo(ActionState::ptr _state){
|
|---|
| 109 | STATUS("Redo of PotentialParseParticleParametersAction not implemented.");
|
|---|
| 110 | return Action::failure;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | bool PotentialParseParticleParametersAction::canUndo() {
|
|---|
| 114 | return false;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | bool PotentialParseParticleParametersAction::shouldUndo() {
|
|---|
| 118 | return false;
|
|---|
| 119 | }
|
|---|
| 120 | /** =========== end of function ====================== */
|
|---|