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
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
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
204ostream & operator << (ostream &ost, const atom &a)
205{
206 ost << "[" << a.Name << "|" << &a << "]";
207 return ost;
208};
209
210ostream & atom::operator << (ostream &ost)
211{
212 ost << "[" << Name << "|" << this << "]";
213 return ost;
214};
215
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
219 */
220bool atom::Compare(const atom &ptr)
221{
222 if (nr < ptr.nr)
223 return true;
224 else
225 return false;
226};
227
228bool operator < (atom &a, atom &b)
229{
230 return a.Compare(b);
231};
232
Note: See TracBrowser for help on using the repository browser.