source: src/atom.cpp@ fcd7b6

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 Candidate_v1.7.0 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 fcd7b6 was fcd7b6, checked in by Frederik Heber <heber@…>, 16 years ago

In molecule::OutputTrajectories() ActOnAllAtoms() with new function atom::OutputTrajectory() is used.

For this to work, I had to change the Trajectory struct that was so far included in molecule.hpp to be incorporated directly into the class atom.
NOTE: This incorporation is incomplete and a ticket (#34) has been filed to remind of this issue.
However, the trajectory is better suited to reside in atom anyway and was probably just put in molecule due to memory prejudices against STL vector<>.
Functions in molecule.cpp, config.cpp, molecule_geometry.cpp and molecule_dynamics.cpp were adapted (changed from Trajectories[atom *] to atom *->Trajectory).
And the atom pointer in the Trajectory structure was removed.

  • Property mode set to 100755
File size: 6.2 KB
Line 
1/** \file atom.cpp
2 *
3 * Function implementations for the class atom.
4 *
5 */
6
7#include "atom.hpp"
8#include "memoryallocator.hpp"
9
10/************************************* Functions for class atom *************************************/
11
12/** Constructor of class atom.
13 */
14atom::atom()
15{
16 father = this; // generally, father is itself
17 previous = NULL;
18 next = NULL;
19 Ancestor = NULL;
20 type = NULL;
21 sort = NULL;
22 FixedIon = 0;
23 GraphNr = -1;
24 ComponentNr = NULL;
25 IsCyclic = false;
26 SeparationVertex = false;
27 LowpointNr = -1;
28 AdaptiveOrder = 0;
29 MaxOrder = false;
30 // set LCNode::Vector to our Vector
31 node = &x;
32};
33
34/** Constructor of class atom.
35 */
36atom::atom(atom *pointer)
37{
38 Name = NULL;
39 previous = NULL;
40 next = NULL;
41 father = pointer; // generally, father is itself
42 Ancestor = NULL;
43 GraphNr = -1;
44 ComponentNr = NULL;
45 IsCyclic = false;
46 SeparationVertex = false;
47 LowpointNr = -1;
48 AdaptiveOrder = 0;
49 MaxOrder = false;
50 type = pointer->type; // copy element of atom
51 x.CopyVector(&pointer->x); // copy coordination
52 v.CopyVector(&pointer->v); // copy velocity
53 FixedIon = pointer->FixedIon;
54 nr = -1;
55 sort = &nr;
56 node = &x;
57}
58
59
60/** Destructor of class atom.
61 */
62atom::~atom()
63{
64 Free<int>(&ComponentNr, "atom::~atom: *ComponentNr");
65 Free<char>(&Name, "atom::~atom: *Name");
66 Trajectory.R.clear();
67 Trajectory.U.clear();
68 Trajectory.F.clear();
69};
70
71
72/** Climbs up the father list until NULL, last is returned.
73 * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen)
74 */
75atom *atom::GetTrueFather()
76{
77 atom *walker = this;
78 do {
79 if (walker == walker->father) // top most father is the one that points on itself
80 break;
81 walker = walker->father;
82 } while (walker != NULL);
83 return walker;
84};
85
86/** Sets father to itself or its father in case of copying a molecule.
87 */
88void atom::CorrectFather()
89{
90 if (father->father == father) // same atom in copy's father points to itself
91 father = this; // set father to itself (copy of a whole molecule)
92 else
93 father = father->father; // set father to original's father
94
95};
96
97/** Check whether father is equal to given atom.
98 * \param *ptr atom to compare father to
99 * \param **res return value (only set if atom::father is equal to \a *ptr)
100 */
101void atom::EqualsFather ( atom *ptr, atom **res )
102{
103 if ( ptr == father )
104 *res = this;
105};
106
107/** Checks whether atom is within the given box.
108 * \param offset offset to box origin
109 * \param *parallelepiped box matrix
110 * \return true - is inside, false - is not
111 */
112bool atom::IsInParallelepiped(Vector offset, double *parallelepiped)
113{
114 return (node->IsInParallelepiped(offset, parallelepiped));
115};
116
117/** Output of a single atom.
118 * \param ElementNo cardinal number of the element
119 * \param AtomNo cardinal number among these atoms of the same element
120 * \param *out stream to output to
121 * \param *comment commentary after '#' sign
122 */
123bool atom::Output(ofstream *out, int ElementNo, int AtomNo, const char *comment) const
124{
125 if (out != NULL) {
126 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
127 *out << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2];
128 *out << "\t" << FixedIon;
129 if (v.Norm() > MYEPSILON)
130 *out << "\t" << scientific << setprecision(6) << v.x[0] << "\t" << v.x[1] << "\t" << v.x[2] << "\t";
131 if (comment != NULL)
132 *out << " # " << comment << endl;
133 else
134 *out << " # molecule nr " << nr << endl;
135 return true;
136 } else
137 return false;
138};
139bool atom::Output(ofstream *out, int *ElementNo, int *AtomNo, const char *comment)
140{
141 AtomNo[type->Z]++; // increment number
142 if (out != NULL) {
143 *out << "Ion_Type" << ElementNo[type->Z] << "_" << AtomNo[type->Z] << "\t" << fixed << setprecision(9) << showpoint;
144 *out << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2];
145 *out << "\t" << FixedIon;
146 if (v.Norm() > MYEPSILON)
147 *out << "\t" << scientific << setprecision(6) << v.x[0] << "\t" << v.x[1] << "\t" << v.x[2] << "\t";
148 if (comment != NULL)
149 *out << " # " << comment << endl;
150 else
151 *out << " # molecule nr " << nr << endl;
152 return true;
153 } else
154 return false;
155};
156
157/** Output of a single atom as one lin in xyz file.
158 * \param *out stream to output to
159 */
160bool atom::OutputXYZLine(ofstream *out) const
161{
162 if (out != NULL) {
163 *out << type->symbol << "\t" << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2] << "\t" << endl;
164 return true;
165 } else
166 return false;
167};
168
169/** Output of a single atom as one lin in xyz file.
170 * \param *out stream to output to
171 */
172bool atom::OutputTrajectory(ofstream *out, int *ElementNo, int *AtomNo, int step) const
173{
174 AtomNo[type->Z]++;
175 if (out != NULL) {
176 *out << "Ion_Type" << ElementNo[type->Z] << "_" << AtomNo[type->Z] << "\t" << fixed << setprecision(9) << showpoint;
177 *out << Trajectory.R.at(step).x[0] << "\t" << Trajectory.R.at(step).x[1] << "\t" << Trajectory.R.at(step).x[2];
178 *out << "\t" << FixedIon;
179 if (Trajectory.U.at(step).Norm() > MYEPSILON)
180 *out << "\t" << scientific << setprecision(6) << Trajectory.U.at(step).x[0] << "\t" << Trajectory.U.at(step).x[1] << "\t" << Trajectory.U.at(step).x[2] << "\t";
181 if (Trajectory.F.at(step).Norm() > MYEPSILON)
182 *out << "\t" << scientific << setprecision(6) << Trajectory.F.at(step).x[0] << "\t" << Trajectory.F.at(step).x[1] << "\t" << Trajectory.F.at(step).x[2] << "\t";
183 *out << "\t# Number in molecule " << nr << endl;
184 return true;
185 } else
186 return false;
187};
188
189ostream & operator << (ostream &ost, const atom &a)
190{
191 ost << "[" << a.Name << "|" << &a << "]";
192 return ost;
193};
194
195ostream & atom::operator << (ostream &ost)
196{
197 ost << "[" << Name << "|" << this << "]";
198 return ost;
199};
200
201/** Compares the indices of \a this atom with a given \a ptr.
202 * \param ptr atom to compare index against
203 * \return true - this one's is smaller, false - not
204 */
205bool atom::Compare(const atom &ptr)
206{
207 if (nr < ptr.nr)
208 return true;
209 else
210 return false;
211};
212
213bool operator < (atom &a, atom &b)
214{
215 return a.Compare(b);
216};
217
Note: See TracBrowser for help on using the repository browser.