| [14de469] | 1 | /** \file atom.cpp
|
|---|
| [1907a7] | 2 | *
|
|---|
| [14de469] | 3 | * Function implementations for the class atom.
|
|---|
| [1907a7] | 4 | *
|
|---|
| [14de469] | 5 | */
|
|---|
| 6 |
|
|---|
| [357fba] | 7 | #include "atom.hpp"
|
|---|
| [29812d] | 8 | #include "memoryallocator.hpp"
|
|---|
| [1907a7] | 9 |
|
|---|
| [14de469] | 10 | /************************************* Functions for class atom *************************************/
|
|---|
| 11 |
|
|---|
| 12 | /** Constructor of class atom.
|
|---|
| 13 | */
|
|---|
| [1907a7] | 14 | atom::atom()
|
|---|
| [14de469] | 15 | {
|
|---|
| [357fba] | 16 | father = this; // generally, father is itself
|
|---|
| [14de469] | 17 | previous = NULL;
|
|---|
| 18 | next = NULL;
|
|---|
| 19 | Ancestor = NULL;
|
|---|
| 20 | type = NULL;
|
|---|
| 21 | sort = NULL;
|
|---|
| [943d02] | 22 | FixedIon = 0;
|
|---|
| [14de469] | 23 | GraphNr = -1;
|
|---|
| 24 | ComponentNr = NULL;
|
|---|
| [683914] | 25 | IsCyclic = false;
|
|---|
| [14de469] | 26 | SeparationVertex = false;
|
|---|
| 27 | LowpointNr = -1;
|
|---|
| [db942e] | 28 | AdaptiveOrder = 0;
|
|---|
| [362b0e] | 29 | MaxOrder = false;
|
|---|
| [357fba] | 30 | // set LCNode::Vector to our Vector
|
|---|
| 31 | node = &x;
|
|---|
| [14de469] | 32 | };
|
|---|
| 33 |
|
|---|
| [2319ed] | 34 | /** Constructor of class atom.
|
|---|
| 35 | */
|
|---|
| 36 | atom::atom(atom *pointer)
|
|---|
| 37 | {
|
|---|
| 38 | Name = NULL;
|
|---|
| 39 | previous = NULL;
|
|---|
| 40 | next = NULL;
|
|---|
| [89c8b2] | 41 | father = pointer; // generally, father is itself
|
|---|
| [2319ed] | 42 | Ancestor = NULL;
|
|---|
| [357fba] | 43 | GraphNr = -1;
|
|---|
| 44 | ComponentNr = NULL;
|
|---|
| 45 | IsCyclic = false;
|
|---|
| 46 | SeparationVertex = false;
|
|---|
| 47 | LowpointNr = -1;
|
|---|
| 48 | AdaptiveOrder = 0;
|
|---|
| 49 | MaxOrder = false;
|
|---|
| [2319ed] | 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;
|
|---|
| [89c8b2] | 56 | node = &x;
|
|---|
| [2319ed] | 57 | }
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| [14de469] | 60 | /** Destructor of class atom.
|
|---|
| 61 | */
|
|---|
| [1907a7] | 62 | atom::~atom()
|
|---|
| [14de469] | 63 | {
|
|---|
| [a33931] | 64 | Free<int>(&ComponentNr, "atom::~atom: *ComponentNr");
|
|---|
| [c26f44] | 65 | Free<char>(&Name, "atom::~atom: *Name");
|
|---|
| [fcd7b6] | 66 | Trajectory.R.clear();
|
|---|
| 67 | Trajectory.U.clear();
|
|---|
| 68 | Trajectory.F.clear();
|
|---|
| [14de469] | 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 | */
|
|---|
| 75 | atom *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 |
|
|---|
| [e65246] | 86 | /** Sets father to itself or its father in case of copying a molecule.
|
|---|
| 87 | */
|
|---|
| 88 | void 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 | */
|
|---|
| 101 | void atom::EqualsFather ( atom *ptr, atom **res )
|
|---|
| 102 | {
|
|---|
| 103 | if ( ptr == father )
|
|---|
| 104 | *res = this;
|
|---|
| 105 | };
|
|---|
| 106 |
|
|---|
| [e9f8f9] | 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 | */
|
|---|
| 112 | bool atom::IsInParallelepiped(Vector offset, double *parallelepiped)
|
|---|
| 113 | {
|
|---|
| 114 | return (node->IsInParallelepiped(offset, parallelepiped));
|
|---|
| 115 | };
|
|---|
| 116 |
|
|---|
| [14de469] | 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
|
|---|
| [1907a7] | 121 | * \param *comment commentary after '#' sign
|
|---|
| [14de469] | 122 | */
|
|---|
| [fcd7b6] | 123 | bool atom::Output(ofstream *out, int ElementNo, int AtomNo, const char *comment) const
|
|---|
| [14de469] | 124 | {
|
|---|
| 125 | if (out != NULL) {
|
|---|
| 126 | *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
|
|---|
| [943d02] | 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";
|
|---|
| [437922] | 131 | if (comment != NULL)
|
|---|
| 132 | *out << " # " << comment << endl;
|
|---|
| [e9f8f9] | 133 | else
|
|---|
| 134 | *out << " # molecule nr " << nr << endl;
|
|---|
| 135 | return true;
|
|---|
| 136 | } else
|
|---|
| 137 | return false;
|
|---|
| 138 | };
|
|---|
| [fcd7b6] | 139 | bool atom::Output(ofstream *out, int *ElementNo, int *AtomNo, const char *comment)
|
|---|
| [e9f8f9] | 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;
|
|---|
| [437922] | 150 | else
|
|---|
| 151 | *out << " # molecule nr " << nr << endl;
|
|---|
| [14de469] | 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 | */
|
|---|
| 160 | bool 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 |
|
|---|
| [fcd7b6] | 169 | /** Output of a single atom as one lin in xyz file.
|
|---|
| 170 | * \param *out stream to output to
|
|---|
| 171 | */
|
|---|
| 172 | bool 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 |
|
|---|
| [681a8a] | 189 | /** Output of a single atom as one lin in xyz file.
|
|---|
| 190 | * \param *out stream to output to
|
|---|
| 191 | */
|
|---|
| 192 | bool 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 |
|
|---|
| [321a11] | 204 | ostream & operator << (ostream &ost, const atom &a)
|
|---|
| [14de469] | 205 | {
|
|---|
| 206 | ost << "[" << a.Name << "|" << &a << "]";
|
|---|
| 207 | return ost;
|
|---|
| 208 | };
|
|---|
| 209 |
|
|---|
| [055861] | 210 | ostream & atom::operator << (ostream &ost)
|
|---|
| 211 | {
|
|---|
| 212 | ost << "[" << Name << "|" << this << "]";
|
|---|
| 213 | return ost;
|
|---|
| 214 | };
|
|---|
| 215 |
|
|---|
| [14de469] | 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
|
|---|
| [1907a7] | 219 | */
|
|---|
| [321a11] | 220 | bool atom::Compare(const atom &ptr)
|
|---|
| [14de469] | 221 | {
|
|---|
| 222 | if (nr < ptr.nr)
|
|---|
| 223 | return true;
|
|---|
| 224 | else
|
|---|
| 225 | return false;
|
|---|
| 226 | };
|
|---|
| 227 |
|
|---|
| [1907a7] | 228 | bool operator < (atom &a, atom &b)
|
|---|
| [14de469] | 229 | {
|
|---|
| 230 | return a.Compare(b);
|
|---|
| 231 | };
|
|---|
| 232 |
|
|---|