source: src/Actions/ParserAction/LoadXyzAction.cpp@ bf3817

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since bf3817 was bf3817, checked in by Frederik Heber <heber@…>, 15 years ago

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

  • is now topmost in front of MemDebug.hpp (and any other).
  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * LoadXyzAction.cpp
3 *
4 * Created on: May 8, 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
15using namespace std;
16
17#include "Actions/ParserAction/LoadXyzAction.hpp"
18#include "Actions/ActionRegistry.hpp"
19#include "Parser/XyzParser.hpp"
20#include "atom.hpp"
21#include "Helpers/Log.hpp"
22#include "molecule.hpp"
23#include "Helpers/Verbose.hpp"
24#include "World.hpp"
25
26#include <iostream>
27#include <set>
28#include <string>
29#include <vector>
30
31#include "UIElements/UIFactory.hpp"
32#include "UIElements/Dialog.hpp"
33#include "Actions/ValueStorage.hpp"
34
35/****** ParserLoadXyzAction *****/
36
37//// memento to remember the state when undoing
38//
39//class ParserLoadXyzState : public ActionState {
40//public:
41// ParserLoadXyzState(molecule* _mol,std::string _lastName) :
42// mol(_mol),
43// lastName(_lastName)
44// {}
45// molecule* mol;
46// std::string lastName;
47//};
48
49const char ParserLoadXyzAction::NAME[] = "parse-xyz";
50
51ParserLoadXyzAction::ParserLoadXyzAction() :
52 Action(NAME)
53{}
54
55ParserLoadXyzAction::~ParserLoadXyzAction()
56{}
57
58void ParserLoadXyz(std::string &filename) {
59 ValueStorage::getInstance().setCurrentValue(ParserLoadXyzAction::NAME, filename);
60 ActionRegistry::getInstance().getActionByName(ParserLoadXyzAction::NAME)->call(Action::NonInteractive);
61};
62
63Dialog* ParserLoadXyzAction::fillDialog(Dialog *dialog) {
64 ASSERT(dialog,"No Dialog given when filling action dialog");
65
66 dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
67
68 return dialog;
69}
70
71Action::state_ptr ParserLoadXyzAction::performCall() {
72 string filename;
73
74 ValueStorage::getInstance().queryCurrentValue(NAME, filename);
75
76 DoLog(1) && (Log() << Verbose(1) << "Parsing xyz file for new atoms." << endl);
77 // parse xyz file
78 ifstream input;
79 input.open(filename.c_str());
80 if (!input.fail()) {
81 // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include
82 set <atom*> UniqueList;
83 {
84 vector<atom *> ListBefore = World::getInstance().getAllAtoms();
85 for (vector<atom *>::iterator runner = ListBefore.begin();runner != ListBefore.end(); ++runner)
86 UniqueList.insert(*runner);
87 }
88 XyzParser parser; // briefly instantiate a parser which is removed at end of focus
89 parser.load(&input);
90 {
91 vector<atom *> ListAfter = World::getInstance().getAllAtoms();
92 pair< set<atom *>::iterator, bool > Inserter;
93 if (UniqueList.size() != ListAfter.size()) { // only create if new atoms have been parsed
94 MoleculeListClass *molecules = World::getInstance().getMolecules();
95 molecule *mol = World::getInstance().createMolecule();
96 molecules->insert(mol);
97 for (vector<atom *>::iterator runner = ListAfter.begin(); runner != ListAfter.end(); ++runner) {
98 Inserter = UniqueList.insert(*runner);
99 if (Inserter.second) { // if not present, then new (just parsed) atom, add ...
100 cout << "Adding new atom " << **runner << " to new mol." << endl;
101 mol->AddAtom(*runner);
102 }
103 }
104 mol->doCountAtoms();
105 } else {
106 cout << "No atoms parsed?" << endl;
107 }
108 }
109 } else {
110 DoeLog(1) && (eLog() << Verbose(1) << "Could not open file " << filename << "." << endl);
111 }
112 input.close();
113 return Action::success;
114}
115
116Action::state_ptr ParserLoadXyzAction::performUndo(Action::state_ptr _state) {
117// ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
118
119 return Action::failure;
120// string newName = state->mol->getName();
121// state->mol->setName(state->lastName);
122//
123// return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
124}
125
126Action::state_ptr ParserLoadXyzAction::performRedo(Action::state_ptr _state){
127 return Action::failure;
128}
129
130bool ParserLoadXyzAction::canUndo() {
131 return false;
132}
133
134bool ParserLoadXyzAction::shouldUndo() {
135 return false;
136}
137
138const string ParserLoadXyzAction::getName() {
139 return NAME;
140}
Note: See TracBrowser for help on using the repository browser.