source: src/Parser/XyzParser.cpp@ bb4408

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

BUGFIX: Removed adding of parsed atoms in LoadXyzAction.

  • a molecule is created and added already in XyzParser::load().
  • this caused the id of a newly parsed in xyz file to be 2 instead of 1 and the creation of an empty molecule.
  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 * XyzParser.cpp
3 *
4 * Created on: Mar 2, 2010
5 * Author: metzler
6 */
7
8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include "Helpers/MemDebug.hpp"
14
15#include "Helpers/Log.hpp"
16#include "Helpers/Verbose.hpp"
17#include "XyzParser.hpp"
18#include "World.hpp"
19#include "atom.hpp"
20#include "molecule.hpp"
21#include "element.hpp"
22#include "periodentafel.hpp"
23
24using namespace std;
25
26/**
27 * Constructor.
28 */
29XyzParser::XyzParser() :
30 comment("")
31{}
32
33/**
34 * Destructor.
35 */
36XyzParser::~XyzParser() {
37}
38
39/**
40 * Loads an XYZ file into the World.
41 *
42 * \param XYZ file
43 */
44void XyzParser::load(istream* file) {
45 atom* newAtom = NULL;
46 molecule* newmol = NULL;
47 int numberOfAtoms;
48 char commentBuffer[512], type[3];
49 double tmp;
50
51 // the first line tells number of atoms, the second line is always a comment
52 *file >> numberOfAtoms >> ws;
53 file->getline(commentBuffer, 512);
54 comment = commentBuffer;
55
56 newmol = World::getInstance().createMolecule();
57 newmol->ActiveFlag = true;
58 // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include
59 World::getInstance().getMolecules()->insert(newmol);
60 for (int i = 0; i < numberOfAtoms; i++) {
61 newAtom = World::getInstance().createAtom();
62 *file >> type;
63 for (int j=0;j<NDIM;j++) {
64 *file >> tmp;
65 newAtom->set(j, tmp);
66 }
67 newAtom->setType(World::getInstance().getPeriode()->FindElement(type));
68 newmol->AddAtom(newAtom);
69 }
70}
71
72/**
73 * Saves the current state of the World into the given XYZ file.
74 *
75 * \param XYZ file
76 */
77void XyzParser::save(ostream* file) {
78 DoLog(0) && (Log() << Verbose(0) << "Saving changes to xyz." << std::endl);
79 if (comment == "") {
80 time_t now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time'
81 comment = "Created by molecuilder on ";
82 // ctime ends in \n\0, we have to cut away the newline
83 std::string time(ctime(&now));
84 size_t pos = time.find('\n');
85 if (pos != 0)
86 comment += time.substr(0,pos);
87 else
88 comment += time;
89 }
90 *file << World::getInstance().numAtoms() << endl << "\t" << comment << endl;
91
92 vector<atom*> atoms = World::getInstance().getAllAtoms();
93 for(vector<atom*>::iterator it = atoms.begin(); it != atoms.end(); it++) {
94 *file << noshowpoint << (*it)->getType()->getSymbol() << "\t" << (*it)->at(0) << "\t" << (*it)->at(1) << "\t" << (*it)->at(2) << endl;
95 }
96}
Note: See TracBrowser for help on using the repository browser.