source: molecuilder/src/atom.cpp@ 8ffe32

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

More functions of molecule now use templated iterators.

  • Property mode set to 100755
File size: 5.1 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");
[a0bcf1]66};
67
68
69/** Climbs up the father list until NULL, last is returned.
70 * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen)
71 */
72atom *atom::GetTrueFather()
73{
74 atom *walker = this;
75 do {
76 if (walker == walker->father) // top most father is the one that points on itself
77 break;
78 walker = walker->father;
79 } while (walker != NULL);
80 return walker;
81};
82
[dcbdf2]83/** Sets father to itself or its father in case of copying a molecule.
84 */
85void atom::CorrectFather()
86{
87 if (father->father == father) // same atom in copy's father points to itself
88 father = this; // set father to itself (copy of a whole molecule)
89 else
90 father = father->father; // set father to original's father
91
92};
93
94/** Check whether father is equal to given atom.
95 * \param *ptr atom to compare father to
96 * \param **res return value (only set if atom::father is equal to \a *ptr)
97 */
98void atom::EqualsFather ( atom *ptr, atom **res )
99{
100 if ( ptr == father )
101 *res = this;
102};
103
[8ffe32]104/** Checks whether atom is within the given box.
105 * \param offset offset to box origin
106 * \param *parallelepiped box matrix
107 * \return true - is inside, false - is not
108 */
109bool atom::IsInParallelepiped(Vector offset, double *parallelepiped)
110{
111 return (node->IsInParallelepiped(offset, parallelepiped));
112};
113
[a0bcf1]114/** Output of a single atom.
115 * \param ElementNo cardinal number of the element
116 * \param AtomNo cardinal number among these atoms of the same element
117 * \param *out stream to output to
[c830e8e]118 * \param *comment commentary after '#' sign
[a0bcf1]119 */
[c830e8e]120bool atom::Output(int ElementNo, int AtomNo, ofstream *out, const char *comment) const
[a0bcf1]121{
122 if (out != NULL) {
123 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
[090299]124 *out << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2];
125 *out << "\t" << FixedIon;
126 if (v.Norm() > MYEPSILON)
127 *out << "\t" << scientific << setprecision(6) << v.x[0] << "\t" << v.x[1] << "\t" << v.x[2] << "\t";
[1b2aa1]128 if (comment != NULL)
129 *out << " # " << comment << endl;
[8ffe32]130 else
131 *out << " # molecule nr " << nr << endl;
132 return true;
133 } else
134 return false;
135};
136bool atom::Output(int *ElementNo, int *AtomNo, ofstream *out, const char *comment)
137{
138 AtomNo[type->Z]++; // increment number
139 if (out != NULL) {
140 *out << "Ion_Type" << ElementNo[type->Z] << "_" << AtomNo[type->Z] << "\t" << fixed << setprecision(9) << showpoint;
141 *out << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2];
142 *out << "\t" << FixedIon;
143 if (v.Norm() > MYEPSILON)
144 *out << "\t" << scientific << setprecision(6) << v.x[0] << "\t" << v.x[1] << "\t" << v.x[2] << "\t";
145 if (comment != NULL)
146 *out << " # " << comment << endl;
[1b2aa1]147 else
148 *out << " # molecule nr " << nr << endl;
[a0bcf1]149 return true;
150 } else
151 return false;
152};
153
154/** Output of a single atom as one lin in xyz file.
155 * \param *out stream to output to
156 */
157bool atom::OutputXYZLine(ofstream *out) const
158{
159 if (out != NULL) {
160 *out << type->symbol << "\t" << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2] << "\t" << endl;
161 return true;
162 } else
163 return false;
164};
165
[b65771]166ostream & operator << (ostream &ost, const atom &a)
[a0bcf1]167{
168 ost << "[" << a.Name << "|" << &a << "]";
169 return ost;
170};
171
[e0521b]172ostream & atom::operator << (ostream &ost)
173{
174 ost << "[" << Name << "|" << this << "]";
175 return ost;
176};
177
[a0bcf1]178/** Compares the indices of \a this atom with a given \a ptr.
179 * \param ptr atom to compare index against
180 * \return true - this one's is smaller, false - not
[c830e8e]181 */
[b65771]182bool atom::Compare(const atom &ptr)
[a0bcf1]183{
184 if (nr < ptr.nr)
185 return true;
186 else
187 return false;
188};
189
[c830e8e]190bool operator < (atom &a, atom &b)
[a0bcf1]191{
192 return a.Compare(b);
193};
194
Note: See TracBrowser for help on using the repository browser.