| [14de469] | 1 | /** \file atom.cpp
 | 
|---|
| [1907a7] | 2 |  *
 | 
|---|
| [14de469] | 3 |  * Function implementations for the class atom.
 | 
|---|
| [1907a7] | 4 |  *
 | 
|---|
| [14de469] | 5 |  */
 | 
|---|
 | 6 | 
 | 
|---|
 | 7 | #include "molecules.hpp"
 | 
|---|
| [1907a7] | 8 | 
 | 
|---|
| [14de469] | 9 | /************************************* Functions for class atom *************************************/
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | /** Constructor of class atom.
 | 
|---|
 | 12 |  */
 | 
|---|
| [1907a7] | 13 | atom::atom()
 | 
|---|
| [14de469] | 14 | {
 | 
|---|
| [ce5ac3] | 15 |   Name = NULL;
 | 
|---|
| [14de469] | 16 |   previous = NULL;
 | 
|---|
 | 17 |   next = NULL;
 | 
|---|
 | 18 |   father = this;  // generally, father is itself
 | 
|---|
 | 19 |   Ancestor = NULL;
 | 
|---|
 | 20 |   type = NULL;
 | 
|---|
 | 21 |   sort = NULL;
 | 
|---|
| [943d02] | 22 |   FixedIon = 0;
 | 
|---|
| [14de469] | 23 |   nr = -1;
 | 
|---|
 | 24 |   GraphNr = -1;
 | 
|---|
 | 25 |   ComponentNr = NULL;
 | 
|---|
| [683914] | 26 |   IsCyclic = false;
 | 
|---|
| [14de469] | 27 |   SeparationVertex = false;
 | 
|---|
 | 28 |   LowpointNr = -1;
 | 
|---|
| [db942e] | 29 |   AdaptiveOrder = 0;
 | 
|---|
| [362b0e] | 30 |   MaxOrder = false;
 | 
|---|
| [14de469] | 31 | };
 | 
|---|
 | 32 | 
 | 
|---|
| [2319ed] | 33 | /** Constructor of class atom.
 | 
|---|
 | 34 |  *
 | 
|---|
 | 35 |  */
 | 
|---|
 | 36 | atom::atom(atom *pointer)
 | 
|---|
 | 37 | {
 | 
|---|
 | 38 |   Name = NULL;
 | 
|---|
 | 39 |   previous = NULL;
 | 
|---|
 | 40 |   next = NULL;
 | 
|---|
 | 41 |   father = this;  // generally, father is itself
 | 
|---|
 | 42 |   Ancestor = NULL;
 | 
|---|
 | 43 |   type = pointer->type;  // copy element of atom
 | 
|---|
 | 44 |   x.CopyVector(&pointer->x); // copy coordination
 | 
|---|
 | 45 |   v.CopyVector(&pointer->v); // copy velocity
 | 
|---|
 | 46 |   FixedIon = pointer->FixedIon;
 | 
|---|
 | 47 |   nr = -1;
 | 
|---|
 | 48 |   sort = &nr;
 | 
|---|
 | 49 | }
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | 
 | 
|---|
| [14de469] | 52 | /** Destructor of class atom.
 | 
|---|
 | 53 |  */
 | 
|---|
| [1907a7] | 54 | atom::~atom()
 | 
|---|
| [14de469] | 55 | {
 | 
|---|
| [ce5ac3] | 56 |   Free((void **)&Name, "atom::~atom: *Name");
 | 
|---|
| [14de469] | 57 |   Free((void **)&ComponentNr, "atom::~atom: *ComponentNr");
 | 
|---|
 | 58 | };
 | 
|---|
 | 59 | 
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 | /** Climbs up the father list until NULL, last is returned.
 | 
|---|
 | 62 |  * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen)
 | 
|---|
 | 63 |  */
 | 
|---|
 | 64 | atom *atom::GetTrueFather()
 | 
|---|
 | 65 | {
 | 
|---|
 | 66 |   atom *walker = this;
 | 
|---|
 | 67 |   do {
 | 
|---|
 | 68 |     if (walker == walker->father) // top most father is the one that points on itself
 | 
|---|
 | 69 |       break;
 | 
|---|
 | 70 |     walker = walker->father;
 | 
|---|
 | 71 |   } while (walker != NULL);
 | 
|---|
 | 72 |   return walker;
 | 
|---|
 | 73 | };
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 | /** Output of a single atom.
 | 
|---|
 | 76 |  * \param ElementNo cardinal number of the element
 | 
|---|
 | 77 |  * \param AtomNo cardinal number among these atoms of the same element
 | 
|---|
 | 78 |  * \param *out stream to output to
 | 
|---|
| [1907a7] | 79 |  * \param *comment commentary after '#' sign
 | 
|---|
| [14de469] | 80 |  */
 | 
|---|
| [1907a7] | 81 | bool atom::Output(int ElementNo, int AtomNo, ofstream *out, const char *comment) const
 | 
|---|
| [14de469] | 82 | {
 | 
|---|
 | 83 |   if (out != NULL) {
 | 
|---|
 | 84 |     *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t"  << fixed << setprecision(9) << showpoint;
 | 
|---|
| [943d02] | 85 |     *out << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2];
 | 
|---|
 | 86 |     *out << "\t" << FixedIon;
 | 
|---|
 | 87 |     if (v.Norm() > MYEPSILON)
 | 
|---|
 | 88 |       *out << "\t" << scientific << setprecision(6) << v.x[0] << "\t" << v.x[1] << "\t" << v.x[2] << "\t";
 | 
|---|
| [437922] | 89 |     if (comment != NULL)
 | 
|---|
 | 90 |       *out << " # " << comment << endl;
 | 
|---|
 | 91 |     else
 | 
|---|
 | 92 |       *out << " # molecule nr " << nr << endl;
 | 
|---|
| [14de469] | 93 |     return true;
 | 
|---|
 | 94 |   } else
 | 
|---|
 | 95 |     return false;
 | 
|---|
 | 96 | };
 | 
|---|
 | 97 | 
 | 
|---|
 | 98 | /** Output of a single atom as one lin in xyz file.
 | 
|---|
 | 99 |  * \param *out stream to output to
 | 
|---|
 | 100 |  */
 | 
|---|
 | 101 | bool atom::OutputXYZLine(ofstream *out) const
 | 
|---|
 | 102 | {
 | 
|---|
 | 103 |   if (out != NULL) {
 | 
|---|
 | 104 |     *out << type->symbol << "\t" << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2] << "\t" << endl;
 | 
|---|
 | 105 |     return true;
 | 
|---|
 | 106 |   } else
 | 
|---|
 | 107 |     return false;
 | 
|---|
 | 108 | };
 | 
|---|
 | 109 | 
 | 
|---|
| [ba4432] | 110 | ostream & operator << (ostream &ost, const atom &a) 
 | 
|---|
| [14de469] | 111 | {
 | 
|---|
 | 112 |   ost << "[" << a.Name << "|" << &a << "]";
 | 
|---|
 | 113 |   return ost;
 | 
|---|
 | 114 | };
 | 
|---|
 | 115 | 
 | 
|---|
 | 116 | /** Compares the indices of \a this atom with a given \a ptr.
 | 
|---|
 | 117 |  * \param ptr atom to compare index against
 | 
|---|
 | 118 |  * \return true - this one's is smaller, false - not
 | 
|---|
| [1907a7] | 119 |  */
 | 
|---|
| [14de469] | 120 | bool atom::Compare(atom &ptr)
 | 
|---|
 | 121 | {
 | 
|---|
 | 122 |   if (nr < ptr.nr)
 | 
|---|
 | 123 |     return true;
 | 
|---|
 | 124 |   else
 | 
|---|
 | 125 |     return false;
 | 
|---|
 | 126 | };
 | 
|---|
 | 127 | 
 | 
|---|
| [1907a7] | 128 | bool operator < (atom &a, atom &b)
 | 
|---|
| [14de469] | 129 | {
 | 
|---|
 | 130 |   return a.Compare(b);
 | 
|---|
 | 131 | };
 | 
|---|
 | 132 | 
 | 
|---|