source: molecuilder/src/atom.cpp@ 0cd3b2

Last change on this file since 0cd3b2 was 0cd3b2, checked in by Frederik Heber <heber@…>, 16 years ago

in molecule::OutputTrajectoriesXYZ() ActOnAllAtoms used by new function atom::OutputTrajectoryXYZ().

  • Property mode set to 100755
File size: 6.6 KB
RevLine 
[a0bcf1]1/** \file atom.cpp
[c830e8e]2 *
[a0bcf1]3 * Function implementations for the class atom.
[c830e8e]4 *
[a0bcf1]5 */
6
[834ff3]7#include "atom.hpp"
[390a2b]8#include "memoryallocator.hpp"
[c830e8e]9
[a0bcf1]10/************************************* Functions for class atom *************************************/
11
12/** Constructor of class atom.
13 */
[c830e8e]14atom::atom()
[a0bcf1]15{
[834ff3]16 father = this; // generally, father is itself
[a0bcf1]17 previous = NULL;
18 next = NULL;
19 Ancestor = NULL;
20 type = NULL;
21 sort = NULL;
[090299]22 FixedIon = 0;
[a0bcf1]23 GraphNr = -1;
24 ComponentNr = NULL;
[126934]25 IsCyclic = false;
[a0bcf1]26 SeparationVertex = false;
27 LowpointNr = -1;
[c75363]28 AdaptiveOrder = 0;
[644ba1]29 MaxOrder = false;
[834ff3]30 // set LCNode::Vector to our Vector
31 node = &x;
[a0bcf1]32};
33
[4e4940]34/** Constructor of class atom.
35 */
36atom::atom(atom *pointer)
37{
38 Name = NULL;
39 previous = NULL;
40 next = NULL;
[bc3953]41 father = pointer; // generally, father is itself
[4e4940]42 Ancestor = NULL;
[834ff3]43 GraphNr = -1;
44 ComponentNr = NULL;
45 IsCyclic = false;
46 SeparationVertex = false;
47 LowpointNr = -1;
48 AdaptiveOrder = 0;
49 MaxOrder = false;
[4e4940]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;
[bc3953]56 node = &x;
[4e4940]57}
58
59
[a0bcf1]60/** Destructor of class atom.
61 */
[c830e8e]62atom::~atom()
[a0bcf1]63{
[8afe31]64 Free<int>(&ComponentNr, "atom::~atom: *ComponentNr");
[58808e]65 Free<char>(&Name, "atom::~atom: *Name");
[567b7f]66 Trajectory.R.clear();
67 Trajectory.U.clear();
68 Trajectory.F.clear();
[a0bcf1]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
[dcbdf2]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
[8ffe32]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
[a0bcf1]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
[c830e8e]121 * \param *comment commentary after '#' sign
[a0bcf1]122 */
[567b7f]123bool atom::Output(ofstream *out, int ElementNo, int AtomNo, const char *comment) const
[a0bcf1]124{
125 if (out != NULL) {
126 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
[090299]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";
[1b2aa1]131 if (comment != NULL)
132 *out << " # " << comment << endl;
[8ffe32]133 else
134 *out << " # molecule nr " << nr << endl;
135 return true;
136 } else
137 return false;
138};
[567b7f]139bool atom::Output(ofstream *out, int *ElementNo, int *AtomNo, const char *comment)
[8ffe32]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;
[1b2aa1]150 else
151 *out << " # molecule nr " << nr << endl;
[a0bcf1]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
[567b7f]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
[0cd3b2]189/** Output of a single atom as one lin in xyz file.
190 * \param *out stream to output to
191 */
192bool atom::OutputTrajectoryXYZ(ofstream *out, int step) const
193{
194 if (out != NULL) {
195 *out << type->symbol << "\t";
196 *out << Trajectory.R.at(step).x[0] << "\t";
197 *out << Trajectory.R.at(step).x[1] << "\t";
198 *out << Trajectory.R.at(step).x[2] << endl;
199 return true;
200 } else
201 return false;
202};
203
[b65771]204ostream & operator << (ostream &ost, const atom &a)
[a0bcf1]205{
206 ost << "[" << a.Name << "|" << &a << "]";
207 return ost;
208};
209
[e0521b]210ostream & atom::operator << (ostream &ost)
211{
212 ost << "[" << Name << "|" << this << "]";
213 return ost;
214};
215
[a0bcf1]216/** Compares the indices of \a this atom with a given \a ptr.
217 * \param ptr atom to compare index against
218 * \return true - this one's is smaller, false - not
[c830e8e]219 */
[b65771]220bool atom::Compare(const atom &ptr)
[a0bcf1]221{
222 if (nr < ptr.nr)
223 return true;
224 else
225 return false;
226};
227
[c830e8e]228bool operator < (atom &a, atom &b)
[a0bcf1]229{
230 return a.Compare(b);
231};
232
Note: See TracBrowser for help on using the repository browser.