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

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

FIX: newly parsed-in atoms should always end up in their own molecule

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