source: src/Actions/ParserAction/LoadXyzAction.cpp@ 8f4df1

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 8f4df1 was 952f38, checked in by Frederik Heber <heber@…>, 14 years ago

created LibMolecuilderHelpers.

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