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