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

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 ce8755 was 0454de, checked in by Frederik Heber <heber@…>, 15 years ago

converted LoadXyzAction to new createDialog().

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